+++ /dev/null
-// ParserAdapter.java - adapt a SAX1 Parser to a SAX2 XMLReader.\r
-// Written by David Megginson, sax@megginson.com\r
-// NO WARRANTY! This class is in the public domain.\r
-\r
-// $Id: ParserAdapter.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
-import java.util.Enumeration;\r
-\r
-import org.xml.sax.Parser; // deprecated\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.Locator;\r
-import org.xml.sax.AttributeList; // deprecated\r
-import org.xml.sax.EntityResolver;\r
-import org.xml.sax.DTDHandler;\r
-import org.xml.sax.DocumentHandler; // deprecated\r
-import org.xml.sax.ErrorHandler;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.SAXParseException;\r
-\r
-import org.xml.sax.XMLReader;\r
-import org.xml.sax.Attributes;\r
-import org.xml.sax.ContentHandler;\r
-import org.xml.sax.SAXNotRecognizedException;\r
-import org.xml.sax.SAXNotSupportedException;\r
-\r
-\r
-/**\r
- * Adapt a SAX1 Parser as a SAX2 XMLReader.\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 wraps a SAX1 {@link org.xml.sax.Parser Parser}\r
- * and makes it act as a SAX2 {@link org.xml.sax.XMLReader XMLReader},\r
- * with feature, property, and Namespace support. Note\r
- * that it is not possible to report {@link org.xml.sax.ContentHandler#skippedEntity\r
- * skippedEntity} events, since SAX1 does not make that information available.</p>\r
- *\r
- * <p>This adapter does not test for duplicate Namespace-qualified\r
- * attribute names.</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.helpers.XMLReaderAdapter\r
- * @see org.xml.sax.XMLReader\r
- * @see org.xml.sax.Parser\r
- */\r
-public class ParserAdapter implements XMLReader, DocumentHandler\r
-{\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Constructors.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Construct a new parser adapter.\r
- *\r
- * <p>Use the "org.xml.sax.parser" property to locate the\r
- * embedded SAX1 driver.</p>\r
- *\r
- * @exception org.xml.sax.SAXException If the embedded driver\r
- * cannot be instantiated or if the\r
- * org.xml.sax.parser property is not specified.\r
- */\r
- public ParserAdapter ()\r
- throws SAXException\r
- {\r
- super();\r
-\r
- String driver = System.getProperty("org.xml.sax.parser");\r
-\r
- try {\r
- setup(ParserFactory.makeParser());\r
- } catch (ClassNotFoundException e1) {\r
- throw new\r
- SAXException("Cannot find SAX1 driver class " +\r
- driver, e1);\r
- } catch (IllegalAccessException e2) {\r
- throw new\r
- SAXException("SAX1 driver class " +\r
- driver +\r
- " found but cannot be loaded", e2);\r
- } catch (InstantiationException e3) {\r
- throw new\r
- SAXException("SAX1 driver class " +\r
- driver +\r
- " loaded but cannot be instantiated", e3);\r
- } catch (ClassCastException e4) {\r
- throw new\r
- SAXException("SAX1 driver class " +\r
- driver +\r
- " does not implement org.xml.sax.Parser");\r
- } catch (NullPointerException e5) {\r
- throw new \r
- SAXException("System property org.xml.sax.parser not specified");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a new parser adapter.\r
- *\r
- * <p>Note that the embedded parser cannot be changed once the\r
- * adapter is created; to embed a different parser, allocate\r
- * a new ParserAdapter.</p>\r
- *\r
- * @param parser The SAX1 parser to embed.\r
- * @exception java.lang.NullPointerException If the parser parameter\r
- * is null.\r
- */\r
- public ParserAdapter (Parser parser)\r
- {\r
- super();\r
- setup(parser);\r
- }\r
-\r
-\r
- /**\r
- * Internal setup method.\r
- *\r
- * @param parser The embedded parser.\r
- * @exception java.lang.NullPointerException If the parser parameter\r
- * is null.\r
- */\r
- private void setup (Parser parser)\r
- {\r
- if (parser == null) {\r
- throw new\r
- NullPointerException("Parser argument must not be null");\r
- }\r
- this.parser = parser;\r
- atts = new AttributesImpl();\r
- nsSupport = new NamespaceSupport();\r
- attAdapter = new AttributeListAdapter();\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.XMLReader.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- //\r
- // Internal constants for the sake of convenience.\r
- //\r
- private final static String FEATURES = "http://xml.org/sax/features/";\r
- private final static String NAMESPACES = FEATURES + "namespaces";\r
- private final static String NAMESPACE_PREFIXES = FEATURES + "namespace-prefixes";\r
- private final static String VALIDATION = FEATURES + "validation";\r
- private final static String EXTERNAL_GENERAL =\r
- FEATURES + "external-general-entities";\r
- private final static String EXTERNAL_PARAMETER =\r
- FEATURES + "external-parameter-entities";\r
-\r
-\r
- /**\r
- * Set a feature for the parser.\r
- *\r
- * <p>The only features supported are namespaces and \r
- * namespace-prefixes.</p>\r
- *\r
- * @param name The feature name, as a complete URI.\r
- * @param state The requested feature state.\r
- * @exception org.xml.sax.SAXNotRecognizedException If the feature\r
- * name is not known.\r
- * @exception org.xml.sax.SAXNotSupportedException If the feature\r
- * state is not supported.\r
- * @see org.xml.sax.XMLReader#setFeature\r
- */\r
- public void setFeature (String name, boolean state)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- if (name.equals(NAMESPACES)) {\r
- checkNotParsing("feature", name);\r
- namespaces = state;\r
- if (!namespaces && !prefixes) {\r
- prefixes = true;\r
- }\r
- } else if (name.equals(NAMESPACE_PREFIXES)) {\r
- checkNotParsing("feature", name);\r
- prefixes = state;\r
- if (!prefixes && !namespaces) {\r
- namespaces = true;\r
- }\r
- } else if (name.equals(VALIDATION) ||\r
- name.equals(EXTERNAL_GENERAL) ||\r
- name.equals(EXTERNAL_PARAMETER)) {\r
- throw new SAXNotSupportedException("Feature: " + name);\r
- } else {\r
- throw new SAXNotRecognizedException("Feature: " + name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Check a parser feature.\r
- *\r
- * <p>The only features supported are namespaces and \r
- * namespace-prefixes.</p>\r
- *\r
- * @param name The feature name, as a complete URI.\r
- * @return The current feature state.\r
- * @exception org.xml.sax.SAXNotRecognizedException If the feature\r
- * name is not known.\r
- * @exception org.xml.sax.SAXNotSupportedException If querying the\r
- * feature state is not supported.\r
- * @see org.xml.sax.XMLReader#setFeature\r
- */\r
- public boolean getFeature (String name)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- if (name.equals(NAMESPACES)) {\r
- return namespaces;\r
- } else if (name.equals(NAMESPACE_PREFIXES)) {\r
- return prefixes;\r
- } else if (name.equals(VALIDATION) ||\r
- name.equals(EXTERNAL_GENERAL) ||\r
- name.equals(EXTERNAL_PARAMETER)) {\r
- throw new SAXNotSupportedException("Feature: " + name);\r
- } else {\r
- throw new SAXNotRecognizedException("Feature: " + name);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Set a parser property.\r
- *\r
- * <p>No special properties are currently supported.</p>\r
- *\r
- * @param name The property name.\r
- * @param value The property value.\r
- * @exception org.xml.sax.SAXNotRecognizedException If the feature\r
- * name is not known.\r
- * @exception org.xml.sax.SAXNotSupportedException If the feature\r
- * state is not supported.\r
- * @see org.xml.sax.XMLReader#setProperty\r
- */\r
- public void setProperty (String name, Object value)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- throw new SAXNotRecognizedException("Property: " + name);\r
- }\r
-\r
-\r
- /**\r
- * Get a parser property.\r
- *\r
- * <p>No special properties are currently supported.</p>\r
- *\r
- * @param name The property name.\r
- * @return The property value.\r
- * @exception org.xml.sax.SAXNotRecognizedException If the feature\r
- * name is not known.\r
- * @exception org.xml.sax.SAXNotSupportedException If the feature\r
- * state is not supported.\r
- * @see org.xml.sax.XMLReader#getProperty\r
- */\r
- public Object getProperty (String name)\r
- throws SAXNotRecognizedException, SAXNotSupportedException\r
- {\r
- throw new SAXNotRecognizedException("Property: " + name);\r
- }\r
-\r
-\r
- /**\r
- * Set the entity resolver.\r
- *\r
- * @param resolver The new entity resolver.\r
- * @exception java.lang.NullPointerException If the entity resolver\r
- * parameter 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
- }\r
- entityResolver = resolver;\r
- }\r
-\r
-\r
- /**\r
- * Return the current entity resolver.\r
- *\r
- * @return The current entity resolver, or null if none was supplied.\r
- * @see org.xml.sax.XMLReader#getEntityResolver\r
- */\r
- public EntityResolver getEntityResolver ()\r
- {\r
- return entityResolver;\r
- }\r
-\r
-\r
- /**\r
- * Set the DTD handler.\r
- *\r
- * @param resolver The new DTD handler.\r
- * @exception java.lang.NullPointerException If the DTD handler\r
- * parameter is null.\r
- * @see org.xml.sax.XMLReader#setEntityResolver\r
- */\r
- public void setDTDHandler (DTDHandler handler)\r
- {\r
- if (handler == null) {\r
- throw new NullPointerException("Null DTD handler");\r
- }\r
- dtdHandler = handler;\r
- }\r
-\r
-\r
- /**\r
- * Return the current DTD handler.\r
- *\r
- * @return The current DTD handler, or null if none was supplied.\r
- * @see org.xml.sax.XMLReader#getEntityResolver\r
- */\r
- public DTDHandler getDTDHandler ()\r
- {\r
- return dtdHandler;\r
- }\r
-\r
-\r
- /**\r
- * Set the content handler.\r
- *\r
- * @param resolver The new content handler.\r
- * @exception java.lang.NullPointerException If the content handler\r
- * parameter is null.\r
- * @see org.xml.sax.XMLReader#setEntityResolver\r
- */\r
- public void setContentHandler (ContentHandler handler)\r
- {\r
- if (handler == null) {\r
- throw new NullPointerException("Null content handler");\r
- }\r
- contentHandler = handler;\r
- }\r
-\r
-\r
- /**\r
- * Return the current content handler.\r
- *\r
- * @return The current content handler, or null if none was supplied.\r
- * @see org.xml.sax.XMLReader#getEntityResolver\r
- */\r
- public ContentHandler getContentHandler ()\r
- {\r
- return contentHandler;\r
- }\r
-\r
-\r
- /**\r
- * Set the error handler.\r
- *\r
- * @param resolver The new error handler.\r
- * @exception java.lang.NullPointerException If the error handler\r
- * parameter is null.\r
- * @see org.xml.sax.XMLReader#setEntityResolver\r
- */\r
- public void setErrorHandler (ErrorHandler handler)\r
- {\r
- if (handler == null) {\r
- throw new NullPointerException("Null error handler");\r
- }\r
- errorHandler = handler;\r
- }\r
-\r
-\r
- /**\r
- * Return the current error handler.\r
- *\r
- * @return The current error handler, or null if none was supplied.\r
- * @see org.xml.sax.XMLReader#getEntityResolver\r
- */\r
- public ErrorHandler getErrorHandler ()\r
- {\r
- return errorHandler;\r
- }\r
-\r
-\r
- /**\r
- * Parse an XML document.\r
- *\r
- * @param systemId The absolute URL of the document.\r
- * @exception java.io.IOException If there is a problem reading\r
- * the raw content of the document.\r
- * @exception org.xml.sax.SAXException If there is a problem\r
- * processing the document.\r
- * @see #parse(org.xml.sax.InputSource)\r
- * @see org.xml.sax.Parser#parse(java.lang.String)\r
- */\r
- public void parse (String systemId)\r
- throws IOException, SAXException\r
- {\r
- parse(new InputSource(systemId));\r
- }\r
-\r
-\r
- /**\r
- * Parse an XML document.\r
- *\r
- * @param input An input source for the document.\r
- * @exception java.io.IOException If there is a problem reading\r
- * the raw content of the document.\r
- * @exception org.xml.sax.SAXException If there is a problem\r
- * processing the document.\r
- * @see #parse(java.lang.String)\r
- * @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)\r
- */\r
- public void parse (InputSource input)\r
- throws IOException, SAXException\r
- {\r
- if (parsing) {\r
- throw new SAXException("Parser is already in use");\r
- }\r
- setupParser();\r
- parsing = true;\r
- try {\r
- parser.parse(input);\r
- } finally {\r
- parsing = false;\r
- }\r
- parsing = false;\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Implementation of org.xml.sax.DocumentHandler.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Adapt a SAX1 document locator event.\r
- *\r
- * @param locator A 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
- * Adapt a SAX1 start document event.\r
- *\r
- * @exception org.xml.sax.SAXException The client may raise a\r
- * processing exception.\r
- * @see org.xml.sax.DocumentHandler#startDocument\r
- */\r
- public void startDocument ()\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.startDocument();\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Adapt a SAX1 end document event.\r
- *\r
- * @exception org.xml.sax.SAXException The client may raise a\r
- * processing exception.\r
- * @see org.xml.sax.DocumentHandler#endDocument\r
- */\r
- public void endDocument ()\r
- throws SAXException\r
- {\r
- if (contentHandler != null) {\r
- contentHandler.endDocument();\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Adapt a SAX1 startElement event.\r
- *\r
- * <p>If necessary, perform Namespace processing.</p>\r
- *\r
- * @param qName The qualified (prefixed) name.\r
- * @param qAtts The XML 1.0 attribute list (with qnames).\r
- */\r
- public void startElement (String qName, AttributeList qAtts)\r
- throws SAXException\r
- {\r
- // If we're not doing Namespace\r
- // processing, dispatch this quickly.\r
- if (!namespaces) {\r
- if (contentHandler != null) {\r
- attAdapter.setAttributeList(qAtts);\r
- contentHandler.startElement("", "", qName.intern(),\r
- attAdapter);\r
- }\r
- return;\r
- }\r
-\r
-\r
- // OK, we're doing Namespace processing.\r
- nsSupport.pushContext();\r
- boolean seenDecl = false;\r
- atts.clear();\r
- \r
- // Take a first pass and copy all\r
- // attributes into the SAX2 attribute\r
- // list, noting any Namespace \r
- // declarations.\r
- int length = qAtts.getLength();\r
- for (int i = 0; i < length; i++) {\r
- String attQName = qAtts.getName(i);\r
- String type = qAtts.getType(i);\r
- String value = qAtts.getValue(i);\r
-\r
- // Found a declaration...\r
- if (attQName.startsWith("xmlns")) {\r
- String prefix;\r
- int n = attQName.indexOf(':');\r
- if (n == -1) {\r
- prefix = "";\r
- } else {\r
- prefix = attQName.substring(n+1);\r
- }\r
- if (!nsSupport.declarePrefix(prefix, value)) {\r
- reportError("Illegal Namespace prefix: " + prefix);\r
- }\r
- if (contentHandler != null) {\r
- contentHandler.startPrefixMapping(prefix, value);\r
- }\r
- // We may still have to add this to\r
- // the list.\r
- if (prefixes) {\r
- atts.addAttribute("", "", attQName.intern(),\r
- type, value);\r
- }\r
- seenDecl = true;\r
-\r
- // This isn't a declaration.\r
- } else {\r
- String attName[] = processName(attQName, true);\r
- atts.addAttribute(attName[0], attName[1], attName[2],\r
- type, value);\r
- }\r
- }\r
- \r
- // If there was a Namespace declaration,\r
- // we have to make a second pass just\r
- // to be safe -- this will happen very\r
- // rarely, possibly only once for each\r
- // document.\r
- if (seenDecl) {\r
- length = atts.getLength();\r
- for (int i = 0; i < length; i++) {\r
- String attQName = atts.getQName(i);\r
- if (!attQName.startsWith("xmlns")) {\r
- String attName[] = processName(attQName, true);\r
- atts.setURI(i, attName[0]);\r
- atts.setLocalName(i, attName[1]);\r
- }\r
- }\r
- }\r
-\r
- // OK, finally report the event.\r
- if (contentHandler != null) {\r
- String name[] = processName(qName, false);\r
- contentHandler.startElement(name[0], name[1], name[2], atts);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Adapt a SAX1 end element event.\r
- *\r
- * @param qName The qualified (prefixed) name.\r
- * @exception org.xml.sax.SAXException The client may raise a\r
- * processing exception.\r
- * @see org.xml.sax.DocumentHandler#endElement\r
- */\r
- public void endElement (String qName)\r
- throws SAXException\r
- {\r
- // If we're not doing Namespace\r
- // processing, dispatch this quickly.\r
- if (!namespaces) {\r
- if (contentHandler != null) {\r
- contentHandler.endElement("", "", qName.intern());\r
- }\r
- return;\r
- }\r
-\r
- // Split the name.\r
- String names[] = processName(qName, false);\r
- if (contentHandler != null) {\r
- contentHandler.endElement(names[0], names[1], names[2]);\r
- Enumeration prefixes = nsSupport.getDeclaredPrefixes();\r
- while (prefixes.hasMoreElements()) {\r
- String prefix = (String)prefixes.nextElement();\r
- contentHandler.endPrefixMapping(prefix);\r
- }\r
- }\r
- nsSupport.popContext();\r
- }\r
-\r
-\r
- /**\r
- * Adapt a SAX1 characters 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.\r
- * @exception org.xml.sax.SAXException The client may raise a\r
- * processing exception.\r
- * @see org.xml.sax.DocumentHandler#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
- * Adapt a SAX1 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.\r
- * @exception org.xml.sax.SAXException The client may raise a\r
- * processing exception.\r
- * @see org.xml.sax.DocumentHandler#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
- * Adapt a SAX1 processing instruction event.\r
- *\r
- * @param target The processing instruction target.\r
- * @param data The remainder of the processing instruction\r
- * @exception org.xml.sax.SAXException The client may raise a\r
- * processing exception.\r
- * @see org.xml.sax.DocumentHandler#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
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Internal utility methods.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Initialize the parser before each run.\r
- */\r
- private void setupParser ()\r
- {\r
- nsSupport.reset();\r
-\r
- if (entityResolver != null) {\r
- parser.setEntityResolver(entityResolver);\r
- }\r
- if (dtdHandler != null) {\r
- parser.setDTDHandler(dtdHandler);\r
- }\r
- if (errorHandler != null) {\r
- parser.setErrorHandler(errorHandler);\r
- }\r
- parser.setDocumentHandler(this);\r
- locator = null;\r
- }\r
-\r
-\r
- /**\r
- * Process a qualified (prefixed) name.\r
- *\r
- * <p>If the name has an undeclared prefix, use only the qname\r
- * and make an ErrorHandler.error callback in case the app is\r
- * interested.</p>\r
- *\r
- * @param qName The qualified (prefixed) name.\r
- * @param isAttribute true if this is an attribute name.\r
- * @return The name split into three parts.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception if there is an error callback.\r
- */\r
- private String [] processName (String qName, boolean isAttribute)\r
- throws SAXException\r
- {\r
- String parts[] = nsSupport.processName(qName, nameParts,\r
- isAttribute);\r
- if (parts == null) {\r
- parts = new String[3];\r
- parts[2] = qName.intern();\r
- reportError("Undeclared prefix: " + qName);\r
- }\r
- return parts;\r
- }\r
-\r
-\r
- /**\r
- * Report a non-fatal error.\r
- *\r
- * @param message The error message.\r
- * @exception org.xml.sax.SAXException The client may throw\r
- * an exception.\r
- */\r
- void reportError (String message)\r
- throws SAXException\r
- {\r
- if (errorHandler == null) {\r
- return;\r
- }\r
-\r
- SAXParseException e;\r
- if (locator != null) {\r
- e = new SAXParseException(message, locator);\r
- } else {\r
- e = new SAXParseException(message, null, null, -1, -1);\r
- }\r
- errorHandler.error(e);\r
- }\r
-\r
-\r
- /**\r
- * Throw an exception if we are parsing.\r
- *\r
- * <p>Use this method to detect illegal feature or\r
- * property changes.</p>\r
- *\r
- * @param type The type of thing (feature or property).\r
- * @param name The feature or property name.\r
- * @exception org.xml.sax.SAXNotSupportedException If a\r
- * document is currently being parsed.\r
- */\r
- private void checkNotParsing (String type, String name)\r
- throws SAXNotSupportedException\r
- {\r
- if (parsing) {\r
- throw new SAXNotSupportedException("Cannot change " +\r
- type + ' ' +\r
- name + " while parsing");\r
- \r
- }\r
- }\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Internal state.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
- private NamespaceSupport nsSupport;\r
- private AttributeListAdapter attAdapter;\r
-\r
- private boolean parsing = false;\r
- private String nameParts[] = new String[3];\r
-\r
- private Parser parser = null;\r
-\r
- private AttributesImpl atts = null;\r
-\r
- // Features\r
- private boolean namespaces = true;\r
- private boolean prefixes = false;\r
-\r
- // Properties\r
-\r
- // Handlers\r
- Locator locator;\r
-\r
- EntityResolver entityResolver = null;\r
- DTDHandler dtdHandler = null;\r
- ContentHandler contentHandler = null;\r
- ErrorHandler errorHandler = null;\r
-\r
-\r
-\f\r
- ////////////////////////////////////////////////////////////////////\r
- // Inner class to wrap an AttributeList when not doing NS proc.\r
- ////////////////////////////////////////////////////////////////////\r
-\r
-\r
- /**\r
- * Adapt a SAX1 AttributeList as a SAX2 Attributes object.\r
- *\r
- * <p>This class is in the Public Domain, and comes with NO\r
- * WARRANTY of any kind.</p>\r
- *\r
- * <p>This wrapper class is used only when Namespace support\r
- * is disabled -- it provides pretty much a direct mapping\r
- * from SAX1 to SAX2, except that names and types are \r
- * interned whenever requested.</p>\r
- */\r
- final class AttributeListAdapter implements Attributes\r
- {\r
-\r
- /**\r
- * Construct a new adapter.\r
- */\r
- AttributeListAdapter ()\r
- {\r
- }\r
-\r
-\r
- /**\r
- * Set the embedded AttributeList.\r
- *\r
- * <p>This method must be invoked before any of the others\r
- * can be used.</p>\r
- *\r
- * @param The SAX1 attribute list (with qnames).\r
- */\r
- void setAttributeList (AttributeList qAtts)\r
- {\r
- this.qAtts = qAtts;\r
- }\r
-\r
-\r
- /**\r
- * Return the length of the attribute list.\r
- *\r
- * @return The number of attributes in the list.\r
- * @see org.xml.sax.Attributes#getLength\r
- */\r
- public int getLength ()\r
- {\r
- return qAtts.getLength();\r
- }\r
-\r
-\r
- /**\r
- * Return the Namespace URI of the specified attribute.\r
- *\r
- * @param The attribute's index.\r
- * @return Always the empty string.\r
- * @see org.xml.sax.Attributes#getURI\r
- */\r
- public String getURI (int i)\r
- {\r
- return "";\r
- }\r
-\r
-\r
- /**\r
- * Return the local name of the specified attribute.\r
- *\r
- * @param The attribute's index.\r
- * @return Always the empty string.\r
- * @see org.xml.sax.Attributes#getLocalName\r
- */\r
- public String getLocalName (int i)\r
- {\r
- return "";\r
- }\r
-\r
-\r
- /**\r
- * Return the qualified (prefixed) name of the specified attribute.\r
- *\r
- * @param The attribute's index.\r
- * @return The attribute's qualified name, internalized.\r
- */\r
- public String getQName (int i)\r
- {\r
- return qAtts.getName(i).intern();\r
- }\r
-\r
-\r
- /**\r
- * Return the type of the specified attribute.\r
- *\r
- * @param The attribute's index.\r
- * @return The attribute's type as an internalized string.\r
- */\r
- public String getType (int i)\r
- {\r
- return qAtts.getType(i).intern();\r
- }\r
-\r
-\r
- /**\r
- * Return the value of the specified attribute.\r
- *\r
- * @param The attribute's index.\r
- * @return The attribute's value.\r
- */\r
- public String getValue (int i)\r
- {\r
- return qAtts.getValue(i);\r
- }\r
-\r
-\r
- /**\r
- * Look up an attribute index by Namespace name.\r
- *\r
- * @param uri The Namespace URI or the empty string.\r
- * @param localName The local name.\r
- * @return The attributes index, or -1 if none was found.\r
- * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)\r
- */\r
- public int getIndex (String uri, String localName)\r
- {\r
- return -1;\r
- }\r
-\r
-\r
- /**\r
- * Look up an attribute index by qualified (prefixed) name.\r
- *\r
- * @param qName The qualified name.\r
- * @return The attributes index, or -1 if none was found.\r
- * @see org.xml.sax.Attributes#getIndex(java.lang.String)\r
- */\r
- public int getIndex (String qName)\r
- {\r
- int max = atts.getLength();\r
- for (int i = 0; i < max; i++) {\r
- if (qAtts.getName(i).equals(qName)) {\r
- return i;\r
- }\r
- }\r
- return -1;\r
- }\r
-\r
-\r
- /**\r
- * Look up the type of an attribute by Namespace name.\r
- *\r
- * @param uri The Namespace URI\r
- * @param localName The local name.\r
- * @return The attribute's type as an internalized string.\r
- */\r
- public String getType (String uri, String localName)\r
- {\r
- return null;\r
- }\r
-\r
-\r
- /**\r
- * Look up the type of an attribute by qualified (prefixed) name.\r
- *\r
- * @param qName The qualified name.\r
- * @return The attribute's type as an internalized string.\r
- */\r
- public String getType (String qName)\r
- {\r
- return qAtts.getType(qName).intern();\r
- }\r
-\r
-\r
- /**\r
- * Look up the value of an attribute by Namespace name.\r
- *\r
- * @param uri The Namespace URI\r
- * @param localName The local name.\r
- * @return The attribute's value.\r
- */\r
- public String getValue (String uri, String localName)\r
- {\r
- return null;\r
- }\r
-\r
-\r
- /**\r
- * Look up the value of an attribute by qualified (prefixed) name.\r
- *\r
- * @param qName The qualified name.\r
- * @return The attribute's value.\r
- */\r
- public String getValue (String qName)\r
- {\r
- return qAtts.getValue(qName);\r
- }\r
-\r
- private AttributeList qAtts;\r
- }\r
-}\r
-\r
-// end of ParserAdapter.java\r