com.cafesoft.core.xml
Class DefaultXmlHandler

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--com.cafesoft.core.xml.DefaultXmlHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class DefaultXmlHandler
extends DefaultHandler

DefaultXmlHandler provides general XML handling facilities. It implements methods for resolving DTD Entities and reporting XML parsing warnings, errors, and fatal errors. In particular, methods within the following interfaces are overridden:

The EntityResolver implementation looks for DTD references and attempts to return an InputSource to a DTD file from an ordered list of DTD directories, enabling this handler to return overridden XML schemas.

The ErrorHandler implementation writes XML parsing exceptions to a Cafesoft Logger.

Since:
2/4/02

Field Summary
protected  boolean debug
          A flag used to enable/disable DEBUG-level messages.
protected  String[] dtdPathArray
          The array of directory paths that are searched for DTD files.
protected  Logger logger
          The Logger to which messages are logged.
 
Constructor Summary
DefaultXmlHandler(String[] dtdPathArray, Logger logger)
          Create a new DefaultXmlHandler.
DefaultXmlHandler(String[] dtdPathArray, Logger logger, String context)
          Create a new DefaultXmlHandler.
 
Method Summary
 void addSAXParseExceptionListener(SAXParseExceptionListener listener)
          Add a SAXParseExceptionListener.
 void error(SAXParseException exception)
          Receive notification of a recoverable error.
 void fatalError(SAXParseException exception)
          Receive notification of a non-recoverable error.
protected  void fireException(SAXParseException exception, int level)
          Fire a SAXParseException to all registered listeners
 void removeSAXParseExceptionListener(SAXParseExceptionListener listener)
          Add a SAXParseExceptionListener.
 InputSource resolveEntity(String publicId, String systemId)
          Resolve an Entity.
 boolean setDebug(boolean enable)
          Enable or disable debugging.
 void warning(SAXParseException exception)
          Receive notification of a warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger
The Logger to which messages are logged.


dtdPathArray

protected String[] dtdPathArray
The array of directory paths that are searched for DTD files.


debug

protected boolean debug
A flag used to enable/disable DEBUG-level messages.

Constructor Detail

DefaultXmlHandler

public DefaultXmlHandler(String[] dtdPathArray,
                         Logger logger)
Create a new DefaultXmlHandler.

Parameters:
dtdPathArray - a String array of directory paths to be searched for DTD files via the EntityResolver interface. The paths are searched in order.
logger - the Logger to which messages are to be logged

DefaultXmlHandler

public DefaultXmlHandler(String[] dtdPathArray,
                         Logger logger,
                         String context)
Create a new DefaultXmlHandler.

Parameters:
dtdPathArray - a String array of directory paths to be searched for DTD files via the EntityResolver interface. The paths are searched in order.
logger - the Logger to which messages are to be logged.
context - a tag used to report the context within which a ErrorHandler method is invoked. For example, the name of the file being parsed.
Method Detail

setDebug

public boolean setDebug(boolean enable)
Enable or disable debugging.

Parameters:
enable - if true, enable debugging, else disable debugging.
Returns:
the previous value of the debug flag, which is useful for restoring the debug state if temporarily changed.

addSAXParseExceptionListener

public void addSAXParseExceptionListener(SAXParseExceptionListener listener)
Add a SAXParseExceptionListener.

Parameters:
listener - the SAXParseExceptionListener

removeSAXParseExceptionListener

public void removeSAXParseExceptionListener(SAXParseExceptionListener listener)
Add a SAXParseExceptionListener.

Parameters:
listener - the SAXParseExceptionListener

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException
Resolve an Entity.

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class DefaultHandler
Parameters:
publicId - the public identifier for the entity.
systemId - the system identifier for the entity.
Returns:
an input source to the DTD associated with the identifier.
Throws:
SAXException - if a problem resolving the Entity.

warning

public void warning(SAXParseException exception)
             throws SAXException
Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML 1.0 recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Parameters:
exception - the warning information encapsulated in a SAX parse exception.
Throws:
SAXException - any SAX exception, possibly wrapping another exception.
See Also:
SAXParseException

error

public void error(SAXParseException exception)
           throws SAXException
Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML 1.0 recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Parameters:
exception - the error information encapsulated in a SAX parse exception.
Throws:
SAXException - any SAX exception, possibly wrapping another exception.
See Also:
SAXParseException

fatalError

public void fatalError(SAXParseException exception)
                throws SAXException
Receive notification of a non-recoverable error.

This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.

The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting addition error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
Parameters:
exception - the warning information encapsulated in a SAX parse exception.
Throws:
SAXException - any SAX exception, possibly wrapping another exception.
See Also:
SAXParseException

fireException

protected void fireException(SAXParseException exception,
                             int level)
Fire a SAXParseException to all registered listeners

Parameters:
exception - the SAXParseException to send to the listeners
level - the level of exception: WARNING, ERROR, or FATAL.


Generated on 5:16:42 PM May 12, 2008, © 1996-2005 Cafésoft LLC. All rights reserved.