org.objectweb.jonas_lib.deployment
Class SAXParserHelper

java.lang.Object
  |
  +--org.objectweb.jonas_lib.deployment.SAXParserHelper
All Implemented Interfaces:
org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class SAXParserHelper
extends java.lang.Object
implements org.xml.sax.ErrorHandler, org.xml.sax.EntityResolver

This class provides support for complete XML parsing support including DTD location resolution and XML parsing errors. It allows parsing XML files with are without DOCTYPE and with DTDs that can be found from the classpath.

Author:
Brett McLaughlin, Christophe Ney

Constructor Summary
SAXParserHelper()
          constructor using the default ErrorHandler and EntityResolver
SAXParserHelper(org.xml.sax.ErrorHandler errorHandler, org.xml.sax.EntityResolver entityResolver)
          constructor for use of external ErrorHandler and EntityResolver.
 
Method Summary
 void error(org.xml.sax.SAXParseException e)
          If a DTD has been found, this will delegate error callbacks to the errorHandler or rethrow them.
 void fatalError(org.xml.sax.SAXParseException e)
          Delegate fatalerror callbacks to the errorHandler or rethrow them.
 org.xml.sax.SAXParseException getSAXParseException()
          Retreive the previously thrown SAXParseException.
 org.xml.sax.EntityResolver getWrappedEntityResolver()
          Return a wrapped EntityResolver for use by the parser.
 org.xml.sax.ErrorHandler getWrappedErrorHandler()
          Return a wrapped ErrorHandler for use by the parser.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicID, java.lang.String systemID)
          Method used by the parser to read the DTD specified in DOCTYPE.
 void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
          set the EntityResolver to be used by the helper
 void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
          set the ErrorHandler to be used by the helper
 void warning(org.xml.sax.SAXParseException e)
          Delegate warning callbacks to the errorHandler or ingnore them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXParserHelper

public SAXParserHelper(org.xml.sax.ErrorHandler errorHandler,
                       org.xml.sax.EntityResolver entityResolver)
constructor for use of external ErrorHandler and EntityResolver. It is important to note that a new helper instance should be used for each new parsing. This ensure a correct value of resolveEntityCalled
Parameters:
errorHandler - the Errorhandler to delegate to
entityResolver - the EntityResolver to delegate to

SAXParserHelper

public SAXParserHelper()
constructor using the default ErrorHandler and EntityResolver
Method Detail

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
set the ErrorHandler to be used by the helper

setEntityResolver

public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
set the EntityResolver to be used by the helper

getWrappedErrorHandler

public org.xml.sax.ErrorHandler getWrappedErrorHandler()
Return a wrapped ErrorHandler for use by the parser. This allows storing the SAXException for precise line:column error reporting

getWrappedEntityResolver

public org.xml.sax.EntityResolver getWrappedEntityResolver()
Return a wrapped EntityResolver for use by the parser. This is done to enable grammar error handling only when the DTD is present

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Delegate warning callbacks to the errorHandler or ingnore them.
Specified by:
warning in interface org.xml.sax.ErrorHandler
Parameters:
e - the SAXParseException that caused the warning.

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
If a DTD has been found, this will delegate error callbacks to the errorHandler or rethrow them. The exception is stored when a SAXParseException is thrown.
Specified by:
error in interface org.xml.sax.ErrorHandler
Parameters:
e - the SAXParseException that caused the error.

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Delegate fatalerror callbacks to the errorHandler or rethrow them. The exception is stored when a SAXParseException is thrown.
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Parameters:
e - the SAXParseException that caused the fatal error.

getSAXParseException

public org.xml.sax.SAXParseException getSAXParseException()
Retreive the previously thrown SAXParseException.
Returns:
SAXParseException previously thrown or null if not found

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicID,
                                             java.lang.String systemID)
                                      throws java.io.IOException,
                                             org.xml.sax.SAXException
Method used by the parser to read the DTD specified in DOCTYPE. This delegates to the entityResolver if set. Otherwise, the default behaviour is as follow:

The filename of the systemID parameter (which matches to the filename of the PUBLIC url or SYSTEM path) is used as a name for loading the DTD as a classloader resource.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Parameters:
publicID - the name of DOCTYPE SYSTEM
systemID - the url of DOCTYPE PUBLIC or path of DOCTYPE SYSTEM