Class XMLReaderAdapter
- All Implemented Interfaces:
ContentHandler, Parser
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:
- 1.4, SAX 2.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new adapter.XMLReaderAdapter(XMLReader xmlReader) Create a new adapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) Adapt a SAX2 characters event.voidEnd document event.voidendElement(String uri, String localName, String qName) Adapt a SAX2 end element event.voidendPrefixMapping(String prefix) Adapt a SAX2 end prefix mapping event.voidignorableWhitespace(char[] ch, int start, int length) Adapt a SAX2 ignorable whitespace event.voidParse the document.voidparse(InputSource input) Parse the document.voidprocessingInstruction(String target, String data) Adapt a SAX2 processing instruction event.voidsetDocumentHandler(DocumentHandler handler) Register the SAX1 document event handler.voidsetDocumentLocator(Locator locator) Set a document locator.voidsetDTDHandler(DTDHandler handler) Register the DTD event handler.voidsetEntityResolver(EntityResolver resolver) Register the entity resolver.voidsetErrorHandler(ErrorHandler handler) Register the error event handler.voidSet the locale for error reporting.voidskippedEntity(String name) Adapt a SAX2 skipped entity event.voidStart document event.voidstartElement(String uri, String localName, String qName, Attributes atts) Adapt a SAX2 start element event.voidstartPrefixMapping(String prefix, String uri) Adapt a SAX2 start prefix mapping event.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.Methods declared in interface ContentHandler
declarationModifier and TypeMethodDescriptiondefault voiddeclaration(String version, String encoding, String standalone) Receives notification of the XML declaration.
-
Constructor Details
-
XMLReaderAdapter
Create a new adapter.Use the "org.xml.sax.driver" property to locate the SAX2 driver to embed.
- Throws:
SAXException- If the embedded driver cannot be instantiated or if the org.xml.sax.driver property is not specified.
-
XMLReaderAdapter
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- If the argument is null.
-
-
Method Details
-
setLocale
Set the locale for error reporting.This is not supported in SAX2, and will always throw an exception.
- Specified by:
setLocalein interfaceParser- Parameters:
locale- the locale for error reporting.- Throws:
SAXException- Thrown unless overridden.- See Also:
-
setEntityResolver
Register the entity resolver.- Specified by:
setEntityResolverin interfaceParser- Parameters:
resolver- The new resolver.- See Also:
-
setDTDHandler
Register the DTD event handler.- Specified by:
setDTDHandlerin interfaceParser- Parameters:
handler- The new DTD event handler.- See Also:
-
setDocumentHandler
Register the SAX1 document event handler.Note that the SAX1 document handler has no Namespace support.
- Specified by:
setDocumentHandlerin interfaceParser- Parameters:
handler- The new SAX1 document event handler.- See Also:
-
setErrorHandler
Register the error event handler.- Specified by:
setErrorHandlerin interfaceParser- Parameters:
handler- The new error event handler.- See Also:
-
parse
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:
parsein interfaceParser- 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
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:
parsein interfaceParser- 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
Set a document locator.- Specified by:
setDocumentLocatorin interfaceContentHandler- Parameters:
locator- The document locator.- See Also:
-
startDocument
Start document event.- Specified by:
startDocumentin interfaceContentHandler- Throws:
SAXException- The client may raise a processing exception.- See Also:
-
endDocument
End document event.- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAXException- The client may raise a processing exception.- See Also:
-
startPrefixMapping
Adapt a SAX2 start prefix mapping event.- Specified by:
startPrefixMappingin interfaceContentHandler- Parameters:
prefix- The prefix being mapped.uri- The Namespace URI being mapped to.- See Also:
-
endPrefixMapping
Adapt a SAX2 end prefix mapping event.- Specified by:
endPrefixMappingin interfaceContentHandler- Parameters:
prefix- The prefix being mapped.- See Also:
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException Adapt a SAX2 start element event.- Specified by:
startElementin interfaceContentHandler- Parameters:
uri- The Namespace URI.localName- The Namespace local name.qName- The qualified (prefixed) name.atts- The SAX2 attributes.- Throws:
SAXException- The client may raise a processing exception.- See Also:
-
endElement
Adapt a SAX2 end element event.- Specified by:
endElementin interfaceContentHandler- Parameters:
uri- The Namespace URI.localName- The Namespace local name.qName- The qualified (prefixed) name.- Throws:
SAXException- The client may raise a processing exception.- See Also:
-
characters
Adapt a SAX2 characters event.- Specified by:
charactersin interfaceContentHandler- 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
Adapt a SAX2 ignorable whitespace event.- Specified by:
ignorableWhitespacein interfaceContentHandler- 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
Adapt a SAX2 processing instruction event.- Specified by:
processingInstructionin interfaceContentHandler- Parameters:
target- The processing instruction target.data- The remainder of the processing instruction- Throws:
SAXException- The client may raise a processing exception.- See Also:
-
skippedEntity
Adapt a SAX2 skipped entity event.- Specified by:
skippedEntityin interfaceContentHandler- Parameters:
name- The name of the skipped entity.- Throws:
SAXException- Throwable by subclasses.- See Also:
-