## Xalan-C++ API Documentation

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

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

# FormatterToXML.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright 1999-2004 The Apache Software Foundation.
    00003  *
    00004  * Licensed under the Apache License, Version 2.0 (the "License");
    00005  * you may not use this file except in compliance with the License.
    00006  * You may obtain a copy of the License at
    00007  *
    00008  *     http://www.apache.org/licenses/LICENSE-2.0
    00009  *
    00010  * Unless required by applicable law or agreed to in writing, software
    00011  * distributed under the License is distributed on an "AS IS" BASIS,
    00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013  * See the License for the specific language governing permissions and
    00014  * limitations under the License.
    00015  */
    00016 #if !defined(FORMATTERTOXML_HEADER_GUARD_1357924680)
    00017 #define FORMATTERTOXML_HEADER_GUARD_1357924680
    00018
    00019
    00020
    00021
    00022 // Base include file.  Must be first.
    00023 #include <xalanc/XMLSupport/XMLSupportDefinitions.hpp>
    00024
    00025
    00026
    00027 #include <xalanc/Include/XalanVector.hpp>
    00028
    00029
    00030
    00031 #include <xalanc/XalanDOM/XalanDOMString.hpp>
    00032
    00033
    00034
    00035 #include <xalanc/PlatformSupport/DOMStringHelper.hpp>
    00036 #include <xalanc/PlatformSupport/XalanUnicode.hpp>
    00037
    00038
    00039
    00040 // Base class header file.
    00041 #include <xalanc/PlatformSupport/FormatterListener.hpp>
    00042
    00043
    00044
    00045 XALAN_CPP_NAMESPACE_BEGIN
    00046
    00047
    00048
    00049 class Writer;
    00050 class XalanOutputStream;
    00051
    00052
    00053
    00057 class XALAN_XMLSUPPORT_EXPORT FormatterToXML : public FormatterListener
    00058 {
    00059 public:
    00060
    00061     enum eDummy
    00062     {
    00063         eDefaultIndentAmount = 0
    00064     };
    00065
    00087     FormatterToXML(
    00088             Writer&                 writer,
    00089             const XalanDOMString&   version = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00090             bool                    doIndent = false,
    00091             int                     indent = eDefaultIndentAmount,
    00092             const XalanDOMString&   encoding = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00093             const XalanDOMString&   mediaType = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00094             const XalanDOMString&   doctypeSystem = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00095             const XalanDOMString&   doctypePublic = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00096             bool                    xmlDecl = true,
    00097             const XalanDOMString&   standalone = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00098             eFormat                 format = OUTPUT_METHOD_XML,
    00099             bool                    fBufferData = true,
    00100             MemoryManagerType&      theManager XALAN_DEFAULT_MEMMGR);
    00101
    00102     static FormatterToXML*
    00103     create(
    00104             MemoryManagerType&      theManager,
    00105             Writer&                 writer,
    00106             const XalanDOMString&   version = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00107             bool                    doIndent = false,
    00108             int                     indent = eDefaultIndentAmount,
    00109             const XalanDOMString&   encoding = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00110             const XalanDOMString&   mediaType = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00111             const XalanDOMString&   doctypeSystem = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00112             const XalanDOMString&   doctypePublic = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00113             bool                    xmlDecl = true,
    00114             const XalanDOMString&   standalone = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
    00115             eFormat                 format = OUTPUT_METHOD_XML,
    00116             bool                    fBufferData = true);
    00117
    00118     virtual
    00119     ~FormatterToXML();
    00120
    00121     MemoryManagerType&
    00122     getMemoryManager()
    00123     {
    00124         return m_stringBuffer.getMemoryManager();
    00125     }
    00126
    00127     // These methods are inherited from FormatterListener ...
    00128
    00129     virtual void
    00130     setDocumentLocator(const LocatorType* const     locator);
    00131
    00132     virtual void
    00133     startDocument();
    00134
    00135     virtual void
    00136     endDocument();
    00137
    00138     virtual void
    00139     startElement(
    00140             const XMLCh* const  name,
    00141             AttributeListType&  attrs);
    00142
    00143     virtual void
    00144     endElement(const XMLCh* const   name);
    00145
    00146     virtual void
    00147     characters(
    00148             const XMLCh* const  chars,
    00149             const unsigned int  length);
    00150
    00151     virtual void
    00152     charactersRaw(
    00153             const XMLCh* const  chars,
    00154             const unsigned int  length);
    00155
    00156     virtual void
    00157     entityReference(const XMLCh* const  name);
    00158
    00159     virtual void
    00160     ignorableWhitespace(
    00161             const XMLCh* const  chars,
    00162             const unsigned int  length);
    00163
    00164     virtual void
    00165     processingInstruction(
    00166             const XMLCh* const  target,
    00167             const XMLCh* const  data);
    00168
    00169
    00170     virtual void
    00171     resetDocument();
    00172
    00173     virtual void
    00174     comment(const XMLCh* const  data);
    00175
    00176     virtual void
    00177     cdata(
    00178             const XMLCh* const  ch,
    00179             const unsigned int  length);
    00180
    00181     virtual Writer*
    00182     getWriter() const;
    00183
    00184     virtual const XalanDOMString&
    00185     getDoctypeSystem() const;
    00186
    00187     virtual const XalanDOMString&
    00188     getDoctypePublic() const;
    00189
    00190     virtual const XalanDOMString&
    00191     getEncoding() const;
    00192
    00193     virtual const XalanDOMString&
    00194     getMediaType() const;
    00195
    00196     virtual int
    00197     getIndent() const;
    00198
    00199     const XalanDOMString&
    00200     getVersion() const
    00201     {
    00202         return m_version;
    00203     }
    00204
    00205     const XalanDOMString&
    00206     getStandalone() const
    00207     {
    00208         return m_standalone;
    00209     }
    00210
    00211     bool
    00212     getShouldWriteXMLHeader() const
    00213     {
    00214         return m_shouldWriteXMLHeader;
    00215     }
    00216
    00217     void
    00218     setShouldWriteXMLHeader(bool    b)
    00219     {
    00220         m_shouldWriteXMLHeader = b;
    00221     }
    00222
    00223     bool
    00224     getStripCData() const
    00225     {
    00226         return m_stripCData;
    00227     }
    00228
    00229     void
    00230     setStripCData(bool  b)
    00231     {
    00232         m_stripCData = b;
    00233     }
    00234
    00235     bool
    00236     getEscapeCData() const
    00237     {
    00238         return m_escapeCData;
    00239     }
    00240
    00241     void
    00242     setEscapeCData(bool b)
    00243     {
    00244         m_escapeCData = b;
    00245     }
    00246
    00247     bool
    00248     getDoIndent() const
    00249     {
    00250         return m_doIndent;
    00251     }
    00252
    00253     void
    00254     setDoIndent(bool    value)
    00255     {
    00256         m_doIndent = value;
    00257     }
    00258
    00259     void
    00260     setIndent(int   value)
    00261     {
    00262         m_indent = value;
    00263     }
    00264
    00265
    00266     typedef XalanVector<bool>           BoolStackType;
    00267     typedef XalanVector<XalanDOMChar>   DOMCharBufferType;
    00268     typedef XalanVector<char>           ByteBufferType;
    00269
    00270
    00271 protected:
    00272
    00276     Writer* const               m_writer;
    00277
    00281     XalanOutputStream* const    m_stream;
    00282
    00286     void
    00287     outputLineSep();
    00288
    00289     typedef void (FormatterToXML::*AccumCharFunctionType)(XalanDOMChar);
    00290
    00291     typedef void (FormatterToXML::*AccumStringFunctionType)(const XalanDOMChar*);
    00292
    00293     typedef void (FormatterToXML::*AccumDOMStringFunctionType)(const XalanDOMString&);
    00294
    00295     typedef void (FormatterToXML::*AccumArrayFunctionType)(
    00296                         const XalanDOMChar[],
    00297                         XalanDOMString::size_type,
    00298                         XalanDOMString::size_type);
    00299
    00300     typedef void (FormatterToXML::*FlushFunctionType)();
    00301
    00311     void
    00312     accumName(XalanDOMChar  ch)
    00313     {
    00314         assert(m_accumNameCharFunction != 0);
    00315
    00316         (this->*m_accumNameCharFunction)(ch);
    00317     }
    00318
    00324     void
    00325     accumContent(XalanDOMChar   ch)
    00326     {
    00327         assert(m_accumContentCharFunction != 0);
    00328
    00329         (this->*m_accumContentCharFunction)(ch);
    00330     }
    00331
    00342     void
    00343     accumName(const XalanDOMChar*   chars)
    00344     {
    00345         assert(m_accumNameStringFunction != 0);
    00346
    00347         (this->*m_accumNameStringFunction)(chars);
    00348     }
    00349
    00356     void
    00357     accumContent(const XalanDOMChar*    chars)
    00358     {
    00359         assert(m_accumContentStringFunction != 0);
    00360
    00361         (this->*m_accumContentStringFunction)(chars);
    00362     }
    00363
    00375     void
    00376     accumName(
    00377             const XalanDOMChar          chars[],
    00378             XalanDOMString::size_type   start,
    00379             XalanDOMString::size_type   length)
    00380     {
    00381         assert(m_accumNameArrayFunction != 0);
    00382
    00383         (this->*m_accumNameArrayFunction)(chars, start, length);
    00384     }
    00385
    00393     void
    00394     accumContent(
    00395             const XalanDOMChar          chars[],
    00396             XalanDOMString::size_type   start,
    00397             XalanDOMString::size_type   length)
    00398     {
    00399         assert(m_accumContentArrayFunction != 0);
    00400
    00401         (this->*m_accumContentArrayFunction)(chars, start, length);
    00402     }
    00403
    00413     void
    00414     accumName(const XalanDOMString&     str)
    00415     {
    00416         assert(m_accumNameDOMStringFunction != 0);
    00417
    00418         (this->*m_accumNameDOMStringFunction)(str);
    00419     }
    00420
    00426     void
    00427     accumContent(const XalanDOMString&  str)
    00428     {
    00429         assert(m_accumContentDOMStringFunction != 0);
    00430
    00431         (this->*m_accumContentDOMStringFunction)(str);
    00432     }
    00433
    00437     XalanDOMString::size_type
    00438     accumDefaultEscape(
    00439             XalanDOMChar                ch,
    00440             XalanDOMString::size_type   i,
    00441             const XalanDOMChar          chars[],
    00442             XalanDOMString::size_type   len,
    00443             bool                        escLF);
    00444
    00449     virtual bool
    00450     accumDefaultEntity(
    00451             XalanDOMChar    ch,
    00452             bool            escLF);
    00453
    00457     void
    00458     initAttrCharsMap();
    00459
    00463     void
    00464     initCharsMap();
    00465
    00469     void
    00470     flushChars();
    00471
    00475     void
    00476     flushBytes();
    00477
    00478     void
    00479     flushWriter();
    00480
    00481     void
    00482     openElementForChildren();
    00483
    00484     bool
    00485     childNodesWereAdded();
    00486
    00487     bool
    00488     shouldIndent() const
    00489     {
    00490         return m_doIndent && (!m_ispreserve && !m_isprevtext);
    00491     }
    00492
    00497     void
    00498     writeParentTagEnd();
    00499
    00504     void
    00505     indent(int  n);
    00506
    00514     virtual void
    00515     writeNormalizedChars(
    00516             const XalanDOMChar          ch[],
    00517             XalanDOMString::size_type   start,
    00518             XalanDOMString::size_type   length,
    00519             bool                        isCData);
    00520
    00526     void
    00527     writeNumberedEntityReference(unsigned long  theNumber);
    00528
    00535     virtual void
    00536     writeAttrString(
    00537             const XalanDOMChar*         theString,
    00538             XalanDOMString::size_type   theStringLength);
    00539
    00544     virtual void
    00545     accumCommentData(const XalanDOMChar*    data);
    00546
    00552     static void
    00553     throwInvalidUTF16SurrogateException(XalanDOMChar    ch,
    00554                                         MemoryManagerType& theManager);
    00555
    00562     static void
    00563     throwInvalidUTF16SurrogateException(
    00564             XalanDOMChar    ch,
    00565             XalanDOMChar    next,
    00566             MemoryManagerType& theManager);
    00567
    00568     static bool
    00569     isUTF16Surrogate(XalanDOMChar   ch)
    00570     {
    00571         return (ch & 0xFC00) == 0xD800 ? true : false;
    00572     }
    00573
    00574     enum eDummyTwo { SPECIALSSIZE = 256};
    00575
    00580     XalanDOMChar            m_maxCharacter;
    00581
    00582     XalanDOMChar            m_attrCharsMap[SPECIALSSIZE];
    00583
    00584     XalanDOMChar            m_charsMap[SPECIALSSIZE];
    00585
    00589     bool        m_shouldWriteXMLHeader;
    00590
    00595     bool        m_ispreserve;
    00596
    00600     bool        m_doIndent;
    00601
    00605     bool        m_startNewLine;
    00606
    00612     bool        m_needToOutputDocTypeDecl;
    00613
    00618     bool        m_isprevtext;
    00619
    00624     bool        m_stripCData;
    00625
    00629     bool        m_nextIsRaw;
    00630
    00634     bool        m_inCData;
    00635
    00640     bool        m_encodingIsUTF;
    00641
    00645     const XalanDOMString    m_doctypeSystem;
    00646
    00650     const XalanDOMString    m_doctypePublic;
    00651
    00655     XalanDOMString  m_encoding;
    00656
    00660     int     m_currentIndent;
    00661
    00665     int     m_indent;
    00666
    00671     BoolStackType   m_preserves;
    00672
    00673     // A text buffer.  We use it mostly for converting
    00674     // to string values.  See uses of UnsignedLongToString()
    00675     // and UnsignedLongToHexString().
    00676     XalanDOMString  m_stringBuffer;
    00677
    00678 private:
    00679
    00680     // These are not implemented.
    00681     FormatterToXML(const FormatterToXML&);
    00682
    00683     FormatterToXML&
    00684     operator=(const FormatterToXML&);
    00685
    00686     bool
    00687     operator==(const FormatterToXML&) const;
    00688
    00697     void
    00698     accumNameAsByte(XalanDOMChar    ch);
    00699
    00708     void
    00709     accumNameAsByteDirect(XalanDOMChar  ch);
    00710
    00718     void
    00719     accumContentAsByte(XalanDOMChar     ch);
    00720
    00728     void
    00729     accumContentAsByteDirect(XalanDOMChar   ch);
    00730
    00739     void
    00740     accumNameAsChar(XalanDOMChar    ch);
    00741
    00750     void
    00751     accumNameAsCharDirect(XalanDOMChar  ch);
    00752
    00758     void
    00759     accumContentAsChar(XalanDOMChar     ch);
    00760
    00766     void
    00767     accumContentAsCharDirect(XalanDOMChar   ch);
    00768
    00776     void
    00777     accumCharUTF(XalanDOMChar   ch);
    00778
    00786     void
    00787     accumCharUTFDirect(XalanDOMChar ch);
    00788
    00797     void
    00798     accumNameString(const XalanDOMChar* chars);
    00799
    00807     void
    00808     accumStringUTF(const XalanDOMChar*  chars);
    00809
    00817     void
    00818     accumStringUTFDirect(const XalanDOMChar*    chars);
    00819
    00827     void
    00828     accumContentString(const XalanDOMChar*  chars);
    00829
    00839     void
    00840     accumNameArray(
    00841             const XalanDOMChar          chars[],
    00842             XalanDOMString::size_type   start,
    00843             XalanDOMString::size_type   length);
    00844
    00854     void
    00855     accumContentArray(
    00856             const XalanDOMChar          chars[],
    00857             XalanDOMString::size_type   start,
    00858             XalanDOMString::size_type   length);
    00859
    00869     void
    00870     accumArrayUTF(
    00871             const XalanDOMChar          chars[],
    00872             XalanDOMString::size_type   start,
    00873             XalanDOMString::size_type   length);
    00874
    00884     void
    00885     accumArrayUTFDirect(
    00886             const XalanDOMChar          chars[],
    00887             XalanDOMString::size_type   start,
    00888             XalanDOMString::size_type   length);
    00889
    00897     void
    00898     accumNameDOMString(const XalanDOMString&    str);
    00899
    00907     void
    00908     accumContentDOMString(const XalanDOMString& str);
    00909
    00917     void
    00918     accumDOMStringUTF(const XalanDOMString& str);
    00919
    00927     void
    00928     accumDOMStringUTFDirect(const XalanDOMString&   str);
    00929
    00935     void
    00936     outputDocTypeDecl(const XalanDOMChar*   name);
    00937
    00943     void
    00944     processAttribute(
    00945             const XalanDOMChar*     name,
    00946             const XalanDOMChar*     value);
    00947
    00952     void
    00953     printSpace(int n);
    00954
    00960     void
    00961     accumNormalizedPIData(
    00962             const XalanDOMChar*         theData,
    00963             XalanDOMString::size_type   theLength);
    00964
    00965
    00966     // Data members...
    00970     bool        m_bytesEqualChars;
    00971
    00972     bool        m_shouldFlush;
    00973
    00977     bool        m_spaceBeforeClose;
    00978
    00984     bool        m_escapeCData;
    00985
    00989     bool        m_inEntityRef;
    00990
    00994     const XalanDOMString    m_version;
    00995
    00999     const XalanDOMString    m_standalone;
    01000
    01004     const XalanDOMString    m_mediaType;
    01005
    01009     const XalanDOMString    m_attrSpecialChars;
    01010
    01011     typedef XalanDOMString::size_type   size_type;
    01012
    01016     static const XalanDOMChar   s_doctypeHeaderStartString[];
    01017
    01018     static const size_type      s_doctypeHeaderStartStringLength;
    01019
    01023     static const XalanDOMChar   s_doctypeHeaderPublicString[];
    01024
    01025     static const size_type      s_doctypeHeaderPublicStringLength;
    01026
    01030     static const XalanDOMChar   s_doctypeHeaderSystemString[];
    01031
    01032     static const size_type      s_doctypeHeaderSystemStringLength;
    01033
    01037     static const XalanDOMChar   s_xmlHeaderStartString[];
    01038
    01039     static const size_type      s_xmlHeaderStartStringLength;
    01040
    01044     static const XalanDOMChar   s_xmlHeaderEncodingString[];
    01045
    01046     static const size_type      s_xmlHeaderEncodingStringLength;
    01047
    01051     static const XalanDOMChar   s_xmlHeaderStandaloneString[];
    01052
    01053     static const size_type      s_xmlHeaderStandaloneStringLength;
    01054
    01058     static const XalanDOMChar   s_xmlHeaderEndString[];
    01059
    01060     static const size_type      s_xmlHeaderEndStringLength;
    01061
    01065     static const XalanDOMChar   s_defaultVersionString[];
    01066
    01067     static const size_type      s_defaultVersionStringLength;
    01068
    01072     static const XalanDOMChar   s_xhtmlDocTypeString[];
    01073
    01074     static const size_type      s_xhtmlDocTypeStringLength;
    01075
    01079     static const XalanDOMChar   s_dtdCDATACloseString[];
    01080
    01081     static const size_type      s_dtdCDATACloseStringLength;
    01082
    01083     DOMCharBufferType                           m_charBuf;
    01084
    01085     XalanDOMString::size_type                   m_pos;
    01086
    01087     ByteBufferType                              m_byteBuf;
    01088
    01089     static const XalanDOMString::size_type      s_maxBufferSize;
    01090
    01095     BoolStackType   m_elemStack;
    01096
    01101     AccumCharFunctionType       m_accumNameCharFunction;
    01102
    01107     AccumStringFunctionType     m_accumNameStringFunction;
    01108
    01113     AccumDOMStringFunctionType  m_accumNameDOMStringFunction;
    01114
    01119     AccumArrayFunctionType      m_accumNameArrayFunction;
    01120
    01125     AccumCharFunctionType       m_accumContentCharFunction;
    01126
    01131     AccumStringFunctionType     m_accumContentStringFunction;
    01132
    01137     AccumDOMStringFunctionType  m_accumContentDOMStringFunction;
    01138
    01143     AccumArrayFunctionType      m_accumContentArrayFunction;
    01144
    01148     FlushFunctionType           m_flushFunction;
    01149
    01153     const XalanDOMChar*         m_newlineString;
    01154
    01158     XalanDOMString::size_type   m_newlineStringLength;
    01159 };
    01160
    01161
    01162
    01163 XALAN_CPP_NAMESPACE_END
    01164
    01165
    01166
    01167 #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.9 Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.