java.lang.Object | +--gnu.xml.pipeline.EventFilterAll Implemented Interfaces:
static java.lang.String | DECL_HANDLER SAX2 property identifier for DeclHandler events |
static java.lang.String | FEATURE_URI SAX2 URI prefix for standard feature flags. |
static java.lang.String | LEXICAL_HANDLER SAX2 property identifier for LexicalHandler events |
static java.lang.String | PROPERTY_URI SAX2 URI prefix for standard properties (mostly for handlers). |
EventFilter() Initializes all handlers to null. |
EventFilter(gnu.xml.pipeline.EventConsumer consumer) Handlers that are not otherwise set will default to those from the specified consumer, making it easy to pass events through. |
void | attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String mode, java.lang.String value) SAX2: passes this callback to the next consumer, if any |
static void | bind(org.xml.sax.XMLReader producer, gnu.xml.pipeline.EventConsumer consumer) Binds the standard SAX2 handlers from the specified consumer pipeline to the specified producer. |
void | chainTo(org.xml.sax.helpers.XMLFilterImpl next) Treats the XMLFilterImpl as a limited functionality event consumer, by arranging to deliver events to it; this lets such classes be "wrapped" as pipeline stages. |
void | characters(char ch[][] , int start, int length) SAX2: passes this callback to the next consumer, if any |
void | comment(char ch[][] , int start, int length) SAX2: passes this callback to the next consumer, if any |
void | elementDecl(java.lang.String name, java.lang.String model) SAX2: passes this callback to the next consumer, if any |
void | endCDATA() SAX2: passes this callback to the next consumer, if any |
void | endDTD() SAX2: passes this callback to the next consumer, if any |
void | endDocument() SAX2: passes this callback to the next consumer, if any |
void | endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) SAX2: passes this callback to the next consumer, if any |
void | endEntity(java.lang.String name) SAX2: passes this callback to the next consumer, if any. |
void | endPrefixMapping(java.lang.String prefix) SAX2: passes this callback to the next consumer, if any |
void | externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) SAX2: passes this callback to the next consumer, if any |
org.xml.sax.ContentHandler | getContentHandler() Returns the content handler being used. |
org.xml.sax.DTDHandler | getDTDHandler() Returns the dtd handler being used. |
org.xml.sax.Locator | getDocumentLocator() Returns any locator provided to the next consumer, if this class (or a subclass) is handling ContentHandler events. |
org.xml.sax.ErrorHandler | getErrorHandler() Returns the error handler assigned this filter stage, or null if no such assigment has been made. |
gnu.xml.pipeline.EventConsumer | getNext() Returns the next event consumer in sequence; or null if there is no such handler. |
java.lang.Object | getProperty(java.lang.String id) Retrieves a property of unknown intent (usually a handler) |
void | ignorableWhitespace(char ch[][] , int start, int length) SAX2: passes this callback to the next consumer, if any |
void | internalEntityDecl(java.lang.String name, java.lang.String value) SAX2: passes this callback to the next consumer, if any |
void | notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) SAX1: passes this callback to the next consumer, if any |
void | processingInstruction(java.lang.String target, java.lang.String data) SAX2: passes this callback to the next consumer, if any |
void | setContentHandler(org.xml.sax.ContentHandler h) Assigns the content handler to use; a null handler indicates that these events will not be forwarded. |
void | setDTDHandler(org.xml.sax.DTDHandler h) Assigns the DTD handler to use; a null handler indicates that these events will not be forwarded. |
void | setDocumentLocator(org.xml.sax.Locator locator) SAX2: passes this callback to the next consumer, if any |
void | setErrorHandler(org.xml.sax.ErrorHandler handler) Records the error handler that should be used by this stage, and passes it "downstream" to any subsequent stage. |
void | setProperty(java.lang.String id, java.lang.Object o) Stores the property, normally a handler; a null handler indicates that these events will not be forwarded. |
void | skippedEntity(java.lang.String name) SAX2: passes this callback to the next consumer, if any |
void | startCDATA() SAX2: passes this callback to the next consumer, if any |
void | startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) SAX2: passes this callback to the next consumer, if any |
void | startDocument() SAX2: passes this callback to the next consumer, if any |
void | startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) SAX2: passes this callback to the next consumer, if any |
void | startEntity(java.lang.String name) SAX2: passes this callback to the next consumer, if any. |
void | startPrefixMapping(java.lang.String prefix, java.lang.String uri) SAX2: passes this callback to the next consumer, if any |
void | unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName) SAX1: passes this callback to the next consumer, if any |
public static final String DECL_HANDLER
public static final String FEATURE_URI
public static final String LEXICAL_HANDLER
public static final String PROPERTY_URI
public EventFilter()
public EventFilter(gnu.xml.pipeline.EventConsumer consumer)
consumer
- public void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String mode, java.lang.String value)
eName
- aName
- type
- mode
- value
- public static void bind(org.xml.sax.XMLReader producer, gnu.xml.pipeline.EventConsumer consumer)
At the head of the pipeline, certain standard event filters are recognized and handled specially. This facilitates construction of processing pipelines that work regardless of the capabilities of the XMLReader implementation in use; for example, it permits validating output of a gnu.xml.util.DomParser.
Other than that, this method works with any kind of event consumer, not just event filters. Note that in all cases, the standard handlers are assigned; any previous handler assignments for the handler will be overridden.
producer
- will deliver events to the specified consumerconsumer
- pipeline supplying event handlers to be associated
with the producer (may not be null)public void chainTo(org.xml.sax.helpers.XMLFilterImpl next)
Upstream Event Setup: If no handlers have been assigned to this EventFilter, then the handlers from specified XMLFilterImpl are returned from this EventConsumer: the XMLFilterImpl is just "wrapped". Otherwise the specified handlers will be returned.
Downstream Event Setup: Subclasses may chain event delivery to the specified XMLFilterImpl by invoking the appropiate superclass methods, as if their constructor passed a "next" EventConsumer to the constructor for this class. If this EventFilter has an ErrorHandler, it is assigned as the error handler for the XMLFilterImpl, just as would be done for a next stage implementing EventConsumer.
next
- the next downstream component of the pipeline.IllegalStateException
- if the "next" consumer has
already been set through the constructor.public void characters(char ch[][] , int start, int length)
- start
- length
- public void comment(char ch[][] , int start, int length)
- start
- length
- public void elementDecl(java.lang.String name, java.lang.String model)
name
- model
- public void endCDATA()
public void endDTD()
public void endDocument()
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
uri
- localName
- qName
- public void endEntity(java.lang.String name)
name
- public void endPrefixMapping(java.lang.String prefix)
prefix
- public void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
name
- publicId
- systemId
- public final ContentHandler getContentHandler()
public final DTDHandler getDTDHandler()
public Locator getDocumentLocator()
public final ErrorHandler getErrorHandler()
public final EventConsumer getNext()
public final Object getProperty(java.lang.String id)
id
- public void ignorableWhitespace(char ch[][] , int start, int length)
- start
- length
- public void internalEntityDecl(java.lang.String name, java.lang.String value)
name
- value
- public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
name
- publicId
- systemId
- public void processingInstruction(java.lang.String target, java.lang.String data)
target
- data
- public final void setContentHandler(org.xml.sax.ContentHandler h)
h
- public final void setDTDHandler(org.xml.sax.DTDHandler h)
h
- public void setDocumentLocator(org.xml.sax.Locator locator)
locator
- public final void setErrorHandler(org.xml.sax.ErrorHandler handler)
handler
- public final void setProperty(java.lang.String id, java.lang.Object o)
id
- o
- public void skippedEntity(java.lang.String name)
name
- public void startCDATA()
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
name
- publicId
- systemId
- public void startDocument()
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
uri
- localName
- qName
- atts
- public void startEntity(java.lang.String name)
name
- public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
prefix
- uri
- public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
name
- publicId
- systemId
- notationName
-
Additionally, SAX handlers may be assigned, which completely replace the "upstream" view (through EventConsumer) of handlers, initially null or the "next" consumer provided to the constructor. To make it easier to build specialized filter classes, this class implements all the standard SAX consumer handlers, and those implementations delegate "downstream" to the consumer accessed by #getNext.
The simplest way to create a custom a filter class is to create a subclass which overrides one or more handler interface methods. The constructor for that subclass then registers itself as a handler for those interfaces using a call such as setContentHandler(this), so the "upstream" view of event delivery is modified from the state established in the base class constructor. That way, the overridden methods intercept those event callbacks as they go "downstream", and all other event callbacks will pass events to any next consumer. Overridden methods may invoke superclass methods (perhaps after modifying parameters) if they wish to delegate such calls. Such subclasses should use #getErrorHandler to report errors using the common error reporting mechanism.
Another important technique is to construct a filter consisting of only a few specific types of handler. For example, one could easily prune out lexical events or various declarations by providing handlers which don't pass those events downstream, or by providing null handlers.
This may be viewed as the consumer oriented analogue of the SAX2 org.xml.sax.helpers.XMLFilterImpl XMLFilterImpl class. Key differences include:
The #chainTo chainTo() convenience routine supports chaining to an XMLFilterImpl, in its role as a limited functionality event consumer. Its event producer role (XMLFilter) is ignored.
The #bind bind() routine may be used associate event pipelines with any kind of XMLReader that will produce the events. Such pipelines don't necessarily need to have any members which are implemented using this class. That routine has some intelligence which supports automatic changes to parser feature flags, letting event piplines become largely independent of the particular feature sets of parsers.