public abstract class TextContentFilter extends ElementStackFilter
filterElement(String). The operation to apply to
character content for these elements is defined by an
implementation in a subclass of filteredCharacters(char[],int,int). Unfiltered characters
and all other SAX events are delegated to the contained handler.
To process text in contiguous chunks, wrap instances of
TextContentFilter as contained handler in an instance
of GroupCharactersFilter.
The elements that are filtered are specified by qualified
element name. If there are no namespace qualifications, the name
will be unqualified. For instance, the following document contains
two bar elements with the same URI:
<foo>
<a:bar xmlns:a="http://one">xyz</a:bar>
<b:bar xmlns:b="http://one">uvw</b:bar>
</foo>
In order to filter the content of element bar, both
prefixes need to be specified: a:bar and
b:bar and other equivalent versions will not be recognized.
There is no way to properly handle a document such as the
following, where the two qualified element names are the same,
but the elements are different:
<foo>
<a:bar xmlns:a="http://one">xyz</a:bar>
<a:bar xmlns:a="http://two">uvw</a:bar>
</foo>
For this document, specifying a:bar will pick up the
bar element from both the http://one
and http://two namespaces.
Because this filter requires qualified names, the XML parser
must set the following SAX2 feature to true:
http://xml.org/sax/features/namespace-prefixesSee the SAX2 Feature Specification for information on this and other features.
mHandlerCDATA_ATTS_TYPE, EMPTY_ATTS, NO_OP_DEFAULT_HANDLER| Constructor and Description |
|---|
TextContentFilter()
Construct a text content filter without a specified contained
handler.
|
TextContentFilter(org.xml.sax.helpers.DefaultHandler handler)
Construct a text content filter which passes events
to the specified handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] cs,
int start,
int length)
Handle character content, delegating unfiltered characters
to the contained handler, and delegating filtered characters
to
filteredCharacters(char[],int,int). |
abstract void |
filteredCharacters(char[] cs,
int start,
int length)
Handle filtered character content.
|
void |
filterElement(String qName)
Filter the text content of elements with the specified
qualified name.
|
currentAttributes, currentElement, endElement, getAttributesStack, getElementStack, noElement, startDocument, startElementendDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, setHandler, skippedEntity, startPrefixMapping, unparsedEntityDecl, warningaddSimpleAttribute, characters, characters, characters, characters, createAttributes, createAttributes, createAttributes, createAttributes, createAttributes, createAttributes, endSimpleElement, endSimpleElement, startEndSimpleElement, startEndSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElement, startSimpleElementpublic TextContentFilter(org.xml.sax.helpers.DefaultHandler handler)
handler - Contained handler to which events are passed.public TextContentFilter()
SAXFilterHandler.setHandler(DefaultHandler).public void filterElement(String qName)
qName - Qualified name of elements to filter.public void characters(char[] cs,
int start,
int length)
throws SAXException
filteredCharacters(char[],int,int).characters in interface ContentHandlercharacters in class SAXFilterHandlercs - Array of characters to filter.start - First character to filter.length - Number of characters to filter.SAXException - If there is an exception from the
contained handler or from the filtered characters method.public abstract void filteredCharacters(char[] cs,
int start,
int length)
throws SAXException
filterElement(String). It is important that this method
not invoke characters(char[],int,int), either directly
through a super call from a subclass; instead,
access the embedded handler SAXFilterHandler.mHandler directly.cs - Array of characters to filter.start - First character to filter.length - Number of characters to filter.SAXException - If there is an exception handling the
characters.Copyright © 2019 Alias-i, Inc.. All rights reserved.