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(XALANOUTPUTSTREAM_HEADER_GUARD_1357924680) 00019 #define XALANOUTPUTSTREAM_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 00030 00031 00032 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00033 00034 00035 00036 #include <xalanc/PlatformSupport/XalanTranscodingServices.hpp> 00037 #include <xalanc/PlatformSupport/XSLException.hpp> 00038 00039 00040 00041 XALAN_CPP_NAMESPACE_BEGIN 00042 00043 00044 00045 class XalanOutputTranscoder; 00046 00047 00048 00049 class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputStream 00050 { 00051 public : 00052 00053 enum { eDefaultBufferSize = 512u, eDefaultTranscoderBlockSize = 1024u }; 00054 00055 typedef XalanVector<XalanDOMChar> BufferType; 00056 typedef XalanVector<char> TranscodeVectorType; 00057 typedef XalanTranscodingServices::size_type size_type; 00058 00059 /** 00060 * Constructor. 00061 * 00062 * @param theBufferSize the size of the transcoding buffer 00063 * @param theTranscoderBlockSize the size of the block used by the transcoder 00064 * @param fThrowTranscodeException If true, an error transcoding will result in an exception being thrown. 00065 */ 00066 explicit 00067 XalanOutputStream( 00068 MemoryManager& theManager, 00069 size_type theBufferSize = eDefaultBufferSize, 00070 size_type theTranscoderBlockSize = eDefaultTranscoderBlockSize, 00071 bool fThrowTranscodeException = true); 00072 00073 virtual 00074 ~XalanOutputStream(); 00075 00076 MemoryManager& 00077 getMemoryManager() 00078 { 00079 return m_buffer.getMemoryManager(); 00080 } 00081 00082 static const XalanDOMChar* 00083 defaultNewlineString() 00084 { 00085 #if defined(XALAN_NEWLINE_IS_CRLF) 00086 return s_nlCRString; 00087 #else 00088 return s_nlString; 00089 #endif 00090 } 00091 00092 /** 00093 * Write the appropriate newline character(s) to the stream. 00094 */ 00095 virtual void 00096 newline(); 00097 00098 /** 00099 * Get the string which is appropriate for inserting a line feed in the stream. 00100 */ 00101 virtual const XalanDOMChar* 00102 getNewlineString() const; 00103 00104 /** 00105 * Flush the stream's transcoding buffer, but do not request 00106 * the implementation class to flush its buffer. 00107 * . 00108 */ 00109 void 00110 flushBuffer(); 00111 00112 /** 00113 * Flush the stream's buffer. 00114 */ 00115 void 00116 flush() 00117 { 00118 flushBuffer(); 00119 00120 doFlush(); 00121 } 00122 00123 /** 00124 * Write a character to the output stream. The character 00125 * will not be transcoded. 00126 * 00127 * @param theChar the character to write 00128 */ 00129 void 00130 write(char theChar) 00131 { 00132 write(&theChar, 1); 00133 } 00134 00135 /** 00136 * Write a wide character to the output stream. The character 00137 * will be transcoded, if an output encoding is specified. 00138 * 00139 * @param theChar the character to write 00140 */ 00141 void 00142 write(XalanDOMChar theChar) 00143 { 00144 assert(m_bufferSize > 0); 00145 00146 if (m_buffer.size() == m_bufferSize) 00147 { 00148 flushBuffer(); 00149 } 00150 00151 m_buffer.push_back(theChar); 00152 } 00153 00154 /** 00155 * Write a null-terminated string to the output file. The character 00156 * will not be transcoded. The caller is responsible for making sure the 00157 * buffer is flushed before calling this member function. 00158 * 00159 * @param theBuffer character buffer to write 00160 */ 00161 void 00162 write(const char* theBuffer) 00163 { 00164 assert(theBuffer != 0); 00165 assert(m_buffer.empty() == true); 00166 00167 write(theBuffer, length(theBuffer)); 00168 } 00169 00170 /** 00171 * Write a null-terminated wide string to the output file. The string 00172 * will be transcoded, if an output encoding is specified. 00173 * 00174 * @param theBuffer character buffer to write 00175 */ 00176 void 00177 write(const XalanDOMChar* theBuffer) 00178 { 00179 write(theBuffer, length(theBuffer)); 00180 } 00181 00182 /** 00183 * Write a specified number of characters to the output stream. The string 00184 * will not be transcoded. The caller is responsible for making sure the 00185 * buffer is flushed before calling this member function. 00186 * 00187 * @param theBuffer character buffer to write 00188 * @param theBufferLength number of characters to write 00189 */ 00190 void 00191 write( 00192 const char* theBuffer, 00193 size_type theBufferLength) 00194 { 00195 assert(theBuffer != 0); 00196 assert(m_buffer.empty() == true); 00197 00198 writeData(theBuffer, 00199 theBufferLength); 00200 } 00201 00202 /** 00203 * Write a specified number of characters to the output stream. The string 00204 * will be transcoded, if an output encoding is specified. 00205 * 00206 * @param theBuffer character buffer to write 00207 * @param theBufferLength number of characters to write 00208 */ 00209 void 00210 write( 00211 const XalanDOMChar* theBuffer, 00212 size_type theBufferLength); 00213 00214 /** 00215 * Get the output encoding for the stream. 00216 * 00217 * @return The encoding name 00218 */ 00219 const XalanDOMString& 00220 getOutputEncoding() const 00221 { 00222 return m_encoding; 00223 } 00224 00225 /** 00226 * Set the output encoding for the stream. 00227 * 00228 * @param theEncoding The encoding name 00229 */ 00230 void 00231 setOutputEncoding(const XalanDOMString& theEncoding); 00232 00233 /** 00234 * Determine if a given value can be represented in 00235 * the output encoding. 00236 * 00237 * @return true if the value can be represented, and false if not. 00238 */ 00239 bool 00240 canTranscodeTo(XalanUnicodeChar theChar) const; 00241 00242 00243 const XalanOutputTranscoder* 00244 getTranscoder() const 00245 { 00246 return m_transcoder; 00247 } 00248 00249 /** 00250 * Set the flag that indicates whether a transcoding 00251 * error should throw an exception. The default is 00252 * to throw an exception. If this flag is false, and 00253 * and an error occurs transcoding, then data will 00254 * likely be lost. 00255 * 00256 * @return the value of the flag. 00257 */ 00258 bool 00259 getThrowTranscodeException() const 00260 { 00261 return m_throwTranscodeException; 00262 } 00263 00264 /** 00265 * Set the flag that indicates whether a transcoding 00266 * error should throw an exception. The default is 00267 * to throw an exception. If this flag is false, and 00268 * and an error occurs transcoding, then data will 00269 * likely be lost. 00270 * 00271 * @param the new value of the flag. 00272 */ 00273 void 00274 setThrowTranscodeException(bool flag) 00275 { 00276 m_throwTranscodeException = flag; 00277 } 00278 00279 /** 00280 * Set the size of the output buffer. 00281 * 00282 * @param theBufferSize The buffer size. 00283 */ 00284 void 00285 setBufferSize(size_type theBufferSize); 00286 00287 00288 class XALAN_PLATFORMSUPPORT_EXPORT XalanOutputStreamException : public XSLException 00289 { 00290 public: 00291 00292 XalanOutputStreamException( 00293 const XalanDOMString& theMessage, 00294 MemoryManager& theManager, 00295 const Locator* theLocator); 00296 00297 XalanOutputStreamException( 00298 const XalanDOMString& theMessage, 00299 MemoryManager& theManager); 00300 00301 XalanOutputStreamException(const XalanOutputStreamException& other); 00302 00303 virtual 00304 ~XalanOutputStreamException(); 00305 00306 virtual const XalanDOMChar* 00307 getType() const; 00308 00309 private: 00310 }; 00311 00312 class XALAN_PLATFORMSUPPORT_EXPORT UnsupportedEncodingException : public XalanOutputStreamException 00313 { 00314 public: 00315 00316 UnsupportedEncodingException( 00317 const XalanDOMString& theEncoding, 00318 XalanDOMString& theBuffer, 00319 const Locator* theLocator); 00320 00321 UnsupportedEncodingException( 00322 const XalanDOMString& theEncoding, 00323 XalanDOMString& theBuffer); 00324 00325 UnsupportedEncodingException(const UnsupportedEncodingException& other) : 00326 XalanOutputStreamException(other), 00327 m_encoding( 00328 other.m_encoding, 00329 other.m_memoryManager) 00330 { 00331 } 00332 00333 virtual 00334 ~UnsupportedEncodingException(); 00335 00336 const XalanDOMString& 00337 getEncoding() const 00338 { 00339 return m_encoding; 00340 } 00341 00342 virtual const XalanDOMChar* 00343 getType() const; 00344 00345 private: 00346 00347 const XalanDOMString m_encoding; 00348 }; 00349 00350 class XALAN_PLATFORMSUPPORT_EXPORT TranscoderInternalFailureException : public XalanOutputStreamException 00351 { 00352 public: 00353 00354 TranscoderInternalFailureException( 00355 const XalanDOMString& theEncoding, 00356 XalanDOMString& theBuffer, 00357 const Locator* theLocator); 00358 00359 TranscoderInternalFailureException( 00360 const XalanDOMString& theEncoding, 00361 XalanDOMString& theBuffer); 00362 00363 TranscoderInternalFailureException(const TranscoderInternalFailureException& other); 00364 00365 virtual 00366 ~TranscoderInternalFailureException(); 00367 00368 virtual const XalanDOMChar* 00369 getType() const; 00370 00371 const XalanDOMString& 00372 getEncoding() const 00373 { 00374 return m_encoding; 00375 } 00376 00377 private: 00378 00379 const XalanDOMString m_encoding; 00380 }; 00381 00382 class XALAN_PLATFORMSUPPORT_EXPORT TranscodingException : public XalanOutputStreamException 00383 { 00384 public: 00385 00386 TranscodingException( 00387 XalanDOMString& theBuffer, 00388 const Locator* theLocator); 00389 00390 explicit 00391 TranscodingException(XalanDOMString& theBuffer); 00392 00393 TranscodingException(const TranscodingException& other); 00394 00395 virtual 00396 ~TranscodingException(); 00397 00398 virtual const XalanDOMChar* 00399 getType() const; 00400 }; 00401 00402 static XalanDOMString& 00403 formatMessage( 00404 const XalanDOMString& theMessage, 00405 int theErrorCode, 00406 XalanDOMString& theBuffer); 00407 00408 protected: 00409 00410 /** 00411 * Transcode a wide string. 00412 * 00413 * @param theBuffer The string to transcode. 00414 * @param theBufferLength The length of the string. 00415 * @param theDestination The destination vector. 00416 */ 00417 void 00418 transcode( 00419 const XalanDOMChar* theBuffer, 00420 size_type theBufferLength, 00421 TranscodeVectorType& theDestination); 00422 00423 /** 00424 * Write the data in the buffer 00425 * 00426 * @param theBuffer The data to write 00427 * @param theBufferLength The length of theBuffer. 00428 */ 00429 virtual void 00430 writeData( 00431 const char* theBuffer, 00432 size_type theBufferLength) = 0; 00433 00434 /** 00435 * Flush the stream. 00436 */ 00437 virtual void 00438 doFlush() = 0; 00439 00440 static const XalanDOMChar s_nlString[]; 00441 static const XalanDOMChar s_nlCRString[]; 00442 00443 static const XalanDOMString::size_type s_nlStringLength; 00444 static const XalanDOMString::size_type s_nlCRStringLength; 00445 00446 private: 00447 00448 // These are not implemented... 00449 XalanOutputStream(const XalanOutputStream&); 00450 00451 XalanOutputStream& 00452 operator=(const XalanOutputStream&); 00453 00454 bool 00455 operator==(const XalanOutputStream&) const; 00456 00457 void 00458 doWrite( 00459 const XalanDOMChar* theBuffer, 00460 size_type theBufferLength); 00461 00462 00463 const size_type m_transcoderBlockSize; 00464 00465 XalanOutputTranscoder* m_transcoder; 00466 00467 size_type m_bufferSize; 00468 00469 BufferType m_buffer; 00470 00471 XalanDOMString m_encoding; 00472 00473 bool m_writeAsUTF16; 00474 00475 bool m_throwTranscodeException; 00476 00477 TranscodeVectorType m_transcodingBuffer; 00478 }; 00479 00480 00481 00482 XALAN_CPP_NAMESPACE_END 00483 00484 00485 00486 #endif // XALANOUTPUTSTREAM_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 |
|