org.apache.xml.resolver.tools
Class ResolvingXMLFilter

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by org.apache.xml.resolver.tools.ResolvingXMLFilter
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, XMLFilter, XMLReader
Direct Known Subclasses:
ResolvingXMLReader

public class ResolvingXMLFilter
extends XMLFilterImpl

A SAX XMLFilter that performs catalog-based entity resolution.

This class implements a SAX XMLFilter that performs entity resolution using the CatalogResolver. The actual, underlying parser is obtained from a SAXParserFactory.

Version:
1.0
Author:
Norman Walsh Norman.Walsh@Sun.COM
See Also:
CatalogResolver, XMLFilter

Field Summary
static boolean suppressExplanation
          Suppress explanatory message?
 
Constructor Summary
ResolvingXMLFilter()
          Construct an empty XML Filter with no parent.
ResolvingXMLFilter(CatalogManager manager)
          Construct an XML filter with the specified parent.
ResolvingXMLFilter(XMLReader parent)
          Construct an XML filter with the specified parent.
ResolvingXMLFilter(XMLReader parent, CatalogManager manager)
          Construct an XML filter with the specified parent.
 
Method Summary
 Catalog getCatalog()
          Provide accessto the underlying Catalog.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          SAX DTDHandler API.
 void parse(InputSource input)
          SAX XMLReader API.
 void parse(java.lang.String systemId)
          SAX XMLReader API.
 void processingInstruction(java.lang.String target, java.lang.String pidata)
          SAX ContentHandler API.
 InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Implements the resolveEntity method for the SAX interface, using an underlying CatalogResolver to do the real work.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes atts)
          SAX ContentHandler API.
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          SAX DTDHandler API.
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, endDocument, endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startPrefixMapping, warning
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

suppressExplanation

public static boolean suppressExplanation
Suppress explanatory message?

See Also:
parse(InputSource)
Constructor Detail

ResolvingXMLFilter

public ResolvingXMLFilter()
Construct an empty XML Filter with no parent.


ResolvingXMLFilter

public ResolvingXMLFilter(XMLReader parent)
Construct an XML filter with the specified parent.


ResolvingXMLFilter

public ResolvingXMLFilter(CatalogManager manager)
Construct an XML filter with the specified parent.


ResolvingXMLFilter

public ResolvingXMLFilter(XMLReader parent,
                          CatalogManager manager)
Construct an XML filter with the specified parent.

Method Detail

getCatalog

public Catalog getCatalog()
Provide accessto the underlying Catalog.


parse

public void parse(InputSource input)
           throws java.io.IOException,
                  SAXException
SAX XMLReader API.

Note that the JAXP 1.1ea2 parser crashes with an InternalError if it encounters a system identifier that appears to be a relative URI that begins with a slash. For example, the declaration:

 <!DOCTYPE book SYSTEM "/path/to/dtd/on/my/system/docbookx.dtd">
 

would cause such an error. As a convenience, this method catches that error and prints an explanation. (Unfortunately, it's not possible to identify the particular system identifier that causes the problem.)

The underlying error is forwarded after printing the explanatory message. The message is only every printed once and if suppressExplanation is set to false before parsing, it will never be printed.

Specified by:
parse in interface XMLReader
Overrides:
parse in class XMLFilterImpl
Parameters:
input - The input source for the document entity.
Throws:
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
InputSource, XMLReader.parse(java.lang.String), XMLReader.setEntityResolver(org.xml.sax.EntityResolver), XMLReader.setDTDHandler(org.xml.sax.DTDHandler), XMLReader.setContentHandler(org.xml.sax.ContentHandler), XMLReader.setErrorHandler(org.xml.sax.ErrorHandler)

parse

public void parse(java.lang.String systemId)
           throws java.io.IOException,
                  SAXException
SAX XMLReader API.

Specified by:
parse in interface XMLReader
Overrides:
parse in class XMLFilterImpl
Parameters:
systemId - The system identifier as a fully-qualified URI.
Throws:
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
parse(InputSource)

resolveEntity

public InputSource resolveEntity(java.lang.String publicId,
                                 java.lang.String systemId)
Implements the resolveEntity method for the SAX interface, using an underlying CatalogResolver to do the real work.

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class XMLFilterImpl
Parameters:
publicId - The entity's public identifier, or null.
systemId - The entity's system identifier.
Returns:
A new InputSource or null for the default.
See Also:
InputSource

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws SAXException
SAX DTDHandler API.

Captured here only to detect the end of the prolog so that we can ignore subsequent oasis-xml-catalog PIs. Otherwise the events are just passed through.

Specified by:
notationDecl in interface DTDHandler
Overrides:
notationDecl in class XMLFilterImpl
Parameters:
name - The notation name.
publicId - The notation's public identifier, or null.
systemId - The notation's system identifier, or null.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String), Attributes

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws SAXException
SAX DTDHandler API.

Captured here only to detect the end of the prolog so that we can ignore subsequent oasis-xml-catalog PIs. Otherwise the events are just passed through.

Specified by:
unparsedEntityDecl in interface DTDHandler
Overrides:
unparsedEntityDecl in class XMLFilterImpl
Parameters:
name - The entity name.
publicId - The entity's public identifier, or null.
systemId - The entity's system identifier, or null.
notationName - The name of the associated notation.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String), Attributes

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         Attributes atts)
                  throws SAXException
SAX ContentHandler API.

Captured here only to detect the end of the prolog so that we can ignore subsequent oasis-xml-catalog PIs. Otherwise the events are just passed through.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class XMLFilterImpl
Parameters:
uri - The element's Namespace URI, or the empty string.
localName - The element's local name, or the empty string.
qName - The element's qualified (prefixed) name, or the empty string.
atts - The element's attributes.
Throws:
SAXException - any SAX exception, possibly wrapping another exception
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String), Attributes, AttributesImpl

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String pidata)
                           throws SAXException
SAX ContentHandler API.

Detect and use the oasis-xml-catalog PI if it occurs.

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class XMLFilterImpl
Parameters:
target - The processing instruction target.
pidata - The text following the target.
Throws:
SAXException - any SAX exception, possibly wrapping another exception