00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999 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_HEADER_GUARD_1357924680) 00058 #define FORMATTERTOXML_HEADER_GUARD_1357924680 00059 00060 00061 00062 00063 // Base include file. Must be first. 00064 #include <XMLSupport/XMLSupportDefinitions.hpp> 00065 00066 00067 00068 #include <vector> 00069 00070 00071 00072 #include <XalanDOM/XalanDOMString.hpp> 00073 00074 00075 00076 #include <PlatformSupport/DOMStringHelper.hpp> 00077 #include <PlatformSupport/XalanUnicode.hpp> 00078 00079 00080 00081 // Base class header file. 00082 #include <PlatformSupport/FormatterListener.hpp> 00083 00084 00085 00086 class AttributeList; 00087 class Writer; 00088 class XalanOutputStream; 00089 00090 00091 00095 class XALAN_XMLSUPPORT_EXPORT FormatterToXML : public FormatterListener 00096 { 00097 public: 00098 00099 enum eDummy 00100 { 00101 eDefaultIndentAmount = 0 00102 }; 00103 00107 static void 00108 initialize(); 00109 00113 static void 00114 terminate(); 00115 00137 FormatterToXML( 00138 Writer& writer, 00139 const XalanDOMString& version = XalanDOMString(), 00140 bool doIndent = false, 00141 int indent = eDefaultIndentAmount, 00142 const XalanDOMString& encoding = XalanDOMString(), 00143 const XalanDOMString& mediaType = XalanDOMString(), 00144 const XalanDOMString& doctypeSystem = XalanDOMString(), 00145 const XalanDOMString& doctypePublic = XalanDOMString(), 00146 bool xmlDecl = true, 00147 const XalanDOMString& standalone = XalanDOMString(), 00148 eFormat format = OUTPUT_METHOD_XML, 00149 bool fBufferData = true); 00150 00151 virtual 00152 ~FormatterToXML(); 00153 00154 00155 // These methods are inherited from FormatterListener ... 00156 00157 virtual void 00158 setDocumentLocator(const Locator* const locator); 00159 00160 virtual void 00161 startDocument(); 00162 00163 virtual void 00164 endDocument(); 00165 00166 virtual void 00167 startElement( 00168 const XMLCh* const name, 00169 AttributeList& attrs); 00170 00171 virtual void 00172 endElement(const XMLCh* const name); 00173 00174 virtual void 00175 characters( 00176 const XMLCh* const chars, 00177 const unsigned int length); 00178 00179 virtual void 00180 charactersRaw( 00181 const XMLCh* const chars, 00182 const unsigned int length); 00183 00184 virtual void 00185 entityReference(const XMLCh* const name); 00186 00187 virtual void 00188 ignorableWhitespace( 00189 const XMLCh* const chars, 00190 const unsigned int length); 00191 00192 virtual void 00193 processingInstruction( 00194 const XMLCh* const target, 00195 const XMLCh* const data); 00196 00197 00198 virtual void 00199 resetDocument(); 00200 00201 virtual void 00202 comment(const XMLCh* const data); 00203 00204 virtual void 00205 cdata( 00206 const XMLCh* const ch, 00207 const unsigned int length); 00208 00209 const Writer* 00210 getWriter() const 00211 { 00212 return m_writer; 00213 } 00214 00215 Writer* 00216 getWriter() 00217 { 00218 return m_writer; 00219 } 00220 00221 const XalanDOMString& 00222 getDoctypeSystem() const 00223 { 00224 return m_doctypeSystem; 00225 } 00226 00227 const XalanDOMString& 00228 getDoctypePublic() const 00229 { 00230 return m_doctypePublic; 00231 } 00232 00233 const XalanDOMString& 00234 getEncoding() const 00235 { 00236 return m_encoding; 00237 } 00238 00239 const XalanDOMString& 00240 getMediaType() const 00241 { 00242 return m_mediaType; 00243 } 00244 00245 const XalanDOMString& 00246 getVersion() const 00247 { 00248 return m_version; 00249 } 00250 00251 const XalanDOMString& 00252 getStandalone() const 00253 { 00254 return m_standalone; 00255 } 00256 00257 bool 00258 getShouldWriteXMLHeader() const 00259 { 00260 return m_shouldWriteXMLHeader; 00261 } 00262 00263 void 00264 setShouldWriteXMLHeader(bool b) 00265 { 00266 m_shouldWriteXMLHeader = b; 00267 } 00268 00269 bool 00270 getStripCData() const 00271 { 00272 return m_stripCData; 00273 } 00274 00275 void 00276 setStripCData(bool b) 00277 { 00278 m_stripCData = b; 00279 } 00280 00281 bool 00282 getEscapeCData() const 00283 { 00284 return m_escapeCData; 00285 } 00286 00287 void 00288 setEscapeCData(bool b) 00289 { 00290 m_escapeCData = b; 00291 } 00292 00293 bool 00294 getDoIndent() const 00295 { 00296 return m_doIndent; 00297 } 00298 00299 int 00300 getIndent() const 00301 { 00302 return m_indent; 00303 } 00304 00305 #if defined(XALAN_NO_NAMESPACES) 00306 typedef vector<bool> BoolStackType; 00307 typedef vector<XalanDOMChar> DOMCharBufferType; 00308 typedef vector<char> ByteBufferType; 00309 #else 00310 typedef std::vector<bool> BoolStackType; 00311 typedef std::vector<XalanDOMChar> DOMCharBufferType; 00312 typedef std::vector<char> ByteBufferType; 00313 #endif 00314 00315 protected: 00316 00320 Writer* const m_writer; 00321 00325 XalanOutputStream* const m_stream; 00326 00330 void 00331 outputLineSep(); 00332 00333 typedef void (FormatterToXML::*AccumCharFunctionType)(XalanDOMChar); 00334 00335 typedef void (FormatterToXML::*AccumStringFunctionType)(const XalanDOMChar*); 00336 00337 typedef void (FormatterToXML::*AccumDOMStringFunctionType)(const XalanDOMString&); 00338 00339 typedef void (FormatterToXML::*AccumArrayFunctionType)( 00340 const XalanDOMChar[], 00341 unsigned int, 00342 unsigned int); 00343 00344 typedef void (FormatterToXML::*FlushFunctionType)(); 00345 00355 void 00356 accumName(XalanDOMChar ch) 00357 { 00358 assert(m_accumNameCharFunction != 0); 00359 00360 (this->*m_accumNameCharFunction)(ch); 00361 } 00362 00368 void 00369 accumContent(XalanDOMChar ch) 00370 { 00371 assert(m_accumContentCharFunction != 0); 00372 00373 (this->*m_accumContentCharFunction)(ch); 00374 } 00375 00386 void 00387 accumName(const XalanDOMChar* chars) 00388 { 00389 assert(m_accumNameStringFunction != 0); 00390 00391 (this->*m_accumNameStringFunction)(chars); 00392 } 00393 00400 void 00401 accumContent(const XalanDOMChar* chars) 00402 { 00403 assert(m_accumContentStringFunction != 0); 00404 00405 (this->*m_accumContentStringFunction)(chars); 00406 } 00407 00419 void 00420 accumName( 00421 const XalanDOMChar chars[], 00422 unsigned int start, 00423 unsigned int length) 00424 { 00425 assert(m_accumNameArrayFunction != 0); 00426 00427 (this->*m_accumNameArrayFunction)(chars, start, length); 00428 } 00429 00437 void 00438 accumContent( 00439 const XalanDOMChar chars[], 00440 unsigned int start, 00441 unsigned int length) 00442 { 00443 assert(m_accumContentArrayFunction != 0); 00444 00445 (this->*m_accumContentArrayFunction)(chars, start, length); 00446 } 00447 00457 void 00458 accumName(const XalanDOMString& str) 00459 { 00460 assert(m_accumNameDOMStringFunction != 0); 00461 00462 (this->*m_accumNameDOMStringFunction)(str); 00463 } 00464 00470 void 00471 accumContent(const XalanDOMString& str) 00472 { 00473 assert(m_accumContentDOMStringFunction != 0); 00474 00475 (this->*m_accumContentDOMStringFunction)(str); 00476 } 00477 00481 void 00482 accumDefaultEscape( 00483 XalanDOMChar ch, 00484 unsigned int i, 00485 const XalanDOMChar chars[], 00486 unsigned int len, 00487 bool escLF); 00488 00493 virtual bool 00494 accumDefaultEntity( 00495 XalanDOMChar ch, 00496 unsigned int i, 00497 const XalanDOMChar chars[], 00498 unsigned int len, 00499 bool escLF); 00500 00504 void 00505 initAttrCharsMap(); 00506 00510 void 00511 initCharsMap(); 00512 00516 void 00517 flushChars(); 00518 00522 void 00523 flushBytes(); 00524 00525 void 00526 flushWriter(); 00527 00528 void 00529 openElementForChildren(); 00530 00531 bool 00532 childNodesWereAdded(); 00533 00534 bool 00535 shouldIndent() const 00536 { 00537 return m_doIndent && (!m_ispreserve && !m_isprevtext); 00538 } 00539 00544 void 00545 writeParentTagEnd(); 00546 00551 void 00552 indent(int n); 00553 00561 virtual void 00562 writeNormalizedChars( 00563 const XalanDOMChar ch[], 00564 unsigned int start, 00565 unsigned int length, 00566 bool isCData); 00567 00573 void 00574 writeNumberedEntityReference(unsigned long theNumber); 00575 00580 virtual void 00581 writeAttrString(const XalanDOMChar* theString); 00582 00587 virtual void 00588 accumCommentData(const XalanDOMChar* data); 00589 00595 static void 00596 throwInvalidUTF16SurrogateException(XalanDOMChar ch); 00597 00604 static void 00605 throwInvalidUTF16SurrogateException( 00606 XalanDOMChar ch, 00607 unsigned int next); 00608 00609 static bool 00610 isUTF16Surrogate(XalanDOMChar ch) 00611 { 00612 return (ch & 0xFC00) == 0xD800 ? true : false; 00613 } 00614 00615 enum eDummyTwo { SPECIALSSIZE = 256}; 00616 00621 XalanDOMChar m_maxCharacter; 00622 00623 XalanDOMChar m_attrCharsMap[SPECIALSSIZE]; 00624 00625 XalanDOMChar m_charsMap[SPECIALSSIZE]; 00626 00630 bool m_shouldWriteXMLHeader; 00631 00636 bool m_ispreserve; 00637 00641 bool m_doIndent; 00642 00646 bool m_startNewLine; 00647 00653 bool m_needToOutputDocTypeDecl; 00654 00659 bool m_isprevtext; 00660 00665 bool m_stripCData; 00666 00670 bool m_nextIsRaw; 00671 00675 bool m_inCData; 00676 00681 bool m_encodingIsUTF; 00682 00686 const XalanDOMString m_doctypeSystem; 00687 00691 const XalanDOMString m_doctypePublic; 00692 00696 XalanDOMString m_encoding; 00697 00701 int m_currentIndent; 00702 00706 int m_indent; 00707 00712 BoolStackType m_preserves; 00713 00714 // A text buffer. We use it mostly for converting 00715 // to string values. See uses of UnsignedLongToString() 00716 // and UnsignedLongToHexString(). 00717 XalanDOMString m_stringBuffer; 00718 00719 private: 00720 00721 // These are not implemented. 00722 FormatterToXML(const FormatterToXML&); 00723 00724 FormatterToXML& 00725 operator=(const FormatterToXML&); 00726 00727 bool 00728 operator==(const FormatterToXML&) const; 00729 00733 static void 00734 initEncodings(); 00735 00744 void 00745 accumNameAsByte(XalanDOMChar ch); 00746 00755 void 00756 accumNameAsByteDirect(XalanDOMChar ch); 00757 00765 void 00766 accumContentAsByte(XalanDOMChar ch); 00767 00775 void 00776 accumContentAsByteDirect(XalanDOMChar ch); 00777 00786 void 00787 accumNameAsChar(XalanDOMChar ch); 00788 00797 void 00798 accumNameAsCharDirect(XalanDOMChar ch); 00799 00805 void 00806 accumContentAsChar(XalanDOMChar ch); 00807 00813 void 00814 accumContentAsCharDirect(XalanDOMChar ch); 00815 00823 void 00824 accumCharUTF(XalanDOMChar ch); 00825 00833 void 00834 accumCharUTFDirect(XalanDOMChar ch); 00835 00844 void 00845 accumNameString(const XalanDOMChar* chars); 00846 00854 void 00855 accumStringUTF(const XalanDOMChar* chars); 00856 00864 void 00865 accumStringUTFDirect(const XalanDOMChar* chars); 00866 00874 void 00875 accumContentString(const XalanDOMChar* chars); 00876 00886 void 00887 accumNameArray( 00888 const XalanDOMChar chars[], 00889 unsigned int start, 00890 unsigned int length); 00891 00901 void 00902 accumContentArray( 00903 const XalanDOMChar chars[], 00904 unsigned int start, 00905 unsigned int length); 00906 00916 void 00917 accumArrayUTF( 00918 const XalanDOMChar chars[], 00919 unsigned int start, 00920 unsigned int length); 00921 00931 void 00932 accumArrayUTFDirect( 00933 const XalanDOMChar chars[], 00934 unsigned int start, 00935 unsigned int length); 00936 00944 void 00945 accumNameDOMString(const XalanDOMString& str); 00946 00954 void 00955 accumContentDOMString(const XalanDOMString& str); 00956 00964 void 00965 accumDOMStringUTF(const XalanDOMString& str); 00966 00974 void 00975 accumDOMStringUTFDirect(const XalanDOMString& str); 00976 00982 void 00983 outputDocTypeDecl(const XalanDOMChar* name); 00984 00990 void 00991 processAttribute( 00992 const XalanDOMChar* name, 00993 const XalanDOMChar* value); 00994 00999 void 01000 printSpace(int n); 01001 01007 void 01008 accumNormalizedPIData( 01009 const XalanDOMChar* theData, 01010 unsigned int theLength); 01011 01012 01013 // Data members... 01017 bool m_bytesEqualChars; 01018 01019 bool m_shouldFlush; 01020 01024 bool m_spaceBeforeClose; 01025 01031 bool m_escapeCData; 01032 01036 bool m_inEntityRef; 01037 01041 const XalanDOMString m_version; 01042 01046 const XalanDOMString m_standalone; 01047 01051 const XalanDOMString m_mediaType; 01052 01056 const XalanDOMString m_attrSpecialChars; 01057 01061 static const XalanDOMString& s_defaultMIMEEncoding; 01062 01066 static const XalanDOMString& s_doctypeHeaderStartString; 01067 01071 static const XalanDOMString& s_doctypeHeaderPublicString; 01072 01076 static const XalanDOMString& s_doctypeHeaderSystemString; 01077 01081 static const XalanDOMString& s_xmlHeaderStartString; 01082 01086 static const XalanDOMString& s_xmlHeaderEncodingString; 01087 01091 static const XalanDOMString& s_xmlHeaderStandaloneString; 01092 01096 static const XalanDOMString& s_xmlHeaderEndString; 01097 01101 static const XalanDOMString& s_defaultVersionString; 01102 01106 static const XalanDOMString& s_xhtmlDocType; 01107 01111 static const XalanDOMString& s_dtdCDATACloseString; 01112 01113 DOMCharBufferType m_charBuf; 01114 01115 DOMCharBufferType::size_type m_pos; 01116 01117 ByteBufferType m_byteBuf; 01118 01119 static const DOMCharBufferType::size_type s_maxBufferSize; 01120 01125 BoolStackType m_elemStack; 01126 01131 AccumCharFunctionType m_accumNameCharFunction; 01132 01137 AccumStringFunctionType m_accumNameStringFunction; 01138 01143 AccumDOMStringFunctionType m_accumNameDOMStringFunction; 01144 01149 AccumArrayFunctionType m_accumNameArrayFunction; 01150 01155 AccumCharFunctionType m_accumContentCharFunction; 01156 01161 AccumStringFunctionType m_accumContentStringFunction; 01162 01167 AccumDOMStringFunctionType m_accumContentDOMStringFunction; 01168 01173 AccumArrayFunctionType m_accumContentArrayFunction; 01174 01178 FlushFunctionType m_flushFunction; 01179 }; 01180 01181 01182 01183 #endif // FORMATTERTOXML_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSL Transformer Version 1.1 |
|