## 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_UTF16.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_UTF16_HEADER_GUARD_1357924680)
    00058 #define FORMATTERTOXML_UTF16_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 // Base class header file.
    00077 #include <xalanc/PlatformSupport/FormatterListener.hpp>
    00078
    00079
    00080
    00081 XALAN_CPP_NAMESPACE_BEGIN
    00082
    00083
    00084
    00085 class Writer;
    00086
    00087
    00088
    00092 class XALAN_XMLSUPPORT_EXPORT FormatterToXML_UTF16 : public FormatterListener
    00093 {
    00094 public:
    00095
    00099     static void
    00100     initialize();
    00101
    00105     static void
    00106     terminate();
    00107
    00123     FormatterToXML_UTF16(
    00124             Writer&                 writer,
    00125             const XalanDOMString&   version = XalanDOMString(),
    00126             const XalanDOMString&   mediaType = XalanDOMString(),
    00127             const XalanDOMString&   doctypeSystem = XalanDOMString(),
    00128             const XalanDOMString&   doctypePublic = XalanDOMString(),
    00129             bool                    xmlDecl = true,
    00130             const XalanDOMString&   standalone = XalanDOMString());
    00131
    00132     virtual
    00133     ~FormatterToXML_UTF16();
    00134
    00135
    00136     // These methods are inherited from FormatterListener ...
    00137
    00138     virtual void
    00139     setDocumentLocator(const LocatorType* const     locator);
    00140
    00141     virtual void
    00142     startDocument();
    00143
    00144     virtual void
    00145     endDocument();
    00146
    00147     virtual void
    00148     startElement(
    00149             const XMLCh* const  name,
    00150             AttributeListType&  attrs);
    00151
    00152     virtual void
    00153     endElement(const XMLCh* const   name);
    00154
    00155     virtual void
    00156     characters(
    00157             const XMLCh* const  chars,
    00158             const unsigned int  length);
    00159
    00160     virtual void
    00161     charactersRaw(
    00162             const XMLCh* const  chars,
    00163             const unsigned int  length);
    00164
    00165     virtual void
    00166     entityReference(const XMLCh* const  name);
    00167
    00168     virtual void
    00169     ignorableWhitespace(
    00170             const XMLCh* const  chars,
    00171             const unsigned int  length);
    00172
    00173     virtual void
    00174     processingInstruction(
    00175             const XMLCh* const  target,
    00176             const XMLCh* const  data);
    00177
    00178
    00179     virtual void
    00180     resetDocument();
    00181
    00182     virtual void
    00183     comment(const XMLCh* const  data);
    00184
    00185     virtual void
    00186     cdata(
    00187             const XMLCh* const  ch,
    00188             const unsigned int  length);
    00189
    00190     virtual Writer*
    00191     getWriter() const;
    00192
    00193     virtual const XalanDOMString&
    00194     getDoctypeSystem() const;
    00195
    00196     virtual const XalanDOMString&
    00197     getDoctypePublic() const;
    00198
    00199     virtual const XalanDOMString&
    00200     getEncoding() const;
    00201
    00202     virtual const XalanDOMString&
    00203     getMediaType() const;
    00204
    00205     const XalanDOMString&
    00206     getVersion() const
    00207     {
    00208         return m_version;
    00209     }
    00210
    00211     const XalanDOMString&
    00212     getStandalone() const
    00213     {
    00214         return m_standalone;
    00215     }
    00216
    00217     bool
    00218     getShouldWriteXMLHeader() const
    00219     {
    00220         return m_shouldWriteXMLHeader;
    00221     }
    00222
    00223     void
    00224     setShouldWriteXMLHeader(bool    b)
    00225     {
    00226         m_shouldWriteXMLHeader = b;
    00227     }
    00228
    00229 #if defined(XALAN_NO_STD_NAMESPACE)
    00230 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
    00231     typedef deque<bool>         BoolStackType;
    00232 #else
    00233     typedef vector<bool>        BoolStackType;
    00234 #endif
    00235 #else
    00236 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL)
    00237     typedef std::deque<bool>    BoolStackType;
    00238 #else
    00239     typedef std::vector<bool>   BoolStackType;
    00240 #endif
    00241 #endif
    00242
    00243 protected:
    00244
    00248     Writer*                 m_writer;
    00249
    00253     void
    00254     outputLineSep();
    00255
    00259     void
    00260     writeDefaultEscape(XalanDOMChar     ch);
    00261
    00265     void
    00266     writeDefaultAttributeEscape(XalanDOMChar    ch);
    00267
    00272     bool
    00273     writeDefaultEntity(XalanDOMChar     ch);
    00274
    00279     bool
    00280     writeDefaultAttributeEntity(XalanDOMChar    ch);
    00281
    00286     void
    00287     writeCommentData(const XalanDOMChar*    data);
    00288
    00289     void
    00290     flushWriter();
    00291
    00292     void
    00293     openElementForChildren();
    00294
    00295     bool
    00296     childNodesWereAdded();
    00297
    00302     void
    00303     writeParentTagEnd();
    00304
    00309     void
    00310     writeNormalizedChar(XalanDOMChar    ch);
    00311
    00318     void
    00319     writeCDATAChars(
    00320             const XalanDOMChar          ch[],
    00321             XalanDOMString::size_type   length);
    00322
    00329     void
    00330     writeAttrString(
    00331             const XalanDOMChar*         theString,
    00332             XalanDOMString::size_type   theStringLength);
    00333
    00339     static void
    00340     throwInvalidUTF16SurrogateException(XalanDOMChar    ch);
    00341
    00348     static void
    00349     throwInvalidUTF16SurrogateException(
    00350             XalanDOMChar    ch,
    00351             XalanDOMChar    next);
    00352
    00356     bool        m_shouldWriteXMLHeader;
    00357
    00363     bool        m_needToOutputDocTypeDecl;
    00364
    00368     bool        m_nextIsRaw;
    00369
    00373     const XalanDOMString    m_doctypeSystem;
    00374
    00378     const XalanDOMString    m_doctypePublic;
    00379
    00380 private:
    00381
    00382     // These are not implemented.
    00383     FormatterToXML_UTF16(const FormatterToXML_UTF16&);
    00384
    00385     FormatterToXML_UTF16&
    00386     operator=(const FormatterToXML_UTF16&);
    00387
    00388     bool
    00389     operator==(const FormatterToXML_UTF16&) const;
    00390
    00391     void
    00392     write(
    00393             const XalanDOMChar*         theChars,
    00394             XalanDOMString::size_type   theLength);
    00395
    00396     void
    00397     writeName(const XalanDOMChar*   theChars);
    00398
    00399     void
    00400     write(const XalanDOMChar*   theChars)
    00401     {
    00402         write(theChars, XalanDOMString::length(theChars));
    00403     }
    00404
    00405     void
    00406     write(XalanDOMChar  theChar)
    00407     {
    00408         write(&theChar, 1);
    00409     }
    00410
    00411     void
    00412     write(const XalanDOMString&     theChars)
    00413     {
    00414         write(theChars.c_str(), theChars.length());
    00415     }
    00416
    00422     void
    00423     outputDocTypeDecl(const XalanDOMChar*   name);
    00424
    00430     void
    00431     processAttribute(
    00432             const XalanDOMChar*     name,
    00433             const XalanDOMChar*     value);
    00434
    00440     void
    00441     writeNormalizedPIData(
    00442             const XalanDOMChar*         theData,
    00443             XalanDOMString::size_type   theLength);
    00444
    00445     void
    00446     flushBuffer();
    00447
    00448     // Data members...
    00452     bool        m_spaceBeforeClose;
    00453
    00457     const XalanDOMString    m_version;
    00458
    00462     const XalanDOMString    m_standalone;
    00463
    00467     const XalanDOMString    m_mediaType;
    00468
    00469
    00473     static const XalanDOMString&    s_utf16String;
    00474
    00478     static const XalanDOMChar               s_doctypeHeaderStartString[];
    00479
    00480     static const XalanDOMString::size_type  s_doctypeHeaderStartStringLength;
    00481
    00485     static const XalanDOMChar               s_doctypeHeaderPublicString[];
    00486
    00487     static const XalanDOMString::size_type  s_doctypeHeaderPublicStringLength;
    00488
    00492     static const XalanDOMChar               s_doctypeHeaderSystemString[];
    00493
    00494     static const XalanDOMString::size_type  s_doctypeHeaderSystemStringLength;
    00495
    00499     static const XalanDOMChar               s_xmlHeaderStartString[];
    00500
    00501     static const XalanDOMString::size_type  s_xmlHeaderStartStringLength;
    00502
    00506     static const XalanDOMChar               s_xmlHeaderEncodingString[];
    00507
    00508     static const XalanDOMString::size_type  s_xmlHeaderEncodingStringLength;
    00509
    00513     static const XalanDOMChar               s_xmlHeaderStandaloneString[];
    00514
    00515     static const XalanDOMString::size_type  s_xmlHeaderStandaloneStringLength;
    00516
    00520     static const XalanDOMChar               s_xmlHeaderEndString[];
    00521
    00522     static const XalanDOMString::size_type  s_xmlHeaderEndStringLength;
    00523
    00527     static const XalanDOMChar               s_defaultVersionString[];
    00528
    00529     static const XalanDOMString::size_type  s_defaultVersionStringLength;
    00530
    00534     static const XalanDOMChar               s_xhtmlDocTypeString[];
    00535
    00536     static const XalanDOMString::size_type  s_xhtmlDocTypeStringLength;
    00537
    00541     static const XalanDOMChar               s_cdataOpenString[];
    00542
    00543     static const XalanDOMString::size_type  s_cdataOpenStringLength;
    00544
    00548     static const XalanDOMChar               s_cdataCloseString[];
    00549
    00550     static const XalanDOMString::size_type  s_cdataCloseStringLength;
    00551
    00555     static const XalanDOMChar               s_lessThanEntityString[];
    00556
    00557     static const XalanDOMString::size_type  s_lessThanEntityStringLength;
    00558
    00562     static const XalanDOMChar               s_greaterThanEntityString[];
    00563
    00564     static const XalanDOMString::size_type  s_greaterThanEntityStringLength;
    00565
    00569     static const XalanDOMChar               s_ampersandEntityString[];
    00570
    00571     static const XalanDOMString::size_type  s_ampersandEntityStringLength;
    00572
    00576     static const XalanDOMChar               s_quoteEntityString[];
    00577
    00578     static const XalanDOMString::size_type  s_quoteEntityStringLength;
    00579
    00583     static const XalanDOMChar               s_linefeedNCRString[];
    00584
    00585     static const XalanDOMString::size_type  s_linefeedNCRStringLength;
    00586
    00591     BoolStackType   m_elemStack;
    00592
    00596     const XalanDOMChar*     m_newlineString;
    00597
    00601     XalanDOMString::size_type   m_newlineStringLength;
    00602
    00603
    00604     enum
    00605     {
    00606             kNotSpecial = 0,
    00607             kContentSpecial = 1,    // A flag to indicate a value in s_specialChars applies to content
    00608             kAttributeSpecial = 2,  // A flag to indicate a value in s_specialChars applies to attributes
    00609             kBothSpecial = 3,       // A flag t0 indicate a value in s_specialChars applies to both content and attributes
    00610             kSpecialsSize = 0x80,   // The size of s_specialChars
    00611             kBufferSize = 512       // The size of the buffer
    00612     };
    00613
    00614     static bool
    00615     isContentSpecial(XalanDOMChar   theChar)
    00616     {
    00617         if ((theChar < kSpecialsSize) && (s_specialChars[theChar] & kContentSpecial))
    00618         {
    00619             return true;
    00620         }
    00621         else
    00622         {
    00623             return false;
    00624         }
    00625     }
    00626
    00627     static bool
    00628     isAttributeSpecial(XalanDOMChar     theChar)
    00629     {
    00630         if ((theChar < kSpecialsSize) && (s_specialChars[theChar] & kAttributeSpecial))
    00631         {
    00632             return true;
    00633         }
    00634         else
    00635         {
    00636             return false;
    00637         }
    00638     }
    00639
    00640     static bool
    00641     isUTF16HighSurrogate(XalanDOMChar   theChar)
    00642     {
    00643         return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
    00644     }
    00645
    00646     static bool
    00647     isUTF16LowSurrogate(XalanDOMChar    theChar)
    00648     {
    00649         return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
    00650     }
    00651
    00652     XalanDOMChar                m_buffer[kBufferSize];
    00653
    00654     XalanDOMChar*               m_bufferPosition;
    00655
    00656     XalanDOMString::size_type                   m_bufferRemaining;
    00657
    00658     static const XalanDOMChar   s_specialChars[];
    00659 };
    00660
    00661
    00662
    00663 XALAN_CPP_NAMESPACE_END
    00664
    00665
    00666
    00667 #endif  // FORMATTERTOXML_UTF16_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.