00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(XMLFORMATTER_HPP)
00022 #define XMLFORMATTER_HPP
00023
00024 #include <xercesc/util/PlatformUtils.hpp>
00025
00026 XERCES_CPP_NAMESPACE_BEGIN
00027
00028 class XMLFormatTarget;
00029 class XMLTranscoder;
00030
00040 class XMLFormatter : public XMemory
00041 {
00042 public:
00043
00044
00045
00123 enum EscapeFlags
00124 {
00125 NoEscapes
00126 , StdEscapes
00127 , AttrEscapes
00128 , CharEscapes
00129
00130
00131 , EscapeFlags_Count
00132 , DefaultEscape = 999
00133 };
00134
00151 enum UnRepFlags
00152 {
00153 UnRep_Fail
00154 , UnRep_CharRef
00155 , UnRep_Replace
00156
00157 , DefaultUnRep = 999
00158 };
00160
00161
00162
00163
00164
00176 XMLFormatter
00177 (
00178 const XMLCh* const outEncoding
00179 , const XMLCh* const docVersion
00180 , XMLFormatTarget* const target
00181 , const EscapeFlags escapeFlags = NoEscapes
00182 , const UnRepFlags unrepFlags = UnRep_Fail
00183 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00184 );
00185
00186 XMLFormatter
00187 (
00188 const char* const outEncoding
00189 , const char* const docVersion
00190 , XMLFormatTarget* const target
00191 , const EscapeFlags escapeFlags = NoEscapes
00192 , const UnRepFlags unrepFlags = UnRep_Fail
00193 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00194 );
00195
00196 XMLFormatter
00197 (
00198 const XMLCh* const outEncoding
00199 , XMLFormatTarget* const target
00200 , const EscapeFlags escapeFlags = NoEscapes
00201 , const UnRepFlags unrepFlags = UnRep_Fail
00202 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00203 );
00204
00205 XMLFormatter
00206 (
00207 const char* const outEncoding
00208 , XMLFormatTarget* const target
00209 , const EscapeFlags escapeFlags = NoEscapes
00210 , const UnRepFlags unrepFlags = UnRep_Fail
00211 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00212 );
00213
00214 ~XMLFormatter();
00216
00217
00218
00219
00220
00230 void formatBuf
00231 (
00232 const XMLCh* const toFormat
00233 , const unsigned int count
00234 , const EscapeFlags escapeFlags = DefaultEscape
00235 , const UnRepFlags unrepFlags = DefaultUnRep
00236 );
00237
00241 XMLFormatter& operator<<
00242 (
00243 const XMLCh* const toFormat
00244 );
00245
00246 XMLFormatter& operator<<
00247 (
00248 const XMLCh toFormat
00249 );
00250
00251 void writeBOM(const XMLByte* const toFormat
00252 , const unsigned int count);
00253
00255
00256
00257
00258
00265 const XMLCh* getEncodingName() const;
00266
00270 inline const XMLTranscoder* getTranscoder() const;
00271
00273
00274
00275
00276
00282 void setEscapeFlags
00283 (
00284 const EscapeFlags newFlags
00285 );
00286
00290 void setUnRepFlags
00291 (
00292 const UnRepFlags newFlags
00293 );
00294
00299 XMLFormatter& operator<<
00300 (
00301 const EscapeFlags newFlags
00302 );
00303
00308 XMLFormatter& operator<<
00309 (
00310 const UnRepFlags newFlags
00311 );
00313
00314
00315
00316
00317
00323 EscapeFlags getEscapeFlags() const;
00324
00328 UnRepFlags getUnRepFlags() const;
00330
00331 private :
00332
00333
00334
00335 XMLFormatter();
00336 XMLFormatter(const XMLFormatter&);
00337 XMLFormatter& operator=(const XMLFormatter&);
00338
00339
00340
00341
00342
00343 enum Constants
00344 {
00345 kTmpBufSize = 16 * 1024
00346 };
00347
00348
00349
00350
00351
00352 const XMLByte* getCharRef(unsigned int & count,
00353 XMLByte* &ref,
00354 const XMLCh * stdRef);
00355
00356 void writeCharRef(const XMLCh &toWrite);
00357 void writeCharRef(unsigned long toWrite);
00358
00359 bool inEscapeList(const XMLFormatter::EscapeFlags escStyle
00360 , const XMLCh toCheck);
00361
00362
00363 unsigned int handleUnEscapedChars(const XMLCh * srcPtr,
00364 const unsigned int count,
00365 const UnRepFlags unrepFlags);
00366
00367 void specialFormat
00368 (
00369 const XMLCh* const toFormat
00370 , const unsigned int count
00371 , const EscapeFlags escapeFlags
00372 );
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 EscapeFlags fEscapeFlags;
00417 XMLCh* fOutEncoding;
00418 XMLFormatTarget* fTarget;
00419 UnRepFlags fUnRepFlags;
00420 XMLTranscoder* fXCoder;
00421 XMLByte fTmpBuf[kTmpBufSize + 4];
00422 XMLByte* fAposRef;
00423 unsigned int fAposLen;
00424 XMLByte* fAmpRef;
00425 unsigned int fAmpLen;
00426 XMLByte* fGTRef;
00427 unsigned int fGTLen;
00428 XMLByte* fLTRef;
00429 unsigned int fLTLen;
00430 XMLByte* fQuoteRef;
00431 unsigned int fQuoteLen;
00432 bool fIsXML11;
00433 MemoryManager* fMemoryManager;
00434 };
00435
00436
00437 class XMLFormatTarget : public XMemory
00438 {
00439 public:
00440
00441
00442
00443 virtual ~XMLFormatTarget() {}
00444
00445
00446
00447
00448
00449 virtual void writeChars
00450 (
00451 const XMLByte* const toWrite
00452 , const unsigned int count
00453 , XMLFormatter* const formatter
00454 ) = 0;
00455
00456 virtual void flush() {};
00457
00458
00459 protected :
00460
00461
00462
00463 XMLFormatTarget() {};
00464
00465 private:
00466
00467
00468
00469 XMLFormatTarget(const XMLFormatTarget&);
00470 XMLFormatTarget& operator=(const XMLFormatTarget&);
00471 };
00472
00473
00474
00475
00476
00477 inline const XMLCh* XMLFormatter::getEncodingName() const
00478 {
00479 return fOutEncoding;
00480 }
00481
00482 inline const XMLTranscoder* XMLFormatter::getTranscoder() const
00483 {
00484 return fXCoder;
00485 }
00486
00487
00488
00489
00490 inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags)
00491 {
00492 fEscapeFlags = newFlags;
00493 }
00494
00495 inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags)
00496 {
00497 fUnRepFlags = newFlags;
00498 }
00499
00500
00501 inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags)
00502 {
00503 fEscapeFlags = newFlags;
00504 return *this;
00505 }
00506
00507 inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags)
00508 {
00509 fUnRepFlags = newFlags;
00510 return *this;
00511 }
00512
00513
00514
00515
00516 inline XMLFormatter::EscapeFlags XMLFormatter::getEscapeFlags() const
00517 {
00518 return fEscapeFlags;
00519 }
00520
00521 inline XMLFormatter::UnRepFlags XMLFormatter::getUnRepFlags() const
00522 {
00523 return fUnRepFlags;
00524 }
00525
00526 XERCES_CPP_NAMESPACE_END
00527
00528 #endif