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