Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:20

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XSDDOMPARSER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XSDDOMPARSER_HPP
0024 
0025 
0026 #include <xercesc/parsers/XercesDOMParser.hpp>
0027 #include <xercesc/validators/schema/XSDErrorReporter.hpp>
0028 #include <xercesc/validators/schema/XSDLocator.hpp>
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 class DOMElement;
0033 class XMLValidator;
0034 
0035 
0036 /**
0037   * This class is used to parse schema documents into DOM trees
0038   */
0039 class PARSERS_EXPORT XSDDOMParser : public XercesDOMParser
0040 {
0041 public :
0042 
0043     // -----------------------------------------------------------------------
0044     //  Constructors and Destructor
0045     // -----------------------------------------------------------------------
0046 
0047     /** @name Constructors and Destructor */
0048     //@{
0049     /** Construct a XSDDOMParser, with an optional validator
0050       *
0051       * Constructor with an instance of validator class to use for
0052       * validation. If you don't provide a validator, a default one will
0053       * be created for you in the scanner.
0054       *
0055       * @param gramPool   Pointer to the grammar pool instance from
0056       *                   external application.
0057       *                   The parser does NOT own it.
0058       *
0059       * @param valToAdopt Pointer to the validator instance to use. The
0060       *                   parser is responsible for freeing the memory.
0061       */
0062     XSDDOMParser
0063     (
0064           XMLValidator* const   valToAdopt = 0
0065         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0066         , XMLGrammarPool* const gramPool = 0
0067     );
0068 
0069     /**
0070       * Destructor
0071       */
0072     ~XSDDOMParser();
0073 
0074     //@}
0075 
0076     // -----------------------------------------------------------------------
0077     //  Implementation of the XMLDocumentHandler interface.
0078     // -----------------------------------------------------------------------
0079 
0080     /** @name Implementation of the XMLDocumentHandler interface. */
0081     //@{
0082 
0083     /** Handle a start element event
0084       *
0085       * This method is used to report the start of an element. It is
0086       * called at the end of the element, by which time all attributes
0087       * specified are also parsed. A new DOM Element node is created
0088       * along with as many attribute nodes as required. This new element
0089       * is added appended as a child of the current node in the tree, and
0090       * then replaces it as the current node (if the isEmpty flag is false.)
0091       *
0092       * @param elemDecl A const reference to the object containing element
0093       *                 declaration information.
0094       * @param urlId    An id referring to the namespace prefix, if
0095       *                 namespaces setting is switched on.
0096       * @param elemPrefix A const pointer to a Unicode string containing
0097       *                 the namespace prefix for this element. Applicable
0098       *                 only when namespace processing is enabled.
0099       * @param attrList A const reference to the object containing the
0100       *                 list of attributes just scanned for this element.
0101       * @param attrCount A count of number of attributes in the list
0102       *                 specified by the parameter 'attrList'.
0103       * @param isEmpty  A flag indicating whether this is an empty element
0104       *                 or not. If empty, then no endElement() call will
0105       *                 be made.
0106       * @param isRoot   A flag indicating whether this element was the
0107       *                 root element.
0108       * @see DocumentHandler#startElement
0109       */
0110     virtual void startElement
0111     (
0112         const   XMLElementDecl&         elemDecl
0113         , const unsigned int            urlId
0114         , const XMLCh* const            elemPrefix
0115         , const RefVectorOf<XMLAttr>&   attrList
0116         , const XMLSize_t               attrCount
0117         , const bool                    isEmpty
0118         , const bool                    isRoot
0119     );
0120 
0121     /** Handle and end of element event
0122       *
0123       * This method is used to indicate the end tag of an element. The
0124       * DOM parser pops the current element off the top of the element
0125       * stack, and make it the new current element.
0126       *
0127       * @param elemDecl A const reference to the object containing element
0128       *                 declaration information.
0129       * @param urlId    An id referring to the namespace prefix, if
0130       *                 namespaces setting is switched on.
0131       * @param isRoot   A flag indicating whether this element was the
0132       *                 root element.
0133       * @param elemPrefix A const pointer to a Unicode string containing
0134       *                 the namespace prefix for this element. Applicable
0135       *                 only when namespace processing is enabled.
0136       */
0137     virtual void endElement
0138     (
0139         const   XMLElementDecl& elemDecl
0140         , const unsigned int    urlId
0141         , const bool            isRoot
0142         , const XMLCh* const    elemPrefix
0143     );
0144 
0145     /** Handle document character events
0146       *
0147       * This method is used to report all the characters scanned by the
0148       * parser. This DOM implementation stores this data in the appropriate
0149       * DOM node, creating one if necessary.
0150       *
0151       * @param chars   A const pointer to a Unicode string representing the
0152       *                character data.
0153       * @param length  The length of the Unicode string returned in 'chars'.
0154       * @param cdataSection  A flag indicating if the characters represent
0155       *                      content from the CDATA section.
0156       */
0157     virtual void docCharacters
0158     (
0159         const   XMLCh* const    chars
0160         , const XMLSize_t       length
0161         , const bool            cdataSection
0162     );
0163 
0164     /** Handle a document comment event
0165       *
0166       * This method is used to report any comments scanned by the parser.
0167       * A new comment node is created which stores this data.
0168       *
0169       * @param comment A const pointer to a null terminated Unicode
0170       *                string representing the comment text.
0171       */
0172     virtual void docComment
0173     (
0174         const   XMLCh* const    comment
0175     );
0176 
0177     /** Handle a start entity reference event
0178       *
0179       * This method is used to indicate the start of an entity reference.
0180       * If the expand entity reference flag is true, then a new
0181       * DOM Entity reference node is created.
0182       *
0183       * @param entDecl A const reference to the object containing the
0184       *                entity declaration information.
0185       */
0186     virtual void startEntityReference
0187     (
0188         const   XMLEntityDecl&  entDecl
0189     );
0190 
0191     /** Handle and end of entity reference event
0192       *
0193       * This method is used to indicate that an end of an entity reference
0194       * was just scanned.
0195       *
0196       * @param entDecl A const reference to the object containing the
0197       *                entity declaration information.
0198       */
0199     virtual void endEntityReference
0200     (
0201         const   XMLEntityDecl&  entDecl
0202     );
0203 
0204     /** Handle an ignorable whitespace vent
0205       *
0206       * This method is used to report all the whitespace characters, which
0207       * are determined to be 'ignorable'. This distinction between characters
0208       * is only made, if validation is enabled.
0209       *
0210       * Any whitespace before content is ignored. If the current node is
0211       * already of type DOMNode::TEXT_NODE, then these whitespaces are
0212       * appended, otherwise a new Text node is created which stores this
0213       * data. Essentially all contiguous ignorable characters are collected
0214       * in one node.
0215       *
0216       * @param chars   A const pointer to a Unicode string representing the
0217       *                ignorable whitespace character data.
0218       * @param length  The length of the Unicode string 'chars'.
0219       * @param cdataSection  A flag indicating if the characters represent
0220       *                      content from the CDATA section.
0221       */
0222     virtual void ignorableWhitespace
0223     (
0224         const   XMLCh* const    chars
0225         , const XMLSize_t       length
0226         , const bool            cdataSection
0227     );
0228 
0229     //@}
0230 
0231     // -----------------------------------------------------------------------
0232     //  Get methods
0233     // -----------------------------------------------------------------------
0234     bool getSawFatal() const;
0235 
0236 
0237     // -----------------------------------------------------------------------
0238     //  Set methods
0239     // -----------------------------------------------------------------------
0240     void setUserErrorReporter(XMLErrorReporter* const errorReporter);
0241     void setUserEntityHandler(XMLEntityHandler* const entityHandler);
0242 
0243 
0244     // -----------------------------------------------------------------------
0245     //  XMLErrorReporter interface
0246     // -----------------------------------------------------------------------
0247     virtual void error
0248     (
0249         const   unsigned int        errCode
0250         , const XMLCh* const        errDomain
0251         , const ErrTypes            type
0252         , const XMLCh* const        errorText
0253         , const XMLCh* const        systemId
0254         , const XMLCh* const        publicId
0255         , const XMLFileLoc          lineNum
0256         , const XMLFileLoc          colNum
0257     );
0258 
0259     // -----------------------------------------------------------------------
0260     //  XMLEntityHandler interface
0261     // -----------------------------------------------------------------------
0262     virtual InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
0263 
0264 protected :
0265     // -----------------------------------------------------------------------
0266     //  Protected Helper methods
0267     // -----------------------------------------------------------------------
0268     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
0269                                             const XMLCh *qualifiedName);
0270 
0271 private:
0272     // -----------------------------------------------------------------------
0273     //  Unimplemented constructors and operators
0274     // -----------------------------------------------------------------------
0275     XSDDOMParser(const XSDDOMParser&);
0276     XSDDOMParser& operator=(const XSDDOMParser&);
0277 
0278     // -----------------------------------------------------------------------
0279     //  Private Helper methods
0280     // -----------------------------------------------------------------------
0281     void startAnnotation
0282     (
0283         const   XMLElementDecl&         elemDecl
0284         , const RefVectorOf<XMLAttr>&   attrList
0285         , const XMLSize_t               attrCount
0286     );
0287     void startAnnotationElement
0288     (
0289         const   XMLElementDecl&         elemDecl
0290         , const RefVectorOf<XMLAttr>&   attrList
0291         , const XMLSize_t               attrCount
0292     );
0293     void endAnnotationElement
0294     (
0295         const XMLElementDecl& elemDecl
0296         ,     bool            complete
0297     );
0298 
0299     // -----------------------------------------------------------------------
0300     //  Private data members
0301     // -----------------------------------------------------------------------
0302     bool                         fSawFatal;
0303     int                          fAnnotationDepth;
0304     int                          fInnerAnnotationDepth;
0305     int                          fDepth;
0306     XMLErrorReporter*            fUserErrorReporter;
0307     XMLEntityHandler*            fUserEntityHandler;
0308     ValueVectorOf<unsigned int>* fURIs;
0309     XMLBuffer                    fAnnotationBuf;
0310     XSDErrorReporter             fXSDErrorReporter;
0311     XSDLocator                   fXSLocator;
0312 };
0313 
0314 
0315 inline bool XSDDOMParser::getSawFatal() const
0316 {
0317     return fSawFatal;
0318 }
0319 
0320 XERCES_CPP_NAMESPACE_END
0321 
0322 #endif