You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2002/07/11 20:27:04 UTC
cvs commit: xml-xerces/c/src/xercesc/parsers XercesDOMParser.hpp XercesDOMParser.cpp SAXParser.hpp SAXParser.cpp SAX2XMLReaderImpl.hpp
knoaman 2002/07/11 11:27:04
Modified: c/src/xercesc/parsers XercesDOMParser.hpp
XercesDOMParser.cpp SAXParser.hpp SAXParser.cpp
SAX2XMLReaderImpl.hpp
Log:
Grammar caching/preparsing - initial implementation.
Revision Changes Path
1.10 +189 -1 xml-xerces/c/src/xercesc/parsers/XercesDOMParser.hpp
Index: XercesDOMParser.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/XercesDOMParser.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XercesDOMParser.hpp 25 Jun 2002 15:58:54 -0000 1.9
+++ XercesDOMParser.hpp 11 Jul 2002 18:27:03 -0000 1.10
@@ -67,6 +67,7 @@
class EntityResolver;
class ErrorHandler;
+class Grammar;
/**
@@ -150,6 +151,53 @@
*/
const EntityResolver* getEntityResolver() const;
+ /** Get the 'Grammar caching' flag
+ *
+ * This method returns the state of the parser's grammar caching when
+ * parsing an XML document.
+ *
+ * @return true, if the parser is currently configured to
+ * cache grammars, false otherwise.
+ *
+ * @see #cacheGrammarFromParse
+ */
+ bool isCachingGrammarFromParse() const;
+
+ /** Get the 'Use cached grammar' flag
+ *
+ * This method returns the state of the parser's use of cached grammar
+ * when parsing an XML document.
+ *
+ * @return true, if the parser is currently configured to
+ * use cached grammars, false otherwise.
+ *
+ * @see #useCachedGrammarInParse
+ */
+ bool isUsingCachedGrammarInParse() const;
+
+ /**
+ * Retrieve the grammar that is associated with the specified namespace key
+ *
+ * @param nameSpaceKey Namespace key
+ * @return Grammar associated with the Namespace key.
+ */
+ Grammar* getGrammar(const XMLCh* const nameSpaceKey);
+
+ /**
+ * Retrieve the grammar where the root element is declared.
+ *
+ * @return Grammar where root element declared
+ */
+ Grammar* getRootGrammar();
+
+ /**
+ * Returns the string corresponding to a URI id from the URI string pool.
+ *
+ * @param uriId id of the string in the URI string pool.
+ * @return URI string corresponding to the URI id.
+ */
+ const XMLCh* getURIText(unsigned int uriId);
+
//@}
@@ -192,6 +240,45 @@
*/
void setEntityResolver(EntityResolver* const handler);
+ /** Set the 'Grammar caching' flag
+ *
+ * This method allows users to enable or disable caching of grammar when
+ * parsing XML documents. When set to true, the parser will cache the
+ * resulting grammar for use in subsequent parses.
+ *
+ * If the flag is set to true, the 'Use cached grammar' flag will also be
+ * set to true.
+ *
+ * The parser's default state is: false.
+ *
+ * @param newState The value specifying whether we should cache grammars
+ * or not.
+ *
+ * @see #isCachingGrammarFromParse
+ * @see #useCachedGrammarInParse
+ */
+ void cacheGrammarFromParse(const bool newState);
+
+ /** Set the 'Use cached grammar' flag
+ *
+ * This method allows users to enable or disable the use of cached
+ * grammars. When set to true, the parser will use the cached grammar,
+ * instead of building the grammar from scratch, to validate XML
+ * documents.
+ *
+ * If the 'Grammar caching' flag is set to true, this mehod ignore the
+ * value passed in.
+ *
+ * The parser's default state is: false.
+ *
+ * @param newState The value specifying whether we should use the cached
+ * grammar or not.
+ *
+ * @see #isUsingCachedGrammarInParse
+ * @see #cacheGrammarFromParse
+ */
+ void useCachedGrammarInParse(const bool newState);
+
//@}
// -----------------------------------------------------------------------
@@ -375,6 +462,107 @@
* being parsed.
*/
virtual void startInputSource(const InputSource& inputSource);
+
+ //@}
+
+ // -----------------------------------------------------------------------
+ // Grammar preparsing interface
+ // -----------------------------------------------------------------------
+
+ /** @name Implementation of Grammar preparsing interface's. */
+ //@{
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via an input source
+ * object.
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the SAX InputSource parameter. If the 'toCache' flag
+ * is enabled, the parser will cache the grammars for re-use. If a grammar
+ * key is found in the pool, no caching of any grammar will take place.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param source A const reference to the SAX InputSource object which
+ * points to the schema grammar file to be preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ *
+ * @see InputSource#InputSource
+ */
+ Grammar* loadGrammar(const InputSource& source,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the file path parameter. If the 'toCache' flag
+ * is enabled, the parser will cache the grammars for re-use. If a grammar
+ * key is found in the pool, no caching of any grammar will take place.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param systemId A const XMLCh pointer to the Unicode string which
+ * contains the path to the XML grammar file to be
+ * preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ */
+ Grammar* loadGrammar(const XMLCh* const systemId,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the file path parameter. If the 'toCache' flag
+ * is enabled, the parser will cache the grammars for re-use. If a grammar
+ * key is found in the pool, no caching of any grammar will take place.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param systemId A const char pointer to a native string which contains
+ * the path to the XML grammar file to be preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ */
+ Grammar* loadGrammar(const char* const systemId,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * This method allows the user to reset the pool of cached grammars.
+ */
+ void resetCachedGrammarPool();
//@}
1.7 +127 -1 xml-xerces/c/src/xercesc/parsers/XercesDOMParser.cpp
Index: XercesDOMParser.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/XercesDOMParser.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XercesDOMParser.cpp 25 Jun 2002 15:58:54 -0000 1.6
+++ XercesDOMParser.cpp 11 Jul 2002 18:27:03 -0000 1.7
@@ -71,6 +71,7 @@
#include <xercesc/sax/EntityResolver.hpp>
#include <xercesc/sax/ErrorHandler.hpp>
#include <xercesc/sax/SAXParseException.hpp>
+#include <xercesc/util/IOException.hpp>
#include <xercesc/internal/XMLScanner.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
@@ -93,6 +94,35 @@
// ---------------------------------------------------------------------------
+// XercesDOMParser: Getter methods
+// ---------------------------------------------------------------------------
+bool XercesDOMParser::isCachingGrammarFromParse() const
+{
+ return getScanner()->isCachingGrammarFromParse();
+}
+
+bool XercesDOMParser::isUsingCachedGrammarInParse() const
+{
+ return getScanner()->isUsingCachedGrammarInParse();
+}
+
+Grammar* XercesDOMParser::getGrammar(const XMLCh* const nameSpaceKey)
+{
+ return getScanner()->getGrammar(nameSpaceKey);
+}
+
+Grammar* XercesDOMParser::getRootGrammar()
+{
+ return getScanner()->getRootGrammar();
+}
+
+const XMLCh* XercesDOMParser::getURIText(unsigned int uriId)
+{
+ return getScanner()->getURIText(uriId);
+}
+
+
+// ---------------------------------------------------------------------------
// XercesDOMParser: Setter methods
// ---------------------------------------------------------------------------
void XercesDOMParser::setErrorHandler(ErrorHandler* const handler)
@@ -120,6 +150,20 @@
}
}
+void XercesDOMParser::cacheGrammarFromParse(const bool newState)
+{
+ getScanner()->cacheGrammarFromParse(newState);
+
+ if (newState)
+ getScanner()->useCachedGrammarInParse(newState);
+}
+
+void XercesDOMParser::useCachedGrammarInParse(const bool newState)
+{
+ if (newState || !getScanner()->isCachingGrammarFromParse())
+ getScanner()->useCachedGrammarInParse(newState);
+}
+
// ---------------------------------------------------------------------------
// XercesDOMParser: Utilities
@@ -192,3 +236,85 @@
return 0;
}
+// ---------------------------------------------------------------------------
+// XercesDOMParser: Grammar preparsing methods
+// ---------------------------------------------------------------------------
+Grammar* XercesDOMParser::loadGrammar(const char* const systemId,
+ const short grammarType,
+ const bool toCache)
+{
+ // Avoid multiple entrance
+ if (getParseInProgress())
+ ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
+
+ Grammar* grammar = 0;
+ try
+ {
+ setParseInProgress(true);
+ grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
+ setParseInProgress(false);
+ }
+
+ catch(...)
+ {
+ setParseInProgress(false);
+ throw;
+ }
+
+ return grammar;
+}
+
+Grammar* XercesDOMParser::loadGrammar(const XMLCh* const systemId,
+ const short grammarType,
+ const bool toCache)
+{
+ // Avoid multiple entrance
+ if (getParseInProgress())
+ ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
+
+ Grammar* grammar = 0;
+ try
+ {
+ setParseInProgress(true);
+ grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
+ setParseInProgress(false);
+ }
+
+ catch(...)
+ {
+ setParseInProgress(false);
+ throw;
+ }
+
+ return grammar;
+}
+
+Grammar* XercesDOMParser::loadGrammar(const InputSource& source,
+ const short grammarType,
+ const bool toCache)
+{
+ // Avoid multiple entrance
+ if (getParseInProgress())
+ ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
+
+ Grammar* grammar = 0;
+ try
+ {
+ setParseInProgress(true);
+ grammar = getScanner()->loadGrammar(source, grammarType, toCache);
+ setParseInProgress(false);
+ }
+
+ catch(...)
+ {
+ setParseInProgress(false);
+ throw;
+ }
+
+ return grammar;
+}
+
+void XercesDOMParser::resetCachedGrammarPool()
+{
+ getScanner()->resetCachedGrammarPool();
+}
1.12 +193 -24 xml-xerces/c/src/xercesc/parsers/SAXParser.hpp
Index: SAXParser.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAXParser.hpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SAXParser.hpp 27 Jun 2002 18:48:04 -0000 1.11
+++ SAXParser.hpp 11 Jul 2002 18:27:03 -0000 1.12
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.12 2002/07/11 18:27:03 knoaman
+ * Grammar caching/preparsing - initial implementation.
+ *
* Revision 1.11 2002/06/27 18:48:04 tng
* API Documentation Update and move getScanner as protected
*
@@ -186,6 +189,7 @@
class XMLPScanToken;
class XMLScanner;
class XMLValidator;
+class Grammar;
/**
@@ -440,6 +444,52 @@
*/
bool getLoadExternalDTD() const;
+ /** Get the 'Grammar caching' flag
+ *
+ * This method returns the state of the parser's grammar caching when
+ * parsing an XML document.
+ *
+ * @return true, if the parser is currently configured to
+ * cache grammars, false otherwise.
+ *
+ * @see #cacheGrammarFromParse
+ */
+ bool isCachingGrammarFromParse() const;
+
+ /** Get the 'Use cached grammar' flag
+ *
+ * This method returns the state of the parser's use of cached grammar
+ * when parsing an XML document.
+ *
+ * @return true, if the parser is currently configured to
+ * use cached grammars, false otherwise.
+ *
+ * @see #useCachedGrammarInParse
+ */
+ bool isUsingCachedGrammarInParse() const;
+
+ /**
+ * Retrieve the grammar that is associated with the specified namespace key
+ *
+ * @param nameSpaceKey Namespace key
+ * @return Grammar associated with the Namespace key.
+ */
+ Grammar* getGrammar(const XMLCh* const nameSpaceKey);
+
+ /**
+ * Retrieve the grammar where the root element is declared.
+ *
+ * @return Grammar where root element declared
+ */
+ Grammar* getRootGrammar();
+
+ /**
+ * Returns the string corresponding to a URI id from the URI string pool.
+ *
+ * @param uriId id of the string in the URI string pool.
+ * @return URI string corresponding to the URI id.
+ */
+ const XMLCh* getURIText(unsigned int uriId);
//@}
@@ -632,6 +682,45 @@
*/
void setLoadExternalDTD(const bool newState);
+ /** Set the 'Grammar caching' flag
+ *
+ * This method allows users to enable or disable caching of grammar when
+ * parsing XML documents. When set to true, the parser will cache the
+ * resulting grammar for use in subsequent parses.
+ *
+ * If the flag is set to true, the 'Use cached grammar' flag will also be
+ * set to true.
+ *
+ * The parser's default state is: false.
+ *
+ * @param newState The value specifying whether we should cache grammars
+ * or not.
+ *
+ * @see #isCachingGrammarFromParse
+ * @see #useCachedGrammarInParse
+ */
+ void cacheGrammarFromParse(const bool newState);
+
+ /** Set the 'Use cached grammar' flag
+ *
+ * This method allows users to enable or disable the use of cached
+ * grammars. When set to true, the parser will use the cached grammar,
+ * instead of building the grammar from scratch, to validate XML
+ * documents.
+ *
+ * If the 'Grammar caching' flag is set to true, this mehod ignore the
+ * value passed in.
+ *
+ * The parser's default state is: false.
+ *
+ * @param newState The value specifying whether we should use the cached
+ * grammar or not.
+ *
+ * @see #isUsingCachedGrammarInParse
+ * @see #cacheGrammarFromParse
+ */
+ void useCachedGrammarInParse(const bool newState);
+
//@}
@@ -694,9 +783,6 @@
* @param toFill A token maintaing state information to maintain
* internal consistency between invocation of 'parseNext'
* calls.
- * @param reuseGrammar The flag indicating whether the existing Grammar
- * should be reused or not for this parsing run.
- * If true, there cannot be any internal subset.
*
* @return 'true', if successful in parsing the prolog. It indicates the
* user can go ahead with parsing the rest of the file. It
@@ -711,7 +797,6 @@
(
const XMLCh* const systemId
, XMLPScanToken& toFill
- , const bool reuseGrammar = false
);
/** Begin a progressive parse operation
@@ -731,9 +816,6 @@
* @param toFill A token maintaing state information to maintain
* internal consIstency between invocation of 'parseNext'
* calls.
- * @param reuseGrammar The flag indicating whether the existing Grammar
- * should be reused or not for this parsing run.
- * If true, there cannot be any internal subset.
*
* @return 'true', if successful in parsing the prolog. It indicates the
* user can go ahead with parsing the rest of the file. It
@@ -748,7 +830,6 @@
(
const char* const systemId
, XMLPScanToken& toFill
- , const bool reuseGrammar = false
);
/** Begin a progressive parse operation
@@ -768,9 +849,6 @@
* @param toFill A token maintaing state information to maintain
* internal consistency between invocation of 'parseNext'
* calls.
- * @param reuseGrammar The flag indicating whether the existing Grammar
- * should be reused or not for this parsing run.
- * If true, there cannot be any internal subset.
*
* @return 'true', if successful in parsing the prolog. It indicates the
* user can go ahead with parsing the rest of the file. It
@@ -785,7 +863,6 @@
(
const InputSource& source
, XMLPScanToken& toFill
- , const bool reuseGrammar = false
);
/** Continue a progressive parse operation
@@ -839,6 +916,107 @@
//@}
+ // -----------------------------------------------------------------------
+ // Grammar preparsing interface
+ // -----------------------------------------------------------------------
+
+ /** @name Implementation of Grammar preparsing interface's. */
+ //@{
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via an input source
+ * object.
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the SAX InputSource parameter. If the 'toCache' flag
+ * is enabled, the parser will cache the grammars for re-use. If a grammar
+ * key is found in the pool, no caching of any grammar will take place.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param source A const reference to the SAX InputSource object which
+ * points to the schema grammar file to be preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ *
+ * @see InputSource#InputSource
+ */
+ Grammar* loadGrammar(const InputSource& source,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the file path parameter. If the 'toCache' flag
+ * is enabled, the parser will cache the grammars for re-use. If a grammar
+ * key is found in the pool, no caching of any grammar will take place.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param systemId A const XMLCh pointer to the Unicode string which
+ * contains the path to the XML grammar file to be
+ * preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ */
+ Grammar* loadGrammar(const XMLCh* const systemId,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the file path parameter. If the 'toCache' flag
+ * is enabled, the parser will cache the grammars for re-use. If a grammar
+ * key is found in the pool, no caching of any grammar will take place.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param systemId A const char pointer to a native string which contains
+ * the path to the XML grammar file to be preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ */
+ Grammar* loadGrammar(const char* const systemId,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * This method allows the user to reset the pool of cached grammars.
+ */
+ void resetCachedGrammarPool();
+
+ //@}
+
// -----------------------------------------------------------------------
// Implementation of the SAX Parser interface
@@ -852,13 +1030,10 @@
*
* @param source A const reference to the InputSource object which
* points to the XML file to be parsed.
- * @param reuseGrammar The flag indicating whether the existing Grammar
- * should be reused or not for this parsing run.
- * If true, there cannot be any internal subset.
*
* @see Parser#parse(InputSource)
*/
- virtual void parse(const InputSource& source, const bool reuseGrammar = false);
+ virtual void parse(const InputSource& source);
/**
* This method invokes the parsing process on the XML file specified by
@@ -866,13 +1041,10 @@
*
* @param systemId A const XMLCh pointer to the Unicode string which
* contains the path to the XML file to be parsed.
- * @param reuseGrammar The flag indicating whether the existing Grammar
- * should be reused or not for this parsing run.
- * If true, there cannot be any internal subset.
*
* @see Parser#parse(XMLCh*)
*/
- virtual void parse(const XMLCh* const systemId, const bool reuseGrammar = false);
+ virtual void parse(const XMLCh* const systemId);
/**
* This method invokes the parsing process on the XML file specified by
@@ -880,11 +1052,8 @@
*
* @param systemId A const char pointer to a native string which
* contains the path to the XML file to be parsed.
- * @param reuseGrammar The flag indicating whether the existing Grammar
- * should be reused or not for this parsing run.
- * If true, there cannot be any internal subset.
*/
- virtual void parse(const char* const systemId, const bool reuseGrammar = false);
+ virtual void parse(const char* const systemId);
/**
* This method installs the user specified SAX Document Handler
1.7 +137 -15 xml-xerces/c/src/xercesc/parsers/SAXParser.cpp
Index: SAXParser.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAXParser.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SAXParser.cpp 30 May 2002 16:20:09 -0000 1.6
+++ SAXParser.cpp 11 Jul 2002 18:27:04 -0000 1.7
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.7 2002/07/11 18:27:04 knoaman
+ * Grammar caching/preparsing - initial implementation.
+ *
* Revision 1.6 2002/05/30 16:20:09 tng
* Add feature to optionally ignore external DTD.
*
@@ -375,6 +378,30 @@
return fScanner->getLoadExternalDTD();
}
+bool SAXParser::isCachingGrammarFromParse() const
+{
+ return fScanner->isCachingGrammarFromParse();
+}
+
+bool SAXParser::isUsingCachedGrammarInParse() const
+{
+ return fScanner->isUsingCachedGrammarInParse();
+}
+
+Grammar* SAXParser::getGrammar(const XMLCh* const nameSpaceKey)
+{
+ return fScanner->getGrammar(nameSpaceKey);
+}
+
+Grammar* SAXParser::getRootGrammar()
+{
+ return fScanner->getRootGrammar();
+}
+
+const XMLCh* SAXParser::getURIText(unsigned int uriId)
+{
+ return fScanner->getURIText(uriId);
+}
// ---------------------------------------------------------------------------
// SAXParser: Setter methods
@@ -440,11 +467,25 @@
fScanner->setLoadExternalDTD(newState);
}
+void SAXParser::cacheGrammarFromParse(const bool newState)
+{
+ fScanner->cacheGrammarFromParse(newState);
+
+ if (newState)
+ fScanner->useCachedGrammarInParse(newState);
+}
+
+void SAXParser::useCachedGrammarInParse(const bool newState)
+{
+ if (newState || !fScanner->isCachingGrammarFromParse())
+ fScanner->useCachedGrammarInParse(newState);
+}
+
// ---------------------------------------------------------------------------
// SAXParser: Overrides of the SAX Parser interface
// ---------------------------------------------------------------------------
-void SAXParser::parse(const InputSource& source, const bool reuseGrammar)
+void SAXParser::parse(const InputSource& source)
{
// Avoid multiple entrance
if (fParseInProgress)
@@ -453,7 +494,7 @@
try
{
fParseInProgress = true;
- fScanner->scanDocument(source, reuseGrammar);
+ fScanner->scanDocument(source);
fParseInProgress = false;
}
@@ -464,7 +505,7 @@
}
}
-void SAXParser::parse(const XMLCh* const systemId, const bool reuseGrammar)
+void SAXParser::parse(const XMLCh* const systemId)
{
// Avoid multiple entrance
if (fParseInProgress)
@@ -473,7 +514,7 @@
try
{
fParseInProgress = true;
- fScanner->scanDocument(systemId, reuseGrammar);
+ fScanner->scanDocument(systemId);
fParseInProgress = false;
}
@@ -484,7 +525,7 @@
}
}
-void SAXParser::parse(const char* const systemId, const bool reuseGrammar)
+void SAXParser::parse(const char* const systemId)
{
// Avoid multiple entrance
if (fParseInProgress)
@@ -493,7 +534,7 @@
try
{
fParseInProgress = true;
- fScanner->scanDocument(systemId, reuseGrammar);
+ fScanner->scanDocument(systemId);
fParseInProgress = false;
}
@@ -573,8 +614,7 @@
// SAXParser: Progressive parse methods
// ---------------------------------------------------------------------------
bool SAXParser::parseFirst( const XMLCh* const systemId
- , XMLPScanToken& toFill
- , const bool reuseGrammar)
+ , XMLPScanToken& toFill)
{
//
// Avoid multiple entrance. We cannot enter here while a regular parse
@@ -583,12 +623,11 @@
if (fParseInProgress)
ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
- return fScanner->scanFirst(systemId, toFill, reuseGrammar);
+ return fScanner->scanFirst(systemId, toFill);
}
bool SAXParser::parseFirst( const char* const systemId
- , XMLPScanToken& toFill
- , const bool reuseGrammar)
+ , XMLPScanToken& toFill)
{
//
// Avoid multiple entrance. We cannot enter here while a regular parse
@@ -597,12 +636,11 @@
if (fParseInProgress)
ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
- return fScanner->scanFirst(systemId, toFill, reuseGrammar);
+ return fScanner->scanFirst(systemId, toFill);
}
bool SAXParser::parseFirst( const InputSource& source
- , XMLPScanToken& toFill
- , const bool reuseGrammar)
+ , XMLPScanToken& toFill)
{
//
// Avoid multiple entrance. We cannot enter here while a regular parse
@@ -611,7 +649,7 @@
if (fParseInProgress)
ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
- return fScanner->scanFirst(source, toFill, reuseGrammar);
+ return fScanner->scanFirst(source, toFill);
}
bool SAXParser::parseNext(XMLPScanToken& token)
@@ -1128,4 +1166,88 @@
(
newState ? XMLScanner::Val_Always : XMLScanner::Val_Never
);
+}
+
+
+// ---------------------------------------------------------------------------
+// SAXParser: Grammar preparsing methods
+// ---------------------------------------------------------------------------
+Grammar* SAXParser::loadGrammar(const char* const systemId,
+ const short grammarType,
+ const bool toCache)
+{
+ // Avoid multiple entrance
+ if (fParseInProgress)
+ ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
+
+ Grammar* grammar = 0;
+ try
+ {
+ fParseInProgress = true;
+ grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
+ fParseInProgress = false;
+ }
+
+ catch(...)
+ {
+ fParseInProgress = false;
+ throw;
+ }
+
+ return grammar;
+}
+
+Grammar* SAXParser::loadGrammar(const XMLCh* const systemId,
+ const short grammarType,
+ const bool toCache)
+{
+ // Avoid multiple entrance
+ if (fParseInProgress)
+ ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
+
+ Grammar* grammar = 0;
+ try
+ {
+ fParseInProgress = true;
+ grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
+ fParseInProgress = false;
+ }
+
+ catch(...)
+ {
+ fParseInProgress = false;
+ throw;
+ }
+
+ return grammar;
+}
+
+Grammar* SAXParser::loadGrammar(const InputSource& source,
+ const short grammarType,
+ const bool toCache)
+{
+ // Avoid multiple entrance
+ if (fParseInProgress)
+ ThrowXML(IOException, XMLExcepts::Gen_ParseInProgress);
+
+ Grammar* grammar = 0;
+ try
+ {
+ fParseInProgress = true;
+ grammar = fScanner->loadGrammar(source, grammarType, toCache);
+ fParseInProgress = false;
+ }
+
+ catch(...)
+ {
+ fParseInProgress = false;
+ throw;
+ }
+
+ return grammar;
+}
+
+void SAXParser::resetCachedGrammarPool()
+{
+ fScanner->resetCachedGrammarPool();
}
1.12 +137 -1 xml-xerces/c/src/xercesc/parsers/SAX2XMLReaderImpl.hpp
Index: SAX2XMLReaderImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/parsers/SAX2XMLReaderImpl.hpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SAX2XMLReaderImpl.hpp 27 Jun 2002 18:47:32 -0000 1.11
+++ SAX2XMLReaderImpl.hpp 11 Jul 2002 18:27:04 -0000 1.12
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.12 2002/07/11 18:27:04 knoaman
+ * Grammar caching/preparsing - initial implementation.
+ *
* Revision 1.11 2002/06/27 18:47:32 tng
* API Documentation Update.
*
@@ -609,6 +612,30 @@
* @see #getFeature
*/
virtual bool getValidationConstraintFatal() const ;
+
+ /**
+ * Retrieve the grammar that is associated with the specified namespace key
+ *
+ * @param nameSpaceKey Namespace key
+ * @return Grammar associated with the Namespace key.
+ */
+ virtual Grammar* getGrammar(const XMLCh* const nameSpaceKey);
+
+ /**
+ * Retrieve the grammar where the root element is declared.
+ *
+ * @return Grammar where root element declared
+ */
+ virtual Grammar* getRootGrammar();
+
+ /**
+ * Returns the string corresponding to a URI id from the URI string pool.
+ *
+ * @param uriId id of the string in the URI string pool.
+ * @return URI string corresponding to the URI id.
+ */
+ virtual const XMLCh* getURIText(unsigned int uriId);
+
//@}
// -----------------------------------------------------------------------
@@ -836,6 +863,101 @@
//@}
+ // -----------------------------------------------------------------------
+ // Implementation of the grammar preparsing interface
+ // -----------------------------------------------------------------------
+
+ /** @name Implementation of Grammar preparsing interface's. */
+ //@{
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via an input source
+ * object.
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the SAX InputSource parameter.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param source A const reference to the SAX InputSource object which
+ * points to the schema grammar file to be preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ *
+ * @see InputSource#InputSource
+ */
+ virtual Grammar* loadGrammar(const InputSource& source,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the file path parameter.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param systemId A const XMLCh pointer to the Unicode string which
+ * contains the path to the XML grammar file to be
+ * preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ */
+ virtual Grammar* loadGrammar(const XMLCh* const systemId,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Preparse schema grammar (XML Schema, DTD, etc.) via a file path or URL
+ *
+ * This method invokes the preparsing process on a schema grammar XML
+ * file specified by the file path parameter.
+ *
+ * <p><b>"Experimental - subject to change"</b></p>
+ *
+ * @param systemId A const char pointer to a native string which contains
+ * the path to the XML grammar file to be preparsed.
+ * @param grammarType The grammar type (Schema or DTD).
+ * @param toCache If <code>true</code>, we cache the preparsed grammar,
+ * otherwise, no chaching. Default is <code>false</code>.
+ * @return The preparsed schema grammar object (SchemaGrammar or
+ * DTDGrammar). That grammar object is owned by the parser.
+ *
+ * @exception SAXException Any SAX exception, possibly
+ * wrapping another exception.
+ * @exception XMLException An exception from the parser or client
+ * handler code.
+ * @exception DOMException A DOM exception as per DOM spec.
+ */
+ virtual Grammar* loadGrammar(const char* const systemId,
+ const short grammarType,
+ const bool toCache = false);
+
+ /**
+ * Clear the cached grammar pool
+ */
+ virtual void resetCachedGrammarPool();
+
+ //@}
+
// -----------------------------------------------------------------------
// Advanced document handler list maintenance methods
@@ -1595,7 +1717,6 @@
bool fnamespacePrefix;
bool fautoValidation;
bool fValidation;
- bool fReuseGrammar;
XMLBufferMgr fStringBuffers ;
RefStackOf<XMLBuffer> * fPrefixes ;
@@ -1667,6 +1788,21 @@
inline bool SAX2XMLReaderImpl::getValidationConstraintFatal() const
{
return fScanner->getValidationConstraintFatal();
+}
+
+inline Grammar* SAX2XMLReaderImpl::getGrammar(const XMLCh* const nameSpaceKey)
+{
+ return fScanner->getGrammar(nameSpaceKey);
+}
+
+inline Grammar* SAX2XMLReaderImpl::getRootGrammar()
+{
+ return fScanner->getRootGrammar();
+}
+
+inline const XMLCh* SAX2XMLReaderImpl::getURIText(unsigned int uriId)
+{
+ return fScanner->getURIText(uriId);
}
#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org