SAXParser.hpp
Go to the documentation of this file.
/*
* 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: SAXParser.hpp 932889 2010-04-11 13:10:10Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_SAXPARSER_HPP)
#define XERCESC_INCLUDE_GUARD_SAXPARSER_HPP
#include <xercesc/sax/Parser.hpp>
#include <xercesc/internal/VecAttrListImpl.hpp>
#include <xercesc/framework/XMLDocumentHandler.hpp>
#include <xercesc/framework/XMLElementDecl.hpp>
#include <xercesc/framework/XMLEntityHandler.hpp>
#include <xercesc/framework/XMLErrorReporter.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/util/SecurityManager.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/validators/DTD/DocTypeHandler.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class DocumentHandler;
class EntityResolver;
class XMLPScanToken;
class XMLScanner;
class XMLValidator;
class GrammarResolver;
class XMLGrammarPool;
class XMLEntityResolver;
class XMLResourceIdentifier;
class PSVIHandler;
class PARSERS_EXPORT SAXParser :
public XMemory
, public Parser
, public XMLDocumentHandler
, public XMLErrorReporter
, public XMLEntityHandler
, public DocTypeHandler
{
public :
// -----------------------------------------------------------------------
// Class types
// -----------------------------------------------------------------------
enum ValSchemes
{
Val_Never
, Val_Always
, Val_Auto
};
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
SAXParser
(
XMLValidator* const valToAdopt = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
, XMLGrammarPool* const gramPool = 0
);
~SAXParser();
// -----------------------------------------------------------------------
// Getter Methods
// -----------------------------------------------------------------------
DocumentHandler* getDocumentHandler();
const DocumentHandler* getDocumentHandler() const;
EntityResolver* getEntityResolver();
const EntityResolver* getEntityResolver() const;
XMLEntityResolver* getXMLEntityResolver();
const XMLEntityResolver* getXMLEntityResolver() const;
ErrorHandler* getErrorHandler();
const ErrorHandler* getErrorHandler() const;
PSVIHandler* getPSVIHandler();
const PSVIHandler* getPSVIHandler() const;
const XMLValidator& getValidator() const;
ValSchemes getValidationScheme() const;
bool getDoSchema() const;
bool getValidationSchemaFullChecking() const;
bool getIdentityConstraintChecking() const;
int getErrorCount() const;
bool getDoNamespaces() const;
bool getExitOnFirstFatalError() const;
bool getValidationConstraintFatal() const;
XMLCh* getExternalSchemaLocation() const;
XMLCh* getExternalNoNamespaceSchemaLocation() const;
SecurityManager* getSecurityManager() const;
XMLSize_t getLowWaterMark() const;
bool getLoadExternalDTD() const;
bool getLoadSchema() const;
bool isCachingGrammarFromParse() const;
bool isUsingCachedGrammarInParse() const;
bool getCalculateSrcOfs() const;
bool getStandardUriConformant() const;
Grammar* getGrammar(const XMLCh* const nameSpaceKey);
Grammar* getRootGrammar();
const XMLCh* getURIText(unsigned int uriId) const;
XMLFilePos getSrcOffset() const;
bool getGenerateSyntheticAnnotations() const;
bool getValidateAnnotations() const;
bool getIgnoreCachedDTD() const;
bool getIgnoreAnnotations() const;
bool getDisableDefaultEntityResolution() const;
bool getSkipDTDValidation() const;
bool getHandleMultipleImports() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setGenerateSyntheticAnnotations(const bool newValue);
void setValidateAnnotations(const bool newValue);
void setDoNamespaces(const bool newState);
void setValidationScheme(const ValSchemes newScheme);
void setDoSchema(const bool newState);
void setValidationSchemaFullChecking(const bool schemaFullChecking);
void setIdentityConstraintChecking(const bool identityConstraintChecking);
void setExitOnFirstFatalError(const bool newState);
void setValidationConstraintFatal(const bool newState);
void setExternalSchemaLocation(const XMLCh* const schemaLocation);
void setExternalSchemaLocation(const char* const schemaLocation);
void setExternalNoNamespaceSchemaLocation(const XMLCh* const noNamespaceSchemaLocation);
void setExternalNoNamespaceSchemaLocation(const char* const noNamespaceSchemaLocation);
void setSecurityManager(SecurityManager* const securityManager);
void setLowWaterMark(XMLSize_t lwm);
void setLoadExternalDTD(const bool newState);
void setLoadSchema(const bool newState);
void cacheGrammarFromParse(const bool newState);
void useCachedGrammarInParse(const bool newState);
void setCalculateSrcOfs(const bool newState);
void setStandardUriConformant(const bool newState);
void useScanner(const XMLCh* const scannerName);
void setInputBufferSize(const XMLSize_t bufferSize);
void setIgnoreCachedDTD(const bool newValue);
void setIgnoreAnnotations(const bool newValue);
void setDisableDefaultEntityResolution(const bool newValue);
void setSkipDTDValidation(const bool newValue);
void setHandleMultipleImports(const bool newValue);
// -----------------------------------------------------------------------
// Advanced document handler list maintenance methods
// -----------------------------------------------------------------------
void installAdvDocHandler(XMLDocumentHandler* const toInstall);
bool removeAdvDocHandler(XMLDocumentHandler* const toRemove);
// -----------------------------------------------------------------------
// Progressive scan methods
// -----------------------------------------------------------------------
bool parseFirst
(
const XMLCh* const systemId
, XMLPScanToken& toFill
);
bool parseFirst
(
const char* const systemId
, XMLPScanToken& toFill
);
bool parseFirst
(
const InputSource& source
, XMLPScanToken& toFill
);
bool parseNext(XMLPScanToken& token);
void parseReset(XMLPScanToken& token);
// -----------------------------------------------------------------------
// Grammar preparsing interface
// -----------------------------------------------------------------------
Grammar* loadGrammar(const InputSource& source,
const Grammar::GrammarType grammarType,
const bool toCache = false);
Grammar* loadGrammar(const XMLCh* const systemId,
const Grammar::GrammarType grammarType,
const bool toCache = false);
Grammar* loadGrammar(const char* const systemId,
const Grammar::GrammarType grammarType,
const bool toCache = false);
void resetCachedGrammarPool();
// -----------------------------------------------------------------------
// Implementation of the SAX Parser interface
// -----------------------------------------------------------------------
virtual void parse(const InputSource& source);
virtual void parse(const XMLCh* const systemId);
virtual void parse(const char* const systemId);
virtual void setDocumentHandler(DocumentHandler* const handler);
virtual void setDTDHandler(DTDHandler* const handler);
virtual void setErrorHandler(ErrorHandler* const handler);
virtual void setPSVIHandler(PSVIHandler* const handler);
virtual void setEntityResolver(EntityResolver* const resolver);
virtual void setXMLEntityResolver(XMLEntityResolver* const resolver);
// -----------------------------------------------------------------------
// 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 endDocument();
virtual void endElement
(
const XMLElementDecl& elemDecl
, const unsigned int urlId
, const bool isRoot
, const XMLCh* const elemPrefix
);
virtual void endEntityReference
(
const XMLEntityDecl& entDecl
);
virtual void ignorableWhitespace
(
const XMLCh* const chars
, const XMLSize_t length
, const bool cdataSection
);
virtual void resetDocument();
virtual void startDocument();
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
);
virtual void startEntityReference
(
const XMLEntityDecl& entDecl
);
virtual void XMLDecl
(
const XMLCh* const versionStr
, const XMLCh* const encodingStr
, const XMLCh* const standaloneStr
, const XMLCh* const actualEncodingStr
);
// -----------------------------------------------------------------------
// Implementation of the XMLErrorReporter interface
// -----------------------------------------------------------------------
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
);
virtual void resetErrors();
// -----------------------------------------------------------------------
// Implementation of the XMLEntityHandler interface
// -----------------------------------------------------------------------
virtual void endInputSource(const InputSource& inputSource);
virtual bool expandSystemId
(
const XMLCh* const systemId
, XMLBuffer& toFill
);
virtual void resetEntities();
virtual InputSource* resolveEntity
(
XMLResourceIdentifier* resourceIdentifier
);
virtual void startInputSource(const InputSource& inputSource);
// -----------------------------------------------------------------------
// Implementation of the Deprecated DocTypeHandler Interface
// -----------------------------------------------------------------------
virtual void attDef
(
const DTDElementDecl& elemDecl
, const DTDAttDef& attDef
, const bool ignore
);
virtual void doctypeComment
(
const XMLCh* const comment
);
virtual void doctypeDecl
(
const DTDElementDecl& elemDecl
, const XMLCh* const publicId
, const XMLCh* const systemId
, const bool hasIntSubset
, const bool hasExtSubset = false
);
virtual void doctypePI
(
const XMLCh* const target
, const XMLCh* const data
);
virtual void doctypeWhitespace
(
const XMLCh* const chars
, const XMLSize_t length
);
virtual void elementDecl
(
const DTDElementDecl& decl
, const bool isIgnored
);
virtual void endAttList
(
const DTDElementDecl& elemDecl
);
virtual void endIntSubset();
virtual void endExtSubset();
virtual void entityDecl
(
const DTDEntityDecl& entityDecl
, const bool isPEDecl
, const bool isIgnored
);
virtual void resetDocType();
virtual void notationDecl
(
const XMLNotationDecl& notDecl
, const bool isIgnored
);
virtual void startAttList
(
const DTDElementDecl& elemDecl
);
virtual void startIntSubset();
virtual void startExtSubset();
virtual void TextDecl
(
const XMLCh* const versionStr
, const XMLCh* const encodingStr
);
protected :
// -----------------------------------------------------------------------
// Protected Methods
// -----------------------------------------------------------------------
const XMLScanner& getScanner() const;
GrammarResolver* getGrammarResolver() const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
SAXParser(const SAXParser&);
SAXParser& operator=(const SAXParser&);
// -----------------------------------------------------------------------
// Initialize/Cleanup methods
// -----------------------------------------------------------------------
void initialize();
void cleanUp();
void resetInProgress();
// -----------------------------------------------------------------------
// Private data members
//
// fAttrList
// A temporary implementation of the basic SAX attribute list
// 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 doc handler, if any. Null if none.
//
// 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.
//
// fPSVIHandler
// The installed PSVI 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.
//
// fGrammarPool
// The grammar pool passed from external application (through derivatives).
// which could be 0, not owned.
//
// -----------------------------------------------------------------------
bool fParseInProgress;
XMLSize_t fElemDepth;
XMLSize_t fAdvDHCount;
XMLSize_t fAdvDHListSize;
VecAttrListImpl fAttrList;
DocumentHandler* fDocHandler;
DTDHandler* fDTDHandler;
EntityResolver* fEntityResolver;
XMLEntityResolver* fXMLEntityResolver;
ErrorHandler* fErrorHandler;
PSVIHandler* fPSVIHandler;
XMLDocumentHandler** fAdvDHList;
XMLScanner* fScanner;
GrammarResolver* fGrammarResolver;
XMLStringPool* fURIStringPool;
XMLValidator* fValidator;
MemoryManager* fMemoryManager;
XMLGrammarPool* fGrammarPool;
XMLBuffer fElemQNameBuf;
};
// ---------------------------------------------------------------------------
// SAXParser: Getter methods
// ---------------------------------------------------------------------------
inline DocumentHandler* SAXParser::getDocumentHandler()
{
return fDocHandler;
}
inline const DocumentHandler* SAXParser::getDocumentHandler() const
{
return fDocHandler;
}
inline EntityResolver* SAXParser::getEntityResolver()
{
return fEntityResolver;
}
inline XMLEntityResolver* SAXParser::getXMLEntityResolver()
{
return fXMLEntityResolver;
}
inline const XMLEntityResolver* SAXParser::getXMLEntityResolver() const
{
return fXMLEntityResolver;
}
inline const EntityResolver* SAXParser::getEntityResolver() const
{
return fEntityResolver;
}
inline ErrorHandler* SAXParser::getErrorHandler()
{
return fErrorHandler;
}
inline const ErrorHandler* SAXParser::getErrorHandler() const
{
return fErrorHandler;
}
inline PSVIHandler* SAXParser::getPSVIHandler()
{
return fPSVIHandler;
}
inline const PSVIHandler* SAXParser::getPSVIHandler() const
{
return fPSVIHandler;
}
inline const XMLScanner& SAXParser::getScanner() const
{
return *fScanner;
}
inline GrammarResolver* SAXParser::getGrammarResolver() const
{
return fGrammarResolver;
}
XERCES_CPP_NAMESPACE_END
#endif
Parser::setEntityResolver
virtual void setEntityResolver(EntityResolver *const resolver)=0
Allow an application to register a custom entity resolver.
XMLDocumentHandler.hpp
XMLDocumentHandler::startEntityReference
virtual void startEntityReference(const XMLEntityDecl &entDecl)=0
Receive notification when the scanner hits an entity reference.
DocumentHandler
Receive notification of general document events.
Definition: DocumentHandler.hpp:60
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition: XMemory.hpp:40
XMLErrorReporter::error
virtual void error(const unsigned int errCode, const XMLCh *const errDomain, const ErrTypes type, const XMLCh *const errorText, const XMLCh *const systemId, const XMLCh *const publicId, const XMLFileLoc lineNum, const XMLFileLoc colNum)=0
Called to report errors from the scanner or validator.
XMLDocumentHandler::endEntityReference
virtual void endEntityReference(const XMLEntityDecl &entDecl)=0
Receive notification when a referenced entity&#39;s content ends.
XMLEntityHandler::resetEntities
virtual void resetEntities()=0
This method allows the entity handler to reset itself, so that it can be used again.
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
SAXParser::getDocumentHandler
DocumentHandler * getDocumentHandler()
This method returns the installed document handler.
Definition: SAXParser.hpp:2142
Parser::parse
virtual void parse(const InputSource &source)=0
Parse an XML document.
XMLEntityHandler::endInputSource
virtual void endInputSource(const InputSource &inputSource)=0
This method get called after the scanner has finished reading from the given input source while proce...
XMLFileLoc
XMLUInt64 XMLFileLoc
Definition: Xerces_autoconf_config.hpp:142
XMLErrorReporter
This abstract class defines a callback mechanism for the scanner.
Definition: XMLErrorReporter.hpp:42
DTDHandler
Receive notification of basic DTD-related events.
Definition: DTDHandler.hpp:59
XMLDocumentHandler::docComment
virtual void docComment(const XMLCh *const comment)=0
Receive notification of comments in the XML content being parsed.
Parser::setDTDHandler
virtual void setDTDHandler(DTDHandler *const handler)=0
Allow an application to register a DTD event handler.
PARSERS_EXPORT
#define PARSERS_EXPORT
Definition: XercesDefs.hpp:168
XMLGrammarPool
Definition: XMLGrammarPool.hpp:43
XMLDocumentHandler::startElement
virtual void startElement(const XMLElementDecl &elemDecl, const unsigned int uriId, const XMLCh *const prefixName, const RefVectorOf< XMLAttr > &attrList, const XMLSize_t attrCount, const bool isEmpty, const bool isRoot)=0
Receive notification of a new start tag.
XMLDocumentHandler::resetDocument
virtual void resetDocument()=0
Reset the document handler&#39;s state, if required.
XMLErrorReporter::resetErrors
virtual void resetErrors()=0
Called before a new parse event to allow the handler to reset.
EntityResolver
Basic interface for resolving entities.
Definition: EntityResolver.hpp:86
XMLNotationDecl
This class represents the core information about a notation declaration that all validators must at l...
Definition: XMLNotationDecl.hpp:41
SAXParser::getXMLEntityResolver
XMLEntityResolver * getXMLEntityResolver()
This method returns the installed entity resolver.
Definition: SAXParser.hpp:2157
XMLEntityHandler.hpp
XMLEntityHandler::expandSystemId
virtual bool expandSystemId(const XMLCh *const systemId, XMLBuffer &toFill)=0
This method allows the passes the scanned systemId to the entity handler, thereby giving it a chance ...
SecurityManager.hpp
ErrorHandler
Basic interface for SAX error handlers.
Definition: ErrorHandler.hpp:60
Parser::setErrorHandler
virtual void setErrorHandler(ErrorHandler *const handler)=0
Allow an application to register an error event handler.
XMLDocumentHandler::ignorableWhitespace
virtual void ignorableWhitespace(const XMLCh *const chars, const XMLSize_t length, const bool cdataSection)=0
Receive notification of ignorable whitespace in element content.
XMLErrorReporter::ErrTypes
ErrTypes
Definition: XMLErrorReporter.hpp:48
SAXParser::ValSchemes
ValSchemes
ValScheme enum used in setValidationScheme Val_Never: Do not report validation errors.
Definition: SAXParser.hpp:90
XMLFilePos
XMLUInt64 XMLFilePos
Definition: Xerces_autoconf_config.hpp:137
Parser::setDocumentHandler
virtual void setDocumentHandler(DocumentHandler *const handler)=0
Allow an application to register a document event handler.
PSVIHandler
This abstract class provides the interface for the scanner to return PSVI information to the applicat...
Definition: PSVIHandler.hpp:38
XMLDocumentHandler::startDocument
virtual void startDocument()=0
Receive notification of the start of a new document.
XMLDocumentHandler
This abstract class provides the interface for the scanner to return XML document information up to t...
Definition: XMLDocumentHandler.hpp:42
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:39
XMLElementDecl
This class defines the core information of an element declaration.
Definition: XMLElementDecl.hpp:51
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:118
XMLDocumentHandler::docCharacters
virtual void docCharacters(const XMLCh *const chars, const XMLSize_t length, const bool cdataSection)=0
Receive notification of character data.
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLDocumentHandler::endElement
virtual void endElement(const XMLElementDecl &elemDecl, const unsigned int uriId, const bool isRoot, const XMLCh *const prefixName=0)=0
Receive notification of the end of an element.
XMLResourceIdentifier
Definition: XMLResourceIdentifier.hpp:95
XMLEntityHandler::startInputSource
virtual void startInputSource(const InputSource &inputSource)=0
This method will be called before the scanner starts reading from an input source while processing ex...
Parser.hpp
XMLValidator
This abstract class provides the interface for all validators.
Definition: XMLValidator.hpp:52
SAXParser::getPSVIHandler
PSVIHandler * getPSVIHandler()
This method returns the installed PSVI handler.
Definition: SAXParser.hpp:2182
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:110
XMLEntityHandler
This abstract class is a callback mechanism for the scanner.
Definition: XMLEntityHandler.hpp:43
XMLErrorReporter.hpp
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
SecurityManager
Allow application to force the parser to behave in a security-conscious way.
Definition: SecurityManager.hpp:51
SAXParser
This class implements the SAX &#39;Parser&#39; interface and should be used by applications wishing to parse ...
Definition: SAXParser.hpp:69
XMLDocumentHandler::endDocument
virtual void endDocument()=0
Receive notification after the scanner has parsed the end of the document.
XMLDocumentHandler::XMLDecl
virtual void XMLDecl(const XMLCh *const versionStr, const XMLCh *const encodingStr, const XMLCh *const standaloneStr, const XMLCh *const autoEncodingStr)=0
Receive notification of an XML declaration.
XMLElementDecl.hpp
XMLEntityDecl
This class defines that core information that defines an XML entity, no matter what validator is used...
Definition: XMLEntityDecl.hpp:50
XMLDocumentHandler::docPI
virtual void docPI(const XMLCh *const target, const XMLCh *const data)=0
Receive notification of PI&#39;s parsed in the XML content.
SAXParser::getErrorHandler
ErrorHandler * getErrorHandler()
This method returns the installed error handler.
Definition: SAXParser.hpp:2172
XMLEntityHandler::resolveEntity
virtual InputSource * resolveEntity(XMLResourceIdentifier *resourceIdentifier)=0
This method allows the entity handler to provide customized application specific entity resolution...
SAXParser::getEntityResolver
EntityResolver * getEntityResolver()
This method returns the installed entity resolver.
Definition: SAXParser.hpp:2152
Parser
Basic interface for SAX (Simple API for XML) parsers.
Definition: Parser.hpp:60
InputSource
A single input source for an XML entity.
Definition: InputSource.hpp:62
SAXParser::getScanner
const XMLScanner & getScanner() const
This method returns a reference to the underlying scanner object.
Definition: SAXParser.hpp:2192
SAXParser::getGrammarResolver
GrammarResolver * getGrammarResolver() const
Get the Grammar resolver.
Definition: SAXParser.hpp:2197
XMLEntityResolver
Revised interface for resolving entities.
Definition: XMLEntityResolver.hpp:99