http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AbstractDOMParser.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 2002, 2003 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 2001, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Id: AbstractDOMParser.hpp,v 1.26 2003/12/01 23:23:26 neilg Exp $
00059  *
00060  */
00061 #if !defined(ABSTRACTDOMPARSER_HPP)
00062 #define ABSTRACTDOMPARSER_HPP
00063 
00064 #include <xercesc/dom/DOMDocument.hpp>
00065 #include <xercesc/framework/XMLDocumentHandler.hpp>
00066 #include <xercesc/framework/XMLErrorReporter.hpp>
00067 #include <xercesc/framework/XMLEntityHandler.hpp>
00068 #include <xercesc/util/SecurityManager.hpp>
00069 #include <xercesc/util/ValueStackOf.hpp>
00070 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00071 #include <xercesc/dom/DOMDocumentType.hpp>
00072 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
00073 #include <xercesc/framework/XMLBufferMgr.hpp>
00074 
00075 XERCES_CPP_NAMESPACE_BEGIN
00076 
00077 class XMLPScanToken;
00078 class XMLScanner;
00079 class XMLValidator;
00080 class DOMDocumentImpl;
00081 class DOMDocumentTypeImpl;
00082 class DOMElement;
00083 class GrammarResolver;
00084 class XMLGrammarPool;
00085 class PSVIHandler;
00086 
00091 class  AbstractDOMParser :
00092 
00093     public XMemory
00094     , public XMLDocumentHandler
00095     , public XMLErrorReporter
00096     , public XMLEntityHandler
00097     , public DocTypeHandler
00098 {
00099 public :
00100     // -----------------------------------------------------------------------
00101     //  Class types
00102     // -----------------------------------------------------------------------
00105 
00113     enum ValSchemes
00114     {
00115         Val_Never
00116         , Val_Always
00117         , Val_Auto
00118     };
00120 
00121 
00122     // -----------------------------------------------------------------------
00123     //  Constructors and Detructor
00124     // -----------------------------------------------------------------------
00127 
00131     virtual ~AbstractDOMParser();
00132 
00134 
00135     // -----------------------------------------------------------------------
00136     //  Utility methods
00137     // -----------------------------------------------------------------------
00138 
00146     void reset();
00147 
00161     DOMDocument* adoptDocument();
00162 
00164 
00165 
00166     // -----------------------------------------------------------------------
00167     //  Getter methods
00168     // -----------------------------------------------------------------------
00169 
00172 
00184     DOMDocument* getDocument();
00185 
00193     const XMLValidator& getValidator() const;
00194 
00202     ValSchemes getValidationScheme() const;
00203 
00214     bool getDoSchema() const;
00215 
00226     bool getValidationSchemaFullChecking() const;
00227 
00239     int getErrorCount() const;
00240 
00251     bool getDoNamespaces() const;
00252 
00265     bool getExitOnFirstFatalError() const;
00266 
00277     bool getValidationConstraintFatal() const;
00278 
00288     bool  getCreateEntityReferenceNodes()const;
00289 
00300     bool getIncludeIgnorableWhitespace() const;
00301 
00321     XMLCh* getExternalSchemaLocation() const;
00322 
00342     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00343 
00359     SecurityManager* getSecurityManager() const;
00360 
00372     bool getLoadExternalDTD() const;
00373 
00382     bool  getCreateCommentNodes()const;
00383 
00395     bool getCalculateSrcOfs() const;
00396 
00407     bool getStandardUriConformant() const;
00408 
00415     PSVIHandler* getPSVIHandler();
00416 
00423     const PSVIHandler* getPSVIHandler() const;
00424 
00426 
00427 
00428     // -----------------------------------------------------------------------
00429     //  Setter methods
00430     // -----------------------------------------------------------------------
00431 
00434 
00449     void setDoNamespaces(const bool newState);
00450 
00467     void setExitOnFirstFatalError(const bool newState);
00468 
00488     void setValidationConstraintFatal(const bool newState);
00489 
00508     void setCreateEntityReferenceNodes(const bool create);
00509 
00531     void setIncludeIgnorableWhitespace(const bool include);
00532 
00549     void setValidationScheme(const ValSchemes newScheme);
00550 
00566     void setDoSchema(const bool newState);
00567 
00584     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00585 
00606     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00607 
00616     void setExternalSchemaLocation(const char* const schemaLocation);
00617 
00632     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00633 
00642     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00643 
00659     void setSecurityManager(SecurityManager* const securityManager);
00660 
00677     void setLoadExternalDTD(const bool newState);
00678 
00689     void setCreateCommentNodes(const bool create);
00690 
00703     void setCalculateSrcOfs(const bool newState);
00704 
00715     void setStandardUriConformant(const bool newState);
00716 
00724     void useScanner(const XMLCh* const scannerName);
00725 
00733     void useImplementation(const XMLCh* const implementationFeatures);
00734 
00743     virtual void setPSVIHandler(PSVIHandler* const handler);
00744 
00746 
00747 
00748     // -----------------------------------------------------------------------
00749     //  Parsing methods
00750     // -----------------------------------------------------------------------
00751 
00754 
00770     void parse(const InputSource& source);
00771 
00788     void parse(const XMLCh* const systemId);
00789 
00805     void parse(const char* const systemId);
00806 
00833     bool parseFirst
00834     (
00835         const   XMLCh* const    systemId
00836         ,       XMLPScanToken&  toFill
00837     );
00838 
00866     bool parseFirst
00867     (
00868         const   char* const     systemId
00869         ,       XMLPScanToken&  toFill
00870     );
00871 
00899     bool parseFirst
00900     (
00901         const   InputSource&    source
00902         ,       XMLPScanToken&  toFill
00903     );
00904 
00927     bool parseNext(XMLPScanToken& token);
00928 
00954     void parseReset(XMLPScanToken& token);
00955 
00957 
00958     // -----------------------------------------------------------------------
00959     //  Implementation of the XMLDocumentHandler interface.
00960     // -----------------------------------------------------------------------
00961 
00964 
00977     virtual void docCharacters
00978     (
00979         const   XMLCh* const    chars
00980         , const unsigned int    length
00981         , const bool            cdataSection
00982     );
00983 
00992     virtual void docComment
00993     (
00994         const   XMLCh* const    comment
00995     );
00996 
01009     virtual void docPI
01010     (
01011         const   XMLCh* const    target
01012         , const XMLCh* const    data
01013     );
01014 
01019     virtual void endDocument();
01020 
01037     virtual void endElement
01038     (
01039         const   XMLElementDecl& elemDecl
01040         , const unsigned int    urlId
01041         , const bool            isRoot
01042         , const XMLCh* const    elemPrefix
01043     );
01044 
01053     virtual void endEntityReference
01054     (
01055         const   XMLEntityDecl&  entDecl
01056     );
01057 
01076     virtual void ignorableWhitespace
01077     (
01078         const   XMLCh* const    chars
01079         , const unsigned int    length
01080         , const bool            cdataSection
01081     );
01082 
01089     virtual void resetDocument();
01090 
01095     virtual void startDocument();
01096 
01124     virtual void startElement
01125     (
01126         const   XMLElementDecl&         elemDecl
01127         , const unsigned int            urlId
01128         , const XMLCh* const            elemPrefix
01129         , const RefVectorOf<XMLAttr>&   attrList
01130         , const unsigned int            attrCount
01131         , const bool                    isEmpty
01132         , const bool                    isRoot
01133     );
01134 
01144     virtual void startEntityReference
01145     (
01146         const   XMLEntityDecl&  entDecl
01147     );
01148 
01167     virtual void XMLDecl
01168     (
01169         const   XMLCh* const    versionStr
01170         , const XMLCh* const    encodingStr
01171         , const XMLCh* const    standaloneStr
01172         , const XMLCh* const    actualEncStr
01173     );
01174 
01194     virtual void elementTypeInfo
01195     (
01196         const   XMLCh* const    typeName
01197         , const XMLCh* const    typeURI
01198     );
01200 
01201 
01202     // -----------------------------------------------------------------------
01203     //  Implementation of the deprecated DocTypeHandler interface.
01204     // -----------------------------------------------------------------------
01207     virtual void attDef
01208     (
01209         const   DTDElementDecl&     elemDecl
01210         , const DTDAttDef&          attDef
01211         , const bool                ignoring
01212     );
01213 
01214     virtual void doctypeComment
01215     (
01216         const   XMLCh* const    comment
01217     );
01218 
01219     virtual void doctypeDecl
01220     (
01221         const   DTDElementDecl& elemDecl
01222         , const XMLCh* const    publicId
01223         , const XMLCh* const    systemId
01224         , const bool            hasIntSubset
01225         , const bool            hasExtSubset = false
01226     );
01227 
01228     virtual void doctypePI
01229     (
01230         const   XMLCh* const    target
01231         , const XMLCh* const    data
01232     );
01233 
01234     virtual void doctypeWhitespace
01235     (
01236         const   XMLCh* const    chars
01237         , const unsigned int    length
01238     );
01239 
01240     virtual void elementDecl
01241     (
01242         const   DTDElementDecl& decl
01243         , const bool            isIgnored
01244     );
01245 
01246     virtual void endAttList
01247     (
01248         const   DTDElementDecl& elemDecl
01249     );
01250 
01251     virtual void endIntSubset();
01252 
01253     virtual void endExtSubset();
01254 
01255     virtual void entityDecl
01256     (
01257         const   DTDEntityDecl&  entityDecl
01258         , const bool            isPEDecl
01259         , const bool            isIgnored
01260     );
01261 
01262     virtual void resetDocType();
01263 
01264     virtual void notationDecl
01265     (
01266         const   XMLNotationDecl&    notDecl
01267         , const bool                isIgnored
01268     );
01269 
01270     virtual void startAttList
01271     (
01272         const   DTDElementDecl& elemDecl
01273     );
01274 
01275     virtual void startIntSubset();
01276 
01277     virtual void startExtSubset();
01278 
01279     virtual void TextDecl
01280     (
01281         const   XMLCh* const    versionStr
01282         , const XMLCh* const    encodingStr
01283     );
01284 
01285 
01287 
01288 
01289     // -----------------------------------------------------------------------
01290     //  Deprecated Methods
01291     // -----------------------------------------------------------------------
01304     bool getDoValidation() const;
01305 
01319     void setDoValidation(const bool newState);
01320 
01334     bool getExpandEntityReferences() const;
01335 
01352     void setExpandEntityReferences(const bool expand);
01353 
01355 
01356 protected :
01357     // -----------------------------------------------------------------------
01358     //  Protected Constructor Methods
01359     // -----------------------------------------------------------------------
01378     AbstractDOMParser
01379     (
01380           XMLValidator* const   valToAdopt = 0
01381         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01382         , XMLGrammarPool* const gramPool = 0
01383     );
01384 
01386 
01387     // -----------------------------------------------------------------------
01388     //  Protected getter methods
01389     // -----------------------------------------------------------------------
01397     DOMNode* getCurrentNode();
01398 
01403     XMLScanner* getScanner() const;
01404 
01409     GrammarResolver* getGrammarResolver() const;
01410 
01416     bool getParseInProgress() const;
01417 
01418     MemoryManager* getMemoryManager() const;
01419 
01421 
01422 
01423     // -----------------------------------------------------------------------
01424     //  Protected setter methods
01425     // -----------------------------------------------------------------------
01426 
01429 
01437     void setCurrentNode(DOMNode* toSet);
01438 
01445     void setDocument(DOMDocument* toSet);
01446 
01453     void setParseInProgress(const bool toSet);
01455 
01456     // -----------------------------------------------------------------------
01457     //  Protected Helper methods
01458     // -----------------------------------------------------------------------
01461     virtual DOMElement* createElementNSNode(const XMLCh *fNamespaceURI,
01462                                               const XMLCh *qualifiedName);
01463 
01464     void resetPool();
01465 
01469     bool isDocumentAdopted() const;
01470 
01472 
01473 
01474 private :
01475     // -----------------------------------------------------------------------
01476     //  Initialize/Cleanup methods
01477     // -----------------------------------------------------------------------
01478     void initialize();
01479     void cleanUp();
01480 
01481 protected:
01482     // -----------------------------------------------------------------------
01483     //  Protected data members
01484     //
01485     //  fCurrentNode
01486     //  fCurrentParent
01487     //      Used to track the current node during nested element events. Since
01488     //      the tree must be built from a set of disjoint callbacks, we need
01489     //      these to keep up with where we currently are.
01490     //
01491     //  fCurrentEntity
01492     //      Used to track the current entity decl.  If a text decl is seen later on,
01493     //      it is used to update the encoding and version information.
01494     //
01495     //  fDocument
01496     //      The root document object, filled with the document contents.
01497     //
01498     //  fCreateEntityReferenceNodes
01499     //      Indicates whether entity reference nodes should be created.
01500     //
01501     //  fIncludeIgnorableWhitespace
01502     //      Indicates whether ignorable whiltespace should be added to
01503     //      the DOM tree for validating parsers.
01504     //
01505     //  fScanner
01506     //      The scanner used for this parser. This is created during the
01507     //      constructor.
01508     //
01509     //  fImplementationFeatures
01510     //      The implementation features that we use to get an implementation
01511     //      for use in creating the DOMDocument used during parse. If this is
01512     //      null then the default DOMImplementation is used
01513     //
01514     //  fNodeStack
01515     //      Used to track previous parent nodes during nested element events.
01516     //
01517     //  fParseInProgress
01518     //      Used to prevent multiple entrance to the parser while its doing
01519     //      a parse.
01520     //
01521     //  fWithinElement
01522     //      A flag to indicate that the parser is within at least one level
01523     //      of element processing.
01524     //
01525     //  fDocumentType
01526     //      Used to store and update the documentType variable information
01527     //      in fDocument
01528     //
01529     //  fDocumentVector
01530     //      Store all the previous fDocument(s) (thus not the current fDocument)
01531     //      created in this parser.  It is destroyed when the parser is destructed.
01532     //
01533     //  fCreateCommentNodes
01534     //      Indicates whether comment nodes should be created.
01535     //
01536     //  fDocumentAdoptedByUser
01537     //      The DOMDocument ownership has been transferred to application
01538     //      If set to true, the parser does not own the document anymore
01539     //      and thus will not release its memory.
01540     //
01541     //  fInternalSubset
01542     //      Buffer for storing the internal subset information.
01543     //      Once complete (after DOCTYPE is finished scanning), send
01544     //      it to DocumentType Node
01545     //
01546     //   fGrammarPool
01547     //      The grammar pool passed from external application (through derivatives).
01548     //      which could be 0, not owned.
01549     //
01550     // -----------------------------------------------------------------------
01551     bool                          fCreateEntityReferenceNodes;
01552     bool                          fIncludeIgnorableWhitespace;
01553     bool                          fWithinElement;
01554     bool                          fParseInProgress;
01555     bool                          fCreateCommentNodes;
01556     bool                          fDocumentAdoptedByUser;
01557     XMLScanner*                   fScanner;
01558     XMLCh*                        fImplementationFeatures;
01559     DOMNode*                      fCurrentParent;
01560     DOMNode*                      fCurrentNode;
01561     DOMEntity*                    fCurrentEntity;
01562     DOMDocumentImpl*              fDocument;
01563     ValueStackOf<DOMNode*>*       fNodeStack;
01564     DOMDocumentTypeImpl*          fDocumentType;
01565     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
01566     GrammarResolver*              fGrammarResolver;
01567     XMLStringPool*                fURIStringPool;
01568     XMLValidator*                 fValidator;
01569     MemoryManager*                fMemoryManager;
01570     XMLGrammarPool*               fGrammarPool;
01571     XMLBufferMgr                  fBufMgr;
01572     XMLBuffer&                    fInternalSubset;
01573     PSVIHandler*                  fPSVIHandler;
01574 };
01575 
01576 
01577 
01578 // ---------------------------------------------------------------------------
01579 //  AbstractDOMParser: Getter methods
01580 // ---------------------------------------------------------------------------
01581 inline bool AbstractDOMParser::getExpandEntityReferences() const
01582 {
01583     return !fCreateEntityReferenceNodes;
01584 }
01585 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
01586 {
01587     return fCreateEntityReferenceNodes;
01588 }
01589 
01590 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
01591 {
01592     return fIncludeIgnorableWhitespace;
01593 }
01594 
01595 inline bool AbstractDOMParser::getParseInProgress() const
01596 {
01597     return fParseInProgress;
01598 }
01599 
01600 inline XMLScanner* AbstractDOMParser::getScanner() const
01601 {
01602     return fScanner;
01603 }
01604 
01605 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
01606 {
01607     return fGrammarResolver;
01608 }
01609 
01610 inline bool AbstractDOMParser::getCreateCommentNodes() const
01611 {
01612     return fCreateCommentNodes;
01613 }
01614 
01615 inline PSVIHandler* AbstractDOMParser::getPSVIHandler()
01616 {
01617     return fPSVIHandler;
01618 }
01619 
01620 inline const PSVIHandler* AbstractDOMParser::getPSVIHandler() const
01621 {
01622     return fPSVIHandler;
01623 }
01624 // ---------------------------------------------------------------------------
01625 //  AbstractDOMParser: Setter methods
01626 // ---------------------------------------------------------------------------
01627 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
01628 {
01629     fCreateEntityReferenceNodes = !expand;
01630 }
01631 
01632 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
01633 {
01634     fCreateEntityReferenceNodes = create;
01635 }
01636 
01637 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
01638 {
01639     fIncludeIgnorableWhitespace = include;
01640 }
01641 
01642 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
01643 {
01644     fCreateCommentNodes = create;
01645 }
01646 
01647 inline void AbstractDOMParser::useImplementation(const XMLCh* const implementationFeatures)
01648 {
01649     fMemoryManager->deallocate(fImplementationFeatures); 
01650     fImplementationFeatures = XMLString::replicate(implementationFeatures, fMemoryManager); 
01651 }
01652 
01653 // ---------------------------------------------------------------------------
01654 //  AbstractDOMParser: Protected getter methods
01655 // ---------------------------------------------------------------------------
01656 inline DOMNode* AbstractDOMParser::getCurrentNode()
01657 {
01658     return fCurrentNode;
01659 }
01660 
01661 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
01662 {
01663     return fMemoryManager;
01664 }
01665 
01666 // ---------------------------------------------------------------------------
01667 //  AbstractDOMParser: Protected setter methods
01668 // ---------------------------------------------------------------------------
01669 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
01670 {
01671     fCurrentNode = toSet;
01672 }
01673 
01674 inline void AbstractDOMParser::setDocument(DOMDocument* toSet)
01675 {
01676     fDocument = (DOMDocumentImpl *)toSet;
01677 }
01678 
01679 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
01680 {
01681     fParseInProgress = toSet;
01682 }
01683 
01684 XERCES_CPP_NAMESPACE_END
01685 
01686 #endif
01687 
01688 
01689 


Copyright © 2003 The Apache Software Foundation. All Rights Reserved.