org.jboss.util.xml.catalog.readers
Class SAXCatalogReader

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

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, DOMCatalogParser

Field Summary
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 Summary
SAXCatalogReader()
          The constructor
SAXCatalogReader(SAXParserFactory parserFactory)
          The constructor
SAXCatalogReader(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(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()
          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(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parserFactory

protected SAXParserFactory parserFactory
The SAX Parser Factory


parserClass

protected String parserClass
The SAX Parser Class


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.


debug

protected Debug debug
The debug class to use for this reader. This is a bit of a hack. Anyway, whenever we read for a catalog, we extract the debug object from the catalog's manager so that we can use it to print messages. In production, we don't really expect any messages so it doesn't really matter. But it's still a bit of a hack.

Constructor Detail

SAXCatalogReader

public SAXCatalogReader()
The constructor


SAXCatalogReader

public SAXCatalogReader(SAXParserFactory parserFactory)
The constructor


SAXCatalogReader

public SAXCatalogReader(String parserClass)
The constructor

Method Detail

setParserFactory

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


setParserClass

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


getParserFactory

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


getParserClass

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


setCatalogParser

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


getCatalogParser

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


readCatalog

public void readCatalog(Catalog catalog,
                        String fileUrl)
                 throws MalformedURLException,
                        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:
MalformedURLException - Improper fileUrl
IOException - Error reading catalog file
CatalogException

readCatalog

public void readCatalog(Catalog catalog,
                        InputStream is)
                 throws 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:
MalformedURLException - Improper fileUrl
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

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

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

startElement

public void startElement(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
Throws:
SAXException

startElement

public void startElement(String namespaceURI,
                         String localName,
                         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
Throws:
SAXException

endElement

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

Specified by:
endElement in interface DocumentHandler
Throws:
SAXException

endElement

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

Specified by:
endElement in interface ContentHandler
Throws:
SAXException

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
Throws:
SAXException

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
Throws:
SAXException

processingInstruction

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

Specified by:
processingInstruction in interface ContentHandler
Specified by:
processingInstruction in interface DocumentHandler
Throws:
SAXException

startPrefixMapping

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

Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException

endPrefixMapping

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

Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException

skippedEntity

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

Specified by:
skippedEntity in interface ContentHandler
Throws:
SAXException


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.