ParserAdapter (Java Platform SE 6) (original) (raw)
org.xml.sax.helpers
Class ParserAdapter
java.lang.Object
org.xml.sax.helpers.ParserAdapter
All Implemented Interfaces:
public class ParserAdapter
extends Object
implements XMLReader, DocumentHandler
Adapt a SAX1 Parser as a SAX2 XMLReader.
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 SAX1 Parser and makes it act as a SAX2 XMLReader, with feature, property, and Namespace support. Note that it is not possible to report skippedEntity events, since SAX1 does not make that information available.
This adapter does not test for duplicate Namespace-qualified attribute names.
Since:
SAX 2.0
See Also:
XMLReaderAdapter, XMLReader, Parser
Constructor Summary |
---|
ParserAdapter() Construct a new parser adapter. |
ParserAdapter(Parser parser) Construct a new parser adapter. |
Method Summary | |
---|---|
void | [characters](../../../../org/xml/sax/helpers/ParserAdapter.html#characters%28char[], int, int%29)(char[] ch, int start, int length) Adapter implementation method; do not call. |
void | endDocument() Adapter implementation method; do not call. |
void | endElement(String qName) Adapter implementation method; do not call. |
ContentHandler | getContentHandler() Return the current content handler. |
DTDHandler | getDTDHandler() Return the current DTD handler. |
EntityResolver | getEntityResolver() Return the current entity resolver. |
ErrorHandler | getErrorHandler() Return the current error handler. |
boolean | getFeature(String name) Check a parser feature flag. |
Object | getProperty(String name) Get a parser property. |
void | [ignorableWhitespace](../../../../org/xml/sax/helpers/ParserAdapter.html#ignorableWhitespace%28char[], int, int%29)(char[] ch, int start, int length) Adapter implementation method; do not call. |
void | parse(InputSource input) Parse an XML document. |
void | parse(String systemId) Parse an XML document. |
void | [processingInstruction](../../../../org/xml/sax/helpers/ParserAdapter.html#processingInstruction%28java.lang.String, java.lang.String%29)(String target,String data) Adapter implementation method; do not call. |
void | setContentHandler(ContentHandler handler) Set the content handler. |
void | setDocumentLocator(Locator locator) Adapter implementation method; do not call. |
void | setDTDHandler(DTDHandler handler) Set the DTD handler. |
void | setEntityResolver(EntityResolver resolver) Set the entity resolver. |
void | setErrorHandler(ErrorHandler handler) Set the error handler. |
void | [setFeature](../../../../org/xml/sax/helpers/ParserAdapter.html#setFeature%28java.lang.String, boolean%29)(String name, boolean value) Set a feature flag for the parser. |
void | [setProperty](../../../../org/xml/sax/helpers/ParserAdapter.html#setProperty%28java.lang.String, java.lang.Object%29)(String name,Object value) Set a parser property. |
void | startDocument() Adapter implementation method; do not call. |
void | [startElement](../../../../org/xml/sax/helpers/ParserAdapter.html#startElement%28java.lang.String, org.xml.sax.AttributeList%29)(String qName,AttributeList qAtts) Adapter implementation method; do not call. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../../../java/lang/Object.html#wait%28long, int%29) |
Constructor Detail |
---|
ParserAdapter
public ParserAdapter() throws SAXException
Construct a new parser adapter.
Use the "org.xml.sax.parser" property to locate the embedded SAX1 driver.
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- If the embedded driver cannot be instantiated or if the org.xml.sax.parser property is not specified.
ParserAdapter
public ParserAdapter(Parser parser)
Construct a new parser adapter.
Note that the embedded parser cannot be changed once the adapter is created; to embed a different parser, allocate a new ParserAdapter.
Parameters:
parser
- The SAX1 parser to embed.
Throws:
[NullPointerException](../../../../java/lang/NullPointerException.html "class in java.lang")
- If the parser parameter is null.
Method Detail |
---|
setFeature
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
Set a feature flag for the parser.
The only features recognized are namespaces and namespace-prefixes.
Specified by:
[setFeature](../../../../org/xml/sax/XMLReader.html#setFeature%28java.lang.String, boolean%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
name
- The feature name, as a complete URI.
value
- The requested feature value.
Throws:
[SAXNotRecognizedException](../../../../org/xml/sax/SAXNotRecognizedException.html "class in org.xml.sax")
- If the feature can't be assigned or retrieved.
[SAXNotSupportedException](../../../../org/xml/sax/SAXNotSupportedException.html "class in org.xml.sax")
- If the feature can't be assigned that value.
See Also:
[XMLReader.setFeature(java.lang.String, boolean)](../../../../org/xml/sax/XMLReader.html#setFeature%28java.lang.String, boolean%29)
getFeature
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException
Check a parser feature flag.
The only features recognized are namespaces and namespace-prefixes.
Specified by:
[getFeature](../../../../org/xml/sax/XMLReader.html#getFeature%28java.lang.String%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
name
- The feature name, as a complete URI.
Returns:
The current feature value.
Throws:
[SAXNotRecognizedException](../../../../org/xml/sax/SAXNotRecognizedException.html "class in org.xml.sax")
- If the feature value can't be assigned or retrieved.
[SAXNotSupportedException](../../../../org/xml/sax/SAXNotSupportedException.html "class in org.xml.sax")
- If the feature is not currently readable.
See Also:
[XMLReader.setFeature(java.lang.String, boolean)](../../../../org/xml/sax/XMLReader.html#setFeature%28java.lang.String, boolean%29)
setProperty
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
Set a parser property.
No properties are currently recognized.
Specified by:
[setProperty](../../../../org/xml/sax/XMLReader.html#setProperty%28java.lang.String, java.lang.Object%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
name
- The property name.
value
- The property value.
Throws:
[SAXNotRecognizedException](../../../../org/xml/sax/SAXNotRecognizedException.html "class in org.xml.sax")
- If the property value can't be assigned or retrieved.
[SAXNotSupportedException](../../../../org/xml/sax/SAXNotSupportedException.html "class in org.xml.sax")
- If the property can't be assigned that value.
See Also:
[XMLReader.setProperty(java.lang.String, java.lang.Object)](../../../../org/xml/sax/XMLReader.html#setProperty%28java.lang.String, java.lang.Object%29)
getProperty
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException
Get a parser property.
No properties are currently recognized.
Specified by:
[getProperty](../../../../org/xml/sax/XMLReader.html#getProperty%28java.lang.String%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
name
- The property name.
Returns:
The property value.
Throws:
[SAXNotRecognizedException](../../../../org/xml/sax/SAXNotRecognizedException.html "class in org.xml.sax")
- If the property value can't be assigned or retrieved.
[SAXNotSupportedException](../../../../org/xml/sax/SAXNotSupportedException.html "class in org.xml.sax")
- If the property value is not currently readable.
See Also:
XMLReader.getProperty(java.lang.String)
setEntityResolver
public void setEntityResolver(EntityResolver resolver)
Set the entity resolver.
Specified by:
[setEntityResolver](../../../../org/xml/sax/XMLReader.html#setEntityResolver%28org.xml.sax.EntityResolver%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
resolver
- The new entity resolver.
See Also:
XMLReader.setEntityResolver(org.xml.sax.EntityResolver)
getEntityResolver
public EntityResolver getEntityResolver()
Return the current entity resolver.
Specified by:
[getEntityResolver](../../../../org/xml/sax/XMLReader.html#getEntityResolver%28%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Returns:
The current entity resolver, or null if none was supplied.
See Also:
setDTDHandler
public void setDTDHandler(DTDHandler handler)
Set the DTD handler.
Specified by:
[setDTDHandler](../../../../org/xml/sax/XMLReader.html#setDTDHandler%28org.xml.sax.DTDHandler%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
handler
- the new DTD handler
See Also:
XMLReader.setEntityResolver(org.xml.sax.EntityResolver)
getDTDHandler
public DTDHandler getDTDHandler()
Return the current DTD handler.
Specified by:
[getDTDHandler](../../../../org/xml/sax/XMLReader.html#getDTDHandler%28%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Returns:
the current DTD handler, or null if none was supplied
See Also:
setContentHandler
public void setContentHandler(ContentHandler handler)
Set the content handler.
Specified by:
[setContentHandler](../../../../org/xml/sax/XMLReader.html#setContentHandler%28org.xml.sax.ContentHandler%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
handler
- the new content handler
See Also:
XMLReader.setEntityResolver(org.xml.sax.EntityResolver)
getContentHandler
public ContentHandler getContentHandler()
Return the current content handler.
Specified by:
[getContentHandler](../../../../org/xml/sax/XMLReader.html#getContentHandler%28%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Returns:
The current content handler, or null if none was supplied.
See Also:
setErrorHandler
public void setErrorHandler(ErrorHandler handler)
Set the error handler.
Specified by:
[setErrorHandler](../../../../org/xml/sax/XMLReader.html#setErrorHandler%28org.xml.sax.ErrorHandler%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
handler
- The new error handler.
See Also:
XMLReader.setEntityResolver(org.xml.sax.EntityResolver)
getErrorHandler
public ErrorHandler getErrorHandler()
Return the current error handler.
Specified by:
[getErrorHandler](../../../../org/xml/sax/XMLReader.html#getErrorHandler%28%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Returns:
The current error handler, or null if none was supplied.
See Also:
parse
public void parse(String systemId) throws IOException, SAXException
Parse an XML document.
Specified by:
[parse](../../../../org/xml/sax/XMLReader.html#parse%28java.lang.String%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
systemId
- The absolute URL of the document.
Throws:
[IOException](../../../../java/io/IOException.html "class in java.io")
- If there is a problem reading the raw content of the document.
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- If there is a problem processing the document.
See Also:
parse(org.xml.sax.InputSource), Parser.parse(java.lang.String)
parse
public void parse(InputSource input) throws IOException, SAXException
Parse an XML document.
Specified by:
[parse](../../../../org/xml/sax/XMLReader.html#parse%28org.xml.sax.InputSource%29)
in interface [XMLReader](../../../../org/xml/sax/XMLReader.html "interface in org.xml.sax")
Parameters:
input
- An input source for the document.
Throws:
[IOException](../../../../java/io/IOException.html "class in java.io")
- If there is a problem reading the raw content of the document.
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- If there is a problem processing the document.
See Also:
parse(java.lang.String), Parser.parse(org.xml.sax.InputSource)
setDocumentLocator
public void setDocumentLocator(Locator locator)
Adapter implementation method; do not call. Adapt a SAX1 document locator event.
Specified by:
[setDocumentLocator](../../../../org/xml/sax/DocumentHandler.html#setDocumentLocator%28org.xml.sax.Locator%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Parameters:
locator
- A document locator.
See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator)
startDocument
public void startDocument() throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 start document event.
Specified by:
[startDocument](../../../../org/xml/sax/DocumentHandler.html#startDocument%28%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
DocumentHandler.startDocument()
endDocument
public void endDocument() throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 end document event.
Specified by:
[endDocument](../../../../org/xml/sax/DocumentHandler.html#endDocument%28%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
startElement
public void startElement(String qName, AttributeList qAtts) throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 startElement event.
If necessary, perform Namespace processing.
Specified by:
[startElement](../../../../org/xml/sax/DocumentHandler.html#startElement%28java.lang.String, org.xml.sax.AttributeList%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Parameters:
qName
- The qualified (prefixed) name.
qAtts
- The XML attribute list (with qnames).
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
DocumentHandler.endElement(java.lang.String), AttributeList
endElement
public void endElement(String qName) throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 end element event.
Specified by:
[endElement](../../../../org/xml/sax/DocumentHandler.html#endElement%28java.lang.String%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Parameters:
qName
- The qualified (prefixed) name.
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
DocumentHandler.endElement(java.lang.String)
characters
public void characters(char[] ch, int start, int length) throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 characters event.
Specified by:
[characters](../../../../org/xml/sax/DocumentHandler.html#characters%28char[], int, int%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Parameters:
ch
- An array of characters.
start
- The starting position in the array.
length
- The number of characters to use.
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
[DocumentHandler.characters(char[], int, int)](../../../../org/xml/sax/DocumentHandler.html#characters%28char[], int, int%29)
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 ignorable whitespace event.
Specified by:
[ignorableWhitespace](../../../../org/xml/sax/DocumentHandler.html#ignorableWhitespace%28char[], int, int%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Parameters:
ch
- An array of characters.
start
- The starting position in the array.
length
- The number of characters to use.
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
[DocumentHandler.ignorableWhitespace(char[], int, int)](../../../../org/xml/sax/DocumentHandler.html#ignorableWhitespace%28char[], int, int%29)
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
Adapter implementation method; do not call. Adapt a SAX1 processing instruction event.
Specified by:
[processingInstruction](../../../../org/xml/sax/DocumentHandler.html#processingInstruction%28java.lang.String, java.lang.String%29)
in interface [DocumentHandler](../../../../org/xml/sax/DocumentHandler.html "interface in org.xml.sax")
Parameters:
target
- The processing instruction target.
data
- The remainder of the processing instruction
Throws:
[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax")
- The client may raise a processing exception.
See Also:
[DocumentHandler.processingInstruction(java.lang.String, java.lang.String)](../../../../org/xml/sax/DocumentHandler.html#processingInstruction%28java.lang.String, java.lang.String%29)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.