org.apache.xml.resolver.readers

Class SAXCatalogReader

public class SAXCatalogReader extends Object implements CatalogReader, ContentHandler, DocumentHandler

A SAX-based CatalogReader

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.

Version: 1.0

Author: Norman Walsh Norman.Walsh@Sun.COM

See Also: Catalog CatalogReader SAXCatalogReader TextCatalogReader

Field Summary
protected HashtablenamespaceMap

Mapping table from QNames to CatalogParser classes.

Each key in this hash table has the form "elementname" or "{namespaceuri}elementname".

protected StringparserClass
The SAX Parser Class
protected SAXParserFactoryparserFactory
The SAX Parser Factory
Constructor Summary
SAXCatalogReader()
The constructor
SAXCatalogReader(SAXParserFactory parserFactory)
The constructor
SAXCatalogReader(String parserClass)
The constructor
Method Summary
voidcharacters(char[] ch, int start, int length)

The SAX characters method.

voidendDocument()

The SAX endDocument method.

voidendElement(String name)

The SAX endElement method.

voidendElement(String namespaceURI, String localName, String qName)

The SAX2 endElement method.

voidendPrefixMapping(String prefix)

The SAX endPrefixMapping method.

StringgetCatalogParser(String namespaceURI, String rootElement)
Get the SAXCatalogParser class for the given namespace/root element type.
StringgetParserClass()
Get the parser class currently in use.
SAXParserFactorygetParserFactory()
Get the parser factory currently in use.
voidignorableWhitespace(char[] ch, int start, int length)

The SAX ignorableWhitespace method.

voidprocessingInstruction(String target, String data)

The SAX processingInstruction method.

voidreadCatalog(Catalog catalog, String fileUrl)

Parse an XML Catalog file.

voidreadCatalog(Catalog catalog, InputStream is)

Parse an XML Catalog stream.

voidsetCatalogParser(String namespaceURI, String rootElement, String parserClass)
Set the SAXCatalogParser class for the given namespace/root element type.
voidsetDocumentLocator(Locator locator)

The SAX setDocumentLocator method.

voidsetParserClass(String parserClass)
Set the XML SAX Parser Class
voidsetParserFactory(SAXParserFactory parserFactory)
Set the XML SAX Parser Factory.
voidskippedEntity(String name)

The SAX skippedentity method.

voidstartDocument()

The SAX startDocument method.

voidstartElement(String name, AttributeList atts)

The SAX startElement method.

The catalog parser is selected based on the namespace of the first element encountered in the catalog.

voidstartElement(String namespaceURI, String localName, String qName, Attributes atts)

The SAX2 startElement method.

The catalog parser is selected based on the namespace of the first element encountered in the catalog.

voidstartPrefixMapping(String prefix, String uri)

The SAX startPrefixMapping method.

Field Detail

namespaceMap

protected Hashtable namespaceMap

Mapping table from QNames to CatalogParser classes.

Each key in this hash table has the form "elementname" or "{namespaceuri}elementname". The former is used if the namespace URI is null.

parserClass

protected String parserClass
The SAX Parser Class

parserFactory

protected SAXParserFactory parserFactory
The SAX Parser Factory

Constructor Detail

SAXCatalogReader

public SAXCatalogReader()
The constructor

SAXCatalogReader

public SAXCatalogReader(SAXParserFactory parserFactory)
The constructor

SAXCatalogReader

public SAXCatalogReader(String parserClass)
The constructor

Method Detail

characters

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

The SAX characters method. Does nothing.

endDocument

public void endDocument()

The SAX endDocument method. Does nothing.

endElement

public void endElement(String name)

The SAX endElement method. Does nothing.

endElement

public void endElement(String namespaceURI, String localName, String qName)

The SAX2 endElement method. Does nothing.

endPrefixMapping

public void endPrefixMapping(String prefix)

The SAX endPrefixMapping method. Does nothing.

getCatalogParser

public String getCatalogParser(String namespaceURI, String rootElement)
Get the SAXCatalogParser class for the given namespace/root element type.

getParserClass

public String getParserClass()
Get the parser class currently in use.

getParserFactory

public SAXParserFactory getParserFactory()
Get the parser factory currently in use.

ignorableWhitespace

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

The SAX ignorableWhitespace method. Does nothing.

processingInstruction

public void processingInstruction(String target, String data)

The SAX processingInstruction method. Does nothing.

readCatalog

public void readCatalog(Catalog catalog, String fileUrl)

Parse an XML Catalog file.

Parameters: catalog The catalog to which this catalog file belongs fileUrl The URL or filename of the catalog file to process

Throws: MalformedURLException Improper fileUrl IOException Error reading catalog file

readCatalog

public void readCatalog(Catalog catalog, InputStream is)

Parse an XML Catalog stream.

Parameters: catalog The catalog to which this catalog file belongs is The input stream from which the catalog will be read

Throws: MalformedURLException Improper fileUrl IOException Error reading catalog file CatalogException A Catalog exception

setCatalogParser

public void setCatalogParser(String namespaceURI, String rootElement, String parserClass)
Set the SAXCatalogParser class for the given namespace/root element type.

setDocumentLocator

public void setDocumentLocator(Locator locator)

The SAX setDocumentLocator method. Does nothing.

setParserClass

public void setParserClass(String parserClass)
Set the XML SAX Parser Class

setParserFactory

public void setParserFactory(SAXParserFactory parserFactory)
Set the XML SAX Parser Factory.

skippedEntity

public void skippedEntity(String name)

The SAX skippedentity method. Does nothing.

startDocument

public void startDocument()

The SAX startDocument method. Does nothing.

startElement

public void startElement(String name, AttributeList atts)

The SAX startElement method.

The catalog parser is selected based on the namespace of the first element encountered in the catalog.

startElement

public void startElement(String namespaceURI, String localName, String qName, Attributes atts)

The SAX2 startElement method.

The catalog parser is selected based on the namespace of the first element encountered in the catalog.

startPrefixMapping

public void startPrefixMapping(String prefix, String uri)

The SAX startPrefixMapping method. Does nothing.

Copyright B) 2001 Apache. All Rights Reserved.