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

Home

Readme
Download
Installation
Build

API Docs
Samples
Schema

FAQs
Programming
Migration

Releases
Bug-Reporting
Feedback

Y2K Compliance
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  

IDOMParser.hpp

Go to the documentation of this file.
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.3 2001/06/08 21:26:05 tng Exp $
00059  *
00060  */
00061 
00062 #if !defined(IDOMPARSER_HPP)
00063 #define IDOMPARSER_HPP
00064 
00065 
00066 #include <idom/IDOM_Document.hpp>
00067 #include <framework/XMLDocumentHandler.hpp>
00068 #include <framework/XMLErrorReporter.hpp>
00069 #include <framework/XMLEntityHandler.hpp>
00070 #include <util/ValueStackOf.hpp>
00071 
00072 #include <validators/DTD/DocTypeHandler.hpp>
00073 #include <idom/IDOM_DocumentType.hpp>
00074 #include <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  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 
00120 
00129     IDOMParser(XMLValidator* const valToAdopt = 0);
00130 
00134     ~IDOMParser();
00135 
00137 
00143     void reset();
00144 
00145 
00146     // -----------------------------------------------------------------------
00147     //  Getter methods
00148     // -----------------------------------------------------------------------
00149 
00152 
00162     IDOM_Document* getDocument();
00163 
00171     ErrorHandler* getErrorHandler();
00172 
00180     const ErrorHandler* getErrorHandler() const;
00181 
00189     EntityResolver* getEntityResolver();
00190 
00198     const EntityResolver* getEntityResolver() const;
00199 
00207     const XMLScanner& getScanner() const;
00208 
00216     const XMLValidator& getValidator() const;
00217 
00225     ValSchemes getValidationScheme() const;
00226 
00237     bool getDoSchema() const;
00238 
00250     int getErrorCount() const;
00251 
00262     bool getDoNamespaces() const;
00263 
00276     bool getExitOnFirstFatalError() const;
00277 
00288     bool getValidationConstraintFatal() const;
00289 
00301     bool getExpandEntityReferences() const;
00302 
00320     bool  getCreateEntityReferenceNodes()const;
00321 
00332     bool getIncludeIgnorableWhitespace() const;
00333 
00335 
00336 
00337     // -----------------------------------------------------------------------
00338     //  Setter methods
00339     // -----------------------------------------------------------------------
00340 
00343 
00357     void setErrorHandler(ErrorHandler* const handler);
00358 
00374     void setEntityResolver(EntityResolver* const handler);
00375 
00394     void setDoNamespaces(const bool newState);
00395 
00412     void setExitOnFirstFatalError(const bool newState);
00413 
00429     void setValidationConstraintFatal(const bool newState);
00430 
00445     void setExpandEntityReferences(const bool expand);
00446 
00463     void setCreateEntityReferenceNodes(const bool create);
00464 
00486     void setIncludeIgnorableWhitespace(const bool include);
00487 
00504     void setValidationScheme(const ValSchemes newScheme);
00505 
00519     void setDoSchema(const bool newState);
00520 
00522 
00523 
00524     // -----------------------------------------------------------------------
00525     //  Parsing methods
00526     // -----------------------------------------------------------------------
00527 
00530 
00544     void parse(const InputSource& source, const bool reuseGrammar = false);
00545 
00560     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00561 
00573     void parse(const char* const systemId, const bool reuseGrammar = false);
00574 
00604     bool parseFirst
00605     (
00606         const   XMLCh* const    systemId
00607         ,       XMLPScanToken&  toFill
00608         , const bool            reuseGrammar = false
00609     );
00610 
00641     bool parseFirst
00642     (
00643         const   char* const     systemId
00644         ,       XMLPScanToken&  toFill
00645         , const bool            reuseGrammar = false
00646     );
00647 
00678     bool parseFirst
00679     (
00680         const   InputSource&    source
00681         ,       XMLPScanToken&  toFill
00682         , const bool            reuseGrammar = false
00683     );
00684 
00707     bool parseNext(XMLPScanToken& token);
00708 
00734     void parseReset(XMLPScanToken& token);
00735 
00737 
00738 
00739 
00740     // -----------------------------------------------------------------------
00741     //  Implementation of the XMLErrorReporter interface.
00742     // -----------------------------------------------------------------------
00743 
00746 
00771     virtual void error
00772     (
00773         const   unsigned int                errCode
00774         , const XMLCh* const                msgDomain
00775         , const XMLErrorReporter::ErrTypes  errType
00776         , const XMLCh* const                errorText
00777         , const XMLCh* const                systemId
00778         , const XMLCh* const                publicId
00779         , const unsigned int                lineNum
00780         , const unsigned int                colNum
00781     );
00782 
00791     virtual void resetErrors();
00793 
00794 
00795     // -----------------------------------------------------------------------
00796     //  Implementation of the XMLEntityHandler interface.
00797     // -----------------------------------------------------------------------
00798 
00801 
00814     virtual void endInputSource(const InputSource& inputSource);
00815 
00831     virtual bool expandSystemId
00832     (
00833         const   XMLCh* const    systemId
00834         ,       XMLBuffer&      toFill
00835     );
00836 
00845     virtual void resetEntities();
00846 
00862     virtual InputSource* resolveEntity
00863     (
00864         const   XMLCh* const    publicId
00865         , const XMLCh* const    systemId
00866     );
00867 
00880     virtual void startInputSource(const InputSource& inputSource);
00881 
00883 
00884 
00885 
00886     // -----------------------------------------------------------------------
00887     //  Implementation of the XMLDocumentHandler interface.
00888     // -----------------------------------------------------------------------
00889 
00892 
00905     virtual void docCharacters
00906     (
00907         const   XMLCh* const    chars
00908         , const unsigned int    length
00909         , const bool            cdataSection
00910     );
00911 
00920     virtual void docComment
00921     (
00922         const   XMLCh* const    comment
00923     );
00924 
00937     virtual void docPI
00938     (
00939         const   XMLCh* const    target
00940         , const XMLCh* const    data
00941     );
00942 
00947     virtual void endDocument();
00948 
00962     virtual void endElement
00963     (
00964         const   XMLElementDecl& elemDecl
00965         , const unsigned int    urlId
00966         , const bool            isRoot
00967     );
00968 
00977     virtual void endEntityReference
00978     (
00979         const   XMLEntityDecl&  entDecl
00980     );
00981 
01000     virtual void ignorableWhitespace
01001     (
01002         const   XMLCh* const    chars
01003         , const unsigned int    length
01004         , const bool            cdataSection
01005     );
01006 
01013     virtual void resetDocument();
01014 
01019     virtual void startDocument();
01020 
01048     virtual void startElement
01049     (
01050         const   XMLElementDecl&         elemDecl
01051         , const unsigned int            urlId
01052         , const XMLCh* const            elemPrefix
01053         , const RefVectorOf<XMLAttr>&   attrList
01054         , const unsigned int            attrCount
01055         , const bool                    isEmpty
01056         , const bool                    isRoot
01057     );
01058 
01068     virtual void startEntityReference
01069     (
01070         const   XMLEntityDecl&  entDecl
01071     );
01072 
01091     virtual void XMLDecl
01092     (
01093         const   XMLCh* const    versionStr
01094         , const XMLCh* const    encodingStr
01095         , const XMLCh* const    standaloneStr
01096         , const XMLCh* const    actualEncStr
01097     );
01099 
01100 
01103 
01113     bool getDoValidation() const;
01114 
01128     void setDoValidation(const bool newState);
01129 
01133     virtual void attDef
01134     (
01135         const   DTDElementDecl&     elemDecl
01136         , const DTDAttDef&          attDef
01137         , const bool                ignoring
01138     );
01139 
01140     virtual void doctypeComment
01141     (
01142         const   XMLCh* const    comment
01143     );
01144 
01145     virtual void doctypeDecl
01146     (
01147         const   DTDElementDecl& elemDecl
01148         , const XMLCh* const    publicId
01149         , const XMLCh* const    systemId
01150         , const bool            hasIntSubset
01151     );
01152 
01153     virtual void doctypePI
01154     (
01155         const   XMLCh* const    target
01156         , const XMLCh* const    data
01157     );
01158 
01159     virtual void doctypeWhitespace
01160     (
01161         const   XMLCh* const    chars
01162         , const unsigned int    length
01163     );
01164 
01165     virtual void elementDecl
01166     (
01167         const   DTDElementDecl& decl
01168         , const bool            isIgnored
01169     );
01170 
01171     virtual void endAttList
01172     (
01173         const   DTDElementDecl& elemDecl
01174     );
01175 
01176     virtual void endIntSubset();
01177 
01178     virtual void endExtSubset();
01179 
01180     virtual void entityDecl
01181     (
01182         const   DTDEntityDecl&  entityDecl
01183         , const bool            isPEDecl
01184         , const bool            isIgnored
01185     );
01186 
01187     virtual void resetDocType();
01188 
01189     virtual void notationDecl
01190     (
01191         const   XMLNotationDecl&    notDecl
01192         , const bool                isIgnored
01193     );
01194 
01195     virtual void startAttList
01196     (
01197         const   DTDElementDecl& elemDecl
01198     );
01199 
01200     virtual void startIntSubset();
01201 
01202     virtual void startExtSubset();
01203 
01204     virtual void TextDecl
01205     (
01206         const   XMLCh* const    versionStr
01207         , const XMLCh* const    encodingStr
01208     );
01209 
01210 
01212 
01213 
01214 protected :
01215     // -----------------------------------------------------------------------
01216     //  Protected getter methods
01217     // -----------------------------------------------------------------------
01218 
01221 
01226     IDOM_Node* getCurrentNode();
01227 
01229 
01230 
01231     // -----------------------------------------------------------------------
01232     //  Protected setter methods
01233     // -----------------------------------------------------------------------
01234 
01237 
01245     void setCurrentNode(IDOM_Node* toSet);
01246 
01253     void setDocument(IDOM_Document* toSet);
01255 
01256 
01257 private :
01258     // -----------------------------------------------------------------------
01259     //  Private data members
01260     //
01261     //  fCurrentNode
01262     //  fCurrentParent
01263     //      Used to track the current node during nested element events. Since
01264     //      the tree must be built from a set of disjoint callbacks, we need
01265     //      these to keep up with where we currently are.
01266     //
01267     //  fDocument
01268     //      The root document object, filled with the document contents.
01269     //
01270     //  fEntityResolver
01271     //      The installed SAX entity resolver, if any. Null if none.
01272     //
01273     //  fErrorHandler
01274     //      The installed SAX error handler, if any. Null if none.
01275     //
01276     //  fCreateEntityReferenceNode
01277     //      Indicates whether entity reference nodes should be created.
01278     //
01279     //  fIncludeIgnorableWhitespace
01280     //      Indicates whether ignorable whiltespace should be added to
01281     //      the IDOM tree for validating parsers.
01282     //
01283     //  fNodeStack
01284     //      Used to track previous parent nodes during nested element events.
01285     //
01286     //  fParseInProgress
01287     //      Used to prevent multiple entrance to the parser while its doing
01288     //      a parse.
01289     //
01290     //  fScanner
01291     //      The scanner used for this parser. This is created during the
01292     //      constructor.
01293     //
01294     //  fWithinElement
01295     //      A flag to indicate that the parser is within at least one level
01296     //      of element processing.
01297     //
01298     //  fDocumentType
01299     //      Used to store and update the documentType variable information
01300     //      in fDocument
01301     //
01302     // -----------------------------------------------------------------------
01303     IDOM_Node*               fCurrentParent;
01304     IDOM_Node*               fCurrentNode;
01305     IDDocumentImpl*          fDocument;
01306     EntityResolver*          fEntityResolver;
01307     ErrorHandler*            fErrorHandler;
01308     bool                     fCreateEntityReferenceNodes;
01309     bool                     fIncludeIgnorableWhitespace;
01310     ValueStackOf<IDOM_Node*>* fNodeStack;
01311     bool                     fParseInProgress;
01312     XMLScanner*              fScanner;
01313     bool                     fWithinElement;
01314     IDDocumentTypeImpl*      fDocumentType;
01315 };
01316 
01317 
01318 
01319 // ---------------------------------------------------------------------------
01320 //  IDOMParser: Handlers for the XMLEntityHandler interface
01321 // ---------------------------------------------------------------------------
01322 inline void IDOMParser::endInputSource(const InputSource&)
01323 {
01324     // The IDOM entity resolver doesn't handle this
01325 }
01326 
01327 inline bool IDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01328 {
01329     // The IDOM entity resolver doesn't handle this
01330     return false;
01331 }
01332 
01333 inline void IDOMParser::resetEntities()
01334 {
01335     // Nothing to do on this one
01336 }
01337 
01338 inline void IDOMParser::startInputSource(const InputSource&)
01339 {
01340     // The IDOM entity resolver doesn't handle this
01341 }
01342 
01343 
01344 // ---------------------------------------------------------------------------
01345 //  IDOMParser: Getter methods
01346 // ---------------------------------------------------------------------------
01347 inline ErrorHandler* IDOMParser::getErrorHandler()
01348 {
01349     return fErrorHandler;
01350 }
01351 
01352 inline const ErrorHandler* IDOMParser::getErrorHandler() const
01353 {
01354     return fErrorHandler;
01355 }
01356 
01357 inline EntityResolver* IDOMParser::getEntityResolver()
01358 {
01359     return fEntityResolver;
01360 }
01361 
01362 inline const EntityResolver* IDOMParser::getEntityResolver() const
01363 {
01364     return fEntityResolver;
01365 }
01366 
01367 inline bool IDOMParser::getExpandEntityReferences() const
01368 {
01369     return fCreateEntityReferenceNodes;
01370 }
01371 inline bool IDOMParser::getCreateEntityReferenceNodes() const
01372 {
01373     return fCreateEntityReferenceNodes;
01374 }
01375 
01376 inline bool IDOMParser::getIncludeIgnorableWhitespace() const
01377 {
01378     return fIncludeIgnorableWhitespace;
01379 }
01380 
01381 inline const XMLScanner& IDOMParser::getScanner() const
01382 {
01383     return *fScanner;
01384 }
01385 
01386 
01387 // ---------------------------------------------------------------------------
01388 //  IDOMParser: Setter methods
01389 // ---------------------------------------------------------------------------
01390 inline void IDOMParser::setExpandEntityReferences(const bool expand)
01391 {
01392     fCreateEntityReferenceNodes = expand;
01393 }
01394 
01395 inline void IDOMParser::setCreateEntityReferenceNodes(const bool create)
01396 {
01397     fCreateEntityReferenceNodes = create;
01398 }
01399 
01400 inline void IDOMParser::setIncludeIgnorableWhitespace(const bool include)
01401 {
01402     fIncludeIgnorableWhitespace = include;
01403 }
01404 
01405 
01406 // ---------------------------------------------------------------------------
01407 //  IDOMParser: Protected getter methods
01408 // ---------------------------------------------------------------------------
01409 inline IDOM_Node* IDOMParser::getCurrentNode()
01410 {
01411     return fCurrentNode;
01412 }
01413 
01414 
01415 // ---------------------------------------------------------------------------
01416 //  IDOMParser: Protected setter methods
01417 // ---------------------------------------------------------------------------
01418 inline void IDOMParser::setCurrentNode(IDOM_Node* toSet)
01419 {
01420     fCurrentNode = toSet;
01421 }
01422 
01423 inline void IDOMParser::setDocument(IDOM_Document* toSet)
01424 {
01425     fDocument = (IDDocumentImpl *)toSet;
01426 }
01427 
01428 #endif


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