public class IncrementalSAXSource_Filter extends java.lang.Object implements IncrementalSAXSource, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.ErrorHandler, java.lang.Runnable
IncrementalSAXSource_Filter implements IncrementalSAXSource, using a standard SAX2 event source as its input and parcelling out those events gradually in reponse to deliverMoreNodes() requests. Output from the filter will be passed along to a SAX handler registered as our listener, but those callbacks will pass through a counting stage which periodically yields control back to the controller coroutine.
%REVIEW%: This filter is not currenly intended to be reusable for parsing additional streams/documents. We may want to consider making it resettable at some point in the future. But it's a small object, so that'd be mostly a convenience issue; the cost of allocating each time is trivial compared to the cost of processing any nontrival stream.
For a brief usage example, see the unit-test main() method.
This is a simplification of the old CoroutineSAXParser, focusing specifically on filtering. The resulting controller protocol is _far_ simpler and less error-prone; the only controller operation is deliverMoreNodes(), and the only requirement is that deliverMoreNodes(false) be called if you want to discard the rest of the stream and the previous deliverMoreNodes() didn't return false.
| Constructor and Description |
|---|
IncrementalSAXSource_Filter() |
IncrementalSAXSource_Filter(CoroutineManager co,
int controllerCoroutineID)
Create a IncrementalSAXSource_Filter which is not yet bound to a specific
SAX event source.
|
| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] ch,
int start,
int length) |
void |
comment(char[] ch,
int start,
int length) |
static IncrementalSAXSource |
createIncrementalSAXSource(CoroutineManager co,
int controllerCoroutineID) |
java.lang.Object |
deliverMoreNodes(boolean parsemore)
deliverMoreNodes() is a simple API which tells the coroutine
parser that we need more nodes.
|
void |
endCDATA() |
void |
endDocument() |
void |
endDTD() |
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName) |
void |
endEntity(java.lang.String name) |
void |
endPrefixMapping(java.lang.String prefix) |
void |
error(org.xml.sax.SAXParseException exception) |
void |
fatalError(org.xml.sax.SAXParseException exception) |
int |
getControllerCoroutineID() |
CoroutineManager |
getCoroutineManager() |
int |
getSourceCoroutineID() |
void |
ignorableWhitespace(char[] ch,
int start,
int length) |
void |
init(CoroutineManager co,
int controllerCoroutineID,
int sourceCoroutineID) |
void |
notationDecl(java.lang.String a,
java.lang.String b,
java.lang.String c) |
void |
processingInstruction(java.lang.String target,
java.lang.String data) |
void |
run() |
void |
setContentHandler(org.xml.sax.ContentHandler handler)
Register a SAX-style content handler for us to output to
|
void |
setDocumentLocator(org.xml.sax.Locator locator) |
void |
setDTDHandler(org.xml.sax.DTDHandler handler)
Register a SAX-style DTD handler for us to output to
|
void |
setErrHandler(org.xml.sax.ErrorHandler handler) |
void |
setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
Register a SAX-style lexical handler for us to output to
|
void |
setReturnFrequency(int events) |
void |
setXMLReader(org.xml.sax.XMLReader eventsource)
Bind our input streams to an XMLReader.
|
void |
skippedEntity(java.lang.String name) |
void |
startCDATA() |
void |
startDocument() |
void |
startDTD(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId) |
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts) |
void |
startEntity(java.lang.String name) |
void |
startParse(org.xml.sax.InputSource source)
Launch a thread that will run an XMLReader's parse() operation within
a thread, feeding events to this IncrementalSAXSource_Filter.
|
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri) |
void |
unparsedEntityDecl(java.lang.String a,
java.lang.String b,
java.lang.String c,
java.lang.String d) |
void |
warning(org.xml.sax.SAXParseException exception) |
public IncrementalSAXSource_Filter()
public IncrementalSAXSource_Filter(CoroutineManager co, int controllerCoroutineID)
public static IncrementalSAXSource createIncrementalSAXSource(CoroutineManager co, int controllerCoroutineID)
public void init(CoroutineManager co, int controllerCoroutineID, int sourceCoroutineID)
public void setXMLReader(org.xml.sax.XMLReader eventsource)
public void setContentHandler(org.xml.sax.ContentHandler handler)
IncrementalSAXSourcesetContentHandler in interface IncrementalSAXSourcepublic void setDTDHandler(org.xml.sax.DTDHandler handler)
IncrementalSAXSourcesetDTDHandler in interface IncrementalSAXSourcepublic void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
IncrementalSAXSourcesetLexicalHandler in interface IncrementalSAXSourcepublic void setErrHandler(org.xml.sax.ErrorHandler handler)
public void setReturnFrequency(int events)
public void characters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
characters in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void endDocument()
throws org.xml.sax.SAXException
endDocument in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void endPrefixMapping(java.lang.String prefix)
throws org.xml.sax.SAXException
endPrefixMapping in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void ignorableWhitespace(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
ignorableWhitespace in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void processingInstruction(java.lang.String target,
java.lang.String data)
throws org.xml.sax.SAXException
processingInstruction in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator in interface org.xml.sax.ContentHandlerpublic void skippedEntity(java.lang.String name)
throws org.xml.sax.SAXException
skippedEntity in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void startDocument()
throws org.xml.sax.SAXException
startDocument in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
throws org.xml.sax.SAXException
startPrefixMapping in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXExceptionpublic void comment(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
comment in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void endCDATA()
throws org.xml.sax.SAXException
endCDATA in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void endDTD()
throws org.xml.sax.SAXException
endDTD in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void endEntity(java.lang.String name)
throws org.xml.sax.SAXException
endEntity in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void startCDATA()
throws org.xml.sax.SAXException
startCDATA in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void startDTD(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
throws org.xml.sax.SAXException
startDTD in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void startEntity(java.lang.String name)
throws org.xml.sax.SAXException
startEntity in interface org.xml.sax.ext.LexicalHandlerorg.xml.sax.SAXExceptionpublic void notationDecl(java.lang.String a,
java.lang.String b,
java.lang.String c)
throws org.xml.sax.SAXException
notationDecl in interface org.xml.sax.DTDHandlerorg.xml.sax.SAXExceptionpublic void unparsedEntityDecl(java.lang.String a,
java.lang.String b,
java.lang.String c,
java.lang.String d)
throws org.xml.sax.SAXException
unparsedEntityDecl in interface org.xml.sax.DTDHandlerorg.xml.sax.SAXExceptionpublic void error(org.xml.sax.SAXParseException exception)
throws org.xml.sax.SAXException
error in interface org.xml.sax.ErrorHandlerorg.xml.sax.SAXExceptionpublic void fatalError(org.xml.sax.SAXParseException exception)
throws org.xml.sax.SAXException
fatalError in interface org.xml.sax.ErrorHandlerorg.xml.sax.SAXExceptionpublic void warning(org.xml.sax.SAXParseException exception)
throws org.xml.sax.SAXException
warning in interface org.xml.sax.ErrorHandlerorg.xml.sax.SAXExceptionpublic int getSourceCoroutineID()
public int getControllerCoroutineID()
public CoroutineManager getCoroutineManager()
public void startParse(org.xml.sax.InputSource source)
throws org.xml.sax.SAXException
startParse in interface IncrementalSAXSourceorg.xml.sax.SAXException - is parse thread is already in progress
or parsing can not be started.public void run()
run in interface java.lang.Runnablepublic java.lang.Object deliverMoreNodes(boolean parsemore)
deliverMoreNodes in interface IncrementalSAXSourceparsemore - If true, tells the incremental filter to generate
another chunk of output. If false, tells the filter that we're
satisfied and it can terminate parsing of this document.Copyright © 2023 Apache XML Project. All Rights Reserved.