+++ /dev/null
-// XMLFilterImpl.java - base SAX2 filter implementation.\r
-// Written by David Megginson, sax@megginson.com\r
-// NO WARRANTY! This class is in the Public Domain.\r
-\r
-// $Id: XMLFilterImpl.java,v 1.1 2000/10/02 02:43:20 sboag Exp $\r
-\r
-package org.xml.sax.helpers;\r
-\r
-import java.io.IOException;\r
-\r
-import org.xml.sax.XMLReader;\r
-import org.xml.sax.XMLFilter;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.Locator;\r
-import org.xml.sax.Attributes;\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.DTDHandler;\r
-import org.xml.sax.ContentHandler;\r
-import org.xml.sax.ErrorHandler;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXParseException;\r
-import org.xml.sax.SAXNotSupportedException;\r
-import org.xml.sax.SAXNotRecognizedException;\r
-\r
-\r
-/**\r
- * Base class for deriving an XML filter.\r
- *\r
- * <blockquote>\r
- * <em>This module, both source code and documentation, is in the\r
- * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>\r
- * </blockquote>\r
- *\r
- * <p>This class is designed to sit between an {@link org.xml.sax.XMLReader\r
- * XMLReader} and the client application's event handlers. By default, it\r
- * does nothing but pass requests up to the reader and events\r
- * on to the handlers unmodified, but subclasses can override\r
- * specific methods to modify the event stream or the configuration\r
- * requests as they pass through.</p>\r
- *\r
- * @since SAX 2.0\r
- * @author David Megginson, \r
- * <a href="mailto:sax@megginson.com">sax@megginson.com</a>\r
- * @version 2.0\r
- * @see org.xml.sax.XMLFilter\r
- * @see org.xml.sax.XMLReader\r
- * @see org.xml.sax.EntityResolver\r
- * @see org.xml.sax.DTDHandler\r
- * @see org.xml.sax.ContentHandler\r
- * @see org.xml.sax.ErrorHandler\r
- */\r
-public class XMLFilterImpl\r
- implements XMLFilter, EntityResolver, DTDHandler, ContentHandler, ErrorHandler\r
-{\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Constructors.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Construct an empty XML filter, with no parent.\r
- *\r
- * <p>This filter will have no parent: you must assign a parent\r
- * before you start a parse or do any configuration with\r
- * setFeature or setProperty.</p>\r
- *\r
- * @see org.xml.sax.XMLReader#setFeature\r
- * @see org.xml.sax.XMLReader#setProperty\r
- */\r
- public XMLFilterImpl ()\r
- {\r
- super();\r
- }\r
-\r
-\r
- /**\r
- * Construct an XML filter with the specified parent.\r
- *\r
- * @see #setParent\r
- * @see #getParent\r
- */\r
- public XMLFilterImpl (XMLReader parent)\r
- {\r
- super();\r
- setParent(parent);\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.XMLFilter.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Set the parent reader.\r
- *\r
- * <p>This is the {@link org.xml.sax.XMLReader XMLReader} from which \r
- * this filter will obtain its events and to which it will pass its \r
- * configuration requests. The parent may itself be another filter.</p>\r
- *\r
- * <p>If there is no parent reader set, any attempt to parse\r
- * or to set or get a feature or property will fail.</p>\r
- *\r
- * @param parent The parent XML reader.\r
- * @exception java.lang.NullPointerException If the parent is null.\r
- * @see #getParent\r
- */\r
- public void setParent (XMLReader parent)\r
- {\r
- if (parent == null) {\r
- throw new NullPointerException("Null parent");\r
- }\r
- this.parent = parent;\r
- }\r
-\r
-\r
- /**\r
- * Get the parent reader.\r
- *\r
- * @return The parent XML reader, or null if none is set.\r
- * @see #setParent\r
- */\r
- public XMLReader getParent ()\r
- {\r
- return parent;\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.XMLReader.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Set the state of a feature.\r
- *\r
- * <p>This will always fail if the parent is null.</p>\r
- *\r
- * @param name The feature name.\r
- * @param state The requested feature state.\r
- * @exception org.xml.sax.SAXNotRecognizedException When the\r
- * XMLReader does not recognize the feature name.\r
- * @exception org.xml.sax.SAXNotSupportedException When the\r
- * XMLReader recognizes the feature name but \r
- * cannot set the requested value.\r
- * @see org.xml.sax.XMLReader#setFeature\r
- */\r
- public void setFeature (String name, boolean state)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- if (parent != null) {\r
- parent.setFeature(name, state);\r
- } else {\r
- throw new SAXNotRecognizedException("Feature: " + name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Look up the state of a feature.\r
- *\r
- * <p>This will always fail if the parent is null.</p>\r
- *\r
- * @param name The feature name.\r
- * @return The current state of the feature.\r
- * @exception org.xml.sax.SAXNotRecognizedException When the\r
- * XMLReader does not recognize the feature name.\r
- * @exception org.xml.sax.SAXNotSupportedException When the\r
- * XMLReader recognizes the feature name but \r
- * cannot determine its state at this time.\r
- * @see org.xml.sax.XMLReader#getFeature\r
- */\r
- public boolean getFeature (String name)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- if (parent != null) {\r
- return parent.getFeature(name);\r
- } else {\r
- throw new SAXNotRecognizedException("Feature: " + name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Set the value of a property.\r
- *\r
- * <p>This will always fail if the parent is null.</p>\r
- *\r
- * @param name The property name.\r
- * @param state The requested property value.\r
- * @exception org.xml.sax.SAXNotRecognizedException When the\r
- * XMLReader does not recognize the property name.\r
- * @exception org.xml.sax.SAXNotSupportedException When the\r
- * XMLReader recognizes the property name but \r
- * cannot set the requested value.\r
- * @see org.xml.sax.XMLReader#setProperty\r
- */\r
- public void setProperty (String name, Object value)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- if (parent != null) {\r
- parent.setProperty(name, value);\r
- } else {\r
- throw new SAXNotRecognizedException("Property: " + name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Look up the value of a property.\r
- *\r
- * @param name The property name.\r
- * @return The current value of the property.\r
- * @exception org.xml.sax.SAXNotRecognizedException When the\r
- * XMLReader does not recognize the feature name.\r
- * @exception org.xml.sax.SAXNotSupportedException When the\r
- * XMLReader recognizes the property name but \r
- * cannot determine its value at this time.\r
- * @see org.xml.sax.XMLReader#setFeature\r
- */\r
- public Object getProperty (String name)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- if (parent != null) {\r
- return parent.getProperty(name);\r
- } else {\r
- throw new SAXNotRecognizedException("Property: " + name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Set the entity resolver.\r
- *\r
- * @param resolver The new entity resolver.\r
- * @exception java.lang.NullPointerException If the resolver\r
- * is null.\r
- * @see org.xml.sax.XMLReader#setEntityResolver\r
- */\r
- public void setEntityResolver (EntityResolver resolver)\r
- {\r
- if (resolver == null) {\r
- throw new NullPointerException("Null entity resolver");\r
- } else {\r
- entityResolver = resolver;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the current entity resolver.\r
- *\r
- * @return The current entity resolver, or null if none was set.\r
- * @see org.xml.sax.XMLReader#getEntityResolver\r
- */\r
- public EntityResolver getEntityResolver ()\r
- {\r
- return entityResolver;\r
- }\r
-\r
-\r
- /**\r
- * Set the DTD event handler.\r
- *\r
- * @param resolver The new DTD handler.\r
- * @exception java.lang.NullPointerException If the handler\r
- * is null.\r
- * @see org.xml.sax.XMLReader#setDTDHandler\r
- */\r
- public void setDTDHandler (DTDHandler handler)\r
- {\r
- if (handler == null) {\r
- throw new NullPointerException("Null DTD handler");\r
- } else {\r
- dtdHandler = handler;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the current DTD event handler.\r
- *\r
- * @return The current DTD handler, or null if none was set.\r
- * @see org.xml.sax.XMLReader#getDTDHandler\r
- */\r
- public DTDHandler getDTDHandler ()\r
- {\r
- return dtdHandler;\r
- }\r
-\r
-\r
- /**\r
- * Set the content event handler.\r
- *\r
- * @param resolver The new content handler.\r
- * @exception java.lang.NullPointerException If the handler\r
- * is null.\r
- * @see org.xml.sax.XMLReader#setContentHandler\r
- */\r
- public void setContentHandler (ContentHandler handler)\r
- {\r
- if (handler == null) {\r
- throw new NullPointerException("Null content handler");\r
- } else {\r
- contentHandler = handler;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the content event handler.\r
- *\r
- * @return The current content handler, or null if none was set.\r
- * @see org.xml.sax.XMLReader#getContentHandler\r
- */\r
- public ContentHandler getContentHandler ()\r
- {\r
- return contentHandler;\r
- }\r
-\r
-\r
- /**\r
- * Set the error event handler.\r
- *\r
- * @param handle The new error handler.\r
- * @exception java.lang.NullPointerException If the handler\r
- * is null.\r
- * @see org.xml.sax.XMLReader#setErrorHandler\r
- */\r
- public void setErrorHandler (ErrorHandler handler)\r
- {\r
- if (handler == null) {\r
- throw new NullPointerException("Null error handler");\r
- } else {\r
- errorHandler = handler;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the current error event handler.\r
- *\r
- * @return The current error handler, or null if none was set.\r
- * @see org.xml.sax.XMLReader#getErrorHandler\r
- */\r
- public ErrorHandler getErrorHandler ()\r
- {\r
- return errorHandler;\r
- }\r
-\r
-\r
- /**\r
- * Parse a document.\r
- *\r
- * @param input The input source for the document entity.\r
- * @exception org.xml.sax.SAXException Any SAX exception, possibly\r
- * wrapping another exception.\r
- * @exception java.io.IOException An IO exception from the parser,\r
- * possibly from a byte stream or character stream\r
- * supplied by the application.\r
- * @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)\r
- */\r
- public void parse (InputSource input)\r
- throws SAXException, IOException\r
- {\r
- setupParse();\r
- parent.parse(input);\r
- }\r
-\r
-\r
- /**\r
- * Parse a document.\r
- *\r
- * @param systemId The system identifier as a fully-qualified URI.\r
- * @exception org.xml.sax.SAXException Any SAX exception, possibly\r
- * wrapping another exception.\r
- * @exception java.io.IOException An IO exception from the parser,\r
- * possibly from a byte stream or character stream\r
- * supplied by the application.\r
- * @see org.xml.sax.XMLReader#parse(java.lang.String)\r
- */\r
- public void parse (String systemId)\r
- throws SAXException, IOException\r
- {\r
- parse(new InputSource(systemId));\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.EntityResolver.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Filter an external entity resolution.\r
- *\r
- * @param publicId The entity's public identifier, or null.\r
- * @param systemId The entity's system identifier.\r
- * @return A new InputSource or null for the default.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @exception java.io.IOException The client may throw an\r
- * I/O-related exception while obtaining the\r
- * new InputSource.\r
- * @see org.xml.sax.EntityResolver#resolveEntity\r
- */\r
- public InputSource resolveEntity (String publicId, String systemId)\r
- throws SAXException, IOException\r
- {\r
- if (entityResolver != null) {\r
- return entityResolver.resolveEntity(publicId, systemId);\r
- } else {\r
- return null;\r
- }\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.DTDHandler.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
- \r
- /**\r
- * Filter a notation declaration event.\r
- *\r
- * @param name The notation name.\r
- * @param publicId The notation's public identifier, or null.\r
- * @param systemId The notation's system identifier, or null.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.DTDHandler#notationDecl\r
- */\r
- public void notationDecl (String name, String publicId, String systemId)\r
- throws SAXException\r
- {\r
- if (dtdHandler != null) {\r
- dtdHandler.notationDecl(name, publicId, systemId);\r
- }\r
- }\r
-\r
- \r
- /**\r
- * Filter an unparsed entity declaration event.\r
- *\r
- * @param name The entity name.\r
- * @param publicId The entity's public identifier, or null.\r
- * @param systemId The entity's system identifier, or null.\r
- * @param notationName The name of the associated notation.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.DTDHandler#unparsedEntityDecl\r
- */\r
- public void unparsedEntityDecl (String name, String publicId,\r
- String systemId, String notationName)\r
- throws SAXException\r
- {\r
- if (dtdHandler != null) {\r
- dtdHandler.unparsedEntityDecl(name, publicId, systemId,\r
- notationName);\r
- }\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.ContentHandler.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Filter a new document locator event.\r
- *\r
- * @param locator The document locator.\r
- * @see org.xml.sax.ContentHandler#setDocumentLocator\r
- */\r
- public void setDocumentLocator (Locator locator)\r
- {\r
- this.locator = locator;\r
- if (contentHandler != null) {\r
- contentHandler.setDocumentLocator(locator);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a start document event.\r
- *\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#startDocument\r
- */\r
- public void startDocument ()\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.startDocument();\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter an end document event.\r
- *\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#endDocument\r
- */\r
- public void endDocument ()\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.endDocument();\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a start Namespace prefix mapping event.\r
- *\r
- * @param prefix The Namespace prefix.\r
- * @param uri The Namespace URI.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#startPrefixMapping\r
- */\r
- public void startPrefixMapping (String prefix, String uri)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.startPrefixMapping(prefix, uri);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter an end Namespace prefix mapping event.\r
- *\r
- * @param prefix The Namespace prefix.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#endPrefixMapping\r
- */\r
- public void endPrefixMapping (String prefix)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.endPrefixMapping(prefix);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a start element event.\r
- *\r
- * @param uri The element's Namespace URI, or the empty string.\r
- * @param localName The element's local name, or the empty string.\r
- * @param qName The element's qualified (prefixed) name, or the empty\r
- * string.\r
- * @param atts The element's attributes.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#startElement\r
- */\r
- public void startElement (String uri, String localName, String qName,\r
- Attributes atts)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.startElement(uri, localName, qName, atts);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter an end element event.\r
- *\r
- * @param uri The element's Namespace URI, or the empty string.\r
- * @param localName The element's local name, or the empty string.\r
- * @param qName The element's qualified (prefixed) name, or the empty\r
- * string.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#endElement\r
- */\r
- public void endElement (String uri, String localName, String qName)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.endElement(uri, localName, qName);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a character data event.\r
- *\r
- * @param ch An array of characters.\r
- * @param start The starting position in the array.\r
- * @param length The number of characters to use from the array.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#characters\r
- */\r
- public void characters (char ch[], int start, int length)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.characters(ch, start, length);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter an ignorable whitespace event.\r
- *\r
- * @param ch An array of characters.\r
- * @param start The starting position in the array.\r
- * @param length The number of characters to use from the array.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#ignorableWhitespace\r
- */\r
- public void ignorableWhitespace (char ch[], int start, int length)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.ignorableWhitespace(ch, start, length);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a processing instruction event.\r
- *\r
- * @param target The processing instruction target.\r
- * @param data The text following the target.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#processingInstruction\r
- */\r
- public void processingInstruction (String target, String data)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.processingInstruction(target, data);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a skipped entity event.\r
- *\r
- * @param name The name of the skipped entity.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ContentHandler#skippedEntity\r
- */\r
- public void skippedEntity (String name)\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.skippedEntity(name);\r
- }\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.ErrorHandler.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Filter a warning event.\r
- *\r
- * @param e The nwarning as an exception.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ErrorHandler#warning\r
- */\r
- public void warning (SAXParseException e)\r
- throws SAXException\r
- {\r
- if (errorHandler != null) {\r
- errorHandler.warning(e);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter an error event.\r
- *\r
- * @param e The error as an exception.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ErrorHandler#error\r
- */\r
- public void error (SAXParseException e)\r
- throws SAXException\r
- {\r
- if (errorHandler != null) {\r
- errorHandler.error(e);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Filter a fatal error event.\r
- *\r
- * @param e The error as an exception.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception during processing.\r
- * @see org.xml.sax.ErrorHandler#fatalError\r
- */\r
- public void fatalError (SAXParseException e)\r
- throws SAXException\r
- {\r
- if (errorHandler != null) {\r
- errorHandler.fatalError(e);\r
- }\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Internal methods.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Set up before a parse.\r
- *\r
- * <p>Before every parse, check whether the parent is\r
- * non-null, and re-register the filter for all of the \r
- * events.</p>\r
- */\r
- private void setupParse ()\r
- {\r
- if (parent == null) {\r
- throw new NullPointerException("No parent for filter");\r
- }\r
- parent.setEntityResolver(this);\r
- parent.setDTDHandler(this);\r
- parent.setContentHandler(this);\r
- parent.setErrorHandler(this);\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Internal state.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
- private XMLReader parent = null;\r
- private Locator locator = null;\r
- private EntityResolver entityResolver = null;\r
- private DTDHandler dtdHandler = null;\r
- private ContentHandler contentHandler = null;\r
- private ErrorHandler errorHandler = null;\r
-\r
-}\r
-\r
-// end of XMLFilterImpl.java\r