source: icXML/icXML-devel/src/xercesc/validators/schema/XSDDOMParser.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

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