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
00149
00150
00151 #if !defined(XMLFORMATTER_HPP)
00152 #define XMLFORMATTER_HPP
00153
00154 #include <xercesc/util/PlatformUtils.hpp>
00155
00156 XERCES_CPP_NAMESPACE_BEGIN
00157
00158 class XMLFormatTarget;
00159 class XMLTranscoder;
00160
00170 class XMLFormatter : public XMemory
00171 {
00172 public:
00173
00174
00175
00253 enum EscapeFlags
00254 {
00255 NoEscapes
00256 , StdEscapes
00257 , AttrEscapes
00258 , CharEscapes
00259
00260
00261 , EscapeFlags_Count
00262 , DefaultEscape = 999
00263 };
00264
00281 enum UnRepFlags
00282 {
00283 UnRep_Fail
00284 , UnRep_CharRef
00285 , UnRep_Replace
00286
00287 , DefaultUnRep = 999
00288 };
00290
00291
00292
00293
00294
00306 XMLFormatter
00307 (
00308 const XMLCh* const outEncoding
00309 , const XMLCh* const docVersion
00310 , XMLFormatTarget* const target
00311 , const EscapeFlags escapeFlags = NoEscapes
00312 , const UnRepFlags unrepFlags = UnRep_Fail
00313 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00314 );
00315
00316 XMLFormatter
00317 (
00318 const char* const outEncoding
00319 , const char* const docVersion
00320 , XMLFormatTarget* const target
00321 , const EscapeFlags escapeFlags = NoEscapes
00322 , const UnRepFlags unrepFlags = UnRep_Fail
00323 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00324 );
00325
00326 XMLFormatter
00327 (
00328 const XMLCh* const outEncoding
00329 , XMLFormatTarget* const target
00330 , const EscapeFlags escapeFlags = NoEscapes
00331 , const UnRepFlags unrepFlags = UnRep_Fail
00332 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00333 );
00334
00335 XMLFormatter
00336 (
00337 const char* const outEncoding
00338 , XMLFormatTarget* const target
00339 , const EscapeFlags escapeFlags = NoEscapes
00340 , const UnRepFlags unrepFlags = UnRep_Fail
00341 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00342 );
00343
00344 ~XMLFormatter();
00346
00347
00348
00349
00350
00360 void formatBuf
00361 (
00362 const XMLCh* const toFormat
00363 , const unsigned int count
00364 , const EscapeFlags escapeFlags = DefaultEscape
00365 , const UnRepFlags unrepFlags = DefaultUnRep
00366 );
00367
00371 XMLFormatter& operator<<
00372 (
00373 const XMLCh* const toFormat
00374 );
00375
00376 XMLFormatter& operator<<
00377 (
00378 const XMLCh toFormat
00379 );
00380
00381 void writeBOM(const XMLByte* const toFormat
00382 , const unsigned int count);
00383
00385
00386
00387
00388
00395 const XMLCh* getEncodingName() const;
00396
00400 inline const XMLTranscoder* getTranscoder() const;
00401
00403
00404
00405
00406
00412 void setEscapeFlags
00413 (
00414 const EscapeFlags newFlags
00415 );
00416
00420 void setUnRepFlags
00421 (
00422 const UnRepFlags newFlags
00423 );
00424
00429 XMLFormatter& operator<<
00430 (
00431 const EscapeFlags newFlags
00432 );
00433
00438 XMLFormatter& operator<<
00439 (
00440 const UnRepFlags newFlags
00441 );
00443
00444
00445 private :
00446
00447
00448
00449 XMLFormatter();
00450 XMLFormatter(const XMLFormatter&);
00451 XMLFormatter& operator=(const XMLFormatter&);
00452
00453
00454
00455
00456
00457 enum Constants
00458 {
00459 kTmpBufSize = 16 * 1024
00460 };
00461
00462
00463
00464
00465
00466 const XMLByte* getCharRef(unsigned int & count,
00467 XMLByte* &ref,
00468 const XMLCh * stdRef);
00469
00470 void writeCharRef(const XMLCh &toWrite);
00471 void writeCharRef(unsigned long toWrite);
00472
00473 bool inEscapeList(const XMLFormatter::EscapeFlags escStyle
00474 , const XMLCh toCheck);
00475
00476
00477 unsigned int handleUnEscapedChars(const XMLCh * srcPtr,
00478 const unsigned int count,
00479 const UnRepFlags unrepFlags);
00480
00481 void specialFormat
00482 (
00483 const XMLCh* const toFormat
00484 , const unsigned int count
00485 , const EscapeFlags escapeFlags
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
00528
00529
00530 EscapeFlags fEscapeFlags;
00531 XMLCh* fOutEncoding;
00532 XMLFormatTarget* fTarget;
00533 UnRepFlags fUnRepFlags;
00534 XMLTranscoder* fXCoder;
00535 XMLByte fTmpBuf[kTmpBufSize + 4];
00536 XMLByte* fAposRef;
00537 unsigned int fAposLen;
00538 XMLByte* fAmpRef;
00539 unsigned int fAmpLen;
00540 XMLByte* fGTRef;
00541 unsigned int fGTLen;
00542 XMLByte* fLTRef;
00543 unsigned int fLTLen;
00544 XMLByte* fQuoteRef;
00545 unsigned int fQuoteLen;
00546 bool fIsXML11;
00547 MemoryManager* fMemoryManager;
00548 };
00549
00550
00551 class XMLFormatTarget : public XMemory
00552 {
00553 public:
00554
00555
00556
00557 virtual ~XMLFormatTarget() {}
00558
00559
00560
00561
00562
00563 virtual void writeChars
00564 (
00565 const XMLByte* const toWrite
00566 , const unsigned int count
00567 , XMLFormatter* const formatter
00568 ) = 0;
00569
00570 virtual void flush() {};
00571
00572
00573 protected :
00574
00575
00576
00577 XMLFormatTarget() {};
00578
00579 private:
00580
00581
00582
00583 XMLFormatTarget(const XMLFormatTarget&);
00584 XMLFormatTarget& operator=(const XMLFormatTarget&);
00585 };
00586
00587
00588
00589
00590
00591 inline const XMLCh* XMLFormatter::getEncodingName() const
00592 {
00593 return fOutEncoding;
00594 }
00595
00596 inline const XMLTranscoder* XMLFormatter::getTranscoder() const
00597 {
00598 return fXCoder;
00599 }
00600
00601
00602
00603
00604 inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags)
00605 {
00606 fEscapeFlags = newFlags;
00607 }
00608
00609 inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags)
00610 {
00611 fUnRepFlags = newFlags;
00612 }
00613
00614
00615 inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags)
00616 {
00617 fEscapeFlags = newFlags;
00618 return *this;
00619 }
00620
00621 inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags)
00622 {
00623 fUnRepFlags = newFlags;
00624 return *this;
00625 }
00626
00627 XERCES_CPP_NAMESPACE_END
00628
00629 #endif