## Xalan-C++ API Documentation

### The Xalan C++ XSLT Processor Version 1.6

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-2003 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 <xalanc/XMLSupport/XMLSupportDefinitions.hpp>
    00065
    00066
    00067
    00068 #include <vector>
    00069
    00070
    00071
    00072 #include <xalanc/XalanDOM/XalanDOMString.hpp>
    00073
    00074
    00075
    00076 #include <xalanc/PlatformSupport/DOMStringHelper.hpp>
    00077 #include <xalanc/PlatformSupport/XalanUnicode.hpp>
    00078
    00079
    00080
    00081 // Base class header file.
    00082 #include <xalanc/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     virtual Writer*
    00201     getWriter() const;
    00202
    00203     virtual const XalanDOMString&
    00204     getDoctypeSystem() const;
    00205
    00206     virtual const XalanDOMString&
    00207     getDoctypePublic() const;
    00208
    00209     virtual const XalanDOMString&
    00210     getEncoding() const;
    00211
    00212     virtual const XalanDOMString&
    00213     getMediaType() const;
    00214
    00215     virtual int
    00216     getIndent() const;
    00217
    00218     const XalanDOMString&
    00219     getVersion() const
    00220     {
    00221         return m_version;
    00222     }
    00223
    00224     const XalanDOMString&
    00225     getStandalone() const
    00226     {
    00227         return m_standalone;
    00228     }
    00229
    00230     bool
    00231     getShouldWriteXMLHeader() const
    00232     {
    00233         return m_shouldWriteXMLHeader;
    00234     }
    00235
    00236     void
    00237     setShouldWriteXMLHeader(bool    b)
    00238     {
    00239         m_shouldWriteXMLHeader = b;
    00240     }
    00241
    00242     bool
    00243     getStripCData() const
    00244     {
    00245         return m_stripCData;
    00246     }
    00247
    00248     void
    00249     setStripCData(bool  b)
    00250     {
    00251         m_stripCData = b;
    00252     }
    00253
    00254     bool
    00255     getEscapeCData() const
    00256     {
    00257         return m_escapeCData;
    00258     }
    00259
    00260     void
    00261     setEscapeCData(bool b)
    00262     {
    00263         m_escapeCData = b;
    00264     }
    00265
    00266     bool
    00267     getDoIndent() const
    00268     {
    00269         return m_doIndent;
    00270     }
    00271
    00272     void
    00273     setDoIndent(bool    value)
    00274     {
    00275         m_doIndent = value;
    00276     }
    00277
    00278     void
    00279     setIndent(int   value)
    00280     {
    00281         m_indent = value;
    00282     }
    00283
    00284 #if defined(XALAN_NO_STD_NAMESPACE)
    00285 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
    00286     typedef deque<bool>                 BoolVectorType;
    00287 #else
    00288     typedef vector<bool>                BoolStackType;
    00289 #endif
    00290     typedef vector<XalanDOMChar>        DOMCharBufferType;
    00291     typedef vector<char>                ByteBufferType;
    00292 #else
    00293 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
    00294     typedef std::deque<bool>        BoolVectorType;
    00295 #else
    00296     typedef std::vector<bool>           BoolStackType;
    00297 #endif
    00298     typedef std::vector<XalanDOMChar>   DOMCharBufferType;
    00299     typedef std::vector<char>           ByteBufferType;
    00300 #endif
    00301
    00302 protected:
    00303
    00307     Writer* const               m_writer;
    00308
    00312     XalanOutputStream* const    m_stream;
    00313
    00317     void
    00318     outputLineSep();
    00319
    00320     typedef void (FormatterToXML::*AccumCharFunctionType)(XalanDOMChar);
    00321
    00322     typedef void (FormatterToXML::*AccumStringFunctionType)(const XalanDOMChar*);
    00323
    00324     typedef void (FormatterToXML::*AccumDOMStringFunctionType)(const XalanDOMString&);
    00325
    00326     typedef void (FormatterToXML::*AccumArrayFunctionType)(
    00327                         const XalanDOMChar[],
    00328                         XalanDOMString::size_type,
    00329                         XalanDOMString::size_type);
    00330
    00331     typedef void (FormatterToXML::*FlushFunctionType)();
    00332
    00342     void
    00343     accumName(XalanDOMChar  ch)
    00344     {
    00345         assert(m_accumNameCharFunction != 0);
    00346
    00347         (this->*m_accumNameCharFunction)(ch);
    00348     }
    00349
    00355     void
    00356     accumContent(XalanDOMChar   ch)
    00357     {
    00358         assert(m_accumContentCharFunction != 0);
    00359
    00360         (this->*m_accumContentCharFunction)(ch);
    00361     }
    00362
    00373     void
    00374     accumName(const XalanDOMChar*   chars)
    00375     {
    00376         assert(m_accumNameStringFunction != 0);
    00377
    00378         (this->*m_accumNameStringFunction)(chars);
    00379     }
    00380
    00387     void
    00388     accumContent(const XalanDOMChar*    chars)
    00389     {
    00390         assert(m_accumContentStringFunction != 0);
    00391
    00392         (this->*m_accumContentStringFunction)(chars);
    00393     }
    00394
    00406     void
    00407     accumName(
    00408             const XalanDOMChar          chars[],
    00409             XalanDOMString::size_type   start,
    00410             XalanDOMString::size_type   length)
    00411     {
    00412         assert(m_accumNameArrayFunction != 0);
    00413
    00414         (this->*m_accumNameArrayFunction)(chars, start, length);
    00415     }
    00416
    00424     void
    00425     accumContent(
    00426             const XalanDOMChar          chars[],
    00427             XalanDOMString::size_type   start,
    00428             XalanDOMString::size_type   length)
    00429     {
    00430         assert(m_accumContentArrayFunction != 0);
    00431
    00432         (this->*m_accumContentArrayFunction)(chars, start, length);
    00433     }
    00434
    00444     void
    00445     accumName(const XalanDOMString&     str)
    00446     {
    00447         assert(m_accumNameDOMStringFunction != 0);
    00448
    00449         (this->*m_accumNameDOMStringFunction)(str);
    00450     }
    00451
    00457     void
    00458     accumContent(const XalanDOMString&  str)
    00459     {
    00460         assert(m_accumContentDOMStringFunction != 0);
    00461
    00462         (this->*m_accumContentDOMStringFunction)(str);
    00463     }
    00464
    00468     XalanDOMString::size_type
    00469     accumDefaultEscape(
    00470             XalanDOMChar                ch,
    00471             XalanDOMString::size_type   i,
    00472             const XalanDOMChar          chars[],
    00473             XalanDOMString::size_type   len,
    00474             bool                        escLF);
    00475
    00480     virtual bool
    00481     accumDefaultEntity(
    00482             XalanDOMChar    ch,
    00483             bool            escLF);
    00484
    00488     void
    00489     initAttrCharsMap();
    00490
    00494     void
    00495     initCharsMap();
    00496
    00500     void
    00501     flushChars();
    00502
    00506     void
    00507     flushBytes();
    00508
    00509     void
    00510     flushWriter();
    00511
    00512     void
    00513     openElementForChildren();
    00514
    00515     bool
    00516     childNodesWereAdded();
    00517
    00518     bool
    00519     shouldIndent() const
    00520     {
    00521         return m_doIndent && (!m_ispreserve && !m_isprevtext);
    00522     }
    00523
    00528     void
    00529     writeParentTagEnd();
    00530
    00535     void
    00536     indent(int  n);
    00537
    00545     virtual void
    00546     writeNormalizedChars(
    00547             const XalanDOMChar          ch[],
    00548             XalanDOMString::size_type   start,
    00549             XalanDOMString::size_type   length,
    00550             bool                        isCData);
    00551
    00557     void
    00558     writeNumberedEntityReference(unsigned long  theNumber);
    00559
    00566     virtual void
    00567     writeAttrString(
    00568             const XalanDOMChar*         theString,
    00569             XalanDOMString::size_type   theStringLength);
    00570
    00575     virtual void
    00576     accumCommentData(const XalanDOMChar*    data);
    00577
    00583     static void
    00584     throwInvalidUTF16SurrogateException(XalanDOMChar    ch);
    00585
    00592     static void
    00593     throwInvalidUTF16SurrogateException(
    00594             XalanDOMChar    ch,
    00595             XalanDOMChar    next);
    00596
    00597     static bool
    00598     isUTF16Surrogate(XalanDOMChar   ch)
    00599     {
    00600         return (ch & 0xFC00) == 0xD800 ? true : false;
    00601     }
    00602
    00603     enum eDummyTwo { SPECIALSSIZE = 256};
    00604
    00609     XalanDOMChar            m_maxCharacter;
    00610
    00611     XalanDOMChar            m_attrCharsMap[SPECIALSSIZE];
    00612
    00613     XalanDOMChar            m_charsMap[SPECIALSSIZE];
    00614
    00618     bool        m_shouldWriteXMLHeader;
    00619
    00624     bool        m_ispreserve;
    00625
    00629     bool        m_doIndent;
    00630
    00634     bool        m_startNewLine;
    00635
    00641     bool        m_needToOutputDocTypeDecl;
    00642
    00647     bool        m_isprevtext;
    00648
    00653     bool        m_stripCData;
    00654
    00658     bool        m_nextIsRaw;
    00659
    00663     bool        m_inCData;
    00664
    00669     bool        m_encodingIsUTF;
    00670
    00674     const XalanDOMString    m_doctypeSystem;
    00675
    00679     const XalanDOMString    m_doctypePublic;
    00680
    00684     XalanDOMString  m_encoding;
    00685
    00689     int     m_currentIndent;
    00690
    00694     int     m_indent;
    00695
    00700     BoolStackType   m_preserves;
    00701
    00702     // A text buffer.  We use it mostly for converting
    00703     // to string values.  See uses of UnsignedLongToString()
    00704     // and UnsignedLongToHexString().
    00705     XalanDOMString  m_stringBuffer;
    00706
    00707 private:
    00708
    00709     // These are not implemented.
    00710     FormatterToXML(const FormatterToXML&);
    00711
    00712     FormatterToXML&
    00713     operator=(const FormatterToXML&);
    00714
    00715     bool
    00716     operator==(const FormatterToXML&) const;
    00717
    00726     void
    00727     accumNameAsByte(XalanDOMChar    ch);
    00728
    00737     void
    00738     accumNameAsByteDirect(XalanDOMChar  ch);
    00739
    00747     void
    00748     accumContentAsByte(XalanDOMChar     ch);
    00749
    00757     void
    00758     accumContentAsByteDirect(XalanDOMChar   ch);
    00759
    00768     void
    00769     accumNameAsChar(XalanDOMChar    ch);
    00770
    00779     void
    00780     accumNameAsCharDirect(XalanDOMChar  ch);
    00781
    00787     void
    00788     accumContentAsChar(XalanDOMChar     ch);
    00789
    00795     void
    00796     accumContentAsCharDirect(XalanDOMChar   ch);
    00797
    00805     void
    00806     accumCharUTF(XalanDOMChar   ch);
    00807
    00815     void
    00816     accumCharUTFDirect(XalanDOMChar ch);
    00817
    00826     void
    00827     accumNameString(const XalanDOMChar* chars);
    00828
    00836     void
    00837     accumStringUTF(const XalanDOMChar*  chars);
    00838
    00846     void
    00847     accumStringUTFDirect(const XalanDOMChar*    chars);
    00848
    00856     void
    00857     accumContentString(const XalanDOMChar*  chars);
    00858
    00868     void
    00869     accumNameArray(
    00870             const XalanDOMChar          chars[],
    00871             XalanDOMString::size_type   start,
    00872             XalanDOMString::size_type   length);
    00873
    00883     void
    00884     accumContentArray(
    00885             const XalanDOMChar          chars[],
    00886             XalanDOMString::size_type   start,
    00887             XalanDOMString::size_type   length);
    00888
    00898     void
    00899     accumArrayUTF(
    00900             const XalanDOMChar          chars[],
    00901             XalanDOMString::size_type   start,
    00902             XalanDOMString::size_type   length);
    00903
    00913     void
    00914     accumArrayUTFDirect(
    00915             const XalanDOMChar          chars[],
    00916             XalanDOMString::size_type   start,
    00917             XalanDOMString::size_type   length);
    00918
    00926     void
    00927     accumNameDOMString(const XalanDOMString&    str);
    00928
    00936     void
    00937     accumContentDOMString(const XalanDOMString& str);
    00938
    00946     void
    00947     accumDOMStringUTF(const XalanDOMString& str);
    00948
    00956     void
    00957     accumDOMStringUTFDirect(const XalanDOMString&   str);
    00958
    00964     void
    00965     outputDocTypeDecl(const XalanDOMChar*   name);
    00966
    00972     void
    00973     processAttribute(
    00974             const XalanDOMChar*     name,
    00975             const XalanDOMChar*     value);
    00976
    00981     void
    00982     printSpace(int n);
    00983
    00989     void
    00990     accumNormalizedPIData(
    00991             const XalanDOMChar*         theData,
    00992             XalanDOMString::size_type   theLength);
    00993
    00994
    00995     // Data members...
    00999     bool        m_bytesEqualChars;
    01000
    01001     bool        m_shouldFlush;
    01002
    01006     bool        m_spaceBeforeClose;
    01007
    01013     bool        m_escapeCData;
    01014
    01018     bool        m_inEntityRef;
    01019
    01023     const XalanDOMString    m_version;
    01024
    01028     const XalanDOMString    m_standalone;
    01029
    01033     const XalanDOMString    m_mediaType;
    01034
    01038     const XalanDOMString    m_attrSpecialChars;
    01039
    01040     typedef XalanDOMString::size_type   size_type;
    01041
    01045     static const XalanDOMChar   s_doctypeHeaderStartString[];
    01046
    01047     static const size_type      s_doctypeHeaderStartStringLength;
    01048
    01052     static const XalanDOMChar   s_doctypeHeaderPublicString[];
    01053
    01054     static const size_type      s_doctypeHeaderPublicStringLength;
    01055
    01059     static const XalanDOMChar   s_doctypeHeaderSystemString[];
    01060
    01061     static const size_type      s_doctypeHeaderSystemStringLength;
    01062
    01066     static const XalanDOMChar   s_xmlHeaderStartString[];
    01067
    01068     static const size_type      s_xmlHeaderStartStringLength;
    01069
    01073     static const XalanDOMChar   s_xmlHeaderEncodingString[];
    01074
    01075     static const size_type      s_xmlHeaderEncodingStringLength;
    01076
    01080     static const XalanDOMChar   s_xmlHeaderStandaloneString[];
    01081
    01082     static const size_type      s_xmlHeaderStandaloneStringLength;
    01083
    01087     static const XalanDOMChar   s_xmlHeaderEndString[];
    01088
    01089     static const size_type      s_xmlHeaderEndStringLength;
    01090
    01094     static const XalanDOMChar   s_defaultVersionString[];
    01095
    01096     static const size_type      s_defaultVersionStringLength;
    01097
    01101     static const XalanDOMChar   s_xhtmlDocTypeString[];
    01102
    01103     static const size_type      s_xhtmlDocTypeStringLength;
    01104
    01108     static const XalanDOMChar   s_dtdCDATACloseString[];
    01109
    01110     static const size_type      s_dtdCDATACloseStringLength;
    01111
    01112     DOMCharBufferType                           m_charBuf;
    01113
    01114     DOMCharBufferType::size_type                m_pos;
    01115
    01116     ByteBufferType                              m_byteBuf;
    01117
    01118     static const DOMCharBufferType::size_type   s_maxBufferSize;
    01119
    01124     BoolStackType   m_elemStack;
    01125
    01130     AccumCharFunctionType       m_accumNameCharFunction;
    01131
    01136     AccumStringFunctionType     m_accumNameStringFunction;
    01137
    01142     AccumDOMStringFunctionType  m_accumNameDOMStringFunction;
    01143
    01148     AccumArrayFunctionType      m_accumNameArrayFunction;
    01149
    01154     AccumCharFunctionType       m_accumContentCharFunction;
    01155
    01160     AccumStringFunctionType     m_accumContentStringFunction;
    01161
    01166     AccumDOMStringFunctionType  m_accumContentDOMStringFunction;
    01167
    01172     AccumArrayFunctionType      m_accumContentArrayFunction;
    01173
    01177     FlushFunctionType           m_flushFunction;
    01178
    01182     const XalanDOMChar*         m_newlineString;
    01183
    01187     XalanDOMString::size_type   m_newlineStringLength;
    01188 };
    01189
    01190
    01191
    01192 XALAN_CPP_NAMESPACE_END
    01193
    01194
    01195
    01196 #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.6 Copyright © 2000, 2001, 2002, 2003 The Apache Software Foundation. All Rights Reserved.