Class ParserAdapter
- All Implemented Interfaces:
-
DocumentHandler
,XMLReader
public class ParserAdapter extends Object implements XMLReader, DocumentHandler
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:
- 1.4, SAX 2.0
- See Also:
Constructor Summary
Constructor | Description |
---|---|
ParserAdapter() |
Construct a new parser adapter. |
ParserAdapter |
Construct a new parser adapter. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void |
characters |
Adapter implementation method; do not call. |
void |
endDocument() |
Adapter implementation method; do not call. |
void |
endElement |
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 |
Check a parser feature flag. |
Object |
getProperty |
Get a parser property. |
void |
ignorableWhitespace |
Adapter implementation method; do not call. |
void |
parse |
Parse an XML document. |
void |
parse |
Parse an XML document. |
void |
processingInstruction |
Adapter implementation method; do not call. |
void |
setContentHandler |
Set the content handler. |
void |
setDocumentLocator |
Adapter implementation method; do not call. |
void |
setDTDHandler |
Set the DTD handler. |
void |
setEntityResolver |
Set the entity resolver. |
void |
setErrorHandler |
Set the error handler. |
void |
setFeature |
Set a feature flag for the parser. |
void |
setProperty |
Set a parser property. |
void |
startDocument() |
Adapter implementation method; do not call. |
void |
startElement |
Adapter implementation method; do not call. |
Constructor Details
ParserAdapter
public ParserAdapter() throws SAXException
Use the "org.xml.sax.parser" property to locate the embedded SAX1 driver.
- Throws:
-
SAXException
- If the embedded driver cannot be instantiated or if the org.xml.sax.parser property is not specified.
ParserAdapter
public ParserAdapter(Parser parser)
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
- If the parser parameter is null.
Method Details
setFeature
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
The only features recognized are namespaces and namespace-prefixes.
- Specified by:
-
setFeature
in interfaceXMLReader
- Parameters:
-
name
- The feature name, as a complete URI. -
value
- The requested feature value. - Throws:
-
SAXNotRecognizedException
- If the feature can't be assigned or retrieved. -
SAXNotSupportedException
- If the feature can't be assigned that value. - See Also:
getFeature
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException
The only features recognized are namespaces and namespace-prefixes.
- Specified by:
-
getFeature
in interfaceXMLReader
- Parameters:
-
name
- The feature name, as a complete URI. - Returns:
- The current feature value.
- Throws:
-
SAXNotRecognizedException
- If the feature value can't be assigned or retrieved. -
SAXNotSupportedException
- If the feature is not currently readable. - See Also:
setProperty
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
No properties are currently recognized.
- Specified by:
-
setProperty
in interfaceXMLReader
- Parameters:
-
name
- The property name. -
value
- The property value. - Throws:
-
SAXNotRecognizedException
- If the property value can't be assigned or retrieved. -
SAXNotSupportedException
- If the property can't be assigned that value. - See Also:
getProperty
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException
No properties are currently recognized.
- Specified by:
-
getProperty
in interfaceXMLReader
- Parameters:
-
name
- The property name. - Returns:
- The property value.
- Throws:
-
SAXNotRecognizedException
- If the property value can't be assigned or retrieved. -
SAXNotSupportedException
- If the property value is not currently readable. - See Also:
setEntityResolver
public void setEntityResolver(EntityResolver resolver)
- Specified by:
-
setEntityResolver
in interfaceXMLReader
- Parameters:
-
resolver
- The new entity resolver. - See Also:
getEntityResolver
public EntityResolver getEntityResolver()
- Specified by:
-
getEntityResolver
in interfaceXMLReader
- Returns:
- The current entity resolver, or null if none was supplied.
- See Also:
setDTDHandler
public void setDTDHandler(DTDHandler handler)
- Specified by:
-
setDTDHandler
in interfaceXMLReader
- Parameters:
-
handler
- the new DTD handler - See Also:
getDTDHandler
public DTDHandler getDTDHandler()
- Specified by:
-
getDTDHandler
in interfaceXMLReader
- Returns:
- the current DTD handler, or null if none was supplied
- See Also:
setContentHandler
public void setContentHandler(ContentHandler handler)
- Specified by:
-
setContentHandler
in interfaceXMLReader
- Parameters:
-
handler
- the new content handler - See Also:
getContentHandler
public ContentHandler getContentHandler()
- Specified by:
-
getContentHandler
in interfaceXMLReader
- Returns:
- The current content handler, or null if none was supplied.
- See Also:
setErrorHandler
public void setErrorHandler(ErrorHandler handler)
- Specified by:
-
setErrorHandler
in interfaceXMLReader
- Parameters:
-
handler
- The new error handler. - See Also:
getErrorHandler
public ErrorHandler getErrorHandler()
- Specified by:
-
getErrorHandler
in interfaceXMLReader
- Returns:
- The current error handler, or null if none was supplied.
- See Also:
parse
public void parse(String systemId) throws IOException, SAXException
- Specified by:
-
parse
in interfaceXMLReader
- Parameters:
-
systemId
- The absolute URL of the document. - Throws:
-
IOException
- If there is a problem reading the raw content of the document. -
SAXException
- If there is a problem processing the document. - See Also:
parse
public void parse(InputSource input) throws IOException, SAXException
- Specified by:
-
parse
in interfaceXMLReader
- Parameters:
-
input
- An input source for the document. - Throws:
-
IOException
- If there is a problem reading the raw content of the document. -
SAXException
- If there is a problem processing the document. - See Also:
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
-
setDocumentLocator
in interfaceDocumentHandler
- Parameters:
-
locator
- A document locator. - See Also:
startDocument
public void startDocument() throws SAXException
- Specified by:
-
startDocument
in interfaceDocumentHandler
- Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
endDocument
public void endDocument() throws SAXException
- Specified by:
-
endDocument
in interfaceDocumentHandler
- Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
startElement
public void startElement(String qName, AttributeList qAtts) throws SAXException
If necessary, perform Namespace processing.
- Specified by:
-
startElement
in interfaceDocumentHandler
- Parameters:
-
qName
- The qualified (prefixed) name. -
qAtts
- The XML attribute list (with qnames). - Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
endElement
public void endElement(String qName) throws SAXException
- Specified by:
-
endElement
in interfaceDocumentHandler
- Parameters:
-
qName
- The qualified (prefixed) name. - Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
characters
public void characters(char[] ch, int start, int length) throws SAXException
- Specified by:
-
characters
in interfaceDocumentHandler
- Parameters:
-
ch
- An array of characters. -
start
- The starting position in the array. -
length
- The number of characters to use. - Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
- Specified by:
-
ignorableWhitespace
in interfaceDocumentHandler
- Parameters:
-
ch
- An array of characters. -
start
- The starting position in the array. -
length
- The number of characters to use. - Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
-
processingInstruction
in interfaceDocumentHandler
- Parameters:
-
target
- The processing instruction target. -
data
- The remainder of the processing instruction - Throws:
-
SAXException
- The client may raise a processing exception. - See Also:
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.xml/org/xml/sax/helpers/ParserAdapter.html