Main Page   Class Hierarchy   Compound List   File List   Compound Members  

DOMParser.hpp

00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2001 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) 1999, 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: DOMParser.hpp,v 1.1 2002/05/11 20:20:50 bhavani Exp $
00059  *
00060  */
00061 
00062 #if !defined(DOMPARSER_HPP)
00063 #define DOMPARSER_HPP
00064 
00065 
00066 #include <xercesc/dom/DOM_Document.hpp>
00067 #include <xercesc/framework/XMLDocumentHandler.hpp>
00068 #include <xercesc/framework/XMLErrorReporter.hpp>
00069 #include <xercesc/framework/XMLEntityHandler.hpp>
00070 #include <xercesc/util/ValueStackOf.hpp>
00071 
00072 #include <xercesc/validators/DTD/DocTypeHandler.hpp>
00073 #include <xercesc/dom/DOM_DocumentType.hpp>
00074 #include <xercesc/validators/DTD/DTDElementDecl.hpp>
00075 
00076 class EntityResolver;
00077 class ErrorHandler;
00078 class XMLPScanToken;
00079 class XMLScanner;
00080 class XMLValidator;
00081 
00082 
00093 class PARSERS_EXPORT DOMParser :
00094 
00095     public XMLDocumentHandler
00096     , public XMLErrorReporter
00097     , public XMLEntityHandler
00098     , public DocTypeHandler
00099 {
00100 public :
00101     // -----------------------------------------------------------------------
00102     //  Class types
00103     // -----------------------------------------------------------------------
00104     enum ValSchemes
00105     {
00106         Val_Never
00107         , Val_Always
00108         , Val_Auto
00109     };
00110 
00111 
00112     // -----------------------------------------------------------------------
00113     //  Constructors and Detructor
00114     // -----------------------------------------------------------------------
00115 
00127     DOMParser(XMLValidator* const valToAdopt = 0);
00128 
00132     ~DOMParser();
00133 
00135 
00141     void reset();
00142 
00143 
00144     // -----------------------------------------------------------------------
00145     //  Getter methods
00146     // -----------------------------------------------------------------------
00147 
00150 
00160     DOM_Document getDocument();
00161 
00169     ErrorHandler* getErrorHandler();
00170 
00178     const ErrorHandler* getErrorHandler() const;
00179 
00187     EntityResolver* getEntityResolver();
00188 
00196     const EntityResolver* getEntityResolver() const;
00197 
00205     const XMLScanner& getScanner() const;
00206 
00214     const XMLValidator& getValidator() const;
00215 
00223     ValSchemes getValidationScheme() const;
00224 
00235     bool getDoSchema() const;
00236 
00247     bool getValidationSchemaFullChecking() const;
00248 
00260     int getErrorCount() const;
00261 
00272     bool getDoNamespaces() const;
00273 
00286     bool getExitOnFirstFatalError() const;
00287 
00298     bool getValidationConstraintFatal() const;
00299 
00317     bool  getCreateEntityReferenceNodes()const;
00318 
00329     bool getIncludeIgnorableWhitespace() const;
00330 
00340     bool getToCreateXMLDeclTypeNode() const;
00341 
00361     XMLCh* getExternalSchemaLocation() const;
00362 
00382     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00383 
00393     bool getURLEntityCaching() const;
00394 
00404     XMLCh* getURLEntityCacheDir() const;
00405 
00407 
00408 
00409     // -----------------------------------------------------------------------
00410     //  Setter methods
00411     // -----------------------------------------------------------------------
00412 
00415 
00429     void setErrorHandler(ErrorHandler* const handler);
00430 
00446     void setEntityResolver(EntityResolver* const handler);
00447 
00466     void setDoNamespaces(const bool newState);
00467 
00484     void setExitOnFirstFatalError(const bool newState);
00485 
00501     void setValidationConstraintFatal(const bool newState);
00502 
00519     void setCreateEntityReferenceNodes(const bool create);
00520 
00542     void setIncludeIgnorableWhitespace(const bool include);
00543 
00560     void setValidationScheme(const ValSchemes newScheme);
00561 
00575     void setDoSchema(const bool newState);
00576 
00593     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00594 
00605     void setToCreateXMLDeclTypeNode(const bool create);
00606 
00627     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00628 
00637     void setExternalSchemaLocation(const char* const schemaLocation);
00638 
00653     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00654 
00663     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00664 
00679     void setURLEntityCaching(const bool useCache);
00680 
00696     void setURLEntityCacheDir(const XMLCh* const cachedir);
00697 
00707     void setURLEntityCacheDir(const char* const cachedir);
00708 
00710 
00711 
00712     // -----------------------------------------------------------------------
00713     //  Parsing methods
00714     // -----------------------------------------------------------------------
00715 
00718 
00739     void parse(const InputSource& source, const bool reuseGrammar = false);
00740 
00760     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00761 
00779     void parse(const char* const systemId, const bool reuseGrammar = false);
00780 
00810     bool parseFirst
00811     (
00812         const   XMLCh* const    systemId
00813         ,       XMLPScanToken&  toFill
00814         , const bool            reuseGrammar = false
00815     );
00816 
00847     bool parseFirst
00848     (
00849         const   char* const     systemId
00850         ,       XMLPScanToken&  toFill
00851         , const bool            reuseGrammar = false
00852     );
00853 
00884     bool parseFirst
00885     (
00886         const   InputSource&    source
00887         ,       XMLPScanToken&  toFill
00888         , const bool            reuseGrammar = false
00889     );
00890 
00913     bool parseNext(XMLPScanToken& token);
00914 
00940     void parseReset(XMLPScanToken& token);
00941 
00943 
00944 
00945 
00946     // -----------------------------------------------------------------------
00947     //  Implementation of the XMLErrorReporter interface.
00948     // -----------------------------------------------------------------------
00949 
00952 
00977     virtual void error
00978     (
00979         const   unsigned int                errCode
00980         , const XMLCh* const                msgDomain
00981         , const XMLErrorReporter::ErrTypes  errType
00982         , const XMLCh* const                errorText
00983         , const XMLCh* const                systemId
00984         , const XMLCh* const                publicId
00985         , const unsigned int                lineNum
00986         , const unsigned int                colNum
00987     );
00988 
00997     virtual void resetErrors();
00999 
01000 
01001     // -----------------------------------------------------------------------
01002     //  Implementation of the XMLEntityHandler interface.
01003     // -----------------------------------------------------------------------
01004 
01007 
01020     virtual void endInputSource(const InputSource& inputSource);
01021 
01037     virtual bool expandSystemId
01038     (
01039         const   XMLCh* const    systemId
01040         ,       XMLBuffer&      toFill
01041     );
01042 
01051     virtual void resetEntities();
01052 
01068     virtual InputSource* resolveEntity
01069     (
01070         const   XMLCh* const    publicId
01071         , const XMLCh* const    systemId
01072     );
01073 
01086     virtual void startInputSource(const InputSource& inputSource);
01087 
01089 
01090 
01091 
01092     // -----------------------------------------------------------------------
01093     //  Implementation of the XMLDocumentHandler interface.
01094     // -----------------------------------------------------------------------
01095 
01098 
01111     virtual void docCharacters
01112     (
01113         const   XMLCh* const    chars
01114         , const unsigned int    length
01115         , const bool            cdataSection
01116     );
01117 
01126     virtual void docComment
01127     (
01128         const   XMLCh* const    comment
01129     );
01130 
01143     virtual void docPI
01144     (
01145         const   XMLCh* const    target
01146         , const XMLCh* const    data
01147     );
01148 
01153     virtual void endDocument();
01154 
01168     virtual void endElement
01169     (
01170         const   XMLElementDecl& elemDecl
01171         , const unsigned int    urlId
01172         , const bool            isRoot
01173     );
01174 
01183     virtual void endEntityReference
01184     (
01185         const   XMLEntityDecl&  entDecl
01186     );
01187 
01206     virtual void ignorableWhitespace
01207     (
01208         const   XMLCh* const    chars
01209         , const unsigned int    length
01210         , const bool            cdataSection
01211     );
01212 
01219     virtual void resetDocument();
01220 
01225     virtual void startDocument();
01226 
01254     virtual void startElement
01255     (
01256         const   XMLElementDecl&         elemDecl
01257         , const unsigned int            urlId
01258         , const XMLCh* const            elemPrefix
01259         , const RefVectorOf<XMLAttr>&   attrList
01260         , const unsigned int            attrCount
01261         , const bool                    isEmpty
01262         , const bool                    isRoot
01263     );
01264 
01274     virtual void startEntityReference
01275     (
01276         const   XMLEntityDecl&  entDecl
01277     );
01278 
01297     virtual void XMLDecl
01298     (
01299         const   XMLCh* const    versionStr
01300         , const XMLCh* const    encodingStr
01301         , const XMLCh* const    standaloneStr
01302         , const XMLCh* const    actualEncStr
01303     );
01305 
01306 
01323     void setExpandEntityReferences(const bool expand);
01324 
01336     bool getExpandEntityReferences() const;
01337 
01351     bool getDoValidation() const;
01352 
01369     void setDoValidation(const bool newState);
01370 
01374         virtual void attDef
01375     (
01376         const   DTDElementDecl&     elemDecl
01377         , const DTDAttDef&          attDef
01378         , const bool                ignoring
01379     );
01380 
01381     virtual void doctypeComment
01382     (
01383         const   XMLCh* const    comment
01384     );
01385 
01386     virtual void doctypeDecl
01387     (
01388         const   DTDElementDecl& elemDecl
01389         , const XMLCh* const    publicId
01390         , const XMLCh* const    systemId
01391         , const bool            hasIntSubset
01392     );
01393 
01394     virtual void doctypePI
01395     (
01396         const   XMLCh* const    target
01397         , const XMLCh* const    data
01398     );
01399 
01400     virtual void doctypeWhitespace
01401     (
01402         const   XMLCh* const    chars
01403         , const unsigned int    length
01404     );
01405 
01406     virtual void elementDecl
01407     (
01408         const   DTDElementDecl& decl
01409         , const bool            isIgnored
01410     );
01411 
01412     virtual void endAttList
01413     (
01414         const   DTDElementDecl& elemDecl
01415     );
01416 
01417     virtual void endIntSubset();
01418 
01419     virtual void endExtSubset();
01420 
01421     virtual void entityDecl
01422     (
01423         const   DTDEntityDecl&  entityDecl
01424         , const bool            isPEDecl
01425         , const bool            isIgnored
01426     );
01427 
01428     virtual void resetDocType();
01429 
01430     virtual void notationDecl
01431     (
01432         const   XMLNotationDecl&    notDecl
01433         , const bool                isIgnored
01434     );
01435 
01436     virtual void startAttList
01437     (
01438         const   DTDElementDecl& elemDecl
01439     );
01440 
01441     virtual void startIntSubset();
01442 
01443     virtual void startExtSubset();
01444 
01445     virtual void TextDecl
01446     (
01447         const   XMLCh* const    versionStr
01448         , const XMLCh* const    encodingStr
01449     );
01450 
01451 
01453 
01454 
01455 protected :
01456     // -----------------------------------------------------------------------
01457     //  Protected getter methods
01458     // -----------------------------------------------------------------------
01459 
01467     DOM_Node getCurrentNode();
01468 
01470 
01471 
01472     // -----------------------------------------------------------------------
01473     //  Protected setter methods
01474     // -----------------------------------------------------------------------
01475 
01478 
01486     void setCurrentNode(DOM_Node toSet);
01487 
01494     void setDocument(DOM_Document toSet);
01496 
01497 
01498 private :
01499     // -----------------------------------------------------------------------
01500     //  Private data members
01501     //
01502     //  fCurrentNode
01503     //  fCurrentParent
01504     //      Used to track the current node during nested element events. Since
01505     //      the tree must be built from a set of disjoint callbacks, we need
01506     //      these to keep up with where we currently are.
01507     //
01508     //  fDocument
01509     //      The root document object, filled with the document contents.
01510     //
01511     //  fEntityResolver
01512     //      The installed SAX entity resolver, if any. Null if none.
01513     //
01514     //  fErrorHandler
01515     //      The installed SAX error handler, if any. Null if none.
01516     //
01517     //  fCreateEntityReferenceNode
01518     //      Indicates whether entity reference nodes should be created.
01519     //
01520     //  fIncludeIgnorableWhitespace
01521     //      Indicates whether ignorable whiltespace should be added to
01522     //      the DOM tree for validating parsers.
01523     //
01524     //  fNodeStack
01525     //      Used to track previous parent nodes during nested element events.
01526     //
01527     //  fParseInProgress
01528     //      Used to prevent multiple entrance to the parser while its doing
01529     //      a parse.
01530     //
01531     //  fScanner
01532     //      The scanner used for this parser. This is created during the
01533     //      constructor.
01534     //
01535     //  fWithinElement
01536     //      A flag to indicate that the parser is within at least one level
01537     //      of element processing.
01538     //
01539     //  fDocumentType
01540     //      Used to store and update the documentType variable information
01541     //      in fDocument
01542     //
01543     //  fToCreateXMLDecTypeNode
01544     //      A flag to create a DOM_XMLDecl node in the ODM tree if it exists
01545     //      This is an extension to xerces implementation
01546     //
01547     // -----------------------------------------------------------------------
01548     DOM_Node                fCurrentParent;
01549     DOM_Node                fCurrentNode;
01550     DOM_Document            fDocument;
01551     EntityResolver*         fEntityResolver;
01552     ErrorHandler*           fErrorHandler;
01553     bool                    fCreateEntityReferenceNodes;
01554     bool                    fIncludeIgnorableWhitespace;
01555     ValueStackOf<DOM_Node>* fNodeStack;
01556     bool                    fParseInProgress;
01557     XMLScanner*             fScanner;
01558     bool                    fWithinElement;
01559     DocumentTypeImpl*       fDocumentType;
01560     bool                    fToCreateXMLDeclTypeNode;
01561 };
01562 
01563 
01564 
01565 // ---------------------------------------------------------------------------
01566 //  DOMParser: Handlers for the XMLEntityHandler interface
01567 // ---------------------------------------------------------------------------
01568 inline void DOMParser::endInputSource(const InputSource&)
01569 {
01570     // The DOM entity resolver doesn't handle this
01571 }
01572 
01573 inline bool DOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01574 {
01575     // The DOM entity resolver doesn't handle this
01576     return false;
01577 }
01578 
01579 inline void DOMParser::resetEntities()
01580 {
01581     // Nothing to do on this one
01582 }
01583 
01584 inline void DOMParser::startInputSource(const InputSource&)
01585 {
01586     // The DOM entity resolver doesn't handle this
01587 }
01588 
01589 
01590 // ---------------------------------------------------------------------------
01591 //  DOMParser: Getter methods
01592 // ---------------------------------------------------------------------------
01593 inline DOM_Document DOMParser::getDocument()
01594 {
01595     return fDocument;
01596 }
01597 
01598 inline ErrorHandler* DOMParser::getErrorHandler()
01599 {
01600     return fErrorHandler;
01601 }
01602 
01603 inline const ErrorHandler* DOMParser::getErrorHandler() const
01604 {
01605     return fErrorHandler;
01606 }
01607 
01608 inline EntityResolver* DOMParser::getEntityResolver()
01609 {
01610     return fEntityResolver;
01611 }
01612 
01613 inline const EntityResolver* DOMParser::getEntityResolver() const
01614 {
01615     return fEntityResolver;
01616 }
01617 
01618 inline bool DOMParser::getExpandEntityReferences() const
01619 {
01620     return fCreateEntityReferenceNodes;
01621 }
01622 inline bool DOMParser::getCreateEntityReferenceNodes() const
01623 {
01624     return fCreateEntityReferenceNodes;
01625 }
01626 
01627 inline bool DOMParser::getIncludeIgnorableWhitespace() const
01628 {
01629     return fIncludeIgnorableWhitespace;
01630 }
01631 
01632 inline const XMLScanner& DOMParser::getScanner() const
01633 {
01634     return *fScanner;
01635 }
01636 
01637 inline bool DOMParser::getToCreateXMLDeclTypeNode() const
01638 {
01639     return fToCreateXMLDeclTypeNode;
01640 }
01641 
01642 
01643 // ---------------------------------------------------------------------------
01644 //  DOMParser: Setter methods
01645 // ---------------------------------------------------------------------------
01646 inline void DOMParser::setExpandEntityReferences(const bool expand)
01647 {
01648     fCreateEntityReferenceNodes = expand;
01649 }
01650 
01651 inline void DOMParser::setCreateEntityReferenceNodes(const bool create)
01652 {
01653     fCreateEntityReferenceNodes = create;
01654 }
01655 
01656 inline void DOMParser::setIncludeIgnorableWhitespace(const bool include)
01657 {
01658     fIncludeIgnorableWhitespace = include;
01659 }
01660 
01661 inline void DOMParser::setToCreateXMLDeclTypeNode(const bool create)
01662 {
01663     fToCreateXMLDeclTypeNode = create;
01664 }
01665 
01666 
01667 // ---------------------------------------------------------------------------
01668 //  DOMParser: Protected getter methods
01669 // ---------------------------------------------------------------------------
01670 inline DOM_Node DOMParser::getCurrentNode()
01671 {
01672     return fCurrentNode;
01673 }
01674 
01675 
01676 // ---------------------------------------------------------------------------
01677 //  DOMParser: Protected setter methods
01678 // ---------------------------------------------------------------------------
01679 inline void DOMParser::setCurrentNode(DOM_Node toSet)
01680 {
01681     fCurrentNode = toSet;
01682 }
01683 
01684 inline void DOMParser::setDocument(DOM_Document toSet)
01685 {
01686     fDocument = toSet;
01687 }
01688 
01689 #endif

Generated on Tue Nov 19 09:36:28 2002 by doxygen1.3-rc1