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

FormatterToXMLBase.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(FORMATTERTOXMLBASE_HEADER_GUARD_1357924680)
00017 #define FORMATTERTOXMLBASE_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 // Base class header file.
00036 #include <xalanc/PlatformSupport/FormatterListener.hpp>
00037 
00038 
00039 
00040 XALAN_CPP_NAMESPACE_BEGIN
00041 
00042 
00043 
00044 class Writer;
00045 
00046 
00047 
00051 class XALAN_XMLSUPPORT_EXPORT FormatterToXMLBase : public FormatterListener 
00052 {
00053 public:
00054 
00070     FormatterToXMLBase(
00071             Writer&                 writer,
00072             const XalanDOMString&   version,
00073             const XalanDOMString&   mediaType,
00074             const XalanDOMString&   doctypeSystem,
00075             const XalanDOMString&   doctypePublic,
00076             bool                    xmlDecl,
00077             const XalanDOMString&   standalone,
00078             MemoryManagerType&      theManager XALAN_DEFAULT_MEMMGR);
00079 
00080     virtual
00081     ~FormatterToXMLBase();
00082 
00083     MemoryManagerType&
00084     getMemoryManager()
00085     {
00086         return m_elemStack.getMemoryManager();
00087     }
00088     // These methods are inherited from FormatterListener ...
00089 
00090     virtual void
00091     setDocumentLocator(const LocatorType* const locator);
00092 
00093     virtual void
00094     startDocument();
00095 
00096     virtual void
00097     endDocument();
00098 
00099     virtual void
00100     startElement(
00101             const XMLCh* const  name,
00102             AttributeListType&  attrs) = 0;
00103 
00104     virtual void
00105     endElement(const XMLCh* const   name) = 0;
00106 
00107     virtual void
00108     characters(
00109             const XMLCh* const  chars,
00110             const unsigned int  length);
00111 
00112     virtual void
00113     charactersRaw(
00114             const XMLCh* const  chars,
00115             const unsigned int  length) = 0;
00116 
00117     virtual void
00118     entityReference(const XMLCh* const  name) = 0;
00119 
00120     virtual void
00121     ignorableWhitespace(
00122             const XMLCh* const  chars,
00123             const unsigned int  length);
00124 
00125     virtual void
00126     processingInstruction(
00127             const XMLCh* const  target,
00128             const XMLCh* const  data);
00129 
00130     virtual void
00131     resetDocument();
00132 
00133     virtual void
00134     comment(const XMLCh* const  data) = 0;
00135 
00136     virtual void
00137     cdata(
00138             const XMLCh* const  ch,
00139             const unsigned int  length);
00140 
00141     virtual Writer*
00142     getWriter() const;
00143 
00144     virtual const XalanDOMString&
00145     getDoctypeSystem() const;
00146 
00147     virtual const XalanDOMString&
00148     getDoctypePublic() const;
00149 
00150     virtual const XalanDOMString&
00151     getEncoding() const = 0;
00152 
00153     virtual const XalanDOMString&
00154     getMediaType() const;
00155 
00156     const XalanDOMString&
00157     getVersion() const
00158     {
00159         return m_version;
00160     }
00161 
00162     const XalanDOMString&
00163     getStandalone() const
00164     {
00165         return m_standalone;
00166     }
00167 
00168     bool
00169     getShouldWriteXMLHeader() const
00170     {
00171         return m_shouldWriteXMLHeader;
00172     }
00173 
00174     void
00175     setShouldWriteXMLHeader(bool    b)
00176     {
00177         m_shouldWriteXMLHeader = b;
00178     }
00179 
00180     typedef XalanVector<bool>       BoolStackType;
00181 
00182 protected:
00183 
00184     virtual void
00185     writeXMLHeader() = 0;
00186 
00187     virtual void
00188     flushBuffer() = 0;
00189 
00190     virtual void
00191     writeDoctypeDecl(const XalanDOMChar*    name) = 0;
00192 
00193     virtual void
00194     writeProcessingInstruction(
00195             const XMLCh*    target,
00196             const XMLCh*    data) = 0;
00197 
00198     virtual void
00199     writeCharacters(
00200             const XMLCh*    chars,
00201             unsigned int    length) = 0;
00202 
00203     virtual void
00204     writeCDATA(
00205             const XMLCh*    chars,
00206             unsigned int    length) = 0;
00207 
00208     virtual void
00209     outputNewline() = 0;
00210 
00219     bool
00220     markParentForChildren()
00221     {
00222         if(!m_elemStack.empty())
00223         {
00224             // See if the parent element has already been flagged as having children.
00225             if(false == m_elemStack.back())
00226             {
00227                 m_elemStack.back() = true;
00228 
00229                 return true;
00230             }
00231         }
00232 
00233         return false;
00234     }
00235 
00239     void
00240     openElementForChildren()
00241     {
00242         m_elemStack.push_back(false);
00243     }
00244 
00245     bool
00246     outsideDocumentElement() const
00247     {
00248         return m_elemStack.empty();
00249     }
00250 
00256     bool
00257     childNodesWereAdded()
00258     {
00259         bool    fResult = false;
00260 
00261         if (m_elemStack.empty() == false)
00262         {
00263             fResult = m_elemStack.back();
00264 
00265             m_elemStack.pop_back();
00266         }
00267 
00268         return fResult;
00269     }
00270 
00271     void
00272     generateDoctypeDecl(const XalanDOMChar*     name)
00273     {
00274         if(true == m_needToOutputDoctypeDecl)          
00275         {
00276             assert(m_doctypeSystem.empty() == false);
00277 
00278             writeDoctypeDecl(name);
00279 
00280             m_needToOutputDoctypeDecl = false;
00281         }
00282     }
00283 
00287     Writer*                 m_writer;
00288 
00289     void
00290     flushWriter();
00291 
00295     bool        m_nextIsRaw;
00296 
00300     bool        m_spaceBeforeClose;
00301 
00305     const XalanDOMString    m_doctypeSystem;
00306 
00310     const XalanDOMString    m_doctypePublic;
00311 
00315     const XalanDOMString    m_version;
00316 
00320     const XalanDOMString    m_standalone;
00321 
00325     const XalanDOMString    m_mediaType;
00326 
00330     const XalanDOMChar*     m_newlineString;
00331 
00335     XalanDOMString::size_type   m_newlineStringLength;
00336 
00337     static bool
00338     isUTF16HighSurrogate(XalanDOMChar   theChar)
00339     {
00340         return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
00341     }
00342 
00343     static bool
00344     isUTF16LowSurrogate(XalanDOMChar    theChar)
00345     {
00346         return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
00347     }
00348 
00349     static unsigned int
00350     decodeUTF16SurrogatePair(
00351             XalanDOMChar    theHighSurrogate,
00352             XalanDOMChar    theLowSurrogate,
00353             MemoryManagerType& theManager);
00354 
00360     static void
00361     throwInvalidUTF16SurrogateException(XalanDOMChar    ch,
00362                                         MemoryManagerType& theManager);
00363 
00370     static void
00371     throwInvalidUTF16SurrogateException(
00372             XalanDOMChar    ch,
00373             XalanDOMChar    next,
00374             MemoryManagerType& theManager);
00375 
00382     static void
00383     throwInvalidCharacterException(unsigned int     ch,
00384                                     MemoryManagerType& theManager);
00385 
00386     enum
00387     {
00388             kNotSpecial = 0,
00389             kContentSpecial = 1,    // A flag to indicate a value in s_specialChars applies to content
00390             kAttributeSpecial = 2,  // A flag to indicate a value in s_specialChars applies to attributes
00391             kBothSpecial = 3,       // A flag t0 indicate a value in s_specialChars applies to both content and attributes
00392             kSpecialsSize = 0x80,   // The size of s_specialChars
00393             kBufferSize = 512       // The size of the buffer
00394     };
00395 
00396     static const XalanDOMChar   s_specialChars[];
00397 
00398 private:
00399 
00400     // These are not implemented.
00401     FormatterToXMLBase(const FormatterToXMLBase&);
00402 
00403     FormatterToXMLBase&
00404     operator=(const FormatterToXMLBase&);
00405 
00406     bool
00407     operator==(const FormatterToXMLBase&) const;
00408 
00409     // Data members...
00415     bool        m_needToOutputDoctypeDecl;
00416 
00420     bool        m_shouldWriteXMLHeader;
00421 
00426     BoolStackType   m_elemStack;
00427 
00431     static const XalanDOMChar               s_xhtmlDocTypeString[];
00432 
00433     static const XalanDOMString::size_type  s_xhtmlDocTypeStringLength;
00434 };
00435 
00436 
00437 
00438 XALAN_CPP_NAMESPACE_END
00439 
00440 
00441 
00442 #endif  // FORMATTERTOXMLBASE_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.