Xalan-C++ API Documentation

The Xalan C++ XSL Transformer Version 1.1

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

FormatterToXML.hpp

Go to the documentation of this file.
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 <XMLSupport/FormatterListener.hpp>
00083 
00084 
00085 
00086 class AttributeList;
00087 class Writer;
00088 
00089 
00090 
00094 class XALAN_XMLSUPPORT_EXPORT FormatterToXML : public FormatterListener 
00095 {
00096 public:
00097 
00098     enum eDummy
00099     {
00100         eDefaultIndentAmount = 0
00101     };
00102 
00106     static void
00107     initialize();
00108 
00112     static void
00113     terminate();
00114 
00135     FormatterToXML(
00136             Writer&                 writer,
00137             const XalanDOMString&   version = XalanDOMString(),
00138             bool                    doIndent = false,
00139             int                     indent = eDefaultIndentAmount,
00140             const XalanDOMString&   encoding = XalanDOMString(),
00141             const XalanDOMString&   mediaType = XalanDOMString(),
00142             const XalanDOMString&   doctypeSystem = XalanDOMString(),
00143             const XalanDOMString&   doctypePublic = XalanDOMString(),
00144             bool                    xmlDecl = true,
00145             const XalanDOMString&   standalone = XalanDOMString(),
00146             eFormat                 format = OUTPUT_METHOD_XML);
00147 
00148     virtual
00149     ~FormatterToXML();
00150 
00151 
00152     // These methods are inherited from FormatterListener ...
00153 
00154     virtual void
00155     setDocumentLocator(const Locator* const     locator);
00156 
00157     virtual void
00158     startDocument();
00159 
00160     virtual void
00161     endDocument();
00162 
00163     virtual void
00164     startElement(
00165             const   XMLCh* const    name,
00166             AttributeList&          attrs);
00167 
00168     virtual void
00169     endElement(const XMLCh* const   name);
00170 
00171     virtual void
00172     characters(
00173             const XMLCh* const  chars,
00174             const unsigned int  length);
00175 
00176     virtual void
00177     charactersRaw(
00178             const XMLCh* const  chars,
00179             const unsigned int  length);
00180 
00181     virtual void
00182     entityReference(const XMLCh* const  name);
00183 
00184     virtual void
00185     ignorableWhitespace(
00186             const XMLCh* const  chars,
00187             const unsigned int  length);
00188 
00189     virtual void
00190     processingInstruction(
00191             const XMLCh* const  target,
00192             const XMLCh* const  data);
00193 
00194 
00195     virtual void
00196     resetDocument();
00197 
00198     virtual void
00199     comment(const XMLCh* const  data);
00200 
00201     virtual void
00202     cdata(
00203             const XMLCh* const  ch,
00204             const unsigned int  length);
00205 
00206     const Writer&
00207     getWriter() const
00208     {
00209         return m_writer;
00210     }
00211 
00212     Writer&
00213     getWriter()
00214     {
00215         return m_writer;
00216     }
00217 
00218     const XalanDOMString&
00219     getDoctypeSystem() const
00220     {
00221         return m_doctypeSystem;
00222     }
00223 
00224     const XalanDOMString&
00225     getDoctypePublic() const
00226     {
00227         return m_doctypePublic;
00228     }
00229 
00230     const XalanDOMString&
00231     getEncoding() const
00232     {
00233         return m_encoding;
00234     }
00235 
00236     const XalanDOMString&
00237     getMediaType() const
00238     {
00239         return m_mediaType;
00240     }
00241 
00242     const XalanDOMString&
00243     getVersion() const
00244     {
00245         return m_version;
00246     }
00247 
00248     const XalanDOMString&
00249     getStandalone() const
00250     {
00251         return m_standalone;
00252     }
00253 
00254     bool
00255     getShouldWriteXMLHeader() const
00256     {
00257         return m_shouldWriteXMLHeader;
00258     }
00259 
00260     void
00261     setShouldWriteXMLHeader(bool    b)
00262     {
00263         m_shouldWriteXMLHeader = b;
00264     }
00265 
00266     bool
00267     getStripCData() const
00268     {
00269         return m_stripCData;
00270     }
00271 
00272     void
00273     setStripCData(bool  b)
00274     {
00275         m_stripCData = b;
00276     }
00277 
00278     bool
00279     getEscapeCData() const
00280     {
00281         return m_escapeCData;
00282     }
00283 
00284     void
00285     setEscapeCData(bool b)
00286     {
00287         m_escapeCData = b;
00288     }
00289 
00290     bool
00291     getDoIndent() const
00292     {
00293         return m_doIndent;
00294     }
00295 
00296     int
00297     getIndent() const
00298     {
00299         return m_indent;
00300     }
00301 
00302 #if defined(XALAN_NO_NAMESPACES)
00303     typedef vector<bool>                BoolStackType;
00304     typedef vector<XalanDOMChar>        DOMCharBufferType;
00305     typedef vector<char>                ByteBufferType;
00306 #else
00307     typedef std::vector<bool>           BoolStackType;
00308     typedef std::vector<XalanDOMChar>   DOMCharBufferType;
00309     typedef std::vector<char>           ByteBufferType;
00310 #endif
00311 
00312 protected:
00313 
00317     Writer&     m_writer;
00318 
00322     void
00323     outputLineSep();
00324 
00333     void
00334     accumName(XalanDOMChar  ch)
00335     {
00336         assert(m_accumNameFunction != 0);
00337 
00338         (this->*m_accumNameFunction)(ch);
00339     }
00340 
00349     void
00350     accumContent(XalanDOMChar   ch)
00351     {
00352         assert(m_accumContentFunction != 0);
00353 
00354         (this->*m_accumContentFunction)(ch);
00355     }
00356 
00363     void
00364     accumName(const XalanDOMChar*   chars);
00365 
00372     void
00373     accumContent(const XalanDOMChar*        chars);
00374 
00382     void
00383     accumName(
00384             const XalanDOMChar  chars[],
00385             unsigned int        start,
00386             unsigned int        length);
00387 
00395     void
00396     accumContent(
00397             const XalanDOMChar  chars[],
00398             unsigned int        start,
00399             unsigned int        length);
00400 
00406     void
00407     accumName(const XalanDOMString&     str);
00408 
00409     typedef void (FormatterToXML::*AccumFunctionType)(XalanDOMChar);
00410 
00416     void
00417     accumContent(const XalanDOMString&  str);
00418 
00422     void
00423     accumDefaultEscape(
00424             XalanDOMChar        ch,
00425             unsigned int        i,
00426             const XalanDOMChar  chars[],
00427             unsigned int        len,
00428             bool                escLF);
00429 
00434     virtual bool
00435     accumDefaultEntity(
00436             XalanDOMChar        ch,
00437             unsigned int        i,
00438             const XalanDOMChar  chars[],
00439             unsigned int        len,
00440             bool                escLF);
00441 
00445     void
00446     initAttrCharsMap();
00447 
00451     void
00452     initCharsMap();
00453 
00457     void
00458     flushChars();
00459 
00463     void
00464     flushBytes();
00465 
00466     void
00467     flush();
00468 
00469     void
00470     flushWriter();
00471 
00472     void
00473     openElementForChildren();
00474 
00475     bool
00476     childNodesWereAdded();
00477 
00478     bool
00479     shouldIndent() const
00480     {
00481         return m_doIndent && (!m_ispreserve && !m_isprevtext);
00482     }
00483 
00488     void
00489     writeParentTagEnd();
00490 
00495     void
00496     indent(int  n);
00497 
00505     virtual void
00506     writeNormalizedChars(
00507             const XalanDOMChar  ch[],
00508             unsigned int        start,
00509             unsigned int        length,
00510             bool                isCData);
00511 
00517     void
00518     writeNumberedEntityReference(unsigned long  theNumber);
00519 
00525     virtual void
00526     writeAttrString(
00527             const XalanDOMChar*     string,
00528             const XalanDOMString&   encoding);
00529 
00534     virtual void
00535     accumCommentData(const XalanDOMChar*    data);
00536 
00542     static void
00543     throwInvalidUTF16SurrogateException(XalanDOMChar    ch);
00544 
00551     static void
00552     throwInvalidUTF16SurrogateException(
00553             XalanDOMChar    ch,
00554             unsigned int    next);
00555 
00556     static bool
00557     isUTF16Surrogate(XalanDOMChar   ch)
00558     {
00559         return (ch & 0xFC00) == 0xD800 ? true : false;
00560     }
00561 
00562     enum eDummyTwo { SPECIALSSIZE = 256};
00563 
00568     XalanDOMChar            m_maxCharacter;
00569 
00570     XalanDOMChar            m_attrCharsMap[SPECIALSSIZE];
00571 
00572     XalanDOMChar            m_charsMap[SPECIALSSIZE];
00573 
00577     bool        m_shouldWriteXMLHeader;
00578 
00583     bool        m_ispreserve;
00584 
00588     bool        m_doIndent;
00589 
00593     bool        m_startNewLine;
00594   
00600     bool        m_needToOutputDocTypeDecl;
00601   
00606     bool        m_isprevtext;
00607 
00612     bool        m_stripCData;
00613 
00617     bool        m_nextIsRaw;
00618 
00622     bool        m_inCData;
00623 
00627     bool        m_isUTF8;
00628 
00632     const XalanDOMString    m_doctypeSystem;
00633 
00637     const XalanDOMString    m_doctypePublic;
00638 
00642     XalanDOMString  m_encoding;
00643 
00647     int     m_currentIndent;
00648   
00652     int     m_indent;
00653 
00658     BoolStackType   m_preserves;
00659 
00660     // A text buffer.  We use it mostly for converting
00661     // to string values.  See uses of UnsignedLongToString()
00662     // and UnsignedLongToHexString().
00663     XalanDOMString  m_stringBuffer;
00664 
00665 private:
00666 
00667     // These are not implemented.
00668     FormatterToXML(const FormatterToXML&);
00669 
00670     FormatterToXML&
00671     operator=(const FormatterToXML&);
00672 
00673     bool
00674     operator==(const FormatterToXML&) const;
00675 
00679     static void
00680     initEncodings();
00681 
00690     void
00691     accumNameAsByte(XalanDOMChar    ch);
00692 
00700     void
00701     accumContentAsByte(XalanDOMChar     ch);
00702 
00711     void
00712     accumNameAsChar(XalanDOMChar    ch);
00713 
00719     void
00720     accumContentAsChar(XalanDOMChar     ch);
00721 
00727     void
00728     outputDocTypeDecl(const XalanDOMChar*   name);
00729 
00735     void
00736     processAttribute(
00737             const XalanDOMChar*     name,
00738             const XalanDOMChar*     value);
00739 
00744     void
00745     printSpace(int n);
00746 
00752     void
00753     accumNormalizedPIData(
00754             const XalanDOMChar*     theData,
00755             unsigned int            theLength);
00756 
00757 
00758     // Data members...
00762     bool        m_bytesEqualChars;
00763 
00764     bool        m_shouldFlush;
00765 
00769     bool        m_spaceBeforeClose;
00770 
00776     bool        m_escapeCData;
00777 
00781     bool        m_inEntityRef;
00782 
00786     static bool     s_javaEncodingIsISO;
00787 
00791     const XalanDOMString    m_version;
00792 
00796     const XalanDOMString    m_standalone;
00797 
00801     const XalanDOMString    m_mediaType;
00802 
00806     const XalanDOMString    m_attrSpecialChars;
00807 
00811     static const XalanDOMString&    s_defaultMIMEEncoding;
00812 
00816     static const XalanDOMString&    s_doctypeHeaderStartString;
00817 
00821     static const XalanDOMString&    s_doctypeHeaderPublicString;
00822 
00826     static const XalanDOMString&    s_doctypeHeaderSystemString;
00827 
00831     static const XalanDOMString&    s_xmlHeaderStartString;
00832 
00836     static const XalanDOMString&    s_xmlHeaderEncodingString;
00837 
00841     static const XalanDOMString&    s_xmlHeaderStandaloneString;
00842 
00846     static const XalanDOMString&    s_xmlHeaderEndString;
00847 
00851     static const XalanDOMString&    s_defaultVersionString;
00852 
00856     static const XalanDOMString&            s_xhtmlDocType;
00857 
00861     static const XalanDOMString&            s_iso88591String;
00862 
00866     static const XalanDOMString&            s_dtdCDATACloseString;
00867 
00868     DOMCharBufferType                           m_charBuf;
00869 
00870     DOMCharBufferType::size_type                m_pos;
00871 
00872     ByteBufferType                              m_byteBuf;
00873 
00874     static const DOMCharBufferType::size_type   s_maxBufferSize;
00875 
00880     BoolStackType   m_elemStack;
00881 
00886     AccumFunctionType   m_accumNameFunction;
00887 
00892     AccumFunctionType   m_accumContentFunction;
00893 };
00894 
00895 
00896 
00897 #endif  // FORMATTERTOXML_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSL Transformer Version 1.1
Copyright © 2000, 2001 The Apache Software Foundation. All Rights Reserved.