XMLReaderAdapter (Java 2 Platform SE 5.0) (original) (raw)


org.xml.sax.helpers

Class XMLReaderAdapter

java.lang.Object extended by org.xml.sax.helpers.XMLReaderAdapter

All Implemented Interfaces:

ContentHandler, Parser


public class XMLReaderAdapter

extends Object

implements Parser, ContentHandler

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.

Since:

SAX 2.0

See Also:

Parser, XMLReader


Constructor Summary
XMLReaderAdapter() Create a new adapter.
XMLReaderAdapter(XMLReader xmlReader) Create a new adapter.
Method Summary
void [characters](../../../../org/xml/sax/helpers/XMLReaderAdapter.html#characters%28char[], int, int%29)(char[] ch, int start, int length) Adapt a SAX2 characters event.
void endDocument() End document event.
void [endElement](../../../../org/xml/sax/helpers/XMLReaderAdapter.html#endElement%28java.lang.String, java.lang.String, java.lang.String%29)(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](../../../../org/xml/sax/helpers/XMLReaderAdapter.html#ignorableWhitespace%28char[], int, int%29)(char[] ch, int start, int length) Adapt a SAX2 ignorable whitespace event.
void parse(InputSource input) Parse the document.
void parse(String systemId) Parse the document.
void [processingInstruction](../../../../org/xml/sax/helpers/XMLReaderAdapter.html#processingInstruction%28java.lang.String, java.lang.String%29)(String target,String data) Adapt a SAX2 processing instruction event.
void setDocumentHandler(DocumentHandler handler) Register the SAX1 document event handler.
void setDocumentLocator(Locator locator) Set a document locator.
void setDTDHandler(DTDHandler handler) Register the DTD event handler.
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](../../../../org/xml/sax/helpers/XMLReaderAdapter.html#startElement%28java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes%29)(String uri,String localName,String qName,Attributes atts) Adapt a SAX2 start element event.
void [startPrefixMapping](../../../../org/xml/sax/helpers/XMLReaderAdapter.html#startPrefixMapping%28java.lang.String, java.lang.String%29)(String prefix,String uri) Adapt a SAX2 start prefix mapping event.
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

XMLReaderAdapter

public XMLReaderAdapter() throws SAXException

Create a new adapter.

Use the "org.xml.sax.driver" property to locate the SAX2 driver to embed.

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.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.

Parameters:

xmlReader - The SAX2 XMLReader to wrap.

Throws:

[NullPointerException](../../../../java/lang/NullPointerException.html "class in java.lang") - If the argument is null.

Method Detail

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.

Specified by:

[setLocale](../../../../org/xml/sax/Parser.html#setLocale%28java.util.Locale%29) in interface [Parser](../../../../org/xml/sax/Parser.html "interface in org.xml.sax")

Parameters:

locale - the locale for error reporting.

Throws:

[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax") - Thrown unless overridden.

See Also:

Parser.setLocale(java.util.Locale)


setEntityResolver

public void setEntityResolver(EntityResolver resolver)

Register the entity resolver.

Specified by:

[setEntityResolver](../../../../org/xml/sax/Parser.html#setEntityResolver%28org.xml.sax.EntityResolver%29) in interface [Parser](../../../../org/xml/sax/Parser.html "interface in org.xml.sax")

Parameters:

resolver - The new resolver.

See Also:

Parser.setEntityResolver(org.xml.sax.EntityResolver)


setDTDHandler

public void setDTDHandler(DTDHandler handler)

Register the DTD event handler.

Specified by:

[setDTDHandler](../../../../org/xml/sax/Parser.html#setDTDHandler%28org.xml.sax.DTDHandler%29) in interface [Parser](../../../../org/xml/sax/Parser.html "interface in org.xml.sax")

Parameters:

handler - The new DTD event handler.

See Also:

Parser.setDTDHandler(org.xml.sax.DTDHandler)


setDocumentHandler

public void setDocumentHandler(DocumentHandler handler)

Register the SAX1 document event handler.

Note that the SAX1 document handler has no Namespace support.

Specified by:

[setDocumentHandler](../../../../org/xml/sax/Parser.html#setDocumentHandler%28org.xml.sax.DocumentHandler%29) in interface [Parser](../../../../org/xml/sax/Parser.html "interface in org.xml.sax")

Parameters:

handler - The new SAX1 document event handler.

See Also:

Parser.setDocumentHandler(org.xml.sax.DocumentHandler)


setErrorHandler

public void setErrorHandler(ErrorHandler handler)

Register the error event handler.

Specified by:

[setErrorHandler](../../../../org/xml/sax/Parser.html#setErrorHandler%28org.xml.sax.ErrorHandler%29) in interface [Parser](../../../../org/xml/sax/Parser.html "interface in org.xml.sax")

Parameters:

handler - The new error event handler.

See Also:

Parser.setErrorHandler(org.xml.sax.ErrorHandler)


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.

Specified by:

[parse](../../../../org/xml/sax/Parser.html#parse%28java.lang.String%29) in interface [Parser](../../../../org/xml/sax/Parser.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 the document.

This method will throw an exception if the embedded XMLReader does not support the http://xml.org/sax/features/namespace-prefixes property.

Specified by:

[parse](../../../../org/xml/sax/Parser.html#parse%28org.xml.sax.InputSource%29) in interface [Parser](../../../../org/xml/sax/Parser.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)

Set a document locator.

Specified by:

[setDocumentLocator](../../../../org/xml/sax/ContentHandler.html#setDocumentLocator%28org.xml.sax.Locator%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.html "interface in org.xml.sax")

Parameters:

locator - The document locator.

See Also:

ContentHandler.setDocumentLocator(org.xml.sax.Locator)


startDocument

public void startDocument() throws SAXException

Start document event.

Specified by:

[startDocument](../../../../org/xml/sax/ContentHandler.html#startDocument%28%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.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:

ContentHandler.startDocument()


endDocument

public void endDocument() throws SAXException

End document event.

Specified by:

[endDocument](../../../../org/xml/sax/ContentHandler.html#endDocument%28%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.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:

ContentHandler.endDocument()


startPrefixMapping

public void startPrefixMapping(String prefix, String uri)

Adapt a SAX2 start prefix mapping event.

Specified by:

[startPrefixMapping](../../../../org/xml/sax/ContentHandler.html#startPrefixMapping%28java.lang.String, java.lang.String%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.html "interface in org.xml.sax")

Parameters:

prefix - The prefix being mapped.

uri - The Namespace URI being mapped to.

See Also:

[ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)](../../../../org/xml/sax/ContentHandler.html#startPrefixMapping%28java.lang.String, java.lang.String%29)


endPrefixMapping

public void endPrefixMapping(String prefix)

Adapt a SAX2 end prefix mapping event.

Specified by:

[endPrefixMapping](../../../../org/xml/sax/ContentHandler.html#endPrefixMapping%28java.lang.String%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.html "interface in org.xml.sax")

Parameters:

prefix - The prefix being mapped.

See Also:

ContentHandler.endPrefixMapping(java.lang.String)


startElement

public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException

Adapt a SAX2 start element event.

Specified by:

[startElement](../../../../org/xml/sax/ContentHandler.html#startElement%28java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.html "interface in org.xml.sax")

Parameters:

uri - The Namespace URI.

localName - The Namespace local name.

qName - The qualified (prefixed) name.

atts - The SAX2 attributes.

Throws:

[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax") - The client may raise a processing exception.

See Also:

ContentHandler.endDocument()


endElement

public void endElement(String uri, String localName, String qName) throws SAXException

Adapt a SAX2 end element event.

Specified by:

[endElement](../../../../org/xml/sax/ContentHandler.html#endElement%28java.lang.String, java.lang.String, java.lang.String%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.html "interface in org.xml.sax")

Parameters:

uri - The Namespace URI.

localName - The Namespace local name.

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:

[ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)](../../../../org/xml/sax/ContentHandler.html#endElement%28java.lang.String, java.lang.String, java.lang.String%29)


characters

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

Adapt a SAX2 characters event.

Specified by:

[characters](../../../../org/xml/sax/ContentHandler.html#characters%28char[], int, int%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.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:

[ContentHandler.characters(char[], int, int)](../../../../org/xml/sax/ContentHandler.html#characters%28char[], int, int%29)


ignorableWhitespace

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

Adapt a SAX2 ignorable whitespace event.

Specified by:

[ignorableWhitespace](../../../../org/xml/sax/ContentHandler.html#ignorableWhitespace%28char[], int, int%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.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:

[ContentHandler.ignorableWhitespace(char[], int, int)](../../../../org/xml/sax/ContentHandler.html#ignorableWhitespace%28char[], int, int%29)


processingInstruction

public void processingInstruction(String target, String data) throws SAXException

Adapt a SAX2 processing instruction event.

Specified by:

[processingInstruction](../../../../org/xml/sax/ContentHandler.html#processingInstruction%28java.lang.String, java.lang.String%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.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:

[ContentHandler.processingInstruction(java.lang.String, java.lang.String)](../../../../org/xml/sax/ContentHandler.html#processingInstruction%28java.lang.String, java.lang.String%29)


skippedEntity

public void skippedEntity(String name) throws SAXException

Adapt a SAX2 skipped entity event.

Specified by:

[skippedEntity](../../../../org/xml/sax/ContentHandler.html#skippedEntity%28java.lang.String%29) in interface [ContentHandler](../../../../org/xml/sax/ContentHandler.html "interface in org.xml.sax")

Parameters:

name - The name of the skipped entity.

Throws:

[SAXException](../../../../org/xml/sax/SAXException.html "class in org.xml.sax") - Throwable by subclasses.

See Also:

ContentHandler.skippedEntity(java.lang.String)



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.