org.apache.xml.resolver.readers
Class SAXCatalogReader

java.lang.Object
  extended by org.apache.xml.resolver.readers.SAXCatalogReader
All Implemented Interfaces:
CatalogReader, ContentHandler, DocumentHandler
Direct Known Subclasses:
OASISXMLCatalogReader, XCatalogReader

public class SAXCatalogReader
extends java.lang.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, DOMCatalogParser

Constructor Summary
SAXCatalogReader()
          The constructor
SAXCatalogReader(SAXParserFactory parserFactory)
          The constructor
SAXCatalogReader(java.lang.String parserClass)
          The constructor
 
Method Summary
 void characters(char[] ch, int start, int length)
          The SAX characters method.
 void endDocument()
          The SAX endDocument method.
 void endElement(java.lang.String name)
          The SAX endElement method.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          The SAX2 endElement method.
 void endPrefixMapping(java.lang.String prefix)
          The SAX endPrefixMapping method.
 java.lang.String getCatalogParser(java.lang.String namespaceURI, java.lang.String rootElement)
          Get the SAXCatalogParser class for the given namespace/root element type.
 java.lang.String getParserClass()
          Get the parser class currently in use.
 SAXParserFactory getParserFactory()
          Get the parser factory currently in use.
 void ignorableWhitespace(char[] ch, int start, int length)
          The SAX ignorableWhitespace method.
 void processingInstruction(java.lang.String target, java.lang.String data)
          The SAX processingInstruction method.
 void readCatalog(Catalog catalog, java.io.InputStream is)
          Parse an XML Catalog stream.
 void readCatalog(Catalog catalog, java.lang.String fileUrl)
          Parse an XML Catalog file.
 void setCatalogParser(java.lang.String namespaceURI, java.lang.String rootElement, java.lang.String parserClass)
          Set the SAXCatalogParser class for the given namespace/root element type.
 void setClassLoader(java.lang.ClassLoader loader)
          Set the class loader to use when loading class by reflection.
 void setDocumentLocator(Locator locator)
          The SAX setDocumentLocator method.
 void setParserClass(java.lang.String parserClass)
          Set the XML SAX Parser Class
 void setParserFactory(SAXParserFactory parserFactory)
          Set the XML SAX Parser Factory.
 void skippedEntity(java.lang.String name)
          The SAX skippedentity method.
 void startDocument()
          The SAX startDocument method.
 void startElement(java.lang.String name, AttributeList atts)
          The SAX startElement method.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, Attributes atts)
          The SAX2 startElement method.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          The SAX startPrefixMapping method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXCatalogReader

public SAXCatalogReader()
The constructor


SAXCatalogReader

public SAXCatalogReader(SAXParserFactory parserFactory)
The constructor


SAXCatalogReader

public SAXCatalogReader(java.lang.String parserClass)
The constructor

Method Detail

setParserFactory

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


setParserClass

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


getParserFactory

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


getParserClass

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


setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Set the class loader to use when loading class by reflection. If not set, the the class loader used to load this class is used.


setCatalogParser

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


getCatalogParser

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


readCatalog

public void readCatalog(Catalog catalog,
                        java.lang.String fileUrl)
                 throws java.net.MalformedURLException,
                        java.io.IOException,
                        CatalogException
Parse an XML Catalog file.

Specified by:
readCatalog in interface CatalogReader
Parameters:
catalog - The catalog to which this catalog file belongs
fileUrl - The URL or filename of the catalog file to process
Throws:
java.net.MalformedURLException - Improper fileUrl
java.io.IOException - Error reading catalog file
CatalogException

readCatalog

public void readCatalog(Catalog catalog,
                        java.io.InputStream is)
                 throws java.io.IOException,
                        CatalogException
Parse an XML Catalog stream.

Specified by:
readCatalog in interface CatalogReader
Parameters:
catalog - The catalog to which this catalog file belongs
is - The input stream from which the catalog will be read
Throws:
java.net.MalformedURLException - Improper fileUrl
java.io.IOException - Error reading catalog file
CatalogException - A Catalog exception

setDocumentLocator

public void setDocumentLocator(Locator locator)
The SAX setDocumentLocator method. Does nothing.

Specified by:
setDocumentLocator in interface ContentHandler
Specified by:
setDocumentLocator in interface DocumentHandler
Parameters:
locator - an object that can return the location of any SAX document event
See Also:
Locator

startDocument

public void startDocument()
                   throws SAXException
The SAX startDocument method. Does nothing.

Specified by:
startDocument in interface ContentHandler
Specified by:
startDocument in interface DocumentHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endDocument()

endDocument

public void endDocument()
                 throws SAXException
The SAX endDocument method. Does nothing.

Specified by:
endDocument in interface ContentHandler
Specified by:
endDocument in interface DocumentHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startDocument()

startElement

public void startElement(java.lang.String name,
                         AttributeList atts)
                  throws SAXException
The SAX startElement method.

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

Specified by:
startElement in interface DocumentHandler
Parameters:
name - The element type name.
atts - The attributes attached to the element, if any.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
DocumentHandler.endElement(java.lang.String), AttributeList

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         Attributes atts)
                  throws SAXException
The SAX2 startElement method.

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

Specified by:
startElement in interface ContentHandler
Parameters:
namespaceURI - the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
localName - the local name (without prefix), or the empty string if Namespace processing is not being performed
qName - the qualified name (with prefix), or the empty string if qualified names are not available
atts - the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined
Throws:
SAXException - any SAX exception, possibly wrapping another exception
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String), Attributes, AttributesImpl

endElement

public void endElement(java.lang.String name)
                throws SAXException
The SAX endElement method. Does nothing.

Specified by:
endElement in interface DocumentHandler
Parameters:
name - The element type name
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws SAXException
The SAX2 endElement method. Does nothing.

Specified by:
endElement in interface ContentHandler
Parameters:
namespaceURI - the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
localName - the local name (without prefix), or the empty string if Namespace processing is not being performed
qName - the qualified XML name (with prefix), or the empty string if qualified names are not available
Throws:
SAXException - any SAX exception, possibly wrapping another exception

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
The SAX characters method. Does nothing.

Specified by:
characters in interface ContentHandler
Specified by:
characters in interface DocumentHandler
Parameters:
ch - the characters from the XML document
start - the start position in the array
length - the number of characters to read from the array
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.ignorableWhitespace(char[], int, int), Locator

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
The SAX ignorableWhitespace method. Does nothing.

Specified by:
ignorableWhitespace in interface ContentHandler
Specified by:
ignorableWhitespace in interface DocumentHandler
Parameters:
ch - the characters from the XML document
start - the start position in the array
length - the number of characters to read from the array
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.characters(char[], int, int)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
The SAX processingInstruction method. Does nothing.

Specified by:
processingInstruction in interface ContentHandler
Specified by:
processingInstruction in interface DocumentHandler
Parameters:
target - the processing instruction target
data - the processing instruction data, or null if none was supplied. The data does not include any whitespace separating it from the target
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws SAXException
The SAX startPrefixMapping method. Does nothing.

Specified by:
startPrefixMapping in interface ContentHandler
Parameters:
prefix - the Namespace prefix being declared. An empty string is used for the default element namespace, which has no prefix.
uri - the Namespace URI the prefix is mapped to
Throws:
SAXException - the client may throw an exception during processing
See Also:
ContentHandler.endPrefixMapping(java.lang.String), ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws SAXException
The SAX endPrefixMapping method. Does nothing.

Specified by:
endPrefixMapping in interface ContentHandler
Parameters:
prefix - the prefix that was being mapped. This is the empty string when a default mapping scope ends.
Throws:
SAXException - the client may throw an exception during processing
See Also:
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String), ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws SAXException
The SAX skippedentity method. Does nothing.

Specified by:
skippedEntity in interface ContentHandler
Parameters:
name - the name of the skipped entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be the string "[dtd]"
Throws:
SAXException - any SAX exception, possibly wrapping another exception