knoaman     2002/12/03 17:47:08

  Modified:    c/src/xercesc/dom/deprecated DOMParser.hpp DOMParser.cpp
  Log:
  Scanner re-organization.
  
  Revision  Changes    Path
  1.12      +52 -10    xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.hpp
  
  Index: DOMParser.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.hpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DOMParser.hpp     4 Nov 2002 15:04:44 -0000       1.11
  +++ DOMParser.hpp     4 Dec 2002 01:47:08 -0000       1.12
  @@ -62,7 +62,6 @@
   #if !defined(DOMPARSER_HPP)
   #define DOMPARSER_HPP
   
  -
   #include <xercesc/framework/XMLDocumentHandler.hpp>
   #include <xercesc/framework/XMLErrorReporter.hpp>
   #include <xercesc/framework/XMLEntityHandler.hpp>
  @@ -82,7 +81,7 @@
   class XMLScanner;
   class XMLValidator;
   class Grammar;
  -
  +class GrammarResolver;
   
   /**
     * This class implements the Document Object Model (DOM) interface.
  @@ -402,6 +401,19 @@
       bool isUsingCachedGrammarInParse() const;
   
       /**
  +      * Get the 'calculate src offset flag'
  +      *
  +      * This method returns the state of the parser's src offset calculation
  +      * when parsing an XML document.
  +      *
  +      * @return true, if the parser is currently configured to
  +      *         calculate src offsets, false otherwise.
  +      *
  +      * @see #setCalculateSrcOfs
  +      */
  +    bool getCalculateSrcOfs() const;
  +
  +    /**
         * Retrieve the grammar that is associated with the specified namespace key
         *
         * @param  nameSpaceKey Namespace key
  @@ -726,6 +738,29 @@
         */
       void useCachedGrammarInParse(const bool newState);
   
  +    /** Enable/disable src offset calculation
  +      *
  +      * This method allows users to enable/disable src offset calculation.
  +      * Disabling the calculation will improve performance.
  +      *
  +      * The parser's default state is: true.
  +      *
  +      * @param newState The value specifying whether we should enable or
  +      *                 disable src offset calculation
  +      *
  +      * @see #getCalculateSrcOfs
  +      */
  +    void setCalculateSrcOfs(const bool newState);
  +
  +    /** Set the scanner to use when scanning the XML document
  +      *
  +      * This method allows users to set the scanner to use
  +      * when scanning a given XML document.
  +      *
  +      * @param scannerName The name of the desired scanner
  +      */
  +    void useScanner(const XMLCh* const scannerName);
  +
       //@}
   
   
  @@ -1613,6 +1648,12 @@
   
   private :
       // -----------------------------------------------------------------------
  +    //  Protected setter methods
  +    // -----------------------------------------------------------------------
  +    void initialize();
  +    void cleanUp();
  +    
  +    // -----------------------------------------------------------------------
       //  Private data members
       //
       //  fCurrentNode
  @@ -1661,23 +1702,25 @@
       //      This is an extension to xerces implementation
       //
       // -----------------------------------------------------------------------
  +    bool                    fToCreateXMLDeclTypeNode;
  +    bool                    fCreateEntityReferenceNodes;
  +    bool                    fIncludeIgnorableWhitespace;
  +    bool                    fParseInProgress;
  +    bool                    fWithinElement;
       DOM_Node                fCurrentParent;
       DOM_Node                fCurrentNode;
       DOM_Document            fDocument;
       EntityResolver*         fEntityResolver;
       ErrorHandler*           fErrorHandler;
  -    bool                    fCreateEntityReferenceNodes;
  -    bool                    fIncludeIgnorableWhitespace;
       ValueStackOf<DOM_Node>* fNodeStack;
  -    bool                    fParseInProgress;
       XMLScanner*             fScanner;
  -    bool                    fWithinElement;
       DocumentTypeImpl*       fDocumentType;
  -    bool                    fToCreateXMLDeclTypeNode;
  +    GrammarResolver*        fGrammarResolver;
  +    XMLStringPool*          fURIStringPool;
  +    XMLValidator*           fValidator;
   };
   
   
  -
   // ---------------------------------------------------------------------------
   //  DOMParser: Handlers for the XMLEntityHandler interface
   // ---------------------------------------------------------------------------
  @@ -1787,7 +1830,6 @@
   {
       return fCurrentNode;
   }
  -
   
   // ---------------------------------------------------------------------------
   //  DOMParser: Protected setter methods
  
  
  
  1.10      +77 -21    xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.cpp
  
  Index: DOMParser.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/deprecated/DOMParser.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DOMParser.cpp     4 Nov 2002 15:04:44 -0000       1.9
  +++ DOMParser.cpp     4 Dec 2002 01:47:08 -0000       1.10
  @@ -68,14 +68,15 @@
   // ---------------------------------------------------------------------------
   //  Includes
   // ---------------------------------------------------------------------------
  +#include <xercesc/internal/XMLScannerResolver.hpp>
   #include <xercesc/sax/EntityResolver.hpp>
   #include <xercesc/util/XMLUniDefs.hpp>
   #include <xercesc/sax/ErrorHandler.hpp>
   #include <xercesc/sax/SAXParseException.hpp>
   #include <xercesc/framework/XMLNotationDecl.hpp>
   #include <xercesc/util/IOException.hpp>
  -#include <xercesc/internal/XMLScanner.hpp>
  -#include <xercesc/validators/DTD/DTDValidator.hpp>
  +#include <xercesc/framework/XMLValidator.hpp>
  +#include <xercesc/validators/common/GrammarResolver.hpp>
   #include "DOMParser.hpp"
   #include "ElementImpl.hpp"
   #include "AttrImpl.hpp"
  @@ -100,35 +101,68 @@
   // ---------------------------------------------------------------------------
   DOMParser::DOMParser(XMLValidator* const valToAdopt) :
   
  -fErrorHandler(0)
  -, fEntityResolver(0)
  -, fCreateEntityReferenceNodes(true)
  -, fToCreateXMLDeclTypeNode(false)
  -, fIncludeIgnorableWhitespace(true)
  -, fNodeStack(0)
  -, fScanner(0)
  +    fToCreateXMLDeclTypeNode(false)
  +    , fCreateEntityReferenceNodes(true)
  +    , fIncludeIgnorableWhitespace(true)
  +    , fParseInProgress(false)
  +    , fWithinElement(false)
  +    , fEntityResolver(0)
  +    , fErrorHandler(0)
  +    , fNodeStack(0)
  +    , fScanner(0)
  +    , fDocumentType(0)
  +    , fGrammarResolver(0)
  +    , fURIStringPool(0)
  +    , fValidator(valToAdopt)
   {
  -    //
  +    try
  +    {
  +        initialize();
  +    }
  +    catch(...)
  +    {
  +        cleanUp();
  +        throw;
  +    }
  +}
  +
  +
  +DOMParser::~DOMParser()
  +{
  +    cleanUp();
  +}
  +
  +// ---------------------------------------------------------------------------
  +//  DOMParser: Initialize/CleanUp methods
  +// ---------------------------------------------------------------------------
  +void DOMParser::initialize()
  +{
  +    // Create grammar resolver and URI string pool to pass to the scanner
  +    fGrammarResolver = new GrammarResolver();
  +    fURIStringPool = new XMLStringPool();
  +
       //  Create a scanner and tell it what validator to use. Then set us
       //  as the document event handler so we can fill the DOM document.
  -    //
  -    fScanner = new XMLScanner(valToAdopt);
  +    fScanner = XMLScannerResolver::getDefaultScanner(fValidator);
       fScanner->setDocHandler(this);
       fScanner->setDocTypeHandler(this);
  +    fScanner->setGrammarResolver(fGrammarResolver);
  +    fScanner->setURIStringPool(fURIStringPool);
   
       fNodeStack = new ValueStackOf<DOM_Node>(64);
       this->reset();
  -
  -
   }
   
  -
  -DOMParser::~DOMParser()
  -{
  +void DOMParser::cleanUp()
  +{    
       delete fNodeStack;
       delete fScanner;
  -}
  +    delete fGrammarResolver;
  +    delete fURIStringPool;
   
  +    if (fValidator)
  +        delete fValidator;
  +}
   
   void DOMParser::reset()
   {
  @@ -221,7 +255,7 @@
   
   Grammar* DOMParser::getGrammar(const XMLCh* const nameSpaceKey)
   {
  -    return fScanner->getGrammar(nameSpaceKey);
  +    return fGrammarResolver->getGrammar(nameSpaceKey);
   }
   
   Grammar* DOMParser::getRootGrammar()
  @@ -234,6 +268,10 @@
       return fScanner->getURIText(uriId);
   }
   
  +bool DOMParser::getCalculateSrcOfs() const
  +{
  +    return fScanner->getCalculateSrcOfs();
  +}
   
   // ---------------------------------------------------------------------------
   //  DOMParser: Setter methods
  @@ -329,6 +367,24 @@
           fScanner->useCachedGrammarInParse(newState);
   }
   
  +void DOMParser::setCalculateSrcOfs(const bool newState)
  +{
  +    fScanner->setCalculateSrcOfs(newState);
  +}
  +
  +void DOMParser::useScanner(const XMLCh* const scannerName)
  +{
  +    XMLScanner* tempScanner = XMLScannerResolver::resolveScanner(scannerName, 
fValidator);
  +
  +    if (tempScanner) {
  +
  +        // REVISIT: need to set scanner options and handlers
  +        delete fScanner;
  +        fScanner = tempScanner;
  +        fScanner->setGrammarResolver(fGrammarResolver);
  +        fScanner->setURIStringPool(fURIStringPool);
  +    }
  +}
   
   // ---------------------------------------------------------------------------
   //  DOMParser: Parsing methods
  @@ -1340,7 +1396,7 @@
   
   void DOMParser::resetCachedGrammarPool()
   {
  -    fScanner->resetCachedGrammarPool();
  +    fGrammarResolver->resetCachedGrammar();
   }
   
   XERCES_CPP_NAMESPACE_END
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to