com.sun.resolver.readers
Class SAXCatalogReader

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

public class SAXCatalogReader
extends java.lang.Object
implements CatalogReader, org.xml.sax.ContentHandler, org.xml.sax.DocumentHandler

A SAX-based CatalogReader

Copyright © 2000, 2001 Sun Microsystems, Inc. All Rights Reserved. This software is the proprietary information of Sun Microsystems, Inc. Use is subject to license terms.

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

Field Summary
protected  java.util.Hashtable namespaceMap
          Mapping table from QNames to CatalogParser classes.
protected  java.lang.String parserClass
          The SAX Parser Class
protected  javax.xml.parsers.SAXParserFactory parserFactory
          The SAX Parser Factory
 
Constructor Summary
SAXCatalogReader()
          The constructor
SAXCatalogReader(javax.xml.parsers.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.
 javax.xml.parsers.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 setDocumentLocator(org.xml.sax.Locator locator)
          The SAX setDocumentLocator method.
 void setParserClass(java.lang.String parserClass)
          Set the XML SAX Parser Class
 void setParserFactory(javax.xml.parsers.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, org.xml.sax.AttributeList atts)
          The SAX startElement method.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parserFactory

protected javax.xml.parsers.SAXParserFactory parserFactory
The SAX Parser Factory


parserClass

protected java.lang.String parserClass
The SAX Parser Class


namespaceMap

protected java.util.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.

Constructor Detail

SAXCatalogReader

public SAXCatalogReader()
The constructor


SAXCatalogReader

public SAXCatalogReader(javax.xml.parsers.SAXParserFactory parserFactory)
The constructor


SAXCatalogReader

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

Method Detail

setParserFactory

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


setParserClass

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


getParserFactory

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


getParserClass

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


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(org.xml.sax.Locator locator)

The SAX setDocumentLocator method. Does nothing.

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException

The SAX startDocument method. Does nothing.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException

The SAX endDocument method. Does nothing.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String name,
                         org.xml.sax.AttributeList atts)
                  throws org.xml.sax.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 org.xml.sax.DocumentHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.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 org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String name)
                throws org.xml.sax.SAXException

The SAX endElement method. Does nothing.

Specified by:
endElement in interface org.xml.sax.DocumentHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException

The SAX2 endElement method. Does nothing.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException

The SAX characters method. Does nothing.

Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException

The SAX ignorableWhitespace method. Does nothing.

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException

The SAX processingInstruction method. Does nothing.

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException

The SAX startPrefixMapping method. Does nothing.

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException

The SAX endPrefixMapping method. Does nothing.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException

The SAX skippedentity method. Does nothing.

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException