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 568078 2007-08-21 11:43:25Z amassari $
00020  *
00021  */
00022 #if !defined(ABSTRACTDOMPARSER_HPP)
00023 #define 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 DOMElement;
00045 class GrammarResolver;
00046 class XMLGrammarPool;
00047 class PSVIHandler;
00048 
00053 class PARSERS_EXPORT AbstractDOMParser :
00054 
00055     public XMemory
00056     , public XMLDocumentHandler
00057     , public XMLErrorReporter
00058     , public XMLEntityHandler
00059     , public DocTypeHandler
00060     , public PSVIHandler
00061 {
00062 public :
00063     // -----------------------------------------------------------------------
00064     //  Class types
00065     // -----------------------------------------------------------------------
00068 
00076     enum ValSchemes
00077     {
00078         Val_Never
00079         , Val_Always
00080         , Val_Auto
00081     };
00082 
00084 
00085 
00086     // -----------------------------------------------------------------------
00087     //  Constructors and Detructor
00088     // -----------------------------------------------------------------------
00091 
00095     virtual ~AbstractDOMParser();
00096 
00098 
00099     // -----------------------------------------------------------------------
00100     //  Utility methods
00101     // -----------------------------------------------------------------------
00102 
00110     void reset();
00111 
00125     DOMDocument* adoptDocument();
00126 
00128 
00129 
00130     // -----------------------------------------------------------------------
00131     //  Getter methods
00132     // -----------------------------------------------------------------------
00133 
00136 
00148     DOMDocument* getDocument();
00149 
00157     const XMLValidator& getValidator() const;
00158 
00166     ValSchemes getValidationScheme() const;
00167 
00178     bool getDoSchema() const;
00179 
00190     bool getValidationSchemaFullChecking() const;
00191 
00202     bool getIdentityConstraintChecking() const;
00203 
00215     int getErrorCount() const;
00216 
00227     bool getDoNamespaces() const;
00228 
00241     bool getExitOnFirstFatalError() const;
00242 
00253     bool getValidationConstraintFatal() const;
00254 
00264     bool  getCreateEntityReferenceNodes()const;
00265 
00276     bool getIncludeIgnorableWhitespace() const;
00277 
00297     XMLCh* getExternalSchemaLocation() const;
00298 
00318     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00319 
00335     SecurityManager* getSecurityManager() const;
00336 
00348     bool getLoadExternalDTD() const;
00349 
00358     bool  getCreateCommentNodes()const;
00359 
00371     bool getCalculateSrcOfs() const;
00372 
00383     bool getStandardUriConformant() const;
00384 
00391     PSVIHandler* getPSVIHandler();
00392 
00399     const PSVIHandler* getPSVIHandler() const;
00400 
00410     bool  getCreateSchemaInfo() const;
00411 
00423     bool getGenerateSyntheticAnnotations() const;
00424 
00432     bool getValidateAnnotations() const;
00433 
00441     bool getIgnoreAnnotations() const;
00442 
00450     bool getDisableDefaultEntityResolution() const;
00451 
00459     bool getSkipDTDValidation() const;
00460 
00462 
00463 
00464     // -----------------------------------------------------------------------
00465     //  Setter methods
00466     // -----------------------------------------------------------------------
00467 
00481     void setGenerateSyntheticAnnotations(const bool newValue);
00482 
00490     void setValidateAnnotations(const bool newValue);
00491 
00506     void setDoNamespaces(const bool newState);
00507 
00524     void setExitOnFirstFatalError(const bool newState);
00525 
00545     void setValidationConstraintFatal(const bool newState);
00546 
00565     void setCreateEntityReferenceNodes(const bool create);
00566 
00588     void setIncludeIgnorableWhitespace(const bool include);
00589 
00606     void setValidationScheme(const ValSchemes newScheme);
00607 
00623     void setDoSchema(const bool newState);
00624 
00641     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00642 
00656     void setIdentityConstraintChecking(const bool newState);
00657 
00678     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00679 
00688     void setExternalSchemaLocation(const char* const schemaLocation);
00689 
00704     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00705 
00714     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00715 
00731     void setSecurityManager(SecurityManager* const securityManager);
00732 
00749     void setLoadExternalDTD(const bool newState);
00750 
00761     void setCreateCommentNodes(const bool create);
00762 
00775     void setCalculateSrcOfs(const bool newState);
00776 
00787     void setStandardUriConformant(const bool newState);
00788 
00796     void useScanner(const XMLCh* const scannerName);
00797 
00805     void useImplementation(const XMLCh* const implementationFeatures);
00806 
00815     virtual void setPSVIHandler(PSVIHandler* const handler);
00816 
00826     void  setCreateSchemaInfo(const bool newState);
00827 
00837     void setIgnoreAnnotations(const bool newValue);
00838 
00853     void setDisableDefaultEntityResolution(const bool newValue);
00854 
00867     void setSkipDTDValidation(const bool newValue);
00869 
00870 
00871     // -----------------------------------------------------------------------
00872     //  Parsing methods
00873     // -----------------------------------------------------------------------
00874 
00877 
00893     void parse(const InputSource& source);
00894 
00911     void parse(const XMLCh* const systemId);
00912 
00928     void parse(const char* const systemId);
00929 
00956     bool parseFirst
00957     (
00958         const   XMLCh* const    systemId
00959         ,       XMLPScanToken&  toFill
00960     );
00961 
00989     bool parseFirst
00990     (
00991         const   char* const     systemId
00992         ,       XMLPScanToken&  toFill
00993     );
00994 
01022     bool parseFirst
01023     (
01024         const   InputSource&    source
01025         ,       XMLPScanToken&  toFill
01026     );
01027 
01050     bool parseNext(XMLPScanToken& token);
01051 
01077     void parseReset(XMLPScanToken& token);
01078 
01080 
01081     // -----------------------------------------------------------------------
01082     //  Implementation of the PSVIHandler interface.
01083     // -----------------------------------------------------------------------
01084     
01087 
01098     virtual void handleElementPSVI
01099     (
01100         const   XMLCh* const            localName 
01101         , const XMLCh* const            uri
01102         ,       PSVIElement *           elementInfo
01103     );
01104 
01105     virtual void handlePartialElementPSVI
01106     (
01107         const   XMLCh* const            localName 
01108         , const XMLCh* const            uri
01109         ,       PSVIElement *           elementInfo
01110     );
01122     virtual void handleAttributesPSVI
01123     (
01124         const   XMLCh* const            localName 
01125         , const XMLCh* const            uri
01126         ,       PSVIAttributeList *     psviAttributes
01127     );
01129 
01130     // -----------------------------------------------------------------------
01131     //  Implementation of the XMLDocumentHandler interface.
01132     // -----------------------------------------------------------------------
01133 
01136 
01149     virtual void docCharacters
01150     (
01151         const   XMLCh* const    chars
01152         , const unsigned int    length
01153         , const bool            cdataSection
01154     );
01155 
01164     virtual void docComment
01165     (
01166         const   XMLCh* const    comment
01167     );
01168 
01181     virtual void docPI
01182     (
01183         const   XMLCh* const    target
01184         , const XMLCh* const    data
01185     );
01186 
01191     virtual void endDocument();
01192 
01209     virtual void endElement
01210     (
01211         const   XMLElementDecl& elemDecl
01212         , const unsigned int    urlId
01213         , const bool            isRoot
01214         , const XMLCh* const    elemPrefix
01215     );
01216 
01225     virtual void endEntityReference
01226     (
01227         const   XMLEntityDecl&  entDecl
01228     );
01229 
01248     virtual void ignorableWhitespace
01249     (
01250         const   XMLCh* const    chars
01251         , const unsigned int    length
01252         , const bool            cdataSection
01253     );
01254 
01261     virtual void resetDocument();
01262 
01267     virtual void startDocument();
01268 
01296     virtual void startElement
01297     (
01298         const   XMLElementDecl&         elemDecl
01299         , const unsigned int            urlId
01300         , const XMLCh* const            elemPrefix
01301         , const RefVectorOf<XMLAttr>&   attrList
01302         , const unsigned int            attrCount
01303         , const bool                    isEmpty
01304         , const bool                    isRoot
01305     );
01306 
01316     virtual void startEntityReference
01317     (
01318         const   XMLEntityDecl&  entDecl
01319     );
01320 
01339     virtual void XMLDecl
01340     (
01341         const   XMLCh* const    versionStr
01342         , const XMLCh* const    encodingStr
01343         , const XMLCh* const    standaloneStr
01344         , const XMLCh* const    actualEncStr
01345     );
01346 
01366     virtual void elementTypeInfo
01367     (
01368         const   XMLCh* const    typeName
01369         , const XMLCh* const    typeURI
01370     );
01372 
01373 
01374     // -----------------------------------------------------------------------
01375     //  Implementation of the deprecated DocTypeHandler interface.
01376     // -----------------------------------------------------------------------
01379     virtual void attDef
01380     (
01381         const   DTDElementDecl&     elemDecl
01382         , const DTDAttDef&          attDef
01383         , const bool                ignoring
01384     );
01385 
01386     virtual void doctypeComment
01387     (
01388         const   XMLCh* const    comment
01389     );
01390 
01391     virtual void doctypeDecl
01392     (
01393         const   DTDElementDecl& elemDecl
01394         , const XMLCh* const    publicId
01395         , const XMLCh* const    systemId
01396         , const bool            hasIntSubset
01397         , const bool            hasExtSubset = false
01398     );
01399 
01400     virtual void doctypePI
01401     (
01402         const   XMLCh* const    target
01403         , const XMLCh* const    data
01404     );
01405 
01406     virtual void doctypeWhitespace
01407     (
01408         const   XMLCh* const    chars
01409         , const unsigned int    length
01410     );
01411 
01412     virtual void elementDecl
01413     (
01414         const   DTDElementDecl& decl
01415         , const bool            isIgnored
01416     );
01417 
01418     virtual void endAttList
01419     (
01420         const   DTDElementDecl& elemDecl
01421     );
01422 
01423     virtual void endIntSubset();
01424 
01425     virtual void endExtSubset();
01426 
01427     virtual void entityDecl
01428     (
01429         const   DTDEntityDecl&  entityDecl
01430         , const bool            isPEDecl
01431         , const bool            isIgnored
01432     );
01433 
01434     virtual void resetDocType();
01435 
01436     virtual void notationDecl
01437     (
01438         const   XMLNotationDecl&    notDecl
01439         , const bool                isIgnored
01440     );
01441 
01442     virtual void startAttList
01443     (
01444         const   DTDElementDecl& elemDecl
01445     );
01446 
01447     virtual void startIntSubset();
01448 
01449     virtual void startExtSubset();
01450 
01451     virtual void TextDecl
01452     (
01453         const   XMLCh* const    versionStr
01454         , const XMLCh* const    encodingStr
01455     );
01456 
01457 
01459 
01460 
01461     // -----------------------------------------------------------------------
01462     //  Deprecated Methods
01463     // -----------------------------------------------------------------------
01476     bool getDoValidation() const;
01477 
01491     void setDoValidation(const bool newState);
01492 
01506     bool getExpandEntityReferences() const;
01507 
01524     void setExpandEntityReferences(const bool expand);
01525 
01527 
01528 protected :
01529     // -----------------------------------------------------------------------
01530     //  Protected Constructor Methods
01531     // -----------------------------------------------------------------------
01550     AbstractDOMParser
01551     (
01552           XMLValidator* const   valToAdopt = 0
01553         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01554         , XMLGrammarPool* const gramPool = 0
01555     );
01556 
01558 
01559     // -----------------------------------------------------------------------
01560     //  Protected getter methods
01561     // -----------------------------------------------------------------------
01569     DOMNode* getCurrentNode();
01570 
01575     XMLScanner* getScanner() const;
01576 
01581     GrammarResolver* getGrammarResolver() const;
01582 
01588     bool getParseInProgress() const;
01589 
01590     MemoryManager* getMemoryManager() const;
01591 
01593 
01594 
01595     // -----------------------------------------------------------------------
01596     //  Protected setter methods
01597     // -----------------------------------------------------------------------
01598 
01601 
01609     void setCurrentNode(DOMNode* toSet);
01610 
01617     void setDocument(DOMDocument* toSet);
01618 
01625     void setParseInProgress(const bool toSet);
01627 
01628     // -----------------------------------------------------------------------
01629     //  Protected Helper methods
01630     // -----------------------------------------------------------------------
01633     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
01634                                               const XMLCh *qualifiedName);
01635 
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     //  fNodeStack
01694     //      Used to track previous parent nodes during nested element events.
01695     //
01696     //  fParseInProgress
01697     //      Used to prevent multiple entrance to the parser while its doing
01698     //      a parse.
01699     //
01700     //  fWithinElement
01701     //      A flag to indicate that the parser is within at least one level
01702     //      of element processing.
01703     //
01704     //  fDocumentType
01705     //      Used to store and update the documentType variable information
01706     //      in fDocument
01707     //
01708     //  fDocumentVector
01709     //      Store all the previous fDocument(s) (thus not the current fDocument)
01710     //      created in this parser.  It is destroyed when the parser is destructed.
01711     //
01712     //  fCreateCommentNodes
01713     //      Indicates whether comment nodes should be created.
01714     //
01715     //  fDocumentAdoptedByUser
01716     //      The DOMDocument ownership has been transferred to application
01717     //      If set to true, the parser does not own the document anymore
01718     //      and thus will not release its memory.
01719     //
01720     //  fInternalSubset
01721     //      Buffer for storing the internal subset information.
01722     //      Once complete (after DOCTYPE is finished scanning), send
01723     //      it to DocumentType Node
01724     //
01725     //   fGrammarPool
01726     //      The grammar pool passed from external application (through derivatives).
01727     //      which could be 0, not owned.
01728     //
01729     //  fCreateSchemaInfo
01730     //      Indicates whether element and attributes will have schema info associated
01731     //
01732     // -----------------------------------------------------------------------
01733     bool                          fCreateEntityReferenceNodes;
01734     bool                          fIncludeIgnorableWhitespace;
01735     bool                          fWithinElement;
01736     bool                          fParseInProgress;
01737     bool                          fCreateCommentNodes;
01738     bool                          fDocumentAdoptedByUser;
01739     bool                          fCreateSchemaInfo;
01740     XMLScanner*                   fScanner;
01741     XMLCh*                        fImplementationFeatures;
01742     DOMNode*                      fCurrentParent;
01743     DOMNode*                      fCurrentNode;
01744     DOMEntity*                    fCurrentEntity;
01745     DOMDocumentImpl*              fDocument;
01746     ValueStackOf<DOMNode*>*       fNodeStack;
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::getExpandEntityReferences() const
01765 {
01766     return !fCreateEntityReferenceNodes;
01767 }
01768 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
01769 {
01770     return fCreateEntityReferenceNodes;
01771 }
01772 
01773 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
01774 {
01775     return fIncludeIgnorableWhitespace;
01776 }
01777 
01778 inline bool AbstractDOMParser::getParseInProgress() const
01779 {
01780     return fParseInProgress;
01781 }
01782 
01783 inline XMLScanner* AbstractDOMParser::getScanner() const
01784 {
01785     return fScanner;
01786 }
01787 
01788 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
01789 {
01790     return fGrammarResolver;
01791 }
01792 
01793 inline bool AbstractDOMParser::getCreateCommentNodes() const
01794 {
01795     return fCreateCommentNodes;
01796 }
01797 
01798 inline PSVIHandler* AbstractDOMParser::getPSVIHandler()
01799 {
01800     return fPSVIHandler;
01801 }
01802 
01803 inline const PSVIHandler* AbstractDOMParser::getPSVIHandler() const
01804 {
01805     return fPSVIHandler;
01806 }
01807 
01808 inline bool AbstractDOMParser::getCreateSchemaInfo() const
01809 {
01810     return fCreateSchemaInfo;
01811 }
01812 // ---------------------------------------------------------------------------
01813 //  AbstractDOMParser: Setter methods
01814 // ---------------------------------------------------------------------------
01815 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
01816 {
01817     fCreateEntityReferenceNodes = !expand;
01818 }
01819 
01820 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
01821 {
01822     fCreateEntityReferenceNodes = create;
01823 }
01824 
01825 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
01826 {
01827     fIncludeIgnorableWhitespace = include;
01828 }
01829 
01830 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
01831 {
01832     fCreateCommentNodes = create;
01833 }
01834 
01835 inline void AbstractDOMParser::useImplementation(const XMLCh* const implementationFeatures)
01836 {
01837     fMemoryManager->deallocate(fImplementationFeatures); 
01838     fImplementationFeatures = XMLString::replicate(implementationFeatures, fMemoryManager); 
01839 }
01840 
01841 // ---------------------------------------------------------------------------
01842 //  AbstractDOMParser: Protected getter methods
01843 // ---------------------------------------------------------------------------
01844 inline DOMNode* AbstractDOMParser::getCurrentNode()
01845 {
01846     return fCurrentNode;
01847 }
01848 
01849 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
01850 {
01851     return fMemoryManager;
01852 }
01853 
01854 // ---------------------------------------------------------------------------
01855 //  AbstractDOMParser: Protected setter methods
01856 // ---------------------------------------------------------------------------
01857 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
01858 {
01859     fCurrentNode = toSet;
01860 }
01861 
01862 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
01863 {
01864     fParseInProgress = toSet;
01865 }
01866 
01867 XERCES_CPP_NAMESPACE_END
01868 
01869 #endif
01870 
01871 
01872 

Generated on Thu Feb 19 11:35:43 2009 for Xerces-C++ by  doxygen 1.5.4