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: DOMBuilderImpl.hpp 569031 2007-08-23 15:05:28Z amassari $ |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | #if !defined(DOMBUILDERIMPL_HPP) |
---|
24 | #define DOMBUILDERIMPL_HPP |
---|
25 | |
---|
26 | |
---|
27 | #include <xercesc/parsers/AbstractDOMParser.hpp> |
---|
28 | #include <xercesc/dom/DOMBuilder.hpp> |
---|
29 | #include <xercesc/util/XercesDefs.hpp> |
---|
30 | |
---|
31 | |
---|
32 | XERCES_CPP_NAMESPACE_BEGIN |
---|
33 | |
---|
34 | class XMLEntityResolver; |
---|
35 | class XMLResourceIdentifier; |
---|
36 | |
---|
37 | /** |
---|
38 | * Introduced in DOM Level 3 |
---|
39 | * |
---|
40 | * DOMBuilderImpl provides an implementation of a DOMBuilder interface. |
---|
41 | * A DOMBuilder instance is obtained from the DOMImplementationLS interface |
---|
42 | * by invoking its createDOMBuilder method. |
---|
43 | */ |
---|
44 | class PARSERS_EXPORT DOMBuilderImpl : public AbstractDOMParser, |
---|
45 | public DOMBuilder |
---|
46 | { |
---|
47 | public : |
---|
48 | // ----------------------------------------------------------------------- |
---|
49 | // Constructors and Detructor |
---|
50 | // ----------------------------------------------------------------------- |
---|
51 | |
---|
52 | /** @name Constructors and Destructor */ |
---|
53 | //@{ |
---|
54 | /** Construct a DOMBuilderImpl, with an optional validator |
---|
55 | * |
---|
56 | * Constructor with an instance of validator class to use for |
---|
57 | * validation. If you don't provide a validator, a default one will |
---|
58 | * be created for you in the scanner. |
---|
59 | * |
---|
60 | * @param gramPool Pointer to the grammar pool instance from |
---|
61 | * external application. |
---|
62 | * The parser does NOT own it. |
---|
63 | * |
---|
64 | * @param valToAdopt Pointer to the validator instance to use. The |
---|
65 | * parser is responsible for freeing the memory. |
---|
66 | */ |
---|
67 | DOMBuilderImpl |
---|
68 | ( |
---|
69 | XMLValidator* const valToAdopt = 0 |
---|
70 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
71 | , XMLGrammarPool* const gramPool = 0 |
---|
72 | ); |
---|
73 | |
---|
74 | /** |
---|
75 | * Destructor |
---|
76 | */ |
---|
77 | virtual ~DOMBuilderImpl(); |
---|
78 | |
---|
79 | //@} |
---|
80 | |
---|
81 | // ----------------------------------------------------------------------- |
---|
82 | // Implementation of DOMBuilder interface |
---|
83 | // ----------------------------------------------------------------------- |
---|
84 | // ----------------------------------------------------------------------- |
---|
85 | // Getter methods |
---|
86 | // ----------------------------------------------------------------------- |
---|
87 | |
---|
88 | /** @name Getter methods */ |
---|
89 | //@{ |
---|
90 | |
---|
91 | /** |
---|
92 | * <p><b>"Experimental - subject to change"</b></p> |
---|
93 | * |
---|
94 | * Get a pointer to the error handler |
---|
95 | * |
---|
96 | * This method returns the installed error handler. If no handler |
---|
97 | * has been installed, then it will be a zero pointer. |
---|
98 | * |
---|
99 | * @return The pointer to the installed error handler object. |
---|
100 | */ |
---|
101 | DOMErrorHandler* getErrorHandler(); |
---|
102 | |
---|
103 | /** |
---|
104 | * <p><b>"Experimental - subject to change"</b></p> |
---|
105 | * |
---|
106 | * Get a const pointer to the error handler |
---|
107 | * |
---|
108 | * This method returns the installed error handler. If no handler |
---|
109 | * has been installed, then it will be a zero pointer. |
---|
110 | * |
---|
111 | * @return A const pointer to the installed error handler object. |
---|
112 | */ |
---|
113 | const DOMErrorHandler* getErrorHandler() const; |
---|
114 | |
---|
115 | /** |
---|
116 | * <p><b>"Experimental - subject to change"</b></p> |
---|
117 | * |
---|
118 | * Get a pointer to the entity resolver |
---|
119 | * |
---|
120 | * This method returns the installed entity resolver. If no resolver |
---|
121 | * has been installed, then it will be a zero pointer. |
---|
122 | * |
---|
123 | * @return The pointer to the installed entity resolver object. |
---|
124 | */ |
---|
125 | DOMEntityResolver* getEntityResolver(); |
---|
126 | |
---|
127 | /** |
---|
128 | * Get a pointer to the entity resolver |
---|
129 | * |
---|
130 | * This method returns the installed entity resolver. If no resolver |
---|
131 | * has been installed, then it will be a zero pointer. |
---|
132 | * |
---|
133 | * @return The pointer to the installed entity resolver object. |
---|
134 | */ |
---|
135 | XMLEntityResolver* getXMLEntityResolver(); |
---|
136 | |
---|
137 | /** |
---|
138 | * Get a const pointer to the entity resolver |
---|
139 | * |
---|
140 | * This method returns the installed entity resolver. If no resolver |
---|
141 | * has been installed, then it will be a zero pointer. |
---|
142 | * |
---|
143 | * @return A const pointer to the installed entity resolver object. |
---|
144 | */ |
---|
145 | const XMLEntityResolver* getXMLEntityResolver() const; |
---|
146 | |
---|
147 | /** |
---|
148 | * <p><b>"Experimental - subject to change"</b></p> |
---|
149 | * |
---|
150 | * Get a const pointer to the entity resolver |
---|
151 | * |
---|
152 | * This method returns the installed entity resolver. If no resolver |
---|
153 | * has been installed, then it will be a zero pointer. |
---|
154 | * |
---|
155 | * @return A const pointer to the installed entity resolver object. |
---|
156 | */ |
---|
157 | const DOMEntityResolver* getEntityResolver() const; |
---|
158 | |
---|
159 | /** |
---|
160 | * <p><b>"Experimental - subject to change"</b></p> |
---|
161 | * |
---|
162 | * Get a pointer to the application filter |
---|
163 | * |
---|
164 | * This method returns the installed application filter. If no filter |
---|
165 | * has been installed, then it will be a zero pointer. |
---|
166 | * |
---|
167 | * @return The pointer to the installed application filter. |
---|
168 | */ |
---|
169 | DOMBuilderFilter* getFilter(); |
---|
170 | |
---|
171 | /** |
---|
172 | * <p><b>"Experimental - subject to change"</b></p> |
---|
173 | * |
---|
174 | * Get a const pointer to the application filter |
---|
175 | * |
---|
176 | * This method returns the installed application filter. If no filter |
---|
177 | * has been installed, then it will be a zero pointer. |
---|
178 | * |
---|
179 | * @return A const pointer to the installed application filter |
---|
180 | */ |
---|
181 | const DOMBuilderFilter* getFilter() const; |
---|
182 | |
---|
183 | //@} |
---|
184 | |
---|
185 | |
---|
186 | // ----------------------------------------------------------------------- |
---|
187 | // Setter methods |
---|
188 | // ----------------------------------------------------------------------- |
---|
189 | |
---|
190 | /** @name Setter methods */ |
---|
191 | //@{ |
---|
192 | |
---|
193 | /** |
---|
194 | * <p><b>"Experimental - subject to change"</b></p> |
---|
195 | * |
---|
196 | * Set the error handler |
---|
197 | * |
---|
198 | * This method allows applications to install their own error handler |
---|
199 | * to trap error and warning messages. |
---|
200 | * |
---|
201 | * <i>Any previously set handler is merely dropped, since the parser |
---|
202 | * does not own them.</i> |
---|
203 | * |
---|
204 | * @param handler A const pointer to the user supplied error |
---|
205 | * handler. |
---|
206 | * |
---|
207 | * @see #getErrorHandler |
---|
208 | */ |
---|
209 | void setErrorHandler(DOMErrorHandler* const handler); |
---|
210 | |
---|
211 | /** |
---|
212 | * <p><b>"Experimental - subject to change"</b></p> |
---|
213 | * |
---|
214 | * Set the entity resolver |
---|
215 | * |
---|
216 | * This method allows applications to install their own entity |
---|
217 | * resolver. By installing an entity resolver, the applications |
---|
218 | * can trap and potentially redirect references to external |
---|
219 | * entities. |
---|
220 | * |
---|
221 | * <i>Any previously set entity resolver is merely dropped, since the parser |
---|
222 | * does not own them. If both setEntityResolver and setXMLEntityResolver |
---|
223 | * are called, then the last one is used.</i> |
---|
224 | * |
---|
225 | * @param handler A const pointer to the user supplied entity |
---|
226 | * resolver. |
---|
227 | * |
---|
228 | * @see #getEntityResolver |
---|
229 | */ |
---|
230 | void setEntityResolver(DOMEntityResolver* const handler); |
---|
231 | |
---|
232 | /** |
---|
233 | * Set the entity resolver |
---|
234 | * |
---|
235 | * This method allows applications to install their own entity |
---|
236 | * resolver. By installing an entity resolver, the applications |
---|
237 | * can trap and potentially redirect references to external |
---|
238 | * entities. |
---|
239 | * |
---|
240 | * <i>Any previously set entity resolver is merely dropped, since the parser |
---|
241 | * does not own them. If both setEntityResolver and setXMLEntityResolver |
---|
242 | * are called, then the last one is used.</i> |
---|
243 | * |
---|
244 | * @param handler A const pointer to the user supplied entity |
---|
245 | * resolver. |
---|
246 | * |
---|
247 | * @see #getXMLEntityResolver |
---|
248 | */ |
---|
249 | void setXMLEntityResolver(XMLEntityResolver* const handler); |
---|
250 | |
---|
251 | /** |
---|
252 | * <p><b>"Experimental - subject to change"</b></p> |
---|
253 | * |
---|
254 | * Set the application filter |
---|
255 | * |
---|
256 | * When the application provides a filter, the parser will call out to |
---|
257 | * the filter at the completion of the construction of each Element node. |
---|
258 | * The filter implementation can choose to remove the element from the |
---|
259 | * document being constructed (unless the element is the document element) |
---|
260 | * or to terminate the parse early. If the document is being validated |
---|
261 | * when it's loaded the validation happens before the filter is called. |
---|
262 | * |
---|
263 | * <i>Any previously set filter is merely dropped, since the parser |
---|
264 | * does not own them.</i> |
---|
265 | * |
---|
266 | * @param filter A const pointer to the user supplied application |
---|
267 | * filter. |
---|
268 | * |
---|
269 | * @see #getFilter |
---|
270 | */ |
---|
271 | void setFilter(DOMBuilderFilter* const filter); |
---|
272 | |
---|
273 | //@} |
---|
274 | |
---|
275 | |
---|
276 | // ----------------------------------------------------------------------- |
---|
277 | // Feature methods |
---|
278 | // ----------------------------------------------------------------------- |
---|
279 | /** @name Feature methods */ |
---|
280 | //@{ |
---|
281 | |
---|
282 | /** |
---|
283 | * <p><b>"Experimental - subject to change"</b></p> |
---|
284 | * |
---|
285 | * Set the state of a feature |
---|
286 | * |
---|
287 | * It is possible for a DOMBuilder to recognize a feature name but to be |
---|
288 | * unable to set its value. |
---|
289 | * |
---|
290 | * @param name The feature name. |
---|
291 | * @param state The requested state of the feature (true or false). |
---|
292 | * @exception DOMException |
---|
293 | * NOT_SUPPORTED_ERR: Raised when the DOMBuilder recognizes the |
---|
294 | * feature name but cannot set the requested value. |
---|
295 | * <br>NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize |
---|
296 | * the feature name. |
---|
297 | * |
---|
298 | * @see #getFeature |
---|
299 | * @see #canSetFeature |
---|
300 | */ |
---|
301 | void setFeature(const XMLCh* const name, const bool state); |
---|
302 | |
---|
303 | /** |
---|
304 | * <p><b>"Experimental - subject to change"</b></p> |
---|
305 | * |
---|
306 | * Look up the value of a feature. |
---|
307 | * |
---|
308 | * @param name The feature name. |
---|
309 | * @return The current state of the feature (true or false) |
---|
310 | * @exception DOMException |
---|
311 | * NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize |
---|
312 | * the feature name. |
---|
313 | * |
---|
314 | * @see #setFeature |
---|
315 | * @see #canSetFeature |
---|
316 | */ |
---|
317 | bool getFeature(const XMLCh* const name) const; |
---|
318 | |
---|
319 | /** |
---|
320 | * <p><b>"Experimental - subject to change"</b></p> |
---|
321 | * |
---|
322 | * Query whether setting a feature to a specific value is supported. |
---|
323 | * |
---|
324 | * @param name The feature name. |
---|
325 | * @param state The requested state of the feature (true or false). |
---|
326 | * @return <code>true</code> if the feature could be successfully set |
---|
327 | * to the specified value, or <code>false</code> if the feature |
---|
328 | * is not recognized or the requested value is not supported. The |
---|
329 | * value of the feature itself is not changed. |
---|
330 | * |
---|
331 | * @see #getFeature |
---|
332 | * @see #setFeature |
---|
333 | */ |
---|
334 | bool canSetFeature(const XMLCh* const name, const bool state) const; |
---|
335 | |
---|
336 | //@} |
---|
337 | |
---|
338 | // ----------------------------------------------------------------------- |
---|
339 | // Parsing methods |
---|
340 | // ----------------------------------------------------------------------- |
---|
341 | /** @name Parsing methods */ |
---|
342 | //@{ |
---|
343 | |
---|
344 | /** |
---|
345 | * <p><b>"Experimental - subject to change"</b></p> |
---|
346 | * |
---|
347 | * Parse via an input source object |
---|
348 | * |
---|
349 | * This method invokes the parsing process on the XML file specified |
---|
350 | * by the DOMInputSource parameter. This API is borrowed from the |
---|
351 | * SAX Parser interface. |
---|
352 | * |
---|
353 | * @param source A const reference to the DOMInputSource object which |
---|
354 | * points to the XML file to be parsed. |
---|
355 | * @return If the DOMBuilder is a synchronous DOMBuilder the newly created |
---|
356 | * and populated Document is returned. If the DOMBuilder is |
---|
357 | * asynchronous then <code>null</code> is returned since the |
---|
358 | * document object is not yet parsed when this method returns. |
---|
359 | * @exception SAXException Any SAX exception, possibly |
---|
360 | * wrapping another exception. |
---|
361 | * @exception XMLException An exception from the parser or client |
---|
362 | * handler code. |
---|
363 | * @exception DOMException A DOM exception as per DOM spec. |
---|
364 | * |
---|
365 | * @see DOMInputSource#DOMInputSource |
---|
366 | * @see #setEntityResolver |
---|
367 | * @see #setErrorHandler |
---|
368 | */ |
---|
369 | DOMDocument* parse(const DOMInputSource& source); |
---|
370 | |
---|
371 | /** |
---|
372 | * <p><b>"Experimental - subject to change"</b></p> |
---|
373 | * |
---|
374 | * Parse via a file path or URL |
---|
375 | * |
---|
376 | * This method invokes the parsing process on the XML file specified by |
---|
377 | * the Unicode string parameter 'systemId'. |
---|
378 | * |
---|
379 | * @param systemId A const XMLCh pointer to the Unicode string which |
---|
380 | * contains the path to the XML file to be parsed. |
---|
381 | * @return If the DOMBuilder is a synchronous DOMBuilder the newly created |
---|
382 | * and populated Document is returned. If the DOMBuilder is |
---|
383 | * asynchronous then <code>null</code> is returned since the |
---|
384 | * document object is not yet parsed when this method returns. |
---|
385 | * @exception SAXException Any SAX exception, possibly |
---|
386 | * wrapping another exception. |
---|
387 | * @exception XMLException An exception from the parser or client |
---|
388 | * handler code. |
---|
389 | * @exception DOM_DOMException A DOM exception as per DOM spec. |
---|
390 | * |
---|
391 | * @see #parse(DOMInputSource,...) |
---|
392 | */ |
---|
393 | DOMDocument* parseURI(const XMLCh* const systemId); |
---|
394 | |
---|
395 | /** |
---|
396 | * <p><b>"Experimental - subject to change"</b></p> |
---|
397 | * |
---|
398 | * Parse via a file path or URL (in the local code page) |
---|
399 | * |
---|
400 | * This method invokes the parsing process on the XML file specified by |
---|
401 | * the native char* string parameter 'systemId'. |
---|
402 | * |
---|
403 | * @param systemId A const char pointer to a native string which |
---|
404 | * contains the path to the XML file to be parsed. |
---|
405 | * @return If the DOMBuilder is a synchronous DOMBuilder the newly created |
---|
406 | * and populated Document is returned. If the DOMBuilder is |
---|
407 | * asynchronous then <code>null</code> is returned since the |
---|
408 | * document object is not yet parsed when this method returns. |
---|
409 | * @exception SAXException Any SAX exception, possibly |
---|
410 | * wrapping another exception. |
---|
411 | * @exception XMLException An exception from the parser or client |
---|
412 | * handler code. |
---|
413 | * @exception DOM_DOMException A DOM exception as per DOM spec. |
---|
414 | * |
---|
415 | * @see #parse(DOMInputSource,...) |
---|
416 | */ |
---|
417 | DOMDocument* parseURI(const char* const systemId); |
---|
418 | |
---|
419 | /** |
---|
420 | * <p><b>"Experimental - subject to change"</b></p> |
---|
421 | * |
---|
422 | * Parse via an input source object |
---|
423 | * |
---|
424 | * This method invokes the parsing process on the XML file specified |
---|
425 | * by the DOMInputSource parameter, and inserts the content into an |
---|
426 | * existing document at the position specified with the contextNode |
---|
427 | * and action arguments. When parsing the input stream the context node |
---|
428 | * is used for resolving unbound namespace prefixes. |
---|
429 | * |
---|
430 | * @param source A const reference to the DOMInputSource object which |
---|
431 | * points to the XML file to be parsed. |
---|
432 | * @param contextNode The node that is used as the context for the data |
---|
433 | * that is being parsed. This node must be a Document |
---|
434 | * node, a DocumentFragment node, or a node of a type |
---|
435 | * that is allowed as a child of an element, e.g. it |
---|
436 | * can not be an attribute node. |
---|
437 | * @param action This parameter describes which action should be taken |
---|
438 | * between the new set of node being inserted and the |
---|
439 | * existing children of the context node. |
---|
440 | * @exception DOMException |
---|
441 | * NOT_SUPPORTED_ERR: Raised when the DOMBuilder doesn't support |
---|
442 | * this method. |
---|
443 | * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if the context node is |
---|
444 | * readonly. |
---|
445 | */ |
---|
446 | virtual void parseWithContext |
---|
447 | ( |
---|
448 | const DOMInputSource& source |
---|
449 | , DOMNode* const contextNode |
---|
450 | , const short action |
---|
451 | ); |
---|
452 | |
---|
453 | |
---|
454 | // ----------------------------------------------------------------------- |
---|
455 | // Non-standard Extension |
---|
456 | // ----------------------------------------------------------------------- |
---|
457 | /** @name Non-standard Extension */ |
---|
458 | //@{ |
---|
459 | |
---|
460 | /** |
---|
461 | * Query the current value of a property in a DOMBuilder. |
---|
462 | * |
---|
463 | * The builder owns the returned pointer. The memory allocated for |
---|
464 | * the returned pointer will be destroyed when the builder is deleted. |
---|
465 | * |
---|
466 | * To ensure assessiblity of the returned information after the builder |
---|
467 | * is deleted, callers need to copy and store the returned information |
---|
468 | * somewhere else; otherwise you may get unexpected result. Since the returned |
---|
469 | * pointer is a generic void pointer, see |
---|
470 | * http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties to learn |
---|
471 | * exactly what type of property value each property returns for replication. |
---|
472 | * |
---|
473 | * @param name The unique identifier (URI) of the property being set. |
---|
474 | * @return The current value of the property. The pointer spans the same |
---|
475 | * life-time as the parser. A null pointer is returned if nothing |
---|
476 | * was specified externally. |
---|
477 | * @exception DOMException |
---|
478 | * <br>NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize |
---|
479 | * the requested property. |
---|
480 | */ |
---|
481 | virtual void* getProperty(const XMLCh* const name) const; |
---|
482 | |
---|
483 | /** |
---|
484 | * Set the value of any property in a DOMBuilder. |
---|
485 | * See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties for |
---|
486 | * the list of supported properties. |
---|
487 | * |
---|
488 | * It takes a void pointer as the property value. Application is required to initialize this void |
---|
489 | * pointer to a correct type. See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties |
---|
490 | * to learn exactly what type of property value each property expects for processing. |
---|
491 | * Passing a void pointer that was initialized with a wrong type will lead to unexpected result. |
---|
492 | * If the same property is set more than once, the last one takes effect. |
---|
493 | * |
---|
494 | * @param name The unique identifier (URI) of the property being set. |
---|
495 | * @param value The requested value for the property. |
---|
496 | * See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties to learn |
---|
497 | * exactly what type of property value each property expects for processing. |
---|
498 | * Passing a void pointer that was initialized with a wrong type will lead |
---|
499 | * to unexpected result. |
---|
500 | * @exception DOMException |
---|
501 | * <br>NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize |
---|
502 | * the requested property. |
---|
503 | */ |
---|
504 | virtual void setProperty(const XMLCh* const name, void* value); |
---|
505 | |
---|
506 | /** |
---|
507 | * Called to indicate that this DOMBuilder is no longer in use |
---|
508 | * and that the implementation may relinquish any resources associated with it. |
---|
509 | * |
---|
510 | */ |
---|
511 | virtual void release(); |
---|
512 | |
---|
513 | /** Reset the documents vector pool and release all the associated memory |
---|
514 | * back to the system. |
---|
515 | * |
---|
516 | * When parsing a document using a DOM parser, all memory allocated |
---|
517 | * for a DOM tree is associated to the DOM document. |
---|
518 | * |
---|
519 | * If you do multiple parse using the same DOM parser instance, then |
---|
520 | * multiple DOM documents will be generated and saved in a vector pool. |
---|
521 | * All these documents (and thus all the allocated memory) |
---|
522 | * won't be deleted until the parser instance is destroyed. |
---|
523 | * |
---|
524 | * If you don't need these DOM documents anymore and don't want to |
---|
525 | * destroy the DOM parser instance at this moment, then you can call this method |
---|
526 | * to reset the document vector pool and release all the allocated memory |
---|
527 | * back to the system. |
---|
528 | * |
---|
529 | * It is an error to call this method if you are in the middle of a |
---|
530 | * parse (e.g. in the mid of a progressive parse). |
---|
531 | * |
---|
532 | * @exception IOException An exception from the parser if this function |
---|
533 | * is called when a parse is in progress. |
---|
534 | * |
---|
535 | */ |
---|
536 | virtual void resetDocumentPool(); |
---|
537 | |
---|
538 | /** |
---|
539 | * Preparse schema grammar (XML Schema, DTD, etc.) via an input source |
---|
540 | * object. |
---|
541 | * |
---|
542 | * This method invokes the preparsing process on a schema grammar XML |
---|
543 | * file specified by the DOMInputSource parameter. If the 'toCache' flag |
---|
544 | * is enabled, the parser will cache the grammars for re-use. If a grammar |
---|
545 | * key is found in the pool, no caching of any grammar will take place. |
---|
546 | * |
---|
547 | * <p><b>"Experimental - subject to change"</b></p> |
---|
548 | * |
---|
549 | * @param source A const reference to the DOMInputSource object which |
---|
550 | * points to the schema grammar file to be preparsed. |
---|
551 | * @param grammarType The grammar type (Schema or DTD). |
---|
552 | * @param toCache If <code>true</code>, we cache the preparsed grammar, |
---|
553 | * otherwise, no chaching. Default is <code>false</code>. |
---|
554 | * @return The preparsed schema grammar object (SchemaGrammar or |
---|
555 | * DTDGrammar). That grammar object is owned by the parser. |
---|
556 | * |
---|
557 | * @exception SAXException Any SAX exception, possibly |
---|
558 | * wrapping another exception. |
---|
559 | * @exception XMLException An exception from the parser or client |
---|
560 | * handler code. |
---|
561 | * @exception DOMException A DOM exception as per DOM spec. |
---|
562 | * |
---|
563 | * @see DOMInputSource#DOMInputSource |
---|
564 | */ |
---|
565 | virtual Grammar* loadGrammar(const DOMInputSource& source, |
---|
566 | const short grammarType, |
---|
567 | const bool toCache = false); |
---|
568 | |
---|
569 | /** |
---|
570 | * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL |
---|
571 | * |
---|
572 | * This method invokes the preparsing process on a schema grammar XML |
---|
573 | * file specified by the file path parameter. If the 'toCache' flag |
---|
574 | * is enabled, the parser will cache the grammars for re-use. If a grammar |
---|
575 | * key is found in the pool, no caching of any grammar will take place. |
---|
576 | * |
---|
577 | * <p><b>"Experimental - subject to change"</b></p> |
---|
578 | * |
---|
579 | * @param systemId A const XMLCh pointer to the Unicode string which |
---|
580 | * contains the path to the XML grammar file to be |
---|
581 | * preparsed. |
---|
582 | * @param grammarType The grammar type (Schema or DTD). |
---|
583 | * @param toCache If <code>true</code>, we cache the preparsed grammar, |
---|
584 | * otherwise, no chaching. Default is <code>false</code>. |
---|
585 | * @return The preparsed schema grammar object (SchemaGrammar or |
---|
586 | * DTDGrammar). That grammar object is owned by the parser. |
---|
587 | * |
---|
588 | * @exception SAXException Any SAX exception, possibly |
---|
589 | * wrapping another exception. |
---|
590 | * @exception XMLException An exception from the parser or client |
---|
591 | * handler code. |
---|
592 | * @exception DOMException A DOM exception as per DOM spec. |
---|
593 | */ |
---|
594 | virtual Grammar* loadGrammar(const XMLCh* const systemId, |
---|
595 | const short grammarType, |
---|
596 | const bool toCache = false); |
---|
597 | |
---|
598 | /** |
---|
599 | * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL |
---|
600 | * |
---|
601 | * This method invokes the preparsing process on a schema grammar XML |
---|
602 | * file specified by the file path parameter. If the 'toCache' flag |
---|
603 | * is enabled, the parser will cache the grammars for re-use. If a grammar |
---|
604 | * key is found in the pool, no caching of any grammar will take place. |
---|
605 | * |
---|
606 | * <p><b>"Experimental - subject to change"</b></p> |
---|
607 | * |
---|
608 | * @param systemId A const char pointer to a native string which contains |
---|
609 | * the path to the XML grammar file to be preparsed. |
---|
610 | * @param grammarType The grammar type (Schema or DTD). |
---|
611 | * @param toCache If <code>true</code>, we cache the preparsed grammar, |
---|
612 | * otherwise, no chaching. Default is <code>false</code>. |
---|
613 | * @return The preparsed schema grammar object (SchemaGrammar or |
---|
614 | * DTDGrammar). That grammar object is owned by the parser. |
---|
615 | * |
---|
616 | * @exception SAXException Any SAX exception, possibly |
---|
617 | * wrapping another exception. |
---|
618 | * @exception XMLException An exception from the parser or client |
---|
619 | * handler code. |
---|
620 | * @exception DOMException A DOM exception as per DOM spec. |
---|
621 | */ |
---|
622 | virtual Grammar* loadGrammar(const char* const systemId, |
---|
623 | const short grammarType, |
---|
624 | const bool toCache = false); |
---|
625 | |
---|
626 | /** |
---|
627 | * Retrieve the grammar that is associated with the specified namespace key |
---|
628 | * |
---|
629 | * @param nameSpaceKey Namespace key |
---|
630 | * @return Grammar associated with the Namespace key. |
---|
631 | */ |
---|
632 | virtual Grammar* getGrammar(const XMLCh* const nameSpaceKey) const; |
---|
633 | |
---|
634 | /** |
---|
635 | * Retrieve the grammar where the root element is declared. |
---|
636 | * |
---|
637 | * @return Grammar where root element declared |
---|
638 | */ |
---|
639 | virtual Grammar* getRootGrammar() const; |
---|
640 | |
---|
641 | /** |
---|
642 | * Returns the string corresponding to a URI id from the URI string pool. |
---|
643 | * |
---|
644 | * @param uriId id of the string in the URI string pool. |
---|
645 | * @return URI string corresponding to the URI id. |
---|
646 | */ |
---|
647 | virtual const XMLCh* getURIText(unsigned int uriId) const; |
---|
648 | |
---|
649 | /** |
---|
650 | * Clear the cached grammar pool |
---|
651 | */ |
---|
652 | virtual void resetCachedGrammarPool(); |
---|
653 | |
---|
654 | /** |
---|
655 | * Returns the current src offset within the input source. |
---|
656 | * To be used only while parsing is in progress. |
---|
657 | * |
---|
658 | * @return offset within the input source |
---|
659 | */ |
---|
660 | virtual unsigned int getSrcOffset() const; |
---|
661 | |
---|
662 | //@} |
---|
663 | |
---|
664 | // ----------------------------------------------------------------------- |
---|
665 | // Implementation of the XMLErrorReporter interface. |
---|
666 | // ----------------------------------------------------------------------- |
---|
667 | |
---|
668 | /** @name Implementation of the XMLErrorReporter interface. */ |
---|
669 | //@{ |
---|
670 | |
---|
671 | /** Handle errors reported from the parser |
---|
672 | * |
---|
673 | * This method is used to report back errors found while parsing the |
---|
674 | * XML file. This method is also borrowed from the SAX specification. |
---|
675 | * It calls the corresponding user installed Error Handler method: |
---|
676 | * 'fatal', 'error', 'warning' depending on the severity of the error. |
---|
677 | * This classification is defined by the XML specification. |
---|
678 | * |
---|
679 | * @param errCode An integer code for the error. |
---|
680 | * @param msgDomain A const pointer to an Unicode string representing |
---|
681 | * the message domain to use. |
---|
682 | * @param errType An enumeration classifying the severity of the error. |
---|
683 | * @param errorText A const pointer to an Unicode string representing |
---|
684 | * the text of the error message. |
---|
685 | * @param systemId A const pointer to an Unicode string representing |
---|
686 | * the system id of the XML file where this error |
---|
687 | * was discovered. |
---|
688 | * @param publicId A const pointer to an Unicode string representing |
---|
689 | * the public id of the XML file where this error |
---|
690 | * was discovered. |
---|
691 | * @param lineNum The line number where the error occurred. |
---|
692 | * @param colNum The column number where the error occurred. |
---|
693 | * @see DOMErrorHandler |
---|
694 | */ |
---|
695 | virtual void error |
---|
696 | ( |
---|
697 | const unsigned int errCode |
---|
698 | , const XMLCh* const msgDomain |
---|
699 | , const XMLErrorReporter::ErrTypes errType |
---|
700 | , const XMLCh* const errorText |
---|
701 | , const XMLCh* const systemId |
---|
702 | , const XMLCh* const publicId |
---|
703 | , const XMLSSize_t lineNum |
---|
704 | , const XMLSSize_t colNum |
---|
705 | ); |
---|
706 | |
---|
707 | /** Reset any error data before a new parse |
---|
708 | * |
---|
709 | * This method allows the user installed Error Handler callback to |
---|
710 | * 'reset' itself. |
---|
711 | * |
---|
712 | * <b><font color="#FF0000">This method is a no-op for this DOM |
---|
713 | * implementation.</font></b> |
---|
714 | */ |
---|
715 | virtual void resetErrors(); |
---|
716 | //@} |
---|
717 | |
---|
718 | |
---|
719 | // ----------------------------------------------------------------------- |
---|
720 | // Implementation of the XMLEntityHandler interface. |
---|
721 | // ----------------------------------------------------------------------- |
---|
722 | |
---|
723 | /** @name Implementation of the XMLEntityHandler interface. */ |
---|
724 | //@{ |
---|
725 | |
---|
726 | /** Handle an end of input source event |
---|
727 | * |
---|
728 | * This method is used to indicate the end of parsing of an external |
---|
729 | * entity file. |
---|
730 | * |
---|
731 | * <b><font color="#FF0000">This method is a no-op for this DOM |
---|
732 | * implementation.</font></b> |
---|
733 | * |
---|
734 | * @param inputSource A const reference to the InputSource object |
---|
735 | * which points to the XML file being parsed. |
---|
736 | * @see InputSource |
---|
737 | */ |
---|
738 | virtual void endInputSource(const InputSource& inputSource); |
---|
739 | |
---|
740 | /** Expand a system id |
---|
741 | * |
---|
742 | * This method allows an installed XMLEntityHandler to further |
---|
743 | * process any system id's of enternal entities encountered in |
---|
744 | * the XML file being parsed, such as redirection etc. |
---|
745 | * |
---|
746 | * <b><font color="#FF0000">This method always returns 'false' |
---|
747 | * for this DOM implementation.</font></b> |
---|
748 | * |
---|
749 | * @param systemId A const pointer to an Unicode string representing |
---|
750 | * the system id scanned by the parser. |
---|
751 | * @param toFill A pointer to a buffer in which the application |
---|
752 | * processed system id is stored. |
---|
753 | * @return 'true', if any processing is done, 'false' otherwise. |
---|
754 | */ |
---|
755 | virtual bool expandSystemId |
---|
756 | ( |
---|
757 | const XMLCh* const systemId |
---|
758 | , XMLBuffer& toFill |
---|
759 | ); |
---|
760 | |
---|
761 | /** Reset any entity handler information |
---|
762 | * |
---|
763 | * This method allows the installed XMLEntityHandler to reset |
---|
764 | * itself. |
---|
765 | * |
---|
766 | * <b><font color="#FF0000">This method is a no-op for this DOM |
---|
767 | * implementation.</font></b> |
---|
768 | */ |
---|
769 | virtual void resetEntities(); |
---|
770 | |
---|
771 | /** Resolve a public/system id |
---|
772 | * |
---|
773 | * This method allows a user installed entity handler to further |
---|
774 | * process any pointers to external entities. The applications can |
---|
775 | * implement 'redirection' via this callback. This method is also |
---|
776 | * borrowed from the SAX specification. |
---|
777 | * |
---|
778 | * @deprecated This method is no longer called (the other resolveEntity one is). |
---|
779 | * |
---|
780 | * @param publicId A const pointer to a Unicode string representing the |
---|
781 | * public id of the entity just parsed. |
---|
782 | * @param systemId A const pointer to a Unicode string representing the |
---|
783 | * system id of the entity just parsed. |
---|
784 | * @param baseURI A const pointer to a Unicode string representing the |
---|
785 | * base URI of the entity just parsed, |
---|
786 | * or <code>null</code> if there is no base URI. |
---|
787 | * @return The value returned by the user installed resolveEntity |
---|
788 | * method or NULL otherwise to indicate no processing was done. |
---|
789 | * The returned InputSource is owned by the DOMBuilder which is |
---|
790 | * responsible to clean up the memory. |
---|
791 | * @see DOMEntityResolver |
---|
792 | * @see XMLEntityHandler |
---|
793 | */ |
---|
794 | virtual InputSource* resolveEntity |
---|
795 | ( |
---|
796 | const XMLCh* const publicId |
---|
797 | , const XMLCh* const systemId |
---|
798 | , const XMLCh* const baseURI = 0 |
---|
799 | ); |
---|
800 | |
---|
801 | /** Resolve a public/system id |
---|
802 | * |
---|
803 | * This method allows a user installed entity handler to further |
---|
804 | * process any pointers to external entities. The applications can |
---|
805 | * implement 'redirection' via this callback. |
---|
806 | * |
---|
807 | * @param resourceIdentifier An object containing the type of |
---|
808 | * resource to be resolved and the associated data members |
---|
809 | * corresponding to this type. |
---|
810 | * @return The value returned by the user installed resolveEntity |
---|
811 | * method or NULL otherwise to indicate no processing was done. |
---|
812 | * The returned InputSource is owned by the parser which is |
---|
813 | * responsible to clean up the memory. |
---|
814 | * @see XMLEntityHandler |
---|
815 | * @see XMLEntityResolver |
---|
816 | */ |
---|
817 | virtual InputSource* resolveEntity |
---|
818 | ( |
---|
819 | XMLResourceIdentifier* resourceIdentifier |
---|
820 | ); |
---|
821 | |
---|
822 | /** Handle a 'start input source' event |
---|
823 | * |
---|
824 | * This method is used to indicate the start of parsing an external |
---|
825 | * entity file. |
---|
826 | * |
---|
827 | * <b><font color="#FF0000">This method is a no-op for this DOM parse |
---|
828 | * implementation.</font></b> |
---|
829 | * |
---|
830 | * @param inputSource A const reference to the InputSource object |
---|
831 | * which points to the external entity |
---|
832 | * being parsed. |
---|
833 | */ |
---|
834 | virtual void startInputSource(const InputSource& inputSource); |
---|
835 | |
---|
836 | //@} |
---|
837 | |
---|
838 | |
---|
839 | private : |
---|
840 | // ----------------------------------------------------------------------- |
---|
841 | // Initialize/Cleanup methods |
---|
842 | // ----------------------------------------------------------------------- |
---|
843 | void resetParse(); |
---|
844 | |
---|
845 | // ----------------------------------------------------------------------- |
---|
846 | // Private data members |
---|
847 | // |
---|
848 | // fEntityResolver |
---|
849 | // The installed DOM entity resolver, if any. Null if none. |
---|
850 | // |
---|
851 | // fErrorHandler |
---|
852 | // The installed DOM error handler, if any. Null if none. |
---|
853 | // |
---|
854 | // fFilter |
---|
855 | // The installed application filter, if any. Null if none. |
---|
856 | // |
---|
857 | // fCharsetOverridesXMLEncoding |
---|
858 | // Indicates if the "charset-overrides-xml-encoding" is set or not |
---|
859 | // |
---|
860 | // fUserAdoptsDocument |
---|
861 | // The DOMDocument ownership has been transferred to application |
---|
862 | // If set to true, the parser does not own the document anymore |
---|
863 | // and thus will not release its memory. |
---|
864 | //----------------------------------------------------------------------- |
---|
865 | bool fAutoValidation; |
---|
866 | bool fValidation; |
---|
867 | DOMEntityResolver* fEntityResolver; |
---|
868 | XMLEntityResolver* fXMLEntityResolver; |
---|
869 | DOMErrorHandler* fErrorHandler; |
---|
870 | DOMBuilderFilter* fFilter; |
---|
871 | bool fCharsetOverridesXMLEncoding; |
---|
872 | bool fUserAdoptsDocument; |
---|
873 | |
---|
874 | // ----------------------------------------------------------------------- |
---|
875 | // Unimplemented constructors and operators |
---|
876 | // ----------------------------------------------------------------------- |
---|
877 | DOMBuilderImpl(const DOMBuilderImpl &); |
---|
878 | DOMBuilderImpl & operator = (const DOMBuilderImpl &); |
---|
879 | }; |
---|
880 | |
---|
881 | |
---|
882 | |
---|
883 | // --------------------------------------------------------------------------- |
---|
884 | // DOMBuilderImpl: Handlers for the XMLEntityHandler interface |
---|
885 | // --------------------------------------------------------------------------- |
---|
886 | inline void DOMBuilderImpl::endInputSource(const InputSource&) |
---|
887 | { |
---|
888 | // The DOM entity resolver doesn't handle this |
---|
889 | } |
---|
890 | |
---|
891 | inline bool DOMBuilderImpl::expandSystemId(const XMLCh* const, XMLBuffer&) |
---|
892 | { |
---|
893 | // The DOM entity resolver doesn't handle this |
---|
894 | return false; |
---|
895 | } |
---|
896 | |
---|
897 | inline void DOMBuilderImpl::resetEntities() |
---|
898 | { |
---|
899 | // Nothing to do on this one |
---|
900 | } |
---|
901 | |
---|
902 | inline void DOMBuilderImpl::startInputSource(const InputSource&) |
---|
903 | { |
---|
904 | // The DOM entity resolver doesn't handle this |
---|
905 | } |
---|
906 | |
---|
907 | |
---|
908 | // --------------------------------------------------------------------------- |
---|
909 | // DOMBuilderImpl: Getter methods |
---|
910 | // --------------------------------------------------------------------------- |
---|
911 | inline DOMErrorHandler* DOMBuilderImpl::getErrorHandler() |
---|
912 | { |
---|
913 | return fErrorHandler; |
---|
914 | } |
---|
915 | |
---|
916 | inline const DOMErrorHandler* DOMBuilderImpl::getErrorHandler() const |
---|
917 | { |
---|
918 | return fErrorHandler; |
---|
919 | } |
---|
920 | |
---|
921 | inline DOMEntityResolver* DOMBuilderImpl::getEntityResolver() |
---|
922 | { |
---|
923 | return fEntityResolver; |
---|
924 | } |
---|
925 | |
---|
926 | inline const DOMEntityResolver* DOMBuilderImpl::getEntityResolver() const |
---|
927 | { |
---|
928 | return fEntityResolver; |
---|
929 | } |
---|
930 | |
---|
931 | inline XMLEntityResolver* DOMBuilderImpl::getXMLEntityResolver() |
---|
932 | { |
---|
933 | return fXMLEntityResolver; |
---|
934 | } |
---|
935 | |
---|
936 | inline const XMLEntityResolver* DOMBuilderImpl::getXMLEntityResolver() const |
---|
937 | { |
---|
938 | return fXMLEntityResolver; |
---|
939 | } |
---|
940 | |
---|
941 | inline DOMBuilderFilter* DOMBuilderImpl::getFilter() |
---|
942 | { |
---|
943 | return fFilter; |
---|
944 | } |
---|
945 | |
---|
946 | inline const DOMBuilderFilter* DOMBuilderImpl::getFilter() const |
---|
947 | { |
---|
948 | return fFilter; |
---|
949 | } |
---|
950 | |
---|
951 | |
---|
952 | XERCES_CPP_NAMESPACE_END |
---|
953 | |
---|
954 | #endif |
---|