You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/07/13 19:56:06 UTC

cvs commit: xml-xalan/c/src/XercesParserLiaison XercesParserLiaison.cpp XercesParserLiaison.hpp

dbertoni    00/07/13 10:56:06

  Modified:    c/src/XercesParserLiaison XercesParserLiaison.cpp
                        XercesParserLiaison.hpp
  Log:
  Cleaned up obsolete code. XercesParserLiaison no longer derives from XMLParserLiaisonDefault.  Added accessors to get/set some Xerces parser properties.  Put creation of parsers into protected, virtual methods, so people can override them if they want.
  
  Revision  Changes    Path
  1.10      +276 -32   xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.cpp
  
  Index: XercesParserLiaison.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XercesParserLiaison.cpp	2000/05/08 17:20:59	1.9
  +++ XercesParserLiaison.cpp	2000/07/13 17:56:06	1.10
  @@ -76,20 +76,31 @@
   
   
   
  +#include <DOMSupport/DOMSupport.hpp>
  +
  +
  +
   #include "XercesDocumentBridge.hpp"
   
   
   
   static const XalanDOMString		theParserName(XALAN_STATIC_UCODE_STRING("Xerces"));
  +static const XalanDOMString		theDefaultSpecialCharacters(XALAN_STATIC_UCODE_STRING("<>&\"\'\r\n"));
   
   
   
  -XercesParserLiaison::XercesParserLiaison(
  -			DOMSupport&		theSupport,
  -			bool			fUseValidatingParser) :
  -	XMLParserLiaisonDefault(theSupport,
  -							theParserName),
  -	m_fUseValidatingParser(fUseValidatingParser),
  +XercesParserLiaison::XercesParserLiaison(DOMSupport&	theSupport) :
  +	m_DOMSupport(theSupport),
  +	m_specialCharacters(theDefaultSpecialCharacters),
  +	m_indent(-1),
  +	m_shouldExpandEntityRefs(true),
  +	m_useValidation(false),
  +	m_includeIgnorableWhitespace(true),
  +	m_doNamespaces(false),
  +	m_exitOnFirstFatalError(true),
  +	m_factory(0),
  +	m_entityResolver(0),
  +	m_errorHandler(this),
   	m_documentMap()
   {
   }
  @@ -116,6 +127,8 @@
   			 makeMapValueDeleteFunctor(m_documentMap));
   
   	m_documentMap.clear();
  +
  +	m_DOMSupport.reset();
   }
   
   
  @@ -128,28 +141,6 @@
   
   
   
  -static inline DOMParser*
  -CreateDOMParser(bool	fValidating)
  -{
  -	DOMParser *parser = new DOMParser;
  -	parser->setDoValidation(fValidating);
  -
  -	return parser;
  -}
  -
  -
  -
  -static inline SAXParser*
  -CreateSAXParser(bool	fValidating)
  -{
  -	SAXParser *parser = new SAXParser;
  -	parser->setDoValidation(fValidating);
  -
  -	return parser;
  -}
  -
  -
  -
   void
   XercesParserLiaison::parseXMLStream(
   			InputSource&			urlInputSource,
  @@ -160,10 +151,9 @@
   	using std::auto_ptr;
   #endif
   
  -	auto_ptr<SAXParser>		theParser(CreateSAXParser(m_fUseValidatingParser));
  +	auto_ptr<SAXParser>		theParser(CreateSAXParser());
   
   	theParser->setDocumentHandler(&handler);
  -	theParser->setErrorHandler(this);
   
   	theParser->parse(urlInputSource);
   }
  @@ -179,9 +169,8 @@
   	using std::auto_ptr;
   #endif
   
  -	auto_ptr<DOMParser>		theParser(CreateDOMParser(m_fUseValidatingParser));
  +	auto_ptr<DOMParser>		theParser(CreateDOMParser());
   
  -	theParser->setErrorHandler(this);
   	theParser->parse(reader);
   
   	const DOM_Document	theXercesDocument =
  @@ -213,6 +202,211 @@
   
   
   XalanDocument*
  +XercesParserLiaison::getDOMFactory()
  +{
  +	if (m_factory == 0)
  +	{
  +		m_factory = createDocument();
  +	}
  +
  +	return m_factory;
  +}
  +
  +
  +
  +/**
  + * Returns the element name with the namespace expanded.
  + */
  +XalanDOMString
  +XercesParserLiaison::getExpandedElementName(const XalanElement&		elem) const
  +{
  +	return m_DOMSupport.getExpandedElementName(elem);
  +}
  +
  +
  +
  +/**
  + * Returns the attribute name with the namespace expanded.
  + */
  +XalanDOMString
  +XercesParserLiaison::getExpandedAttributeName(const XalanAttr&	attr) const
  +{
  +	return m_DOMSupport.getExpandedAttributeName(attr);
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setSpecialCharacters(const XalanDOMString&	str)
  +{
  +	m_specialCharacters = str;
  +}
  +
  +
  +
  +const XalanDOMString&
  +XercesParserLiaison::getSpecialCharacters() const
  +{
  +	return m_specialCharacters;
  +}
  +
  +
  +
  +int
  +XercesParserLiaison::getIndent() const
  +{
  +	return m_indent;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setIndent(int	i)
  +{
  +	m_indent = i;
  +}
  +
  +
  +
  +bool
  +XercesParserLiaison::getShouldExpandEntityRefs() const
  +{
  +	return m_shouldExpandEntityRefs;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::SetShouldExpandEntityRefs(bool	b)
  +{
  +	m_shouldExpandEntityRefs = b;
  +}
  +
  +
  +
  +bool
  +XercesParserLiaison::getUseValidation() const
  +{
  +	return m_useValidation;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setUseValidation(bool	b)
  +{
  +	m_useValidation = b;
  +}
  +
  +
  +
  +const XalanDOMString&
  +XercesParserLiaison::getParserDescription() const
  +{
  +	return theParserName;
  +}
  +
  +
  +
  +bool
  +XercesParserLiaison::getIncludeIgnorableWhitespace() const
  +{
  +	return m_includeIgnorableWhitespace;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setIncludeIgnorableWhitespace(bool	include)
  +{
  +	m_includeIgnorableWhitespace = include;
  +}
  +
  +
  +
  +ErrorHandler*
  +XercesParserLiaison::getErrorHandler()
  +{
  +	return m_errorHandler;
  +}
  +
  +
  +
  +const ErrorHandler*
  +XercesParserLiaison::getErrorHandler() const
  +{
  +	return m_errorHandler;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setErrorHandler(ErrorHandler*	handler)
  +{
  +	assert(handler != 0);
  +
  +	m_errorHandler = handler;
  +}
  +
  +
  +
  +bool
  +XercesParserLiaison::getDoNamespaces() const
  +{
  +	return m_doNamespaces;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setDoNamespaces(bool	newState)
  +{
  +	m_doNamespaces = newState;
  +}
  +
  +
  +
  +bool
  +XercesParserLiaison::getExitOnFirstFatalError() const
  +{
  +	return m_exitOnFirstFatalError;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setExitOnFirstFatalError(bool	newState)
  +{
  +	m_exitOnFirstFatalError = newState;
  +}
  +
  +
  +
  +EntityResolver*
  +XercesParserLiaison::getEntityResolver()
  +{
  +	return m_entityResolver;
  +}
  +
  +
  +
  +const EntityResolver*
  +XercesParserLiaison::getEntityResolver() const
  +{
  +	return m_entityResolver;
  +}
  +
  +
  +
  +void
  +XercesParserLiaison::setEntityResolver(EntityResolver*	resolver)
  +{
  +	m_entityResolver = resolver;
  +}
  +
  +
  +
  +XalanDocument*
   XercesParserLiaison::createDocument(const DOM_Document&		theXercesDocument)
   {
   	XercesDocumentBridge* const		theNewDocument =
  @@ -295,4 +489,54 @@
   void
   XercesParserLiaison::resetErrors()
   {
  +}
  +
  +
  +
  +DOMParser*
  +XercesParserLiaison::CreateDOMParser()
  +{
  +	DOMParser* const	theParser = new DOMParser;
  +
  +	theParser->setExpandEntityReferences(m_shouldExpandEntityRefs);
  +
  +	theParser->setDoValidation(m_useValidation);
  +
  +	theParser->setIncludeIgnorableWhitespace(m_includeIgnorableWhitespace);
  +
  +	theParser->setDoNamespaces(m_doNamespaces);
  +
  +	theParser->setExitOnFirstFatalError(m_exitOnFirstFatalError);
  +
  +	if (m_entityResolver != 0)
  +	{
  +		theParser->setEntityResolver(m_entityResolver);
  +	}
  +
  +	theParser->setErrorHandler(m_errorHandler);
  +
  +	return theParser;
  +}
  +
  +
  +
  +SAXParser*
  +XercesParserLiaison::CreateSAXParser()
  +{
  +	SAXParser* const	theParser = new SAXParser;
  +
  +	theParser->setDoValidation(m_useValidation);
  +
  +	theParser->setDoNamespaces(m_doNamespaces);
  +
  +	theParser->setExitOnFirstFatalError(m_exitOnFirstFatalError);
  +
  +	if (m_entityResolver != 0)
  +	{
  +		theParser->setEntityResolver(m_entityResolver);
  +	}
  +
  +	theParser->setErrorHandler(m_errorHandler);
  +
  +	return theParser;
   }
  
  
  
  1.10      +236 -12   xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.hpp
  
  Index: XercesParserLiaison.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XercesParserLiaison/XercesParserLiaison.hpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XercesParserLiaison.hpp	2000/05/08 17:20:59	1.9
  +++ XercesParserLiaison.hpp	2000/07/13 17:56:06	1.10
  @@ -76,31 +76,30 @@
   
   
   // Base class header file.
  -#include <XMLSupport/XMLParserLiaisonDefault.hpp>
  +#include <XMLSupport/XMLParserLiaison.hpp>
   
   
   
  -class DOM_Document;
  +class DOMParser;
   class DOMSupport;
  +class EntityResolver;
   class InputSource;
  +class SAXParser;
   class XercesDocumentBridge;
   class XSLProcessor;
   
   
   
  -class XALAN_XERCESPARSERLIAISON_EXPORT XercesParserLiaison : public XMLParserLiaisonDefault, public ErrorHandler
  +class XALAN_XERCESPARSERLIAISON_EXPORT XercesParserLiaison : public XMLParserLiaison, public ErrorHandler
   {
   public:
   
   	/**
   	 * Construct a XercesParserLiaison instance.
   	 *
  -	 * @param theSupport           instance of DOMSupport object
  -	 * @param fUseValidatingParser true if a validating parser is to be used
  +	 * @param theSupport		   instance of DOMSupport object
   	 */
  -	XercesParserLiaison(
  -			DOMSupport& 	theSupport,
  -			bool			fUseValidatingParser = false);
  +	XercesParserLiaison(DOMSupport&		theSupport);
   
   	virtual
   	~XercesParserLiaison();
  @@ -127,12 +126,208 @@
   	virtual XalanDocument*
   	createDocument();
   
  +	virtual XalanDocument*
  +	getDOMFactory();
  +
  +	virtual XalanDOMString
  +	getExpandedElementName(const XalanElement&	elem) const;
  +
  +	virtual XalanDOMString
  +	getExpandedAttributeName(const XalanAttr&	attr) const;
  +
  +	virtual void
  +	setSpecialCharacters(const XalanDOMString&	str);
  +
  +	virtual const XalanDOMString&
  +	getSpecialCharacters() const;
  +
  +	virtual int
  +	getIndent() const;
  +
  +	virtual void
  +	setIndent(int	i);
  +
  +	virtual bool
  +	getShouldExpandEntityRefs() const;
  +
  +	virtual void
  +	SetShouldExpandEntityRefs(bool	b);
  +
  +	virtual bool
  +	getUseValidation() const;
  +
  +	virtual void
  +	setUseValidation(bool	b);
  +
  +	virtual const XalanDOMString&
  +	getParserDescription() const;
  +
  +
   	// These interfaces are new to XercesParserLiaison...
   
  -	/** 
  +	/** Get the 'include ignorable whitespace' flag.
  +	  *
  +	  * This method returns the state of the parser's include ignorable
  +	  * whitespace flag.
  +	  *
  +	  * @return 'true' if the include ignorable whitespace flag is set on
  +	  * 		the parser, 'false' otherwise.
  +	  *
  +	  * @see #setIncludeIgnorableWhitespace
  +	  */
  +	virtual bool
  +	getIncludeIgnorableWhitespace() const;
  +
  +	/** Set the 'include ignorable whitespace' flag
  +	  *
  +	  * This method allows the user to specify whether a validating parser
  +	  * should include ignorable whitespaces as text nodes.  It has no effect
  +	  * on non-validating parsers which always include non-markup text.
  +	  * <p>When set to true (also the default), ignorable whitespaces will be
  +	  * added to the DOM tree as text nodes.  The method
  +	  * DOM_Text::isIgnorableWhitespace() will return true for those text
  +	  * nodes only.
  +	  * <p>When set to false, all ignorable whitespace will be discarded and
  +	  * no text node is added to the DOM tree.	Note: applications intended
  +	  * to process the "xml:space" attribute should not set this flag to false.
  +	  *
  +	  * @param include The new state of the include ignorable whitespace
  +	  * 			   flag.
  +	  *
  +	  * @see #getIncludeIgnorableWhitespace
  +	  */
  +	virtual void
  +	setIncludeIgnorableWhitespace(bool	include);
  +
  +	/**
  +	  * This method returns the installed error handler. Suitable
  +	  * for 'lvalue' usages.
  +	  *
  +	  * @return The pointer to the installed error handler object.
  +	  */
  +	virtual ErrorHandler*
  +	getErrorHandler();
  +
  +	/**
  +	  * This method returns the installed error handler. Suitable
  +	  * for 'rvalue' usages.
  +	  *
  +	  * @return A const pointer to the installed error handler object.
  +	  */
  +	virtual const ErrorHandler*
  +	getErrorHandler() const;
  +
  +	/**
  +	  * This method installs the user specified error handler on
  +	  * the parser.
  +	  *
  +	  * @param handler A pointer to the error handler to be called
  +	  * 			   when the parser comes across 'error' events
  +	  * 			   as per the SAX specification.
  +	  *
  +	  * @see Parser#setErrorHandler
  +	  */
  +	virtual void
  +	setErrorHandler(ErrorHandler*	handler);
  +
  +	/**
  +	  * This method returns the state of the parser's namespace
  +	  * handling capability.
  +	  *
  +	  * @return true, if the parser is currently configured to
  +	  * 		understand namespaces, false otherwise.
  +	  *
  +	  * @see #setDoNamespaces
  +	  */
  +	virtual bool
  +	getDoNamespaces() const;
  +
  +	/**
  +	  * This method allows users to enable or disable the parser's
  +	  * namespace processing. When set to true, parser starts enforcing
  +	  * all the constraints / rules specified by the NameSpace
  +	  * specification.
  +	  *
  +	  * <p>The parser's default state is: false.</p>
  +	  *
  +	  * <p>This flag is ignored by the underlying scanner if the installed
  +	  * validator indicates that namespace constraints should be
  +	  * enforced.</p>
  +	  *
  +	  * @param newState The value specifying whether NameSpace rules should
  +	  * 				be enforced or not.
  +	  *
  +	  * @see #getDoNamespaces
  +	  */
  +	virtual void
  +	setDoNamespaces(bool	newState);
  +
  +	/**
  +	  * This method returns the state of the parser's
  +	  * exit-on-First-Fatal-Error flag.
  +	  *
  +	  * @return true, if the parser is currently configured to
  +	  * 		exit on the first fatal error, false otherwise.
  +	  *
  +	  * @see #setExitOnFirstFatalError
  +	  */
  +	virtual bool
  +	getExitOnFirstFatalError() const;
  +
  +	/**
  +	  * 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.
  +	  *
  +	  * <p>The default value is 'true' and the parser exits on the
  +	  * first fatal error.</p>
  +	  *
  +	  * @param newState The value specifying whether the parser should
  +	  * 				continue or exit when it encounters the first
  +	  * 				fatal error.
  +	  *
  +	  * @see #getExitOnFirstFatalError
  +	  */
  +	virtual void
  +	setExitOnFirstFatalError(bool	newState);
  +
  +	/**
  +	  * This method returns the installed entity resolver. Suitable
  +	  * for 'lvalue' usages.
  +	  *
  +	  * @return The pointer to the installed entity resolver object.
  +	  */
  +	virtual EntityResolver*
  +	getEntityResolver();
  +
  +	/**
  +	  * This method returns the installed entity resolver. Suitable
  +	  * for 'rvalue' usages.
  +	  *
  +	  * @return A const pointer to the installed entity resolver object.
  +	  */
  +	virtual const EntityResolver*
  +	getEntityResolver() const;
  +
  +	/**
  +	  * This method installs the user specified entity resolver on the
  +	  * parser. It allows applications to trap and redirect calls to
  +	  * external entities.
  +	  *
  +	  * @param handler A pointer to the entity resolver to be called
  +	  * 			   when the parser comes across references to
  +	  * 			   entities in the XML file.
  +	  *
  +	  * @see Parser#setEntityResolver
  +	  */
  +	virtual void
  +	setEntityResolver(EntityResolver*	resolver);
  +
  +	/**
   	 * Create a XalanDocument proxy for an existing Xerces document.
   	 * The parser liaison owns the instance, and you must not delete
  -	 * it.  The liaison will delete it when reset() is called, or the
  +	 * it.	The liaison will delete it when reset() is called, or the
   	 * liaison is destroyed.
   	 *
   	 * @param theXercesDocument The Xerces document.
  @@ -179,6 +374,14 @@
   	virtual void
   	resetErrors();
   
  +protected:
  +
  +	virtual DOMParser*
  +	CreateDOMParser();
  +
  +	virtual SAXParser*
  +	CreateSAXParser();
  +
   private:
   
   #if defined(XALAN_NO_NAMESPACES)
  @@ -186,10 +389,31 @@
   #else
   	typedef std::map<const XalanDocument*, XercesDocumentBridge*>	DocumentMapType;
   #endif
  +
  +	// Data members...
  +	DOMSupport& 		m_DOMSupport;
  +
  +	XalanDOMString		m_specialCharacters;
  +
  +	int 				m_indent;
  +
  +	bool				m_shouldExpandEntityRefs;
  +
  +	bool				m_useValidation;
  +
  +	bool				m_includeIgnorableWhitespace;
  +
  +	bool				m_doNamespaces;
  +
  +	bool				m_exitOnFirstFatalError;
  +
  +	XalanDocument*		m_factory;
  +
  +	EntityResolver* 	m_entityResolver;
   
  -	const bool			m_fUseValidatingParser;
  +	ErrorHandler*		m_errorHandler;
   
  -	DocumentMapType		m_documentMap;
  +	DocumentMapType 	m_documentMap;
   };