public class SAXCatalogReader extends Object implements CatalogReader, ContentHandler, DocumentHandler
This class is used to read XML Catalogs using the SAX. This reader has an advantage over the DOM-based reader in that it functions on the stream of SAX events. It has the disadvantage that it cannot look around in the tree.
Since the choice of CatalogReaders (in the InputStream case) can only be made on the basis of MIME type, the following problem occurs: only one CatalogReader can exist for all XML mime types. In order to get around this problem, the SAXCatalogReader relies on a set of external CatalogParsers to actually build the catalog.
The selection of CatalogParsers is made on the basis of the QName of the root element of the document.
Catalog
,
CatalogReader
,
SAXCatalogReader
,
TextCatalogReader
,
DOMCatalogParser
Modifier and Type | Field and Description |
---|---|
protected Debug |
debug
The debug class to use for this reader.
|
protected Hashtable |
namespaceMap
Mapping table from QNames to CatalogParser classes.
|
protected String |
parserClass
The SAX Parser Class
|
protected SAXParserFactory |
parserFactory
The SAX Parser Factory
|
Constructor and Description |
---|
SAXCatalogReader()
The constructor
|
SAXCatalogReader(SAXParserFactory parserFactory)
The constructor
|
SAXCatalogReader(String parserClass)
The constructor
|
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] ch,
int start,
int length)
The SAX
characters method. |
void |
endDocument()
The SAX
endDocument method. |
void |
endElement(String name)
The SAX
endElement method. |
void |
endElement(String namespaceURI,
String localName,
String qName)
The SAX2
endElement method. |
void |
endPrefixMapping(String prefix)
The SAX
endPrefixMapping method. |
String |
getCatalogParser(String namespaceURI,
String rootElement)
Get the SAXCatalogParser class for the given namespace/root
element type.
|
String |
getParserClass() |
SAXParserFactory |
getParserFactory() |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
The SAX
ignorableWhitespace method. |
void |
processingInstruction(String target,
String data)
The SAX
processingInstruction method. |
void |
readCatalog(Catalog catalog,
InputStream is)
Parse an XML Catalog stream.
|
void |
readCatalog(Catalog catalog,
String fileUrl)
Parse an XML Catalog file.
|
void |
setCatalogParser(String namespaceURI,
String rootElement,
String parserClass)
Set the SAXCatalogParser class for the given namespace/root
element type.
|
void |
setDocumentLocator(Locator locator)
The SAX
setDocumentLocator method. |
void |
setParserClass(String parserClass)
Set the XML SAX Parser Class
|
void |
setParserFactory(SAXParserFactory parserFactory)
Set the XML SAX Parser Factory.
|
void |
skippedEntity(String name)
The SAX
skippedentity method. |
void |
startDocument()
The SAX
startDocument method. |
void |
startElement(String name,
AttributeList atts)
The SAX
startElement method. |
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes atts)
The SAX2
startElement method. |
void |
startPrefixMapping(String prefix,
String uri)
The SAX
startPrefixMapping method. |
protected SAXParserFactory parserFactory
protected String parserClass
protected Hashtable namespaceMap
Each key in this hash table has the form "elementname" or "{namespaceuri}elementname". The former is used if the namespace URI is null.
protected Debug debug
public SAXCatalogReader()
public SAXCatalogReader(SAXParserFactory parserFactory)
parserFactory
- public SAXCatalogReader(String parserClass)
parserClass
- public void setParserFactory(SAXParserFactory parserFactory)
parserFactory
- public void setParserClass(String parserClass)
parserClass
- public SAXParserFactory getParserFactory()
public String getParserClass()
public void setCatalogParser(String namespaceURI, String rootElement, String parserClass)
namespaceURI
- rootElement
- parserClass
- public String getCatalogParser(String namespaceURI, String rootElement)
namespaceURI
- rootElement
- public void readCatalog(Catalog catalog, String fileUrl) throws MalformedURLException, IOException, CatalogException
readCatalog
in interface CatalogReader
catalog
- The catalog to which this catalog file belongsfileUrl
- The URL or filename of the catalog file to processMalformedURLException
- Improper fileUrlIOException
- Error reading catalog fileCatalogException
- for any errorpublic void readCatalog(Catalog catalog, InputStream is) throws IOException, CatalogException
readCatalog
in interface CatalogReader
catalog
- The catalog to which this catalog file belongsis
- The input stream from which the catalog will be readMalformedURLException
- Improper fileUrlIOException
- Error reading catalog fileCatalogException
- A Catalog exceptionpublic void setDocumentLocator(Locator locator)
setDocumentLocator
method. Does nothing.setDocumentLocator
in interface ContentHandler
setDocumentLocator
in interface DocumentHandler
public void startDocument() throws SAXException
startDocument
method. Does nothing.startDocument
in interface ContentHandler
startDocument
in interface DocumentHandler
SAXException
public void endDocument() throws SAXException
endDocument
method. Does nothing.endDocument
in interface ContentHandler
endDocument
in interface DocumentHandler
SAXException
public void startElement(String name, AttributeList atts) throws SAXException
startElement
method.
The catalog parser is selected based on the namespace of the first element encountered in the catalog.
startElement
in interface DocumentHandler
SAXException
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
startElement
method.
The catalog parser is selected based on the namespace of the first element encountered in the catalog.
startElement
in interface ContentHandler
SAXException
public void endElement(String name) throws SAXException
endElement
method. Does nothing.endElement
in interface DocumentHandler
SAXException
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement
method. Does nothing.endElement
in interface ContentHandler
SAXException
public void characters(char[] ch, int start, int length) throws SAXException
characters
method. Does nothing.characters
in interface ContentHandler
characters
in interface DocumentHandler
SAXException
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
ignorableWhitespace
method. Does nothing.ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in interface DocumentHandler
SAXException
public void processingInstruction(String target, String data) throws SAXException
processingInstruction
method. Does nothing.processingInstruction
in interface ContentHandler
processingInstruction
in interface DocumentHandler
SAXException
public void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping
method. Does nothing.startPrefixMapping
in interface ContentHandler
SAXException
public void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
method. Does nothing.endPrefixMapping
in interface ContentHandler
SAXException
public void skippedEntity(String name) throws SAXException
skippedentity
method. Does nothing.skippedEntity
in interface ContentHandler
SAXException
Copyright © 2018 JBoss by Red Hat. All rights reserved.