org.xml.sax.helpers
Class XMLReaderAdapter
java.lang.Object
org.xml.sax.helpers.XMLReaderAdapter
- ContentHandler, Parser
public class XMLReaderAdapter
extends java.lang.Object
Adapt a SAX2 XMLReader as a SAX1 Parser.
This module, both source code and documentation, is in the
Public Domain, and comes with NO WARRANTY.
See http://www.saxproject.org
for further information.
This class wraps a SAX2
XMLReader
and makes it act as a SAX1
Parser
. The XMLReader
must support a true value for the
http://xml.org/sax/features/namespace-prefixes property or parsing will fail
with a
SAXException
; if the XMLReader
supports a false value for the http://xml.org/sax/features/namespaces
property, that will also be used to improve efficiency.
void | characters(ch[] , int start, int length) - Adapt a SAX2 characters event.
|
void | endDocument() - End document event.
|
void | endElement(String uri, String localName, String qName) - Adapt a SAX2 end element event.
|
void | endPrefixMapping(String prefix) - Adapt a SAX2 end prefix mapping event.
|
void | ignorableWhitespace(ch[] , int start, int length) - Adapt a SAX2 ignorable whitespace event.
|
void | parse(String systemId) - Parse the document.
|
void | parse(InputSource input) - Parse the document.
|
void | processingInstruction(String target, String data) - Adapt a SAX2 processing instruction event.
|
void | setDTDHandler(DTDHandler handler) - Register the DTD event handler.
|
void | setDocumentHandler(DocumentHandler handler) - Register the SAX1 document event handler.
|
void | setDocumentLocator(Locator locator) - Set a document locator.
|
void | setEntityResolver(EntityResolver resolver) - Register the entity resolver.
|
void | setErrorHandler(ErrorHandler handler) - Register the error event handler.
|
void | setLocale(Locale locale) - Set the locale for error reporting.
|
void | skippedEntity(String name) - Adapt a SAX2 skipped entity event.
|
void | startDocument() - Start document event.
|
void | startElement(String uri, String localName, String qName, Attributes atts) - Adapt a SAX2 start element event.
|
void | startPrefixMapping(String prefix, String uri) - Adapt a SAX2 start prefix mapping event.
|
XMLReaderAdapter
public XMLReaderAdapter()
throws SAXException
Create a new adapter.
Use the "org.xml.sax.driver" property to locate the SAX2
driver to embed.
SAXException
- If the embedded driver
cannot be instantiated or if the
org.xml.sax.driver property is not specified.
XMLReaderAdapter
public XMLReaderAdapter(XMLReader xmlReader)
Create a new adapter.
Create a new adapter, wrapped around a SAX2 XMLReader.
The adapter will make the XMLReader act like a SAX1
Parser.
xmlReader
- The SAX2 XMLReader to wrap.
characters
public void characters(ch[] ,
int start,
int length)
throws SAXException
Adapt a SAX2 characters event.
- characters in interface ContentHandler
start
- The starting position in the array.length
- The number of characters to use.
endElement
public void endElement(String uri,
String localName,
String qName)
throws SAXException
Adapt a SAX2 end element event.
- endElement in interface ContentHandler
uri
- The Namespace URI.localName
- The Namespace local name.qName
- The qualified (prefixed) name.
endPrefixMapping
public void endPrefixMapping(String prefix)
Adapt a SAX2 end prefix mapping event.
- endPrefixMapping in interface ContentHandler
prefix
- The prefix being mapped.
ignorableWhitespace
public void ignorableWhitespace(ch[] ,
int start,
int length)
throws SAXException
Adapt a SAX2 ignorable whitespace event.
- ignorableWhitespace in interface ContentHandler
start
- The starting position in the array.length
- The number of characters to use.
parse
public void parse(String systemId)
throws IOException,
SAXException
Parse the document.
This method will throw an exception if the embedded
XMLReader does not support the
http://xml.org/sax/features/namespace-prefixes property.
- parse in interface Parser
systemId
- The absolute URL of the document.
SAXException
- If there is a problem
processing the document.
parse
public void parse(InputSource input)
throws IOException,
SAXException
Parse the document.
This method will throw an exception if the embedded
XMLReader does not support the
http://xml.org/sax/features/namespace-prefixes property.
- parse in interface Parser
input
- An input source for the document.
SAXException
- If there is a problem
processing the document.
processingInstruction
public void processingInstruction(String target,
String data)
throws SAXException
Adapt a SAX2 processing instruction event.
- processingInstruction in interface ContentHandler
target
- The processing instruction target.data
- The remainder of the processing instruction
setDTDHandler
public void setDTDHandler(DTDHandler handler)
Register the DTD event handler.
- setDTDHandler in interface Parser
handler
- The new DTD event handler.
setDocumentHandler
public void setDocumentHandler(DocumentHandler handler)
Register the SAX1 document event handler.
Note that the SAX1 document handler has no Namespace
support.
- setDocumentHandler in interface Parser
handler
- The new SAX1 document event handler.
setErrorHandler
public void setErrorHandler(ErrorHandler handler)
Register the error event handler.
- setErrorHandler in interface Parser
handler
- The new error event handler.
setLocale
public void setLocale(Locale locale)
throws SAXException
Set the locale for error reporting.
This is not supported in SAX2, and will always throw
an exception.
- setLocale in interface Parser
locale
- the locale for error reporting.
startElement
public void startElement(String uri,
String localName,
String qName,
Attributes atts)
throws SAXException
Adapt a SAX2 start element event.
- startElement in interface ContentHandler
uri
- The Namespace URI.localName
- The Namespace local name.qName
- The qualified (prefixed) name.atts
- The SAX2 attributes.
startPrefixMapping
public void startPrefixMapping(String prefix,
String uri)
Adapt a SAX2 start prefix mapping event.
- startPrefixMapping in interface ContentHandler
prefix
- The prefix being mapped.uri
- The Namespace URI being mapped to.