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.27 2004/01/29 11:46:32 cargilld 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     // -----------------------------------------------------------------------
01482     //  Unimplemented constructors and operators
01483     // -----------------------------------------------------------------------
01484     AbstractDOMParser(const AbstractDOMParser&);
01485     AbstractDOMParser& operator=(const AbstractDOMParser&);
01486 
01487 protected:
01488     // -----------------------------------------------------------------------
01489     //  Protected data members
01490     //
01491     //  fCurrentNode
01492     //  fCurrentParent
01493     //      Used to track the current node during nested element events. Since
01494     //      the tree must be built from a set of disjoint callbacks, we need
01495     //      these to keep up with where we currently are.
01496     //
01497     //  fCurrentEntity
01498     //      Used to track the current entity decl.  If a text decl is seen later on,
01499     //      it is used to update the encoding and version information.
01500     //
01501     //  fDocument
01502     //      The root document object, filled with the document contents.
01503     //
01504     //  fCreateEntityReferenceNodes
01505     //      Indicates whether entity reference nodes should be created.
01506     //
01507     //  fIncludeIgnorableWhitespace
01508     //      Indicates whether ignorable whiltespace should be added to
01509     //      the DOM tree for validating parsers.
01510     //
01511     //  fScanner
01512     //      The scanner used for this parser. This is created during the
01513     //      constructor.
01514     //
01515     //  fImplementationFeatures
01516     //      The implementation features that we use to get an implementation
01517     //      for use in creating the DOMDocument used during parse. If this is
01518     //      null then the default DOMImplementation is used
01519     //
01520     //  fNodeStack
01521     //      Used to track previous parent nodes during nested element events.
01522     //
01523     //  fParseInProgress
01524     //      Used to prevent multiple entrance to the parser while its doing
01525     //      a parse.
01526     //
01527     //  fWithinElement
01528     //      A flag to indicate that the parser is within at least one level
01529     //      of element processing.
01530     //
01531     //  fDocumentType
01532     //      Used to store and update the documentType variable information
01533     //      in fDocument
01534     //
01535     //  fDocumentVector
01536     //      Store all the previous fDocument(s) (thus not the current fDocument)
01537     //      created in this parser.  It is destroyed when the parser is destructed.
01538     //
01539     //  fCreateCommentNodes
01540     //      Indicates whether comment nodes should be created.
01541     //
01542     //  fDocumentAdoptedByUser
01543     //      The DOMDocument ownership has been transferred to application
01544     //      If set to true, the parser does not own the document anymore
01545     //      and thus will not release its memory.
01546     //
01547     //  fInternalSubset
01548     //      Buffer for storing the internal subset information.
01549     //      Once complete (after DOCTYPE is finished scanning), send
01550     //      it to DocumentType Node
01551     //
01552     //   fGrammarPool
01553     //      The grammar pool passed from external application (through derivatives).
01554     //      which could be 0, not owned.
01555     //
01556     // -----------------------------------------------------------------------
01557     bool                          fCreateEntityReferenceNodes;
01558     bool                          fIncludeIgnorableWhitespace;
01559     bool                          fWithinElement;
01560     bool                          fParseInProgress;
01561     bool                          fCreateCommentNodes;
01562     bool                          fDocumentAdoptedByUser;
01563     XMLScanner*                   fScanner;
01564     XMLCh*                        fImplementationFeatures;
01565     DOMNode*                      fCurrentParent;
01566     DOMNode*                      fCurrentNode;
01567     DOMEntity*                    fCurrentEntity;
01568     DOMDocumentImpl*              fDocument;
01569     ValueStackOf<DOMNode*>*       fNodeStack;
01570     DOMDocumentTypeImpl*          fDocumentType;
01571     RefVectorOf<DOMDocumentImpl>* fDocumentVector;
01572     GrammarResolver*              fGrammarResolver;
01573     XMLStringPool*                fURIStringPool;
01574     XMLValidator*                 fValidator;
01575     MemoryManager*                fMemoryManager;
01576     XMLGrammarPool*               fGrammarPool;
01577     XMLBufferMgr                  fBufMgr;
01578     XMLBuffer&                    fInternalSubset;
01579     PSVIHandler*                  fPSVIHandler;
01580 };
01581 
01582 
01583 
01584 // ---------------------------------------------------------------------------
01585 //  AbstractDOMParser: Getter methods
01586 // ---------------------------------------------------------------------------
01587 inline bool AbstractDOMParser::getExpandEntityReferences() const
01588 {
01589     return !fCreateEntityReferenceNodes;
01590 }
01591 inline bool AbstractDOMParser::getCreateEntityReferenceNodes() const
01592 {
01593     return fCreateEntityReferenceNodes;
01594 }
01595 
01596 inline bool AbstractDOMParser::getIncludeIgnorableWhitespace() const
01597 {
01598     return fIncludeIgnorableWhitespace;
01599 }
01600 
01601 inline bool AbstractDOMParser::getParseInProgress() const
01602 {
01603     return fParseInProgress;
01604 }
01605 
01606 inline XMLScanner* AbstractDOMParser::getScanner() const
01607 {
01608     return fScanner;
01609 }
01610 
01611 inline GrammarResolver* AbstractDOMParser::getGrammarResolver() const
01612 {
01613     return fGrammarResolver;
01614 }
01615 
01616 inline bool AbstractDOMParser::getCreateCommentNodes() const
01617 {
01618     return fCreateCommentNodes;
01619 }
01620 
01621 inline PSVIHandler* AbstractDOMParser::getPSVIHandler()
01622 {
01623     return fPSVIHandler;
01624 }
01625 
01626 inline const PSVIHandler* AbstractDOMParser::getPSVIHandler() const
01627 {
01628     return fPSVIHandler;
01629 }
01630 // ---------------------------------------------------------------------------
01631 //  AbstractDOMParser: Setter methods
01632 // ---------------------------------------------------------------------------
01633 inline void AbstractDOMParser::setExpandEntityReferences(const bool expand)
01634 {
01635     fCreateEntityReferenceNodes = !expand;
01636 }
01637 
01638 inline void AbstractDOMParser::setCreateEntityReferenceNodes(const bool create)
01639 {
01640     fCreateEntityReferenceNodes = create;
01641 }
01642 
01643 inline void AbstractDOMParser::setIncludeIgnorableWhitespace(const bool include)
01644 {
01645     fIncludeIgnorableWhitespace = include;
01646 }
01647 
01648 inline void AbstractDOMParser::setCreateCommentNodes(const bool create)
01649 {
01650     fCreateCommentNodes = create;
01651 }
01652 
01653 inline void AbstractDOMParser::useImplementation(const XMLCh* const implementationFeatures)
01654 {
01655     fMemoryManager->deallocate(fImplementationFeatures); 
01656     fImplementationFeatures = XMLString::replicate(implementationFeatures, fMemoryManager); 
01657 }
01658 
01659 // ---------------------------------------------------------------------------
01660 //  AbstractDOMParser: Protected getter methods
01661 // ---------------------------------------------------------------------------
01662 inline DOMNode* AbstractDOMParser::getCurrentNode()
01663 {
01664     return fCurrentNode;
01665 }
01666 
01667 inline MemoryManager* AbstractDOMParser::getMemoryManager() const
01668 {
01669     return fMemoryManager;
01670 }
01671 
01672 // ---------------------------------------------------------------------------
01673 //  AbstractDOMParser: Protected setter methods
01674 // ---------------------------------------------------------------------------
01675 inline void AbstractDOMParser::setCurrentNode(DOMNode* toSet)
01676 {
01677     fCurrentNode = toSet;
01678 }
01679 
01680 inline void AbstractDOMParser::setDocument(DOMDocument* toSet)
01681 {
01682     fDocument = (DOMDocumentImpl *)toSet;
01683 }
01684 
01685 inline void AbstractDOMParser::setParseInProgress(const bool toSet)
01686 {
01687     fParseInProgress = toSet;
01688 }
01689 
01690 XERCES_CPP_NAMESPACE_END
01691 
01692 #endif
01693 
01694 
01695 


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