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 void 00300 setDoIndent(bool value) 00301 { 00302 m_doIndent = value; 00303 } 00304 00305 int 00306 getIndent() const 00307 { 00308 return m_indent; 00309 } 00310 00311 void 00312 setIndent(int value) 00313 { 00314 m_indent = value; 00315 } 00316 00317 #if defined(XALAN_NO_NAMESPACES) 00318 typedef vector<bool> BoolStackType; 00319 typedef vector<XalanDOMChar> DOMCharBufferType; 00320 typedef vector<char> ByteBufferType; 00321 #else 00322 typedef std::vector<bool> BoolStackType; 00323 typedef std::vector<XalanDOMChar> DOMCharBufferType; 00324 typedef std::vector<char> ByteBufferType; 00325 #endif 00326 00327 protected: 00328 00332 Writer* const m_writer; 00333 00337 XalanOutputStream* const m_stream; 00338 00342 void 00343 outputLineSep(); 00344 00345 typedef void (FormatterToXML::*AccumCharFunctionType)(XalanDOMChar); 00346 00347 typedef void (FormatterToXML::*AccumStringFunctionType)(const XalanDOMChar*); 00348 00349 typedef void (FormatterToXML::*AccumDOMStringFunctionType)(const XalanDOMString&); 00350 00351 typedef void (FormatterToXML::*AccumArrayFunctionType)( 00352 const XalanDOMChar[], 00353 XalanDOMString::size_type, 00354 XalanDOMString::size_type); 00355 00356 typedef void (FormatterToXML::*FlushFunctionType)(); 00357 00367 void 00368 accumName(XalanDOMChar ch) 00369 { 00370 assert(m_accumNameCharFunction != 0); 00371 00372 (this->*m_accumNameCharFunction)(ch); 00373 } 00374 00380 void 00381 accumContent(XalanDOMChar ch) 00382 { 00383 assert(m_accumContentCharFunction != 0); 00384 00385 (this->*m_accumContentCharFunction)(ch); 00386 } 00387 00398 void 00399 accumName(const XalanDOMChar* chars) 00400 { 00401 assert(m_accumNameStringFunction != 0); 00402 00403 (this->*m_accumNameStringFunction)(chars); 00404 } 00405 00412 void 00413 accumContent(const XalanDOMChar* chars) 00414 { 00415 assert(m_accumContentStringFunction != 0); 00416 00417 (this->*m_accumContentStringFunction)(chars); 00418 } 00419 00431 void 00432 accumName( 00433 const XalanDOMChar chars[], 00434 XalanDOMString::size_type start, 00435 XalanDOMString::size_type length) 00436 { 00437 assert(m_accumNameArrayFunction != 0); 00438 00439 (this->*m_accumNameArrayFunction)(chars, start, length); 00440 } 00441 00449 void 00450 accumContent( 00451 const XalanDOMChar chars[], 00452 XalanDOMString::size_type start, 00453 XalanDOMString::size_type length) 00454 { 00455 assert(m_accumContentArrayFunction != 0); 00456 00457 (this->*m_accumContentArrayFunction)(chars, start, length); 00458 } 00459 00469 void 00470 accumName(const XalanDOMString& str) 00471 { 00472 assert(m_accumNameDOMStringFunction != 0); 00473 00474 (this->*m_accumNameDOMStringFunction)(str); 00475 } 00476 00482 void 00483 accumContent(const XalanDOMString& str) 00484 { 00485 assert(m_accumContentDOMStringFunction != 0); 00486 00487 (this->*m_accumContentDOMStringFunction)(str); 00488 } 00489 00493 void 00494 accumDefaultEscape( 00495 XalanDOMChar ch, 00496 XalanDOMString::size_type i, 00497 const XalanDOMChar chars[], 00498 XalanDOMString::size_type len, 00499 bool escLF); 00500 00505 virtual bool 00506 accumDefaultEntity( 00507 XalanDOMChar ch, 00508 XalanDOMString::size_type i, 00509 const XalanDOMChar chars[], 00510 XalanDOMString::size_type len, 00511 bool escLF); 00512 00516 void 00517 initAttrCharsMap(); 00518 00522 void 00523 initCharsMap(); 00524 00528 void 00529 flushChars(); 00530 00534 void 00535 flushBytes(); 00536 00537 void 00538 flushWriter(); 00539 00540 void 00541 openElementForChildren(); 00542 00543 bool 00544 childNodesWereAdded(); 00545 00546 bool 00547 shouldIndent() const 00548 { 00549 return m_doIndent && (!m_ispreserve && !m_isprevtext); 00550 } 00551 00556 void 00557 writeParentTagEnd(); 00558 00563 void 00564 indent(int n); 00565 00573 virtual void 00574 writeNormalizedChars( 00575 const XalanDOMChar ch[], 00576 XalanDOMString::size_type start, 00577 XalanDOMString::size_type length, 00578 bool isCData); 00579 00585 void 00586 writeNumberedEntityReference(unsigned long theNumber); 00587 00592 virtual void 00593 writeAttrString(const XalanDOMChar* theString); 00594 00599 virtual void 00600 accumCommentData(const XalanDOMChar* data); 00601 00607 static void 00608 throwInvalidUTF16SurrogateException(XalanDOMChar ch); 00609 00616 static void 00617 throwInvalidUTF16SurrogateException( 00618 XalanDOMChar ch, 00619 XalanDOMChar next); 00620 00621 static bool 00622 isUTF16Surrogate(XalanDOMChar ch) 00623 { 00624 return (ch & 0xFC00) == 0xD800 ? true : false; 00625 } 00626 00627 enum eDummyTwo { SPECIALSSIZE = 256}; 00628 00633 XalanDOMChar m_maxCharacter; 00634 00635 XalanDOMChar m_attrCharsMap[SPECIALSSIZE]; 00636 00637 XalanDOMChar m_charsMap[SPECIALSSIZE]; 00638 00642 bool m_shouldWriteXMLHeader; 00643 00648 bool m_ispreserve; 00649 00653 bool m_doIndent; 00654 00658 bool m_startNewLine; 00659 00665 bool m_needToOutputDocTypeDecl; 00666 00671 bool m_isprevtext; 00672 00677 bool m_stripCData; 00678 00682 bool m_nextIsRaw; 00683 00687 bool m_inCData; 00688 00693 bool m_encodingIsUTF; 00694 00698 const XalanDOMString m_doctypeSystem; 00699 00703 const XalanDOMString m_doctypePublic; 00704 00708 XalanDOMString m_encoding; 00709 00713 int m_currentIndent; 00714 00718 int m_indent; 00719 00724 BoolStackType m_preserves; 00725 00726 // A text buffer. We use it mostly for converting 00727 // to string values. See uses of UnsignedLongToString() 00728 // and UnsignedLongToHexString(). 00729 XalanDOMString m_stringBuffer; 00730 00731 private: 00732 00733 // These are not implemented. 00734 FormatterToXML(const FormatterToXML&); 00735 00736 FormatterToXML& 00737 operator=(const FormatterToXML&); 00738 00739 bool 00740 operator==(const FormatterToXML&) const; 00741 00745 static void 00746 initEncodings(); 00747 00756 void 00757 accumNameAsByte(XalanDOMChar ch); 00758 00767 void 00768 accumNameAsByteDirect(XalanDOMChar ch); 00769 00777 void 00778 accumContentAsByte(XalanDOMChar ch); 00779 00787 void 00788 accumContentAsByteDirect(XalanDOMChar ch); 00789 00798 void 00799 accumNameAsChar(XalanDOMChar ch); 00800 00809 void 00810 accumNameAsCharDirect(XalanDOMChar ch); 00811 00817 void 00818 accumContentAsChar(XalanDOMChar ch); 00819 00825 void 00826 accumContentAsCharDirect(XalanDOMChar ch); 00827 00835 void 00836 accumCharUTF(XalanDOMChar ch); 00837 00845 void 00846 accumCharUTFDirect(XalanDOMChar ch); 00847 00856 void 00857 accumNameString(const XalanDOMChar* chars); 00858 00866 void 00867 accumStringUTF(const XalanDOMChar* chars); 00868 00876 void 00877 accumStringUTFDirect(const XalanDOMChar* chars); 00878 00886 void 00887 accumContentString(const XalanDOMChar* chars); 00888 00898 void 00899 accumNameArray( 00900 const XalanDOMChar chars[], 00901 XalanDOMString::size_type start, 00902 XalanDOMString::size_type length); 00903 00913 void 00914 accumContentArray( 00915 const XalanDOMChar chars[], 00916 XalanDOMString::size_type start, 00917 XalanDOMString::size_type length); 00918 00928 void 00929 accumArrayUTF( 00930 const XalanDOMChar chars[], 00931 XalanDOMString::size_type start, 00932 XalanDOMString::size_type length); 00933 00943 void 00944 accumArrayUTFDirect( 00945 const XalanDOMChar chars[], 00946 XalanDOMString::size_type start, 00947 XalanDOMString::size_type length); 00948 00956 void 00957 accumNameDOMString(const XalanDOMString& str); 00958 00966 void 00967 accumContentDOMString(const XalanDOMString& str); 00968 00976 void 00977 accumDOMStringUTF(const XalanDOMString& str); 00978 00986 void 00987 accumDOMStringUTFDirect(const XalanDOMString& str); 00988 00994 void 00995 outputDocTypeDecl(const XalanDOMChar* name); 00996 01002 void 01003 processAttribute( 01004 const XalanDOMChar* name, 01005 const XalanDOMChar* value); 01006 01011 void 01012 printSpace(int n); 01013 01019 void 01020 accumNormalizedPIData( 01021 const XalanDOMChar* theData, 01022 XalanDOMString::size_type theLength); 01023 01024 01025 // Data members... 01029 bool m_bytesEqualChars; 01030 01031 bool m_shouldFlush; 01032 01036 bool m_spaceBeforeClose; 01037 01043 bool m_escapeCData; 01044 01048 bool m_inEntityRef; 01049 01053 const XalanDOMString m_version; 01054 01058 const XalanDOMString m_standalone; 01059 01063 const XalanDOMString m_mediaType; 01064 01068 const XalanDOMString m_attrSpecialChars; 01069 01073 static const XalanDOMString& s_defaultMIMEEncoding; 01074 01078 static const XalanDOMString& s_doctypeHeaderStartString; 01079 01083 static const XalanDOMString& s_doctypeHeaderPublicString; 01084 01088 static const XalanDOMString& s_doctypeHeaderSystemString; 01089 01093 static const XalanDOMString& s_xmlHeaderStartString; 01094 01098 static const XalanDOMString& s_xmlHeaderEncodingString; 01099 01103 static const XalanDOMString& s_xmlHeaderStandaloneString; 01104 01108 static const XalanDOMString& s_xmlHeaderEndString; 01109 01113 static const XalanDOMString& s_defaultVersionString; 01114 01118 static const XalanDOMString& s_xhtmlDocType; 01119 01123 static const XalanDOMString& s_dtdCDATACloseString; 01124 01125 DOMCharBufferType m_charBuf; 01126 01127 DOMCharBufferType::size_type m_pos; 01128 01129 ByteBufferType m_byteBuf; 01130 01131 static const DOMCharBufferType::size_type s_maxBufferSize; 01132 01137 BoolStackType m_elemStack; 01138 01143 AccumCharFunctionType m_accumNameCharFunction; 01144 01149 AccumStringFunctionType m_accumNameStringFunction; 01150 01155 AccumDOMStringFunctionType m_accumNameDOMStringFunction; 01156 01161 AccumArrayFunctionType m_accumNameArrayFunction; 01162 01167 AccumCharFunctionType m_accumContentCharFunction; 01168 01173 AccumStringFunctionType m_accumContentStringFunction; 01174 01179 AccumDOMStringFunctionType m_accumContentDOMStringFunction; 01180 01185 AccumArrayFunctionType m_accumContentArrayFunction; 01186 01190 FlushFunctionType m_flushFunction; 01191 }; 01192 01193 01194 01195 #endif // FORMATTERTOXML_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.3 |
|