00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * Copyright (c) 1999-2000 The Apache Software Foundation. All rights 00005 * reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * 3. The end-user documentation included with the redistribution, 00020 * if any, must include the following acknowledgment: 00021 * "This product includes software developed by the 00022 * Apache Software Foundation (http://www.apache.org/)." 00023 * Alternately, this acknowledgment may appear in the software itself, 00024 * if and wherever such third-party acknowledgments normally appear. 00025 * 00026 * 4. The names "Xerces" and "Apache Software Foundation" must 00027 * not be used to endorse or promote products derived from this 00028 * software without prior written permission. For written 00029 * permission, please contact apache\@apache.org. 00030 * 00031 * 5. Products derived from this software may not be called "Apache", 00032 * nor may "Apache" appear in their name, without prior written 00033 * permission of the Apache Software Foundation. 00034 * 00035 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00036 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00037 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00038 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00039 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00040 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00041 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00042 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00043 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00044 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00045 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00046 * SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Apache Software Foundation, and was 00051 * originally based on software copyright (c) 1999, International 00052 * Business Machines, Inc., http://www.ibm.com . For more information 00053 * on the Apache Software Foundation, please see 00054 * <http://www.apache.org/>. 00055 */ 00056 00057 /* 00058 * $Log: XMLFormatter.hpp,v $ 00059 * Revision 1.1 2002/05/11 20:03:18 bhavani 00060 * CR#CR062582# adding xercesc 1.7 file 00061 * 00062 * Revision 1.1.1.1 2002/02/01 22:21:52 peiyongz 00063 * sane_include 00064 * 00065 * Revision 1.7 2000/10/17 19:25:38 andyh 00066 * XMLFormatTarget, removed version of writeChars with no length. Can not be 00067 * safely used, and obscured other errors. 00068 * 00069 * Revision 1.6 2000/10/10 23:54:58 andyh 00070 * XMLFormatter patch, contributed by Bill Schindler. Fix problems with 00071 * output to multi-byte encodings. 00072 * 00073 * Revision 1.5 2000/04/07 01:01:56 roddey 00074 * Fixed an error message so that it indicated the correct radix for the rep 00075 * token. Get all of the basic output formatting functionality in place for 00076 * at least ICU and Win32 transcoders. 00077 * 00078 * Revision 1.4 2000/04/06 23:50:38 roddey 00079 * Now the low level formatter handles doing char refs for 00080 * unrepresentable chars (in addition to the replacement char style 00081 * already done.) 00082 * 00083 * Revision 1.3 2000/04/06 19:09:21 roddey 00084 * Some more improvements to output formatting. Now it will correctly 00085 * handle doing the 'replacement char' style of dealing with chars 00086 * that are unrepresentable. 00087 * 00088 * Revision 1.2 2000/04/05 00:20:16 roddey 00089 * More updates for the low level formatted output support 00090 * 00091 * Revision 1.1 2000/03/28 19:43:17 roddey 00092 * Fixes for signed/unsigned warnings. New work for two way transcoding 00093 * stuff. 00094 * 00095 */ 00096 00097 #if !defined(XMLFORMATTER_HPP) 00098 #define XMLFORMATTER_HPP 00099 00100 #include <xercesc/util/XercesDefs.hpp> 00101 00102 class XMLFormatTarget; 00103 class XMLTranscoder; 00104 00114 class XMLPARSER_EXPORT XMLFormatter 00115 { 00116 public: 00117 // ----------------------------------------------------------------------- 00118 // Class types 00119 // ----------------------------------------------------------------------- 00120 enum EscapeFlags 00121 { 00122 NoEscapes 00123 , StdEscapes 00124 , AttrEscapes 00125 , CharEscapes 00126 00127 // Special values, don't use directly 00128 , EscapeFlags_Count 00129 , DefaultEscape = 999 00130 }; 00131 00132 enum UnRepFlags 00133 { 00134 UnRep_Fail 00135 , UnRep_CharRef 00136 , UnRep_Replace 00137 00138 , DefaultUnRep = 999 00139 }; 00140 00141 00142 // ----------------------------------------------------------------------- 00143 // Constructors and Destructor 00144 // ----------------------------------------------------------------------- 00145 XMLFormatter 00146 ( 00147 const XMLCh* const outEncoding 00148 , XMLFormatTarget* const target 00149 , const EscapeFlags escapeFlags = NoEscapes 00150 , const UnRepFlags unrepFlags = UnRep_Fail 00151 ); 00152 00153 XMLFormatter 00154 ( 00155 const char* const outEncoding 00156 , XMLFormatTarget* const target 00157 , const EscapeFlags escapeFlags = NoEscapes 00158 , const UnRepFlags unrepFlags = UnRep_Fail 00159 ); 00160 00161 ~XMLFormatter(); 00162 00163 00164 // ----------------------------------------------------------------------- 00165 // Formatting methods 00166 // ----------------------------------------------------------------------- 00167 void formatBuf 00168 ( 00169 const XMLCh* const toFormat 00170 , const unsigned int count 00171 , const EscapeFlags escapeFlags = DefaultEscape 00172 , const UnRepFlags unrepFlags = DefaultUnRep 00173 ); 00174 00175 XMLFormatter& operator<< 00176 ( 00177 const XMLCh* const toFormat 00178 ); 00179 00180 XMLFormatter& operator<< 00181 ( 00182 const XMLCh toFormat 00183 ); 00184 00185 00186 // ----------------------------------------------------------------------- 00187 // Getter methods 00188 // ----------------------------------------------------------------------- 00189 const XMLCh* getEncodingName() const; 00190 00191 00192 // ----------------------------------------------------------------------- 00193 // Setter methods 00194 // ----------------------------------------------------------------------- 00195 void setEscapeFlags 00196 ( 00197 const EscapeFlags newFlags 00198 ); 00199 00200 void setUnRepFlags 00201 ( 00202 const UnRepFlags newFlags 00203 ); 00204 00205 XMLFormatter& operator<< 00206 ( 00207 const EscapeFlags newFlags 00208 ); 00209 00210 XMLFormatter& operator<< 00211 ( 00212 const UnRepFlags newFlags 00213 ); 00214 00215 00216 private : 00217 // ----------------------------------------------------------------------- 00218 // Unimplemented constructors and operators 00219 // ----------------------------------------------------------------------- 00220 XMLFormatter(); 00221 XMLFormatter(const XMLFormatter&); 00222 void operator=(const XMLFormatter&); 00223 00224 00225 // ----------------------------------------------------------------------- 00226 // Private class constants 00227 // ----------------------------------------------------------------------- 00228 enum Constants 00229 { 00230 kTmpBufSize = 16 * 1024 00231 }; 00232 00233 00234 // ----------------------------------------------------------------------- 00235 // Private helper methods 00236 // ----------------------------------------------------------------------- 00237 const XMLByte* getAposRef(unsigned int & count); 00238 const XMLByte* getAmpRef(unsigned int & count); 00239 const XMLByte* getGTRef(unsigned int & count); 00240 const XMLByte* getLTRef(unsigned int & count); 00241 const XMLByte* getQuoteRef(unsigned int & count); 00242 00243 void specialFormat 00244 ( 00245 const XMLCh* const toFormat 00246 , const unsigned int count 00247 , const EscapeFlags escapeFlags 00248 ); 00249 00250 00251 // ----------------------------------------------------------------------- 00252 // Private, non-virtual methods 00253 // 00254 // fEscapeFlags 00255 // The escape flags we were told to use in formatting. These are 00256 // defaults set in the ctor, which can be overridden on a particular 00257 // call. 00258 // 00259 // fOutEncoding 00260 // This the name of the output encoding. Saved mainly for meaningful 00261 // error messages. 00262 // 00263 // fTarget 00264 // This is the target object for the formatting operation. 00265 // 00266 // fUnRepFlags 00267 // The unrepresentable flags that indicate how to react when a 00268 // character cannot be represented in the target encoding. 00269 // 00270 // fXCoder 00271 // This the transcoder that we will use. It is created using the 00272 // encoding name we were told to use. 00273 // 00274 // fTmpBuf 00275 // An output buffer that we use to transcode chars into before we 00276 // send them off to be output. 00277 // 00278 // fAposRef 00279 // fAmpRef 00280 // fGTRef 00281 // fLTRef 00282 // fQuoteRef 00283 // These are character refs for the standard char refs, in the 00284 // output encoding. They are faulted in as required, by transcoding 00285 // them from fixed Unicode versions. 00286 // ----------------------------------------------------------------------- 00287 EscapeFlags fEscapeFlags; 00288 XMLCh* fOutEncoding; 00289 XMLFormatTarget* fTarget; 00290 UnRepFlags fUnRepFlags; 00291 XMLTranscoder* fXCoder; 00292 XMLByte fTmpBuf[kTmpBufSize + 4]; 00293 00294 XMLByte* fAposRef; 00295 unsigned int fAposLen; 00296 XMLByte* fAmpRef; 00297 unsigned int fAmpLen; 00298 XMLByte* fGTRef; 00299 unsigned int fGTLen; 00300 XMLByte* fLTRef; 00301 unsigned int fLTLen; 00302 XMLByte* fQuoteRef; 00303 unsigned int fQuoteLen; 00304 }; 00305 00306 00307 class XMLPARSER_EXPORT XMLFormatTarget 00308 { 00309 public: 00310 // ----------------------------------------------------------------------- 00311 // Constructors and Destructor 00312 // ----------------------------------------------------------------------- 00313 virtual ~XMLFormatTarget() {} 00314 00315 00316 // ----------------------------------------------------------------------- 00317 // Virtual interface 00318 // ----------------------------------------------------------------------- 00319 virtual void writeChars 00320 ( 00321 const XMLByte* const toWrite 00322 , const unsigned int count 00323 , XMLFormatter* const formatter 00324 ) = 0; 00325 00326 00327 protected : 00328 // ----------------------------------------------------------------------- 00329 // Hidden constructors and operators 00330 // ----------------------------------------------------------------------- 00331 XMLFormatTarget() {} 00332 XMLFormatTarget(const XMLFormatTarget&) {} 00333 void operator=(const XMLFormatTarget&) {} 00334 }; 00335 00336 00337 // --------------------------------------------------------------------------- 00338 // XMLFormatter: Getter methods 00339 // --------------------------------------------------------------------------- 00340 inline const XMLCh* XMLFormatter::getEncodingName() const 00341 { 00342 return fOutEncoding; 00343 } 00344 00345 00346 // --------------------------------------------------------------------------- 00347 // XMLFormatter: Setter methods 00348 // --------------------------------------------------------------------------- 00349 inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags) 00350 { 00351 fEscapeFlags = newFlags; 00352 } 00353 00354 inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags) 00355 { 00356 fUnRepFlags = newFlags; 00357 } 00358 00359 00360 inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags) 00361 { 00362 fEscapeFlags = newFlags; 00363 return *this; 00364 } 00365 00366 inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags) 00367 { 00368 fUnRepFlags = newFlags; 00369 return *this; 00370 } 00371 00372 00373 #endif