org.apache.xml.resolver.readers
Class DOMCatalogReader

java.lang.Object
  extended by org.apache.xml.resolver.readers.DOMCatalogReader
All Implemented Interfaces:
CatalogReader

public class DOMCatalogReader
extends java.lang.Object
implements CatalogReader

A DOM-based CatalogReader.

This class is used to read XML Catalogs using the DOM. This reader has an advantage over the SAX-based reader that it can analyze the DOM tree rather than simply a series of SAX events. It has the disadvantage that it requires all of the code necessary to build and walk a DOM 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 DOMCatalogReader 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.

This class requires the Java API for XML Parsing.

Version:
1.0
Author:
Norman Walsh Norman.Walsh@Sun.COM
See Also:
Catalog, CatalogReader, SAXCatalogReader, TextCatalogReader, DOMCatalogParser

Constructor Summary
DOMCatalogReader()
          Null constructor; something for subclasses to call.
 
Method Summary
 java.lang.String getCatalogParser(java.lang.String namespaceURI, java.lang.String rootElement)
          Get the name of the parser class for a given catalog type.
 void readCatalog(Catalog catalog, java.io.InputStream is)
          Read a catalog from an input stream.
 void readCatalog(Catalog catalog, java.lang.String fileUrl)
          Read the catalog behind the specified URL.
 void setCatalogParser(java.lang.String namespaceURI, java.lang.String rootElement, java.lang.String parserClass)
          Add a new parser to the reader.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMCatalogReader

public DOMCatalogReader()
Null constructor; something for subclasses to call.

Method Detail

setCatalogParser

public void setCatalogParser(java.lang.String namespaceURI,
                             java.lang.String rootElement,
                             java.lang.String parserClass)
Add a new parser to the reader.

This method associates the specified parserClass with the namespaceURI/rootElement names specified.

Parameters:
namespaceURI - The namespace URI. Not the prefix.
rootElement - The name of the root element.
parserClass - The name of the parserClass to instantiate for this kind of catalog.

getCatalogParser

public java.lang.String getCatalogParser(java.lang.String namespaceURI,
                                         java.lang.String rootElement)
Get the name of the parser class for a given catalog type.

This method returns the parserClass associated with the namespaceURI/rootElement names specified.

Parameters:
namespaceURI - The namespace URI. Not the prefix.
rootElement - The name of the root element.
Returns:
The parser class.

readCatalog

public void readCatalog(Catalog catalog,
                        java.io.InputStream is)
                 throws java.io.IOException,
                        CatalogException
Read a catalog from an input stream.

This class reads a catalog from an input stream:

Specified by:
readCatalog in interface CatalogReader
Parameters:
catalog - The catalog for which this reader is called.
is - The input stream that is to be read.
Throws:
java.io.IOException - if the URL cannot be read.
UnknownCatalogFormatException - if the catalog format is not recognized.
UnparseableCatalogException - if the catalog cannot be parsed. (For example, if it is supposed to be XML and isn't well-formed or if the parser class cannot be instantiated.)
CatalogException

readCatalog

public void readCatalog(Catalog catalog,
                        java.lang.String fileUrl)
                 throws java.net.MalformedURLException,
                        java.io.IOException,
                        CatalogException
Read the catalog behind the specified URL.

Specified by:
readCatalog in interface CatalogReader
Parameters:
catalog - The catalog for which we are reading.
fileUrl - The URL of the document that should be read.
Throws:
java.net.MalformedURLException - if the specified URL cannot be turned into a URL object.
java.io.IOException - if the URL cannot be read.
UnknownCatalogFormatException - if the catalog format is not recognized.
UnparseableCatalogException - if the catalog cannot be parsed. (For example, if it is supposed to be XML and isn't well-formed.)
CatalogException
See Also:
readCatalog(Catalog, InputStream)