Class SAXCatalogReader
- All Implemented Interfaces:
CatalogReader
,ContentHandler
,DocumentHandler
- Direct Known Subclasses:
OASISXMLCatalogReader
,XCatalogReader
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Debug
The debug class to use for this reader.protected Hashtable
Mapping table from QNames to CatalogParser classes.protected String
The SAX Parser Classprotected SAXParserFactory
The SAX Parser Factory -
Constructor Summary
ConstructorsConstructorDescriptionThe constructorSAXCatalogReader
(String parserClass) The constructorSAXCatalogReader
(SAXParserFactory parserFactory) The constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) The SAXcharacters
method.void
The SAXendDocument
method.void
endElement
(String name) The SAXendElement
method.void
endElement
(String namespaceURI, String localName, String qName) The SAX2endElement
method.void
endPrefixMapping
(String prefix) The SAXendPrefixMapping
method.getCatalogParser
(String namespaceURI, String rootElement) Get the SAXCatalogParser class for the given namespace/root element type.Get the parser class currently in use.Get the parser factory currently in use.void
ignorableWhitespace
(char[] ch, int start, int length) The SAXignorableWhitespace
method.void
processingInstruction
(String target, String data) The SAXprocessingInstruction
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
setClassLoader
(ClassLoader loader) Set the class loader to use when loading class by reflection.void
setDocumentLocator
(Locator locator) The SAXsetDocumentLocator
method.void
setParserClass
(String parserClass) Set the XML SAX Parser Classvoid
setParserFactory
(SAXParserFactory parserFactory) Set the XML SAX Parser Factory.void
skippedEntity
(String name) The SAXskippedentity
method.void
The SAXstartDocument
method.void
startElement
(String namespaceURI, String localName, String qName, Attributes atts) The SAX2startElement
method.void
startElement
(String name, AttributeList atts) The SAXstartElement
method.void
startPrefixMapping
(String prefix, String uri) The SAXstartPrefixMapping
method.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
parserFactory
The SAX Parser Factory -
parserClass
The SAX Parser Class -
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
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 Details
-
SAXCatalogReader
public SAXCatalogReader()The constructor -
SAXCatalogReader
The constructor -
SAXCatalogReader
The constructor
-
-
Method Details
-
setParserFactory
Set the XML SAX Parser Factory. -
setParserClass
Set the XML SAX Parser Class -
getParserFactory
Get the parser factory currently in use. -
getParserClass
Get the parser class currently in use. -
setClassLoader
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
Set the SAXCatalogParser class for the given namespace/root element type. -
getCatalogParser
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 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
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:
MalformedURLException
- Improper fileUrlIOException
- Error reading catalog fileCatalogException
- A Catalog exception
-
setDocumentLocator
The SAXsetDocumentLocator
method. Does nothing.- Specified by:
setDocumentLocator
in interfaceContentHandler
- Specified by:
setDocumentLocator
in interfaceDocumentHandler
-
startDocument
The SAXstartDocument
method. Does nothing.- Specified by:
startDocument
in interfaceContentHandler
- Specified by:
startDocument
in interfaceDocumentHandler
- Throws:
SAXException
-
endDocument
The SAXendDocument
method. Does nothing.- Specified by:
endDocument
in interfaceContentHandler
- Specified by:
endDocument
in interfaceDocumentHandler
- Throws:
SAXException
-
startElement
The SAXstartElement
method.The catalog parser is selected based on the namespace of the first element encountered in the catalog.
- Specified by:
startElement
in interfaceDocumentHandler
- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws 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 interfaceContentHandler
- Throws:
SAXException
-
endElement
The SAXendElement
method. Does nothing.- Specified by:
endElement
in interfaceDocumentHandler
- Throws:
SAXException
-
endElement
The SAX2endElement
method. Does nothing.- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
characters
The SAXcharacters
method. Does nothing.- Specified by:
characters
in interfaceContentHandler
- Specified by:
characters
in interfaceDocumentHandler
- Throws:
SAXException
-
ignorableWhitespace
The SAXignorableWhitespace
method. Does nothing.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Specified by:
ignorableWhitespace
in interfaceDocumentHandler
- Throws:
SAXException
-
processingInstruction
The SAXprocessingInstruction
method. Does nothing.- Specified by:
processingInstruction
in interfaceContentHandler
- Specified by:
processingInstruction
in interfaceDocumentHandler
- Throws:
SAXException
-
startPrefixMapping
The SAXstartPrefixMapping
method. Does nothing.- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
The SAXendPrefixMapping
method. Does nothing.- Specified by:
endPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
skippedEntity
The SAXskippedentity
method. Does nothing.- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-