Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.4

Main Page   Namespace List   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 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 
00125     FormatterToXML(
00126             Writer&                 writer,
00127             const XalanDOMString&   version = XalanDOMString(),
00128             bool                    doIndent = false,
00129             int                     indent = eDefaultIndentAmount,
00130             const XalanDOMString&   encoding = XalanDOMString(),
00131             const XalanDOMString&   mediaType = XalanDOMString(),
00132             const XalanDOMString&   doctypeSystem = XalanDOMString(),
00133             const XalanDOMString&   doctypePublic = XalanDOMString(),
00134             bool                    xmlDecl = true,
00135             const XalanDOMString&   standalone = XalanDOMString(),
00136             eFormat                 format = OUTPUT_METHOD_XML,
00137             bool                    fBufferData = true);
00138 
00139     virtual
00140     ~FormatterToXML();
00141 
00142 
00143     // These methods are inherited from FormatterListener ...
00144 
00145     virtual void
00146     setDocumentLocator(const Locator* const     locator);
00147 
00148     virtual void
00149     startDocument();
00150 
00151     virtual void
00152     endDocument();
00153 
00154     virtual void
00155     startElement(
00156             const XMLCh* const  name,
00157             AttributeList&      attrs);
00158 
00159     virtual void
00160     endElement(const XMLCh* const   name);
00161 
00162     virtual void
00163     characters(
00164             const XMLCh* const  chars,
00165             const unsigned int  length);
00166 
00167     virtual void
00168     charactersRaw(
00169             const XMLCh* const  chars,
00170             const unsigned int  length);
00171 
00172     virtual void
00173     entityReference(const XMLCh* const  name);
00174 
00175     virtual void
00176     ignorableWhitespace(
00177             const XMLCh* const  chars,
00178             const unsigned int  length);
00179 
00180     virtual void
00181     processingInstruction(
00182             const XMLCh* const  target,
00183             const XMLCh* const  data);
00184 
00185 
00186     virtual void
00187     resetDocument();
00188 
00189     virtual void
00190     comment(const XMLCh* const  data);
00191 
00192     virtual void
00193     cdata(
00194             const XMLCh* const  ch,
00195             const unsigned int  length);
00196 
00197     const Writer*
00198     getWriter() const
00199     {
00200         return m_writer;
00201     }
00202 
00203     Writer*
00204     getWriter()
00205     {
00206         return m_writer;
00207     }
00208 
00209     const XalanDOMString&
00210     getDoctypeSystem() const
00211     {
00212         return m_doctypeSystem;
00213     }
00214 
00215     const XalanDOMString&
00216     getDoctypePublic() const
00217     {
00218         return m_doctypePublic;
00219     }
00220 
00221     const XalanDOMString&
00222     getEncoding() const
00223     {
00224         return m_encoding;
00225     }
00226 
00227     const XalanDOMString&
00228     getMediaType() const
00229     {
00230         return m_mediaType;
00231     }
00232 
00233     const XalanDOMString&
00234     getVersion() const
00235     {
00236         return m_version;
00237     }
00238 
00239     const XalanDOMString&
00240     getStandalone() const
00241     {
00242         return m_standalone;
00243     }
00244 
00245     bool
00246     getShouldWriteXMLHeader() const
00247     {
00248         return m_shouldWriteXMLHeader;
00249     }
00250 
00251     void
00252     setShouldWriteXMLHeader(bool    b)
00253     {
00254         m_shouldWriteXMLHeader = b;
00255     }
00256 
00257     bool
00258     getStripCData() const
00259     {
00260         return m_stripCData;
00261     }
00262 
00263     void
00264     setStripCData(bool  b)
00265     {
00266         m_stripCData = b;
00267     }
00268 
00269     bool
00270     getEscapeCData() const
00271     {
00272         return m_escapeCData;
00273     }
00274 
00275     void
00276     setEscapeCData(bool b)
00277     {
00278         m_escapeCData = b;
00279     }
00280 
00281     bool
00282     getDoIndent() const
00283     {
00284         return m_doIndent;
00285     }
00286 
00287     void
00288     setDoIndent(bool    value)
00289     {
00290         m_doIndent = value;
00291     }
00292 
00293     int
00294     getIndent() const
00295     {
00296         return m_indent;
00297     }
00298 
00299     void
00300     setIndent(int   value)
00301     {
00302         m_indent = value;
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                         XalanDOMString::size_type,
00342                         XalanDOMString::size_type);
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             XalanDOMString::size_type   start,
00423             XalanDOMString::size_type   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             XalanDOMString::size_type   start,
00441             XalanDOMString::size_type   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             XalanDOMString::size_type   i,
00485             const XalanDOMChar          chars[],
00486             XalanDOMString::size_type   len,
00487             bool                        escLF);
00488 
00493     virtual bool
00494     accumDefaultEntity(
00495             XalanDOMChar                ch,
00496             XalanDOMString::size_type   i,
00497             const XalanDOMChar          chars[],
00498             XalanDOMString::size_type   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             XalanDOMString::size_type   start,
00565             XalanDOMString::size_type   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             XalanDOMChar    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             XalanDOMString::size_type   start,
00890             XalanDOMString::size_type   length);
00891 
00901     void
00902     accumContentArray(
00903             const XalanDOMChar          chars[],
00904             XalanDOMString::size_type   start,
00905             XalanDOMString::size_type   length);
00906 
00916     void
00917     accumArrayUTF(
00918             const XalanDOMChar          chars[],
00919             XalanDOMString::size_type   start,
00920             XalanDOMString::size_type   length);
00921 
00931     void
00932     accumArrayUTFDirect(
00933             const XalanDOMChar          chars[],
00934             XalanDOMString::size_type   start,
00935             XalanDOMString::size_type   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             XalanDOMString::size_type   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 
01058     typedef XalanDOMString::size_type   size_type;
01059 
01063     static const XalanDOMChar   s_doctypeHeaderStartString[];
01064 
01065     static const size_type      s_doctypeHeaderStartStringLength;
01066 
01070     static const XalanDOMChar   s_doctypeHeaderPublicString[];
01071 
01072     static const size_type      s_doctypeHeaderPublicStringLength;
01073 
01077     static const XalanDOMChar   s_doctypeHeaderSystemString[];
01078 
01079     static const size_type      s_doctypeHeaderSystemStringLength;
01080 
01084     static const XalanDOMChar   s_xmlHeaderStartString[];
01085 
01086     static const size_type      s_xmlHeaderStartStringLength;
01087 
01091     static const XalanDOMChar   s_xmlHeaderEncodingString[];
01092 
01093     static const size_type      s_xmlHeaderEncodingStringLength;
01094 
01098     static const XalanDOMChar   s_xmlHeaderStandaloneString[];
01099 
01100     static const size_type      s_xmlHeaderStandaloneStringLength;
01101 
01105     static const XalanDOMChar   s_xmlHeaderEndString[];
01106 
01107     static const size_type      s_xmlHeaderEndStringLength;
01108 
01112     static const XalanDOMChar   s_defaultVersionString[];
01113 
01114     static const size_type      s_defaultVersionStringLength;
01115 
01119     static const XalanDOMChar   s_xhtmlDocTypeString[];
01120 
01121     static const size_type      s_xhtmlDocTypeStringLength;
01122 
01126     static const XalanDOMChar   s_dtdCDATACloseString[];
01127 
01128     static const size_type      s_dtdCDATACloseStringLength;
01129 
01130     DOMCharBufferType                           m_charBuf;
01131 
01132     DOMCharBufferType::size_type                m_pos;
01133 
01134     ByteBufferType                              m_byteBuf;
01135 
01136     static const DOMCharBufferType::size_type   s_maxBufferSize;
01137 
01142     BoolStackType   m_elemStack;
01143 
01148     AccumCharFunctionType       m_accumNameCharFunction;
01149 
01154     AccumStringFunctionType     m_accumNameStringFunction;
01155 
01160     AccumDOMStringFunctionType  m_accumNameDOMStringFunction;
01161 
01166     AccumArrayFunctionType      m_accumNameArrayFunction;
01167 
01172     AccumCharFunctionType       m_accumContentCharFunction;
01173 
01178     AccumStringFunctionType     m_accumContentStringFunction;
01179 
01184     AccumDOMStringFunctionType  m_accumContentDOMStringFunction;
01185 
01190     AccumArrayFunctionType      m_accumContentArrayFunction;
01191 
01195     FlushFunctionType           m_flushFunction;
01196 };
01197 
01198 
01199 
01200 #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.4
Copyright © 2000, 2001, 2002 The Apache Software Foundation. All Rights Reserved.