00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 #if !defined(XMLFORMATTER_HPP)
00134 #define XMLFORMATTER_HPP
00135
00136 #include <xercesc/util/PlatformUtils.hpp>
00137
00138 XERCES_CPP_NAMESPACE_BEGIN
00139
00140 class XMLFormatTarget;
00141 class XMLTranscoder;
00142
00152 class XMLFormatter : public XMemory
00153 {
00154 public:
00155
00156
00157
00235 enum EscapeFlags
00236 {
00237 NoEscapes
00238 , StdEscapes
00239 , AttrEscapes
00240 , CharEscapes
00241
00242
00243 , EscapeFlags_Count
00244 , DefaultEscape = 999
00245 };
00246
00263 enum UnRepFlags
00264 {
00265 UnRep_Fail
00266 , UnRep_CharRef
00267 , UnRep_Replace
00268
00269 , DefaultUnRep = 999
00270 };
00272
00273
00274
00275
00276
00285 XMLFormatter
00286 (
00287 const XMLCh* const outEncoding
00288 , const XMLCh* const docVersion
00289 , XMLFormatTarget* const target
00290 , const EscapeFlags escapeFlags = NoEscapes
00291 , const UnRepFlags unrepFlags = UnRep_Fail
00292 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00293 );
00294
00295 XMLFormatter
00296 (
00297 const char* const outEncoding
00298 , const char* const docVersion
00299 , XMLFormatTarget* const target
00300 , const EscapeFlags escapeFlags = NoEscapes
00301 , const UnRepFlags unrepFlags = UnRep_Fail
00302 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00303 );
00304
00305 ~XMLFormatter();
00307
00308
00309
00310
00311
00321 void formatBuf
00322 (
00323 const XMLCh* const toFormat
00324 , const unsigned int count
00325 , const EscapeFlags escapeFlags = DefaultEscape
00326 , const UnRepFlags unrepFlags = DefaultUnRep
00327 );
00328
00332 XMLFormatter& operator<<
00333 (
00334 const XMLCh* const toFormat
00335 );
00336
00337 XMLFormatter& operator<<
00338 (
00339 const XMLCh toFormat
00340 );
00341
00342 void writeBOM(const XMLByte* const toFormat
00343 , const unsigned int count);
00344
00346
00347
00348
00349
00356 const XMLCh* getEncodingName() const;
00357
00361 inline const XMLTranscoder* getTranscoder() const;
00362
00364
00365
00366
00367
00373 void setEscapeFlags
00374 (
00375 const EscapeFlags newFlags
00376 );
00377
00381 void setUnRepFlags
00382 (
00383 const UnRepFlags newFlags
00384 );
00385
00390 XMLFormatter& operator<<
00391 (
00392 const EscapeFlags newFlags
00393 );
00394
00399 XMLFormatter& operator<<
00400 (
00401 const UnRepFlags newFlags
00402 );
00404
00405
00406 private :
00407
00408
00409
00410 XMLFormatter();
00411 XMLFormatter(const XMLFormatter&);
00412 XMLFormatter& operator=(const XMLFormatter&);
00413
00414
00415
00416
00417
00418 enum Constants
00419 {
00420 kTmpBufSize = 16 * 1024
00421 };
00422
00423
00424
00425
00426
00427 const XMLByte* getCharRef(unsigned int & count,
00428 XMLByte* &ref,
00429 const XMLCh * stdRef);
00430
00431 const void writeCharRef(const XMLCh &toWrite);
00432
00433 bool inEscapeList(const XMLFormatter::EscapeFlags escStyle
00434 , const XMLCh toCheck);
00435
00436
00437 unsigned int handleUnEscapedChars(const XMLCh * srcPtr,
00438 const unsigned int count,
00439 const UnRepFlags unrepFlags);
00440
00441 void specialFormat
00442 (
00443 const XMLCh* const toFormat
00444 , const unsigned int count
00445 , const EscapeFlags escapeFlags
00446 );
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 EscapeFlags fEscapeFlags;
00491 XMLCh* fOutEncoding;
00492 XMLFormatTarget* fTarget;
00493 UnRepFlags fUnRepFlags;
00494 XMLTranscoder* fXCoder;
00495 XMLByte fTmpBuf[kTmpBufSize + 4];
00496 XMLByte* fAposRef;
00497 unsigned int fAposLen;
00498 XMLByte* fAmpRef;
00499 unsigned int fAmpLen;
00500 XMLByte* fGTRef;
00501 unsigned int fGTLen;
00502 XMLByte* fLTRef;
00503 unsigned int fLTLen;
00504 XMLByte* fQuoteRef;
00505 unsigned int fQuoteLen;
00506 bool fIsXML11;
00507 MemoryManager* fMemoryManager;
00508 };
00509
00510
00511 class XMLFormatTarget : public XMemory
00512 {
00513 public:
00514
00515
00516
00517 virtual ~XMLFormatTarget() {}
00518
00519
00520
00521
00522
00523 virtual void writeChars
00524 (
00525 const XMLByte* const toWrite
00526 , const unsigned int count
00527 , XMLFormatter* const formatter
00528 ) = 0;
00529
00530 virtual void flush() {};
00531
00532
00533 protected :
00534
00535
00536
00537 XMLFormatTarget() {}
00538 XMLFormatTarget(const XMLFormatTarget&) {}
00539 void operator=(const XMLFormatTarget&) {}
00540 };
00541
00542
00543
00544
00545
00546 inline const XMLCh* XMLFormatter::getEncodingName() const
00547 {
00548 return fOutEncoding;
00549 }
00550
00551 inline const XMLTranscoder* XMLFormatter::getTranscoder() const
00552 {
00553 return fXCoder;
00554 }
00555
00556
00557
00558
00559 inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags)
00560 {
00561 fEscapeFlags = newFlags;
00562 }
00563
00564 inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags)
00565 {
00566 fUnRepFlags = newFlags;
00567 }
00568
00569
00570 inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags)
00571 {
00572 fEscapeFlags = newFlags;
00573 return *this;
00574 }
00575
00576 inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags)
00577 {
00578 fUnRepFlags = newFlags;
00579 return *this;
00580 }
00581
00582 XERCES_CPP_NAMESPACE_END
00583
00584 #endif