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, warningpublic 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.
SAXExceptionpublic 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 ContentHandlerstartDocument in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void processingInstruction(String target, String data) throws SAXException
processingInstruction in interface ContentHandlerprocessingInstruction in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void setDocumentLocator(Locator locator)
setDocumentLocator in interface ContentHandlersetDocumentLocator in class org.xml.sax.helpers.DefaultHandlerpublic void skippedEntity(String name) throws SAXException
skippedEntity in interface ContentHandlerskippedEntity in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping in interface ContentHandlerstartPrefixMapping in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping in interface ContentHandlerendPrefixMapping in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException
startElement in interface ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void characters(char[] characters,
int start,
int length)
throws SAXException
characters in interface ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void ignorableWhitespace(char[] characters,
int start,
int length)
throws SAXException
ignorableWhitespace in interface ContentHandlerignorableWhitespace in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void endElement(String uri, String localName, String name) throws SAXException
endElement in interface ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerSAXExceptionpublic void endDocument()
throws SAXException
endDocument in interface ContentHandlerendDocument in class org.xml.sax.helpers.DefaultHandlerSAXExceptionCopyright © 2015. All Rights Reserved.