Class SAXCatalogReader
- java.lang.Object
-
- com.sun.org.apache.xml.internal.resolver.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
Fields Modifier and Type Field Description protected DebugdebugThe debug class to use for this reader.protected HashtablenamespaceMapMapping table from QNames to CatalogParser classes.protected StringparserClassThe SAX Parser Classprotected SAXParserFactoryparserFactoryThe SAX Parser Factory
-
Constructor Summary
Constructors Constructor Description SAXCatalogReader()The constructorSAXCatalogReader(String parserClass)The constructorSAXCatalogReader(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(String name)The SAXendElementmethod.voidendElement(String namespaceURI, String localName, String qName)The SAX2endElementmethod.voidendPrefixMapping(String prefix)The SAXendPrefixMappingmethod.StringgetCatalogParser(String namespaceURI, String rootElement)Get the SAXCatalogParser class for the given namespace/root element type.StringgetParserClass()Get the parser class currently in use.SAXParserFactorygetParserFactory()Get the parser factory currently in use.voidignorableWhitespace(char[] ch, int start, int length)The SAXignorableWhitespacemethod.voidprocessingInstruction(String target, String data)The SAXprocessingInstructionmethod.voidreadCatalog(Catalog catalog, InputStream is)Parse an XML Catalog stream.voidreadCatalog(Catalog catalog, String fileUrl)Parse an XML Catalog file.voidsetCatalogParser(String namespaceURI, String rootElement, String parserClass)Set the SAXCatalogParser class for the given namespace/root element type.voidsetDocumentLocator(Locator locator)The SAXsetDocumentLocatormethod.voidsetParserClass(String parserClass)Set the XML SAX Parser ClassvoidsetParserFactory(SAXParserFactory parserFactory)Set the XML SAX Parser Factory.voidskippedEntity(String name)The SAXskippedentitymethod.voidstartDocument()The SAXstartDocumentmethod.voidstartElement(String namespaceURI, String localName, String qName, Attributes atts)The SAX2startElementmethod.voidstartElement(String name, AttributeList atts)The SAXstartElementmethod.voidstartPrefixMapping(String prefix, String uri)The SAXstartPrefixMappingmethod.
-
-
-
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:
readCatalogin interfaceCatalogReader- Parameters:
catalog- The catalog to which this catalog file belongsfileUrl- The URL or filename of the catalog file to process- Throws:
MalformedURLException- Improper fileUrlIOException- Error reading catalog fileCatalogException
-
readCatalog
public void readCatalog(Catalog catalog, InputStream is) throws 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:
MalformedURLException- Improper fileUrlIOException- Error reading catalog fileCatalogException- A Catalog exception
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
The SAXsetDocumentLocatormethod. Does nothing.- Specified by:
setDocumentLocatorin interfaceContentHandler- Specified by:
setDocumentLocatorin interfaceDocumentHandler
-
startDocument
public void startDocument() throws SAXExceptionThe SAXstartDocumentmethod. Does nothing.- Specified by:
startDocumentin interfaceContentHandler- Specified by:
startDocumentin interfaceDocumentHandler- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXExceptionThe SAXendDocumentmethod. Does nothing.- Specified by:
endDocumentin interfaceContentHandler- Specified by:
endDocumentin interfaceDocumentHandler- Throws:
SAXException
-
startElement
public void startElement(String name, AttributeList atts) throws SAXException
The SAXstartElementmethod.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElementin interfaceDocumentHandler- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
The SAX2startElementmethod.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElementin interfaceContentHandler- Throws:
SAXException
-
endElement
public void endElement(String name) throws SAXException
The SAXendElementmethod. Does nothing.- Specified by:
endElementin interfaceDocumentHandler- Throws:
SAXException
-
endElement
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
The SAX2endElementmethod. Does nothing.- Specified by:
endElementin interfaceContentHandler- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXExceptionThe SAXcharactersmethod. Does nothing.- Specified by:
charactersin interfaceContentHandler- Specified by:
charactersin interfaceDocumentHandler- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXExceptionThe SAXignorableWhitespacemethod. Does nothing.- Specified by:
ignorableWhitespacein interfaceContentHandler- Specified by:
ignorableWhitespacein interfaceDocumentHandler- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
The SAXprocessingInstructionmethod. Does nothing.- Specified by:
processingInstructionin interfaceContentHandler- Specified by:
processingInstructionin interfaceDocumentHandler- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
The SAXstartPrefixMappingmethod. Does nothing.- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
The SAXendPrefixMappingmethod. Does nothing.- Specified by:
endPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
The SAXskippedentitymethod. Does nothing.- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
-