Main Page   Class Hierarchy   Compound List   File List   Compound Members  

IDOMParser.hpp

00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 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) 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: IDOMParser.hpp,v 1.1 2002/05/11 20:21:07 bhavani Exp $
00059  *
00060  */
00061 
00062 #if !defined(IDOMPARSER_HPP)
00063 #define IDOMPARSER_HPP
00064 
00065 
00066 #include <xercesc/idom/IDOM_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/idom/IDOM_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 class IDDocumentImpl;
00082 class IDDocumentTypeImpl;
00083 
00084 
00095 class PARSERS_EXPORT IDOMParser :
00096 
00097     public XMLDocumentHandler
00098     , public XMLErrorReporter
00099     , public XMLEntityHandler
00100     , public DocTypeHandler
00101 {
00102 public :
00103     // -----------------------------------------------------------------------
00104     //  Class types
00105     // -----------------------------------------------------------------------
00106     enum ValSchemes
00107     {
00108         Val_Never
00109         , Val_Always
00110         , Val_Auto
00111     };
00112 
00113 
00114     // -----------------------------------------------------------------------
00115     //  Constructors and Detructor
00116     // -----------------------------------------------------------------------
00117 
00129     IDOMParser(XMLValidator* const valToAdopt = 0);
00130 
00134     ~IDOMParser();
00135 
00137 
00143     void reset();
00144 
00168     void resetDocumentPool();
00169 
00170 
00171     // -----------------------------------------------------------------------
00172     //  Getter methods
00173     // -----------------------------------------------------------------------
00174 
00177 
00187     IDOM_Document* getDocument();
00188 
00196     ErrorHandler* getErrorHandler();
00197 
00205     const ErrorHandler* getErrorHandler() const;
00206 
00214     EntityResolver* getEntityResolver();
00215 
00223     const EntityResolver* getEntityResolver() const;
00224 
00232     const XMLValidator& getValidator() const;
00233 
00241     ValSchemes getValidationScheme() const;
00242 
00253     bool getDoSchema() const;
00254 
00265     bool getValidationSchemaFullChecking() const;
00266 
00278     int getErrorCount() const;
00279 
00290     bool getDoNamespaces() const;
00291 
00304     bool getExitOnFirstFatalError() const;
00305 
00316     bool getValidationConstraintFatal() const;
00317 
00329     bool getExpandEntityReferences() const;
00330 
00348     bool  getCreateEntityReferenceNodes()const;
00349 
00360     bool getIncludeIgnorableWhitespace() const;
00361 
00381     XMLCh* getExternalSchemaLocation() const;
00382 
00402     XMLCh* getExternalNoNamespaceSchemaLocation() const;
00403 
00413     bool getURLEntityCaching() const;
00414 
00424     XMLCh* getURLEntityCacheDir() const;
00425 
00427 
00428 
00429     // -----------------------------------------------------------------------
00430     //  Setter methods
00431     // -----------------------------------------------------------------------
00432 
00435 
00449     void setErrorHandler(ErrorHandler* const handler);
00450 
00466     void setEntityResolver(EntityResolver* const handler);
00467 
00486     void setDoNamespaces(const bool newState);
00487 
00504     void setExitOnFirstFatalError(const bool newState);
00505 
00521     void setValidationConstraintFatal(const bool newState);
00522 
00537     void setExpandEntityReferences(const bool expand);
00538 
00555     void setCreateEntityReferenceNodes(const bool create);
00556 
00578     void setIncludeIgnorableWhitespace(const bool include);
00579 
00596     void setValidationScheme(const ValSchemes newScheme);
00597 
00611     void setDoSchema(const bool newState);
00612 
00629     void setValidationSchemaFullChecking(const bool schemaFullChecking);
00630 
00651     void setExternalSchemaLocation(const XMLCh* const schemaLocation);
00652 
00661     void setExternalSchemaLocation(const char* const schemaLocation);
00662 
00677     void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
00678 
00687     void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
00688 
00702     void setURLEntityCaching(const bool useCache);
00703 
00718     void setURLEntityCacheDir(const XMLCh* cachedir);
00719 
00729     void setURLEntityCacheDir(const char* cachedir);
00730 
00732 
00733 
00734     // -----------------------------------------------------------------------
00735     //  Parsing methods
00736     // -----------------------------------------------------------------------
00737 
00740 
00761     void parse(const InputSource& source, const bool reuseGrammar = false);
00762 
00782     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00783 
00802     void parse(const char* const systemId, const bool reuseGrammar = false);
00803 
00833     bool parseFirst
00834     (
00835         const   XMLCh* const    systemId
00836         ,       XMLPScanToken&  toFill
00837         , const bool            reuseGrammar = false
00838     );
00839 
00870     bool parseFirst
00871     (
00872         const   char* const     systemId
00873         ,       XMLPScanToken&  toFill
00874         , const bool            reuseGrammar = false
00875     );
00876 
00907     bool parseFirst
00908     (
00909         const   InputSource&    source
00910         ,       XMLPScanToken&  toFill
00911         , const bool            reuseGrammar = false
00912     );
00913 
00936     bool parseNext(XMLPScanToken& token);
00937 
00963     void parseReset(XMLPScanToken& token);
00964 
00966 
00967 
00968 
00969     // -----------------------------------------------------------------------
00970     //  Implementation of the XMLErrorReporter interface.
00971     // -----------------------------------------------------------------------
00972 
00975 
01000     virtual void error
01001     (
01002         const   unsigned int                errCode
01003         , const XMLCh* const                msgDomain
01004         , const XMLErrorReporter::ErrTypes  errType
01005         , const XMLCh* const                errorText
01006         , const XMLCh* const                systemId
01007         , const XMLCh* const                publicId
01008         , const unsigned int                lineNum
01009         , const unsigned int                colNum
01010     );
01011 
01020     virtual void resetErrors();
01022 
01023 
01024     // -----------------------------------------------------------------------
01025     //  Implementation of the XMLEntityHandler interface.
01026     // -----------------------------------------------------------------------
01027 
01030 
01043     virtual void endInputSource(const InputSource& inputSource);
01044 
01060     virtual bool expandSystemId
01061     (
01062         const   XMLCh* const    systemId
01063         ,       XMLBuffer&      toFill
01064     );
01065 
01074     virtual void resetEntities();
01075 
01091     virtual InputSource* resolveEntity
01092     (
01093         const   XMLCh* const    publicId
01094         , const XMLCh* const    systemId
01095     );
01096 
01109     virtual void startInputSource(const InputSource& inputSource);
01110 
01112 
01113 
01114 
01115     // -----------------------------------------------------------------------
01116     //  Implementation of the XMLDocumentHandler interface.
01117     // -----------------------------------------------------------------------
01118 
01121 
01134     virtual void docCharacters
01135     (
01136         const   XMLCh* const    chars
01137         , const unsigned int    length
01138         , const bool            cdataSection
01139     );
01140 
01149     virtual void docComment
01150     (
01151         const   XMLCh* const    comment
01152     );
01153 
01166     virtual void docPI
01167     (
01168         const   XMLCh* const    target
01169         , const XMLCh* const    data
01170     );
01171 
01176     virtual void endDocument();
01177 
01191     virtual void endElement
01192     (
01193         const   XMLElementDecl& elemDecl
01194         , const unsigned int    urlId
01195         , const bool            isRoot
01196     );
01197 
01206     virtual void endEntityReference
01207     (
01208         const   XMLEntityDecl&  entDecl
01209     );
01210 
01229     virtual void ignorableWhitespace
01230     (
01231         const   XMLCh* const    chars
01232         , const unsigned int    length
01233         , const bool            cdataSection
01234     );
01235 
01242     virtual void resetDocument();
01243 
01248     virtual void startDocument();
01249 
01277     virtual void startElement
01278     (
01279         const   XMLElementDecl&         elemDecl
01280         , const unsigned int            urlId
01281         , const XMLCh* const            elemPrefix
01282         , const RefVectorOf<XMLAttr>&   attrList
01283         , const unsigned int            attrCount
01284         , const bool                    isEmpty
01285         , const bool                    isRoot
01286     );
01287 
01297     virtual void startEntityReference
01298     (
01299         const   XMLEntityDecl&  entDecl
01300     );
01301 
01320     virtual void XMLDecl
01321     (
01322         const   XMLCh* const    versionStr
01323         , const XMLCh* const    encodingStr
01324         , const XMLCh* const    standaloneStr
01325         , const XMLCh* const    actualEncStr
01326     );
01328 
01329 
01342     bool getDoValidation() const;
01343 
01357     void setDoValidation(const bool newState);
01358 
01362         virtual void attDef
01363     (
01364         const   DTDElementDecl&     elemDecl
01365         , const DTDAttDef&          attDef
01366         , const bool                ignoring
01367     );
01368 
01369     virtual void doctypeComment
01370     (
01371         const   XMLCh* const    comment
01372     );
01373 
01374     virtual void doctypeDecl
01375     (
01376         const   DTDElementDecl& elemDecl
01377         , const XMLCh* const    publicId
01378         , const XMLCh* const    systemId
01379         , const bool            hasIntSubset
01380     );
01381 
01382     virtual void doctypePI
01383     (
01384         const   XMLCh* const    target
01385         , const XMLCh* const    data
01386     );
01387 
01388     virtual void doctypeWhitespace
01389     (
01390         const   XMLCh* const    chars
01391         , const unsigned int    length
01392     );
01393 
01394     virtual void elementDecl
01395     (
01396         const   DTDElementDecl& decl
01397         , const bool            isIgnored
01398     );
01399 
01400     virtual void endAttList
01401     (
01402         const   DTDElementDecl& elemDecl
01403     );
01404 
01405     virtual void endIntSubset();
01406 
01407     virtual void endExtSubset();
01408 
01409     virtual void entityDecl
01410     (
01411         const   DTDEntityDecl&  entityDecl
01412         , const bool            isPEDecl
01413         , const bool            isIgnored
01414     );
01415 
01416     virtual void resetDocType();
01417 
01418     virtual void notationDecl
01419     (
01420         const   XMLNotationDecl&    notDecl
01421         , const bool                isIgnored
01422     );
01423 
01424     virtual void startAttList
01425     (
01426         const   DTDElementDecl& elemDecl
01427     );
01428 
01429     virtual void startIntSubset();
01430 
01431     virtual void startExtSubset();
01432 
01433     virtual void TextDecl
01434     (
01435         const   XMLCh* const    versionStr
01436         , const XMLCh* const    encodingStr
01437     );
01438 
01439 
01441 
01442 
01443 protected :
01444     // -----------------------------------------------------------------------
01445     //  Protected getter methods
01446     // -----------------------------------------------------------------------
01447 
01455     IDOM_Node* getCurrentNode();
01456 
01458 
01459 
01460     // -----------------------------------------------------------------------
01461     //  Protected setter methods
01462     // -----------------------------------------------------------------------
01463 
01466 
01474     void setCurrentNode(IDOM_Node* toSet);
01475 
01482     void setDocument(IDOM_Document* toSet);
01484 
01485 
01486 private :
01487     // -----------------------------------------------------------------------
01488     //  Private data members
01489     //
01490     //  fCurrentNode
01491     //  fCurrentParent
01492     //      Used to track the current node during nested element events. Since
01493     //      the tree must be built from a set of disjoint callbacks, we need
01494     //      these to keep up with where we currently are.
01495     //
01496     //  fDocument
01497     //      The root document object, filled with the document contents.
01498     //
01499     //  fEntityResolver
01500     //      The installed SAX entity resolver, if any. Null if none.
01501     //
01502     //  fErrorHandler
01503     //      The installed SAX error handler, if any. Null if none.
01504     //
01505     //  fCreateEntityReferenceNode
01506     //      Indicates whether entity reference nodes should be created.
01507     //
01508     //  fIncludeIgnorableWhitespace
01509     //      Indicates whether ignorable whiltespace should be added to
01510     //      the IDOM tree for validating parsers.
01511     //
01512     //  fNodeStack
01513     //      Used to track previous parent nodes during nested element events.
01514     //
01515     //  fParseInProgress
01516     //      Used to prevent multiple entrance to the parser while its doing
01517     //      a parse.
01518     //
01519     //  fScanner
01520     //      The scanner used for this parser. This is created during the
01521     //      constructor.
01522     //
01523     //  fWithinElement
01524     //      A flag to indicate that the parser is within at least one level
01525     //      of element processing.
01526     //
01527     //  fDocumentType
01528     //      Used to store and update the documentType variable information
01529     //      in fDocument
01530     //
01531     //  fDocumentVector
01532     //      Store all the previous fDocument(s) (thus not the current fDocument)
01533     //      created in this parser.  It is destroyed when the parser is destructed.
01534     // -----------------------------------------------------------------------
01535     IDOM_Node*               fCurrentParent;
01536     IDOM_Node*               fCurrentNode;
01537     IDDocumentImpl*          fDocument;
01538     EntityResolver*          fEntityResolver;
01539     ErrorHandler*            fErrorHandler;
01540     bool                     fCreateEntityReferenceNodes;
01541     bool                     fIncludeIgnorableWhitespace;
01542     ValueStackOf<IDOM_Node*>* fNodeStack;
01543     bool                     fParseInProgress;
01544     XMLScanner*              fScanner;
01545     bool                     fWithinElement;
01546     IDDocumentTypeImpl*      fDocumentType;
01547     RefVectorOf<IDDocumentImpl>* fDocumentVector;
01548 };
01549 
01550 
01551 
01552 // ---------------------------------------------------------------------------
01553 //  IDOMParser: Handlers for the XMLEntityHandler interface
01554 // ---------------------------------------------------------------------------
01555 inline void IDOMParser::endInputSource(const InputSource&)
01556 {
01557     // The IDOM entity resolver doesn't handle this
01558 }
01559 
01560 inline bool IDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01561 {
01562     // The IDOM entity resolver doesn't handle this
01563     return false;
01564 }
01565 
01566 inline void IDOMParser::resetEntities()
01567 {
01568     // Nothing to do on this one
01569 }
01570 
01571 inline void IDOMParser::startInputSource(const InputSource&)
01572 {
01573     // The IDOM entity resolver doesn't handle this
01574 }
01575 
01576 
01577 // ---------------------------------------------------------------------------
01578 //  IDOMParser: Getter methods
01579 // ---------------------------------------------------------------------------
01580 inline ErrorHandler* IDOMParser::getErrorHandler()
01581 {
01582     return fErrorHandler;
01583 }
01584 
01585 inline const ErrorHandler* IDOMParser::getErrorHandler() const
01586 {
01587     return fErrorHandler;
01588 }
01589 
01590 inline EntityResolver* IDOMParser::getEntityResolver()
01591 {
01592     return fEntityResolver;
01593 }
01594 
01595 inline const EntityResolver* IDOMParser::getEntityResolver() const
01596 {
01597     return fEntityResolver;
01598 }
01599 
01600 inline bool IDOMParser::getExpandEntityReferences() const
01601 {
01602     return fCreateEntityReferenceNodes;
01603 }
01604 inline bool IDOMParser::getCreateEntityReferenceNodes() const
01605 {
01606     return fCreateEntityReferenceNodes;
01607 }
01608 
01609 inline bool IDOMParser::getIncludeIgnorableWhitespace() const
01610 {
01611     return fIncludeIgnorableWhitespace;
01612 }
01613 
01614 
01615 // ---------------------------------------------------------------------------
01616 //  IDOMParser: Setter methods
01617 // ---------------------------------------------------------------------------
01618 inline void IDOMParser::setExpandEntityReferences(const bool expand)
01619 {
01620     fCreateEntityReferenceNodes = expand;
01621 }
01622 
01623 inline void IDOMParser::setCreateEntityReferenceNodes(const bool create)
01624 {
01625     fCreateEntityReferenceNodes = create;
01626 }
01627 
01628 inline void IDOMParser::setIncludeIgnorableWhitespace(const bool include)
01629 {
01630     fIncludeIgnorableWhitespace = include;
01631 }
01632 
01633 
01634 // ---------------------------------------------------------------------------
01635 //  IDOMParser: Protected getter methods
01636 // ---------------------------------------------------------------------------
01637 inline IDOM_Node* IDOMParser::getCurrentNode()
01638 {
01639     return fCurrentNode;
01640 }
01641 
01642 
01643 // ---------------------------------------------------------------------------
01644 //  IDOMParser: Protected setter methods
01645 // ---------------------------------------------------------------------------
01646 inline void IDOMParser::setCurrentNode(IDOM_Node* toSet)
01647 {
01648     fCurrentNode = toSet;
01649 }
01650 
01651 inline void IDOMParser::setDocument(IDOM_Document* toSet)
01652 {
01653     fDocument = (IDDocumentImpl *)toSet;
01654 }
01655 
01656 #endif

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