00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680) 00019 #define XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00025 00026 00027 00028 #include <cassert> 00029 00030 00031 00032 #include <xalanc/PlatformSupport/DOMStringHelper.hpp> 00033 #include <xalanc/PlatformSupport/XSLException.hpp> 00034 00035 00036 00037 XALAN_CPP_NAMESPACE_BEGIN 00038 00039 00040 00041 class XalanOutputTranscoder; 00042 00043 00044 00045 class XALAN_PLATFORMSUPPORT_EXPORT XalanTranscodingServices 00046 { 00047 public: 00048 00049 /** 00050 * Perform static initialization. See class PlatformSupportInit. 00051 */ 00052 static void 00053 initialize(MemoryManager& theManager); 00054 00055 /** 00056 * Perform static shut down. See class PlatformSupportInit. 00057 */ 00058 static void 00059 terminate(); 00060 00061 typedef unsigned char XalanXMLByte; 00062 typedef XalanSize_t size_type; 00063 00064 static size_type 00065 length(const XalanXMLByte* theBytes) 00066 { 00067 assert(theBytes != 0); 00068 00069 size_type i = 0; 00070 00071 while(theBytes[i] != 0) 00072 { 00073 ++i; 00074 } 00075 00076 return i; 00077 } 00078 00079 enum eCode 00080 { 00081 OK, 00082 UnsupportedEncoding, 00083 InternalFailure, 00084 SupportFilesNotFound 00085 }; 00086 00087 00088 /** 00089 * Create a transcoder instance for the specified encoding. 00090 * 00091 * @param theEncodingName The name of the desired output encoding. 00092 * @param theResult The error code. 00093 * @param theTarget The target array for storing the transcoded data. 00094 * @param theBlockSize The block size the transcoder should use. 00095 * @return The new transcoder, or 0 if there was an error. 00096 */ 00097 static XalanOutputTranscoder* 00098 makeNewTranscoder( 00099 MemoryManager& theManager, 00100 const XalanDOMString& theEncodingName, 00101 eCode& theResult, 00102 size_type theBlockSize); 00103 00104 static XalanOutputTranscoder* 00105 makeNewTranscoder( 00106 MemoryManager& theManager, 00107 const XalanDOMChar* theEncodingName, 00108 eCode& theResult, 00109 size_type theBlockSize); 00110 00111 /** 00112 * Destroy a transcoder instance. 00113 * 00114 * @theTranscoder The transcoder to destroy. 00115 */ 00116 static void 00117 destroyTranscoder(XalanOutputTranscoder* theTranscoder); 00118 00119 /** 00120 * Determine if the encoding name supplied is equivalent to UTF-8. 00121 * 00122 * @param theEncodingName The name of the output encoding. 00123 * @return true or false 00124 */ 00125 static bool 00126 encodingIsUTF8(const XalanDOMChar* theEncodingName); 00127 00128 /** 00129 * Determine if the encoding name supplied is equivalent to UTF-8. 00130 * 00131 * @param theEncodingName The name of the output encoding. 00132 * @return true or false 00133 */ 00134 static bool 00135 encodingIsUTF8(const XalanDOMString& theEncodingName); 00136 00137 /** 00138 * Determine if the encoding name supplied is equivalent to UTF-16. 00139 * 00140 * @param theEncodingName The name of the output encoding. 00141 * @return true or false 00142 */ 00143 static bool 00144 encodingIsUTF16(const XalanDOMChar* theEncodingName); 00145 00146 /** 00147 * Determine if the encoding name supplied is equivalent to UTF-16. 00148 * 00149 * @param theEncodingName The name of the output encoding. 00150 * @return true or false 00151 */ 00152 static bool 00153 encodingIsUTF16(const XalanDOMString& theEncodingName); 00154 00155 /** 00156 * Determine if the encoding name supplied is equivalent to UTF-32. 00157 * 00158 * @param theEncodingName The name of the output encoding. 00159 * @return true or false 00160 */ 00161 static bool 00162 encodingIsUTF32(const XalanDOMChar* theEncodingName); 00163 00164 /** 00165 * Determine if the encoding name supplied is equivalent to UTF-32. 00166 * 00167 * @param theEncodingName The name of the output encoding. 00168 * @return true or false 00169 */ 00170 static bool 00171 encodingIsUTF32(const XalanDOMString& theEncodingName); 00172 00173 /** 00174 * Get an array that contains any leading bytes that should be 00175 * written to an XML stream for the specified encoding. For example, 00176 * if the encoding is UTF-16, the vector will contain the appropriate 00177 * byte order mark for the current platform. If there is no 00178 * prolog for the encoding, or the encoding is unknown, an empty 00179 * array is returned. 00180 * 00181 * @param theEncodingName The name of the desired output encoding. 00182 * @return An array containing the appropriate bytes. 00183 */ 00184 static const XalanXMLByte* 00185 getStreamProlog(const XalanDOMString& theEncodingName); 00186 00187 /** 00188 * Get the maximum character value for the encoding. 00189 * 00190 * @param theEncoding The encoding name. 00191 * @return The maximum character value the encoding supports. 00192 */ 00193 static XalanDOMChar 00194 getMaximumCharacterValue(const XalanDOMString& theEncoding); 00195 00196 /** 00197 * Get the maximum character value for the local code page. 00198 * This is now deprecated, since it's impossibly broken. 00199 * 00200 * @deprecated 00201 * 00202 * @return The maximum character value the local code page supports. 00203 */ 00204 static XalanDOMChar 00205 getMaximumCharacterValue(); 00206 00207 /** 00208 * Determine if the output stage can safely skip transcoding 00209 * by truncating. 00210 * 00211 * @param theEncoding The encoding name. 00212 * @return true if truncation is possible, false if not. 00213 */ 00214 static bool 00215 getBytesEqualChars(const XalanDOMString& theEncoding); 00216 00217 static const XalanDOMChar s_utf8String[]; 00218 00219 static const XalanDOMChar s_utf16String[]; 00220 00221 static const XalanDOMChar s_utf16LEString[]; 00222 00223 static const XalanDOMChar s_utf16BEString[]; 00224 00225 static const XalanDOMChar s_utf32String[]; 00226 00227 static const XalanDOMChar s_asciiString[]; 00228 00229 static const XalanDOMChar s_usASCIIString[]; 00230 00231 static const XalanDOMChar s_windows1250String[]; 00232 00233 static const XalanDOMChar s_iso88591String[]; 00234 00235 static const XalanDOMChar s_shiftJISString[]; 00236 00237 00238 class XALAN_PLATFORMSUPPORT_EXPORT MakeTranscoderException : public XSLException 00239 { 00240 public: 00241 00242 MakeTranscoderException( 00243 eCode theCode, 00244 const XalanDOMChar* theEncoding, 00245 XalanDOMString& theBuffer, 00246 const Locator* theLocator = 0); 00247 00248 MakeTranscoderException(const MakeTranscoderException&); 00249 00250 virtual 00251 ~MakeTranscoderException(); 00252 00253 eCode 00254 getCode() const 00255 { 00256 return m_code; 00257 } 00258 00259 const XalanDOMString& 00260 getEncoding() const 00261 { 00262 return m_encoding; 00263 } 00264 00265 virtual const XalanDOMChar* 00266 getType() const 00267 { 00268 return s_type; 00269 } 00270 00271 private: 00272 00273 static const XalanDOMChar s_type[]; 00274 00275 const eCode m_code; 00276 00277 mutable XalanDOMString m_encoding; 00278 }; 00279 00280 class XALAN_PLATFORMSUPPORT_EXPORT UnrepresentableCharacterException : public XSLException 00281 { 00282 public: 00283 00284 UnrepresentableCharacterException( 00285 XalanUnicodeChar theCharacter, 00286 const XalanDOMString& theEncoding, 00287 XalanDOMString& theBuffer, 00288 const Locator* theLocator = 0); 00289 00290 UnrepresentableCharacterException(const UnrepresentableCharacterException& theSource); 00291 00292 virtual 00293 ~UnrepresentableCharacterException(); 00294 00295 XalanUnicodeChar 00296 getCharacter() const 00297 { 00298 return m_badCharacter; 00299 } 00300 00301 const XalanDOMString& 00302 getEncoding() const 00303 { 00304 return m_encoding; 00305 } 00306 00307 virtual const XalanDOMChar* 00308 getType() const 00309 { 00310 return s_type; 00311 } 00312 00313 private: 00314 00315 static const XalanDOMChar s_type[]; 00316 00317 00318 const XalanUnicodeChar m_badCharacter; 00319 00320 mutable XalanDOMString m_encoding; 00321 }; 00322 00323 private: 00324 00325 static const XalanXMLByte s_dummyByteOrderMark[]; 00326 static const XalanXMLByte s_UTF8ByteOrderMark[]; 00327 static const XalanDOMChar s_UTF16ByteOrderMark[]; 00328 }; 00329 00330 00331 00332 class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputTranscoder 00333 { 00334 public: 00335 00336 typedef XalanTranscodingServices::XalanXMLByte XalanXMLByte; 00337 typedef XalanTranscodingServices::eCode eCode; 00338 typedef XalanTranscodingServices::size_type size_type; 00339 00340 explicit 00341 XalanOutputTranscoder(MemoryManager& theManager); 00342 00343 virtual 00344 ~XalanOutputTranscoder(); 00345 00346 MemoryManager& 00347 getMemoryManager() 00348 { 00349 return m_memoryManager; 00350 } 00351 00352 /** 00353 * Transcode data from UTF-16 to the transcoder's encoding. If successfull, 00354 * theResult will be set to OK. If not, it will be set to one of the other 00355 * codes. 00356 * 00357 * @param theSourceData The source data to transcode 00358 * @param theSourceCount The length of the source data. 00359 * @param theTarget The target array for storing the transcoded data. 00360 * @param theTargetSize The number of characters that can be stored in the target. 00361 * @param theSourceCharsTranscoded The count of the source characters that were transcoded. 00362 * @param theTargetBytesUsed The number of characters stored in the target array 00363 * @return The result code. 00364 */ 00365 virtual eCode 00366 transcode( 00367 const XalanDOMChar* theSourceData, 00368 size_type theSourceCount, 00369 XalanXMLByte* theTarget, 00370 size_type theTargetSize, 00371 size_type& theSourceCharsTranscoded, 00372 size_type& theTargetBytesUsed) = 0; 00373 00374 /** 00375 * Transcode data from the transcoder's encoding to UTF-16. If successfull, 00376 * theResult will be set to OK. If not, it will be set to one of the other 00377 * codes. 00378 * 00379 * @param theSourceData The source data to transcode 00380 * @param theSourceCount The length of the source data. 00381 * @param theTarget The target array for storing the transcoded data. 00382 * @param theTargetSize The number of characters that can be stored in the target. 00383 * @param theSourceCharsTranscoded The count of the source characters that were transcoded. 00384 * @param theTargetBytesUsed The number of characters stored in the target array 00385 * @param theCharSizes For each character in theTarget, the number of characters consumed from theSourceData. 00386 * @return The result code. 00387 */ 00388 virtual eCode 00389 transcode( 00390 const XalanXMLByte* theSourceData, 00391 size_type theSourceCount, 00392 XalanDOMChar* theTarget, 00393 size_type theTargetSize, 00394 size_type& theSourceCharsTranscoded, 00395 size_type& theTargetBytesUsed, 00396 unsigned char* theCharSizes) = 0; 00397 00398 virtual bool 00399 canTranscodeTo(XalanUnicodeChar theChar) const = 0; 00400 00401 private: 00402 00403 MemoryManager& m_memoryManager; 00404 00405 // Not implemented... 00406 XalanOutputTranscoder(const XalanOutputTranscoder& theSource); 00407 00408 bool 00409 operator==(const XalanOutputTranscoder& theRHS) const; 00410 00411 XalanOutputTranscoder& 00412 operator=(const XalanOutputTranscoder& theRHS); 00413 }; 00414 00415 00416 00417 XALAN_CPP_NAMESPACE_END 00418 00419 00420 00421 #endif // XALANTRANSCODINGSERVICES_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|