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 #if !defined(XMLFORMATTER_HPP)
00095 #define XMLFORMATTER_HPP
00096
00097 #include <xercesc/util/XercesDefs.hpp>
00098
00099 class XMLFormatTarget;
00100 class XMLTranscoder;
00101
00111 class XMLFormatter
00112 {
00113 public:
00114
00115
00116
00117 enum EscapeFlags
00118 {
00119 NoEscapes
00120 , StdEscapes
00121 , AttrEscapes
00122 , CharEscapes
00123
00124
00125 , EscapeFlags_Count
00126 , DefaultEscape = 999
00127 };
00128
00129 enum UnRepFlags
00130 {
00131 UnRep_Fail
00132 , UnRep_CharRef
00133 , UnRep_Replace
00134
00135 , DefaultUnRep = 999
00136 };
00137
00138
00139
00140
00141
00142 XMLFormatter
00143 (
00144 const XMLCh* const outEncoding
00145 , XMLFormatTarget* const target
00146 , const EscapeFlags escapeFlags = NoEscapes
00147 , const UnRepFlags unrepFlags = UnRep_Fail
00148 );
00149
00150 XMLFormatter
00151 (
00152 const char* const outEncoding
00153 , XMLFormatTarget* const target
00154 , const EscapeFlags escapeFlags = NoEscapes
00155 , const UnRepFlags unrepFlags = UnRep_Fail
00156 );
00157
00158 ~XMLFormatter();
00159
00160
00161
00162
00163
00164 void formatBuf
00165 (
00166 const XMLCh* const toFormat
00167 , const unsigned int count
00168 , const EscapeFlags escapeFlags = DefaultEscape
00169 , const UnRepFlags unrepFlags = DefaultUnRep
00170 );
00171
00172 XMLFormatter& operator<<
00173 (
00174 const XMLCh* const toFormat
00175 );
00176
00177 XMLFormatter& operator<<
00178 (
00179 const XMLCh toFormat
00180 );
00181
00182
00183
00184
00185
00186 const XMLCh* getEncodingName() const;
00187
00188
00189
00190
00191
00192 void setEscapeFlags
00193 (
00194 const EscapeFlags newFlags
00195 );
00196
00197 void setUnRepFlags
00198 (
00199 const UnRepFlags newFlags
00200 );
00201
00202 XMLFormatter& operator<<
00203 (
00204 const EscapeFlags newFlags
00205 );
00206
00207 XMLFormatter& operator<<
00208 (
00209 const UnRepFlags newFlags
00210 );
00211
00212
00213 private :
00214
00215
00216
00217 XMLFormatter();
00218 XMLFormatter(const XMLFormatter&);
00219 void operator=(const XMLFormatter&);
00220
00221
00222
00223
00224
00225 enum Constants
00226 {
00227 kTmpBufSize = 16 * 1024
00228 };
00229
00230
00231
00232
00233
00234 const XMLByte* getAposRef(unsigned int & count);
00235 const XMLByte* getAmpRef(unsigned int & count);
00236 const XMLByte* getGTRef(unsigned int & count);
00237 const XMLByte* getLTRef(unsigned int & count);
00238 const XMLByte* getQuoteRef(unsigned int & count);
00239
00240 void specialFormat
00241 (
00242 const XMLCh* const toFormat
00243 , const unsigned int count
00244 , const EscapeFlags escapeFlags
00245 );
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 EscapeFlags fEscapeFlags;
00285 XMLCh* fOutEncoding;
00286 XMLFormatTarget* fTarget;
00287 UnRepFlags fUnRepFlags;
00288 XMLTranscoder* fXCoder;
00289 XMLByte fTmpBuf[kTmpBufSize + 4];
00290
00291 XMLByte* fAposRef;
00292 unsigned int fAposLen;
00293 XMLByte* fAmpRef;
00294 unsigned int fAmpLen;
00295 XMLByte* fGTRef;
00296 unsigned int fGTLen;
00297 XMLByte* fLTRef;
00298 unsigned int fLTLen;
00299 XMLByte* fQuoteRef;
00300 unsigned int fQuoteLen;
00301 };
00302
00303
00304 class XMLFormatTarget
00305 {
00306 public:
00307
00308
00309
00310 virtual ~XMLFormatTarget() {}
00311
00312
00313
00314
00315
00316 virtual void writeChars
00317 (
00318 const XMLByte* const toWrite
00319 , const unsigned int count
00320 , XMLFormatter* const formatter
00321 ) = 0;
00322
00323
00324 protected :
00325
00326
00327
00328 XMLFormatTarget() {}
00329 XMLFormatTarget(const XMLFormatTarget&) {}
00330 void operator=(const XMLFormatTarget&) {}
00331 };
00332
00333
00334
00335
00336
00337 inline const XMLCh* XMLFormatter::getEncodingName() const
00338 {
00339 return fOutEncoding;
00340 }
00341
00342
00343
00344
00345
00346 inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags)
00347 {
00348 fEscapeFlags = newFlags;
00349 }
00350
00351 inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags)
00352 {
00353 fUnRepFlags = newFlags;
00354 }
00355
00356
00357 inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags)
00358 {
00359 fEscapeFlags = newFlags;
00360 return *this;
00361 }
00362
00363 inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags)
00364 {
00365 fUnRepFlags = newFlags;
00366 return *this;
00367 }
00368
00369
00370 #endif