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
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 #if !defined(XMLFORMATTER_HPP)
00149 #define XMLFORMATTER_HPP
00150
00151 #include <xercesc/util/PlatformUtils.hpp>
00152
00153 XERCES_CPP_NAMESPACE_BEGIN
00154
00155 class XMLFormatTarget;
00156 class XMLTranscoder;
00157
00167 class XMLFormatter : public XMemory
00168 {
00169 public:
00170
00171
00172
00250 enum EscapeFlags
00251 {
00252 NoEscapes
00253 , StdEscapes
00254 , AttrEscapes
00255 , CharEscapes
00256
00257
00258 , EscapeFlags_Count
00259 , DefaultEscape = 999
00260 };
00261
00278 enum UnRepFlags
00279 {
00280 UnRep_Fail
00281 , UnRep_CharRef
00282 , UnRep_Replace
00283
00284 , DefaultUnRep = 999
00285 };
00287
00288
00289
00290
00291
00303 XMLFormatter
00304 (
00305 const XMLCh* const outEncoding
00306 , const XMLCh* const docVersion
00307 , XMLFormatTarget* const target
00308 , const EscapeFlags escapeFlags = NoEscapes
00309 , const UnRepFlags unrepFlags = UnRep_Fail
00310 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00311 );
00312
00313 XMLFormatter
00314 (
00315 const char* const outEncoding
00316 , const char* const docVersion
00317 , XMLFormatTarget* const target
00318 , const EscapeFlags escapeFlags = NoEscapes
00319 , const UnRepFlags unrepFlags = UnRep_Fail
00320 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00321 );
00322
00323 XMLFormatter
00324 (
00325 const XMLCh* const outEncoding
00326 , XMLFormatTarget* const target
00327 , const EscapeFlags escapeFlags = NoEscapes
00328 , const UnRepFlags unrepFlags = UnRep_Fail
00329 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00330 );
00331
00332 XMLFormatter
00333 (
00334 const char* const outEncoding
00335 , XMLFormatTarget* const target
00336 , const EscapeFlags escapeFlags = NoEscapes
00337 , const UnRepFlags unrepFlags = UnRep_Fail
00338 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00339 );
00340
00341 ~XMLFormatter();
00343
00344
00345
00346
00347
00357 void formatBuf
00358 (
00359 const XMLCh* const toFormat
00360 , const unsigned int count
00361 , const EscapeFlags escapeFlags = DefaultEscape
00362 , const UnRepFlags unrepFlags = DefaultUnRep
00363 );
00364
00368 XMLFormatter& operator<<
00369 (
00370 const XMLCh* const toFormat
00371 );
00372
00373 XMLFormatter& operator<<
00374 (
00375 const XMLCh toFormat
00376 );
00377
00378 void writeBOM(const XMLByte* const toFormat
00379 , const unsigned int count);
00380
00382
00383
00384
00385
00392 const XMLCh* getEncodingName() const;
00393
00397 inline const XMLTranscoder* getTranscoder() const;
00398
00400
00401
00402
00403
00409 void setEscapeFlags
00410 (
00411 const EscapeFlags newFlags
00412 );
00413
00417 void setUnRepFlags
00418 (
00419 const UnRepFlags newFlags
00420 );
00421
00426 XMLFormatter& operator<<
00427 (
00428 const EscapeFlags newFlags
00429 );
00430
00435 XMLFormatter& operator<<
00436 (
00437 const UnRepFlags newFlags
00438 );
00440
00441
00442 private :
00443
00444
00445
00446 XMLFormatter();
00447 XMLFormatter(const XMLFormatter&);
00448 XMLFormatter& operator=(const XMLFormatter&);
00449
00450
00451
00452
00453
00454 enum Constants
00455 {
00456 kTmpBufSize = 16 * 1024
00457 };
00458
00459
00460
00461
00462
00463 const XMLByte* getCharRef(unsigned int & count,
00464 XMLByte* &ref,
00465 const XMLCh * stdRef);
00466
00467 void writeCharRef(const XMLCh &toWrite);
00468 void writeCharRef(unsigned long toWrite);
00469
00470 bool inEscapeList(const XMLFormatter::EscapeFlags escStyle
00471 , const XMLCh toCheck);
00472
00473
00474 unsigned int handleUnEscapedChars(const XMLCh * srcPtr,
00475 const unsigned int count,
00476 const UnRepFlags unrepFlags);
00477
00478 void specialFormat
00479 (
00480 const XMLCh* const toFormat
00481 , const unsigned int count
00482 , const EscapeFlags escapeFlags
00483 );
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527 EscapeFlags fEscapeFlags;
00528 XMLCh* fOutEncoding;
00529 XMLFormatTarget* fTarget;
00530 UnRepFlags fUnRepFlags;
00531 XMLTranscoder* fXCoder;
00532 XMLByte fTmpBuf[kTmpBufSize + 4];
00533 XMLByte* fAposRef;
00534 unsigned int fAposLen;
00535 XMLByte* fAmpRef;
00536 unsigned int fAmpLen;
00537 XMLByte* fGTRef;
00538 unsigned int fGTLen;
00539 XMLByte* fLTRef;
00540 unsigned int fLTLen;
00541 XMLByte* fQuoteRef;
00542 unsigned int fQuoteLen;
00543 bool fIsXML11;
00544 MemoryManager* fMemoryManager;
00545 };
00546
00547
00548 class XMLFormatTarget : public XMemory
00549 {
00550 public:
00551
00552
00553
00554 virtual ~XMLFormatTarget() {}
00555
00556
00557
00558
00559
00560 virtual void writeChars
00561 (
00562 const XMLByte* const toWrite
00563 , const unsigned int count
00564 , XMLFormatter* const formatter
00565 ) = 0;
00566
00567 virtual void flush() {};
00568
00569
00570 protected :
00571
00572
00573
00574 XMLFormatTarget() {}
00575 XMLFormatTarget(const XMLFormatTarget&) {}
00576 void operator=(const XMLFormatTarget&) {}
00577 };
00578
00579
00580
00581
00582
00583 inline const XMLCh* XMLFormatter::getEncodingName() const
00584 {
00585 return fOutEncoding;
00586 }
00587
00588 inline const XMLTranscoder* XMLFormatter::getTranscoder() const
00589 {
00590 return fXCoder;
00591 }
00592
00593
00594
00595
00596 inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags)
00597 {
00598 fEscapeFlags = newFlags;
00599 }
00600
00601 inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags)
00602 {
00603 fUnRepFlags = newFlags;
00604 }
00605
00606
00607 inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags)
00608 {
00609 fEscapeFlags = newFlags;
00610 return *this;
00611 }
00612
00613 inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags)
00614 {
00615 fUnRepFlags = newFlags;
00616 return *this;
00617 }
00618
00619 XERCES_CPP_NAMESPACE_END
00620
00621 #endif