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  

XalanXMLSerializerBase.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(XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680)
00017 #define XALANXMLSERIALIZERBASE_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 XalanOutputStream;
00045 
00046 
00047 
00048 XALAN_USING_XERCES(MemoryManager)
00049 
00050 
00051 
00056 class XALAN_XMLSUPPORT_EXPORT XalanXMLSerializerBase : public FormatterListener 
00057 {
00058 public:
00059 
00063     static void
00064     initialize(MemoryManager&   theManager);
00065  
00069     static void
00070     terminate();
00071 
00072 
00087     XalanXMLSerializerBase(
00088                 MemoryManager&              theManager,
00089                 eXMLVersion                 theXMLVersion,
00090                 const XalanDOMString&       theEncoding,
00091                 const XalanDOMString&       theDoctypeSystem,
00092                 const XalanDOMString&       theDoctypePublic,
00093                 bool                        xmlDecl,
00094                 const XalanDOMString&       theStandalone);
00095 
00096     virtual
00097     ~XalanXMLSerializerBase();
00098 
00099     MemoryManagerType&
00100     getMemoryManager()
00101     {
00102         return m_elemStack.getMemoryManager();
00103     }
00104 
00105 
00106     // These methods are inherited from FormatterListener ...
00107 
00108     virtual void
00109     setDocumentLocator(const Locator* const     locator);
00110 
00111     virtual void
00112     startDocument();
00113 
00114     virtual void
00115     startElement(
00116             const XMLCh* const  name,
00117             AttributeList&      attrs) = 0;
00118 
00119     virtual void
00120     endElement(const XMLCh* const   name) = 0;
00121 
00122     virtual void
00123     characters(
00124             const XMLCh* const  chars,
00125             const unsigned int  length);
00126 
00127     virtual void
00128     charactersRaw(
00129             const XMLCh* const  chars,
00130             const unsigned int  length) = 0;
00131 
00132     virtual void
00133     entityReference(const XMLCh* const  name) = 0;
00134 
00135     virtual void
00136     ignorableWhitespace(
00137             const XMLCh* const  chars,
00138             const unsigned int  length);
00139 
00140     virtual void
00141     processingInstruction(
00142             const XMLCh* const  target,
00143             const XMLCh* const  data);
00144 
00145     virtual void
00146     resetDocument();
00147 
00148     virtual void
00149     comment(const XMLCh* const  data) = 0;
00150 
00151     virtual void
00152     cdata(
00153             const XMLCh* const  ch,
00154             const unsigned int  length);
00155 
00156     virtual const XalanDOMString&
00157     getDoctypeSystem() const;
00158 
00159     virtual const XalanDOMString&
00160     getDoctypePublic() const;
00161 
00162     virtual const XalanDOMString&
00163     getEncoding() const = 0;
00164 
00165     const XalanDOMString&
00166     getVersion() const
00167     {
00168         return m_version;
00169     }
00170 
00171     const XalanDOMString&
00172     getStandalone() const
00173     {
00174         return m_standalone;
00175     }
00176 
00177     bool
00178     getShouldWriteXMLHeader() const
00179     {
00180         return m_shouldWriteXMLHeader;
00181     }
00182 
00183     void
00184     setShouldWriteXMLHeader(bool    b)
00185     {
00186         m_shouldWriteXMLHeader = b;
00187     }
00188 
00189     typedef XalanVector<bool>       BoolStackType;
00190 
00191 
00192     static const XalanDOMString&    s_1_0String;
00193 
00194     static const XalanDOMString&    s_1_1String;
00195 
00196 
00197     class XALAN_XMLSUPPORT_EXPORT UTF8
00198     {
00199     public:
00200 
00201         // Static data members...
00205         static const XalanDOMString&    s_encodingString;
00206 
00210         static const char                       s_doctypeHeaderStartString[];
00211 
00212         static const XalanDOMString::size_type  s_doctypeHeaderStartStringLength;
00213 
00217         static const char                       s_doctypeHeaderPublicString[];
00218 
00219         static const XalanDOMString::size_type  s_doctypeHeaderPublicStringLength;
00220 
00224         static const char                       s_doctypeHeaderSystemString[];
00225 
00226         static const XalanDOMString::size_type  s_doctypeHeaderSystemStringLength;
00227 
00231         static const char                       s_xmlHeaderStartString[];
00232 
00233         static const XalanDOMString::size_type  s_xmlHeaderStartStringLength;
00234 
00238         static const char                       s_xmlHeaderEncodingString[];
00239 
00240         static const XalanDOMString::size_type  s_xmlHeaderEncodingStringLength;
00241 
00245         static const char                       s_xmlHeaderStandaloneString[];
00246 
00247         static const XalanDOMString::size_type  s_xmlHeaderStandaloneStringLength;
00248 
00252         static const char                       s_xmlHeaderEndString[];
00253 
00254         static const XalanDOMString::size_type  s_xmlHeaderEndStringLength;
00255 
00259         static const char                       s_defaultVersionString[];
00260 
00261         static const XalanDOMString::size_type  s_defaultVersionStringLength;
00262 
00266         static const XalanDOMChar               s_xhtmlDocTypeString[];
00267 
00268         static const XalanDOMString::size_type  s_xhtmlDocTypeStringLength;
00269 
00273         static const char                       s_cdataOpenString[];
00274 
00275         static const XalanDOMString::size_type  s_cdataOpenStringLength;
00276 
00280         static const char                       s_cdataCloseString[];
00281 
00282         static const XalanDOMString::size_type  s_cdataCloseStringLength;
00283 
00287         static const char                       s_lessThanEntityString[];
00288 
00289         static const XalanDOMString::size_type  s_lessThanEntityStringLength;
00290 
00294         static const char                       s_greaterThanEntityString[];
00295 
00296         static const XalanDOMString::size_type  s_greaterThanEntityStringLength;
00297 
00301         static const char                       s_ampersandEntityString[];
00302 
00303         static const XalanDOMString::size_type  s_ampersandEntityStringLength;
00304 
00308         static const char                       s_quoteEntityString[];
00309 
00310         static const XalanDOMString::size_type  s_quoteEntityStringLength;
00311     };
00312 
00313     class XALAN_XMLSUPPORT_EXPORT UTF16
00314     {
00315     public:
00316 
00320         static const XalanDOMString&    s_encodingString;
00321 
00325         static const XalanDOMChar               s_doctypeHeaderStartString[];
00326 
00327         static const XalanDOMString::size_type  s_doctypeHeaderStartStringLength;
00328 
00332         static const XalanDOMChar               s_doctypeHeaderPublicString[];
00333 
00334         static const XalanDOMString::size_type  s_doctypeHeaderPublicStringLength;
00335 
00339         static const XalanDOMChar               s_doctypeHeaderSystemString[];
00340 
00341         static const XalanDOMString::size_type  s_doctypeHeaderSystemStringLength;
00342 
00346         static const XalanDOMChar               s_xmlHeaderStartString[];
00347 
00348         static const XalanDOMString::size_type  s_xmlHeaderStartStringLength;
00349 
00353         static const XalanDOMChar               s_xmlHeaderEncodingString[];
00354 
00355         static const XalanDOMString::size_type  s_xmlHeaderEncodingStringLength;
00356 
00360         static const XalanDOMChar               s_xmlHeaderStandaloneString[];
00361 
00362         static const XalanDOMString::size_type  s_xmlHeaderStandaloneStringLength;
00363 
00367         static const XalanDOMChar               s_xmlHeaderEndString[];
00368 
00369         static const XalanDOMString::size_type  s_xmlHeaderEndStringLength;
00370 
00374         static const XalanDOMChar               s_defaultVersionString[];
00375 
00376         static const XalanDOMString::size_type  s_defaultVersionStringLength;
00377 
00381         static const XalanDOMChar               s_xhtmlDocTypeString[];
00382 
00383         static const XalanDOMString::size_type  s_xhtmlDocTypeStringLength;
00384 
00388         static const XalanDOMChar               s_cdataOpenString[];
00389 
00390         static const XalanDOMString::size_type  s_cdataOpenStringLength;
00391 
00395         static const XalanDOMChar               s_cdataCloseString[];
00396 
00397         static const XalanDOMString::size_type  s_cdataCloseStringLength;
00398 
00402         static const XalanDOMChar               s_lessThanEntityString[];
00403 
00404         static const XalanDOMString::size_type  s_lessThanEntityStringLength;
00405 
00409         static const XalanDOMChar               s_greaterThanEntityString[];
00410 
00411         static const XalanDOMString::size_type  s_greaterThanEntityStringLength;
00412 
00416         static const XalanDOMChar               s_ampersandEntityString[];
00417 
00418         static const XalanDOMString::size_type  s_ampersandEntityStringLength;
00419 
00423         static const XalanDOMChar               s_quoteEntityString[];
00424 
00425         static const XalanDOMString::size_type  s_quoteEntityStringLength;
00426     };
00427 
00428     enum
00429     {
00430         eBufferSize = 512       // The size of the buffer
00431     };
00432 
00433     class XALAN_XMLSUPPORT_EXPORT CharFunctor1_0 
00434     {
00435     public:
00436 
00437         bool
00438         attribute(XalanDOMChar  theChar) const
00439         {
00440             return theChar > s_lastSpecial ?
00441                         false :
00442                         s_specialChars[theChar] > eNone;
00443         }
00444 
00445         bool
00446         content(XalanDOMChar  theChar) const
00447         {
00448             return theChar > s_lastSpecial ?
00449                         false :
00450                         s_specialChars[theChar] > eAttr;
00451         }
00452 
00453         bool
00454         range(XalanDOMChar  theChar) const
00455         {
00456             assert(theChar > 0);
00457 
00458             return theChar > s_lastSpecial;
00459         }
00460 
00461         bool
00462         isForbidden(XalanDOMChar  theChar) const
00463         {
00464             return theChar > s_lastSpecial ?
00465                         false :
00466                         s_specialChars[theChar] == eForb;
00467         }
00468 
00469         bool
00470         isCharRefForbidden(XalanDOMChar  theChar) const
00471         {
00472             return theChar > s_lastSpecial ?
00473                         false :
00474                         s_specialChars[theChar] == eForb;
00475         }
00476  
00477 
00478     private:
00479          static const size_t    s_lastSpecial;
00480 
00481          static const char      s_specialChars[];
00482     };
00483 
00484 
00485 
00486     class XALAN_XMLSUPPORT_EXPORT CharFunctor1_1
00487     {
00488     public:
00489 
00490         bool
00491         attribute(XalanDOMChar  theChar) const
00492         {
00493             return theChar > s_lastSpecial ?
00494                         false :
00495                         s_specialChars[theChar] > eNone;
00496         }
00497 
00498         bool
00499         content(XalanDOMChar  theChar) const
00500         {
00501             return theChar > s_lastSpecial ?
00502                         false :
00503                         s_specialChars[theChar] > eAttr;
00504         }
00505 
00506         bool
00507         range(XalanDOMChar  theChar) const
00508         {
00509             assert(theChar > 0);
00510 
00511             return theChar > s_lastSpecial;
00512         }
00513 
00514         bool
00515         isForbidden(XalanDOMChar  theChar) const
00516         {
00517             return theChar > s_lastSpecial ?
00518                         false :
00519                         s_specialChars[theChar] == eForb;
00520         }
00521 
00522         bool
00523         isCharRefForbidden(XalanDOMChar  theChar) const
00524         {
00525             return theChar > s_lastSpecial ?
00526                         false :
00527                         s_specialChars[theChar] == eCRFb;
00528         }
00529 
00530     private:
00531         static const size_t     s_lastSpecial;
00532 
00533         static const char       s_specialChars[];
00534 
00535     };
00536 
00537   
00538 
00539 
00540     enum
00541     {
00542         eNone = 0u,
00543         eAttr = 1u,  // A flag to indicate a value in s_specialChars applies to attributes
00544         eBoth = 2u,  // A flag to indicate a value in s_specialChars applies to both content and attributes
00545         eForb = 4u,  // A flag to indicate a forbidden value in s_specialChars 
00546                      // XML1.1 put a requirement to output chars #x1...#x1F and #x7F...#x9F as charRefs only
00547                      // In the comments , PI and CDATA usage of charRefs is forbidden, so we will report an error in 
00548         eCRFb = 5u   // that case. For the elemets and attributes is should work the same as eBoth
00549     };
00550  
00551 
00552 
00553 protected:
00554 
00555     virtual void
00556     writeXMLHeader() = 0;
00557 
00558     virtual void
00559     flushBuffer() = 0;
00560 
00561     virtual void
00562     writeDoctypeDecl(const XalanDOMChar*    name) = 0;
00563 
00564     virtual void
00565     writeProcessingInstruction(
00566             const XMLCh*    target,
00567             const XMLCh*    data) = 0;
00568 
00569     virtual void
00570     writeCharacters(
00571             const XMLCh*    chars,
00572             unsigned int    length) = 0;
00573 
00574     virtual void
00575     writeCDATA(
00576             const XMLCh*    chars,
00577             unsigned int    length) = 0;
00578 
00579     virtual void
00580     outputNewline() = 0;
00581 
00590     bool
00591     markParentForChildren()
00592     {
00593         if(!m_elemStack.empty())
00594         {
00595             // See if the parent element has already been flagged as having children.
00596             if(false == m_elemStack.back())
00597             {
00598                 m_elemStack.back() = true;
00599 
00600                 return true;
00601             }
00602         }
00603 
00604         return false;
00605     }
00606 
00611     bool
00612     getNeedToOutputDoctypeDecl() const
00613     {
00614         return m_needToOutputDoctypeDecl;
00615     }
00616 
00620     void
00621     openElementForChildren()
00622     {
00623         m_elemStack.push_back(false);
00624     }
00625 
00626     bool
00627     outsideDocumentElement() const
00628     {
00629         return m_elemStack.empty();
00630     }
00631 
00637     bool
00638     childNodesWereAdded()
00639     {
00640         bool    fResult = false;
00641 
00642         if (m_elemStack.empty() == false)
00643         {
00644             fResult = m_elemStack.back();
00645 
00646             m_elemStack.pop_back();
00647         }
00648 
00649         return fResult;
00650     }
00651 
00652     void
00653     generateDoctypeDecl(const XalanDOMChar*     name)
00654     {
00655         if(true == m_needToOutputDoctypeDecl)          
00656         {
00657             assert(m_doctypeSystem.empty() == false);
00658 
00659             writeDoctypeDecl(name);
00660 
00661             m_needToOutputDoctypeDecl = false;
00662         }
00663     }
00664 
00668     bool        m_nextIsRaw;
00669 
00673     bool        m_spaceBeforeClose;
00674 
00678     const XalanDOMString    m_doctypeSystem;
00679 
00683     const XalanDOMString    m_doctypePublic;
00684 
00688     const XalanDOMString&   m_version;
00689 
00693     const XalanDOMString    m_standalone;
00694 
00695     const XalanDOMString  m_encoding;
00696 
00697     static bool
00698     isUTF16HighSurrogate(XalanDOMChar   theChar)
00699     {
00700         return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
00701     }
00702 
00703     static bool
00704     isUTF16LowSurrogate(XalanDOMChar    theChar)
00705     {
00706         return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
00707     }
00708 
00709     static unsigned int
00710     decodeUTF16SurrogatePair(
00711             XalanDOMChar    theHighSurrogate,
00712             XalanDOMChar    theLowSurrogate,
00713             MemoryManager&  theManager);
00714 
00720     static void
00721     throwInvalidUTF16SurrogateException(
00722             XalanDOMChar    ch,
00723             MemoryManager&  theManager);
00724 
00731     static void
00732     throwInvalidUTF16SurrogateException(
00733             XalanDOMChar    ch,
00734             XalanDOMChar    next,
00735             MemoryManager&  theManager);
00736 
00743     static void
00744     throwInvalidCharacterException(
00745             unsigned int    ch,
00746             MemoryManager&  theManager);
00747 
00748 
00755     static void
00756     throwInvalidXMLCharacterException(
00757             unsigned int                ch,
00758             const XalanDOMString&       theXMLversion,
00759             MemoryManager&              theManager);
00760 private:
00761 
00762     // These are not implemented.
00763     XalanXMLSerializerBase(const XalanXMLSerializerBase&);
00764 
00765     XalanXMLSerializerBase&
00766     operator=(const XalanXMLSerializerBase&);
00767 
00768     bool
00769     operator==(const XalanXMLSerializerBase&) const;
00770 
00771     // Data members...
00777     bool        m_needToOutputDoctypeDecl;
00778 
00782     bool        m_shouldWriteXMLHeader;
00783 
00788     BoolStackType   m_elemStack;
00789 
00793     static const XalanDOMChar               s_xhtmlDocTypeString[];
00794 
00795     static const XalanDOMString::size_type  s_xhtmlDocTypeStringLength;
00796 };
00797 
00798 
00799 
00800 XALAN_CPP_NAMESPACE_END
00801 
00802 
00803 
00804 #endif  // XALANXMLSERIALIZERBASE_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