www.alphaworks.ibm.comwww.ibm.com/developerwww.ibm.com

Home

Readme
Download

Build







Migration

Releases

Feedback

Y2K Compliance


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.4 2001/06/23 14:13:16 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 XMLValidator& getValidator() const;
00208 
00216     ValSchemes getValidationScheme() const;
00217 
00228     bool getDoSchema() const;
00229 
00241     int getErrorCount() const;
00242 
00253     bool getDoNamespaces() const;
00254 
00267     bool getExitOnFirstFatalError() const;
00268 
00279     bool getValidationConstraintFatal() const;
00280 
00292     bool getExpandEntityReferences() const;
00293 
00311     bool  getCreateEntityReferenceNodes()const;
00312 
00323     bool getIncludeIgnorableWhitespace() const;
00324 
00326 
00327 
00328     // -----------------------------------------------------------------------
00329     //  Setter methods
00330     // -----------------------------------------------------------------------
00331 
00334 
00348     void setErrorHandler(ErrorHandler* const handler);
00349 
00365     void setEntityResolver(EntityResolver* const handler);
00366 
00385     void setDoNamespaces(const bool newState);
00386 
00403     void setExitOnFirstFatalError(const bool newState);
00404 
00420     void setValidationConstraintFatal(const bool newState);
00421 
00436     void setExpandEntityReferences(const bool expand);
00437 
00454     void setCreateEntityReferenceNodes(const bool create);
00455 
00477     void setIncludeIgnorableWhitespace(const bool include);
00478 
00495     void setValidationScheme(const ValSchemes newScheme);
00496 
00510     void setDoSchema(const bool newState);
00511 
00513 
00514 
00515     // -----------------------------------------------------------------------
00516     //  Parsing methods
00517     // -----------------------------------------------------------------------
00518 
00521 
00535     void parse(const InputSource& source, const bool reuseGrammar = false);
00536 
00551     void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
00552 
00564     void parse(const char* const systemId, const bool reuseGrammar = false);
00565 
00595     bool parseFirst
00596     (
00597         const   XMLCh* const    systemId
00598         ,       XMLPScanToken&  toFill
00599         , const bool            reuseGrammar = false
00600     );
00601 
00632     bool parseFirst
00633     (
00634         const   char* const     systemId
00635         ,       XMLPScanToken&  toFill
00636         , const bool            reuseGrammar = false
00637     );
00638 
00669     bool parseFirst
00670     (
00671         const   InputSource&    source
00672         ,       XMLPScanToken&  toFill
00673         , const bool            reuseGrammar = false
00674     );
00675 
00698     bool parseNext(XMLPScanToken& token);
00699 
00725     void parseReset(XMLPScanToken& token);
00726 
00728 
00729 
00730 
00731     // -----------------------------------------------------------------------
00732     //  Implementation of the XMLErrorReporter interface.
00733     // -----------------------------------------------------------------------
00734 
00737 
00762     virtual void error
00763     (
00764         const   unsigned int                errCode
00765         , const XMLCh* const                msgDomain
00766         , const XMLErrorReporter::ErrTypes  errType
00767         , const XMLCh* const                errorText
00768         , const XMLCh* const                systemId
00769         , const XMLCh* const                publicId
00770         , const unsigned int                lineNum
00771         , const unsigned int                colNum
00772     );
00773 
00782     virtual void resetErrors();
00784 
00785 
00786     // -----------------------------------------------------------------------
00787     //  Implementation of the XMLEntityHandler interface.
00788     // -----------------------------------------------------------------------
00789 
00792 
00805     virtual void endInputSource(const InputSource& inputSource);
00806 
00822     virtual bool expandSystemId
00823     (
00824         const   XMLCh* const    systemId
00825         ,       XMLBuffer&      toFill
00826     );
00827 
00836     virtual void resetEntities();
00837 
00853     virtual InputSource* resolveEntity
00854     (
00855         const   XMLCh* const    publicId
00856         , const XMLCh* const    systemId
00857     );
00858 
00871     virtual void startInputSource(const InputSource& inputSource);
00872 
00874 
00875 
00876 
00877     // -----------------------------------------------------------------------
00878     //  Implementation of the XMLDocumentHandler interface.
00879     // -----------------------------------------------------------------------
00880 
00883 
00896     virtual void docCharacters
00897     (
00898         const   XMLCh* const    chars
00899         , const unsigned int    length
00900         , const bool            cdataSection
00901     );
00902 
00911     virtual void docComment
00912     (
00913         const   XMLCh* const    comment
00914     );
00915 
00928     virtual void docPI
00929     (
00930         const   XMLCh* const    target
00931         , const XMLCh* const    data
00932     );
00933 
00938     virtual void endDocument();
00939 
00953     virtual void endElement
00954     (
00955         const   XMLElementDecl& elemDecl
00956         , const unsigned int    urlId
00957         , const bool            isRoot
00958     );
00959 
00968     virtual void endEntityReference
00969     (
00970         const   XMLEntityDecl&  entDecl
00971     );
00972 
00991     virtual void ignorableWhitespace
00992     (
00993         const   XMLCh* const    chars
00994         , const unsigned int    length
00995         , const bool            cdataSection
00996     );
00997 
01004     virtual void resetDocument();
01005 
01010     virtual void startDocument();
01011 
01039     virtual void startElement
01040     (
01041         const   XMLElementDecl&         elemDecl
01042         , const unsigned int            urlId
01043         , const XMLCh* const            elemPrefix
01044         , const RefVectorOf<XMLAttr>&   attrList
01045         , const unsigned int            attrCount
01046         , const bool                    isEmpty
01047         , const bool                    isRoot
01048     );
01049 
01059     virtual void startEntityReference
01060     (
01061         const   XMLEntityDecl&  entDecl
01062     );
01063 
01082     virtual void XMLDecl
01083     (
01084         const   XMLCh* const    versionStr
01085         , const XMLCh* const    encodingStr
01086         , const XMLCh* const    standaloneStr
01087         , const XMLCh* const    actualEncStr
01088     );
01090 
01091 
01094 
01104     bool getDoValidation() const;
01105 
01119     void setDoValidation(const bool newState);
01120 
01124     virtual void attDef
01125     (
01126         const   DTDElementDecl&     elemDecl
01127         , const DTDAttDef&          attDef
01128         , const bool                ignoring
01129     );
01130 
01131     virtual void doctypeComment
01132     (
01133         const   XMLCh* const    comment
01134     );
01135 
01136     virtual void doctypeDecl
01137     (
01138         const   DTDElementDecl& elemDecl
01139         , const XMLCh* const    publicId
01140         , const XMLCh* const    systemId
01141         , const bool            hasIntSubset
01142     );
01143 
01144     virtual void doctypePI
01145     (
01146         const   XMLCh* const    target
01147         , const XMLCh* const    data
01148     );
01149 
01150     virtual void doctypeWhitespace
01151     (
01152         const   XMLCh* const    chars
01153         , const unsigned int    length
01154     );
01155 
01156     virtual void elementDecl
01157     (
01158         const   DTDElementDecl& decl
01159         , const bool            isIgnored
01160     );
01161 
01162     virtual void endAttList
01163     (
01164         const   DTDElementDecl& elemDecl
01165     );
01166 
01167     virtual void endIntSubset();
01168 
01169     virtual void endExtSubset();
01170 
01171     virtual void entityDecl
01172     (
01173         const   DTDEntityDecl&  entityDecl
01174         , const bool            isPEDecl
01175         , const bool            isIgnored
01176     );
01177 
01178     virtual void resetDocType();
01179 
01180     virtual void notationDecl
01181     (
01182         const   XMLNotationDecl&    notDecl
01183         , const bool                isIgnored
01184     );
01185 
01186     virtual void startAttList
01187     (
01188         const   DTDElementDecl& elemDecl
01189     );
01190 
01191     virtual void startIntSubset();
01192 
01193     virtual void startExtSubset();
01194 
01195     virtual void TextDecl
01196     (
01197         const   XMLCh* const    versionStr
01198         , const XMLCh* const    encodingStr
01199     );
01200 
01201 
01203 
01204 
01205 protected :
01206     // -----------------------------------------------------------------------
01207     //  Protected getter methods
01208     // -----------------------------------------------------------------------
01209 
01212 
01217     IDOM_Node* getCurrentNode();
01218 
01220 
01221 
01222     // -----------------------------------------------------------------------
01223     //  Protected setter methods
01224     // -----------------------------------------------------------------------
01225 
01228 
01236     void setCurrentNode(IDOM_Node* toSet);
01237 
01244     void setDocument(IDOM_Document* toSet);
01246 
01247 
01248 private :
01249     // -----------------------------------------------------------------------
01250     //  Private data members
01251     //
01252     //  fCurrentNode
01253     //  fCurrentParent
01254     //      Used to track the current node during nested element events. Since
01255     //      the tree must be built from a set of disjoint callbacks, we need
01256     //      these to keep up with where we currently are.
01257     //
01258     //  fDocument
01259     //      The root document object, filled with the document contents.
01260     //
01261     //  fEntityResolver
01262     //      The installed SAX entity resolver, if any. Null if none.
01263     //
01264     //  fErrorHandler
01265     //      The installed SAX error handler, if any. Null if none.
01266     //
01267     //  fCreateEntityReferenceNode
01268     //      Indicates whether entity reference nodes should be created.
01269     //
01270     //  fIncludeIgnorableWhitespace
01271     //      Indicates whether ignorable whiltespace should be added to
01272     //      the IDOM tree for validating parsers.
01273     //
01274     //  fNodeStack
01275     //      Used to track previous parent nodes during nested element events.
01276     //
01277     //  fParseInProgress
01278     //      Used to prevent multiple entrance to the parser while its doing
01279     //      a parse.
01280     //
01281     //  fScanner
01282     //      The scanner used for this parser. This is created during the
01283     //      constructor.
01284     //
01285     //  fWithinElement
01286     //      A flag to indicate that the parser is within at least one level
01287     //      of element processing.
01288     //
01289     //  fDocumentType
01290     //      Used to store and update the documentType variable information
01291     //      in fDocument
01292     //
01293     // -----------------------------------------------------------------------
01294     IDOM_Node*               fCurrentParent;
01295     IDOM_Node*               fCurrentNode;
01296     IDDocumentImpl*          fDocument;
01297     EntityResolver*          fEntityResolver;
01298     ErrorHandler*            fErrorHandler;
01299     bool                     fCreateEntityReferenceNodes;
01300     bool                     fIncludeIgnorableWhitespace;
01301     ValueStackOf<IDOM_Node*>* fNodeStack;
01302     bool                     fParseInProgress;
01303     XMLScanner*              fScanner;
01304     bool                     fWithinElement;
01305     IDDocumentTypeImpl*      fDocumentType;
01306 };
01307 
01308 
01309 
01310 // ---------------------------------------------------------------------------
01311 //  IDOMParser: Handlers for the XMLEntityHandler interface
01312 // ---------------------------------------------------------------------------
01313 inline void IDOMParser::endInputSource(const InputSource&)
01314 {
01315     // The IDOM entity resolver doesn't handle this
01316 }
01317 
01318 inline bool IDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
01319 {
01320     // The IDOM entity resolver doesn't handle this
01321     return false;
01322 }
01323 
01324 inline void IDOMParser::resetEntities()
01325 {
01326     // Nothing to do on this one
01327 }
01328 
01329 inline void IDOMParser::startInputSource(const InputSource&)
01330 {
01331     // The IDOM entity resolver doesn't handle this
01332 }
01333 
01334 
01335 // ---------------------------------------------------------------------------
01336 //  IDOMParser: Getter methods
01337 // ---------------------------------------------------------------------------
01338 inline ErrorHandler* IDOMParser::getErrorHandler()
01339 {
01340     return fErrorHandler;
01341 }
01342 
01343 inline const ErrorHandler* IDOMParser::getErrorHandler() const
01344 {
01345     return fErrorHandler;
01346 }
01347 
01348 inline EntityResolver* IDOMParser::getEntityResolver()
01349 {
01350     return fEntityResolver;
01351 }
01352 
01353 inline const EntityResolver* IDOMParser::getEntityResolver() const
01354 {
01355     return fEntityResolver;
01356 }
01357 
01358 inline bool IDOMParser::getExpandEntityReferences() const
01359 {
01360     return fCreateEntityReferenceNodes;
01361 }
01362 inline bool IDOMParser::getCreateEntityReferenceNodes() const
01363 {
01364     return fCreateEntityReferenceNodes;
01365 }
01366 
01367 inline bool IDOMParser::getIncludeIgnorableWhitespace() const
01368 {
01369     return fIncludeIgnorableWhitespace;
01370 }
01371 
01372 
01373 // ---------------------------------------------------------------------------
01374 //  IDOMParser: Setter methods
01375 // ---------------------------------------------------------------------------
01376 inline void IDOMParser::setExpandEntityReferences(const bool expand)
01377 {
01378     fCreateEntityReferenceNodes = expand;
01379 }
01380 
01381 inline void IDOMParser::setCreateEntityReferenceNodes(const bool create)
01382 {
01383     fCreateEntityReferenceNodes = create;
01384 }
01385 
01386 inline void IDOMParser::setIncludeIgnorableWhitespace(const bool include)
01387 {
01388     fIncludeIgnorableWhitespace = include;
01389 }
01390 
01391 
01392 // ---------------------------------------------------------------------------
01393 //  IDOMParser: Protected getter methods
01394 // ---------------------------------------------------------------------------
01395 inline IDOM_Node* IDOMParser::getCurrentNode()
01396 {
01397     return fCurrentNode;
01398 }
01399 
01400 
01401 // ---------------------------------------------------------------------------
01402 //  IDOMParser: Protected setter methods
01403 // ---------------------------------------------------------------------------
01404 inline void IDOMParser::setCurrentNode(IDOM_Node* toSet)
01405 {
01406     fCurrentNode = toSet;
01407 }
01408 
01409 inline void IDOMParser::setDocument(IDOM_Document* toSet)
01410 {
01411     fDocument = (IDDocumentImpl *)toSet;
01412 }
01413 
01414 #endif


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