Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
gnu.xml.pipeline.EventFilter
public class EventFilter
extends java.lang.Object
implements EventConsumer, ContentHandler2, DTDHandler, LexicalHandler, DeclHandler
getNext()
.
getNext()
returns null.
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.
XMLFilterImpl
class.
Key differences include: EventConsumer
, which groups related
consumer methods together, rather than leaving them separated.
TeeConsumer
class.)
chainTo()
convenience routine supports chaining to
an XMLFilterImpl, in its role as a limited functionality event
consumer. Its event producer role (XMLFilter
) is ignored.
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.
Field Summary | |
static String |
|
static String |
|
static String |
|
static String |
|
Constructor Summary | |
| |
|
Method Summary | |
void |
|
static void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
ContentHandler |
|
DTDHandler |
|
Locator |
|
ErrorHandler |
|
EventConsumer |
|
Object |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
public static final String FEATURE_URI
SAX2 URI prefix for standard feature flags.
public static final String LEXICAL_HANDLER
SAX2 property identifier forLexicalHandler
events
public static final String PROPERTY_URI
SAX2 URI prefix for standard properties (mostly for handlers).
public EventFilter()
Initializes all handlers to null.
public EventFilter(EventConsumer consumer)
Handlers that are not otherwise set will default to those from the specified consumer, making it easy to pass events through. If the consumer is null, all handlers are initialzed to null.
public void attributeDecl(String eName, String aName, String type, String mode, String value) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- attributeDecl in interface DeclHandler
public static void bind(XMLReader producer, EventConsumer consumer)
Binds the standard SAX2 handlers from the specified consumer pipeline to the specified producer. These handlers include the coreContentHandler
andDTDHandler
, plus the extensionDeclHandler
andLexicalHandler
. Any additional application-specific handlers need to be bound separately. TheErrorHandler
is handled differently: the producer's error handler is passed through to the consumer pipeline. The producer is told to include namespace prefix information if it can, since many pipeline stages need that Infoset information to work well. 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 aDomParser
.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.
NSFilter
will be removed if the producer can be told not to discard namespace data, using the "namespace-prefixes" feature flag.ValidationConsumer
will be removed if the producer can be told to validate, using the "validation" feature flag.WellFormednessFilter
is always removed, on the grounds that no XMLReader is permitted to producee malformed event streams and this would just be processing overhead.XIncludeFilter
stops the special handling, except that it's told about the "namespace-prefixes" feature of the event producer so that the event stream is internally consistent.- The first consumer which is not one of those classes stops such special handling. This means that if you want to force one of those filters to be used, you could just precede it with an instance of
EventFilter
configured as a pass-through. You might need to do that if you are using anNSFilter
subclass to fix names found in attributes or character data.
- Parameters:
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(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. Upstream Event Setup: If no handlers have been assigned to this EventFilter, then the handlers from specified XMLFilterImpl are returned from thisEventConsumer
: 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 implementingEventConsumer
.
- Parameters:
next
- the next downstream component of the pipeline.
public void characters(ch[] , int start, int length) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- characters in interface ContentHandler
public void comment(ch[] , int start, int length) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- comment in interface LexicalHandler
public void elementDecl(String name, String model) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- elementDecl in interface DeclHandler
public void endCDATA() throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- endCDATA in interface LexicalHandler
public void endDTD() throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- endDTD in interface LexicalHandler
public void endDocument() throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- endDocument in interface ContentHandler
public void endElement(String uri, String localName, String qName) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- endElement in interface ContentHandler
public void endEntity(String name) throws SAXException
SAX2: passes this callback to the next consumer, if any.
- Specified by:
- endEntity in interface LexicalHandler
public void endPrefixMapping(String prefix) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- endPrefixMapping in interface ContentHandler
public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- externalEntityDecl in interface DeclHandler
public final ContentHandler getContentHandler()
Returns the content handler being used.
- Specified by:
- getContentHandler in interface EventConsumer
public final DTDHandler getDTDHandler()
Returns the dtd handler being used.
- Specified by:
- getDTDHandler in interface EventConsumer
public Locator getDocumentLocator()
Returns any locator provided to the next consumer, if this class (or a subclass) is handlingContentHandler
events.
public final ErrorHandler getErrorHandler()
Returns the error handler assigned this filter stage, or null if no such assigment has been made.
public final EventConsumer getNext()
Returns the next event consumer in sequence; or null if there is no such handler.
public final Object getProperty(String id) throws SAXNotRecognizedException
Retrieves a property of unknown intent (usually a handler)
- Specified by:
- getProperty in interface EventConsumer
public void ignorableWhitespace(ch[] , int start, int length) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- ignorableWhitespace in interface ContentHandler
public void internalEntityDecl(String name, String value) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- internalEntityDecl in interface DeclHandler
public void notationDecl(String name, String publicId, String systemId) throws SAXException
SAX1: passes this callback to the next consumer, if any
- Specified by:
- notationDecl in interface DTDHandler
public void processingInstruction(String target, String data) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- processingInstruction in interface ContentHandler
public final void setContentHandler(ContentHandler h)
Assigns the content handler to use; a null handler indicates that these events will not be forwarded. This overrides the previous settting for this handler, which was probably pointed to the next consumer by the base class constructor.
public final void setDTDHandler(DTDHandler h)
Assigns the DTD handler to use; a null handler indicates that these events will not be forwarded. This overrides the previous settting for this handler, which was probably pointed to the next consumer by the base class constructor.
public void setDocumentLocator(Locator locator)
SAX2: passes this callback to the next consumer, if any
- Specified by:
- setDocumentLocator in interface ContentHandler
public final void setErrorHandler(ErrorHandler handler)
Records the error handler that should be used by this stage, and passes it "downstream" to any subsequent stage.
- Specified by:
- setErrorHandler in interface EventConsumer
public final void setProperty(String id, Object o) throws SAXNotRecognizedException, SAXNotSupportedException
Stores the property, normally a handler; a null handler indicates that these events will not be forwarded. This overrides the previous handler settting, which was probably pointed to the next consumer by the base class constructor.
public void skippedEntity(String name) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- skippedEntity in interface ContentHandler
public void startCDATA() throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- startCDATA in interface LexicalHandler
public void startDTD(String name, String publicId, String systemId) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- startDTD in interface LexicalHandler
public void startDocument() throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- startDocument in interface ContentHandler
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- startElement in interface ContentHandler
public void startEntity(String name) throws SAXException
SAX2: passes this callback to the next consumer, if any.
- Specified by:
- startEntity in interface LexicalHandler
public void startPrefixMapping(String prefix, String uri) throws SAXException
SAX2: passes this callback to the next consumer, if any
- Specified by:
- startPrefixMapping in interface ContentHandler
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException
SAX1: passes this callback to the next consumer, if any
- Specified by:
- unparsedEntityDecl in interface DTDHandler
public void xmlDecl(String version, String encoding, boolean standalone, String inputEncoding) throws SAXException
Reports the XML declaration.
- Specified by:
- xmlDecl in interface ContentHandler2
- Parameters:
version
- the value of the version attribute in the XML declarationencoding
- the encoding specified in the XML declaration, if anystandalone
- the standalone attribute from the XML declarationinputEncoding
- the encoding of the XML input