source: icXML/icXML-devel/src/icxercesc/validators/schema/XSDDOMParser.hpp @ 2774

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

Various fixes

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