⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.xml.sax.helpers

Class ParserAdapter

java.lang.Object
|
+--org.xml.sax.helpers.ParserAdapter

All Implemented Interfaces:
DocumentHandler, XMLReader


public class ParserAdapter
extends java.lang.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 org.xml.sax.Parser Parser and makes it act as a SAX2 org.xml.sax.XMLReader XMLReader, with feature, property, and Namespace support. Note that it is not possible to report org.xml.sax.ContentHandler.skippedEntity 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
Author:
David Megginson
See Also:
org.xml.sax.helpers.XMLReaderAdapter
org.xml.sax.XMLReader
org.xml.sax.Parser

Constructor Summary

ParserAdapter()

Construct a new parser adapter.

ParserAdapter(Parser parser)

Construct a new parser adapter.

Method Summary

void

characters(char[] ch, int start, int length)

Adapter implementation method; do not call.

void

endDocument()

Adapter implementation method; do not call.

void

endElement(java.lang.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(java.lang.String name)

Check a parser feature flag.

java.lang.Object

getProperty(java.lang.String name)

Get a parser property.

void

ignorableWhitespace(char[] ch, int start, int length)

Adapter implementation method; do not call.

void

parse(java.lang.String systemId)

Parse an XML document.

void

parse(InputSource input)

Parse an XML document.

void

processingInstruction(java.lang.String target, java.lang.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(java.lang.String name, boolean value)

Set a feature flag for the parser.

void

setProperty(java.lang.String name, java.lang.Object value)

Set a parser property.

void

startDocument()

Adapter implementation method; do not call.

void

startElement(java.lang.String qName, AttributeList qAtts)

Adapter implementation method; do not call.

Constructor Details

ParserAdapter

public ParserAdapter()

Construct a new parser adapter.

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)

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:
java.lang.NullPointerException - If the parser parameter is null.

Method Details

characters

public void characters(char[] ch, int start, int length)

Adapter implementation method; do not call. Adapt a SAX1 characters event.

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:
org.xml.sax.DocumentHandler.characters

endDocument

public void endDocument()

Adapter implementation method; do not call. Adapt a SAX1 end document event.

Throws:
SAXException - The client may raise a processing exception.
See Also:
org.xml.sax.DocumentHandler.endDocument

endElement

public void endElement(java.lang.String qName)

Adapter implementation method; do not call. Adapt a SAX1 end element event.

Parameters:
qName - The qualified (prefixed) name.
Throws:
SAXException - The client may raise a processing exception.
See Also:
org.xml.sax.DocumentHandler.endElement

getContentHandler

public ContentHandler getContentHandler()

Return the current content handler.

Returns:
The current content handler, or null if none was supplied.
See Also:
org.xml.sax.XMLReader.getEntityResolver

getDTDHandler

public DTDHandler getDTDHandler()

Return the current DTD handler.

Returns:
The current DTD handler, or null if none was supplied.
See Also:
org.xml.sax.XMLReader.getEntityResolver

getEntityResolver

public EntityResolver getEntityResolver()

Return the current entity resolver.

Returns:
The current entity resolver, or null if none was supplied.
See Also:
org.xml.sax.XMLReader.getEntityResolver

getErrorHandler

public ErrorHandler getErrorHandler()

Return the current error handler.

Returns:
The current error handler, or null if none was supplied.
See Also:
org.xml.sax.XMLReader.getEntityResolver

getFeature

public boolean getFeature(java.lang.String name)

Check a parser feature flag.

The only features recognized are namespaces and namespace-prefixes.

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:
org.xml.sax.XMLReader.setFeature

getProperty

public Object getProperty(java.lang.String name)

Get a parser property.

No properties are currently recognized.

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:
org.xml.sax.XMLReader.getProperty

ignorableWhitespace

public void ignorableWhitespace(char[] ch, int start, int length)

Adapter implementation method; do not call. Adapt a SAX1 ignorable whitespace event.

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:
org.xml.sax.DocumentHandler.ignorableWhitespace

parse

public void parse(java.lang.String systemId)

Parse an XML document.

Parameters:
systemId - The absolute URL of the document.
Throws:
java.io.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(org.xml.sax.InputSource)
org.xml.sax.Parser.parse(java.lang.String)

parse

public void parse(InputSource input)

Parse an XML document.

Parameters:
input - An input source for the document.
Throws:
java.io.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(java.lang.String)
org.xml.sax.Parser.parse(org.xml.sax.InputSource)

processingInstruction

public void processingInstruction(java.lang.String target, java.lang.String data)

Adapter implementation method; do not call. Adapt a SAX1 processing instruction event.

Parameters:
target - The processing instruction target.
data - The remainder of the processing instruction
Throws:
SAXException - The client may raise a processing exception.
See Also:
org.xml.sax.DocumentHandler.processingInstruction

setContentHandler

public void setContentHandler(ContentHandler handler)

Set the content handler.

Parameters:
handler - The new content handler.
See Also:
org.xml.sax.XMLReader.setEntityResolver

setDocumentLocator

public void setDocumentLocator(Locator locator)

Adapter implementation method; do not call. Adapt a SAX1 document locator event.

Parameters:
locator - A document locator.
See Also:
org.xml.sax.ContentHandler.setDocumentLocator

setDTDHandler

public void setDTDHandler(DTDHandler handler)

Set the DTD handler.

Parameters:
handler - The new DTD handler.
See Also:
org.xml.sax.XMLReader.setEntityResolver

setEntityResolver

public void setEntityResolver(EntityResolver resolver)

Set the entity resolver.

Parameters:
resolver - The new entity resolver.
See Also:
org.xml.sax.XMLReader.setEntityResolver

setErrorHandler

public void setErrorHandler(ErrorHandler handler)

Set the error handler.

Parameters:
handler - The new error handler.
See Also:
org.xml.sax.XMLReader.setEntityResolver

setFeature

public void setFeature(java.lang.String name, boolean value)

Set a feature flag for the parser.

The only features recognized are namespaces and namespace-prefixes.

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:
org.xml.sax.XMLReader.setFeature

setProperty

public void setProperty(java.lang.String name, java.lang.Object value)

Set a parser property.

No properties are currently recognized.

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:
org.xml.sax.XMLReader.setProperty

startDocument

public void startDocument()

Adapter implementation method; do not call. Adapt a SAX1 start document event.

Throws:
SAXException - The client may raise a processing exception.
See Also:
org.xml.sax.DocumentHandler.startDocument

startElement

public void startElement(java.lang.String qName, AttributeList qAtts)

Adapter implementation method; do not call. Adapt a SAX1 startElement event.

If necessary, perform Namespace processing.

Parameters:
qName - The qualified (prefixed) name.
qAtts - The XML 1.0 attribute list (with qnames).
Throws:
SAXException - The client may raise a processing exception.