source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/dom/DOMBuilder.hpp @ 2674

Revision 2674, 27.0 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef DOMBuilder_HEADER_GUARD_
2#define DOMBuilder_HEADER_GUARD_
3
4/*
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements.  See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License.  You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21/*
22 * $Id: DOMBuilder.hpp 569031 2007-08-23 15:05:28Z amassari $
23 *
24 */
25
26
27#include <xercesc/util/XercesDefs.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31
32class DOMErrorHandler;
33class DOMEntityResolver;
34class DOMInputSource;
35class DOMBuilderFilter;
36class DOMNode;
37class DOMDocument;
38class Grammar;
39
40/**
41 * DOMBuilder provides an API for parsing XML documents and building the
42 * corresponding DOM document tree. A DOMBuilder instance is obtained from
43 * the DOMImplementationLS interface by invoking its createDOMBuilder method.
44 * This implementation also allows the applications to install an error and
45 * an entity handler (useful extensions to the DOM specification).
46 *
47 * @since DOM Level 3
48 *
49 */
50class CDOM_EXPORT DOMBuilder
51{
52protected :
53    // -----------------------------------------------------------------------
54    //  Hidden constructors
55    // -----------------------------------------------------------------------
56    /** @name Hidden constructors */
57    //@{   
58    DOMBuilder() {};
59    //@}
60
61private:   
62    // -----------------------------------------------------------------------
63    // Unimplemented constructors and operators
64    // -----------------------------------------------------------------------
65    /** @name Unimplemented constructors and operators */
66    //@{
67    DOMBuilder(const DOMBuilder &);
68    DOMBuilder & operator = (const DOMBuilder &);
69    //@}
70
71public:
72    // -----------------------------------------------------------------------
73    //  All constructors are hidden, just the destructor is available
74    // -----------------------------------------------------------------------
75    /** @name Destructor */
76    //@{
77    /**
78     * Destructor
79     *
80     */
81    virtual ~DOMBuilder() {};
82    //@}
83
84    // -----------------------------------------------------------------------
85    //  Class types
86    // -----------------------------------------------------------------------
87    /** @name Public Constants */
88    //@{
89    /**
90     * Action types for use in parseWithContext.
91     *
92     * <p> <code>ACTION_REPLACE</code>:
93     * Replace the context node with the result of parsing the input source.
94     * For this action to work the context node must be an
95     * <code>DOMElement</code>, <code>DOMText</code>, <code>DOMCDATASection</code>,
96     * <code>DOMComment</code>, <code>DOMProcessingInstruction</code>, or
97     * <code>DOMEntityReference</code> node.</p>
98     *
99     * <p> <code>ACTION_APPEND</code>:
100     * Append the result of parsing the input source to the context node. For
101     * this action to work, the context node must be an <code>DOMElement</code>.</p>
102     *
103     * <p> <code>ACTION_INSERT_AFTER</code>:
104     * Insert the result of parsing the input source after the context node.
105     * For this action to work the context nodes parent must be an
106     * <code>DOMElement</code>.</p>
107     *
108     * <p> <code>ACTION_INSERT_BEFORE</code>:
109     * Insert the result of parsing the input source before the context node.
110     * For this action to work the context nodes parent must be an
111     * <code>DOMElement</code>.</p>
112     *
113     * @see parseWithContext(...)
114     * @since DOM Level 3
115     */
116    enum ActionType
117    {
118        ACTION_REPLACE            = 1,
119        ACTION_APPEND_AS_CHILDREN = 2,
120        ACTION_INSERT_AFTER       = 3,
121        ACTION_INSERT_BEFORE      = 4
122    };
123    //@}
124
125    // -----------------------------------------------------------------------
126    //  Virtual DOMBuilder interface
127    // -----------------------------------------------------------------------
128    /** @name Functions introduced in DOM Level 3 */
129    //@{
130
131    // -----------------------------------------------------------------------
132    //  Getter methods
133    // -----------------------------------------------------------------------
134
135    /**
136      * Get a pointer to the error handler
137      *
138      * This method returns the installed error handler. If no handler
139      * has been installed, then it will be a zero pointer.
140      *
141      * <p><b>"Experimental - subject to change"</b></p>
142      *
143      * @return The pointer to the installed error handler object.
144      * @since DOM Level 3
145      */
146    virtual DOMErrorHandler* getErrorHandler() = 0;
147
148    /**
149      * Get a const pointer to the error handler
150      *
151      * This method returns the installed error handler.  If no handler
152      * has been installed, then it will be a zero pointer.
153      *
154      * <p><b>"Experimental - subject to change"</b></p>
155      *
156      * @return A const pointer to the installed error handler object.
157      * @since DOM Level 3
158      */
159    virtual const DOMErrorHandler* getErrorHandler() const = 0;
160
161    /**
162      * Get a pointer to the entity resolver
163      *
164      * This method returns the installed entity resolver.  If no resolver
165      * has been installed, then it will be a zero pointer.
166      *
167      * <p><b>"Experimental - subject to change"</b></p>
168      *
169      * @return The pointer to the installed entity resolver object.
170      * @since DOM Level 3
171      */
172    virtual DOMEntityResolver* getEntityResolver() = 0;
173
174    /**
175      * Get a const pointer to the entity resolver
176      *
177      * This method returns the installed entity resolver. If no resolver
178      * has been installed, then it will be a zero pointer.
179      *
180      * <p><b>"Experimental - subject to change"</b></p>
181      *
182      * @return A const pointer to the installed entity resolver object.
183      * @since DOM Level 3
184      */
185    virtual const DOMEntityResolver* getEntityResolver() const = 0;
186
187    /**
188      * Get a pointer to the application filter
189      *
190      * This method returns the installed application filter. If no filter
191      * has been installed, then it will be a zero pointer.
192      *
193      * <p><b>"Experimental - subject to change"</b></p>
194      *
195      * @return The pointer to the installed application filter.
196      * @since DOM Level 3
197      */
198    virtual DOMBuilderFilter* getFilter() = 0;
199
200    /**
201      * Get a const pointer to the application filter
202      *
203      * This method returns the installed application filter. If no filter
204      * has been installed, then it will be a zero pointer.
205      *
206      * <p><b>"Experimental - subject to change"</b></p>
207      *
208      * @return A const pointer to the installed application filter
209      * @since DOM Level 3
210      */
211    virtual const DOMBuilderFilter* getFilter() const = 0;
212
213    // -----------------------------------------------------------------------
214    //  Setter methods
215    // -----------------------------------------------------------------------
216    /**
217      * Set the error handler
218      *
219      * This method allows applications to install their own error handler
220      * to trap error and warning messages.
221      *
222      * <i>Any previously set handler is merely dropped, since the parser
223      * does not own them.</i>
224      *
225      * <p><b>"Experimental - subject to change"</b></p>
226      *
227      * @param handler  A const pointer to the user supplied error
228      *                 handler.
229      *
230      * @see #getErrorHandler
231      * @since DOM Level 3
232      */
233    virtual void setErrorHandler(DOMErrorHandler* const handler) = 0;
234
235    /**
236      * Set the entity resolver
237      *
238      * This method allows applications to install their own entity
239      * resolver. By installing an entity resolver, the applications
240      * can trap and potentially redirect references to external
241      * entities.
242      *
243      * <i>Any previously set resolver is merely dropped, since the parser
244      * does not own them.</i>
245      *
246      * <p><b>"Experimental - subject to change"</b></p>
247      *
248      * @param handler  A const pointer to the user supplied entity
249      *                 resolver.
250      *
251      * @see #getEntityResolver
252      * @since DOM Level 3
253      */
254    virtual void setEntityResolver(DOMEntityResolver* const handler) = 0;
255
256    /**
257      * Set the application filter
258      *
259      * When the application provides a filter, the parser will call out to
260      * the filter at the completion of the construction of each Element node.
261      * The filter implementation can choose to remove the element from the
262      * document being constructed (unless the element is the document element)
263      * or to terminate the parse early. If the document is being validated
264      * when it's loaded the validation happens before the filter is called.
265      *
266      * <i>Any previously set filter is merely dropped, since the parser
267      * does not own them.</i>
268      *
269      * <p><b>"Experimental - subject to change"</b></p>
270      *
271      * @param filter  A const pointer to the user supplied application
272      *                filter.
273      *
274      * @see #getFilter
275      * @since DOM Level 3
276      */
277    virtual void setFilter(DOMBuilderFilter* const filter) = 0;
278
279    // -----------------------------------------------------------------------
280    //  Feature methods
281    // -----------------------------------------------------------------------
282    /**
283      * Set the state of a feature
284      *
285      * It is possible for a DOMBuilder to recognize a feature name but to be
286      * unable to set its value.
287      *
288      * <p><b>"Experimental - subject to change"</b></p>
289      *
290      * See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderFeatures for
291      * the list of supported features.
292      *
293      * @param name  The feature name.
294      * @param state The requested state of the feature (true or false).
295      * @exception DOMException
296      *     NOT_SUPPORTED_ERR: Raised when the DOMBuilder recognizes the
297      *     feature name but cannot set the requested value.
298      *     <br>NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize
299      *     the feature name.
300      *
301      * @see #setFeature
302      * @see #canSetFeature
303      * @since DOM Level 3
304      */
305    virtual void setFeature(const XMLCh* const name, const bool state) = 0;
306
307    /**
308      * Look up the value of a feature.
309      *
310      * <p><b>"Experimental - subject to change"</b></p>
311      *
312      * @param name The feature name.
313      * @return The current state of the feature (true or false)
314      * @exception DOMException
315      *     NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize
316      *     the feature name.
317      *
318      * @see #getFeature
319      * @see #canSetFeature
320      * @since DOM Level 3
321      */
322    virtual bool getFeature(const XMLCh* const name) const = 0;
323
324    /**
325      * Query whether setting a feature to a specific value is supported.
326      *
327      * <p><b>"Experimental - subject to change"</b></p>
328      *
329      * @param name  The feature name.
330      * @param state The requested state of the feature (true or false).
331      * @return <code>true</code> if the feature could be successfully set
332      *     to the specified value, or <code>false</code> if the feature
333      *     is not recognized or the requested value is not supported. The
334      *     value of the feature itself is not changed.
335      *
336      * @see #getFeature
337      * @see #setFeature
338      * @since DOM Level 3
339      */
340    virtual bool canSetFeature(const XMLCh* const name, const bool state) const = 0;
341
342    // -----------------------------------------------------------------------
343    //  Parsing methods
344    // -----------------------------------------------------------------------
345    /**
346      * Parse via an input source object
347      *
348      * This method invokes the parsing process on the XML file specified
349      * by the DOMInputSource parameter. This API is borrowed from the
350      * SAX Parser interface.
351      *
352      * The parser owns the returned DOMDocument.  It will be deleted
353      * when the parser is released.
354      *
355      * <p><b>"Experimental - subject to change"</b></p>
356      *
357      * @param source A const reference to the DOMInputSource object which
358      *               points to the XML file to be parsed.
359      * @return If the DOMBuilder is a synchronous DOMBuilder the newly created
360      *         and populated DOMDocument is returned. If the DOMBuilder is
361      *         asynchronous then <code>null</code> is returned since the
362      *         document object is not yet parsed when this method returns.
363      * @exception SAXException Any SAX exception, possibly
364      *            wrapping another exception.
365      * @exception XMLException An exception from the parser or client
366      *            handler code.
367      * @exception DOMException A DOM exception as per DOM spec.
368      *
369      * @see DOMInputSource#DOMInputSource
370      * @see #setEntityResolver
371      * @see #setErrorHandler
372      * @see resetDocumentPool
373      * @since DOM Level 3
374      */
375    virtual DOMDocument* parse(const DOMInputSource& source) = 0;
376
377    /**
378      * Parse via a file path or URL
379      *
380      * This method invokes the parsing process on the XML file specified by
381      * the Unicode string parameter 'systemId'.
382      *
383      * The parser owns the returned DOMDocument.  It will be deleted
384      * when the parser is released.
385      *
386      * <p><b>"Experimental - subject to change"</b></p>
387      *
388      * @param systemId A const XMLCh pointer to the Unicode string which
389      *                 contains the path to the XML file to be parsed.
390      * @return If the DOMBuilder is a synchronous DOMBuilder the newly created
391      *         and populated DOMDocument is returned. If the DOMBuilder is
392      *         asynchronous then <code>null</code> is returned since the
393      *         document object is not yet parsed when this method returns.
394      * @exception SAXException Any SAX exception, possibly
395      *            wrapping another exception.
396      * @exception XMLException An exception from the parser or client
397      *            handler code.
398      * @exception DOMException A DOM exception as per DOM spec.
399      *
400      * @see #parse(DOMInputSource,...)
401      * @see resetDocumentPool
402      * @since DOM Level 3
403      */
404    virtual DOMDocument* parseURI(const XMLCh* const systemId) = 0;
405
406    /**
407      * Parse via a file path or URL (in the local code page)
408      *
409      * This method invokes the parsing process on the XML file specified by
410      * the native char* string parameter 'systemId'.
411      *
412      * The parser owns the returned DOMDocument.  It will be deleted
413      * when the parser is released.
414      *
415      * <p><b>"Experimental - subject to change"</b></p>
416      *
417      * @param systemId A const char pointer to a native string which
418      *                 contains the path to the XML file to be parsed.
419      * @return If the DOMBuilder is a synchronous DOMBuilder the newly created
420      *         and populated DOMDocument is returned. If the DOMBuilder is
421      *         asynchronous then <code>null</code> is returned since the
422      *         document object is not yet parsed when this method returns.
423      * @exception SAXException Any SAX exception, possibly
424      *            wrapping another exception.
425      * @exception XMLException An exception from the parser or client
426      *            handler code.
427      * @exception DOMException A DOM exception as per DOM spec.
428      *
429      * @see #parse(DOMInputSource,...)
430      * @see resetDocumentPool
431      */
432    virtual DOMDocument* parseURI(const char* const systemId) = 0;
433
434    /**
435      * Parse via an input source object
436      *
437      * This method invokes the parsing process on the XML file specified
438      * by the DOMInputSource parameter, and inserts the content into an
439      * existing document at the position specified with the contextNode
440      * and action arguments. When parsing the input stream the context node
441      * is used for resolving unbound namespace prefixes.
442      *
443      * <p><b>"Experimental - subject to change"</b></p>
444      *
445      * @param source A const reference to the DOMInputSource object which
446      *               points to the XML file to be parsed.
447      * @param contextNode The node that is used as the context for the data
448      *                    that is being parsed. This node must be a Document
449      *                    node, a DocumentFragment node, or a node of a type
450      *                    that is allowed as a child of an element, e.g. it
451      *                    can not be an attribute node.
452      * @param action This parameter describes which action should be taken
453      *               between the new set of node being inserted and the
454      *               existing children of the context node.
455      * @exception DOMException
456      *     NOT_SUPPORTED_ERR: Raised when the DOMBuilder doesn't support
457      *     this method.
458      *     <br>NO_MODIFICATION_ALLOWED_ERR: Raised if the context node is
459      *     readonly.
460      * @since DOM Level 3
461      */
462    virtual void parseWithContext
463    (
464        const   DOMInputSource& source
465        ,       DOMNode* const contextNode
466        , const short action
467    ) = 0;
468    //@}
469
470    // -----------------------------------------------------------------------
471    //  Non-standard Extension
472    // -----------------------------------------------------------------------
473    /** @name Non-standard Extension */
474    //@{
475
476    /**
477      * Query the current value of a property in a DOMBuilder.
478      *
479      * The builder owns the returned pointer.  The memory allocated for
480      * the returned pointer will be destroyed when the builder is deleted.
481      *
482      * To ensure assessiblity of the returned information after the builder
483      * is deleted, callers need to copy and store the returned information
484      * somewhere else; otherwise you may get unexpected result.  Since the returned
485      * pointer is a generic void pointer, see
486      * http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties to learn
487      * exactly what type of property value each property returns for replication.
488      *
489      * @param name The unique identifier (URI) of the property being set.
490      * @return     The current value of the property.  The pointer spans the same
491      *             life-time as the parser.  A null pointer is returned if nothing
492      *             was specified externally.
493      * @exception DOMException
494      *     <br>NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize
495      *     the requested property.
496      */
497    virtual void* getProperty(const XMLCh* const name) const = 0 ;
498
499    /**
500      * Set the value of any property in a DOMBuilder.
501      * See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties for
502      * the list of supported properties.
503      *
504      * It takes a void pointer as the property value.  Application is required to initialize this void
505      * pointer to a correct type.  See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties
506      * to learn exactly what type of property value each property expects for processing.
507      * Passing a void pointer that was initialized with a wrong type will lead to unexpected result.
508      * If the same property is set more than once, the last one takes effect.
509      *
510      * @param name The unique identifier (URI) of the property being set.
511      * @param value The requested value for the property.
512      *            See http://xerces.apache.org/xerces-c/program-dom.html#DOMBuilderProperties to learn
513      *            exactly what type of property value each property expects for processing.
514      *            Passing a void pointer that was initialized with a wrong type will lead
515      *            to unexpected result.
516      * @exception DOMException
517      *     <br>NOT_FOUND_ERR: Raised when the DOMBuilder does not recognize
518      *     the requested property.
519      */
520    virtual void setProperty(const XMLCh* const name, void* value) = 0 ;
521
522    /**
523     * Called to indicate that this DOMBuilder is no longer in use
524     * and that the implementation may relinquish any resources associated with it.
525     *
526     * Access to a released object will lead to unexpected result.
527     */
528    virtual void              release() = 0;
529
530    /** Reset the documents vector pool and release all the associated memory
531      * back to the system.
532      *
533      * When parsing a document using a DOM parser, all memory allocated
534      * for a DOM tree is associated to the DOM document.
535      *
536      * If you do multiple parse using the same DOM parser instance, then
537      * multiple DOM documents will be generated and saved in a vector pool.
538      * All these documents (and thus all the allocated memory)
539      * won't be deleted until the parser instance is destroyed.
540      *
541      * If you don't need these DOM documents anymore and don't want to
542      * destroy the DOM parser instance at this moment, then you can call this method
543      * to reset the document vector pool and release all the allocated memory
544      * back to the system.
545      *
546      * It is an error to call this method if you are in the middle of a
547      * parse (e.g. in the mid of a progressive parse).
548      *
549      * @exception IOException An exception from the parser if this function
550      *            is called when a parse is in progress.
551      *
552      */
553    virtual void              resetDocumentPool() = 0;
554
555    /**
556      * Preparse schema grammar (XML Schema, DTD, etc.) via an input source
557      * object.
558      *
559      * This method invokes the preparsing process on a schema grammar XML
560      * file specified by the DOMInputSource parameter. If the 'toCache' flag
561      * is enabled, the parser will cache the grammars for re-use. If a grammar
562      * key is found in the pool, no caching of any grammar will take place.
563      *
564      * <p><b>"Experimental - subject to change"</b></p>
565      *
566      * @param source A const reference to the DOMInputSource object which
567      *               points to the schema grammar file to be preparsed.
568      * @param grammarType The grammar type (Schema or DTD).
569      * @param toCache If <code>true</code>, we cache the preparsed grammar,
570      *                otherwise, no chaching. Default is <code>false</code>.
571      * @return The preparsed schema grammar object (SchemaGrammar or
572      *         DTDGrammar). That grammar object is owned by the parser.
573      *
574      * @exception SAXException Any SAX exception, possibly
575      *            wrapping another exception.
576      * @exception XMLException An exception from the parser or client
577      *            handler code.
578      * @exception DOMException A DOM exception as per DOM spec.
579      *
580      * @see DOMInputSource#DOMInputSource
581      */
582    virtual Grammar* loadGrammar(const DOMInputSource& source,
583                                 const short grammarType,
584                                 const bool toCache = false) = 0;
585
586    /**
587      * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
588      *
589      * This method invokes the preparsing process on a schema grammar XML
590      * file specified by the file path parameter. If the 'toCache' flag is
591      * enabled, the parser will cache the grammars for re-use. If a grammar
592      * key is found in the pool, no caching of any grammar will take place.
593      *
594      * <p><b>"Experimental - subject to change"</b></p>
595      *
596      * @param systemId A const XMLCh pointer to the Unicode string which
597      *                 contains the path to the XML grammar file to be
598      *                 preparsed.
599      * @param grammarType The grammar type (Schema or DTD).
600      * @param toCache If <code>true</code>, we cache the preparsed grammar,
601      *                otherwise, no chaching. Default is <code>false</code>.
602      * @return The preparsed schema grammar object (SchemaGrammar or
603      *         DTDGrammar). That grammar object is owned by the parser.
604      *
605      * @exception SAXException Any SAX exception, possibly
606      *            wrapping another exception.
607      * @exception XMLException An exception from the parser or client
608      *            handler code.
609      * @exception DOMException A DOM exception as per DOM spec.
610      */
611    virtual Grammar* loadGrammar(const XMLCh* const systemId,
612                                 const short grammarType,
613                                 const bool toCache = false) = 0;
614
615    /**
616      * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
617      *
618      * This method invokes the preparsing process on a schema grammar XML
619      * file specified by the file path parameter. If the 'toCache' flag is
620      * enabled, the parser will cache the grammars for re-use. If a grammar
621      * key is found in the pool, no caching of any grammar will take place.
622      *
623      * <p><b>"Experimental - subject to change"</b></p>
624      *
625      * @param systemId A const char pointer to a native string which contains
626      *                 the path to the XML grammar file to be preparsed.
627      * @param grammarType The grammar type (Schema or DTD).
628      * @param toCache If <code>true</code>, we cache the preparsed grammar,
629      *                otherwise, no chaching. Default is <code>false</code>.
630      * @return The preparsed schema grammar object (SchemaGrammar or
631      *         DTDGrammar). That grammar object is owned by the parser.
632      *
633      *
634      * @exception SAXException Any SAX exception, possibly
635      *            wrapping another exception.
636      * @exception XMLException An exception from the parser or client
637      *            handler code.
638      * @exception DOMException A DOM exception as per DOM spec.
639      */
640    virtual Grammar* loadGrammar(const char* const systemId,
641                                 const short grammarType,
642                                 const bool toCache = false) = 0;
643
644    /**
645     * Retrieve the grammar that is associated with the specified namespace key
646     *
647     * @param  nameSpaceKey Namespace key
648     * @return Grammar associated with the Namespace key.
649     */
650    virtual Grammar* getGrammar(const XMLCh* const nameSpaceKey) const = 0;
651
652    /**
653     * Retrieve the grammar where the root element is declared.
654     *
655     * @return Grammar where root element declared
656     */
657    virtual Grammar* getRootGrammar() const = 0;
658
659    /**
660     * Returns the string corresponding to a URI id from the URI string pool.
661     *
662     * @param uriId id of the string in the URI string pool.
663     * @return URI string corresponding to the URI id.
664     */
665    virtual const XMLCh* getURIText(unsigned int uriId) const = 0;
666
667    /**
668      * Clear the cached grammar pool
669      */
670    virtual void resetCachedGrammarPool() = 0;
671
672    /**
673      * Returns the current src offset within the input source.
674      *
675      * @return offset within the input source
676      */
677    virtual unsigned int getSrcOffset() const = 0;
678
679    //@}
680
681};
682
683
684XERCES_CPP_NAMESPACE_END
685
686#endif
Note: See TracBrowser for help on using the repository browser.