286N/A * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. 286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/A * This code is free software; you can redistribute it and/or modify it 286N/A * under the terms of the GNU General Public License version 2 only, as 286N/A * published by the Free Software Foundation. Oracle designates this 286N/A * particular file as subject to the "Classpath" exception as provided 286N/A * by Oracle in the LICENSE file that accompanied this code. 286N/A * This code is distributed in the hope that it will be useful, but WITHOUT 286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/A * version 2 for more details (a copy is included in the LICENSE file that 286N/A * accompanied this code). 286N/A * You should have received a copy of the GNU General Public License version 286N/A * 2 along with this work; if not, write to the Free Software Foundation, 286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A * or visit www.oracle.com if you need additional information or have any 286N/A// Written by David Megginson 286N/A// NO WARRANTY! This class is in the public domain. 286N/A * Adapt a SAX1 Parser as a SAX2 XMLReader. 286N/A * <em>This module, both source code and documentation, is in the 286N/A * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> 286N/A * for further information. 286N/A * <p>This class wraps a SAX1 {@link org.xml.sax.Parser Parser} 286N/A * with feature, property, and Namespace support. Note 286N/A * that it is not possible to report {@link org.xml.sax.ContentHandler#skippedEntity 286N/A * skippedEntity} events, since SAX1 does not make that information available.</p> 286N/A * <p>This adapter does not test for duplicate Namespace-qualified 286N/A * @author David Megginson 524N/A * @version 2.0.1 (sax2r2) 286N/A //////////////////////////////////////////////////////////////////// 286N/A //////////////////////////////////////////////////////////////////// 286N/A * Construct a new parser adapter. 286N/A * embedded SAX1 driver.</p> 286N/A * @exception SAXException If the embedded driver 286N/A * cannot be instantiated or if the 286N/A " found but cannot be loaded",
e2);
286N/A " loaded but cannot be instantiated",
e3);
286N/A * Construct a new parser adapter. 286N/A * <p>Note that the embedded parser cannot be changed once the 286N/A * adapter is created; to embed a different parser, allocate 286N/A * a new ParserAdapter.</p> 286N/A * @param parser The SAX1 parser to embed. 286N/A * @exception java.lang.NullPointerException If the parser parameter 286N/A * Internal setup method. 286N/A * @param parser The embedded parser. 286N/A * @exception java.lang.NullPointerException If the parser parameter 286N/A //////////////////////////////////////////////////////////////////// 286N/A //////////////////////////////////////////////////////////////////// 286N/A // Internal constants for the sake of convenience. 286N/A * Set a feature flag for the parser. 286N/A * <p>The only features recognized are namespaces and 286N/A * namespace-prefixes.</p> 286N/A * @param name The feature name, as a complete URI. 286N/A * @param value The requested feature value. 286N/A * @exception SAXNotRecognizedException If the feature 286N/A * can't be assigned or retrieved. 286N/A * @exception SAXNotSupportedException If the feature 286N/A * can't be assigned that value. 286N/A * Check a parser feature flag. 286N/A * <p>The only features recognized are namespaces and 286N/A * namespace-prefixes.</p> 286N/A * @param name The feature name, as a complete URI. 286N/A * @return The current feature value. 286N/A * @exception SAXNotRecognizedException If the feature 286N/A * value can't be assigned or retrieved. 286N/A * @exception SAXNotSupportedException If the 286N/A * feature is not currently readable. 286N/A * Set a parser property. 286N/A * <p>No properties are currently recognized.</p> 286N/A * @param name The property name. 286N/A * @param value The property value. 286N/A * @exception SAXNotRecognizedException If the property 286N/A * value can't be assigned or retrieved. 286N/A * @exception SAXNotSupportedException If the property 286N/A * can't be assigned that value. 286N/A * Get a parser property. 286N/A * <p>No properties are currently recognized.</p> 286N/A * @param name The property name. 286N/A * @return The property value. 286N/A * @exception SAXNotRecognizedException If the property 286N/A * value can't be assigned or retrieved. 286N/A * @exception SAXNotSupportedException If the property 286N/A * value is not currently readable. 286N/A * Set the entity resolver. 286N/A * @param resolver The new entity resolver. 286N/A * Return the current entity resolver. 286N/A * @return The current entity resolver, or null if none was supplied. 286N/A * @param handler the new DTD handler 286N/A * Return the current DTD handler. 286N/A * @return the current DTD handler, or null if none was supplied 286N/A * Set the content handler. 286N/A * @param handler the new content handler 286N/A * Return the current content handler. 286N/A * @return The current content handler, or null if none was supplied. 286N/A * Set the error handler. 286N/A * @param handler The new error handler. 286N/A * Return the current error handler. 286N/A * @return The current error handler, or null if none was supplied. 286N/A * Parse an XML document. 286N/A * @param systemId The absolute URL of the document. 286N/A * @exception java.io.IOException If there is a problem reading 286N/A * the raw content of the document. 286N/A * @exception SAXException If there is a problem 286N/A * processing the document. 286N/A * Parse an XML document. 286N/A * @param input An input source for the document. 286N/A * @exception java.io.IOException If there is a problem reading 286N/A * the raw content of the document. 286N/A * @exception SAXException If there is a problem 286N/A * processing the document. 286N/A * @see #parse(java.lang.String) 286N/A //////////////////////////////////////////////////////////////////// 286N/A //////////////////////////////////////////////////////////////////// 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 document locator event. 286N/A * @param locator A document locator. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 start document event. 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 end document event. 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 startElement event. 286N/A * <p>If necessary, perform Namespace processing.</p> 286N/A * @param qName The qualified (prefixed) name. 286N/A * @param qAtts The XML attribute list (with qnames). 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A // These are exceptions from the 286N/A // first pass; they should be 286N/A // ignored if there's a second pass, 286N/A // but reported otherwise. 286N/A // If we're not doing Namespace 286N/A // processing, dispatch this quickly. 286N/A // OK, we're doing Namespace processing. 286N/A // First pass: handle NS decls 286N/A // Could be a declaration... 286N/A // XML namespaces spec doesn't discuss "xmlnsf:oo" 286N/A // (and similarly named) attributes ... at most, warn 286N/A }
else // xmlns:foo=... 286N/A // Second pass: copy all relevant 286N/A // attributes into the SAX2 AttributeList 286N/A // using updated prefix bindings 286N/A // XML namespaces spec doesn't discuss "xmlnsf:oo" 286N/A // (and similarly named) attributes ... ignore 286N/A // Yes, decl: report or prune 286N/A // note funky case: localname can be null 286N/A // when declaring the default prefix, and 286N/A // yet the uri isn't null. 286N/A // Not a declaration -- report 286N/A // now handle the deferred exception reports 286N/A // OK, finally report the event. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 end element event. 286N/A * @param qName The qualified (prefixed) name. 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A // If we're not doing Namespace 286N/A // processing, dispatch this quickly. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 characters event. 286N/A * @param ch An array of characters. 286N/A * @param start The starting position in the array. 286N/A * @param length The number of characters to use. 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 ignorable whitespace event. 286N/A * @param ch An array of characters. 286N/A * @param start The starting position in the array. 286N/A * @param length The number of characters to use. 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A * Adapter implementation method; do not call. 286N/A * Adapt a SAX1 processing instruction event. 286N/A * @param target The processing instruction target. 286N/A * @param data The remainder of the processing instruction 286N/A * @exception SAXException The client may raise a 286N/A * processing exception. 286N/A //////////////////////////////////////////////////////////////////// 286N/A // Internal utility methods. 286N/A //////////////////////////////////////////////////////////////////// 286N/A * Initialize the parser before each run. 286N/A // catch an illegal "nonsense" state. 286N/A * Process a qualified (prefixed) name. 286N/A * <p>If the name has an undeclared prefix, use only the qname 286N/A * and make an ErrorHandler.error callback in case the app is 286N/A * @param qName The qualified (prefixed) name. 286N/A * @param isAttribute true if this is an attribute name. 286N/A * @return The name split into three parts. 286N/A * @exception SAXException The client may throw 286N/A * an exception if there is an error callback. 286N/A * Report a non-fatal error. 286N/A * @param message The error message. 286N/A * @exception SAXException The client may throw 286N/A * Construct an exception for the current context. 286N/A * @param message The error message. 286N/A * Throw an exception if we are parsing. 286N/A * <p>Use this method to detect illegal feature or 286N/A * property changes.</p> 286N/A * @param type The type of thing (feature or property). 286N/A * @param name The feature or property name. 286N/A * @exception SAXNotSupportedException If a 286N/A * document is currently being parsed. 286N/A //////////////////////////////////////////////////////////////////// 286N/A //////////////////////////////////////////////////////////////////// 286N/A //////////////////////////////////////////////////////////////////// 286N/A // Inner class to wrap an AttributeList when not doing NS proc. 286N/A //////////////////////////////////////////////////////////////////// 286N/A * Adapt a SAX1 AttributeList as a SAX2 Attributes object. 286N/A * <p>This class is in the Public Domain, and comes with NO 286N/A * WARRANTY of any kind.</p> 286N/A * <p>This wrapper class is used only when Namespace support 286N/A * is disabled -- it provides pretty much a direct mapping 286N/A * from SAX1 to SAX2, except that names and types are 286N/A * interned whenever requested.</p> 286N/A * Construct a new adapter. 286N/A * Set the embedded AttributeList. 286N/A * <p>This method must be invoked before any of the others 286N/A * @param The SAX1 attribute list (with qnames). 286N/A * Return the length of the attribute list. 286N/A * @return The number of attributes in the list. 286N/A * Return the Namespace URI of the specified attribute. 286N/A * @param The attribute's index. 286N/A * @return Always the empty string. 286N/A * Return the local name of the specified attribute. 286N/A * @param The attribute's index. 286N/A * @return Always the empty string. 286N/A * Return the qualified (prefixed) name of the specified attribute. 286N/A * @param The attribute's index. 286N/A * @return The attribute's qualified name, internalized. 286N/A * Return the type of the specified attribute. 286N/A * @param The attribute's index. 286N/A * @return The attribute's type as an internalized string. 286N/A * Return the value of the specified attribute. 286N/A * @param The attribute's index. 286N/A * @return The attribute's value. 286N/A * Look up an attribute index by Namespace name. 286N/A * @param uri The Namespace URI or the empty string. 286N/A * @param localName The local name. 286N/A * @return The attributes index, or -1 if none was found. 286N/A * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String) 286N/A * Look up an attribute index by qualified (prefixed) name. 286N/A * @param qName The qualified name. 286N/A * @return The attributes index, or -1 if none was found. 286N/A * Look up the type of an attribute by Namespace name. 286N/A * @param uri The Namespace URI 286N/A * @param localName The local name. 286N/A * @return The attribute's type as an internalized string. 286N/A * Look up the type of an attribute by qualified (prefixed) name. 286N/A * @param qName The qualified name. 286N/A * @return The attribute's type as an internalized string. 286N/A * Look up the value of an attribute by Namespace name. 286N/A * @param uri The Namespace URI 286N/A * @param localName The local name. 286N/A * @return The attribute's value. 286N/A * Look up the value of an attribute by qualified (prefixed) name. 286N/A * @param qName The qualified name. 286N/A * @return The attribute's value.