FileDocCategorySizeDatePackage
XMLFilterImpl.javaAPI DocAndroid 1.5 API20155Wed May 06 22:41:06 BST 2009org.xml.sax.helpers

XMLFilterImpl

public class XMLFilterImpl extends Object implements ErrorHandler, XMLFilter, EntityResolver, DTDHandler, ContentHandler
Base class for deriving an XML filter.
This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY. See http://www.saxproject.org for further information.

This class is designed to sit between an {@link org.xml.sax.XMLReader XMLReader} and the client application's event handlers. By default, it does nothing but pass requests up to the reader and events on to the handlers unmodified, but subclasses can override specific methods to modify the event stream or the configuration requests as they pass through.

since
SAX 2.0
author
David Megginson
version
2.0.1 (sax2r2)
see
org.xml.sax.XMLFilter
see
org.xml.sax.XMLReader
see
org.xml.sax.EntityResolver
see
org.xml.sax.DTDHandler
see
org.xml.sax.ContentHandler
see
org.xml.sax.ErrorHandler

Fields Summary
private XMLReader
parent
private Locator
locator
private EntityResolver
entityResolver
private DTDHandler
dtdHandler
private ContentHandler
contentHandler
private ErrorHandler
errorHandler
Constructors Summary
public XMLFilterImpl()
Construct an empty XML filter, with no parent.

This filter will have no parent: you must assign a parent before you start a parse or do any configuration with setFeature or setProperty, unless you use this as a pure event consumer rather than as an {@link XMLReader}.

see
org.xml.sax.XMLReader#setFeature
see
org.xml.sax.XMLReader#setProperty
see
#setParent

    super();
    
public XMLFilterImpl(XMLReader parent)
Construct an XML filter with the specified parent.

param
parent the XML reader from which this filter receives its events.
see
#setParent
see
#getParent

        super();
    setParent(parent);
    
Methods Summary
public voidcharacters(char[] ch, int start, int length)
Filter a character data event.

param
ch An array of characters.
param
start The starting position in the array.
param
length The number of characters to use from the array.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.characters(ch, start, length);
    }
    
public voidendDocument()
Filter an end document event.

exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.endDocument();
    }
    
public voidendElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
Filter an end element event.

param
uri The element's Namespace URI, or the empty string.
param
localName The element's local name, or the empty string.
param
qName The element's qualified (prefixed) name, or the empty string.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.endElement(uri, localName, qName);
    }
    
public voidendPrefixMapping(java.lang.String prefix)
Filter an end Namespace prefix mapping event.

param
prefix The Namespace prefix.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.endPrefixMapping(prefix);
    }
    
public voiderror(org.xml.sax.SAXParseException e)
Filter an error event.

param
e The error as an exception.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (errorHandler != null) {
        errorHandler.error(e);
    }
    
public voidfatalError(org.xml.sax.SAXParseException e)
Filter a fatal error event.

param
e The error as an exception.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (errorHandler != null) {
        errorHandler.fatalError(e);
    }
    
public org.xml.sax.ContentHandlergetContentHandler()
Get the content event handler.

return
The current content handler, or null if none was set.

    return contentHandler;
    
public org.xml.sax.DTDHandlergetDTDHandler()
Get the current DTD event handler.

return
The current DTD handler, or null if none was set.

    return dtdHandler;
    
public org.xml.sax.EntityResolvergetEntityResolver()
Get the current entity resolver.

return
The current entity resolver, or null if none was set.

    return entityResolver;
    
public org.xml.sax.ErrorHandlergetErrorHandler()
Get the current error event handler.

return
The current error handler, or null if none was set.

    return errorHandler;
    
public booleangetFeature(java.lang.String name)
Look up the value of a feature.

This will always fail if the parent is null.

param
name The feature name.
return
The current value of the feature.
exception
org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved from the parent.
exception
org.xml.sax.SAXNotSupportedException When the parent recognizes the feature name but cannot determine its value at this time.

    if (parent != null) {
        return parent.getFeature(name);
    } else {
        throw new SAXNotRecognizedException("Feature: " + name);
    }
    
public org.xml.sax.XMLReadergetParent()
Get the parent reader.

return
The parent XML reader, or null if none is set.
see
#setParent

    return parent;
    
public java.lang.ObjectgetProperty(java.lang.String name)
Look up the value of a property.

param
name The property name.
return
The current value of the property.
exception
org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved from the parent.
exception
org.xml.sax.SAXNotSupportedException When the parent recognizes the property name but cannot determine its value at this time.

    if (parent != null) {
        return parent.getProperty(name);
    } else {
        throw new SAXNotRecognizedException("Property: " + name);
    }
    
public voidignorableWhitespace(char[] ch, int start, int length)
Filter an ignorable whitespace event.

param
ch An array of characters.
param
start The starting position in the array.
param
length The number of characters to use from the array.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.ignorableWhitespace(ch, start, length);
    }
    
public voidnotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
Filter a notation declaration event.

param
name The notation name.
param
publicId The notation's public identifier, or null.
param
systemId The notation's system identifier, or null.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (dtdHandler != null) {
        dtdHandler.notationDecl(name, publicId, systemId);
    }
    
public voidparse(org.xml.sax.InputSource input)
Parse a document.

param
input The input source for the document entity.
exception
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
exception
java.io.IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.

    setupParse();
    parent.parse(input);
    
public voidparse(java.lang.String systemId)
Parse a document.

param
systemId The system identifier as a fully-qualified URI.
exception
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception.
exception
java.io.IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.

    parse(new InputSource(systemId));
    
public voidprocessingInstruction(java.lang.String target, java.lang.String data)
Filter a processing instruction event.

param
target The processing instruction target.
param
data The text following the target.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.processingInstruction(target, data);
    }
    
public org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.String systemId)
Filter an external entity resolution.

param
publicId The entity's public identifier, or null.
param
systemId The entity's system identifier.
return
A new InputSource or null for the default.
exception
org.xml.sax.SAXException The client may throw an exception during processing.
exception
java.io.IOException The client may throw an I/O-related exception while obtaining the new InputSource.

    if (entityResolver != null) {
        return entityResolver.resolveEntity(publicId, systemId);
    } else {
        return null;
    }
    
public voidsetContentHandler(org.xml.sax.ContentHandler handler)
Set the content event handler.

param
handler the new content handler

    contentHandler = handler;
    
public voidsetDTDHandler(org.xml.sax.DTDHandler handler)
Set the DTD event handler.

param
handler the new DTD handler

    dtdHandler = handler;
    
public voidsetDocumentLocator(org.xml.sax.Locator locator)
Filter a new document locator event.

param
locator The document locator.

    this.locator = locator;
    if (contentHandler != null) {
        contentHandler.setDocumentLocator(locator);
    }
    
public voidsetEntityResolver(org.xml.sax.EntityResolver resolver)
Set the entity resolver.

param
resolver The new entity resolver.

    entityResolver = resolver;
    
public voidsetErrorHandler(org.xml.sax.ErrorHandler handler)
Set the error event handler.

param
handler the new error handler

    errorHandler = handler;
    
public voidsetFeature(java.lang.String name, boolean value)
Set the value of a feature.

This will always fail if the parent is null.

param
name The feature name.
param
value The requested feature value.
exception
org.xml.sax.SAXNotRecognizedException If the feature value can't be assigned or retrieved from the parent.
exception
org.xml.sax.SAXNotSupportedException When the parent recognizes the feature name but cannot set the requested value.

    if (parent != null) {
        parent.setFeature(name, value);
    } else {
        throw new SAXNotRecognizedException("Feature: " + name);
    }
    
public voidsetParent(org.xml.sax.XMLReader parent)
Set the parent reader.

This is the {@link org.xml.sax.XMLReader XMLReader} from which this filter will obtain its events and to which it will pass its configuration requests. The parent may itself be another filter.

If there is no parent reader set, any attempt to parse or to set or get a feature or property will fail.

param
parent The parent XML reader.
see
#getParent

    this.parent = parent;
    
public voidsetProperty(java.lang.String name, java.lang.Object value)
Set the value of a property.

This will always fail if the parent is null.

param
name The property name.
param
value The requested property value.
exception
org.xml.sax.SAXNotRecognizedException If the property value can't be assigned or retrieved from the parent.
exception
org.xml.sax.SAXNotSupportedException When the parent recognizes the property name but cannot set the requested value.

    if (parent != null) {
        parent.setProperty(name, value);
    } else {
        throw new SAXNotRecognizedException("Property: " + name);
    }
    
private voidsetupParse()
Set up before a parse.

Before every parse, check whether the parent is non-null, and re-register the filter for all of the events.

    if (parent == null) {
        throw new NullPointerException("No parent for filter");
    }
    parent.setEntityResolver(this);
    parent.setDTDHandler(this);
    parent.setContentHandler(this);
    parent.setErrorHandler(this);
    
public voidskippedEntity(java.lang.String name)
Filter a skipped entity event.

param
name The name of the skipped entity.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.skippedEntity(name);
    }
    
public voidstartDocument()
Filter a start document event.

exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.startDocument();
    }
    
public voidstartElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
Filter a start element event.

param
uri The element's Namespace URI, or the empty string.
param
localName The element's local name, or the empty string.
param
qName The element's qualified (prefixed) name, or the empty string.
param
atts The element's attributes.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.startElement(uri, localName, qName, atts);
    }
    
public voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)
Filter a start Namespace prefix mapping event.

param
prefix The Namespace prefix.
param
uri The Namespace URI.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (contentHandler != null) {
        contentHandler.startPrefixMapping(prefix, uri);
    }
    
public voidunparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
Filter an unparsed entity declaration event.

param
name The entity name.
param
publicId The entity's public identifier, or null.
param
systemId The entity's system identifier, or null.
param
notationName The name of the associated notation.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (dtdHandler != null) {
        dtdHandler.unparsedEntityDecl(name, publicId, systemId,
                      notationName);
    }
    
public voidwarning(org.xml.sax.SAXParseException e)
Filter a warning event.

param
e The warning as an exception.
exception
org.xml.sax.SAXException The client may throw an exception during processing.

    if (errorHandler != null) {
        errorHandler.warning(e);
    }