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 <map> 00069 #include <vector> 00070 00071 00072 00073 #include <XalanDOM/XalanDOMString.hpp> 00074 00075 00076 00077 #include <PlatformSupport/DOMStringHelper.hpp> 00078 #include <PlatformSupport/XalanUnicode.hpp> 00079 00080 00081 00082 // Base class header file. 00083 #include <XMLSupport/FormatterListener.hpp> 00084 00085 00086 00087 class AttributeList; 00088 class Writer; 00089 00090 00091 00095 class XALAN_XMLSUPPORT_EXPORT FormatterToXML : public FormatterListener 00096 { 00097 public: 00098 00099 enum eDummy 00100 { 00101 eDefaultIndentAmount = 4 00102 }; 00103 00107 static void 00108 initialize(); 00109 00113 static void 00114 terminate(); 00115 00136 FormatterToXML( 00137 Writer& writer, 00138 const XalanDOMString& version = XalanDOMString(), 00139 bool doIndent = false, 00140 int indent = eDefaultIndentAmount, 00141 const XalanDOMString& encoding = XalanDOMString(), 00142 const XalanDOMString& mediaType = XalanDOMString(), 00143 const XalanDOMString& doctypeSystem = XalanDOMString(), 00144 const XalanDOMString& doctypePublic = XalanDOMString(), 00145 bool xmlDecl = true, 00146 const XalanDOMString& standalone = XalanDOMString(), 00147 eFormat format = OUTPUT_METHOD_XML); 00148 00149 virtual 00150 ~FormatterToXML(); 00151 00152 00153 // These methods are inherited from FormatterListener ... 00154 00155 virtual void 00156 setDocumentLocator(const Locator* const locator); 00157 00158 virtual void 00159 startDocument(); 00160 00161 virtual void 00162 endDocument(); 00163 00164 virtual void 00165 startElement( 00166 const XMLCh* const name, 00167 AttributeList& attrs); 00168 00169 virtual void 00170 endElement(const XMLCh* const name); 00171 00172 virtual void 00173 characters( 00174 const XMLCh* const chars, 00175 const unsigned int length); 00176 00177 virtual void 00178 charactersRaw( 00179 const XMLCh* const chars, 00180 const unsigned int length); 00181 00182 virtual void 00183 entityReference(const XMLCh* const name); 00184 00185 virtual void 00186 ignorableWhitespace( 00187 const XMLCh* const chars, 00188 const unsigned int length); 00189 00190 virtual void 00191 processingInstruction( 00192 const XMLCh* const target, 00193 const XMLCh* const data); 00194 00195 00196 virtual void 00197 resetDocument(); 00198 00199 virtual void 00200 comment(const XMLCh* const data); 00201 00202 virtual void 00203 cdata( 00204 const XMLCh* const ch, 00205 const unsigned int length); 00206 00207 #if 0 00223 00224 static const XalanDOMString 00225 convertMime2JavaEncoding(const XalanDOMString& mimeCharsetName); 00226 00227 static const XalanDOMString 00228 convertJava2MimeEncoding(const XalanDOMString& encoding); 00229 00230 #endif 00231 00232 const Writer& 00233 getWriter() const 00234 { 00235 return m_writer; 00236 } 00237 00238 Writer& 00239 getWriter() 00240 { 00241 return m_writer; 00242 } 00243 00244 const XalanDOMString& 00245 getDoctypeSystem() const 00246 { 00247 return m_doctypeSystem; 00248 } 00249 00250 const XalanDOMString& 00251 getDoctypePublic() const 00252 { 00253 return m_doctypePublic; 00254 } 00255 00256 const XalanDOMString& 00257 getEncoding() const 00258 { 00259 return m_encoding; 00260 } 00261 00262 const XalanDOMString& 00263 getMediaType() const 00264 { 00265 return m_mediaType; 00266 } 00267 00268 const XalanDOMString& 00269 getVersion() const 00270 { 00271 return m_version; 00272 } 00273 00274 const XalanDOMString& 00275 getStandalone() const 00276 { 00277 return m_standalone; 00278 } 00279 00280 bool 00281 getShouldWriteXMLHeader() const 00282 { 00283 return m_shouldWriteXMLHeader; 00284 } 00285 00286 void 00287 setShouldWriteXMLHeader(bool b) 00288 { 00289 m_shouldWriteXMLHeader = b; 00290 } 00291 00292 bool 00293 getStripCData() const 00294 { 00295 return m_stripCData; 00296 } 00297 00298 void 00299 setStripCData(bool b) 00300 { 00301 m_stripCData = b; 00302 } 00303 00304 bool 00305 getEscapeCData() const 00306 { 00307 return m_escapeCData; 00308 } 00309 00310 void 00311 setEscapeCData(bool b) 00312 { 00313 m_escapeCData = b; 00314 } 00315 00316 bool 00317 getDoIndent() const 00318 { 00319 return m_doIndent; 00320 } 00321 00322 int 00323 getIndent() const 00324 { 00325 return m_indent; 00326 } 00327 00328 #if defined(XALAN_NO_NAMESPACES) 00329 typedef vector<bool> BoolStackType; 00330 typedef vector<XalanDOMChar> DOMCharBufferType; 00331 typedef vector<char> ByteBufferType; 00332 typedef map<XalanDOMString, 00333 XalanDOMChar, 00334 less<XalanDOMString> > MaximumCharacterValueMapType; 00335 #else 00336 typedef std::vector<bool> BoolStackType; 00337 typedef std::vector<XalanDOMChar> DOMCharBufferType; 00338 typedef std::vector<char> ByteBufferType; 00339 typedef std::map<XalanDOMString, 00340 XalanDOMChar> MaximumCharacterValueMapType; 00341 #endif 00342 00343 protected: 00344 00348 Writer& m_writer; 00349 00353 void 00354 outputLineSep(); 00355 00361 void 00362 accum(XalanDOMChar ch); 00363 00370 void 00371 accum(const XalanDOMChar* chars); 00372 00380 void 00381 accum( 00382 const XalanDOMChar chars[], 00383 unsigned int start, 00384 unsigned int length); 00385 00391 void 00392 accum(const XalanDOMString& str); 00393 00399 void 00400 accum(const XalanDOMCharVectorType& theVector); 00401 00405 void 00406 accumDefaultEscape( 00407 XalanDOMChar ch, 00408 unsigned int i, 00409 const XalanDOMChar chars[], 00410 unsigned int len, 00411 bool escLF); 00412 00417 bool 00418 accumDefaultEntity( 00419 XalanDOMChar ch, 00420 unsigned int i, 00421 const XalanDOMChar chars[], 00422 unsigned int len, 00423 bool escLF); 00424 00428 void 00429 initAttrCharsMap(); 00430 00434 void 00435 initCharsMap(); 00436 00440 void 00441 flushChars(); 00442 00446 void 00447 flushBytes(); 00448 00449 void 00450 flush(); 00451 00452 void 00453 flushWriter(); 00454 00455 void 00456 openElementForChildren(); 00457 00458 bool 00459 childNodesWereAdded(); 00460 00461 bool 00462 shouldIndent() const 00463 { 00464 return m_doIndent && (!m_ispreserve && !m_isprevtext); 00465 } 00466 00471 void 00472 writeParentTagEnd(); 00473 00478 void 00479 indent(int n); 00480 00488 virtual void 00489 writeNormalizedChars( 00490 const XalanDOMChar ch[], 00491 unsigned int start, 00492 unsigned int length, 00493 bool isCData); 00494 00500 void 00501 writeNumberedEntityReference(unsigned long theNumber); 00502 00508 virtual void 00509 writeAttrString( 00510 const XalanDOMChar* string, 00511 const XalanDOMString& encoding); 00512 00518 static void 00519 throwInvalidUTF16SurrogateException(XalanDOMChar ch); 00520 00527 static void 00528 throwInvalidUTF16SurrogateException( 00529 XalanDOMChar ch, 00530 unsigned int next); 00531 00539 static XalanDOMChar 00540 getMaximumCharacterValue(const XalanDOMString& theEncoding); 00541 00542 enum eDummyTwo { SPECIALSSIZE = 256}; 00543 00548 XalanDOMChar m_maxCharacter; 00549 00550 XalanDOMChar m_attrCharsMap[SPECIALSSIZE]; 00551 00552 XalanDOMChar m_charsMap[SPECIALSSIZE]; 00553 00557 bool m_shouldWriteXMLHeader; 00558 00563 bool m_ispreserve; 00564 00568 bool m_doIndent; 00569 00573 bool m_startNewLine; 00574 00580 bool m_needToOutputDocTypeDecl; 00581 00586 bool m_isprevtext; 00587 00592 bool m_stripCData; 00593 00597 bool m_nextIsRaw; 00598 00602 bool m_inCData; 00603 00607 bool m_isUTF8; 00608 00612 const XalanDOMString m_doctypeSystem; 00613 00617 const XalanDOMString m_doctypePublic; 00618 00622 XalanDOMString m_encoding; 00623 00627 int m_currentIndent; 00628 00632 int m_indent; 00633 00637 static const XalanDOMCharVectorType& s_xsltNextIsRawString; 00638 00642 static const XalanDOMCharVectorType& s_formatterToDOMString; 00643 00648 BoolStackType m_preserves; 00649 00650 private: 00651 00652 // These are not implemented. 00653 FormatterToXML(const FormatterToXML&); 00654 00655 FormatterToXML& 00656 operator=(const FormatterToXML&); 00657 00658 bool 00659 operator==(const FormatterToXML&) const; 00660 00664 static void 00665 initEncodings(); 00666 00672 void 00673 outputDocTypeDecl(const XalanDOMString& name); 00674 00680 void 00681 processAttribute( 00682 const XalanDOMChar* name, 00683 const XalanDOMChar* value); 00684 00689 void 00690 printSpace(int n); 00691 00697 void 00698 accumNormalizedPIData( 00699 const XalanDOMChar* theData, 00700 unsigned int theLength); 00701 00702 00703 // Data members... 00707 bool m_bytesEqualChars; 00708 00709 bool m_shouldFlush; 00710 00714 bool m_spaceBeforeClose; 00715 00721 bool m_escapeCData; 00722 00726 bool m_inEntityRef; 00727 00731 static bool s_javaEncodingIsISO; 00732 00736 const XalanDOMString m_version; 00737 00741 const XalanDOMString m_standalone; 00742 00746 const XalanDOMString m_mediaType; 00747 00751 const XalanDOMString m_attrSpecialChars; 00752 00756 static const XalanDOMCharVectorType& s_defaultMIMEEncoding; 00757 00761 static const XalanDOMCharVectorType& s_doctypeHeaderStartString; 00762 00766 static const XalanDOMCharVectorType& s_doctypeHeaderPublicString; 00767 00771 static const XalanDOMCharVectorType& s_doctypeHeaderSystemString; 00772 00776 static const XalanDOMCharVectorType& s_xmlHeaderStartString; 00777 00781 static const XalanDOMCharVectorType& s_xmlHeaderEncodingString; 00782 00786 static const XalanDOMCharVectorType& s_xmlHeaderStandaloneString; 00787 00791 static const XalanDOMCharVectorType& s_xmlHeaderEndString; 00792 00796 static const XalanDOMCharVectorType& s_defaultVersionString; 00797 00801 static const XalanDOMCharVectorType& s_windows1250EncodingString; 00802 00806 static const XalanDOMCharVectorType& s_usASCIIEncodingString; 00807 00811 static const XalanDOMCharVectorType& s_asciiEncodingString; 00812 00816 static const XalanDOMString& s_utf8EncodingString; 00817 00818 00819 DOMCharBufferType m_charBuf; 00820 00821 DOMCharBufferType::size_type m_pos; 00822 00823 ByteBufferType m_byteBuf; 00824 00825 static const DOMCharBufferType::size_type s_maxBufferSize; 00826 00827 static const MaximumCharacterValueMapType& s_maximumCharacterValues; 00828 00832 int m_level; 00833 00838 BoolStackType m_elemStack; 00839 }; 00840 00841 00842 00843 #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.0 |
|