Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.5

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-2002 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 XALAN_CPP_NAMESPACE_BEGIN
00087 
00088 
00089 
00090 class Writer;
00091 class XalanOutputStream;
00092 
00093 
00094 
00098 class XALAN_XMLSUPPORT_EXPORT FormatterToXML : public FormatterListener 
00099 {
00100 public:
00101 
00102     enum eDummy
00103     {
00104         eDefaultIndentAmount = 0
00105     };
00106 
00128     FormatterToXML(
00129             Writer&                 writer,
00130             const XalanDOMString&   version = XalanDOMString(),
00131             bool                    doIndent = false,
00132             int                     indent = eDefaultIndentAmount,
00133             const XalanDOMString&   encoding = XalanDOMString(),
00134             const XalanDOMString&   mediaType = XalanDOMString(),
00135             const XalanDOMString&   doctypeSystem = XalanDOMString(),
00136             const XalanDOMString&   doctypePublic = XalanDOMString(),
00137             bool                    xmlDecl = true,
00138             const XalanDOMString&   standalone = XalanDOMString(),
00139             eFormat                 format = OUTPUT_METHOD_XML,
00140             bool                    fBufferData = true);
00141 
00142     virtual
00143     ~FormatterToXML();
00144 
00145 
00146     // These methods are inherited from FormatterListener ...
00147 
00148     virtual void
00149     setDocumentLocator(const LocatorType* const     locator);
00150 
00151     virtual void
00152     startDocument();
00153 
00154     virtual void
00155     endDocument();
00156 
00157     virtual void
00158     startElement(
00159             const XMLCh* const  name,
00160             AttributeListType&  attrs);
00161 
00162     virtual void
00163     endElement(const XMLCh* const   name);
00164 
00165     virtual void
00166     characters(
00167             const XMLCh* const  chars,
00168             const unsigned int  length);
00169 
00170     virtual void
00171     charactersRaw(
00172             const XMLCh* const  chars,
00173             const unsigned int  length);
00174 
00175     virtual void
00176     entityReference(const XMLCh* const  name);
00177 
00178     virtual void
00179     ignorableWhitespace(
00180             const XMLCh* const  chars,
00181             const unsigned int  length);
00182 
00183     virtual void
00184     processingInstruction(
00185             const XMLCh* const  target,
00186             const XMLCh* const  data);
00187 
00188 
00189     virtual void
00190     resetDocument();
00191 
00192     virtual void
00193     comment(const XMLCh* const  data);
00194 
00195     virtual void
00196     cdata(
00197             const XMLCh* const  ch,
00198             const unsigned int  length);
00199 
00200     const Writer*
00201     getWriter() const
00202     {
00203         return m_writer;
00204     }
00205 
00206     Writer*
00207     getWriter()
00208     {
00209         return m_writer;
00210     }
00211 
00212     const XalanDOMString&
00213     getDoctypeSystem() const
00214     {
00215         return m_doctypeSystem;
00216     }
00217 
00218     const XalanDOMString&
00219     getDoctypePublic() const
00220     {
00221         return m_doctypePublic;
00222     }
00223 
00224     const XalanDOMString&
00225     getEncoding() const
00226     {
00227         return m_encoding;
00228     }
00229 
00230     const XalanDOMString&
00231     getMediaType() const
00232     {
00233         return m_mediaType;
00234     }
00235 
00236     const XalanDOMString&
00237     getVersion() const
00238     {
00239         return m_version;
00240     }
00241 
00242     const XalanDOMString&
00243     getStandalone() const
00244     {
00245         return m_standalone;
00246     }
00247 
00248     bool
00249     getShouldWriteXMLHeader() const
00250     {
00251         return m_shouldWriteXMLHeader;
00252     }
00253 
00254     void
00255     setShouldWriteXMLHeader(bool    b)
00256     {
00257         m_shouldWriteXMLHeader = b;
00258     }
00259 
00260     bool
00261     getStripCData() const
00262     {
00263         return m_stripCData;
00264     }
00265 
00266     void
00267     setStripCData(bool  b)
00268     {
00269         m_stripCData = b;
00270     }
00271 
00272     bool
00273     getEscapeCData() const
00274     {
00275         return m_escapeCData;
00276     }
00277 
00278     void
00279     setEscapeCData(bool b)
00280     {
00281         m_escapeCData = b;
00282     }
00283 
00284     bool
00285     getDoIndent() const
00286     {
00287         return m_doIndent;
00288     }
00289 
00290     void
00291     setDoIndent(bool    value)
00292     {
00293         m_doIndent = value;
00294     }
00295 
00296     int
00297     getIndent() const
00298     {
00299         return m_indent;
00300     }
00301 
00302     void
00303     setIndent(int   value)
00304     {
00305         m_indent = value;
00306     }
00307 
00308 #if defined(XALAN_NO_STD_NAMESPACE)
00309 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
00310     typedef deque<bool>                 BoolVectorType;
00311 #else
00312     typedef vector<bool>                BoolStackType;
00313 #endif
00314     typedef vector<XalanDOMChar>        DOMCharBufferType;
00315     typedef vector<char>                ByteBufferType;
00316 #else
00317 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
00318     typedef std::deque<bool>        BoolVectorType;
00319 #else
00320     typedef std::vector<bool>           BoolStackType;
00321 #endif
00322     typedef std::vector<XalanDOMChar>   DOMCharBufferType;
00323     typedef std::vector<char>           ByteBufferType;
00324 #endif
00325 
00326 protected:
00327 
00331     Writer* const               m_writer;
00332 
00336     XalanOutputStream* const    m_stream;
00337 
00341     void
00342     outputLineSep();
00343 
00344     typedef void (FormatterToXML::*AccumCharFunctionType)(XalanDOMChar);
00345 
00346     typedef void (FormatterToXML::*AccumStringFunctionType)(const XalanDOMChar*);
00347 
00348     typedef void (FormatterToXML::*AccumDOMStringFunctionType)(const XalanDOMString&);
00349 
00350     typedef void (FormatterToXML::*AccumArrayFunctionType)(
00351                         const XalanDOMChar[],
00352                         XalanDOMString::size_type,
00353                         XalanDOMString::size_type);
00354 
00355     typedef void (FormatterToXML::*FlushFunctionType)();
00356 
00366     void
00367     accumName(XalanDOMChar  ch)
00368     {
00369         assert(m_accumNameCharFunction != 0);
00370 
00371         (this->*m_accumNameCharFunction)(ch);
00372     }
00373 
00379     void
00380     accumContent(XalanDOMChar   ch)
00381     {
00382         assert(m_accumContentCharFunction != 0);
00383 
00384         (this->*m_accumContentCharFunction)(ch);
00385     }
00386 
00397     void
00398     accumName(const XalanDOMChar*   chars)
00399     {
00400         assert(m_accumNameStringFunction != 0);
00401 
00402         (this->*m_accumNameStringFunction)(chars);
00403     }
00404 
00411     void
00412     accumContent(const XalanDOMChar*    chars)
00413     {
00414         assert(m_accumContentStringFunction != 0);
00415 
00416         (this->*m_accumContentStringFunction)(chars);
00417     }
00418 
00430     void
00431     accumName(
00432             const XalanDOMChar          chars[],
00433             XalanDOMString::size_type   start,
00434             XalanDOMString::size_type   length)
00435     {
00436         assert(m_accumNameArrayFunction != 0);
00437 
00438         (this->*m_accumNameArrayFunction)(chars, start, length);
00439     }
00440 
00448     void
00449     accumContent(
00450             const XalanDOMChar          chars[],
00451             XalanDOMString::size_type   start,
00452             XalanDOMString::size_type   length)
00453     {
00454         assert(m_accumContentArrayFunction != 0);
00455 
00456         (this->*m_accumContentArrayFunction)(chars, start, length);
00457     }
00458 
00468     void
00469     accumName(const XalanDOMString&     str)
00470     {
00471         assert(m_accumNameDOMStringFunction != 0);
00472 
00473         (this->*m_accumNameDOMStringFunction)(str);
00474     }
00475 
00481     void
00482     accumContent(const XalanDOMString&  str)
00483     {
00484         assert(m_accumContentDOMStringFunction != 0);
00485 
00486         (this->*m_accumContentDOMStringFunction)(str);
00487     }
00488 
00492     void
00493     accumDefaultEscape(
00494             XalanDOMChar                ch,
00495             XalanDOMString::size_type   i,
00496             const XalanDOMChar          chars[],
00497             XalanDOMString::size_type   len,
00498             bool                        escLF);
00499 
00504     virtual bool
00505     accumDefaultEntity(
00506             XalanDOMChar                ch,
00507             bool                        escLF);
00508 
00512     void
00513     initAttrCharsMap();
00514 
00518     void
00519     initCharsMap();
00520 
00524     void
00525     flushChars();
00526 
00530     void
00531     flushBytes();
00532 
00533     void
00534     flushWriter();
00535 
00536     void
00537     openElementForChildren();
00538 
00539     bool
00540     childNodesWereAdded();
00541 
00542     bool
00543     shouldIndent() const
00544     {
00545         return m_doIndent && (!m_ispreserve && !m_isprevtext);
00546     }
00547 
00552     void
00553     writeParentTagEnd();
00554 
00559     void
00560     indent(int  n);
00561 
00569     virtual void
00570     writeNormalizedChars(
00571             const XalanDOMChar          ch[],
00572             XalanDOMString::size_type   start,
00573             XalanDOMString::size_type   length,
00574             bool                        isCData);
00575 
00581     void
00582     writeNumberedEntityReference(unsigned long  theNumber);
00583 
00590     virtual void
00591     writeAttrString(
00592             const XalanDOMChar*         theString,
00593             XalanDOMString::size_type   theStringLength);
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 
01070     typedef XalanDOMString::size_type   size_type;
01071 
01075     static const XalanDOMChar   s_doctypeHeaderStartString[];
01076 
01077     static const size_type      s_doctypeHeaderStartStringLength;
01078 
01082     static const XalanDOMChar   s_doctypeHeaderPublicString[];
01083 
01084     static const size_type      s_doctypeHeaderPublicStringLength;
01085 
01089     static const XalanDOMChar   s_doctypeHeaderSystemString[];
01090 
01091     static const size_type      s_doctypeHeaderSystemStringLength;
01092 
01096     static const XalanDOMChar   s_xmlHeaderStartString[];
01097 
01098     static const size_type      s_xmlHeaderStartStringLength;
01099 
01103     static const XalanDOMChar   s_xmlHeaderEncodingString[];
01104 
01105     static const size_type      s_xmlHeaderEncodingStringLength;
01106 
01110     static const XalanDOMChar   s_xmlHeaderStandaloneString[];
01111 
01112     static const size_type      s_xmlHeaderStandaloneStringLength;
01113 
01117     static const XalanDOMChar   s_xmlHeaderEndString[];
01118 
01119     static const size_type      s_xmlHeaderEndStringLength;
01120 
01124     static const XalanDOMChar   s_defaultVersionString[];
01125 
01126     static const size_type      s_defaultVersionStringLength;
01127 
01131     static const XalanDOMChar   s_xhtmlDocTypeString[];
01132 
01133     static const size_type      s_xhtmlDocTypeStringLength;
01134 
01138     static const XalanDOMChar   s_dtdCDATACloseString[];
01139 
01140     static const size_type      s_dtdCDATACloseStringLength;
01141 
01142     DOMCharBufferType                           m_charBuf;
01143 
01144     DOMCharBufferType::size_type                m_pos;
01145 
01146     ByteBufferType                              m_byteBuf;
01147 
01148     static const DOMCharBufferType::size_type   s_maxBufferSize;
01149 
01154     BoolStackType   m_elemStack;
01155 
01160     AccumCharFunctionType       m_accumNameCharFunction;
01161 
01166     AccumStringFunctionType     m_accumNameStringFunction;
01167 
01172     AccumDOMStringFunctionType  m_accumNameDOMStringFunction;
01173 
01178     AccumArrayFunctionType      m_accumNameArrayFunction;
01179 
01184     AccumCharFunctionType       m_accumContentCharFunction;
01185 
01190     AccumStringFunctionType     m_accumContentStringFunction;
01191 
01196     AccumDOMStringFunctionType  m_accumContentDOMStringFunction;
01197 
01202     AccumArrayFunctionType      m_accumContentArrayFunction;
01203 
01207     FlushFunctionType           m_flushFunction;
01208 
01212     const XalanDOMChar*         m_newlineString;
01213 
01217     XalanDOMString::size_type   m_newlineStringLength;
01218 };
01219 
01220 
01221 
01222 XALAN_CPP_NAMESPACE_END
01223 
01224 
01225 
01226 #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++ XSLT Processor Version 1.5
Copyright © 2000, 2001, 2002, 2003 The Apache Software Foundation. All Rights Reserved.