public class XMLReaderAdapter extends java.lang.Object implements org.xml.sax.Parser, org.xml.sax.ContentHandler
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.
Parser,
XMLReader| Constructor and Description |
|---|
XMLReaderAdapter()
Create a new adapter.
|
XMLReaderAdapter(org.xml.sax.XMLReader xmlReader)
Create a new adapter.
|
| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] ch,
int start,
int length)
Adapt a SAX2 characters event.
|
void |
endDocument()
End document event.
|
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Adapt a SAX2 end element event.
|
void |
endPrefixMapping(java.lang.String prefix)
Adapt a SAX2 end prefix mapping event.
|
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Adapt a SAX2 ignorable whitespace event.
|
void |
parse(org.xml.sax.InputSource input)
Parse the document.
|
void |
parse(java.lang.String systemId)
Parse the document.
|
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Adapt a SAX2 processing instruction event.
|
void |
setDocumentHandler(org.xml.sax.DocumentHandler handler)
Register the SAX1 document event handler.
|
void |
setDocumentLocator(org.xml.sax.Locator locator)
Set a document locator.
|
void |
setDTDHandler(org.xml.sax.DTDHandler handler)
Register the DTD event handler.
|
void |
setEntityResolver(org.xml.sax.EntityResolver resolver)
Register the entity resolver.
|
void |
setErrorHandler(org.xml.sax.ErrorHandler handler)
Register the error event handler.
|
void |
setLocale(java.util.Locale locale)
Set the locale for error reporting.
|
void |
skippedEntity(java.lang.String name)
Adapt a SAX2 skipped entity event.
|
void |
startDocument()
Start document event.
|
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
Adapt a SAX2 start element event.
|
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
Adapt a SAX2 start prefix mapping event.
|
public XMLReaderAdapter() throws org.xml.sax.SAXException
Use the "org.xml.sax.driver" property to locate the SAX2 driver to embed.
org.xml.sax.SAXException - If the embedded driver
cannot be instantiated or if the
org.xml.sax.driver property is not specified.public XMLReaderAdapter(org.xml.sax.XMLReader xmlReader)
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.java.lang.NullPointerException - If the argument is null.public void setLocale(java.util.Locale locale) throws org.xml.sax.SAXException
This is not supported in SAX2, and will always throw an exception.
setLocale in interface org.xml.sax.Parserlocale - the locale for error reporting.org.xml.sax.SAXException - Thrown unless overridden.Parser.setLocale(java.util.Locale)public void setEntityResolver(org.xml.sax.EntityResolver resolver)
setEntityResolver in interface org.xml.sax.Parserresolver - The new resolver.Parser.setEntityResolver(org.xml.sax.EntityResolver)public void setDTDHandler(org.xml.sax.DTDHandler handler)
setDTDHandler in interface org.xml.sax.Parserhandler - The new DTD event handler.Parser.setDTDHandler(org.xml.sax.DTDHandler)public void setDocumentHandler(org.xml.sax.DocumentHandler handler)
Note that the SAX1 document handler has no Namespace support.
setDocumentHandler in interface org.xml.sax.Parserhandler - The new SAX1 document event handler.Parser.setDocumentHandler(org.xml.sax.DocumentHandler)public void setErrorHandler(org.xml.sax.ErrorHandler handler)
setErrorHandler in interface org.xml.sax.Parserhandler - The new error event handler.Parser.setErrorHandler(org.xml.sax.ErrorHandler)public void parse(java.lang.String systemId) throws java.io.IOException, org.xml.sax.SAXException
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 org.xml.sax.ParsersystemId - The absolute URL of the document.java.io.IOException - If there is a problem reading
the raw content of the document.org.xml.sax.SAXException - If there is a problem
processing the document.parse(org.xml.sax.InputSource),
Parser.parse(java.lang.String)public void parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXException
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 org.xml.sax.Parserinput - An input source for the document.java.io.IOException - If there is a problem reading
the raw content of the document.org.xml.sax.SAXException - If there is a problem
processing the document.parse(java.lang.String),
Parser.parse(org.xml.sax.InputSource)public void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator in interface org.xml.sax.ContentHandlerlocator - The document locator.ContentHandler.setDocumentLocator(org.xml.sax.Locator)public void startDocument() throws org.xml.sax.SAXException
startDocument in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.startDocument()public void endDocument() throws org.xml.sax.SAXException
endDocument in interface org.xml.sax.ContentHandlerorg.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.endDocument()public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
startPrefixMapping in interface org.xml.sax.ContentHandlerprefix - The prefix being mapped.uri - The Namespace URI being mapped to.ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)public void endPrefixMapping(java.lang.String prefix)
endPrefixMapping in interface org.xml.sax.ContentHandlerprefix - The prefix being mapped.ContentHandler.endPrefixMapping(java.lang.String)public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandleruri - The Namespace URI.localName - The Namespace local name.qName - The qualified (prefixed) name.atts - The SAX2 attributes.org.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.endDocument()public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandleruri - The Namespace URI.localName - The Namespace local name.qName - The qualified (prefixed) name.org.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
characters in interface org.xml.sax.ContentHandlerch - An array of characters.start - The starting position in the array.length - The number of characters to use.org.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.characters(char[], int, int)public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
ignorableWhitespace in interface org.xml.sax.ContentHandlerch - An array of characters.start - The starting position in the array.length - The number of characters to use.org.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.ignorableWhitespace(char[], int, int)public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
processingInstruction in interface org.xml.sax.ContentHandlertarget - The processing instruction target.data - The remainder of the processing instructionorg.xml.sax.SAXException - The client may raise a
processing exception.ContentHandler.processingInstruction(java.lang.String, java.lang.String)public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
skippedEntity in interface org.xml.sax.ContentHandlername - The name of the skipped entity.org.xml.sax.SAXException - Throwable by subclasses.ContentHandler.skippedEntity(java.lang.String)