AbstractDOMParser.hpp

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: AbstractDOMParser.hpp 698579 2008-09-24 14:13:08Z borisk $
00020  */
00021 
00022 #if !defined(XERCESC_INCLUDE_GUARD_ABSTRACTDOMPARSER_HPP)
00023 #define XERCESC_INCLUDE_GUARD_ABSTRACTDOMPARSER_HPP
00024 
00025 #include <xercesc/dom/DOMDocument.hpp>
00026 #include <xercesc/framework/XMLDocumentHandler.hpp>
00027 #include <xercesc/framework/XMLErrorReporter.hpp>
00028 #include <xercesc/framework/XMLEntityHandler.hpp>
00029 #include <xercesc/util/SecurityManager.hpp>
00030 #include <xercesc/util/ValueStackOf.hpp>
00031 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00032 #include <xercesc/dom/DOMDocumentType.hpp>
00033 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
00034 #include <xercesc/framework/XMLBufferMgr.hpp>
00035 #include <xercesc/framework/psvi/PSVIHandler.hpp>
00036 
00037 XERCES_CPP_NAMESPACE_BEGIN
00038 
00039 class XMLPScanToken;
00040 class XMLScanner;
00041 class XMLValidator;
00042 class DOMDocumentImpl;
00043 class DOMDocumentTypeImpl;
00044 class DOMEntityImpl;
00045 class DOMElement;
00046 class GrammarResolver;
00047 class XMLGrammarPool;
00048 class PSVIHandler;
00049 
00054 class PARSERS_EXPORT AbstractDOMParser :
00055 
00056     public XMemory
00057     , public XMLDocumentHandler
00058     , public XMLErrorReporter
00059     , public XMLEntityHandler
00060     , public DocTypeHandler
00061     , public PSVIHandler
00062 {
00063 public :
00064     // -----------------------------------------------------------------------
00065     //  Class types
00066     // -----------------------------------------------------------------------
00069 
00077     enum ValSchemes
00078     {
00079         Val_Never
00080         , Val_Always
00081         , Val_Auto
00082     };
00083 
00085 
00086 
00087     // -----------------------------------------------------------------------
00088     //  Constructors and Detructor
00089     // -----------------------------------------------------------------------
00092 
00096     virtual ~AbstractDOMParser();
00097 
00099 
00100     // -----------------------------------------------------------------------
00101     //  Utility methods
00102     // -----------------------------------------------------------------------
00103 
00111     void reset();
00112 
00126     DOMDocument* adoptDocument();
00127 
00129 
00130 
00131     // -----------------------------------------------------------------------
00132     //  Getter methods
00133     // -----------------------------------------------------------------------
00134 
00137 
00149     DOMDocument* getDocument();
00150 
00158     const XMLValidator& getValidator() const;
00159 
00167     ValSchemes getValidationScheme() const;
00168 
00179     bool getDoSchema() const;
00180 
00191     bool getValidationSchemaFullChecking() const;
00192 
00203     bool getIdentityConstraintChecking() const;
00204 
00216     XMLSize_t getErrorCount() const;
00217 
00228     bool getDoNamespaces() const;
00229 
00242     bool getExitOnFirstFatalError() const;
00243 
00254     bool getValidationConstraintFatal() const;
00255 
00265     bool  getCreateEntityReferenceNodes()const;
00266 
00277     bool getIncludeIgnorableWhitespace() const;
00278 
00298     XMLCh* getExternalSchemaLocation() const;
00299 
00319     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00320 
00336     SecurityManager* getSecurityManager() const;
00337 
00349     bool getLoadExternalDTD() const;
00350 
00362     bool getLoadSchema() const;
00363 
00372     bool  getCreateCommentNodes()const;
00373 
00385     bool getCalculateSrcOfs() const;
00386 
00397     bool getStandardUriConformant() const;
00398 
00405     PSVIHandler* getPSVIHandler();
00406 
00413     const PSVIHandler* getPSVIHandler() const;
00414 
00424     bool getCreateSchemaInfo() const;
00425 
00435     bool getDoXInclude() const;
00436 
00448     bool getGenerateSyntheticAnnotations() const;
00449 
00457     bool getValidateAnnotations() const;
00458 
00466     bool getIgnoreAnnotations() const;
00467 
00475     bool getDisableDefaultEntityResolution() const;
00476 
00484     bool getSkipDTDValidation() const;
00485 
00493     bool getHandleMultipleImports() const;
00495 
00496 
00497     // -----------------------------------------------------------------------
00498     //  Setter methods
00499     // -----------------------------------------------------------------------
00500 
00514     void setGenerateSyntheticAnnotations(const bool newValue);
00515 
00523     void setValidateAnnotations(const bool newValue);
00524 
00539     void setDoNamespaces(const bool newState);
00540 
00557     void setExitOnFirstFatalError(const bool newState);
00558 
00578     void setValidationConstraintFatal(const bool newState);
00579 
00598     void setCreateEntityReferenceNodes(const bool create);
00599 
00621     void setIncludeIgnorableWhitespace(const bool include);
00622 
00639     void setValidationScheme(const ValSchemes newScheme);
00640 
00656     void setDoSchema(const bool newState);
00657 
00674     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00675 
00689     void setIdentityConstraintChecking(const bool newState);
00690 
00711     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00712 
00721     void setExternalSchemaLocation(const char* const schemaLocation);
00722 
00737     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00738 
00747     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00748 
00764     void setSecurityManager(SecurityManager* const securityManager);
00765 
00782     void setLoadExternalDTD(const bool newState);
00783 
00799     void setLoadSchema(const bool newState);
00800 
00811     void setCreateCommentNodes(const bool create);
00812 
00825     void setCalculateSrcOfs(const bool newState);
00826 
00837     void setStandardUriConformant(const bool newState);
00838 
00846     void useScanner(const XMLCh* const scannerName);
00847 
00855     void useImplementation(const XMLCh* const implementationFeatures);
00856 
00865     virtual void setPSVIHandler(PSVIHandler* const handler);
00866 
00876     void  setCreateSchemaInfo(const bool newState);
00877 
00887     void  setDoXInclude(const bool newState);
00888 
00898     void setIgnoreAnnotations(const bool newValue);
00899 
00914     void setDisableDefaultEntityResolution(const bool newValue);
00915 
00928     void setSkipDTDValidation(const bool newValue);
00929 
00941     void setHandleMultipleImports(const bool newValue);
00943 
00944 
00945     // -----------------------------------------------------------------------
00946     //  Parsing methods
00947     // -----------------------------------------------------------------------
00948 
00951 
00967     void parse(const InputSource& source);
00968 
00985     void parse(const XMLCh* const systemId);
00986 
01002     void parse(const char* const systemId);
01003 
01030     bool parseFirst
01031     (
01032         const   XMLCh* const    systemId
01033         ,       XMLPScanToken&  toFill
01034     );
01035 
01063     bool parseFirst
01064     (
01065         const   char* const     systemId
01066         ,       XMLPScanToken&  toFill
01067     );
01068 
01096     bool parseFirst
01097     (
01098         const   InputSource&    source
01099         ,       XMLPScanToken&  toFill
01100     );
01101 
01124     bool parseNext(XMLPScanToken& token);
01125 
01151     void parseReset(XMLPScanToken& token);
01152 
01154 
01155     // -----------------------------------------------------------------------
01156     //  Implementation of the PSVIHandler interface.
01157     // -----------------------------------------------------------------------
01158 
01161 
01172     virtual void handleElementPSVI
01173     (
01174         const   XMLCh* const            localName
01175         , const XMLCh* const            uri
01176         ,       PSVIElement *           elementInfo
01177     );
01178 
01179     virtual void handlePartialElementPSVI
01180     (
01181         const   XMLCh* const            localName
01182         , const XMLCh* const            uri
01183         ,       PSVIElement *           elementInfo
01184     );
01196     virtual void handleAttributesPSVI
01197     (
01198         const   XMLCh* const            localName
01199         , const XMLCh* const            uri
01200         ,       PSVIAttributeList *     psviAttributes
01201     );
01203 
01204     // -----------------------------------------------------------------------
01205     //  Implementation of the XMLDocumentHandler interface.
01206     // -----------------------------------------------------------------------
01207 
01210 
01223     virtual void docCharacters
01224     (
01225         const   XMLCh* const    chars
01226         , const XMLSize_t       length
01227         , const bool            cdataSection
01228     );
01229 
01238     virtual void docComment
01239     (
01240         const   XMLCh* const    comment
01241     );
01242 
01255     virtual void docPI
01256     (
01257         const   XMLCh* const    target
01258         , const XMLCh* const    data
01259     );
01260 
01265     virtual void endDocument();
01266 
01283     virtual void endElement
01284     (
01285         const   XMLElementDecl& elemDecl
01286         , const unsigned int    urlId
01287         , const bool            isRoot
01288         , const XMLCh* const    elemPrefix
01289     );
01290 
01299     virtual void endEntityReference
01300     (
01301         const   XMLEntityDecl&  entDecl
01302     );
01303 
01322     virtual void ignorableWhitespace
01323     (
01324         const   XMLCh* const    chars
01325         , const XMLSize_t       length
01326         , const bool            cdataSection
01327     );
01328 
01335     virtual void resetDocument();
01336 
01341     virtual void startDocument();
01342 
01370     virtual void startElement
01371     (
01372         const   XMLElementDecl&         elemDecl
01373         , const unsigned int            urlId
01374         , const XMLCh* const            elemPrefix
01375         , const RefVectorOf<XMLAttr>&   attrList
01376         , const XMLSize_t               attrCount
01377         , const bool                    isEmpty
01378         , const bool                    isRoot
01379     );
01380 
01390     virtual void startEntityReference
01391     (
01392         const   XMLEntityDecl&  entDecl
01393     );
01394 
01413     virtual void XMLDecl
01414     (
01415         const   XMLCh* const    versionStr
01416         , const XMLCh* const    encodingStr
01417         , const XMLCh* const    standaloneStr
01418         , const XMLCh* const    actualEncStr
01419     );
01420 
01422 
01423 
01424     // -----------------------------------------------------------------------
01425     //  Implementation of the deprecated DocTypeHandler interface.
01426     // -----------------------------------------------------------------------
01429     virtual void attDef
01430     (
01431         const   DTDElementDecl&     elemDecl
01432         , const DTDAttDef&          attDef
01433         , const bool                ignoring
01434     );
01435 
01436     virtual void doctypeComment
01437     (
01438         const   XMLCh* const    comment
01439     );
01440 
01441     virtual void doctypeDecl
01442     (
01443         const   DTDElementDecl& elemDecl
01444         , const XMLCh* const    publicId
01445         , const XMLCh* const    systemId
01446         , const bool            hasIntSubset
01447         , const bool            hasExtSubset = false
01448     );
01449 
01450     virtual void doctypePI
01451     (
01452         const   XMLCh* const    target
01453         , const XMLCh* const    data
01454     );
01455 
01456     virtual void doctypeWhitespace
01457     (
01458         const   XMLCh* const    chars
01459         , const XMLSize_t       length
01460     );
01461 
01462     virtual void elementDecl
01463     (
01464         const   DTDElementDecl& decl
01465         , const bool            isIgnored
01466     );
01467 
01468     virtual void endAttList
01469     (
01470         const   DTDElementDecl& elemDecl
01471     );
01472 
01473     virtual void endIntSubset();
01474 
01475     virtual void endExtSubset();
01476 
01477     virtual void entityDecl
01478     (
01479         const   DTDEntityDecl&  entityDecl
01480         , const bool            isPEDecl
01481         , const bool            isIgnored
01482     );
01483 
01484     virtual void resetDocType();
01485 
01486     virtual void notationDecl
01487     (
01488         const   XMLNotationDecl&    notDecl
01489         , const bool                isIgnored
01490     );
01491 
01492     virtual void startAttList
01493     (
01494         const   DTDElementDecl& elemDecl
01495     );
01496 
01497     virtual void startIntSubset();
01498 
01499     virtual void startExtSubset();
01500 
01501     virtual void TextDecl
01502     (
01503         const   XMLCh* const    versionStr
01504         , const XMLCh* const    encodingStr
01505     );
01506 
01508 
01509 protected:
01510     // DOM node creation hooks. Override them if you are using your own
01511     // DOM node types.
01512     //
01513     virtual DOMCDATASection* createCDATASection (const XMLCh*, XMLSize_t);
01514     virtual DOMText* createText (const XMLCh*, XMLSize_t);
01515 
01516     virtual DOMElement* createElement (const XMLCh* name);
01517     virtual DOMElement* createElementNS (const XMLCh* namespaceURI,
01518                                          const XMLCh* elemPrefix,
01519                                          const XMLCh* localName,
01520                                          const XMLCh* qName);
01521 
01522     virtual DOMAttr* createAttr (const XMLCh* name);
01523     virtual DOMAttr* createAttrNS (const XMLCh* namespaceURI,
01524                                    const XMLCh* elemPrefix,
01525                                    const XMLCh* localName,
01526                                    const XMLCh* qName);
01527 
01528 
01529 
01530 
01531 protected :
01532     // -----------------------------------------------------------------------
01533     //  Protected Constructor Methods
01534     // -----------------------------------------------------------------------
01553     AbstractDOMParser
01554     (
01555           XMLValidator* const   valToAdopt = 0
01556         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01557         , XMLGrammarPool* const gramPool = 0
01558     );
01559 
01561 
01562     // -----------------------------------------------------------------------
01563     //  Protected getter methods
01564     // -----------------------------------------------------------------------
01572     DOMNode* getCurrentNode();
01573 
01578     XMLScanner* getScanner() const;
01579 
01584     GrammarResolver* getGrammarResolver() const;
01585 
01591     bool getParseInProgress() const;
01592 
01593     MemoryManager* getMemoryManager() const;
01594 
01596 
01597 
01598     // -----------------------------------------------------------------------
01599     //  Protected setter methods
01600     // -----------------------------------------------------------------------
01601 
01604 
01612     void setCurrentNode(DOMNode* toSet);
01613 
01620     void setDocument(DOMDocument* toSet);
01621 
01628     void setParseInProgress(const bool toSet);
01630 
01631     // -----------------------------------------------------------------------
01632     //  Protected Helper methods
01633     // -----------------------------------------------------------------------
01636     void resetPool();
01637 
01641     bool isDocumentAdopted() const;
01642 
01644 
01645 
01646 private :
01647     // -----------------------------------------------------------------------
01648     //  Initialize/Cleanup methods
01649     // -----------------------------------------------------------------------
01650     void initialize();
01651     void cleanUp();
01652     void resetInProgress();
01653 
01654     // -----------------------------------------------------------------------
01655     //  Unimplemented constructors and operators
01656     // -----------------------------------------------------------------------
01657     AbstractDOMParser(const AbstractDOMParser&);
01658     AbstractDOMParser& operator=(const AbstractDOMParser&);
01659 
01660 protected:
01661     // -----------------------------------------------------------------------
01662     //  Protected data members
01663     //
01664     //  fCurrentNode
01665     //  fCurrentParent
01666     //      Used to track the current node during nested element events. Since
01667     //      the tree must be built from a set of disjoint callbacks, we need
01668     //      these to keep up with where we currently are.
01669     //
01670     //  fCurrentEntity
01671     //      Used to track the current entity decl.  If a text decl is seen later on,
01672     //      it is used to update the encoding and version information.
01673     //
01674     //  fDocument
01675     //      The root document object, filled with the document contents.
01676     //
01677     //  fCreateEntityReferenceNodes
01678     //      Indicates whether entity reference nodes should be created.
01679     //
01680     //  fIncludeIgnorableWhitespace
01681     //      Indicates whether ignorable whiltespace should be added to
01682     //      the DOM tree for validating parsers.
01683     //
01684     //  fScanner
01685     //      The scanner used for this parser. This is created during the
01686     //      constructor.
01687     //
01688     //  fImplementationFeatures
01689     //      The implementation features that we use to get an implementation
01690     //      for use in creating the DOMDocument used during parse. If this is
01691     //      null then the default DOMImplementation is used
01692     //
01693     //  fParseInProgress
01694     //      Used to prevent multiple entrance to the parser while its doing
01695     //      a parse.
01696     //
01697     //  fWithinElement
01698     //      A flag to indicate that the parser is within at least one level
01699     //      of element processing.
01700     //
01701     //  fDocumentType
01702     //      Used to store and update the documentType variable information
01703     //      in fDocument
01704     //
01705     //  fDocumentVector
01706     //      Store all the previous fDocument(s) (thus not the current fDocument)
01707     //      created in this parser.  It is destroyed when the parser is destructed.
01708     //
01709     //  fCreateCommentNodes
01710     //      Indicates whether comment nodes should be created.
01711     //
01712     //  fDocumentAdoptedByUser
01713     //      The DOMDocument ownership has been transferred to application
01714     //      If set to true, the parser does not own the document anymore
01715     //      and thus will not release its memory.
01716     //
01717     //  fInternalSubset
01718     //      Buffer for storing the internal subset information.
01719     //      Once complete (after DOCTYPE is finished scanning), send
01720     //      it to DocumentType Node
01721     //
01722     //   fGrammarPool
01723     //      The grammar pool passed from external application (through derivatives).
01724     //      which could be 0, not owned.
01725     //
01726     //  fCreateSchemaInfo
01727     //      Indicates whether element and attributes will have schema info associated
01728     //
01729     //   fDoXinclude
01730     //      A bool used to request that XInlcude processing occur on the
01731     //      Document the parser parses.
01732     // -----------------------------------------------------------------------
01733     bool                          fCreateEntityReferenceNodes;
01734     bool                          fIncludeIgnorableWhitespace;
01735     bool                          fWithinElement;
01736     bool                          fParseInProgress;
01737     bool                          fCreateCommentNodes;
01738     bool                          fDocumentAdoptedByUser;
01739     bool                          fCreateSchemaInfo;
01740     bool                          fDoXInclude;
01741     XMLScanner*                   fScanner;
01742     XMLCh*                        fImplementationFeatures;
01743     DOMNode*                      fCurrentParent;
01744     DOMNode*                      fCurrentNode;
01745     DOMEntityImpl*                fCurrentEntity;
01746     DOMDocumentImpl*              fDocument;
01747     DOMDocumentTypeImpl*          fDocumentType;
01748     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
01749     GrammarResolver*              fGrammarResolver;
01750     XMLStringPool*                fURIStringPool;
01751     XMLValidator*                 fValidator;
01752     MemoryManager*                fMemoryManager;
01753     XMLGrammarPool*               fGrammarPool;
01754     XMLBufferMgr                  fBufMgr;
01755     XMLBuffer&                    fInternalSubset;
01756     PSVIHandler*                  fPSVIHandler;
01757 };
01758 
01759 
01760 
01761 // ---------------------------------------------------------------------------
01762 //  AbstractDOMParser: Getter methods
01763 // ---------------------------------------------------------------------------
01764 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
01765 {
01766     return fCreateEntityReferenceNodes;
01767 }
01768 
01769 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
01770 {
01771     return fIncludeIgnorableWhitespace;
01772 }
01773 
01774 inline bool AbstractDOMParser::getParseInProgress() const
01775 {
01776     return fParseInProgress;
01777 }
01778 
01779 inline XMLScanner* AbstractDOMParser::getScanner() const
01780 {
01781     return fScanner;
01782 }
01783 
01784 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
01785 {
01786     return fGrammarResolver;
01787 }
01788 
01789 inline bool AbstractDOMParser::getCreateCommentNodes() const
01790 {
01791     return fCreateCommentNodes;
01792 }
01793 
01794 inline PSVIHandler* AbstractDOMParser::getPSVIHandler()
01795 {
01796     return fPSVIHandler;
01797 }
01798 
01799 inline const PSVIHandler* AbstractDOMParser::getPSVIHandler() const
01800 {
01801     return fPSVIHandler;
01802 }
01803 
01804 inline bool AbstractDOMParser::getCreateSchemaInfo() const
01805 {
01806     return fCreateSchemaInfo;
01807 }
01808 
01809 inline bool AbstractDOMParser::getDoXInclude() const
01810 {
01811     return fDoXInclude;
01812 }
01813 // ---------------------------------------------------------------------------
01814 //  AbstractDOMParser: Setter methods
01815 // ---------------------------------------------------------------------------
01816 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
01817 {
01818     fCreateEntityReferenceNodes = create;
01819 }
01820 
01821 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
01822 {
01823     fIncludeIgnorableWhitespace = include;
01824 }
01825 
01826 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
01827 {
01828     fCreateCommentNodes = create;
01829 }
01830 
01831 inline void AbstractDOMParser::useImplementation(const XMLCh* const implementationFeatures)
01832 {
01833     fMemoryManager->deallocate(fImplementationFeatures);
01834     fImplementationFeatures = XMLString::replicate(implementationFeatures, fMemoryManager);
01835 }
01836 
01837 inline void AbstractDOMParser::setDoXInclude(const bool newState)
01838 {
01839     fDoXInclude = newState;
01840 }
01841 
01842 // ---------------------------------------------------------------------------
01843 //  AbstractDOMParser: Protected getter methods
01844 // ---------------------------------------------------------------------------
01845 inline DOMNode* AbstractDOMParser::getCurrentNode()
01846 {
01847     return fCurrentNode;
01848 }
01849 
01850 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
01851 {
01852     return fMemoryManager;
01853 }
01854 
01855 // ---------------------------------------------------------------------------
01856 //  AbstractDOMParser: Protected setter methods
01857 // ---------------------------------------------------------------------------
01858 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
01859 {
01860     fCurrentNode = toSet;
01861 }
01862 
01863 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
01864 {
01865     fParseInProgress = toSet;
01866 }
01867 
01868 XERCES_CPP_NAMESPACE_END
01869 
01870 #endif

Generated on Wed Sep 24 16:36:32 2008 for Xerces-C++ by  doxygen 1.5.4