public static class XmlUtils.CachingContentHandler extends org.xml.sax.helpers.DefaultHandler
CachingContentHandler
operates in two modes. In the first mode it is constructed
and passed a delegate ContentHandler
. It then proceeds to route all SAX events
to the delegate as normal, recording them as it does so. Following endDocument
,
it sets the delegate to null
.
In the second mode, clients can call replay
to replay the recorded SAX events on
a new ContentHandler
.
Constructor and Description |
---|
XmlUtils.CachingContentHandler(ContentHandler delegate) |
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] characters,
int start,
int length) |
void |
endDocument() |
void |
endElement(String uri,
String localName,
String name) |
void |
endPrefixMapping(String prefix) |
void |
ignorableWhitespace(char[] characters,
int start,
int length) |
boolean |
isPaused() |
void |
pause(boolean includeLastEvent) |
void |
processingInstruction(String target,
String data) |
void |
releaseDelegate()
The ContentHandler delegate passed to
CachingContentHandler 's constructor
must be released in order to prevent memory leaks. |
void |
replay(ContentHandler replayTo)
Replay the cached events.
|
void |
setDocumentLocator(Locator locator) |
void |
skippedEntity(String name) |
void |
startDocument() |
void |
startElement(String uri,
String localName,
String name,
Attributes attributes) |
void |
startPrefixMapping(String prefix,
String uri) |
void |
unpause(boolean includeLastEvent) |
error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warning
public XmlUtils.CachingContentHandler(ContentHandler delegate)
delegate
- the delegate to route all SAX events to, recording as we gopublic boolean isPaused()
public void pause(boolean includeLastEvent)
includeLastEvent
- whether to include the most recent SAX event in the cache (ie. the one that
led us to call pause)public void unpause(boolean includeLastEvent)
includeLastEvent
- whether to include the most recent SAX event in the cache (ie. the one that
led us to call unpause)public void replay(ContentHandler replayTo) throws SAXException
Note: replay
does not necessarily trigger startDocument
and
endDocument
(ie. it does not assume the original recording contained them).
Because of this, CachingContentHandler
can be used to cache
fragments of SAX events.
SAXException
public void releaseDelegate()
CachingContentHandler
's constructor
must be released in order to prevent memory leaks. This is done automatically by
endDocument
. But for use cases where endDocument
is not
triggered, clients can call releaseDelegate
to release the delegate
manually.public void startDocument() throws SAXException
startDocument
in interface ContentHandler
startDocument
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
processingInstruction
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class org.xml.sax.helpers.DefaultHandler
public void skippedEntity(String name) throws SAXException
skippedEntity
in interface ContentHandler
skippedEntity
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException
startElement
in interface ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void characters(char[] characters, int start, int length) throws SAXException
characters
in interface ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void ignorableWhitespace(char[] characters, int start, int length) throws SAXException
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void endElement(String uri, String localName, String name) throws SAXException
endElement
in interface ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
SAXException
public void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class org.xml.sax.helpers.DefaultHandler
SAXException
Copyright © 2015. All Rights Reserved.