|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gnu.xml.pipeline.EventFilter
A customizable event consumer, used to assemble various kinds of filters using SAX handlers and an optional second consumer. It can be constructed in two ways:
getNext()
.
getNext()
returns null.
Additionally, SAX handlers may be provided, which completely replace
handlers from the consumer provided through the constructor. To make
it easier to build specialized filter classes, this class implements
all the standard SAX consumer handlers, and those implementations
will delegate 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, and then itself registers as a handler (for those interfaces) to the base class using a call such as setContentHandler(this). That way, those overridden methods will intercept those event callbacks, and all other event callbacks will pass events to the next consumer. Overridden methods may invoke superclass methods (perhaps after modifying parameters) should they wish to delegate such calls. Such subclasses should use shared ErrorHandler to report errors.
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 the events on, or null handlers.
This may be viewed as the consumer oriented analogue of the SAX2
XMLFilterImpl
class.
Key differences include:
EventConsumer
, which groups related
consumer methods together, rather than leaving them separated.
TeeConsumer
class.)
The bind(org.xml.sax.XMLReader, gnu.xml.pipeline.EventConsumer)
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 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). |
Constructor Summary | |
EventFilter()
Initializes all handlers to null. |
|
EventFilter(EventConsumer consumer)
Handlers that are not otherwise set will default to those from the specified consumer, making it easy to pass events through. |
Method Summary | |
void |
attributeDecl(java.lang.String e,
java.lang.String a,
java.lang.String b,
java.lang.String c,
java.lang.String d)
SAX2: passes this callback to the next consumer, if any |
static void |
bind(XMLReader producer,
EventConsumer consumer)
Binds the standard SAX2 handlers from the specified consumer pipeline to the specified producer. |
void |
characters(char[] buf,
int off,
int len)
SAX2: passes this callback to the next consumer, if any |
void |
comment(char[] buf,
int off,
int len)
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 |
endDocument()
SAX2: passes this callback to the next consumer, if any |
void |
endDTD()
SAX2: passes this callback to the next consumer, if any |
void |
endElement(java.lang.String ns,
java.lang.String l,
java.lang.String n)
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 p)
SAX2: passes this callback to the next consumer, if any |
void |
externalEntityDecl(java.lang.String name,
java.lang.String pub,
java.lang.String sys)
SAX2: passes this callback to the next consumer, if any |
ContentHandler |
getContentHandler()
Returns the content handler being used. |
Locator |
getDocumentLocator()
Returns any locator provided to the next consumer, if this class (or a subclass) is handling ContentHandler events. |
DTDHandler |
getDTDHandler()
Returns the dtd handler being used. |
ErrorHandler |
getErrorHandler()
Returns the error handler assigned this filter stage, or null if no such assigment has been made. |
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[] buf,
int off,
int len)
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 s1,
java.lang.String s2,
java.lang.String s3)
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(ContentHandler h)
Assigns the content handler to use; a null handler indicates that these events will not be forwarded. |
void |
setDocumentLocator(Locator l)
SAX2: passes this callback to the next consumer, if any |
void |
setDTDHandler(DTDHandler h)
Assigns the DTD handler to use; a null handler indicates that these events will not be forwarded. |
void |
setErrorHandler(ErrorHandler handler)
Records the error handler that should be used by this stage, and passes it on 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 n)
SAX2: passes this callback to the next consumer, if any |
void |
startCDATA()
SAX2: passes this callback to the next consumer, if any |
void |
startDocument()
SAX2: passes this callback to the next consumer, if any |
void |
startDTD(java.lang.String root,
java.lang.String p,
java.lang.String s)
SAX2: passes this callback to the next consumer, if any |
void |
startElement(java.lang.String ns,
java.lang.String l,
java.lang.String name,
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 p,
java.lang.String u)
SAX2: passes this callback to the next consumer, if any |
void |
unparsedEntityDecl(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4)
SAX1: passes this callback to the next consumer, if any |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String FEATURE_URI
public static final java.lang.String PROPERTY_URI
public static final java.lang.String DECL_HANDLER
DeclHandler
eventspublic static final java.lang.String LEXICAL_HANDLER
LexicalHandler
eventsConstructor Detail |
public EventFilter()
public EventFilter(EventConsumer consumer)
Method Detail |
public static void bind(XMLReader producer, EventConsumer consumer)
ContentHandler
and DTDHandler
, plus the extension
DeclHandler
and LexicalHandler
. Any additional
application-specific handlers need to be bound separately.
The ErrorHandler
is handled differently: the producer's
error handler is passed through to the consumer pipeline.
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 DomParser
.
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.
EventFilter
configured as a pass-through.
You might need to do that if you are using an NSFilter
subclass to fix names found in attributes or character data.
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 producerpublic final void setErrorHandler(ErrorHandler handler)
setErrorHandler
in interface EventConsumer
gnu.xml.pipeline.EventConsumer
handler
- encapsulates error handling policy for this stagepublic final ErrorHandler getErrorHandler()
public final EventConsumer getNext()
public final void setContentHandler(ContentHandler h)
public final ContentHandler getContentHandler()
getContentHandler
in interface EventConsumer
public final void setDTDHandler(DTDHandler h)
public final DTDHandler getDTDHandler()
getDTDHandler
in interface EventConsumer
public final void setProperty(java.lang.String id, java.lang.Object o) throws SAXNotRecognizedException, SAXNotSupportedException
public final java.lang.Object getProperty(java.lang.String id) throws SAXNotRecognizedException
getProperty
in interface EventConsumer
gnu.xml.pipeline.EventConsumer
id
- This is a URI identifying the type of property desired.SAXNotRecognizedException
- Thrown if the particular
pipeline stage does not understand the specified identifier.public Locator getDocumentLocator()
ContentHandler
events.public void setDocumentLocator(Locator l)
setDocumentLocator
in interface ContentHandler
org.xml.sax.ContentHandler
locator
- An object that can return the location of
any SAX document event.Locator
public void startDocument() throws SAXException
startDocument
in interface ContentHandler
org.xml.sax.ContentHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.endDocument()
public void skippedEntity(java.lang.String n) throws SAXException
skippedEntity
in interface ContentHandler
org.xml.sax.ContentHandler
name
- The name of the skipped entity. If it is a
parameter entity, the name will begin with '%', and if
it is the external DTD subset, it will be the string
"[dtd]".SAXException
- Any SAX exception, possibly
wrapping another exception.public void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException
processingInstruction
in interface ContentHandler
org.xml.sax.ContentHandler
target
- The processing instruction target.data
- The processing instruction data, or null if
none was supplied. The data does not include any
whitespace separating it from the target.SAXException
- Any SAX exception, possibly
wrapping another exception.public void characters(char[] buf, int off, int len) throws SAXException
characters
in interface ContentHandler
org.xml.sax.ContentHandler
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.ignorableWhitespace(char[], int, int)
,
Locator
public void ignorableWhitespace(char[] buf, int off, int len) throws SAXException
ignorableWhitespace
in interface ContentHandler
org.xml.sax.ContentHandler
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.characters(char[], int, int)
public void startPrefixMapping(java.lang.String p, java.lang.String u) throws SAXException
startPrefixMapping
in interface ContentHandler
org.xml.sax.ContentHandler
prefix
- The Namespace prefix being declared.uri
- The Namespace URI the prefix is mapped to.SAXException
- The client may throw
an exception during processing.ContentHandler.endPrefixMapping(java.lang.String)
,
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public void startElement(java.lang.String ns, java.lang.String l, java.lang.String name, Attributes atts) throws SAXException
startElement
in interface ContentHandler
org.xml.sax.ContentHandler
uri
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qName
- The qualified name (with prefix), or the
empty string if qualified names are not available.atts
- The attributes attached to the element. If
there are no attributes, it shall be an empty
Attributes object.SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
,
Attributes
public void endElement(java.lang.String ns, java.lang.String l, java.lang.String n) throws SAXException
endElement
in interface ContentHandler
org.xml.sax.ContentHandler
uri
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qName
- The qualified XML 1.0 name (with prefix), or the
empty string if qualified names are not available.SAXException
- Any SAX exception, possibly
wrapping another exception.public void endPrefixMapping(java.lang.String p) throws SAXException
endPrefixMapping
in interface ContentHandler
org.xml.sax.ContentHandler
prefix
- The prefix that was being mapping.SAXException
- The client may throw
an exception during processing.ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
,
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
public void endDocument() throws SAXException
endDocument
in interface ContentHandler
org.xml.sax.ContentHandler
SAXException
- Any SAX exception, possibly
wrapping another exception.ContentHandler.startDocument()
public void unparsedEntityDecl(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4) throws SAXException
unparsedEntityDecl
in interface DTDHandler
org.xml.sax.DTDHandler
name
- The unparsed entity's name.publicId
- The entity's public identifier, or null if none
was given.systemId
- The entity's system identifier.notation
- name The name of the associated notation.SAXException
- Any SAX exception, possibly
wrapping another exception.DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
public void notationDecl(java.lang.String s1, java.lang.String s2, java.lang.String s3) throws SAXException
notationDecl
in interface DTDHandler
org.xml.sax.DTDHandler
name
- The notation name.publicId
- The notation's public identifier, or null if
none was given.systemId
- The notation's system identifier, or null if
none was given.SAXException
- Any SAX exception, possibly
wrapping another exception.DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
public void startDTD(java.lang.String root, java.lang.String p, java.lang.String s) throws SAXException
startDTD
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
name
- The document type name.publicId
- The declared public identifier for the
external DTD subset, or null if none was declared.systemId
- The declared system identifier for the
external DTD subset, or null if none was declared.SAXException
- The application may raise an
exception.LexicalHandler.endDTD()
,
LexicalHandler.startEntity(java.lang.String)
public void endDTD() throws SAXException
endDTD
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
public void comment(char[] buf, int off, int len) throws SAXException
comment
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
ch
- An array holding the characters in the comment.start
- The starting position in the array.length
- The number of characters to use from the array.SAXException
- The application may raise an exception.public void startCDATA() throws SAXException
startCDATA
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.endCDATA()
public void endCDATA() throws SAXException
endCDATA
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
SAXException
- The application may raise an exception.LexicalHandler.startCDATA()
public void startEntity(java.lang.String name) throws SAXException
startEntity
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%', and if it is the
external DTD subset, it will be "[dtd]".SAXException
- The application may raise an exception.LexicalHandler.endEntity(java.lang.String)
,
DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,
DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
public void endEntity(java.lang.String name) throws SAXException
endEntity
in interface LexicalHandler
org.xml.sax.ext.LexicalHandler
name
- The name of the entity that is ending.SAXException
- The application may raise an exception.LexicalHandler.startEntity(java.lang.String)
public void elementDecl(java.lang.String name, java.lang.String model) throws SAXException
elementDecl
in interface DeclHandler
org.xml.sax.ext.DeclHandler
name
- The element type name.model
- The content model as a normalized string.SAXException
- The application may raise an exception.public void attributeDecl(java.lang.String e, java.lang.String a, java.lang.String b, java.lang.String c, java.lang.String d) throws SAXException
attributeDecl
in interface DeclHandler
org.xml.sax.ext.DeclHandler
eName
- The name of the associated element.aName
- The name of the attribute.type
- A string representing the attribute type.valueDefault
- A string representing the attribute default
("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
none of these applies.value
- A string representing the attribute's default value,
or null if there is none.SAXException
- The application may raise an exception.public void externalEntityDecl(java.lang.String name, java.lang.String pub, java.lang.String sys) throws SAXException
externalEntityDecl
in interface DeclHandler
org.xml.sax.ext.DeclHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.publicId
- The declared public identifier of the entity, or
null if none was declared.systemId
- The declared system identifier of the entity.SAXException
- The application may raise an exception.DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void internalEntityDecl(java.lang.String name, java.lang.String value) throws SAXException
internalEntityDecl
in interface DeclHandler
org.xml.sax.ext.DeclHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.value
- The replacement text of the entity.SAXException
- The application may raise an exception.DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
Source code is GPL'd in the JAXP subproject at http://savannah.gnu.org/projects/classpathx |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |