com.aliasi.xml
Class SAXFilterHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.aliasi.xml.SimpleElementHandler
          extended by com.aliasi.xml.SAXFilterHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
CompositeFilter, ElementStackFilter, GroupCharactersFilter, RemoveElementsFilter, SAXWriterFilter

public class SAXFilterHandler
extends SimpleElementHandler

The SAXFilterHandler provides a base class for filtering SAX handlers. A SAX filter handler behaves like other output stream filters such as FilterOutputStream. A filter acts as a container for a handler, which may be supplied at construction time or set. The filter typically receives SAX events and processes them in some way before passing them to the contained handler. This particular filter implements the content handler component of XMLFilterImpl.

The contained handler may be changed with setHandler(DefaultHandler), thus allowing reuse of filters. The implementation of all methods in this class delegates the methods to the contained handler, so an extending class need only implement the handler methods that it would like to filter. The contained handler is protected and may be accessed directly by subclasses; its methods may be accessed through super.

Warning: The Sun JDK 1.4.2 implementation of DefaultHandler is defective in not declaring an IOException to be thrown by DefaultHandler.resolveEntity(String,String). See the method documentation for resolveEntity(String,String) for a description of this class's implemented workaround.

Since:
LingPipe1.0
Version:
1.0
Author:
Bob Carpenter

Field Summary
protected  DefaultHandler mHandler
          The contained default handler to which events are delegated by default.
 
Fields inherited from class com.aliasi.xml.SimpleElementHandler
CDATA_ATTS_TYPE, EMPTY_ATTS, NO_OP_DEFAULT_HANDLER
 
Constructor Summary
SAXFilterHandler()
          Construct a filter handler that contains the no-op handler SimpleElementHandler.NO_OP_DEFAULT_HANDLER.
SAXFilterHandler(DefaultHandler handler)
          Construct a filter handler with the specified contained handler.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Call delegated to mHandler.
 void endDocument()
          Call delegated to mHandler.
 void endElement(String namespaceURI, String localName, String qName)
          Call delegated to mHandler.
 void endPrefixMapping(String prefix)
          Call delegated to mHandler.
 void error(SAXParseException exception)
          Call delegated to mHandler.
 void fatalError(SAXParseException exception)
          Call delegated to mHandler.
 void ignorableWhitespace(char[] ch, int start, int length)
          Call delegated to mHandler.
 void notationDecl(String name, String publicId, String systemId)
          Call delegated to mHandler.
 void processingInstruction(String target, String data)
          Call delegated to mHandler.
 InputSource resolveEntity(String publicId, String systemId)
          Call delegated to mHandler.
 void setDocumentLocator(Locator locator)
          Call delegated to mHandler.
 void setHandler(DefaultHandler handler)
          Sets the contained handler to the specified value.
 void skippedEntity(String name)
          Call delegated to mHandler.
 void startDocument()
          Call delegated to mHandler.
 void startElement(String namespaceURI, String localName, String qName, Attributes atts)
          Call delegated to mHandler.
 void startPrefixMapping(String prefix, String uri)
          Call delegated to mHandler.
 void unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
          Call delegated to mHandler.
 void warning(SAXParseException exception)
          Call delegated to mHandler.
 
Methods inherited from class com.aliasi.xml.SimpleElementHandler
addSimpleAttribute, characters, characters, characters, characters, createAttributes, createAttributes, createAttributes, createAttributes, createAttributes, createAttributes, endSimpleElement, endSimpleElement, startEndSimpleElement, startEndSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mHandler

protected DefaultHandler mHandler
The contained default handler to which events are delegated by default. Subclasses may also access its methods by means of super invocations.

Constructor Detail

SAXFilterHandler

public SAXFilterHandler(DefaultHandler handler)
Construct a filter handler with the specified contained handler.

Parameters:
handler - The handler to be contained by the constructed filter.

SAXFilterHandler

public SAXFilterHandler()
Construct a filter handler that contains the no-op handler SimpleElementHandler.NO_OP_DEFAULT_HANDLER.

Method Detail

setHandler

public void setHandler(DefaultHandler handler)
Sets the contained handler to the specified value.


startDocument

public void startDocument()
                   throws SAXException
Call delegated to mHandler.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
SAXException - if the contained hanlder throws a SAX exception.

endDocument

public void endDocument()
                 throws SAXException
Call delegated to mHandler.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
Throws:
SAXException - if the contained hanlder throws a SAX exception.

startElement

public void startElement(String namespaceURI,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Call delegated to mHandler.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Parameters:
namespaceURI - The URI identifying the name space, or null if there isn't one.
localName - Local name of element.
qName - Qualified name of element, which is prefixed with the name space URI and a colon if it is non-null, and is equal to local name if there is no name space specified.
atts - Attributes for this element.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

endElement

public void endElement(String namespaceURI,
                       String localName,
                       String qName)
                throws SAXException
Call delegated to mHandler.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Parameters:
namespaceURI - The URI identifying the name space, or null if there isn't one.
localName - Local name of element.
qName - Qualified name of element, which is prefixed with the name space URI and a colon if it is non-null, and is equal to local name if there is no name space specified.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Call delegated to mHandler.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Parameters:
ch - Character array containing characters to handle.
start - Index of first character to handle.
length - Number of characters to handle.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Call delegated to mHandler.

Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class DefaultHandler
Parameters:
ch - Character array containing characters to handle.
start - Index of first character to handle.
length - Number of characters to handle.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Call delegated to mHandler.

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class DefaultHandler
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none is supplied.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Call delegated to mHandler.

Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class DefaultHandler
Parameters:
prefix - The namespace prefix being declared.
uri - The namespace URI mapped to the prefix.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Call delegated to mHandler.

Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class DefaultHandler
Parameters:
prefix - The namespace prefix being declared.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Call delegated to mHandler.

Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class DefaultHandler
Parameters:
name - The name of the skipped entity.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

setDocumentLocator

public void setDocumentLocator(Locator locator)
Call delegated to mHandler.

Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler
Parameters:
locator - A locator for all SAX document events.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException
Call delegated to mHandler.

Note that this method only throws SAX exceptions, whereas the SAX specification allows it to also throw an I/O exception. In this class's implementation, all I/O exceptions thrown by the delegate are converted to SAX exceptions before being re-thrown by this method. This extreme measure is taken because a bug in JDK 1.4.x failed to delcare an I/O exception on the resolve entity method. Although Sun's 1.5 JDK does declare the exception, this method converts it to allow the same source to compile in 1.4 and 1.5. For more information on this bug, see Sun's bug report:

resolveEntity in DefaultHandler does not throw IOException

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class DefaultHandler
Parameters:
publicId - The public identifier, or null if none is available.
systemId - The system identifier provided in the XML document.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

error

public void error(SAXParseException exception)
           throws SAXException
Call delegated to mHandler.

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Parameters:
exception - The error information, encoded as an exception.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

fatalError

public void fatalError(SAXParseException exception)
                throws SAXException
Call delegated to mHandler.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
Parameters:
exception - The fatal error information, encoded as an exception.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

warning

public void warning(SAXParseException exception)
             throws SAXException
Call delegated to mHandler.

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Parameters:
exception - The warning information, encoded as an exception.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

notationDecl

public void notationDecl(String name,
                         String publicId,
                         String systemId)
                  throws SAXException
Call delegated to mHandler.

Specified by:
notationDecl in interface DTDHandler
Overrides:
notationDecl in class DefaultHandler
Parameters:
name - The notation name.
publicId - The notation public identifier, or null if none is available.
systemId - The notation system identifier.
Throws:
SAXException - if the contained hanlder throws a SAX exception.

unparsedEntityDecl

public void unparsedEntityDecl(String name,
                               String publicId,
                               String systemId,
                               String notationName)
                        throws SAXException
Call delegated to mHandler.

Specified by:
unparsedEntityDecl in interface DTDHandler
Overrides:
unparsedEntityDecl in class DefaultHandler
Parameters:
name - The entity name.
publicId - The entity public identifier, or null if none is available.
systemId - The entity system identifier.
notationName - The name of the associated notation.
Throws:
SAXException - if the contained hanlder throws a SAX exception.