Class SAXCatalogReader
- java.lang.Object
-
- org.apache.xml.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.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
Fields Modifier and Type Field Description protected Debug
debug
The debug class to use for this reader.protected java.util.Hashtable
namespaceMap
Mapping table from QNames to CatalogParser classes.protected java.lang.String
parserClass
The SAX Parser Classprotected javax.xml.parsers.SAXParserFactory
parserFactory
The SAX Parser Factory
-
Constructor Summary
Constructors Constructor Description SAXCatalogReader()
The constructorSAXCatalogReader(java.lang.String parserClass)
The constructorSAXCatalogReader(javax.xml.parsers.SAXParserFactory parserFactory)
The constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] ch, int start, int length)
The SAXcharacters
method.void
endDocument()
The SAXendDocument
method.void
endElement(java.lang.String name)
The SAXendElement
method.void
endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
The SAX2endElement
method.void
endPrefixMapping(java.lang.String prefix)
The SAXendPrefixMapping
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 SAXignorableWhitespace
method.void
processingInstruction(java.lang.String target, java.lang.String data)
The SAXprocessingInstruction
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(org.xml.sax.Locator locator)
The SAXsetDocumentLocator
method.void
setParserClass(java.lang.String parserClass)
Set the XML SAX Parser Classvoid
setParserFactory(javax.xml.parsers.SAXParserFactory parserFactory)
Set the XML SAX Parser Factory.void
skippedEntity(java.lang.String name)
The SAXskippedentity
method.void
startDocument()
The SAXstartDocument
method.void
startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
The SAX2startElement
method.void
startElement(java.lang.String name, org.xml.sax.AttributeList atts)
The SAXstartElement
method.void
startPrefixMapping(java.lang.String prefix, java.lang.String uri)
The SAXstartPrefixMapping
method.
-
-
-
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.
-
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.
-
-
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.
-
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 interfaceCatalogReader
- Parameters:
catalog
- The catalog to which this catalog file belongsfileUrl
- The URL or filename of the catalog file to process- Throws:
java.net.MalformedURLException
- Improper fileUrljava.io.IOException
- Error reading catalog fileCatalogException
-
readCatalog
public void readCatalog(Catalog catalog, java.io.InputStream is) throws java.io.IOException, CatalogException
Parse an XML Catalog stream.- Specified by:
readCatalog
in interfaceCatalogReader
- Parameters:
catalog
- The catalog to which this catalog file belongsis
- The input stream from which the catalog will be read- Throws:
java.net.MalformedURLException
- Improper fileUrljava.io.IOException
- Error reading catalog fileCatalogException
- A Catalog exception
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
The SAXsetDocumentLocator
method. Does nothing.- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.DocumentHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
The SAXstartDocument
method. Does nothing.- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Specified by:
startDocument
in interfaceorg.xml.sax.DocumentHandler
- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
The SAXendDocument
method. Does nothing.- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Specified by:
endDocument
in interfaceorg.xml.sax.DocumentHandler
- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String name, org.xml.sax.AttributeList atts) throws org.xml.sax.SAXException
The SAXstartElement
method.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElement
in interfaceorg.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 SAX2startElement
method.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String name) throws org.xml.sax.SAXException
The SAXendElement
method. Does nothing.- Specified by:
endElement
in interfaceorg.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 SAX2endElement
method. Does nothing.- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
The SAXcharacters
method. Does nothing.- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Specified by:
characters
in interfaceorg.xml.sax.DocumentHandler
- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
The SAXignorableWhitespace
method. Does nothing.- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.DocumentHandler
- Throws:
org.xml.sax.SAXException
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
The SAXprocessingInstruction
method. Does nothing.- Specified by:
processingInstruction
in interfaceorg.xml.sax.ContentHandler
- Specified by:
processingInstruction
in interfaceorg.xml.sax.DocumentHandler
- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
The SAXstartPrefixMapping
method. Does nothing.- Specified by:
startPrefixMapping
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
The SAXendPrefixMapping
method. Does nothing.- Specified by:
endPrefixMapping
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
The SAXskippedentity
method. Does nothing.- Specified by:
skippedEntity
in interfaceorg.xml.sax.ContentHandler
- Throws:
org.xml.sax.SAXException
-
-