Added Xerces-C++ 3.1.2

This commit is contained in:
sippeangelo
2015-12-01 10:23:50 +01:00
parent 65d3f3bc31
commit 1b478d3159
815 changed files with 262638 additions and 0 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+715
View File
@@ -0,0 +1,715 @@
/*
* 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: DOMLSParserImpl.hpp 830538 2009-10-28 13:41:11Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMBUILDERIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMBUILDERIMPL_HPP
#include <xercesc/parsers/AbstractDOMParser.hpp>
#include <xercesc/dom/DOMLSParser.hpp>
#include <xercesc/dom/DOMLSInput.hpp>
#include <xercesc/dom/DOMConfiguration.hpp>
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/RefVectorOf.hpp>
#include <xercesc/util/ValueHashTableOf.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLEntityResolver;
class XMLResourceIdentifier;
class DOMStringListImpl;
class DOMLSResourceResolver;
/**
* Introduced in DOM Level 3
*
* DOMLSParserImpl provides an implementation of a DOMLSParser interface.
* A DOMLSParser instance is obtained from the DOMImplementationLS interface
* by invoking its createDOMLSParser method.
*/
class PARSERS_EXPORT DOMLSParserImpl : public AbstractDOMParser,
public DOMLSParser,
public DOMConfiguration
{
public :
// -----------------------------------------------------------------------
// Constructors and Detructor
// -----------------------------------------------------------------------
/** @name Constructors and Destructor */
//@{
/** Construct a DOMLSParserImpl, with an optional validator
*
* Constructor with an instance of validator class to use for
* validation. If you don't provide a validator, a default one will
* be created for you in the scanner.
*
* @param valToAdopt Pointer to the validator instance to use. The
* parser is responsible for freeing the memory.
* @param manager The memory manager to be used for memory allocations
* @param gramPool Pointer to the grammar pool instance from
* external application.
* The parser does NOT own it.
*
*/
DOMLSParserImpl
(
XMLValidator* const valToAdopt = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
, XMLGrammarPool* const gramPool = 0
);
/**
* Destructor
*/
virtual ~DOMLSParserImpl();
//@}
// -----------------------------------------------------------------------
// Implementation of DOMLSParser interface
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
/** @name Getter methods */
//@{
/**
* @see DOMLSParser#getDomConfig
*/
virtual DOMConfiguration* getDomConfig();
/**
* @see DOMLSParser#getFilter
*/
virtual const DOMLSParserFilter* getFilter() const;
/**
* @see DOMLSParser#getAsync
*/
virtual bool getAsync() const;
/**
* @see DOMLSParser#getBusy
*/
virtual bool getBusy() const;
//@}
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
/** @name Setter methods */
//@{
/**
* @see DOMLSParser#setFilter
*/
virtual void setFilter(DOMLSParserFilter* const filter);
//@}
// -----------------------------------------------------------------------
// Parsing methods
// -----------------------------------------------------------------------
/** @name Parsing methods */
//@{
// -----------------------------------------------------------------------
// Parsing methods
// -----------------------------------------------------------------------
/**
* @see DOMLSParser#parse
*/
virtual DOMDocument* parse(const DOMLSInput* source);
/**
* @see DOMLSParser#parseURI
*/
virtual DOMDocument* parseURI(const XMLCh* const uri);
/**
* @see DOMLSParser#parseURI
*/
virtual DOMDocument* parseURI(const char* const uri);
/**
* @see DOMLSParser#parseWithContext
*/
virtual DOMNode* parseWithContext
(
const DOMLSInput* source
, DOMNode* contextNode
, const ActionType action
);
/**
* @see DOMLSParser#abort
*/
virtual void abort();
// -----------------------------------------------------------------------
// Non-standard Extension
// -----------------------------------------------------------------------
/** @name Non-standard Extension */
//@{
/**
* Called to indicate that this DOMLSParser is no longer in use
* and that the implementation may relinquish any resources associated with it.
*
*/
virtual void release();
/** Reset the documents vector pool and release all the associated memory
* back to the system.
*
* When parsing a document using a DOM parser, all memory allocated
* for a DOM tree is associated to the DOM document.
*
* If you do multiple parse using the same DOM parser instance, then
* multiple DOM documents will be generated and saved in a vector pool.
* All these documents (and thus all the allocated memory)
* won't be deleted until the parser instance is destroyed.
*
* If you don't need these DOM documents anymore and don't want to
* destroy the DOM parser instance at this moment, then you can call this method
* to reset the document vector pool and release all the allocated memory
* back to the system.
*
* It is an error to call this method if you are in the middle of a
* parse (e.g. in the mid of a progressive parse).
*
* @exception IOException An exception from the parser if this function
* is called when a parse is in progress.
*
*/
virtual void resetDocumentPool();
/**
* 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 DOMLSInput 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.
*
* @param source A const reference to the DOMLSInput 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 DOMLSInput#DOMLSInput
*/
virtual Grammar* loadGrammar(const DOMLSInput* source,
const Grammar::GrammarType 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.
*
* @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 Grammar::GrammarType 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.
*
* @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 Grammar::GrammarType grammarType,
const bool toCache = false);
/**
* 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) const;
/**
* Retrieve the grammar where the root element is declared.
*
* @return Grammar where root element declared
*/
virtual Grammar* getRootGrammar() const;
/**
* 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;
/**
* Clear the cached grammar pool
*/
virtual void resetCachedGrammarPool();
/**
* 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 XMLFilePos getSrcOffset() const;
//@}
// -----------------------------------------------------------------------
// Implementation of the DOMConfiguration interface.
// -----------------------------------------------------------------------
/** @name Implementation of the DOMConfiguration interface. */
//@{
/**
* Set the value of a parameter.
*
* @param name The name of the parameter to set.
* @param value The new value or null if the user wishes to unset the
* parameter. While the type of the value parameter is defined as
* <code>DOMUserData</code>, the object type must match the type defined
* by the definition of the parameter. For example, if the parameter is
* "error-handler", the value must be of type <code>DOMErrorHandler</code>
*
* @exception DOMException (NOT_SUPPORTED_ERR) Raised when the
* parameter name is recognized but the requested value cannot be set.
* @exception DOMException (NOT_FOUND_ERR) Raised when the
* parameter name is not recognized.
*
* @since DOM level 3
**/
virtual void setParameter(const XMLCh* name, const void* value);
virtual void setParameter(const XMLCh* name, bool value);
/**
* Return the value of a parameter if known.
*
* @param name The name of the parameter.
* @return The current object associated with the specified parameter or
* null if no object has been associated or if the parameter is not
* supported.
*
* @exception DOMException (NOT_FOUND_ERR) Raised when the i
* boolean parameter
* name is not recognized.
*
* @since DOM level 3
**/
virtual const void* getParameter(const XMLCh* name) const;
/**
* Check if setting a parameter to a specific value is supported.
*
* @param name The name of the parameter to check.
* @param value An object. if null, the returned value is true.
* @return true if the parameter could be successfully set to the specified
* value, or false if the parameter is not recognized or the requested value
* is not supported. This does not change the current value of the parameter
* itself.
*
* @since DOM level 3
**/
virtual bool canSetParameter(const XMLCh* name, const void* value) const;
virtual bool canSetParameter(const XMLCh* name, bool value) const;
/**
* The list of the parameters supported by this DOMConfiguration object and
* for which at least one value can be set by the application.
* Note that this list can also contain parameter names defined outside this specification.
*
* @return The list of parameters that can be used with setParameter/getParameter
* @since DOM level 3
**/
virtual const DOMStringList* getParameterNames() const;
//@}
// -----------------------------------------------------------------------
// Implementation of the XMLErrorReporter interface.
// -----------------------------------------------------------------------
/** @name Implementation of the XMLErrorReporter interface. */
//@{
/** Handle errors reported from the parser
*
* This method is used to report back errors found while parsing the
* XML file. This method is also borrowed from the SAX specification.
* It calls the corresponding user installed Error Handler method:
* '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 DOMErrorHandler
*/
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 XMLFileLoc lineNum
, const XMLFileLoc colNum
);
/** Reset any error data before a new parse
*
* This method allows the user installed Error Handler callback to
* 'reset' itself.
*
* <b><font color="#FF0000">This method is a no-op for this DOM
* implementation.</font></b>
*/
virtual void resetErrors();
//@}
// -----------------------------------------------------------------------
// Implementation of the XMLEntityHandler interface.
// -----------------------------------------------------------------------
/** @name Implementation of the XMLEntityHandler interface. */
//@{
/** Handle an end of input source event
*
* This method is used to indicate the end of parsing of an external
* entity file.
*
* <b><font color="#FF0000">This method is a no-op for this DOM
* implementation.</font></b>
*
* @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);
/** Expand a system id
*
* 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.
*
* <b><font color="#FF0000">This method always returns 'false'
* for this DOM implementation.</font></b>
*
* @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
);
/** Reset any entity handler information
*
* This method allows the installed XMLEntityHandler to reset
* itself.
*
* <b><font color="#FF0000">This method is a no-op for this DOM
* implementation.</font></b>
*/
virtual void resetEntities();
/** 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
);
/** Handle a 'start input source' event
*
* This method is used to indicate the start of parsing an external
* entity file.
*
* <b><font color="#FF0000">This method is a no-op for this DOM parse
* implementation.</font></b>
*
* @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 XMLDocumentHandler interface.
// -----------------------------------------------------------------------
virtual void docCharacters
(
const XMLCh* const chars
, const XMLSize_t length
, const bool cdataSection
);
virtual void docComment
(
const XMLCh* const comment
);
virtual void docPI
(
const XMLCh* const target
, const XMLCh* const data
);
virtual void startEntityReference
(
const XMLEntityDecl& entDecl
);
virtual void endElement
(
const XMLElementDecl& elemDecl
, const unsigned int urlId
, const bool isRoot
, const XMLCh* const elemPrefix
);
virtual void startElement
(
const XMLElementDecl& elemDecl
, const unsigned int urlId
, const XMLCh* const elemPrefix
, const RefVectorOf<XMLAttr>& attrList
, const XMLSize_t attrCount
, const bool isEmpty
, const bool isRoot
);
// overriden callbacks to implement parseWithContext behavior
virtual void startDocument();
virtual void XMLDecl
(
const XMLCh* const versionStr
, const XMLCh* const encodingStr
, const XMLCh* const standaloneStr
, const XMLCh* const actualEncStr
);
private :
// -----------------------------------------------------------------------
// Initialize/Cleanup methods
// -----------------------------------------------------------------------
void resetParse();
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
void applyFilter(DOMNode* node);
// -----------------------------------------------------------------------
// Private data members
//
// fEntityResolver
// The installed DOM entity resolver, if any. Null if none.
//
// fXMLEntityResolver
// The installed Xerces entity resolver, if any. Null if none.
//
// fErrorHandler
// The installed DOM error handler, if any. Null if none.
//
// fFilter
// The installed application filter, if any. Null if none.
//
// fCharsetOverridesXMLEncoding
// Indicates if the "charset-overrides-xml-encoding" is set or not
//
// fUserAdoptsDocument
// The DOMDocument ownership has been transferred to application
// If set to true, the parser does not own the document anymore
// and thus will not release its memory.
//
// fSupportedParameters
// A list of the parameters that can be set, including the ones
// specific of Xerces
//
// fFilterAction
// A map of elements rejected by the DOMLSParserFilter::startElement
// callback, used to avoid invoking DOMLSParserFilter::acceptNode
// on its children
//
// fFilterDelayedTextNodes
// As text nodes are filled incrementally, store them in a map
// so that we ask DOMLSParserFilter::acceptNode only once, when it
// is completely created
//
// fWrapNodesInDocumentFragment
// fWrapNodesContext
// fWrapNodesAction
// Variables used to keep the state for parseWithContext API
//
//-----------------------------------------------------------------------
DOMLSResourceResolver* fEntityResolver;
XMLEntityResolver* fXMLEntityResolver;
DOMErrorHandler* fErrorHandler;
DOMLSParserFilter* fFilter;
bool fCharsetOverridesXMLEncoding;
bool fUserAdoptsDocument;
DOMStringListImpl* fSupportedParameters;
ValueHashTableOf<DOMLSParserFilter::FilterAction, PtrHasher>* fFilterAction;
ValueHashTableOf<bool, PtrHasher>* fFilterDelayedTextNodes;
DOMDocumentFragment* fWrapNodesInDocumentFragment;
DOMNode* fWrapNodesContext;
ActionType fWrapNodesAction;
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DOMLSParserImpl(const DOMLSParserImpl &);
DOMLSParserImpl & operator = (const DOMLSParserImpl &);
};
// ---------------------------------------------------------------------------
// DOMLSParserImpl: Handlers for the XMLEntityHandler interface
// ---------------------------------------------------------------------------
inline void DOMLSParserImpl::endInputSource(const InputSource&)
{
// The DOM entity resolver doesn't handle this
}
inline bool DOMLSParserImpl::expandSystemId(const XMLCh* const, XMLBuffer&)
{
// The DOM entity resolver doesn't handle this
return false;
}
inline void DOMLSParserImpl::resetEntities()
{
// Nothing to do on this one
}
inline void DOMLSParserImpl::startInputSource(const InputSource&)
{
// The DOM entity resolver doesn't handle this
}
// ---------------------------------------------------------------------------
// DOMLSParserImpl: Getter methods
// ---------------------------------------------------------------------------
inline DOMConfiguration* DOMLSParserImpl::getDomConfig()
{
return this;
}
inline bool DOMLSParserImpl::getAsync() const
{
// We are a synchronous parser
return false;
}
inline const DOMLSParserFilter* DOMLSParserImpl::getFilter() const
{
return fFilter;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,416 @@
/*
* 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: SAX2XMLFilterImpl.cpp 673975 2008-07-04 09:23:56Z borisk $
*/
#include <xercesc/parsers/SAX2XMLFilterImpl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
SAX2XMLFilterImpl::SAX2XMLFilterImpl(SAX2XMLReader* parent) :
fParentReader(0)
, fDocHandler(0)
, fDTDHandler(0)
, fEntityResolver(0)
, fErrorHandler(0)
{
setParent(parent);
}
SAX2XMLFilterImpl::~SAX2XMLFilterImpl()
{
}
// ---------------------------------------------------------------------------
// SAX2XMLFilterImpl: XMLFilter impl
// ---------------------------------------------------------------------------
void SAX2XMLFilterImpl::setParent(SAX2XMLReader* parent)
{
if(fParentReader)
{
fParentReader->setEntityResolver(0);
fParentReader->setDTDHandler(0);
fParentReader->setContentHandler(0);
fParentReader->setErrorHandler(0);
}
fParentReader=parent;
if(fParentReader)
{
fParentReader->setEntityResolver(this);
fParentReader->setDTDHandler(this);
fParentReader->setContentHandler(this);
fParentReader->setErrorHandler(this);
}
}
bool SAX2XMLFilterImpl::getExitOnFirstFatalError() const
{
if(fParentReader)
fParentReader->getExitOnFirstFatalError();
return false;
}
bool SAX2XMLFilterImpl::getValidationConstraintFatal() const
{
if(fParentReader)
fParentReader->getValidationConstraintFatal();
return false;
}
Grammar* SAX2XMLFilterImpl::getRootGrammar()
{
if(fParentReader)
fParentReader->getRootGrammar();
return NULL;
}
const XMLCh* SAX2XMLFilterImpl::getURIText(unsigned int uriId) const
{
if(fParentReader)
fParentReader->getURIText(uriId);
return NULL;
}
XMLFilePos SAX2XMLFilterImpl::getSrcOffset() const
{
if(fParentReader)
fParentReader->getSrcOffset();
return 0;
}
// ---------------------------------------------------------------------------
// SAX2XMLFilterImpl Validator functions
// ---------------------------------------------------------------------------
void SAX2XMLFilterImpl::setValidator(XMLValidator* valueToAdopt)
{
if(fParentReader)
fParentReader->setValidator(valueToAdopt);
}
XMLValidator* SAX2XMLFilterImpl::getValidator() const
{
if(fParentReader)
return fParentReader->getValidator();
return 0;
}
// ---------------------------------------------------------------------------
// SAX2XMLReader Interface
// ---------------------------------------------------------------------------
XMLSize_t SAX2XMLFilterImpl::getErrorCount() const
{
if(fParentReader)
return fParentReader->getErrorCount();
return 0;
}
void SAX2XMLFilterImpl::setExitOnFirstFatalError(const bool newState)
{
if(fParentReader)
fParentReader->setExitOnFirstFatalError(newState);
}
void SAX2XMLFilterImpl::setValidationConstraintFatal(const bool newState)
{
if(fParentReader)
fParentReader->setValidationConstraintFatal(newState);
}
void SAX2XMLFilterImpl::parse (const InputSource& source)
{
if(fParentReader)
fParentReader->parse(source);
}
void SAX2XMLFilterImpl::parse (const XMLCh* const systemId)
{
if(fParentReader)
fParentReader->parse(systemId);
}
void SAX2XMLFilterImpl::parse (const char* const systemId)
{
if(fParentReader)
fParentReader->parse(systemId);
}
// ---------------------------------------------------------------------------
// SAX2XMLFilterImpl: Progressive parse methods
// ---------------------------------------------------------------------------
bool SAX2XMLFilterImpl::parseFirst( const XMLCh* const systemId
, XMLPScanToken& toFill)
{
if(fParentReader)
return fParentReader->parseFirst(systemId, toFill);
return false;
}
bool SAX2XMLFilterImpl::parseFirst( const char* const systemId
, XMLPScanToken& toFill)
{
if(fParentReader)
fParentReader->parseFirst(systemId, toFill);
return false;
}
bool SAX2XMLFilterImpl::parseFirst( const InputSource& source
, XMLPScanToken& toFill)
{
if(fParentReader)
fParentReader->parseFirst(source, toFill);
return false;
}
bool SAX2XMLFilterImpl::parseNext(XMLPScanToken& token)
{
if(fParentReader)
fParentReader->parseNext(token);
return false;
}
void SAX2XMLFilterImpl::parseReset(XMLPScanToken& token)
{
if(fParentReader)
fParentReader->parseReset(token);
}
// ---------------------------------------------------------------------------
// SAX2XMLFilterImpl: Features and Properties
// ---------------------------------------------------------------------------
void SAX2XMLFilterImpl::setFeature(const XMLCh* const name, const bool value)
{
if(fParentReader)
fParentReader->setFeature(name,value);
}
bool SAX2XMLFilterImpl::getFeature(const XMLCh* const name) const
{
if(fParentReader)
return fParentReader->getFeature(name);
return false;
}
void SAX2XMLFilterImpl::setProperty(const XMLCh* const name, void* value)
{
if(fParentReader)
fParentReader->setProperty(name,value);
}
void* SAX2XMLFilterImpl::getProperty(const XMLCh* const name) const
{
if(fParentReader)
return fParentReader->getProperty(name);
return NULL;
}
// ---------------------------------------------------------------------------
// SAX2XMLFilterImpl: Grammar preparsing
// ---------------------------------------------------------------------------
Grammar* SAX2XMLFilterImpl::loadGrammar(const char* const systemId,
const Grammar::GrammarType grammarType,
const bool toCache)
{
if(fParentReader)
return fParentReader->loadGrammar(systemId, grammarType, toCache);
return NULL;
}
Grammar* SAX2XMLFilterImpl::loadGrammar(const XMLCh* const systemId,
const Grammar::GrammarType grammarType,
const bool toCache)
{
if(fParentReader)
return fParentReader->loadGrammar(systemId, grammarType, toCache);
return NULL;
}
Grammar* SAX2XMLFilterImpl::loadGrammar(const InputSource& source,
const Grammar::GrammarType grammarType,
const bool toCache)
{
if(fParentReader)
return fParentReader->loadGrammar(source, grammarType, toCache);
return NULL;
}
void SAX2XMLFilterImpl::resetCachedGrammarPool()
{
if(fParentReader)
fParentReader->resetCachedGrammarPool();
}
void SAX2XMLFilterImpl::setInputBufferSize(const XMLSize_t bufferSize)
{
if(fParentReader)
fParentReader->setInputBufferSize(bufferSize);
}
Grammar* SAX2XMLFilterImpl::getGrammar(const XMLCh* const nameSpaceKey)
{
if(fParentReader)
return fParentReader->getGrammar(nameSpaceKey);
return NULL;
}
// -----------------------------------------------------------------------
// Implementation of the EntityResolver interface
// -----------------------------------------------------------------------
InputSource* SAX2XMLFilterImpl::resolveEntity(const XMLCh* const publicId
, const XMLCh* const systemId)
{
if(fEntityResolver)
return fEntityResolver->resolveEntity(publicId, systemId);
return 0;
}
// -----------------------------------------------------------------------
// Implementation of the DTDHandler interface
// -----------------------------------------------------------------------
void SAX2XMLFilterImpl::notationDecl( const XMLCh* const name
, const XMLCh* const publicId
, const XMLCh* const systemId)
{
if(fDTDHandler)
fDTDHandler->notationDecl(name, publicId, systemId);
}
void SAX2XMLFilterImpl::unparsedEntityDecl(const XMLCh* const name
, const XMLCh* const publicId
, const XMLCh* const systemId
, const XMLCh* const notationName)
{
if(fDTDHandler)
fDTDHandler->unparsedEntityDecl(name, publicId, systemId, notationName);
}
void SAX2XMLFilterImpl::resetDocType()
{
if(fDTDHandler)
fDTDHandler->resetDocType();
}
// -----------------------------------------------------------------------
// Implementation of the ContentHandler interface
// -----------------------------------------------------------------------
void SAX2XMLFilterImpl::characters(const XMLCh* const chars
, const XMLSize_t length)
{
if(fDocHandler)
fDocHandler->characters(chars, length);
}
void SAX2XMLFilterImpl::endDocument()
{
if(fDocHandler)
fDocHandler->endDocument();
}
void SAX2XMLFilterImpl::endElement(const XMLCh* const uri
, const XMLCh* const localname
, const XMLCh* const qname)
{
if(fDocHandler)
fDocHandler->endElement(uri, localname, qname);
}
void SAX2XMLFilterImpl::ignorableWhitespace(const XMLCh* const chars
, const XMLSize_t length)
{
if(fDocHandler)
fDocHandler->ignorableWhitespace(chars, length);
}
void SAX2XMLFilterImpl::processingInstruction(const XMLCh* const target
, const XMLCh* const data)
{
if(fDocHandler)
fDocHandler->processingInstruction(target, data);
}
void SAX2XMLFilterImpl::setDocumentLocator(const Locator* const locator)
{
if(fDocHandler)
fDocHandler->setDocumentLocator(locator);
}
void SAX2XMLFilterImpl::startDocument()
{
if(fDocHandler)
fDocHandler->startDocument();
}
void SAX2XMLFilterImpl::startElement(const XMLCh* const uri
, const XMLCh* const localname
, const XMLCh* const qname
, const Attributes& attrs)
{
if(fDocHandler)
fDocHandler->startElement(uri, localname, qname, attrs);
}
void SAX2XMLFilterImpl::startPrefixMapping(const XMLCh* const prefix
, const XMLCh* const uri)
{
if(fDocHandler)
fDocHandler->startPrefixMapping(prefix, uri);
}
void SAX2XMLFilterImpl::endPrefixMapping(const XMLCh* const prefix)
{
if(fDocHandler)
fDocHandler->endPrefixMapping(prefix);
}
void SAX2XMLFilterImpl::skippedEntity(const XMLCh* const name)
{
if(fDocHandler)
fDocHandler->skippedEntity(name);
}
// -----------------------------------------------------------------------
// Implementation of the ErrorHandler interface
// -----------------------------------------------------------------------
void SAX2XMLFilterImpl::warning(const SAXParseException& exc)
{
if(fErrorHandler)
fErrorHandler->warning(exc);
}
void SAX2XMLFilterImpl::error(const SAXParseException& exc)
{
if(fErrorHandler)
fErrorHandler->error(exc);
}
void SAX2XMLFilterImpl::fatalError(const SAXParseException& exc)
{
if(fErrorHandler)
fErrorHandler->fatalError(exc);
}
void SAX2XMLFilterImpl::resetErrors()
{
if(fErrorHandler)
fErrorHandler->resetErrors();
}
XERCES_CPP_NAMESPACE_END
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+349
View File
@@ -0,0 +1,349 @@
/*
* 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.
*/
/**
* This file contains code to build the DOM tree. It registers a document
* handler with the scanner. In these handler methods, appropriate DOM nodes
* are created and added to the DOM tree.
*
* $Id: XercesDOMParser.cpp 882548 2009-11-20 13:44:14Z borisk $
*
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#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>
#include <xercesc/validators/common/GrammarResolver.hpp>
#include <xercesc/framework/XMLGrammarPool.hpp>
#include <xercesc/framework/XMLSchemaDescription.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/util/XMLEntityResolver.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XercesDOMParser: Constructors and Destructor
// ---------------------------------------------------------------------------
XercesDOMParser::XercesDOMParser( XMLValidator* const valToAdopt
, MemoryManager* const manager
, XMLGrammarPool* const gramPool):
AbstractDOMParser(valToAdopt, manager, gramPool)
, fEntityResolver(0)
, fXMLEntityResolver(0)
, fErrorHandler(0)
{
}
XercesDOMParser::~XercesDOMParser()
{
}
// ---------------------------------------------------------------------------
// 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 getGrammarResolver()->getGrammar(nameSpaceKey);
}
Grammar* XercesDOMParser::getRootGrammar()
{
return getScanner()->getRootGrammar();
}
const XMLCh* XercesDOMParser::getURIText(unsigned int uriId) const
{
return getScanner()->getURIText(uriId);
}
XMLFilePos XercesDOMParser::getSrcOffset() const
{
return getScanner()->getSrcOffset();
}
bool XercesDOMParser::getIgnoreCachedDTD() const
{
return getScanner()->getIgnoreCachedDTD();
}
// ---------------------------------------------------------------------------
// XercesDOMParser: Setter methods
// ---------------------------------------------------------------------------
void XercesDOMParser::setErrorHandler(ErrorHandler* const handler)
{
fErrorHandler = handler;
XMLScanner* scanner = getScanner();
if (fErrorHandler) {
scanner->setErrorReporter(this);
scanner->setErrorHandler(fErrorHandler);
}
else {
scanner->setErrorReporter(0);
scanner->setErrorHandler(0);
}
}
void XercesDOMParser::setEntityResolver(EntityResolver* const handler)
{
fEntityResolver = handler;
if (fEntityResolver) {
getScanner()->setEntityHandler(this);
fXMLEntityResolver = 0;
}
else {
getScanner()->setEntityHandler(0);
}
}
void XercesDOMParser::setXMLEntityResolver(XMLEntityResolver* const handler)
{
fXMLEntityResolver = handler;
if (fXMLEntityResolver) {
getScanner()->setEntityHandler(this);
fEntityResolver = 0;
}
else {
getScanner()->setEntityHandler(0);
}
}
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);
}
void XercesDOMParser::setIgnoreCachedDTD(const bool newValue)
{
getScanner()->setIgnoredCachedDTD(newValue);
}
// ---------------------------------------------------------------------------
// XercesDOMParser: Utilities
// ---------------------------------------------------------------------------
void XercesDOMParser::resetDocumentPool()
{
resetPool();
}
// ---------------------------------------------------------------------------
// XercesDOMParser: Implementation of the XMLErrorReporter interface
// ---------------------------------------------------------------------------
void XercesDOMParser::error( const unsigned int
, const XMLCh* const
, const XMLErrorReporter::ErrTypes errType
, const XMLCh* const errorText
, const XMLCh* const systemId
, const XMLCh* const publicId
, const XMLFileLoc lineNum
, const XMLFileLoc colNum)
{
SAXParseException toThrow = SAXParseException
(
errorText
, publicId
, systemId
, lineNum
, colNum
, getMemoryManager()
);
//
// If there is an error handler registered, call it, otherwise ignore
// all but the fatal errors.
//
if (!fErrorHandler)
{
if (errType == XMLErrorReporter::ErrType_Fatal)
throw toThrow;
return;
}
if (errType == XMLErrorReporter::ErrType_Warning)
fErrorHandler->warning(toThrow);
else if (errType >= XMLErrorReporter::ErrType_Fatal)
fErrorHandler->fatalError(toThrow);
else
fErrorHandler->error(toThrow);
}
void XercesDOMParser::resetErrors()
{
}
// ---------------------------------------------------------------------------
// XercesDOMParser: Implementation of XMLEntityHandler interface
// ---------------------------------------------------------------------------
InputSource*
XercesDOMParser::resolveEntity(XMLResourceIdentifier* resourceIdentifier)
{
//
// Just map it to the SAX entity resolver. If there is not one installed,
// return a null pointer to cause the default resolution.
//
if (fEntityResolver)
return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(),
resourceIdentifier->getSystemId());
if (fXMLEntityResolver)
return fXMLEntityResolver->resolveEntity(resourceIdentifier);
return 0;
}
typedef JanitorMemFunCall<XercesDOMParser> ResetParseType;
// ---------------------------------------------------------------------------
// XercesDOMParser: Grammar preparsing methods
// ---------------------------------------------------------------------------
Grammar* XercesDOMParser::loadGrammar(const char* const systemId,
const Grammar::GrammarType grammarType,
const bool toCache)
{
// Avoid multiple entrance
if (getParseInProgress())
ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
ResetParseType resetParse(this, &XercesDOMParser::resetParse);
Grammar* grammar = 0;
try
{
setParseInProgress(true);
if (grammarType == Grammar::DTDGrammarType)
getScanner()->setDocTypeHandler(0);
grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
}
catch(const OutOfMemoryException&)
{
resetParse.release();
throw;
}
return grammar;
}
Grammar* XercesDOMParser::loadGrammar(const XMLCh* const systemId,
const Grammar::GrammarType grammarType,
const bool toCache)
{
// Avoid multiple entrance
if (getParseInProgress())
ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
ResetParseType resetParse(this, &XercesDOMParser::resetParse);
Grammar* grammar = 0;
try
{
setParseInProgress(true);
if (grammarType == Grammar::DTDGrammarType)
getScanner()->setDocTypeHandler(0);
grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
}
catch(const OutOfMemoryException&)
{
resetParse.release();
throw;
}
return grammar;
}
Grammar* XercesDOMParser::loadGrammar(const InputSource& source,
const Grammar::GrammarType grammarType,
const bool toCache)
{
// Avoid multiple entrance
if (getParseInProgress())
ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
ResetParseType resetParse(this, &XercesDOMParser::resetParse);
Grammar* grammar = 0;
try
{
setParseInProgress(true);
if (grammarType == Grammar::DTDGrammarType)
getScanner()->setDocTypeHandler(0);
grammar = getScanner()->loadGrammar(source, grammarType, toCache);
}
catch(const OutOfMemoryException&)
{
resetParse.release();
throw;
}
return grammar;
}
void XercesDOMParser::resetParse()
{
if (getScanner()->getDocTypeHandler() == 0)
{
getScanner()->setDocTypeHandler(this);
}
setParseInProgress(false);
}
void XercesDOMParser::resetCachedGrammarPool()
{
getGrammarResolver()->resetCachedGrammar();
getScanner()->resetCachedGrammar();
}
XERCES_CPP_NAMESPACE_END
+696
View File
@@ -0,0 +1,696 @@
/*
* 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: XercesDOMParser.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XERCESDOMPARSER_HPP)
#define XERCESC_INCLUDE_GUARD_XERCESDOMPARSER_HPP
#include <xercesc/parsers/AbstractDOMParser.hpp>
#include <xercesc/validators/common/Grammar.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class EntityResolver;
class ErrorHandler;
class XMLEntityResolver;
class XMLResourceIdentifier;
/**
* This class implements the Document Object Model (DOM) interface.
* It should be used by applications which choose to parse and
* process the XML document using the DOM api's. This implementation
* also allows the applications to install an error and an entity
* handler (useful extensions to the DOM specification).
*
* <p>It can be used to instantiate a validating or non-validating
* parser, by setting a member flag.</p>
*/
class PARSERS_EXPORT XercesDOMParser : public AbstractDOMParser
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
/** @name Constructors and Destructor */
//@{
/** Construct a XercesDOMParser, with an optional validator
*
* Constructor with an instance of validator class to use for
* validation. If you don't provide a validator, a default one will
* be created for you in the scanner.
*
* @param gramPool Pointer to the grammar pool instance from
* external application.
* The parser does NOT own it.
*
* @param valToAdopt Pointer to the validator instance to use. The
* parser is responsible for freeing the memory.
* @param manager Pointer to the memory manager to be used to
* allocate objects.
*/
XercesDOMParser
(
XMLValidator* const valToAdopt = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
, XMLGrammarPool* const gramPool = 0
);
/**
* Destructor
*/
virtual ~XercesDOMParser();
//@}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
/** @name Getter methods */
//@{
/** Get a pointer to the error handler
*
* This method returns the installed error handler. If no handler
* has been installed, then it will be a zero pointer.
*
* @return The pointer to the installed error handler object.
*/
ErrorHandler* getErrorHandler();
/** Get a const pointer to the error handler
*
* This method returns the installed error handler. If no handler
* has been installed, then it will be a zero pointer.
*
* @return A const pointer to the installed error handler object.
*/
const ErrorHandler* getErrorHandler() const;
/** Get a pointer to the entity resolver
*
* This method returns the installed entity resolver. If no resolver
* has been installed, then it will be a zero pointer.
*
* @return The pointer to the installed entity resolver object.
*/
EntityResolver* getEntityResolver();
/** Get a const pointer to the entity resolver
*
* This method returns the installed entity resolver. If no resolver
* has been installed, then it will be a zero pointer.
*
* @return A const pointer to the installed entity resolver object.
*/
const EntityResolver* getEntityResolver() const;
/**
* Get a pointer to the entity resolver
*
* This method returns the installed entity resolver. If no resolver
* has been installed, then it will be a zero pointer.
*
* @return The pointer to the installed entity resolver object.
*/
XMLEntityResolver* getXMLEntityResolver();
/**
* Get a const pointer to the entity resolver
*
* This method returns the installed entity resolver. If no resolver
* has been installed, then it will be a zero pointer.
*
* @return A const pointer to the installed entity resolver object.
*/
const XMLEntityResolver* getXMLEntityResolver() 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) 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
*/
XMLFilePos getSrcOffset() const;
/** Get the 'ignore cached DTD grammar' flag
*
* @return true, if the parser is currently configured to
* ignore cached DTD, false otherwise.
*
* @see #setIgnoreCachedDTD
*/
bool getIgnoreCachedDTD() const;
//@}
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
/** @name Setter methods */
//@{
/** Set the error handler
*
* This method allows applications to install their own error handler
* to trap error and warning messages.
*
* <i>Any previously set handler is merely dropped, since the parser
* does not own them.</i>
*
* @param handler A const pointer to the user supplied error
* handler.
*
* @see #getErrorHandler
*/
void setErrorHandler(ErrorHandler* const handler);
/** 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.
*
* <i>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.</i>
*
* @param handler A const pointer to the user supplied entity
* resolver.
*
* @see #getEntityResolver
*/
void setEntityResolver(EntityResolver* const handler);
/**
* 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.
*
* <i>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 set is used.</i>
*
* @param handler A const pointer to the user supplied entity
* resolver.
*
* @see #getXMLEntityResolver
*/
void setXMLEntityResolver(XMLEntityResolver* 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 method 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);
/** Set the 'ignore cached DTD grammar' flag
*
* This method gives users the option to ignore a cached DTD grammar, when
* an XML document contains both an internal and external DTD, and the use
* cached grammar from parse option is enabled. Currently, we do not allow
* using cached DTD grammar when an internal subset is present in the
* document. This option will only affect the behavior of the parser when
* an internal and external DTD both exist in a document (i.e. no effect
* if document has no internal subset).
*
* The parser's default state is false
*
* @param newValue The state to set
*/
void setIgnoreCachedDTD(const bool newValue);
//@}
// -----------------------------------------------------------------------
// Utility methods
// -----------------------------------------------------------------------
/** @name Utility methods */
//@{
/** Reset the documents vector pool and release all the associated memory
* back to the system.
*
* When parsing a document using a DOM parser, all memory allocated
* for a DOM tree is associated to the DOM document.
*
* If you do multiple parse using the same DOM parser instance, then
* multiple DOM documents will be generated and saved in a vector pool.
* All these documents (and thus all the allocated memory)
* won't be deleted until the parser instance is destroyed.
*
* If you don't need these DOM documents anymore and don't want to
* destroy the DOM parser instance at this moment, then you can call this method
* to reset the document vector pool and release all the allocated memory
* back to the system.
*
* It is an error to call this method if you are in the middle of a
* parse (e.g. in the mid of a progressive parse).
*
* @exception IOException An exception from the parser if this function
* is called when a parse is in progress.
*
*/
void resetDocumentPool();
//@}
// -----------------------------------------------------------------------
// Implementation of the XMLErrorReporter interface.
// -----------------------------------------------------------------------
/** @name Implementation of the XMLErrorReporter interface. */
//@{
/** Handle errors reported from the parser
*
* This method is used to report back errors found while parsing the
* XML file. This method is also borrowed from the SAX specification.
* It calls the corresponding user installed Error Handler method:
* '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 XMLFileLoc lineNum
, const XMLFileLoc colNum
);
/** Reset any error data before a new parse
*
* This method allows the user installed Error Handler callback to
* 'reset' itself.
*
* <b>This method is a no-op for this DOM
* implementation.</b>
*/
virtual void resetErrors();
//@}
// -----------------------------------------------------------------------
// Implementation of the XMLEntityHandler interface.
// -----------------------------------------------------------------------
/** @name Implementation of the XMLEntityHandler interface. */
//@{
/** Handle an end of input source event
*
* This method is used to indicate the end of parsing of an external
* entity file.
*
* <b>This method is a no-op for this DOM
* implementation.</b>
*
* @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);
/** Expand a system id
*
* This method allows an installed XMLEntityHandler to further
* process any system id's of external entities encountered in
* the XML file being parsed, such as redirection etc.
*
* <b>This method always returns 'false'
* for this DOM implementation.</b>
*
* @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
);
/** Reset any entity handler information
*
* This method allows the installed XMLEntityHandler to reset
* itself.
*
* <b>This method is a no-op for this DOM
* implementation.</b>
*/
virtual void resetEntities();
/** 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
);
/** Handle a 'start input source' event
*
* This method is used to indicate the start of parsing an external
* entity file.
*
* <b>This method is a no-op for this DOM parse
* implementation.</b>
*
* @param inputSource A const reference to the InputSource object
* which points to the external entity
* 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.
*
*
* @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 caching. 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 Grammar::GrammarType 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.
*
*
* @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 caching. 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 Grammar::GrammarType 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.
*
*
* @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 caching. 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 Grammar::GrammarType grammarType,
const bool toCache = false);
/**
* This method allows the user to reset the pool of cached grammars.
*/
void resetCachedGrammarPool();
//@}
private :
// -----------------------------------------------------------------------
// Initialize/Cleanup methods
// -----------------------------------------------------------------------
void resetParse();
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XercesDOMParser(const XercesDOMParser&);
XercesDOMParser& operator=(const XercesDOMParser&);
// -----------------------------------------------------------------------
// Private data members
//
// fEntityResolver
// The installed SAX entity resolver, if any. Null if none.
//
// fErrorHandler
// The installed SAX error handler, if any. Null if none.
//-----------------------------------------------------------------------
EntityResolver* fEntityResolver;
XMLEntityResolver* fXMLEntityResolver;
ErrorHandler* fErrorHandler;
};
// ---------------------------------------------------------------------------
// XercesDOMParser: Handlers for the XMLEntityHandler interface
// ---------------------------------------------------------------------------
inline void XercesDOMParser::endInputSource(const InputSource&)
{
// The DOM entity resolver doesn't handle this
}
inline bool XercesDOMParser::expandSystemId(const XMLCh* const, XMLBuffer&)
{
// The DOM entity resolver doesn't handle this
return false;
}
inline void XercesDOMParser::resetEntities()
{
// Nothing to do on this one
}
inline void XercesDOMParser::startInputSource(const InputSource&)
{
// The DOM entity resolver doesn't handle this
}
// ---------------------------------------------------------------------------
// XercesDOMParser: Getter methods
// ---------------------------------------------------------------------------
inline ErrorHandler* XercesDOMParser::getErrorHandler()
{
return fErrorHandler;
}
inline const ErrorHandler* XercesDOMParser::getErrorHandler() const
{
return fErrorHandler;
}
inline EntityResolver* XercesDOMParser::getEntityResolver()
{
return fEntityResolver;
}
inline const EntityResolver* XercesDOMParser::getEntityResolver() const
{
return fEntityResolver;
}
inline XMLEntityResolver* XercesDOMParser::getXMLEntityResolver()
{
return fXMLEntityResolver;
}
inline const XMLEntityResolver* XercesDOMParser::getXMLEntityResolver() const
{
return fXMLEntityResolver;
}
XERCES_CPP_NAMESPACE_END
#endif