1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: XSDDOMParser.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | #if !defined(XSDDOMPARSER_HPP) |
---|
24 | #define XSDDOMPARSER_HPP |
---|
25 | |
---|
26 | |
---|
27 | #include <xercesc/parsers/XercesDOMParser.hpp> |
---|
28 | #include <xercesc/validators/schema/XSDErrorReporter.hpp> |
---|
29 | #include <xercesc/validators/schema/XSDLocator.hpp> |
---|
30 | |
---|
31 | XERCES_CPP_NAMESPACE_BEGIN |
---|
32 | |
---|
33 | class DOMElement; |
---|
34 | class XMLValidator; |
---|
35 | |
---|
36 | |
---|
37 | /** |
---|
38 | * This class is used to parse schema documents into DOM trees |
---|
39 | */ |
---|
40 | class PARSERS_EXPORT XSDDOMParser : public XercesDOMParser |
---|
41 | { |
---|
42 | public : |
---|
43 | |
---|
44 | // ----------------------------------------------------------------------- |
---|
45 | // Constructors and Detructor |
---|
46 | // ----------------------------------------------------------------------- |
---|
47 | |
---|
48 | /** @name Constructors and Destructor */ |
---|
49 | //@{ |
---|
50 | /** Construct a XSDDOMParser, with an optional validator |
---|
51 | * |
---|
52 | * Constructor with an instance of validator class to use for |
---|
53 | * validation. If you don't provide a validator, a default one will |
---|
54 | * be created for you in the scanner. |
---|
55 | * |
---|
56 | * @param gramPool Pointer to the grammar pool instance from |
---|
57 | * external application. |
---|
58 | * The parser does NOT own it. |
---|
59 | * |
---|
60 | * @param valToAdopt Pointer to the validator instance to use. The |
---|
61 | * parser is responsible for freeing the memory. |
---|
62 | */ |
---|
63 | XSDDOMParser |
---|
64 | ( |
---|
65 | XMLValidator* const valToAdopt = 0 |
---|
66 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
67 | , XMLGrammarPool* const gramPool = 0 |
---|
68 | ); |
---|
69 | |
---|
70 | /** |
---|
71 | * Destructor |
---|
72 | */ |
---|
73 | ~XSDDOMParser(); |
---|
74 | |
---|
75 | //@} |
---|
76 | |
---|
77 | // ----------------------------------------------------------------------- |
---|
78 | // Implementation of the XMLDocumentHandler interface. |
---|
79 | // ----------------------------------------------------------------------- |
---|
80 | |
---|
81 | /** @name Implementation of the XMLDocumentHandler interface. */ |
---|
82 | //@{ |
---|
83 | |
---|
84 | /** Handle a start element event |
---|
85 | * |
---|
86 | * This method is used to report the start of an element. It is |
---|
87 | * called at the end of the element, by which time all attributes |
---|
88 | * specified are also parsed. A new DOM Element node is created |
---|
89 | * along with as many attribute nodes as required. This new element |
---|
90 | * is added appended as a child of the current node in the tree, and |
---|
91 | * then replaces it as the current node (if the isEmpty flag is false.) |
---|
92 | * |
---|
93 | * @param elemDecl A const reference to the object containing element |
---|
94 | * declaration information. |
---|
95 | * @param urlId An id referring to the namespace prefix, if |
---|
96 | * namespaces setting is switched on. |
---|
97 | * @param elemPrefix A const pointer to a Unicode string containing |
---|
98 | * the namespace prefix for this element. Applicable |
---|
99 | * only when namespace processing is enabled. |
---|
100 | * @param attrList A const reference to the object containing the |
---|
101 | * list of attributes just scanned for this element. |
---|
102 | * @param attrCount A count of number of attributes in the list |
---|
103 | * specified by the parameter 'attrList'. |
---|
104 | * @param isEmpty A flag indicating whether this is an empty element |
---|
105 | * or not. If empty, then no endElement() call will |
---|
106 | * be made. |
---|
107 | * @param isRoot A flag indicating whether this element was the |
---|
108 | * root element. |
---|
109 | * @see DocumentHandler#startElement |
---|
110 | */ |
---|
111 | virtual void startElement |
---|
112 | ( |
---|
113 | const XMLElementDecl& elemDecl |
---|
114 | , const unsigned int urlId |
---|
115 | , const XMLCh* const elemPrefix |
---|
116 | , const RefVectorOf<XMLAttr>& attrList |
---|
117 | , const unsigned int attrCount |
---|
118 | , const bool isEmpty |
---|
119 | , const bool isRoot |
---|
120 | ); |
---|
121 | |
---|
122 | /** Handle and end of element event |
---|
123 | * |
---|
124 | * This method is used to indicate the end tag of an element. The |
---|
125 | * DOM parser pops the current element off the top of the element |
---|
126 | * stack, and make it the new current element. |
---|
127 | * |
---|
128 | * @param elemDecl A const reference to the object containing element |
---|
129 | * declaration information. |
---|
130 | * @param urlId An id referring to the namespace prefix, if |
---|
131 | * namespaces setting is switched on. |
---|
132 | * @param isRoot A flag indicating whether this element was the |
---|
133 | * root element. |
---|
134 | * @param elemPrefix A const pointer to a Unicode string containing |
---|
135 | * the namespace prefix for this element. Applicable |
---|
136 | * only when namespace processing is enabled. |
---|
137 | */ |
---|
138 | virtual void endElement |
---|
139 | ( |
---|
140 | const XMLElementDecl& elemDecl |
---|
141 | , const unsigned int urlId |
---|
142 | , const bool isRoot |
---|
143 | , const XMLCh* const elemPrefix |
---|
144 | ); |
---|
145 | |
---|
146 | /** Handle document character events |
---|
147 | * |
---|
148 | * This method is used to report all the characters scanned by the |
---|
149 | * parser. This DOM implementation stores this data in the appropriate |
---|
150 | * DOM node, creating one if necessary. |
---|
151 | * |
---|
152 | * @param chars A const pointer to a Unicode string representing the |
---|
153 | * character data. |
---|
154 | * @param length The length of the Unicode string returned in 'chars'. |
---|
155 | * @param cdataSection A flag indicating if the characters represent |
---|
156 | * content from the CDATA section. |
---|
157 | */ |
---|
158 | virtual void docCharacters |
---|
159 | ( |
---|
160 | const XMLCh* const chars |
---|
161 | , const unsigned int length |
---|
162 | , const bool cdataSection |
---|
163 | ); |
---|
164 | |
---|
165 | /** Handle a document comment event |
---|
166 | * |
---|
167 | * This method is used to report any comments scanned by the parser. |
---|
168 | * A new comment node is created which stores this data. |
---|
169 | * |
---|
170 | * @param comment A const pointer to a null terminated Unicode |
---|
171 | * string representing the comment text. |
---|
172 | */ |
---|
173 | virtual void docComment |
---|
174 | ( |
---|
175 | const XMLCh* const comment |
---|
176 | ); |
---|
177 | |
---|
178 | /** Handle a start entity reference event |
---|
179 | * |
---|
180 | * This method is used to indicate the start of an entity reference. |
---|
181 | * If the expand entity reference flag is true, then a new |
---|
182 | * DOM Entity reference node is created. |
---|
183 | * |
---|
184 | * @param entDecl A const reference to the object containing the |
---|
185 | * entity declaration information. |
---|
186 | */ |
---|
187 | virtual void startEntityReference |
---|
188 | ( |
---|
189 | const XMLEntityDecl& entDecl |
---|
190 | ); |
---|
191 | |
---|
192 | /** Handle and end of entity reference event |
---|
193 | * |
---|
194 | * This method is used to indicate that an end of an entity reference |
---|
195 | * was just scanned. |
---|
196 | * |
---|
197 | * @param entDecl A const reference to the object containing the |
---|
198 | * entity declaration information. |
---|
199 | */ |
---|
200 | virtual void endEntityReference |
---|
201 | ( |
---|
202 | const XMLEntityDecl& entDecl |
---|
203 | ); |
---|
204 | |
---|
205 | /** Handle an ignorable whitespace vent |
---|
206 | * |
---|
207 | * This method is used to report all the whitespace characters, which |
---|
208 | * are determined to be 'ignorable'. This distinction between characters |
---|
209 | * is only made, if validation is enabled. |
---|
210 | * |
---|
211 | * Any whitespace before content is ignored. If the current node is |
---|
212 | * already of type DOMNode::TEXT_NODE, then these whitespaces are |
---|
213 | * appended, otherwise a new Text node is created which stores this |
---|
214 | * data. Essentially all contiguous ignorable characters are collected |
---|
215 | * in one node. |
---|
216 | * |
---|
217 | * @param chars A const pointer to a Unicode string representing the |
---|
218 | * ignorable whitespace character data. |
---|
219 | * @param length The length of the Unicode string 'chars'. |
---|
220 | * @param cdataSection A flag indicating if the characters represent |
---|
221 | * content from the CDATA section. |
---|
222 | */ |
---|
223 | virtual void ignorableWhitespace |
---|
224 | ( |
---|
225 | const XMLCh* const chars |
---|
226 | , const unsigned int length |
---|
227 | , const bool cdataSection |
---|
228 | ); |
---|
229 | |
---|
230 | //@} |
---|
231 | |
---|
232 | // ----------------------------------------------------------------------- |
---|
233 | // Get methods |
---|
234 | // ----------------------------------------------------------------------- |
---|
235 | bool getSawFatal() const; |
---|
236 | |
---|
237 | |
---|
238 | // ----------------------------------------------------------------------- |
---|
239 | // Set methods |
---|
240 | // ----------------------------------------------------------------------- |
---|
241 | void setUserErrorReporter(XMLErrorReporter* const errorReporter); |
---|
242 | void setUserEntityHandler(XMLEntityHandler* const entityHandler); |
---|
243 | |
---|
244 | |
---|
245 | // ----------------------------------------------------------------------- |
---|
246 | // XMLErrorReporter interface |
---|
247 | // ----------------------------------------------------------------------- |
---|
248 | virtual void error |
---|
249 | ( |
---|
250 | const unsigned int errCode |
---|
251 | , const XMLCh* const errDomain |
---|
252 | , const ErrTypes type |
---|
253 | , const XMLCh* const errorText |
---|
254 | , const XMLCh* const systemId |
---|
255 | , const XMLCh* const publicId |
---|
256 | , const XMLSSize_t lineNum |
---|
257 | , const XMLSSize_t colNum |
---|
258 | ); |
---|
259 | |
---|
260 | // ----------------------------------------------------------------------- |
---|
261 | // XMLEntityHandler interface |
---|
262 | // ----------------------------------------------------------------------- |
---|
263 | virtual InputSource* resolveEntity |
---|
264 | ( |
---|
265 | const XMLCh* const publicId |
---|
266 | , const XMLCh* const systemId |
---|
267 | , const XMLCh* const baseURI = 0 |
---|
268 | ); |
---|
269 | |
---|
270 | virtual InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier); |
---|
271 | |
---|
272 | protected : |
---|
273 | // ----------------------------------------------------------------------- |
---|
274 | // Protected Helper methods |
---|
275 | // ----------------------------------------------------------------------- |
---|
276 | virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI, |
---|
277 | const XMLCh *qualifiedName); |
---|
278 | |
---|
279 | private: |
---|
280 | // ----------------------------------------------------------------------- |
---|
281 | // Unimplemented constructors and operators |
---|
282 | // ----------------------------------------------------------------------- |
---|
283 | XSDDOMParser(const XSDDOMParser&); |
---|
284 | XSDDOMParser& operator=(const XSDDOMParser&); |
---|
285 | |
---|
286 | // ----------------------------------------------------------------------- |
---|
287 | // Private Helper methods |
---|
288 | // ----------------------------------------------------------------------- |
---|
289 | void startAnnotation |
---|
290 | ( |
---|
291 | const XMLElementDecl& elemDecl |
---|
292 | , const RefVectorOf<XMLAttr>& attrList |
---|
293 | , const unsigned int attrCount |
---|
294 | ); |
---|
295 | void startAnnotationElement |
---|
296 | ( |
---|
297 | const XMLElementDecl& elemDecl |
---|
298 | , const RefVectorOf<XMLAttr>& attrList |
---|
299 | , const unsigned int attrCount |
---|
300 | ); |
---|
301 | void endAnnotationElement |
---|
302 | ( |
---|
303 | const XMLElementDecl& elemDecl |
---|
304 | , bool complete |
---|
305 | ); |
---|
306 | |
---|
307 | // ----------------------------------------------------------------------- |
---|
308 | // Private data members |
---|
309 | // ----------------------------------------------------------------------- |
---|
310 | bool fSawFatal; |
---|
311 | int fAnnotationDepth; |
---|
312 | int fInnerAnnotationDepth; |
---|
313 | int fDepth; |
---|
314 | XMLErrorReporter* fUserErrorReporter; |
---|
315 | XMLEntityHandler* fUserEntityHandler; |
---|
316 | ValueVectorOf<unsigned int>* fURIs; |
---|
317 | XMLBuffer fAnnotationBuf; |
---|
318 | XSDErrorReporter fXSDErrorReporter; |
---|
319 | XSDLocator fXSLocator; |
---|
320 | }; |
---|
321 | |
---|
322 | |
---|
323 | inline bool XSDDOMParser::getSawFatal() const |
---|
324 | { |
---|
325 | return fSawFatal; |
---|
326 | } |
---|
327 | |
---|
328 | XERCES_CPP_NAMESPACE_END |
---|
329 | |
---|
330 | #endif |
---|