Xalan-C++ API Reference  1.12.0
XalanSourceTreeContentHandler.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 
19 #if !defined(XALANSOURCETREECONTENTHANDLER_HEADER_GUARD_1357924680)
20 #define XALANSOURCETREECONTENTHANDLER_HEADER_GUARD_1357924680
21 
22 
23 
25 
26 
27 
29 
30 
31 
32 #include <xercesc/sax/DocumentHandler.hpp>
33 #include <xercesc/sax/DTDHandler.hpp>
34 #include <xercesc/sax2/ContentHandler.hpp>
35 #include <xercesc/sax2/LexicalHandler.hpp>
36 
37 
38 
40 
41 
42 
43 namespace XERCES_CPP_NAMESPACE
44 {
45  class Attributes;
46  class AttributeList;
47  class ContentHandler;
48  class DTDHandler;
49  class LexicalHandler;
50  class Locator;
51 }
52 
53 
54 
55 namespace XALAN_CPP_NAMESPACE {
56 
57 
58 
59 using xercesc::Locator;
60 
61 
62 
63 typedef xercesc::Attributes AttributesType;
64 typedef xercesc::AttributeList AttributeListType;
65 typedef xercesc::ContentHandler ContentHandlerType;
66 typedef xercesc::DTDHandler DTDHandlerType;
67 typedef xercesc::LexicalHandler LexicalHandlerType;
68 typedef xercesc::Locator LocatorType;
69 
70 
71 
72 class XalanNode;
75 
76 
77 
79  public ContentHandlerType,
80  public DTDHandlerType,
81  public LexicalHandlerType
82 {
83 public:
84 
87  typedef XalanSize_t size_type;
88 
89  enum { eDefaultStackSize = 50, eDefaultTextBufferSize = 100 };
90 
91 
92  // Constructor
93  explicit
95  MemoryManager& theManager,
96  XalanSourceTreeDocument* theDocument = 0,
97  bool fAccumulateText = true);
98 
99  virtual
101 
102 
103  // Inherited from ContentHandler...
104  virtual void
105  characters(
106  const XMLCh* const chars,
107  const size_type length);
108 
109  virtual void
110  endDocument();
111 
112  virtual void
113  endElement(
114  const XMLCh* const uri,
115  const XMLCh* const localname,
116  const XMLCh* const qname);
117 
118  virtual void
119  ignorableWhitespace(
120  const XMLCh* const chars,
121  const size_type length);
122 
123  virtual void
124  processingInstruction(
125  const XMLCh* const target,
126  const XMLCh* const data);
127 
128  virtual void
129  setDocumentLocator(const Locator* const locator);
130 
131  virtual void
132  startDocument();
133 
134  virtual void
135  startElement(
136  const XMLCh* const uri,
137  const XMLCh* const localname,
138  const XMLCh* const qname,
139  const AttributesType& attrs);
140 
141  virtual void
142  startPrefixMapping(
143  const XMLCh* const prefix,
144  const XMLCh* const uri);
145 
146  virtual void
147  endPrefixMapping(const XMLCh* const prefix);
148 
149 
150  virtual void
151  skippedEntity(const XMLCh* const name);
152 
153 
154  // Inherited from DTDHandler...
155 
156  virtual void
157  notationDecl(
158  const XMLCh* const name,
159  const XMLCh* const publicId,
160  const XMLCh* const systemId);
161 
162  virtual void
163  unparsedEntityDecl(
164  const XMLCh* const name,
165  const XMLCh* const publicId,
166  const XMLCh* const systemId,
167  const XMLCh* const notationName);
168 
169  virtual void
170  resetDocType();
171 
172 
173  // Inherited from LexicalHandler...
174 
175  virtual void
176  comment(
177  const XMLCh* const chars,
178  const size_type length);
179 
180  virtual void
181  endCDATA();
182 
183  virtual void
184  endDTD();
185 
186  virtual void
187  endEntity(const XMLCh* const name);
188 
189  virtual void
190  startCDATA();
191 
192  virtual void
193  startDTD(
194  const XMLCh* const name,
195  const XMLCh* const publicId,
196  const XMLCh* const systemId);
197 
198  virtual void
199  startEntity(const XMLCh* const name);
200 
201 
202  // New to XalanSourceTreeContentHandler...
203 
205  getDocument() const
206  {
207  return m_document;
208  }
209 
210  void
211  setDocument(XalanSourceTreeDocument* theDocument);
212 
213 private:
214 
215  // Not implemented...
217 
219  operator=(const XalanSourceTreeContentHandler&);
220 
221  bool
223 
224  // Helper functions...
226  createElement(
227  const XMLCh* const uri,
228  const XMLCh* const localname,
229  const XMLCh* const qname,
230  const AttributesType& attrs,
231  XalanSourceTreeElement* theOwnerElement);
232 
233  void
234  processAccumulatedText();
235 
236  void
237  doCharacters(
238  const XMLCh* chars,
239  size_type length);
240 
241  // Data members...
242 
243  // The current document we're building...
244  XalanSourceTreeDocument* m_document;
245 
246  // The current element...
247  XalanSourceTreeElement* m_currentElement;
248 
249  // Stack of elements...
250  ElementStackType m_elementStack;
251 
252  // The last child appended to the current element. This is
253  // an important optimization, because XalanSourceTreeElement
254  // does not have a pointer to its last child. Without this,
255  // appending a child becomes a linear search.
256  XalanNode* m_lastChild;
257 
258  // Stack of last children appended. There is a ono-to-one
259  // correspondance to the entries in m_elementStack.
260  LastChildStackType m_lastChildStack;
261 
262  // If true, the handler will accumulate text from calls to
263  // characters() until another event triggers the creation
264  // of the node.
265  const bool m_accumulateText;
266 
267  // A buffer to hold accumulated text.
268  XalanDOMString m_textBuffer;
269 
270  // A flag to determine if the DTD is being processed.
271  bool m_inDTD;
272 };
273 
274 
275 
276 }
277 
278 
279 
280 #endif // #if !defined(XALANSOURCETREECONTENTHANDLER_HEADER_GUARD_1357924680)
xalanc::XalanSourceTreeContentHandler::ElementStackType
XalanVector< XalanSourceTreeElement * > ElementStackType
Definition: XalanSourceTreeContentHandler.hpp:85
xalanc::ContentHandlerType
xercesc::ContentHandler ContentHandlerType
Definition: XalanSourceTreeContentHandler.hpp:65
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanSourceTreeContentHandler::LastChildStackType
XalanVector< XalanNode * > LastChildStackType
Definition: XalanSourceTreeContentHandler.hpp:86
xalanc::AttributeListType
xercesc::AttributeList AttributeListType
Definition: AttributeListImpl.hpp:41
xalanc::XalanNode
Definition: XalanNode.hpp:38
XalanDOMString.hpp
xalanc::XalanVector< XalanSourceTreeElement * >
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
XalanVector.hpp
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::LexicalHandlerType
xercesc::LexicalHandler LexicalHandlerType
Definition: XalanSourceTreeContentHandler.hpp:67
xalanc::XalanSourceTreeContentHandler::size_type
XalanSize_t size_type
Definition: XalanSourceTreeContentHandler.hpp:87
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
XalanSourceTreeDefinitions.hpp
xalanc::XalanSourceTreeContentHandler
Definition: XalanSourceTreeContentHandler.hpp:78
XALAN_XALANSOURCETREE_EXPORT
#define XALAN_XALANSOURCETREE_EXPORT
Definition: XalanSourceTreeDefinitions.hpp:35
xalanc::XalanSourceTreeElement
Definition: XalanSourceTreeElement.hpp:46
xalanc::DTDHandlerType
xercesc::DTDHandler DTDHandlerType
Definition: XalanSourceTreeContentHandler.hpp:66
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanSourceTreeDocument
Definition: XalanSourceTreeDocument.hpp:78
xalanc::AttributesType
xercesc::Attributes AttributesType
Definition: AttributesImpl.hpp:40
xalanc::XalanSourceTreeContentHandler::getDocument
XalanSourceTreeDocument * getDocument() const
Definition: XalanSourceTreeContentHandler.hpp:205
xalanc::LocatorType
xercesc::Locator LocatorType
Definition: ExecutionContext.hpp:47