|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.brownell.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 initialized in two ways:
SAX handlers given to these objects will often consume events
completely, or chain them to the second consumer after filtering. That
second consumer may be acquired through getNext()
.
The simplest way to build such handlers is to create a subclass which overrides one or more handler methods, and register an instance of that subclass to serve as one or more of the SAX handlers. Methods which aren't overridden will automatically chain to the appropriate method in the next event consumer. Subclass methods may invoke superclass methods to do similar chaining, perhaps after modifying parameters. Event filter subclasses should use the ErrorHandler to report most errors. Record and use the locator, for more useful diagnostics.
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, such as an instance of the DefaultHandler class.
This may be viewed as the consumer side analogue of the
XMLFilterImpl
class, introduced
in SAX2. Events are pushed through an EventFilter (like normal method
calls), not pulled through like data through a parser.
Also, there is no policy that the producer must look like a SAX parser;
application modules can send events directly. Implementations of that
"XMLFilter" interface may be used with an EventProducer
on the
event production part of a pipeline.
Field Summary | |
static java.lang.String |
HANDLER_URI
SAX2 URI prefix for standard 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 |
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. |
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)
SAX2: 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. |
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 a property of unknown intent (usually a handler) |
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)
SAX2: 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 HANDLER_URI
Constructor Detail |
public EventFilter()
public EventFilter(EventConsumer consumer)
Method Detail |
public final void setErrorHandler(ErrorHandler handler)
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()
public final void setDTDHandler(DTDHandler h)
public final DTDHandler getDTDHandler()
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
id
- This is a URI identifying the type of property desired.public void setDocumentLocator(Locator l)
locator
- An object that can return the location of
any SAX document event.Locator
public void startDocument() throws SAXException
ContentHandler.endDocument()
public void skippedEntity(java.lang.String n) throws SAXException
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]".public void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException
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.public void characters(char[] buf, int off, int len) throws SAXException
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.ContentHandler.ignorableWhitespace(char[], int, int)
,
Locator
public void ignorableWhitespace(char[] buf, int off, int len) throws SAXException
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.ContentHandler.characters(char[], int, int)
public void startPrefixMapping(java.lang.String p, java.lang.String u) throws SAXException
prefix
- The Namespace prefix being declared.uri
- The Namespace URI the prefix is mapped to.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
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.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
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.public void endPrefixMapping(java.lang.String p) throws SAXException
prefix
- The prefix that was being mapping.ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
,
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
public void endDocument() throws SAXException
ContentHandler.startDocument()
public void unparsedEntityDecl(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4) throws SAXException
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.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
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.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
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.LexicalHandler.endDTD()
,
LexicalHandler.startEntity(java.lang.String)
public void endDTD() throws SAXException
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
public void comment(char[] buf, int off, int len) throws SAXException
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.public void startCDATA() throws SAXException
LexicalHandler.endCDATA()
public void endCDATA() throws SAXException
LexicalHandler.startCDATA()
public void startEntity(java.lang.String name) throws SAXException
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]".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
name
- The name of the entity that is ending.LexicalHandler.startEntity(java.lang.String)
public void elementDecl(java.lang.String name, java.lang.String model) throws SAXException
name
- The element type name.model
- The content model as a normalized string.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
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.public void externalEntityDecl(java.lang.String name, java.lang.String pub, java.lang.String sys) throws SAXException
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.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
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.value
- The replacement text of the entity.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)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |