00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999-2004 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(FORMATTERTOXMLBASE_HEADER_GUARD_1357924680) 00058 #define FORMATTERTOXMLBASE_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 FormatterToXMLBase : public FormatterListener 00093 { 00094 public: 00095 00111 FormatterToXMLBase( 00112 Writer& writer, 00113 const XalanDOMString& version, 00114 const XalanDOMString& mediaType, 00115 const XalanDOMString& doctypeSystem, 00116 const XalanDOMString& doctypePublic, 00117 bool xmlDecl, 00118 const XalanDOMString& standalone); 00119 00120 virtual 00121 ~FormatterToXMLBase(); 00122 00123 // These methods are inherited from FormatterListener ... 00124 00125 virtual void 00126 setDocumentLocator(const LocatorType* const locator); 00127 00128 virtual void 00129 startDocument(); 00130 00131 virtual void 00132 endDocument(); 00133 00134 virtual void 00135 startElement( 00136 const XMLCh* const name, 00137 AttributeListType& attrs) = 0; 00138 00139 virtual void 00140 endElement(const XMLCh* const name) = 0; 00141 00142 virtual void 00143 characters( 00144 const XMLCh* const chars, 00145 const unsigned int length); 00146 00147 virtual void 00148 charactersRaw( 00149 const XMLCh* const chars, 00150 const unsigned int length) = 0; 00151 00152 virtual void 00153 entityReference(const XMLCh* const name) = 0; 00154 00155 virtual void 00156 ignorableWhitespace( 00157 const XMLCh* const chars, 00158 const unsigned int length); 00159 00160 virtual void 00161 processingInstruction( 00162 const XMLCh* const target, 00163 const XMLCh* const data); 00164 00165 virtual void 00166 resetDocument(); 00167 00168 virtual void 00169 comment(const XMLCh* const data) = 0; 00170 00171 virtual void 00172 cdata( 00173 const XMLCh* const ch, 00174 const unsigned int length); 00175 00176 virtual Writer* 00177 getWriter() const; 00178 00179 virtual const XalanDOMString& 00180 getDoctypeSystem() const; 00181 00182 virtual const XalanDOMString& 00183 getDoctypePublic() const; 00184 00185 virtual const XalanDOMString& 00186 getEncoding() const = 0; 00187 00188 virtual const XalanDOMString& 00189 getMediaType() const; 00190 00191 const XalanDOMString& 00192 getVersion() const 00193 { 00194 return m_version; 00195 } 00196 00197 const XalanDOMString& 00198 getStandalone() const 00199 { 00200 return m_standalone; 00201 } 00202 00203 bool 00204 getShouldWriteXMLHeader() const 00205 { 00206 return m_shouldWriteXMLHeader; 00207 } 00208 00209 void 00210 setShouldWriteXMLHeader(bool b) 00211 { 00212 m_shouldWriteXMLHeader = b; 00213 } 00214 00215 #if defined(XALAN_NO_STD_NAMESPACE) 00216 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL) 00217 typedef deque<bool> BoolStackType; 00218 #else 00219 typedef vector<bool> BoolStackType; 00220 #endif 00221 #else 00222 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL) 00223 typedef std::deque<bool> BoolStackType; 00224 #else 00225 typedef std::vector<bool> BoolStackType; 00226 #endif 00227 #endif 00228 00229 protected: 00230 00231 virtual void 00232 writeXMLHeader() = 0; 00233 00234 virtual void 00235 flushBuffer() = 0; 00236 00237 virtual void 00238 writeDoctypeDecl(const XalanDOMChar* name) = 0; 00239 00240 virtual void 00241 writeProcessingInstruction( 00242 const XMLCh* target, 00243 const XMLCh* data) = 0; 00244 00245 virtual void 00246 writeCharacters( 00247 const XMLCh* chars, 00248 unsigned int length) = 0; 00249 00250 virtual void 00251 writeCDATA( 00252 const XMLCh* chars, 00253 unsigned int length) = 0; 00254 00263 bool 00264 markParentForChildren() 00265 { 00266 if(!m_elemStack.empty()) 00267 { 00268 // See if the parent element has already been flagged as having children. 00269 if(false == m_elemStack.back()) 00270 { 00271 m_elemStack.back() = true; 00272 00273 return true; 00274 } 00275 } 00276 00277 return false; 00278 } 00279 00283 void 00284 openElementForChildren() 00285 { 00286 m_elemStack.push_back(false); 00287 } 00288 00289 bool 00290 outsideDocumentElement() const 00291 { 00292 return m_elemStack.empty(); 00293 } 00294 00300 bool 00301 childNodesWereAdded() 00302 { 00303 bool fResult = false; 00304 00305 if (m_elemStack.empty() == false) 00306 { 00307 fResult = m_elemStack.back(); 00308 00309 m_elemStack.pop_back(); 00310 } 00311 00312 return fResult; 00313 } 00314 00315 void 00316 generateDoctypeDecl(const XalanDOMChar* name) 00317 { 00318 if(true == m_needToOutputDoctypeDecl) 00319 { 00320 assert(m_doctypeSystem.empty() == false); 00321 00322 writeDoctypeDecl(name); 00323 00324 m_needToOutputDoctypeDecl = false; 00325 } 00326 } 00327 00331 Writer* m_writer; 00332 00333 void 00334 flushWriter(); 00335 00339 bool m_nextIsRaw; 00340 00344 bool m_spaceBeforeClose; 00345 00349 const XalanDOMString m_doctypeSystem; 00350 00354 const XalanDOMString m_doctypePublic; 00355 00359 const XalanDOMString m_version; 00360 00364 const XalanDOMString m_standalone; 00365 00369 const XalanDOMString m_mediaType; 00370 00374 const XalanDOMChar* m_newlineString; 00375 00379 XalanDOMString::size_type m_newlineStringLength; 00380 00381 static bool 00382 isUTF16HighSurrogate(XalanDOMChar theChar) 00383 { 00384 return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false; 00385 } 00386 00387 static bool 00388 isUTF16LowSurrogate(XalanDOMChar theChar) 00389 { 00390 return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false; 00391 } 00392 00393 static unsigned int 00394 decodeUTF16SurrogatePair( 00395 XalanDOMChar theHighSurrogate, 00396 XalanDOMChar theLowSurrogate); 00397 00403 static void 00404 throwInvalidUTF16SurrogateException(XalanDOMChar ch); 00405 00412 static void 00413 throwInvalidUTF16SurrogateException( 00414 XalanDOMChar ch, 00415 XalanDOMChar next); 00416 00423 static void 00424 throwInvalidCharacterException(unsigned int ch); 00425 00426 enum 00427 { 00428 kNotSpecial = 0, 00429 kContentSpecial = 1, // A flag to indicate a value in s_specialChars applies to content 00430 kAttributeSpecial = 2, // A flag to indicate a value in s_specialChars applies to attributes 00431 kBothSpecial = 3, // A flag t0 indicate a value in s_specialChars applies to both content and attributes 00432 kSpecialsSize = 0x80, // The size of s_specialChars 00433 kBufferSize = 512 // The size of the buffer 00434 }; 00435 00436 static const XalanDOMChar s_specialChars[]; 00437 00438 private: 00439 00440 // These are not implemented. 00441 FormatterToXMLBase(const FormatterToXMLBase&); 00442 00443 FormatterToXMLBase& 00444 operator=(const FormatterToXMLBase&); 00445 00446 bool 00447 operator==(const FormatterToXMLBase&) const; 00448 00449 // Data members... 00455 bool m_needToOutputDoctypeDecl; 00456 00460 bool m_shouldWriteXMLHeader; 00461 00466 BoolStackType m_elemStack; 00467 00471 static const XalanDOMChar s_xhtmlDocTypeString[]; 00472 00473 static const XalanDOMString::size_type s_xhtmlDocTypeStringLength; 00474 }; 00475 00476 00477 00478 XALAN_CPP_NAMESPACE_END 00479 00480 00481 00482 #endif // FORMATTERTOXMLBASE_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.7 |
|