Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

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  * 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 
00553     static void
00554     throwInvalidUTF16SurrogateException(
00555             XalanDOMChar        ch,
00556             MemoryManagerType&  theManager);
00557 
00565     static void
00566     throwInvalidUTF16SurrogateException(
00567             XalanDOMChar        ch,
00568             XalanDOMChar        next,
00569             MemoryManagerType& theManager);
00570 
00571 
00578     static void
00579     throwInvalidCharacterException( 
00580             unsigned int        ch,
00581             MemoryManagerType&  theManager);
00582 
00583     static bool
00584     isUTF16Surrogate(XalanDOMChar   ch)
00585     {
00586         return (ch & 0xFC00) == 0xD800 ? true : false;
00587     }
00588 
00589     enum eDummyTwo { SPECIALSSIZE = 256};
00590 
00595     XalanDOMChar            m_maxCharacter;
00596 
00597     XalanDOMChar            m_attrCharsMap[SPECIALSSIZE];
00598 
00599     XalanDOMChar            m_charsMap[SPECIALSSIZE];
00600 
00604     bool        m_shouldWriteXMLHeader;
00605 
00610     bool        m_ispreserve;
00611 
00615     bool        m_doIndent;
00616 
00620     bool        m_startNewLine;
00621   
00627     bool        m_needToOutputDocTypeDecl;
00628   
00633     bool        m_isprevtext;
00634 
00639     bool        m_stripCData;
00640 
00644     bool        m_nextIsRaw;
00645 
00649     bool        m_inCData;
00650 
00655     bool        m_encodingIsUTF;
00656 
00660     const XalanDOMString    m_doctypeSystem;
00661 
00665     const XalanDOMString    m_doctypePublic;
00666 
00670     XalanDOMString  m_encoding;
00671 
00675     int     m_currentIndent;
00676   
00680     int     m_indent;
00681 
00686     BoolStackType   m_preserves;
00687 
00688     // A text buffer.  We use it mostly for converting
00689     // to string values.  See uses of UnsignedLongToString()
00690     // and UnsignedLongToHexString().
00691     XalanDOMString  m_stringBuffer;
00692 
00693 private:
00694 
00695     // These are not implemented.
00696     FormatterToXML(const FormatterToXML&);
00697 
00698     FormatterToXML&
00699     operator=(const FormatterToXML&);
00700 
00701     bool
00702     operator==(const FormatterToXML&) const;
00703 
00712     void
00713     accumNameAsByte(XalanDOMChar    ch);
00714 
00723     void
00724     accumNameAsByteDirect(XalanDOMChar  ch);
00725 
00733     void
00734     accumContentAsByte(XalanDOMChar     ch);
00735 
00743     void
00744     accumContentAsByteDirect(XalanDOMChar   ch);
00745 
00754     void
00755     accumNameAsChar(XalanDOMChar    ch);
00756 
00765     void
00766     accumNameAsCharDirect(XalanDOMChar  ch);
00767 
00773     void
00774     accumContentAsChar(XalanDOMChar     ch);
00775 
00781     void
00782     accumContentAsCharDirect(XalanDOMChar   ch);
00783 
00791     void
00792     accumCharUTF(XalanDOMChar   ch);
00793 
00801     void
00802     accumCharUTFDirect(XalanDOMChar ch);
00803 
00812     void
00813     accumNameString(const XalanDOMChar* chars);
00814 
00822     void
00823     accumStringUTF(const XalanDOMChar*  chars);
00824 
00832     void
00833     accumStringUTFDirect(const XalanDOMChar*    chars);
00834 
00842     void
00843     accumContentString(const XalanDOMChar*  chars);
00844 
00854     void
00855     accumNameArray(
00856             const XalanDOMChar          chars[],
00857             XalanDOMString::size_type   start,
00858             XalanDOMString::size_type   length);
00859 
00869     void
00870     accumContentArray(
00871             const XalanDOMChar          chars[],
00872             XalanDOMString::size_type   start,
00873             XalanDOMString::size_type   length);
00874 
00884     void
00885     accumArrayUTF(
00886             const XalanDOMChar          chars[],
00887             XalanDOMString::size_type   start,
00888             XalanDOMString::size_type   length);
00889 
00899     void
00900     accumArrayUTFDirect(
00901             const XalanDOMChar          chars[],
00902             XalanDOMString::size_type   start,
00903             XalanDOMString::size_type   length);
00904 
00912     void
00913     accumNameDOMString(const XalanDOMString&    str);
00914 
00922     void
00923     accumContentDOMString(const XalanDOMString& str);
00924 
00932     void
00933     accumDOMStringUTF(const XalanDOMString& str);
00934 
00942     void
00943     accumDOMStringUTFDirect(const XalanDOMString&   str);
00944 
00950     void
00951     outputDocTypeDecl(const XalanDOMChar*   name);
00952 
00958     void
00959     processAttribute(
00960             const XalanDOMChar*     name,
00961             const XalanDOMChar*     value);
00962 
00967     void
00968     printSpace(int n);
00969 
00975     void
00976     accumNormalizedPIData(
00977             const XalanDOMChar*         theData,
00978             XalanDOMString::size_type   theLength);
00979 
00980 
00981     // Data members...
00985     bool        m_bytesEqualChars;
00986 
00987     bool        m_shouldFlush;
00988 
00992     bool        m_spaceBeforeClose;
00993 
00999     bool        m_escapeCData;
01000 
01004     const XalanDOMString    m_version;
01005 
01009     const XalanDOMString    m_standalone;
01010 
01014     const XalanDOMString    m_mediaType;
01015 
01019     const XalanDOMString    m_attrSpecialChars;
01020 
01021     typedef XalanDOMString::size_type   size_type;
01022 
01026     static const XalanDOMChar   s_doctypeHeaderStartString[];
01027 
01028     static const size_type      s_doctypeHeaderStartStringLength;
01029 
01033     static const XalanDOMChar   s_doctypeHeaderPublicString[];
01034 
01035     static const size_type      s_doctypeHeaderPublicStringLength;
01036 
01040     static const XalanDOMChar   s_doctypeHeaderSystemString[];
01041 
01042     static const size_type      s_doctypeHeaderSystemStringLength;
01043 
01047     static const XalanDOMChar   s_xmlHeaderStartString[];
01048 
01049     static const size_type      s_xmlHeaderStartStringLength;
01050 
01054     static const XalanDOMChar   s_xmlHeaderEncodingString[];
01055 
01056     static const size_type      s_xmlHeaderEncodingStringLength;
01057 
01061     static const XalanDOMChar   s_xmlHeaderStandaloneString[];
01062 
01063     static const size_type      s_xmlHeaderStandaloneStringLength;
01064 
01068     static const XalanDOMChar   s_xmlHeaderEndString[];
01069 
01070     static const size_type      s_xmlHeaderEndStringLength;
01071 
01075     static const XalanDOMChar   s_defaultVersionString[];
01076 
01077     static const size_type      s_defaultVersionStringLength;
01078 
01082     static const XalanDOMChar   s_xhtmlDocTypeString[];
01083 
01084     static const size_type      s_xhtmlDocTypeStringLength;
01085 
01089     static const XalanDOMChar   s_dtdCDATACloseString[];
01090 
01091     static const size_type      s_dtdCDATACloseStringLength;
01092 
01093     DOMCharBufferType                           m_charBuf;
01094 
01095     XalanDOMString::size_type                   m_pos;
01096 
01097     ByteBufferType                              m_byteBuf;
01098 
01099     static const XalanDOMString::size_type      s_maxBufferSize;
01100 
01105     BoolStackType   m_elemStack;
01106 
01111     AccumCharFunctionType       m_accumNameCharFunction;
01112 
01117     AccumStringFunctionType     m_accumNameStringFunction;
01118 
01123     AccumDOMStringFunctionType  m_accumNameDOMStringFunction;
01124 
01129     AccumArrayFunctionType      m_accumNameArrayFunction;
01130 
01135     AccumCharFunctionType       m_accumContentCharFunction;
01136 
01141     AccumStringFunctionType     m_accumContentStringFunction;
01142 
01147     AccumDOMStringFunctionType  m_accumContentDOMStringFunction;
01148 
01153     AccumArrayFunctionType      m_accumContentArrayFunction;
01154 
01158     FlushFunctionType           m_flushFunction;
01159 
01163     const XalanDOMChar*         m_newlineString;
01164 
01168     XalanDOMString::size_type   m_newlineStringLength;
01169 
01170     bool                        m_isXML1_1;
01171 };
01172 
01173 
01174 
01175 XALAN_CPP_NAMESPACE_END
01176 
01177 
01178 
01179 #endif  // FORMATTERTOXML_HEADER_GUARD_1357924680

Interpreting class diagrams

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

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo