- java.lang.Object
-
- 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 SAX1Parser
. The XMLReader must support a true value for the http://xml.org/sax/features/namespace-prefixes property or parsing will fail with aSAXException
; if the XMLReader supports a false value for the http://xml.org/sax/features/namespaces property, that will also be used to improve efficiency.
-
-
Constructor Summary
Constructors Constructor and Description XMLReaderAdapter()
Create a new adapter.XMLReaderAdapter(XMLReader xmlReader)
Create a new adapter.
-
Method Summary
Methods Modifier and Type Method and Description void
characters(char[] ch, int start, int length)
Adapt a SAX2 characters event.void
endDocument()
End document event.void
endElement(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(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(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(String uri, String localName, String qName, Attributes atts)
Adapt a SAX2 start element event.void
startPrefixMapping(String prefix, String uri)
Adapt a SAX2 start prefix mapping event.
-
-
-
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
- 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
- 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
in interfaceParser
- Parameters:
locale
- the locale for error reporting.- Throws:
SAXException
- Thrown unless overridden.- See Also:
Parser.setLocale(java.util.Locale)
-
setEntityResolver
public void setEntityResolver(EntityResolver resolver)
Register the entity resolver.- Specified by:
setEntityResolver
in interfaceParser
- 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
in interfaceParser
- 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
in interfaceParser
- 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
in interfaceParser
- 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
in 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(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
in 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:
parse(java.lang.String)
,Parser.parse(org.xml.sax.InputSource)
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
Set a document locator.- Specified by:
setDocumentLocator
in interfaceContentHandler
- 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
in interfaceContentHandler
- Throws:
SAXException
- The client may raise a processing exception.- See Also:
ContentHandler.startDocument()
-
endDocument
public void endDocument() throws SAXException
End document event.- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
- 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
in interfaceContentHandler
- Parameters:
prefix
- The prefix being mapped.uri
- The Namespace URI being mapped to.- See Also:
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
-
endPrefixMapping
public void endPrefixMapping(String prefix)
Adapt a SAX2 end prefix mapping event.- Specified by:
endPrefixMapping
in interfaceContentHandler
- 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
in 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:
ContentHandler.endDocument()
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
Adapt a SAX2 end element event.- Specified by:
endElement
in 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:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
-
characters
public void characters(char[] ch, int start, int length) throws SAXException
Adapt a SAX2 characters event.- Specified by:
characters
in 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:
ContentHandler.characters(char[], int, int)
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
Adapt a SAX2 ignorable whitespace event.- Specified by:
ignorableWhitespace
in 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:
ContentHandler.ignorableWhitespace(char[], int, int)
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
Adapt a SAX2 processing instruction event.- Specified by:
processingInstruction
in 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:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)
-
skippedEntity
public void skippedEntity(String name) throws SAXException
Adapt a SAX2 skipped entity event.- Specified by:
skippedEntity
in interfaceContentHandler
- Parameters:
name
- The name of the skipped entity.- Throws:
SAXException
- Throwable by subclasses.- See Also:
ContentHandler.skippedEntity(java.lang.String)
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-org/xml/sax/helpers/XMLReaderAdapter.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.