00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 */ 00057 #if !defined(FORMATTERTOXML_UTF8_HEADER_GUARD_1357924680) 00058 #define FORMATTERTOXML_UTF8_HEADER_GUARD_1357924680 00059 00060 00061 00062 00063 // Base include file. Must be first. 00064 #include <xalanc/XMLSupport/XMLSupportDefinitions.hpp> 00065 00066 00067 00068 #include <vector> 00069 00070 00071 00072 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00073 00074 00075 00076 // Base class header file. 00077 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00078 00079 00080 00081 XALAN_CPP_NAMESPACE_BEGIN 00082 00083 00084 00085 class Writer; 00086 00087 00088 00092 class XALAN_XMLSUPPORT_EXPORT FormatterToXML_UTF8 : public FormatterListener 00093 { 00094 public: 00095 00099 static void 00100 initialize(); 00101 00105 static void 00106 terminate(); 00107 00123 FormatterToXML_UTF8( 00124 Writer& writer, 00125 const XalanDOMString& version = XalanDOMString(), 00126 const XalanDOMString& mediaType = XalanDOMString(), 00127 const XalanDOMString& doctypeSystem = XalanDOMString(), 00128 const XalanDOMString& doctypePublic = XalanDOMString(), 00129 bool xmlDecl = true, 00130 const XalanDOMString& standalone = XalanDOMString()); 00131 00132 virtual 00133 ~FormatterToXML_UTF8(); 00134 00135 00136 // These methods are inherited from FormatterListener ... 00137 00138 virtual void 00139 setDocumentLocator(const LocatorType* const locator); 00140 00141 virtual void 00142 startDocument(); 00143 00144 virtual void 00145 endDocument(); 00146 00147 virtual void 00148 startElement( 00149 const XMLCh* const name, 00150 AttributeListType& attrs); 00151 00152 virtual void 00153 endElement(const XMLCh* const name); 00154 00155 virtual void 00156 characters( 00157 const XMLCh* const chars, 00158 const unsigned int length); 00159 00160 virtual void 00161 charactersRaw( 00162 const XMLCh* const chars, 00163 const unsigned int length); 00164 00165 virtual void 00166 entityReference(const XMLCh* const name); 00167 00168 virtual void 00169 ignorableWhitespace( 00170 const XMLCh* const chars, 00171 const unsigned int length); 00172 00173 virtual void 00174 processingInstruction( 00175 const XMLCh* const target, 00176 const XMLCh* const data); 00177 00178 00179 virtual void 00180 resetDocument(); 00181 00182 virtual void 00183 comment(const XMLCh* const data); 00184 00185 virtual void 00186 cdata( 00187 const XMLCh* const ch, 00188 const unsigned int length); 00189 00190 virtual Writer* 00191 getWriter() const; 00192 00193 virtual const XalanDOMString& 00194 getDoctypeSystem() const; 00195 00196 virtual const XalanDOMString& 00197 getDoctypePublic() const; 00198 00199 virtual const XalanDOMString& 00200 getEncoding() const; 00201 00202 virtual const XalanDOMString& 00203 getMediaType() const; 00204 00205 const XalanDOMString& 00206 getVersion() const 00207 { 00208 return m_version; 00209 } 00210 00211 const XalanDOMString& 00212 getStandalone() const 00213 { 00214 return m_standalone; 00215 } 00216 00217 bool 00218 getShouldWriteXMLHeader() const 00219 { 00220 return m_shouldWriteXMLHeader; 00221 } 00222 00223 void 00224 setShouldWriteXMLHeader(bool b) 00225 { 00226 m_shouldWriteXMLHeader = b; 00227 } 00228 00229 #if defined(XALAN_NO_STD_NAMESPACE) 00230 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL) 00231 typedef deque<bool> BoolStackType; 00232 #else 00233 typedef vector<bool> BoolStackType; 00234 #endif 00235 #else 00236 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL) 00237 typedef std::deque<bool> BoolStackType; 00238 #else 00239 typedef std::vector<bool> BoolStackType; 00240 #endif 00241 #endif 00242 00243 protected: 00244 00248 Writer* m_writer; 00249 00253 void 00254 outputLineSep(); 00255 00259 XalanDOMString::size_type 00260 writeDefaultEscape( 00261 XalanDOMChar ch, 00262 XalanDOMString::size_type i, 00263 const XalanDOMChar chars[], 00264 XalanDOMString::size_type len); 00265 00269 XalanDOMString::size_type 00270 writeDefaultAttributeEscape( 00271 XalanDOMChar ch, 00272 XalanDOMString::size_type i, 00273 const XalanDOMChar chars[], 00274 XalanDOMString::size_type len); 00275 00280 bool 00281 writeDefaultEntity(XalanDOMChar ch); 00282 00287 bool 00288 writeDefaultAttributeEntity(XalanDOMChar ch); 00289 00294 void 00295 writeCommentData(const XalanDOMChar* data); 00296 00297 void 00298 flushWriter(); 00299 00300 void 00301 openElementForChildren(); 00302 00303 bool 00304 childNodesWereAdded(); 00305 00310 void 00311 writeParentTagEnd(); 00312 00319 XalanDOMString::size_type 00320 writeNormalizedChar( 00321 XalanDOMChar ch, 00322 const XalanDOMChar chars[], 00323 XalanDOMString::size_type start, 00324 XalanDOMString::size_type length); 00325 00332 void 00333 writeCDATAChars( 00334 const XalanDOMChar ch[], 00335 XalanDOMString::size_type length); 00336 00343 void 00344 writeAttrString( 00345 const XalanDOMChar* theString, 00346 XalanDOMString::size_type theStringLength); 00347 00353 static void 00354 throwInvalidUTF16SurrogateException(XalanDOMChar ch); 00355 00362 static void 00363 throwInvalidUTF16SurrogateException( 00364 XalanDOMChar ch, 00365 XalanDOMChar next); 00366 00370 bool m_shouldWriteXMLHeader; 00371 00377 bool m_needToOutputDocTypeDecl; 00378 00382 bool m_nextIsRaw; 00383 00387 const XalanDOMString m_doctypeSystem; 00388 00392 const XalanDOMString m_doctypePublic; 00393 00394 private: 00395 00396 // These are not implemented. 00397 FormatterToXML_UTF8(const FormatterToXML_UTF8&); 00398 00399 FormatterToXML_UTF8& 00400 operator=(const FormatterToXML_UTF8&); 00401 00402 bool 00403 operator==(const FormatterToXML_UTF8&) const; 00404 00405 void 00406 safeWriteContent( 00407 const XalanDOMChar* theChars, 00408 XalanDOMString::size_type theLength); 00409 00410 void 00411 write( 00412 const XalanDOMChar* theChars, 00413 XalanDOMString::size_type theLength); 00414 00415 void 00416 writeName1_0(const XalanDOMChar* theChars); 00417 00418 void 00419 writeName1_1(const XalanDOMChar* theChars); 00420 00421 void 00422 write(const XalanDOMChar* theChars) 00423 { 00424 write(theChars, XalanDOMString::length(theChars)); 00425 } 00426 00427 void 00428 write(XalanDOMChar theChar) 00429 { 00430 write((unsigned int)theChar); 00431 } 00432 00433 void 00434 write(unsigned int theChar); 00435 00436 void 00437 write(const XalanDOMString& theChars) 00438 { 00439 write(theChars.c_str(), theChars.length()); 00440 } 00441 00442 void 00443 write(char theChar); 00444 00445 void 00446 write( 00447 const char* theChars, 00448 XalanDOMString::size_type theLength); 00449 00450 void 00451 write(const char* theChars) 00452 { 00453 write(theChars, XalanDOMString::length(theChars)); 00454 } 00455 00461 void 00462 outputDocTypeDecl(const XalanDOMChar* name); 00463 00469 void 00470 processAttribute( 00471 const XalanDOMChar* name, 00472 const XalanDOMChar* value); 00473 00479 void 00480 writeNormalizedPIData( 00481 const XalanDOMChar* theData, 00482 XalanDOMString::size_type theLength); 00483 00484 void 00485 flushBuffer(); 00486 00487 // Data members... 00491 bool m_spaceBeforeClose; 00492 00496 const XalanDOMString m_version; 00497 00501 const XalanDOMString m_standalone; 00502 00506 const XalanDOMString m_mediaType; 00507 00511 static const XalanDOMString& s_utf8String; 00512 00516 static const char s_doctypeHeaderStartString[]; 00517 00518 static const XalanDOMString::size_type s_doctypeHeaderStartStringLength; 00519 00523 static const char s_doctypeHeaderPublicString[]; 00524 00525 static const XalanDOMString::size_type s_doctypeHeaderPublicStringLength; 00526 00530 static const char s_doctypeHeaderSystemString[]; 00531 00532 static const XalanDOMString::size_type s_doctypeHeaderSystemStringLength; 00533 00537 static const char s_xmlHeaderStartString[]; 00538 00539 static const XalanDOMString::size_type s_xmlHeaderStartStringLength; 00540 00544 static const char s_xmlHeaderEncodingString[]; 00545 00546 static const XalanDOMString::size_type s_xmlHeaderEncodingStringLength; 00547 00551 static const char s_xmlHeaderStandaloneString[]; 00552 00553 static const XalanDOMString::size_type s_xmlHeaderStandaloneStringLength; 00554 00558 static const char s_xmlHeaderEndString[]; 00559 00560 static const XalanDOMString::size_type s_xmlHeaderEndStringLength; 00561 00565 static const char s_defaultVersionString[]; 00566 00567 static const XalanDOMString::size_type s_defaultVersionStringLength; 00568 00572 static const XalanDOMChar s_xhtmlDocTypeString[]; 00573 00574 static const XalanDOMString::size_type s_xhtmlDocTypeStringLength; 00575 00579 static const char s_cdataOpenString[]; 00580 00581 static const XalanDOMString::size_type s_cdataOpenStringLength; 00582 00586 static const char s_cdataCloseString[]; 00587 00588 static const XalanDOMString::size_type s_cdataCloseStringLength; 00589 00593 static const char s_lessThanEntityString[]; 00594 00595 static const XalanDOMString::size_type s_lessThanEntityStringLength; 00596 00600 static const char s_greaterThanEntityString[]; 00601 00602 static const XalanDOMString::size_type s_greaterThanEntityStringLength; 00603 00607 static const char s_ampersandEntityString[]; 00608 00609 static const XalanDOMString::size_type s_ampersandEntityStringLength; 00610 00614 static const char s_quoteEntityString[]; 00615 00616 static const XalanDOMString::size_type s_quoteEntityStringLength; 00617 00621 static const char s_linefeedNCRString[]; 00622 00623 static const XalanDOMString::size_type s_linefeedNCRStringLength; 00624 00629 BoolStackType m_elemStack; 00630 00634 const XalanDOMChar* m_newlineString; 00635 00639 XalanDOMString::size_type m_newlineStringLength; 00640 00641 typedef void (FormatterToXML_UTF8::*NameFunctionType)(const XalanDOMChar*); 00642 00643 NameFunctionType m_nameFunction; 00644 00645 void 00646 writeName(const XalanDOMChar* theChars) 00647 { 00648 assert(m_nameFunction != 0); 00649 00650 (this->*m_nameFunction)(theChars); 00651 } 00652 00653 enum 00654 { 00655 kNotSpecial = 0, 00656 kContentSpecial = 1, // A flag to indicate a value in s_specialChars applies to content 00657 kAttributeSpecial = 2, // A flag to indicate a value in s_specialChars applies to attributes 00658 kBothSpecial = 3, // A flag t0 indicate a value in s_specialChars applies to both content and attributes 00659 kSpecialsSize = 0x80, // The size of s_specialChars 00660 kBufferSize = 512 // The size of the buffer 00661 }; 00662 00663 static bool 00664 isContentSpecial(XalanDOMChar theChar) 00665 { 00666 if ((theChar >= kSpecialsSize) || (s_specialChars[theChar] & kContentSpecial)) 00667 { 00668 return true; 00669 } 00670 else 00671 { 00672 return false; 00673 } 00674 } 00675 00676 static bool 00677 isAttributeSpecial(XalanDOMChar theChar) 00678 { 00679 if ((theChar >= kSpecialsSize) || (s_specialChars[theChar] & kAttributeSpecial)) 00680 { 00681 return true; 00682 } 00683 else 00684 { 00685 return false; 00686 } 00687 } 00688 00689 static bool 00690 isUTF16HighSurrogate(XalanDOMChar theChar) 00691 { 00692 return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false; 00693 } 00694 00695 static bool 00696 isUTF16LowSurrogate(XalanDOMChar theChar) 00697 { 00698 return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false; 00699 } 00700 00701 static unsigned int 00702 decodeUTF16SurrogatePair( 00703 XalanDOMChar theHighSurrogate, 00704 XalanDOMChar theLowSurrogate); 00705 00706 char m_buffer[kBufferSize]; 00707 00708 char* m_bufferPosition; 00709 00710 XalanDOMString::size_type m_bufferRemaining; 00711 00712 static const XalanDOMChar s_specialChars[]; 00713 }; 00714 00715 00716 00717 XALAN_CPP_NAMESPACE_END 00718 00719 00720 00721 #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.6 |
|