00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(FORMATTERTOSOURCETREE_HEADER_GUARD_1357924680) 00019 #define FORMATTERTOSOURCETREE_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XalanSourceTree/XalanSourceTreeDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 00030 00031 00032 // Base class header file. 00033 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00034 00035 00036 00037 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00038 00039 00040 00041 XALAN_CPP_NAMESPACE_BEGIN 00042 00043 00044 00045 class PrefixResolver; 00046 class XalanNode; 00047 class XalanSourceTreeDocument; 00048 class XalanSourceTreeDocumentFragment; 00049 class XalanSourceTreeElement; 00050 00051 00052 00053 /** 00054 * This class takes SAX events (in addition to some extra events that SAX 00055 * doesn't handle yet) and adds the result to a document or document fragment. 00056 */ 00057 class XALAN_XALANSOURCETREE_EXPORT FormatterToSourceTree : public FormatterListener 00058 { 00059 public: 00060 00061 typedef XalanVector<XalanSourceTreeElement*> ElementStackType; 00062 typedef XalanVector<XalanNode*> LastChildStackType; 00063 00064 enum { eDefaultStackSize = 50, eDefaultTextBufferSize = 100 }; 00065 00066 /** 00067 * Perform static initialization. See class XalanSourceTreeInit. 00068 */ 00069 static void 00070 initialize(MemoryManager& theManager); 00071 00072 /** 00073 * Perform static shut down. See class XalanSourceTreeInit. 00074 */ 00075 static void 00076 terminate(); 00077 00078 00079 /** 00080 * Construct a FormatterToSourceTree instance. it will add the nodes 00081 * to the document. 00082 * 00083 * @param theDocument The document for nodes 00084 */ 00085 explicit 00086 FormatterToSourceTree( 00087 MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR, 00088 XalanSourceTreeDocument* theDocument = 0); 00089 00090 /** 00091 * Construct a FormatterToSourceTree instance. it will add the nodes 00092 * to the document fragment. 00093 * 00094 * @param theDocument The document for nodes 00095 * @param theDocumentFragment The document fragment for nodes 00096 */ 00097 FormatterToSourceTree( 00098 XalanSourceTreeDocument* theDocument, 00099 XalanSourceTreeDocumentFragment* theDocumentFragment, 00100 MemoryManager& theManager XALAN_DEFAULT_MEMMGR); 00101 00102 virtual 00103 ~FormatterToSourceTree(); 00104 00105 00106 XalanSourceTreeDocument* 00107 getDocument() const 00108 { 00109 return m_document; 00110 } 00111 00112 void 00113 setDocument(XalanSourceTreeDocument* theDocument) 00114 { 00115 m_document = theDocument; 00116 } 00117 00118 XalanSourceTreeDocumentFragment* 00119 getDocumentFragment() const 00120 { 00121 return m_documentFragment; 00122 } 00123 00124 void 00125 setDocumentFragment(XalanSourceTreeDocumentFragment* theDocumentFragment) 00126 { 00127 m_documentFragment = theDocumentFragment; 00128 } 00129 00130 XalanSourceTreeElement* 00131 getCurrentElement() const 00132 { 00133 return m_currentElement; 00134 } 00135 00136 void 00137 setCurrentElement(XalanSourceTreeElement* theElement) 00138 { 00139 m_currentElement = theElement; 00140 } 00141 00142 // These methods are inherited from DocumentHandler ... 00143 00144 virtual void 00145 charactersRaw( 00146 const XMLCh* const chars, 00147 const size_type length); 00148 00149 virtual void 00150 comment(const XMLCh* const data); 00151 00152 virtual void 00153 cdata( 00154 const XMLCh* const ch, 00155 const size_type length); 00156 00157 virtual void 00158 entityReference(const XMLCh* const name); 00159 00160 virtual void 00161 setDocumentLocator(const Locator* const locator); 00162 00163 virtual void 00164 startDocument(); 00165 00166 virtual void 00167 endDocument(); 00168 00169 virtual void 00170 startElement( 00171 const XMLCh* const name, 00172 AttributeListType& attrs); 00173 00174 virtual void 00175 endElement(const XMLCh* const name); 00176 00177 virtual void 00178 characters( 00179 const XMLCh* const chars, 00180 const size_type length); 00181 00182 virtual void 00183 ignorableWhitespace( 00184 const XMLCh* const chars, 00185 const size_type length); 00186 00187 virtual void 00188 processingInstruction( 00189 const XMLCh* const target, 00190 const XMLCh* const data); 00191 00192 virtual void 00193 resetDocument(); 00194 00195 private: 00196 00197 // Some utility functions... 00198 void 00199 processAccumulatedText(); 00200 00201 XalanSourceTreeElement* 00202 createElementNode( 00203 const XalanDOMChar* name, 00204 AttributeListType& attrs, 00205 XalanSourceTreeElement* theParentElement); 00206 00207 void 00208 doCharacters( 00209 const XalanDOMChar* chars, 00210 size_type length); 00211 00212 void 00213 doProcessingInstruction( 00214 const XalanDOMChar* target, 00215 const XalanDOMChar* data); 00216 00217 00218 // Data members... 00219 XalanSourceTreeDocument* m_document; 00220 00221 XalanSourceTreeDocumentFragment* m_documentFragment; 00222 00223 XalanSourceTreeElement* m_currentElement; 00224 00225 ElementStackType m_elementStack; 00226 00227 // The last child appended to the current element. This is 00228 // an important optimization, because XalanSourceTreeElement 00229 // does not have a pointer to it's last child. Without this, 00230 // appending a child becomes a linear search. 00231 XalanNode* m_lastChild; 00232 00233 // Stack of last children appended. There is a one-to-one 00234 // correspondance to the entries in m_elementStack. 00235 LastChildStackType m_lastChildStack; 00236 00237 XalanDOMString m_textBuffer; 00238 }; 00239 00240 00241 00242 XALAN_CPP_NAMESPACE_END 00243 00244 00245 00246 #endif // FORMATTERTOSOURCETREE_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.11 |
|