00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(FORMATTERTOXML_UTF8_HEADER_GUARD_1357924680) 00017 #define FORMATTERTOXML_UTF8_HEADER_GUARD_1357924680 00018 00019 00020 00021 00022 // Base include file. Must be first. 00023 #include <xalanc/XMLSupport/XMLSupportDefinitions.hpp> 00024 00025 00026 00027 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00028 00029 00030 00031 // Base class header file. 00032 #include "FormatterToXMLBase.hpp" 00033 00034 00035 00036 XALAN_CPP_NAMESPACE_BEGIN 00037 00038 00039 00043 class XALAN_XMLSUPPORT_EXPORT FormatterToXML_UTF8 : public FormatterToXMLBase 00044 { 00045 public: 00046 00050 static void 00051 initialize(); 00052 00056 static void 00057 terminate(); 00058 00074 FormatterToXML_UTF8( 00075 Writer& writer, 00076 const XalanDOMString& version = XalanDOMString(), 00077 const XalanDOMString& mediaType = XalanDOMString(), 00078 const XalanDOMString& doctypeSystem = XalanDOMString(), 00079 const XalanDOMString& doctypePublic = XalanDOMString(), 00080 bool xmlDecl = true, 00081 const XalanDOMString& standalone = XalanDOMString()); 00082 00083 virtual 00084 ~FormatterToXML_UTF8(); 00085 00086 00087 // These methods are inherited from FormatterListener ... 00088 00089 virtual void 00090 startElement( 00091 const XMLCh* const name, 00092 AttributeListType& attrs); 00093 00094 virtual void 00095 endElement(const XMLCh* const name); 00096 00097 virtual void 00098 charactersRaw( 00099 const XMLCh* const chars, 00100 const unsigned int length); 00101 00102 virtual void 00103 entityReference(const XMLCh* const name); 00104 00105 virtual void 00106 comment(const XMLCh* const data); 00107 00108 virtual const XalanDOMString& 00109 getEncoding() const; 00110 00111 protected: 00112 00113 virtual void 00114 writeXMLHeader(); 00115 00116 virtual void 00117 flushBuffer(); 00118 00119 virtual void 00120 writeDoctypeDecl(const XalanDOMChar* name); 00121 00122 virtual void 00123 writeProcessingInstruction( 00124 const XMLCh* target, 00125 const XMLCh* data); 00126 00127 virtual void 00128 writeCharacters( 00129 const XMLCh* chars, 00130 unsigned int length); 00131 00132 virtual void 00133 writeCDATA( 00134 const XMLCh* chars, 00135 unsigned int length); 00136 00140 virtual void 00141 outputNewline(); 00142 00146 XalanDOMString::size_type 00147 writeDefaultEscape( 00148 XalanDOMChar ch, 00149 XalanDOMString::size_type i, 00150 const XalanDOMChar chars[], 00151 XalanDOMString::size_type len); 00152 00156 XalanDOMString::size_type 00157 writeDefaultAttributeEscape( 00158 XalanDOMChar ch, 00159 XalanDOMString::size_type i, 00160 const XalanDOMChar chars[], 00161 XalanDOMString::size_type len); 00162 00167 bool 00168 writeDefaultEntity(XalanDOMChar ch); 00169 00174 bool 00175 writeDefaultAttributeEntity(XalanDOMChar ch); 00176 00181 void 00182 writeCommentData(const XalanDOMChar* data); 00183 00188 void 00189 writeParentTagEnd(); 00190 00197 XalanDOMString::size_type 00198 writeNormalizedChar( 00199 XalanDOMChar ch, 00200 const XalanDOMChar chars[], 00201 XalanDOMString::size_type start, 00202 XalanDOMString::size_type length); 00203 00210 void 00211 writeCDATAChars( 00212 const XalanDOMChar ch[], 00213 XalanDOMString::size_type length); 00214 00221 void 00222 writeAttrString( 00223 const XalanDOMChar* theString, 00224 XalanDOMString::size_type theStringLength); 00225 00226 private: 00227 00228 // These are not implemented. 00229 FormatterToXML_UTF8(const FormatterToXML_UTF8&); 00230 00231 FormatterToXML_UTF8& 00232 operator=(const FormatterToXML_UTF8&); 00233 00234 bool 00235 operator==(const FormatterToXML_UTF8&) const; 00236 00237 void 00238 safeWriteContent( 00239 const XalanDOMChar* theChars, 00240 XalanDOMString::size_type theLength); 00241 00242 void 00243 write( 00244 const XalanDOMChar* theChars, 00245 XalanDOMString::size_type theLength); 00246 00247 void 00248 writeName1_0(const XalanDOMChar* theChars); 00249 00250 void 00251 writeName1_1(const XalanDOMChar* theChars); 00252 00253 void 00254 write(const XalanDOMChar* theChars) 00255 { 00256 write(theChars, XalanDOMString::length(theChars)); 00257 } 00258 00259 void 00260 write(XalanDOMChar theChar) 00261 { 00262 write((unsigned int)theChar); 00263 } 00264 00265 void 00266 write(unsigned int theChar); 00267 00268 void 00269 write(const XalanDOMString& theChars) 00270 { 00271 write(theChars.c_str(), theChars.length()); 00272 } 00273 00274 void 00275 write(char theChar); 00276 00277 void 00278 write( 00279 const char* theChars, 00280 XalanDOMString::size_type theLength); 00281 00282 void 00283 write(const char* theChars) 00284 { 00285 write(theChars, XalanDOMString::length(theChars)); 00286 } 00287 00293 void 00294 processAttribute( 00295 const XalanDOMChar* name, 00296 const XalanDOMChar* value); 00297 00303 void 00304 writeNormalizedPIData( 00305 const XalanDOMChar* theData, 00306 XalanDOMString::size_type theLength); 00307 00308 // Data members... 00312 static const XalanDOMString& s_utf8String; 00313 00317 static const char s_doctypeHeaderStartString[]; 00318 00319 static const XalanDOMString::size_type s_doctypeHeaderStartStringLength; 00320 00324 static const char s_doctypeHeaderPublicString[]; 00325 00326 static const XalanDOMString::size_type s_doctypeHeaderPublicStringLength; 00327 00331 static const char s_doctypeHeaderSystemString[]; 00332 00333 static const XalanDOMString::size_type s_doctypeHeaderSystemStringLength; 00334 00338 static const char s_xmlHeaderStartString[]; 00339 00340 static const XalanDOMString::size_type s_xmlHeaderStartStringLength; 00341 00345 static const char s_xmlHeaderEncodingString[]; 00346 00347 static const XalanDOMString::size_type s_xmlHeaderEncodingStringLength; 00348 00352 static const char s_xmlHeaderStandaloneString[]; 00353 00354 static const XalanDOMString::size_type s_xmlHeaderStandaloneStringLength; 00355 00359 static const char s_xmlHeaderEndString[]; 00360 00361 static const XalanDOMString::size_type s_xmlHeaderEndStringLength; 00362 00366 static const char s_defaultVersionString[]; 00367 00368 static const XalanDOMString::size_type s_defaultVersionStringLength; 00369 00373 static const XalanDOMChar s_xhtmlDocTypeString[]; 00374 00375 static const XalanDOMString::size_type s_xhtmlDocTypeStringLength; 00376 00380 static const char s_cdataOpenString[]; 00381 00382 static const XalanDOMString::size_type s_cdataOpenStringLength; 00383 00387 static const char s_cdataCloseString[]; 00388 00389 static const XalanDOMString::size_type s_cdataCloseStringLength; 00390 00394 static const char s_lessThanEntityString[]; 00395 00396 static const XalanDOMString::size_type s_lessThanEntityStringLength; 00397 00401 static const char s_greaterThanEntityString[]; 00402 00403 static const XalanDOMString::size_type s_greaterThanEntityStringLength; 00404 00408 static const char s_ampersandEntityString[]; 00409 00410 static const XalanDOMString::size_type s_ampersandEntityStringLength; 00411 00415 static const char s_quoteEntityString[]; 00416 00417 static const XalanDOMString::size_type s_quoteEntityStringLength; 00418 00422 static const char s_linefeedNCRString[]; 00423 00424 static const XalanDOMString::size_type s_linefeedNCRStringLength; 00425 00429 static const char s_carriageReturnNCRString[]; 00430 00431 static const XalanDOMString::size_type s_carriageReturnNCRStringLength; 00432 00436 static const char s_htabNCRString[]; 00437 00438 static const XalanDOMString::size_type s_htabNCRStringLength; 00439 00440 00441 typedef void (FormatterToXML_UTF8::*NameFunctionType)(const XalanDOMChar*); 00442 00443 NameFunctionType m_nameFunction; 00444 00445 void 00446 writeName(const XalanDOMChar* theChars) 00447 { 00448 assert(m_nameFunction != 0); 00449 00450 (this->*m_nameFunction)(theChars); 00451 } 00452 00453 enum 00454 { 00455 kBufferSize = 512 // The size of the buffer 00456 }; 00457 00458 static bool 00459 isContentSpecial(XalanDOMChar theChar) 00460 { 00461 if ((theChar >= kSpecialsSize) || (s_specialChars[theChar] & kContentSpecial)) 00462 { 00463 return true; 00464 } 00465 else 00466 { 00467 return false; 00468 } 00469 } 00470 00471 static bool 00472 isAttributeSpecial(XalanDOMChar theChar) 00473 { 00474 if ((theChar >= kSpecialsSize) || (s_specialChars[theChar] & kAttributeSpecial)) 00475 { 00476 return true; 00477 } 00478 else 00479 { 00480 return false; 00481 } 00482 } 00483 00484 char m_buffer[kBufferSize]; 00485 00486 char* m_bufferPosition; 00487 00488 XalanDOMString::size_type m_bufferRemaining; 00489 }; 00490 00491 00492 00493 XALAN_CPP_NAMESPACE_END 00494 00495 00496 00497 #endif // FORMATTERTOXML_UTF8_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.8 |
|