Xalan-C++ API Reference  1.12.0
FormatterToSourceTree.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(FORMATTERTOSOURCETREE_HEADER_GUARD_1357924680)
19 #define FORMATTERTOSOURCETREE_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
29 
30 
31 
32 // Base class header file.
34 
35 
36 
38 
39 
40 
41 namespace XALAN_CPP_NAMESPACE {
42 
43 
44 
45 class PrefixResolver;
46 class XalanNode;
47 class XalanSourceTreeDocument;
48 class XalanSourceTreeDocumentFragment;
49 class XalanSourceTreeElement;
50 
51 
52 
53 /**
54  * This class takes SAX events (in addition to some extra events that SAX
55  * doesn't handle yet) and adds the result to a document or document fragment.
56  */
58 {
59 public:
60 
63 
64  enum { eDefaultStackSize = 50, eDefaultTextBufferSize = 100 };
65 
66  /**
67  * Perform static initialization. See class XalanSourceTreeInit.
68  */
69  static void
70  initialize(MemoryManager& theManager);
71 
72  /**
73  * Perform static shut down. See class XalanSourceTreeInit.
74  */
75  static void
76  terminate();
77 
78 
79  /**
80  * Construct a FormatterToSourceTree instance. it will add the nodes
81  * to the document.
82  *
83  * @param theDocument The document for nodes
84  */
85  explicit
87  MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR,
88  XalanSourceTreeDocument* theDocument = 0);
89 
90  /**
91  * Construct a FormatterToSourceTree instance. it will add the nodes
92  * to the document fragment.
93  *
94  * @param theDocument The document for nodes
95  * @param theDocumentFragment The document fragment for nodes
96  */
98  XalanSourceTreeDocument* theDocument,
99  XalanSourceTreeDocumentFragment* theDocumentFragment,
100  MemoryManager& theManager XALAN_DEFAULT_MEMMGR);
101 
102  virtual
104 
105 
107  getDocument() const
108  {
109  return m_document;
110  }
111 
112  void
114  {
115  m_document = theDocument;
116  }
117 
120  {
121  return m_documentFragment;
122  }
123 
124  void
126  {
127  m_documentFragment = theDocumentFragment;
128  }
129 
132  {
133  return m_currentElement;
134  }
135 
136  void
138  {
139  m_currentElement = theElement;
140  }
141 
142  // These methods are inherited from DocumentHandler ...
143 
144  virtual void
145  charactersRaw(
146  const XMLCh* const chars,
147  const size_type length);
148 
149  virtual void
150  comment(const XMLCh* const data);
151 
152  virtual void
153  cdata(
154  const XMLCh* const ch,
155  const size_type length);
156 
157  virtual void
158  entityReference(const XMLCh* const name);
159 
160  virtual void
161  setDocumentLocator(const Locator* const locator);
162 
163  virtual void
164  startDocument();
165 
166  virtual void
167  endDocument();
168 
169  virtual void
170  startElement(
171  const XMLCh* const name,
172  AttributeListType& attrs);
173 
174  virtual void
175  endElement(const XMLCh* const name);
176 
177  virtual void
178  characters(
179  const XMLCh* const chars,
180  const size_type length);
181 
182  virtual void
183  ignorableWhitespace(
184  const XMLCh* const chars,
185  const size_type length);
186 
187  virtual void
188  processingInstruction(
189  const XMLCh* const target,
190  const XMLCh* const data);
191 
192  virtual void
193  resetDocument();
194 
195 private:
196 
197  // Some utility functions...
198  void
199  processAccumulatedText();
200 
202  createElementNode(
203  const XalanDOMChar* name,
204  AttributeListType& attrs,
205  XalanSourceTreeElement* theParentElement);
206 
207  void
208  doCharacters(
209  const XalanDOMChar* chars,
210  size_type length);
211 
212  void
213  doProcessingInstruction(
214  const XalanDOMChar* target,
215  const XalanDOMChar* data);
216 
217 
218  // Data members...
219  XalanSourceTreeDocument* m_document;
220 
221  XalanSourceTreeDocumentFragment* m_documentFragment;
222 
223  XalanSourceTreeElement* m_currentElement;
224 
225  ElementStackType m_elementStack;
226 
227  // The last child appended to the current element. This is
228  // an important optimization, because XalanSourceTreeElement
229  // does not have a pointer to it's last child. Without this,
230  // appending a child becomes a linear search.
231  XalanNode* m_lastChild;
232 
233  // Stack of last children appended. There is a one-to-one
234  // correspondance to the entries in m_elementStack.
235  LastChildStackType m_lastChildStack;
236 
237  XalanDOMString m_textBuffer;
238 };
239 
240 
241 
242 }
243 
244 
245 
246 #endif // FORMATTERTOSOURCETREE_HEADER_GUARD_1357924680
xalanc::XalanSourceTreeDocumentFragment
Definition: XalanSourceTreeDocumentFragment.hpp:49
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::FormatterToSourceTree::getCurrentElement
XalanSourceTreeElement * getCurrentElement() const
Definition: FormatterToSourceTree.hpp:131
xalanc::AttributeListType
xercesc::AttributeList AttributeListType
Definition: AttributeListImpl.hpp:41
xalanc::XalanNode
Definition: XalanNode.hpp:38
XalanDOMString.hpp
xalanc::XalanVector< XalanSourceTreeElement * >
FormatterListener.hpp
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
XALAN_DEFAULT_MEMMGR
#define XALAN_DEFAULT_MEMMGR
Definition: XalanMemoryManagement.hpp:516
XalanVector.hpp
xalanc::FormatterToSourceTree::setCurrentElement
void setCurrentElement(XalanSourceTreeElement *theElement)
Definition: FormatterToSourceTree.hpp:137
xalanc::FormatterToSourceTree
This class takes SAX events (in addition to some extra events that SAX doesn't handle yet) and adds t...
Definition: FormatterToSourceTree.hpp:57
xalanc::FormatterToSourceTree::getDocument
XalanSourceTreeDocument * getDocument() const
Definition: FormatterToSourceTree.hpp:107
xalanc::FormatterToSourceTree::ElementStackType
XalanVector< XalanSourceTreeElement * > ElementStackType
Definition: FormatterToSourceTree.hpp:61
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
xalanc::FormatterToSourceTree::setDocument
void setDocument(XalanSourceTreeDocument *theDocument)
Definition: FormatterToSourceTree.hpp:113
XalanSourceTreeDefinitions.hpp
xalanc::FormatterToSourceTree::setDocumentFragment
void setDocumentFragment(XalanSourceTreeDocumentFragment *theDocumentFragment)
Definition: FormatterToSourceTree.hpp:125
xalanc::FormatterListener
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:56
XALAN_XALANSOURCETREE_EXPORT
#define XALAN_XALANSOURCETREE_EXPORT
Definition: XalanSourceTreeDefinitions.hpp:35
xalanc::XalanSourceTreeElement
Definition: XalanSourceTreeElement.hpp:46
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::FormatterToSourceTree::LastChildStackType
XalanVector< XalanNode * > LastChildStackType
Definition: FormatterToSourceTree.hpp:62
xalanc::XalanSourceTreeDocument
Definition: XalanSourceTreeDocument.hpp:78
XALAN_DEFAULT_CONSTRUCTOR_MEMMGR
#define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR
Definition: XalanMemoryManagement.hpp:515
xalanc::FormatterToSourceTree::getDocumentFragment
XalanSourceTreeDocumentFragment * getDocumentFragment() const
Definition: FormatterToSourceTree.hpp:119