/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * $Id: SAX2XMLReaderImpl.hpp 569031 2007-08-23 15:05:28Z amassari $ */ #if !defined(SAX2XMLReaderImpl_HPP) #define SAX2XMLReaderImpl_HPP #include #include #include #include #include #include #include #include XERCES_CPP_NAMESPACE_BEGIN class ContentHandler; class LexicalHandler; class DeclHandler; class GrammarResolver; class XMLGrammarPool; class XMLResourceIdentifier; class PSVIHandler; /** * This class implements the SAX2 'XMLReader' interface and should be * used by applications wishing to parse the XML files using SAX2. * It allows the client program to install SAX2 handlers for event * callbacks. * *

It can be used to instantiate a validating or non-validating * parser, by setting a member flag.

* * we basically re-use the existing SAX1 parser code, but provide a * new implementation of XMLContentHandler that raises the new * SAX2 style events * */ class PARSERS_EXPORT SAX2XMLReaderImpl : public XMemory , public SAX2XMLReader , public XMLDocumentHandler , public XMLErrorReporter , public XMLEntityHandler , public DocTypeHandler { public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- /** @name Constructors and Destructor */ //@{ /** The default constructor */ SAX2XMLReaderImpl( MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager , XMLGrammarPool* const gramPool = 0 ); /** The destructor */ ~SAX2XMLReaderImpl() ; //@} //----------------------------------------------------------------------- // Implementation of SAX2XMLReader Interface //----------------------------------------------------------------------- //----------------------------------------------------------------------- // The XMLReader interface //----------------------------------------------------------------------- /** @name Implementation of SAX 2.0 XMLReader interface's. */ //@{ /** * This method returns the installed content handler. * * @return A pointer to the installed content handler object. */ virtual ContentHandler* getContentHandler() const ; /** * This method returns the installed DTD handler. * * @return A pointer to the installed DTD handler object. */ virtual DTDHandler* getDTDHandler() const ; /** * This method returns the installed entity resolver. * * @return A pointer to the installed entity resolver object. */ virtual EntityResolver* getEntityResolver() const ; /** * This method returns the installed entity resolver. * * @return A pointer to the installed entity resolver object. */ virtual XMLEntityResolver* getXMLEntityResolver() const ; /** * This method returns the installed error handler. * * @return A pointer to the installed error handler object. */ virtual ErrorHandler* getErrorHandler() const ; /** * This method returns the installed PSVI handler. * * @return A pointer to the installed PSVI handler object. */ virtual PSVIHandler* getPSVIHandler() const ; /** * Query the current state of any feature in a SAX2 XMLReader. * * @param name The unique identifier (URI) of the feature being set. * @return The current state of the feature. * @exception SAXNotRecognizedException If the requested feature is not known. */ virtual bool getFeature(const XMLCh* const name) const ; /** * Query the current value of a property in a SAX2 XMLReader. * * The parser owns the returned pointer. The memory allocated for * the returned pointer will be destroyed when the parser is deleted. * * To ensure assessiblity of the returned information after the parser * is deleted, callers need to copy and store the returned information * somewhere else; otherwise you may get unexpected result. Since the returned * pointer is a generic void pointer, see * http://xerces.apache.org/xerces-c/program-sax2.html#SAX2Properties to learn * exactly what type of property value each property returns for replication. * * @param name The unique identifier (URI) of the property being set. * @return The current value of the property. The pointer spans the same * life-time as the parser. A null pointer is returned if nothing * was specified externally. * @exception SAXNotRecognizedException If the requested property is not known. */ virtual void* getProperty(const XMLCh* const name) const ; /** * Allow an application to register a document event handler. * * If the application does not register a document handler, all * document events reported by the SAX parser will be silently * ignored (this is the default behaviour implemented by * HandlerBase). * * Applications may register a new or different handler in the * middle of a parse, and the SAX parser must begin using the new * handler immediately. * * @param handler The document handler. * @see DocumentHandler#DocumentHandler * @see HandlerBase#HandlerBase */ virtual void setContentHandler(ContentHandler* const handler) ; /** * Allow an application to register a DTD event handler. * * If the application does not register a DTD handler, all DTD * events reported by the SAX parser will be silently ignored (this * is the default behaviour implemented by HandlerBase). * * Applications may register a new or different handler in the middle * of a parse, and the SAX parser must begin using the new handler * immediately. * * @param handler The DTD handler. * @see DTDHandler#DTDHandler * @see HandlerBase#HandlerBase */ virtual void setDTDHandler(DTDHandler* const handler) ; /** * Allow an application to register a custom entity resolver. * * If the application does not register an entity resolver, the * SAX parser will resolve system identifiers and open connections * to entities itself (this is the default behaviour implemented in * DefaultHandler). * * Applications may register a new or different entity resolver * in the middle of a parse, and the SAX parser must begin using * the new resolver immediately. * * Any previously set entity resolver is merely dropped, since the parser * does not own them. If both setEntityResolver and setXMLEntityResolver * are called, then the last one is used. * * @param resolver The object for resolving entities. * @see EntityResolver#EntityResolver * @see DefaultHandler#DefaultHandler */ virtual void setEntityResolver(EntityResolver* const resolver) ; /** Set the entity resolver * * This method allows applications to install their own entity * resolver. By installing an entity resolver, the applications * can trap and potentially redirect references to external * entities. * * Any previously set entity resolver is merely dropped, since the parser * does not own them. If both setEntityResolver and setXMLEntityResolver * are called, then the last one is used. * * @param resolver A const pointer to the user supplied entity * resolver. * * @see #getXMLEntityResolver */ virtual void setXMLEntityResolver(XMLEntityResolver* const resolver) ; /** * Allow an application to register an error event handler. * * If the application does not register an error event handler, * all error events reported by the SAX parser will be silently * ignored, except for fatalError, which will throw a SAXException * (this is the default behaviour implemented by HandlerBase). * * Applications may register a new or different handler in the * middle of a parse, and the SAX parser must begin using the new * handler immediately. * * @param handler The error handler. * @see ErrorHandler#ErrorHandler * @see SAXException#SAXException * @see HandlerBase#HandlerBase */ virtual void setErrorHandler(ErrorHandler* const handler) ; /** * This method installs the user specified PSVI handler on * the parser. * * @param handler A pointer to the PSVI handler to be called * when the parser comes across 'PSVI' events * as per the schema specification. */ virtual void setPSVIHandler(PSVIHandler* const handler); /** * Set the state of any feature in a SAX2 XMLReader. * Supported features in SAX2 for xerces-c are: *
(See http://xerces.apache.org/xerces-c/program-sax2.html#SAX2Features for detail description). * *
http://xml.org/sax/features/validation (default: false) *
http://xml.org/sax/features/namespaces (default: true) *
http://xml.org/sax/features/namespace-prefixes (default: false) *
http://apache.org/xml/features/validation/dynamic (default: false) *
http://apache.org/xml/features/validation/reuse-grammar (default: false) *
http://apache.org/xml/features/validation/schema (default: true) *
http://apache.org/xml/features/validation/schema-full-checking (default: false) *
http://apache.org/xml/features/nonvalidating/load-external-dtd (default: true) *
http://apache.org/xml/features/continue-after-fatal-error (default: false) *
http://apache.org/xml/features/validation-error-as-fatal (default: false) *
http://apache.org/xml/features/validation/reuse-validator (Deprecated) (default: false) * * @param name The unique identifier (URI) of the feature. * @param value The requested state of the feature (true or false). * @exception SAXNotRecognizedException If the requested feature is not known. * @exception SAXNotSupportedException Feature modification is not supported during parse * */ virtual void setFeature(const XMLCh* const name, const bool value) ; /** * Set the value of any property in a SAX2 XMLReader. * Supported properties in SAX2 for xerces-c are: *
(See http://xerces.apache.org/xerces-c/program-sax2.html#SAX2Properties for detail description). * *
http://apache.org/xml/properties/schema/external-schemaLocation *
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation. * * It takes a void pointer as the property value. Application is required to initialize this void * pointer to a correct type. See http://xerces.apache.org/xerces-c/program-sax2.html#SAX2Properties * to learn exactly what type of property value each property expects for processing. * Passing a void pointer that was initialized with a wrong type will lead to unexpected result. * If the same property is set more than once, the last one takes effect. * * @param name The unique identifier (URI) of the property being set. * @param value The requested value for the property. See * http://xerces.apache.org/xerces-c/program-sax2.html#SAX2Properties to learn * exactly what type of property value each property expects for processing. * Passing a void pointer that was initialized with a wrong type will lead * to unexpected result. * @exception SAXNotRecognizedException If the requested property is not known. * @exception SAXNotSupportedException Property modification is not supported during parse */ virtual void setProperty(const XMLCh* const name, void* value) ; /** * Parse an XML document. * * The application can use this method to instruct the SAX parser * to begin parsing an XML document from any valid input * source (a character stream, a byte stream, or a URI). * * Applications may not invoke this method while a parse is in * progress (they should create a new Parser instead for each * additional XML document). Once a parse is complete, an * application may reuse the same Parser object, possibly with a * different input source. * * @param source The input source for the top-level of the * XML document. * @exception SAXException Any SAX exception, possibly * wrapping another exception. * @exception XMLException An exception from the parser or client * handler code. * @see InputSource#InputSource * @see #setEntityResolver * @see #setDTDHandler * @see #setDocumentHandler * @see #setErrorHandler */ virtual void parse ( const InputSource& source ) ; /** * Parse an XML document from a system identifier (URI). * * This method is a shortcut for the common case of reading a * document from a system identifier. It is the exact equivalent * of the following: * * parse(new URLInputSource(systemId)); * * If the system identifier is a URL, it must be fully resolved * by the application before it is passed to the parser. * * @param systemId The system identifier (URI). * @exception SAXException Any SAX exception, possibly * wrapping another exception. * @exception XMLException An exception from the parser or client * handler code. * @see #parse(InputSource) */ virtual void parse ( const XMLCh* const systemId ) ; /** * Parse an XML document from a system identifier (URI). * * This method is a shortcut for the common case of reading a * document from a system identifier. It is the exact equivalent * of the following: * * parse(new URLInputSource(systemId)); * * If the system identifier is a URL, it must be fully resolved * by the application before it is passed to the parser. * * @param systemId The system identifier (URI). * @exception SAXException Any SAX exception, possibly * wrapping another exception. * @exception XMLException An exception from the parser or client * handler code. * @see #parse(InputSource) */ virtual void parse ( const char* const systemId ) ; //@} // ----------------------------------------------------------------------- // SAX 2.0-ext // ----------------------------------------------------------------------- /** @name SAX 2.0-ext */ //@{ /** * This method returns the installed declaration handler. * * @return A pointer to the installed declaration handler object. */ virtual DeclHandler* getDeclarationHandler() const ; /** * This method returns the installed lexical handler. * * @return A pointer to the installed lexical handler object. */ virtual LexicalHandler* getLexicalHandler() const ; /** * Allow an application to register a declaration event handler. * * If the application does not register a declaration handler, * all events reported by the SAX parser will be silently * ignored. (this is the default behaviour implemented by DefaultHandler). * * Applications may register a new or different handler in the * middle of a parse, and the SAX parser must begin using the new * handler immediately. * * @param handler The DTD declaration handler. * @see DeclHandler#DeclHandler * @see SAXException#SAXException * @see DefaultHandler#DefaultHandler */ virtual void setDeclarationHandler(DeclHandler* const handler) ; /** * Allow an application to register a lexical event handler. * * If the application does not register a lexical handler, * all events reported by the SAX parser will be silently * ignored. (this is the default behaviour implemented by HandlerBase). * * Applications may register a new or different handler in the * middle of a parse, and the SAX parser must begin using the new * handler immediately. * * @param handler The error handler. * @see LexicalHandler#LexicalHandler * @see SAXException#SAXException * @see HandlerBase#HandlerBase */ virtual void setLexicalHandler(LexicalHandler* const handler) ; //@} // ----------------------------------------------------------------------- // Getter Methods // ----------------------------------------------------------------------- /** @name Getter Methods (Xerces-C specific) */ //@{ /** * This method is used to get the current validator. * * SAX2XMLReader assumes responsibility for the validator. It will be * deleted when the XMLReader is destroyed. * * @return A pointer to the validator. An application should not deleted * the object returned. * */ virtual XMLValidator* getValidator() const ; //@} /** Get error count from the last parse operation. * * This method returns the error count from the last parse * operation. Note that this count is actually stored in the * scanner, so this method simply returns what the * scanner reports. * * @return number of errors encountered during the latest * parse operation. */ virtual int getErrorCount() const ; /** * This method returns the state of the parser's * exit-on-First-Fatal-Error flag. * *

Or you can query the feature "http://apache.org/xml/features/continue-after-fatal-error" * which indicates the opposite state.

* * @return true, if the parser is currently configured to * exit on the first fatal error, false otherwise. * * @see #setExitOnFirstFatalError * @see #getFeature */ virtual bool getExitOnFirstFatalError() const ; /** * This method returns the state of the parser's * validation-constraint-fatal flag. * *

Or you can query the feature "http://apache.org/xml/features/validation-error-as-fatal" * which means the same thing. * * @return true, if the parser is currently configured to * set validation constraint errors as fatal, false * otherwise. * * @see #setValidationContraintFatal * @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) const; /** * Returns the current src offset within the input source. * To be used only while parsing is in progress. * * @return offset within the input source */ virtual unsigned int getSrcOffset() const; //@} // ----------------------------------------------------------------------- // Setter Methods // ----------------------------------------------------------------------- /** @name Setter Methods (Xerces-C specific) */ //@{ /** * This method is used to set a validator. * * SAX2XMLReader assumes responsibility for the validator. It will be * deleted when the XMLReader is destroyed. * * @param valueToAdopt A pointer to the validator that the reader should use. * */ virtual void setValidator(XMLValidator* valueToAdopt) ; /** * This method allows users to set the parser's behaviour when it * encounters the first fatal error. If set to true, the parser * will exit at the first fatal error. If false, then it will * report the error and continue processing. * *

The default value is 'true' and the parser exits on the * first fatal error.

* *

Or you can set the feature "http://apache.org/xml/features/continue-after-fatal-error" * which has the opposite behaviour.

* *

If both the feature above and this function are used, the latter takes effect.

* * @param newState The value specifying whether the parser should * continue or exit when it encounters the first * fatal error. * * @see #getExitOnFirstFatalError * @see #setFeature */ virtual void setExitOnFirstFatalError(const bool newState) ; /** * This method allows users to set the parser's behaviour when it * encounters a validtion constraint error. If set to true, and the * the parser will treat validation error as fatal and will exit depends on the * state of "getExitOnFirstFatalError". If false, then it will * report the error and continue processing. * * Note: setting this true does not mean the validation error will be printed with * the word "Fatal Error". It is still printed as "Error", but the parser * will exit if "setExitOnFirstFatalError" is set to true. * *

The default value is 'false'.

* *

Or you can set the feature "http://apache.org/xml/features/validation-error-as-fatal" * which means the same thing.

* *

If both the feature above and this function are used, the latter takes effect.

* * @param newState If true, the parser will exit if "setExitOnFirstFatalError" * is set to true. * * @see #getValidationConstraintFatal * @see #setExitOnFirstFatalError * @see #setFeature */ virtual void setValidationConstraintFatal(const bool newState) ; //@} // ----------------------------------------------------------------------- // Progressive scan methods // ----------------------------------------------------------------------- /** @name Progressive scan methods */ //@{ /** Begin a progressive parse operation * * This method is used to start a progressive parse on a XML file. * To continue parsing, subsequent calls must be to the parseNext * method. * * It scans through the prolog and returns a token to be used on * subsequent scanNext() calls. If the return value is true, then the * token is legal and ready for further use. If it returns false, then * the scan of the prolog failed and the token is not going to work on * subsequent scanNext() calls. * * @param systemId A pointer to a Unicode string represting the path * to the XML file to be parsed. * @param toFill A token maintaing state information to maintain * internal consistency between invocation of 'parseNext' * calls. * * @return 'true', if successful in parsing the prolog. It indicates the * user can go ahead with parsing the rest of the file. It * returns 'false' to indicate that the parser could parse the * prolog (which means the token will not be valid.) * * @see #parseNext * @see #parseFirst(char*,...) * @see #parseFirst(InputSource&,...) */ virtual bool parseFirst ( const XMLCh* const systemId , XMLPScanToken& toFill ) ; /** Begin a progressive parse operation * * This method is used to start a progressive parse on a XML file. * To continue parsing, subsequent calls must be to the parseNext * method. * * It scans through the prolog and returns a token to be used on * subsequent scanNext() calls. If the return value is true, then the * token is legal and ready for further use. If it returns false, then * the scan of the prolog failed and the token is not going to work on * subsequent scanNext() calls. * * @param systemId A pointer to a regular native string represting * the path to the XML file to be parsed. * @param toFill A token maintaing state information to maintain * internal consIstency between invocation of 'parseNext' * calls. * * @return 'true', if successful in parsing the prolog. It indicates the * user can go ahead with parsing the rest of the file. It * returns 'false' to indicate that the parser could not parse * the prolog. * * @see #parseNext * @see #parseFirst(XMLCh*,...) * @see #parseFirst(InputSource&,...) */ virtual bool parseFirst ( const char* const systemId , XMLPScanToken& toFill ) ; /** Begin a progressive parse operation * * This method is used to start a progressive parse on a XML file. * To continue parsing, subsequent calls must be to the parseNext * method. * * It scans through the prolog and returns a token to be used on * subsequent scanNext() calls. If the return value is true, then the * token is legal and ready for further use. If it returns false, then * the scan of the prolog failed and the token is not going to work on * subsequent scanNext() calls. * * @param source A const reference to the InputSource object which * points to the XML file to be parsed. * @param toFill A token maintaing state information to maintain * internal consistency between invocation of 'parseNext' * calls. * * @return 'true', if successful in parsing the prolog. It indicates the * user can go ahead with parsing the rest of the file. It * returns 'false' to indicate that the parser could not parse * the prolog. * * @see #parseNext * @see #parseFirst(XMLCh*,...) * @see #parseFirst(char*,...) */ virtual bool parseFirst ( const InputSource& source , XMLPScanToken& toFill ) ; /** Continue a progressive parse operation * * This method is used to continue with progressive parsing of * XML files started by a call to 'parseFirst' method. * * It parses the XML file and stops as soon as it comes across * a XML token (as defined in the XML specification). Relevant * callback handlers are invoked as required by the SAX * specification. * * @param token A token maintaing state information to maintain * internal consistency between invocation of 'parseNext' * calls. * * @return 'true', if successful in parsing the next XML token. * It indicates the user can go ahead with parsing the rest * of the file. It returns 'false' to indicate that the parser * could not find next token as per the XML specification * production rule. * * @see #parseFirst(XMLCh*,...) * @see #parseFirst(char*,...) * @see #parseFirst(InputSource&,...) */ virtual bool parseNext(XMLPScanToken& token) ; /** Reset the parser after a progressive parse * * If a progressive parse loop exits before the end of the document * is reached, the parser has no way of knowing this. So it will leave * open any files or sockets or memory buffers that were in use at * the time that the parse loop exited. * * The next parse operation will cause these open files and such to * be closed, but the next parse operation might occur at some unknown * future point. To avoid this problem, you should reset the parser if * you exit the loop early. * * If you exited because of an error, then this cleanup will be done * for you. Its only when you exit the file prematurely of your own * accord, because you've found what you wanted in the file most * likely. * * @param token A token maintaing state information to maintain * internal consistency between invocation of 'parseNext' * calls. */ virtual void parseReset(XMLPScanToken& token) ; //@} // ----------------------------------------------------------------------- // 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. * *

"Experimental - subject to change"

* * @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 true, we cache the preparsed grammar, * otherwise, no chaching. Default is false. * @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. * *

"Experimental - subject to change"

* * @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 true, we cache the preparsed grammar, * otherwise, no chaching. Default is false. * @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. * *

"Experimental - subject to change"

* * @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 true, we cache the preparsed grammar, * otherwise, no chaching. Default is false. * @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(); /** Set maximum input buffer size * * This method allows users to limit the size of buffers used in parsing * XML character data. The effect of setting this size is to limit the * size of a ContentHandler::characters() call. * * The parser's default input buffer size is 1 megabyte. * * @param bufferSize The maximum input buffer size */ virtual void setInputBufferSize(const size_t bufferSize); //@} // ----------------------------------------------------------------------- // Advanced document handler list maintenance methods // ----------------------------------------------------------------------- /** @name Advanced document handler list maintenance methods */ //@{ /** * This method installs the specified 'advanced' document callback * handler, thereby allowing the user to customize the processing, * if they choose to do so. Any number of advanced callback handlers * maybe installed. * *

The methods in the advanced callback interface represent * Xerces-C extensions. There is no specification for this interface.

* * @param toInstall A pointer to the users advanced callback handler. * * @see #removeAdvDocHandler */ virtual void installAdvDocHandler(XMLDocumentHandler* const toInstall) ; /** * This method removes the 'advanced' document handler callback from * the underlying parser scanner. If no handler is installed, advanced * callbacks are not invoked by the scanner. * @param toRemove A pointer to the advanced callback handler which * should be removed. * * @see #installAdvDocHandler */ virtual bool removeAdvDocHandler(XMLDocumentHandler* const toRemove) ; //@} // ----------------------------------------------------------------------- // Implementation of the XMLDocumentHandler interface // ----------------------------------------------------------------------- /** @name Implementation of the XMLDocumentHandler Interface. */ //@{ /** * This method is used to report all the characters scanned * by the parser. The driver will invoke the 'characters' * method of the user installed SAX Document Handler. * *

If any advanced callback handlers are installed, the * corresponding 'docCharacters' method will also be invoked.

* * @param chars A const pointer to a Unicode string representing the * character data. * @param length The length of the Unicode string returned in 'chars'. * @param cdataSection A flag indicating if the characters represent * content from the CDATA section. * @see DocumentHandler#characters */ virtual void docCharacters ( const XMLCh* const chars , const unsigned int length , const bool cdataSection ); /** * This method is used to report any comments scanned by the parser. * This method is a no-op unless, unless an advanced callback handler * is installed, in which case the corresponding 'docComment' method * is invoked. * * @param comment A const pointer to a null terminated Unicode * string representing the comment text. */ virtual void docComment ( const XMLCh* const comment ); /** * This method is used to report any PI scanned by the parser. * *

Any PI's occurring before any 'content' are not reported * to any SAX handler as per the specification. However, all * PI's within content are reported via the SAX Document Handler's * 'processingInstruction' method. * *

If any advanced callback handlers are installed, the * corresponding 'docPI' method will be invoked.

* * @param target A const pointer to a Unicode string representing the * target of the PI declaration. * @param data A const pointer to a Unicode string representing the * data of the PI declaration. See the PI production rule * in the XML specification for details. * * @see DocumentHandler#processingInstruction */ virtual void docPI ( const XMLCh* const target , const XMLCh* const data ); /** * This method is used to indicate the end of root element * was just scanned by the parser. Corresponding 'endDocument' * method of the user installed SAX Document Handler will also * be invoked. * *

In addition, if any advanced callback handlers are installed, * the corresponding 'endDocument' method is invoked.

* * @see DocumentHandler#endDocument */ virtual void endDocument(); /** * This method is used to indicate the end tag of an element. * The driver will invoke the corresponding 'endElement' method of * the SAX Document Handler interface. * *

If any advanced callback handlers are installed, the * corresponding 'endElement' method is also invoked.

* * @param elemDecl A const reference to the object containing element * declaration information. * @param urlId An id referring to the namespace prefix, if * namespaces setting is switched on. * @param isRoot A flag indicating whether this element was the * root element. * @param elemPrefix A const pointer to a Unicode string containing * the namespace prefix for this element. Applicable * only when namespace processing is enabled. * @see DocumentHandler#endElement */ virtual void endElement ( const XMLElementDecl& elemDecl , const unsigned int urlId , const bool isRoot , const XMLCh* const elemPrefix=0 ); /** * This method is used to indicate that an end of an entity reference * was just scanned. * *

If any advanced callback handlers are installed, the * corresponding 'endEnityReference' method is invoked.

* * @param entDecl A const reference to the object containing the * entity declaration information. */ virtual void endEntityReference ( const XMLEntityDecl& entDecl ); /** * This method is used to report all the whitespace characters, * which are determined to be 'ignorable'. This distinction * between characters is only made, if validation is enabled. * Corresponding 'ignorableWhitespace' method of the user installed * SAX Document Handler interface is called. * *

Any whitespace before content is not reported to the SAX * Document Handler method, as per the SAX specification. * However, if any advanced callback handlers are installed, the * corresponding 'ignorableWhitespace' method is invoked.

* * @param chars A const pointer to a Unicode string representing the * ignorable whitespace character data. * @param length The length of the Unicode string 'chars'. * @param cdataSection A flag indicating if the characters represent * content from the CDATA section. * @see DocumentHandler#ignorableWhitespace */ virtual void ignorableWhitespace ( const XMLCh* const chars , const unsigned int length , const bool cdataSection ); /** * This method allows the user installed Document Handler and * any advanced callback handlers to 'reset' themselves. */ virtual void resetDocument(); /** * This method is used to report the start of the parsing process. * The corresponding user installed SAX Document Handler's method * 'startDocument' is invoked. * *

If any advanced callback handlers are installed, then the * corresponding 'startDocument' method is also called.

* * @see DocumentHandler#startDocument */ virtual void startDocument(); /** * This method is used to report the start of an element. It is * called at the end of the element, by which time all attributes * specified are also parsed. The corresponding user installed * SAX Document Handler's method 'startElement' is invoked. * *

If any advanced callback handlers are installed, then the * corresponding 'startElement' method is also called.

* * @param elemDecl A const reference to the object containing element * declaration information. * @param urlId An id referring to the namespace prefix, if * namespaces setting is switched on. * @param elemPrefix A const pointer to a Unicode string containing * the namespace prefix for this element. Applicable * only when namespace processing is enabled. * @param attrList A const reference to the object containing the * list of attributes just scanned for this element. * @param attrCount A count of number of attributes in the list * specified by the parameter 'attrList'. * @param isEmpty A flag indicating whether this is an empty element * or not. * @param isRoot A flag indicating whether this element was the * root element. * @see DocumentHandler#startElement */ virtual void startElement ( const XMLElementDecl& elemDecl , const unsigned int urlId , const XMLCh* const elemPrefix , const RefVectorOf& attrList , const unsigned int attrCount , const bool isEmpty , const bool isRoot ); /** * This method is used to indicate the start of an entity reference. * *

If any advanced callback handlers are installed, the * corresponding 'endEnityReference' method is invoked.

* * @param entDecl A const reference to the object containing the * entity declaration information. */ virtual void startEntityReference ( const XMLEntityDecl& entDecl ); /** * This method is used to report the XML decl scanned by the parser. * Refer to the XML specification to see the meaning of parameters. * * This method is a no-op for this SAX driver * implementation. * * @param versionStr A const pointer to a Unicode string representing * version string value. * @param encodingStr A const pointer to a Unicode string representing * the encoding string value. * @param standaloneStr A const pointer to a Unicode string * representing the standalone string value. * @param actualEncodingStr A const pointer to a Unicode string * representing the actual encoding string * value. */ virtual void XMLDecl ( const XMLCh* const versionStr , const XMLCh* const encodingStr , const XMLCh* const standaloneStr , const XMLCh* const actualEncodingStr ); //@} // ----------------------------------------------------------------------- // Implementation of the XMLErrorReporter interface // ----------------------------------------------------------------------- /** @name Implementation of the XMLErrorReporter Interface. */ //@{ /** * This method is used to report back errors found while parsing the * XML file. The driver will call the corresponding user installed * SAX Error Handler methods: 'fatal', 'error', 'warning' depending * on the severity of the error. This classification is defined by * the XML specification. * * @param errCode An integer code for the error. * @param msgDomain A const pointer to an Unicode string representing * the message domain to use. * @param errType An enumeration classifying the severity of the error. * @param errorText A const pointer to an Unicode string representing * the text of the error message. * @param systemId A const pointer to an Unicode string representing * the system id of the XML file where this error * was discovered. * @param publicId A const pointer to an Unicode string representing * the public id of the XML file where this error * was discovered. * @param lineNum The line number where the error occurred. * @param colNum The column number where the error occurred. * @see ErrorHandler */ virtual void error ( const unsigned int errCode , const XMLCh* const msgDomain , const XMLErrorReporter::ErrTypes errType , const XMLCh* const errorText , const XMLCh* const systemId , const XMLCh* const publicId , const XMLSSize_t lineNum , const XMLSSize_t colNum ); /** * This method allows the user installed Error Handler * callback to 'reset' itself. * * This method is a no-op for this SAX driver * implementation. * */ virtual void resetErrors(); //@} // ----------------------------------------------------------------------- // Implementation of the XMLEntityHandler interface // ----------------------------------------------------------------------- /** @name Implementation of the XMLEntityHandler Interface. */ //@{ /** * This method is used to indicate the end of parsing of an external * entity file. * * This method is a no-op for this SAX driver * implementation. * * @param inputSource A const reference to the InputSource object * which points to the XML file being parsed. * @see InputSource */ virtual void endInputSource(const InputSource& inputSource); /** * This method allows an installed XMLEntityHandler to further * process any system id's of enternal entities encountered in * the XML file being parsed, such as redirection etc. * * This method always returns 'false' * for this SAX driver implementation. * * @param systemId A const pointer to an Unicode string representing * the system id scanned by the parser. * @param toFill A pointer to a buffer in which the application * processed system id is stored. * @return 'true', if any processing is done, 'false' otherwise. */ virtual bool expandSystemId ( const XMLCh* const systemId , XMLBuffer& toFill ); /** * This method allows the installed XMLEntityHandler to reset * itself. * * This method is a no-op for this SAX driver * implementation. */ virtual void resetEntities(); /** * This method allows a user installed entity handler to further * process any pointers to external entities. The applications * can implement 'redirection' via this callback. The driver * should call the SAX EntityHandler 'resolveEntity' method. * * @deprecated This method is no longer called (the other resolveEntity one is). * * @param publicId A const pointer to a Unicode string representing the * public id of the entity just parsed. * @param systemId A const pointer to a Unicode string representing the * system id of the entity just parsed. * @param baseURI A const pointer to a Unicode string representing the * base URI of the entity just parsed, * or null if there is no base URI. * @return The value returned by the SAX resolveEntity method or * NULL otherwise to indicate no processing was done. * The returned InputSource is owned by the parser which is * responsible to clean up the memory. * @see EntityResolver * @see XMLEntityHandler */ virtual InputSource* resolveEntity ( const XMLCh* const publicId , const XMLCh* const systemId , const XMLCh* const baseURI = 0 ); /** Resolve a public/system id * * This method allows a user installed entity handler to further * process any pointers to external entities. The applications can * implement 'redirection' via this callback. * * @param resourceIdentifier An object containing the type of * resource to be resolved and the associated data members * corresponding to this type. * @return The value returned by the user installed resolveEntity * method or NULL otherwise to indicate no processing was done. * The returned InputSource is owned by the parser which is * responsible to clean up the memory. * @see XMLEntityHandler * @see XMLEntityResolver */ virtual InputSource* resolveEntity ( XMLResourceIdentifier* resourceIdentifier ); /** * This method is used to indicate the start of parsing an * external entity file. * * This method is a no-op for this SAX driver * implementation. * * @param inputSource A const reference to the InputSource object * which points to the external entity * being parsed. */ virtual void startInputSource(const InputSource& inputSource); //@} // ----------------------------------------------------------------------- // Implementation of the Deprecated DocTypeHandler Interface // ----------------------------------------------------------------------- /** @name Implementation of the deprecated DocTypeHandler Interface */ //@{ /** * This method is used to report an attribute definition. * * This method is a no-op for this SAX * driver implementation. * * @param elemDecl A const reference to the object containing information * about the element whose attribute definition was just * parsed. * @param attDef A const reference to the object containing information * attribute definition. * @param ignore The flag indicating whether this attribute definition * was ignored by the parser or not. */ virtual void attDef ( const DTDElementDecl& elemDecl , const DTDAttDef& attDef , const bool ignoring ); /** * This method is used to report a comment occurring within the DTD. * * This method is a no-op for this SAX driver * implementation. * * @param comment A const pointer to a Unicode string representing the * text of the comment just parsed. */ virtual void doctypeComment ( const XMLCh* const comment ); /** * This method is used to report the DOCTYPE declaration. * * This method is a no-op for this SAX driver * implementation. * * @param elemDecl A const reference to the object containing information * about the root element definition declaration of the * XML document being parsed. * @param publicId A const pointer to a Unicode string representing the * public id of the DTD file. * @param systemId A const pointer to a Unicode string representing the * system id of the DTD file. * @param hasIntSubset A flag indicating if this XML file contains any * internal subset. * @param hasExtSubset A flag indicating if this XML file contains any * external subset. Default is false. */ virtual void doctypeDecl ( const DTDElementDecl& elemDecl , const XMLCh* const publicId , const XMLCh* const systemId , const bool hasIntSubset , const bool hasExtSubset = false ); /** * This method is used to report any PI declarations * occurring inside the DTD definition block. * * This method is a no-op for this SAX driver * implementation. * * @param target A const pointer to a Unicode string representing the * target of the PI declaration. * @param data A const pointer to a Unicode string representing the * data of the PI declaration. See the PI production rule * in the XML specification for details. */ virtual void doctypePI ( const XMLCh* const target , const XMLCh* const data ); /** * This method is used to report any whitespaces * occurring inside the DTD definition block. * * This method is a no-op for this SAX driver * implementation. * * @param chars A const pointer to a Unicode string representing the * whitespace characters. * @param length The length of the whitespace Unicode string. */ virtual void doctypeWhitespace ( const XMLCh* const chars , const unsigned int length ); /** * This method is used to report an element declarations * successfully scanned by the parser. * * This method is a no-op for this SAX driver * implementation. * * @param decl A const reference to the object containing element * declaration information. * @param isIgnored The flag indicating whether this definition was * ignored by the parser or not. */ virtual void elementDecl ( const DTDElementDecl& decl , const bool isIgnored ); /** * This method is used to report the end of an attribute * list declaration for an element. * * This method is a no-op for this SAX driver * implementation. * * @param elemDecl A const reference to the object containing element * declaration information. */ virtual void endAttList ( const DTDElementDecl& elemDecl ); /** * This method is used to report the end of the internal subset. * * This method is a no-op for this SAX driver * implementation. */ virtual void endIntSubset(); /** * This method is used to report the end of the external subset. * * This method is a no-op for this SAX driver * implementation. */ virtual void endExtSubset(); /** * This method is used to report any entity declarations. * For unparsed entities, this driver will invoke the * SAX DTDHandler::unparsedEntityDecl callback. * * @param entityDecl A const reference to the object containing * the entity declaration information. * @param isPEDecl The flag indicating whether this was a * parameter entity declaration or not. * @param isIgnored The flag indicating whether this definition * was ignored by the parser or not. * * @see DTDHandler#unparsedEntityDecl */ virtual void entityDecl ( const DTDEntityDecl& entityDecl , const bool isPEDecl , const bool isIgnored ); /** * This method allows the user installed DTD handler to * reset itself. */ virtual void resetDocType(); /** * This method is used to report any notation declarations. * If there is a user installed DTDHandler, then the driver will * invoke the SAX DTDHandler::notationDecl callback. * * @param notDecl A const reference to the object containing the notation * declaration information. * @param isIgnored The flag indicating whether this definition was ignored * by the parser or not. * * @see DTDHandler#notationDecl */ virtual void notationDecl ( const XMLNotationDecl& notDecl , const bool isIgnored ); /** * This method is used to indicate the start of an element's attribute * list declaration. * * This method is a no-op for this SAX driver * implementation. * * @param elemDecl A const reference to the object containing element * declaration information. */ virtual void startAttList ( const DTDElementDecl& elemDecl ); /** * This method is used indicate the start of the internal subset. * * This method is a no-op for this SAX driver * implementation. */ virtual void startIntSubset(); /** * This method is used indicate the start of the external subset. * * This method is a no-op for this SAX driver * implementation. */ virtual void startExtSubset(); /** * This method is used to report the TextDecl. Refer to the XML * specification for the syntax of a TextDecl. * * This method is a no-op for this SAX driver * implementation. * * @param versionStr A const pointer to a Unicode string representing * the version number of the 'version' clause. * @param encodingStr A const pointer to a Unicode string representing * the encoding name of the 'encoding' clause. */ virtual void TextDecl ( const XMLCh* const versionStr , const XMLCh* const encodingStr ); //@} private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- SAX2XMLReaderImpl(const SAX2XMLReaderImpl&); SAX2XMLReaderImpl& operator=(const SAX2XMLReaderImpl&); // ----------------------------------------------------------------------- // Initialize/Cleanup methods // ----------------------------------------------------------------------- void initialize(); void cleanUp(); void resetInProgress(); // ----------------------------------------------------------------------- // Private data members // // fAttrList // A temporary implementation of the basic SAX2 Attributes // interface. We use this one over and over on each startElement // event to allow SAX-like access to the element attributes. // // fDocHandler // The installed SAX content handler, if any. Null if none. // // fnamespacePrefix // Indicates whether the namespace-prefix feature is on or off. // // fautoValidation // Indicates whether automatic validation is on or off // // fValidation // Indicates whether the 'validation' core features is on or off // // fReuseGrammar // Tells the parser whether it should reuse the grammar or not. // If true, there cannot be any internal subset. // // fPrefixesStorage // the namespace prefixes will be allocated from this pool // // fPrefixes // A Stack of the current namespace prefixes that need calls to // endPrefixMapping // // fPrefixCounts // A Stack of the number of prefixes that need endPrefixMapping // calls for that element // // fDTDHandler // The installed SAX DTD handler, if any. Null if none. // // fElemDepth // This is used to track the element nesting depth, so that we can // know when we are inside content. This is so we can ignore char // data outside of content. // // fEntityResolver // The installed SAX entity handler, if any. Null if none. // // fErrorHandler // The installed SAX error handler, if any. Null if none. // // fLexicalHandler // The installed SAX lexical handler, if any. Null if none. // // fDecllHandler // The installed SAX declaration handler, if any. Null if none. // // fAdvDHCount // fAdvDHList // fAdvDHListSize // This is an array of pointers to XMLDocumentHandlers, which is // how we see installed advanced document handlers. There will // usually not be very many at all, so a simple array is used // instead of a collection, for performance. It will grow if needed, // but that is unlikely. // // The count is how many handlers are currently installed. The size // is how big the array itself is (for expansion purposes.) When // count == size, is time to expand. // // fParseInProgress // This flag is set once a parse starts. It is used to prevent // multiple entrance or reentrance of the parser. // // fScanner // The scanner being used by this parser. It is created internally // during construction. // // fHasExternalSubset // Indicate if the document has external DTD subset. // // fGrammarPool // The grammar pool passed from external application (through derivatives). // which could be 0, not owned. // // ----------------------------------------------------------------------- bool fNamespacePrefix; bool fAutoValidation; bool fValidation; bool fParseInProgress; bool fHasExternalSubset; unsigned int fElemDepth; unsigned int fAdvDHCount; unsigned int fAdvDHListSize; VecAttributesImpl fAttrList ; ContentHandler* fDocHandler ; RefVectorOf* fTempAttrVec ; XMLStringPool* fPrefixesStorage ; ValueStackOf* fPrefixes ; ValueStackOf* fPrefixCounts ; DTDHandler* fDTDHandler; EntityResolver* fEntityResolver; XMLEntityResolver* fXMLEntityResolver; ErrorHandler* fErrorHandler; PSVIHandler* fPSVIHandler; LexicalHandler* fLexicalHandler; DeclHandler* fDeclHandler; XMLDocumentHandler** fAdvDHList; XMLScanner* fScanner; GrammarResolver* fGrammarResolver; XMLStringPool* fURIStringPool; XMLValidator* fValidator; MemoryManager* fMemoryManager; XMLGrammarPool* fGrammarPool; // ----------------------------------------------------------------------- // internal function used to set the state of the parser // ----------------------------------------------------------------------- void setValidationScheme(const ValSchemes newScheme); void setDoNamespaces(const bool newState); bool getDoNamespaces() const; void setDoSchema(const bool newState); bool getDoSchema() const; }; // --------------------------------------------------------------------------- // SAX2XMLReader: Getter methods // --------------------------------------------------------------------------- inline ContentHandler* SAX2XMLReaderImpl::getContentHandler() const { return fDocHandler; } inline DTDHandler* SAX2XMLReaderImpl::getDTDHandler() const { return fDTDHandler ; } inline EntityResolver* SAX2XMLReaderImpl::getEntityResolver() const { return fEntityResolver; } inline XMLEntityResolver* SAX2XMLReaderImpl::getXMLEntityResolver() const { return fXMLEntityResolver; } inline ErrorHandler* SAX2XMLReaderImpl::getErrorHandler() const { return fErrorHandler; } inline PSVIHandler* SAX2XMLReaderImpl::getPSVIHandler() const { return fPSVIHandler; } inline LexicalHandler* SAX2XMLReaderImpl::getLexicalHandler() const { return fLexicalHandler; } inline DeclHandler* SAX2XMLReaderImpl::getDeclarationHandler() const { return fDeclHandler; } inline bool SAX2XMLReaderImpl::getExitOnFirstFatalError() const { return fScanner->getExitOnFirstFatal(); } inline bool SAX2XMLReaderImpl::getValidationConstraintFatal() const { return fScanner->getValidationConstraintFatal(); } inline Grammar* SAX2XMLReaderImpl::getRootGrammar() { return fScanner->getRootGrammar(); } inline const XMLCh* SAX2XMLReaderImpl::getURIText(unsigned int uriId) const { return fScanner->getURIText(uriId); } inline unsigned int SAX2XMLReaderImpl::getSrcOffset() const { return fScanner->getSrcOffset(); } XERCES_CPP_NAMESPACE_END #endif