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 DebugdebugThe debug class to use for this reader.protected java.util.HashtablenamespaceMapMapping table from QNames to CatalogParser classes.protected java.lang.StringparserClassThe SAX Parser Classprotected javax.xml.parsers.SAXParserFactoryparserFactoryThe 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 voidcharacters(char[] ch, int start, int length)The SAXcharactersmethod.voidendDocument()The SAXendDocumentmethod.voidendElement(java.lang.String name)The SAXendElementmethod.voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)The SAX2endElementmethod.voidendPrefixMapping(java.lang.String prefix)The SAXendPrefixMappingmethod.java.lang.StringgetCatalogParser(java.lang.String namespaceURI, java.lang.String rootElement)Get the SAXCatalogParser class for the given namespace/root element type.java.lang.StringgetParserClass()Get the parser class currently in use.javax.xml.parsers.SAXParserFactorygetParserFactory()Get the parser factory currently in use.voidignorableWhitespace(char[] ch, int start, int length)The SAXignorableWhitespacemethod.voidprocessingInstruction(java.lang.String target, java.lang.String data)The SAXprocessingInstructionmethod.voidreadCatalog(Catalog catalog, java.io.InputStream is)Parse an XML Catalog stream.voidreadCatalog(Catalog catalog, java.lang.String fileUrl)Parse an XML Catalog file.voidsetCatalogParser(java.lang.String namespaceURI, java.lang.String rootElement, java.lang.String parserClass)Set the SAXCatalogParser class for the given namespace/root element type.voidsetClassLoader(java.lang.ClassLoader loader)Set the class loader to use when loading class by reflection.voidsetDocumentLocator(org.xml.sax.Locator locator)The SAXsetDocumentLocatormethod.voidsetParserClass(java.lang.String parserClass)Set the XML SAX Parser ClassvoidsetParserFactory(javax.xml.parsers.SAXParserFactory parserFactory)Set the XML SAX Parser Factory.voidskippedEntity(java.lang.String name)The SAXskippedentitymethod.voidstartDocument()The SAXstartDocumentmethod.voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)The SAX2startElementmethod.voidstartElement(java.lang.String name, org.xml.sax.AttributeList atts)The SAXstartElementmethod.voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)The SAXstartPrefixMappingmethod.
-
-
-
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:
readCatalogin 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:
readCatalogin 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 SAXsetDocumentLocatormethod. Does nothing.- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.DocumentHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXExceptionThe SAXstartDocumentmethod. Does nothing.- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Specified by:
startDocumentin interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXExceptionThe SAXendDocumentmethod. Does nothing.- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Specified by:
endDocumentin 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.SAXExceptionThe SAXstartElementmethod.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElementin 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.SAXExceptionThe SAX2startElementmethod.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String name) throws org.xml.sax.SAXExceptionThe SAXendElementmethod. Does nothing.- Specified by:
endElementin 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.SAXExceptionThe SAX2endElementmethod. Does nothing.- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionThe SAXcharactersmethod. Does nothing.- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Specified by:
charactersin interfaceorg.xml.sax.DocumentHandler- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXExceptionThe SAXignorableWhitespacemethod. Does nothing.- Specified by:
ignorableWhitespacein interfaceorg.xml.sax.ContentHandler- Specified by:
ignorableWhitespacein 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.SAXExceptionThe SAXprocessingInstructionmethod. Does nothing.- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Specified by:
processingInstructionin 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.SAXExceptionThe SAXstartPrefixMappingmethod. Does nothing.- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXExceptionThe SAXendPrefixMappingmethod. Does nothing.- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
skippedEntity
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXExceptionThe SAXskippedentitymethod. Does nothing.- Specified by:
skippedEntityin interfaceorg.xml.sax.ContentHandler- Throws:
org.xml.sax.SAXException
-
-