Commit 7a163ec0 by Anthony Green Committed by Tom Tromey

Makefile.am (ordinary_java_source_files): Add org/xml/sax/helpers/NewInstance.java.

2002-12-19  Anthony Green  <green@redhat.com>

	* Makefile.am (ordinary_java_source_files): Add
	org/xml/sax/helpers/NewInstance.java.
	* Makefile.in: Rebuilt.
	* org/xml/sax/package.html, org/xml/sax/ext/package.html,
	org/xml/sax/helpers/package.html: New files.
	* org/xml/sax/*: Upgrade to SAX 2.0.1 release from
	http://www.saxproject.org.

From-SVN: r60350
parent 51d6eed4
2002-12-19 Anthony Green <green@redhat.com>
* Makefile.am (ordinary_java_source_files): Add
org/xml/sax/helpers/NewInstance.java.
* Makefile.in: Rebuilt.
* org/xml/sax/package.html, org/xml/sax/ext/package.html,
org/xml/sax/helpers/package.html: New files.
* org/xml/sax/*: Upgrade to SAX 2.0.1 release from
http://www.saxproject.org.
2002-12-19 Andrew Haley <aph@redhat.com> 2002-12-19 Andrew Haley <aph@redhat.com>
* java/util/natResourceBundle.cc: Include * java/util/natResourceBundle.cc: Include
......
...@@ -2252,6 +2252,7 @@ org/xml/sax/helpers/AttributesImpl.java \ ...@@ -2252,6 +2252,7 @@ org/xml/sax/helpers/AttributesImpl.java \
org/xml/sax/helpers/DefaultHandler.java \ org/xml/sax/helpers/DefaultHandler.java \
org/xml/sax/helpers/LocatorImpl.java \ org/xml/sax/helpers/LocatorImpl.java \
org/xml/sax/helpers/NamespaceSupport.java \ org/xml/sax/helpers/NamespaceSupport.java \
org/xml/sax/helpers/NewInstance.java \
org/xml/sax/helpers/ParserAdapter.java \ org/xml/sax/helpers/ParserAdapter.java \
org/xml/sax/helpers/ParserFactory.java \ org/xml/sax/helpers/ParserFactory.java \
org/xml/sax/helpers/XMLFilterImpl.java \ org/xml/sax/helpers/XMLFilterImpl.java \
......
...@@ -2002,6 +2002,7 @@ org/xml/sax/helpers/AttributesImpl.java \ ...@@ -2002,6 +2002,7 @@ org/xml/sax/helpers/AttributesImpl.java \
org/xml/sax/helpers/DefaultHandler.java \ org/xml/sax/helpers/DefaultHandler.java \
org/xml/sax/helpers/LocatorImpl.java \ org/xml/sax/helpers/LocatorImpl.java \
org/xml/sax/helpers/NamespaceSupport.java \ org/xml/sax/helpers/NamespaceSupport.java \
org/xml/sax/helpers/NewInstance.java \
org/xml/sax/helpers/ParserAdapter.java \ org/xml/sax/helpers/ParserAdapter.java \
org/xml/sax/helpers/ParserFactory.java \ org/xml/sax/helpers/ParserFactory.java \
org/xml/sax/helpers/XMLFilterImpl.java \ org/xml/sax/helpers/XMLFilterImpl.java \
...@@ -3701,6 +3702,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ ...@@ -3701,6 +3702,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/org/xml/sax/helpers/DefaultHandler.P \ .deps/org/xml/sax/helpers/DefaultHandler.P \
.deps/org/xml/sax/helpers/LocatorImpl.P \ .deps/org/xml/sax/helpers/LocatorImpl.P \
.deps/org/xml/sax/helpers/NamespaceSupport.P \ .deps/org/xml/sax/helpers/NamespaceSupport.P \
.deps/org/xml/sax/helpers/NewInstance.P \
.deps/org/xml/sax/helpers/ParserAdapter.P \ .deps/org/xml/sax/helpers/ParserAdapter.P \
.deps/org/xml/sax/helpers/ParserFactory.P \ .deps/org/xml/sax/helpers/ParserFactory.P \
.deps/org/xml/sax/helpers/XMLFilterImpl.P \ .deps/org/xml/sax/helpers/XMLFilterImpl.P \
......
// SAX Attribute List Interface. // SAX Attribute List Interface.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: AttributeList.java,v 1.1 2000/10/02 02:43:16 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: AttributeList.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Interface for an element's attribute specifications. /**
* * Interface for an element's attribute specifications.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This is the original SAX1 interface for reporting an element's * for further information.
* attributes. Unlike the new {@link org.xml.sax.Attributes Attributes} * </blockquote>
* interface, it does not support Namespace-related information.</p> *
* * <p>This is the original SAX1 interface for reporting an element's
* <p>When an attribute list is supplied as part of a * attributes. Unlike the new {@link org.xml.sax.Attributes Attributes}
* {@link org.xml.sax.DocumentHandler#startElement startElement} * interface, it does not support Namespace-related information.</p>
* event, the list will return valid results only during the *
* scope of the event; once the event handler returns control * <p>When an attribute list is supplied as part of a
* to the parser, the attribute list is invalid. To save a * {@link org.xml.sax.DocumentHandler#startElement startElement}
* persistent copy of the attribute list, use the SAX1 * event, the list will return valid results only during the
* {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl} * scope of the event; once the event handler returns control
* helper class.</p> * to the parser, the attribute list is invalid. To save a
* * persistent copy of the attribute list, use the SAX1
* <p>An attribute list includes only attributes that have been * {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
* specified or defaulted: #IMPLIED attributes will not be included.</p> * helper class.</p>
* *
* <p>There are two ways for the SAX application to obtain information * <p>An attribute list includes only attributes that have been
* from the AttributeList. First, it can iterate through the entire * specified or defaulted: #IMPLIED attributes will not be included.</p>
* list:</p> *
* * <p>There are two ways for the SAX application to obtain information
* <pre> * from the AttributeList. First, it can iterate through the entire
* public void startElement (String name, AttributeList atts) { * list:</p>
* for (int i = 0; i < atts.getLength(); i++) { *
* String name = atts.getName(i); * <pre>
* String type = atts.getType(i); * public void startElement (String name, AttributeList atts) {
* String value = atts.getValue(i); * for (int i = 0; i < atts.getLength(); i++) {
* [...] * String name = atts.getName(i);
* } * String type = atts.getType(i);
* } * String value = atts.getValue(i);
* </pre> * [...]
* * }
* <p>(Note that the result of getLength() will be zero if there * }
* are no attributes.) * </pre>
* *
* <p>As an alternative, the application can request the value or * <p>(Note that the result of getLength() will be zero if there
* type of specific attributes:</p> * are no attributes.)
* *
* <pre> * <p>As an alternative, the application can request the value or
* public void startElement (String name, AttributeList atts) { * type of specific attributes:</p>
* String identifier = atts.getValue("id"); *
* String label = atts.getValue("label"); * <pre>
* [...] * public void startElement (String name, AttributeList atts) {
* } * String identifier = atts.getValue("id");
* </pre> * String label = atts.getValue("label");
* * [...]
* @deprecated This interface has been replaced by the SAX2 * }
* {@link org.xml.sax.Attributes Attributes} * </pre>
* interface, which includes Namespace support. *
* @since SAX 1.0 * @deprecated This interface has been replaced by the SAX2
* @author David Megginson, * {@link org.xml.sax.Attributes Attributes}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * interface, which includes Namespace support.
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.DocumentHandler#startElement startElement * @author David Megginson
* @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.DocumentHandler#startElement startElement
public interface AttributeList { * @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
*/
public interface AttributeList {
////////////////////////////////////////////////////////////////////
// Iteration methods.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Iteration methods.
////////////////////////////////////////////////////////////////////
/**
* Return the number of attributes in this list.
* /**
* <p>The SAX parser may provide attributes in any * Return the number of attributes in this list.
* arbitrary order, regardless of the order in which they were *
* declared or specified. The number of attributes may be * <p>The SAX parser may provide attributes in any
* zero.</p> * arbitrary order, regardless of the order in which they were
* * declared or specified. The number of attributes may be
* @return The number of attributes in the list. * zero.</p>
*/ *
public abstract int getLength (); * @return The number of attributes in the list.
*/
public abstract int getLength ();
/**
* Return the name of an attribute in this list (by position).
* /**
* <p>The names must be unique: the SAX parser shall not include the * Return the name of an attribute in this list (by position).
* same attribute twice. Attributes without values (those declared *
* #IMPLIED without a value specified in the start tag) will be * <p>The names must be unique: the SAX parser shall not include the
* omitted from the list.</p> * same attribute twice. Attributes without values (those declared
* * #IMPLIED without a value specified in the start tag) will be
* <p>If the attribute name has a namespace prefix, the prefix * omitted from the list.</p>
* will still be attached.</p> *
* * <p>If the attribute name has a namespace prefix, the prefix
* @param i The index of the attribute in the list (starting at 0). * will still be attached.</p>
* @return The name of the indexed attribute, or null *
* if the index is out of range. * @param i The index of the attribute in the list (starting at 0).
* @see #getLength * @return The name of the indexed attribute, or null
*/ * if the index is out of range.
public abstract String getName (int i); * @see #getLength
*/
public abstract String getName (int i);
/**
* Return the type of an attribute in the list (by position).
* /**
* <p>The attribute type is one of the strings "CDATA", "ID", * Return the type of an attribute in the list (by position).
* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", *
* or "NOTATION" (always in upper case).</p> * <p>The attribute type is one of the strings "CDATA", "ID",
* * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
* <p>If the parser has not read a declaration for the attribute, * or "NOTATION" (always in upper case).</p>
* or if the parser does not report attribute types, then it must *
* return the value "CDATA" as stated in the XML 1.0 Recommentation * <p>If the parser has not read a declaration for the attribute,
* (clause 3.3.3, "Attribute-Value Normalization").</p> * or if the parser does not report attribute types, then it must
* * return the value "CDATA" as stated in the XML 1.0 Recommentation
* <p>For an enumerated attribute that is not a notation, the * (clause 3.3.3, "Attribute-Value Normalization").</p>
* parser will report the type as "NMTOKEN".</p> *
* * <p>For an enumerated attribute that is not a notation, the
* @param i The index of the attribute in the list (starting at 0). * parser will report the type as "NMTOKEN".</p>
* @return The attribute type as a string, or *
* null if the index is out of range. * @param i The index of the attribute in the list (starting at 0).
* @see #getLength * @return The attribute type as a string, or
* @see #getType(java.lang.String) * null if the index is out of range.
*/ * @see #getLength
public abstract String getType (int i); * @see #getType(java.lang.String)
*/
public abstract String getType (int i);
/**
* Return the value of an attribute in the list (by position).
* /**
* <p>If the attribute value is a list of tokens (IDREFS, * Return the value of an attribute in the list (by position).
* ENTITIES, or NMTOKENS), the tokens will be concatenated *
* into a single string separated by whitespace.</p> * <p>If the attribute value is a list of tokens (IDREFS,
* * ENTITIES, or NMTOKENS), the tokens will be concatenated
* @param i The index of the attribute in the list (starting at 0). * into a single string separated by whitespace.</p>
* @return The attribute value as a string, or *
* null if the index is out of range. * @param i The index of the attribute in the list (starting at 0).
* @see #getLength * @return The attribute value as a string, or
* @see #getValue(java.lang.String) * null if the index is out of range.
*/ * @see #getLength
public abstract String getValue (int i); * @see #getValue(java.lang.String)
*/
public abstract String getValue (int i);
////////////////////////////////////////////////////////////////////
// Lookup methods.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Lookup methods.
////////////////////////////////////////////////////////////////////
/**
* Return the type of an attribute in the list (by name).
* /**
* <p>The return value is the same as the return value for * Return the type of an attribute in the list (by name).
* getType(int).</p> *
* * <p>The return value is the same as the return value for
* <p>If the attribute name has a namespace prefix in the document, * getType(int).</p>
* the application must include the prefix here.</p> *
* * <p>If the attribute name has a namespace prefix in the document,
* @param name The name of the attribute. * the application must include the prefix here.</p>
* @return The attribute type as a string, or null if no *
* such attribute exists. * @param name The name of the attribute.
* @see #getType(int) * @return The attribute type as a string, or null if no
*/ * such attribute exists.
public abstract String getType (String name); * @see #getType(int)
*/
public abstract String getType (String name);
/**
* Return the value of an attribute in the list (by name).
* /**
* <p>The return value is the same as the return value for * Return the value of an attribute in the list (by name).
* getValue(int).</p> *
* * <p>The return value is the same as the return value for
* <p>If the attribute name has a namespace prefix in the document, * getValue(int).</p>
* the application must include the prefix here.</p> *
* * <p>If the attribute name has a namespace prefix in the document,
* @param i The index of the attribute in the list. * the application must include the prefix here.</p>
* @return The attribute value as a string, or null if *
* no such attribute exists. * @param i The index of the attribute in the list.
* @see #getValue(int) * @return The attribute value as a string, or null if
*/ * no such attribute exists.
public abstract String getValue (String name); * @see #getValue(int)
*/
} public abstract String getValue (String name);
// end of AttributeList.java }
// end of AttributeList.java
// Attributes.java - attribute list with Namespace support // Attributes.java - attribute list with Namespace support
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the public domain. // Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: Attributes.java,v 1.1 2000/10/02 02:43:16 sboag Exp $
// $Id: Attributes.java,v 1.5.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Interface for a list of XML attributes. /**
* * Interface for a list of XML attributes.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This interface allows access to a list of attributes in * for further information.
* three different ways:</p> * </blockquote>
* *
* <ol> * <p>This interface allows access to a list of attributes in
* <li>by attribute index;</li> * three different ways:</p>
* <li>by Namespace-qualified name; or</li> *
* <li>by qualified (prefixed) name.</li> * <ol>
* </ol> * <li>by attribute index;</li>
* * <li>by Namespace-qualified name; or</li>
* <p>The list will not contain attributes that were declared * <li>by qualified (prefixed) name.</li>
* #IMPLIED but not specified in the start tag. It will also not * </ol>
* contain attributes used as Namespace declarations (xmlns*) unless *
* the <code>http://xml.org/sax/features/namespace-prefixes</code> * <p>The list will not contain attributes that were declared
* feature is set to <var>true</var> (it is <var>false</var> by * #IMPLIED but not specified in the start tag. It will also not
* default).</p> * contain attributes used as Namespace declarations (xmlns*) unless
* * the <code>http://xml.org/sax/features/namespace-prefixes</code>
* <p>If the namespace-prefixes feature (see above) is <var>false</var>, * feature is set to <var>true</var> (it is <var>false</var> by
* access by qualified name may not be available; if the * default).
* <code>http://xml.org/sax/features/namespaces</code> * Because SAX2 conforms to the "Namespaces in XML" specification,
* feature is <var>false</var>, access by Namespace-qualified names * it does not give namespace declaration attributes a namespace URI.
* may not be available.</p> * Some other W3C specifications are in conflict with that, expecting
* * these declarations to be in a namespace.
* <p>This interface replaces the now-deprecated SAX1 {@link * Handler code may need to resolve that conflict.
* org.xml.sax.AttributeList AttributeList} interface, which does not * </p>
* contain Namespace support. In addition to Namespace support, it *
* adds the <var>getIndex</var> methods (below).</p> * <p>If the namespace-prefixes feature (see above) is <var>false</var>,
* * access by qualified name may not be available; if the
* <p>The order of attributes in the list is unspecified, and will * <code>http://xml.org/sax/features/namespaces</code>
* vary from implementation to implementation.</p> * feature is <var>false</var>, access by Namespace-qualified names
* * may not be available.</p>
* @since SAX 2.0 *
* @author David Megginson, * <p>This interface replaces the now-deprecated SAX1 {@link
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * org.xml.sax.AttributeList AttributeList} interface, which does not
* @version 2.0 * contain Namespace support. In addition to Namespace support, it
* @see org.xml.sax.helpers.AttributeListImpl * adds the <var>getIndex</var> methods (below).</p>
*/ *
public interface Attributes * <p>The order of attributes in the list is unspecified, and will
{ * vary from implementation to implementation.</p>
*
* @since SAX 2.0
//////////////////////////////////////////////////////////////////// * @author David Megginson
// Indexed access. * @version 2.0.1 (sax2r2)
//////////////////////////////////////////////////////////////////// * @see org.xml.sax.helpers.AttributesImpl
* @see org.xml.sax.ext.DeclHandler#attributeDecl
*/
/** public interface Attributes
* Return the number of attributes in the list. {
*
* <p>Once you know the number of attributes, you can iterate
* through the list.</p> ////////////////////////////////////////////////////////////////////
* // Indexed access.
* @return The number of attributes in the list. ////////////////////////////////////////////////////////////////////
* @see #getURI(int)
* @see #getLocalName(int)
* @see #getQName(int) /**
* @see #getType(int) * Return the number of attributes in the list.
* @see #getValue(int) *
*/ * <p>Once you know the number of attributes, you can iterate
public abstract int getLength (); * through the list.</p>
*
* @return The number of attributes in the list.
/** * @see #getURI(int)
* Look up an attribute's Namespace URI by index. * @see #getLocalName(int)
* * @see #getQName(int)
* @param index The attribute index (zero-based). * @see #getType(int)
* @return The Namespace URI, or the empty string if none * @see #getValue(int)
* is available, or null if the index is out of */
* range. public abstract int getLength ();
* @see #getLength
*/
public abstract String getURI (int index); /**
* Look up an attribute's Namespace URI by index.
*
/** * @param index The attribute index (zero-based).
* Look up an attribute's local name by index. * @return The Namespace URI, or the empty string if none
* * is available, or null if the index is out of
* @param index The attribute index (zero-based). * range.
* @return The local name, or the empty string if Namespace * @see #getLength
* processing is not being performed, or null */
* if the index is out of range. public abstract String getURI (int index);
* @see #getLength
*/
public abstract String getLocalName (int index); /**
* Look up an attribute's local name by index.
*
/** * @param index The attribute index (zero-based).
* Look up an attribute's XML 1.0 qualified name by index. * @return The local name, or the empty string if Namespace
* * processing is not being performed, or null
* @param index The attribute index (zero-based). * if the index is out of range.
* @return The XML 1.0 qualified name, or the empty string * @see #getLength
* if none is available, or null if the index */
* is out of range. public abstract String getLocalName (int index);
* @see #getLength
*/
public abstract String getQName (int index); /**
* Look up an attribute's XML 1.0 qualified name by index.
*
/** * @param index The attribute index (zero-based).
* Look up an attribute's type by index. * @return The XML 1.0 qualified name, or the empty string
* * if none is available, or null if the index
* <p>The attribute type is one of the strings "CDATA", "ID", * is out of range.
* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", * @see #getLength
* or "NOTATION" (always in upper case).</p> */
* public abstract String getQName (int index);
* <p>If the parser has not read a declaration for the attribute,
* or if the parser does not report attribute types, then it must
* return the value "CDATA" as stated in the XML 1.0 Recommentation /**
* (clause 3.3.3, "Attribute-Value Normalization").</p> * Look up an attribute's type by index.
* *
* <p>For an enumerated attribute that is not a notation, the * <p>The attribute type is one of the strings "CDATA", "ID",
* parser will report the type as "NMTOKEN".</p> * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
* * or "NOTATION" (always in upper case).</p>
* @param index The attribute index (zero-based). *
* @return The attribute's type as a string, or null if the * <p>If the parser has not read a declaration for the attribute,
* index is out of range. * or if the parser does not report attribute types, then it must
* @see #getLength * return the value "CDATA" as stated in the XML 1.0 Recommentation
*/ * (clause 3.3.3, "Attribute-Value Normalization").</p>
public abstract String getType (int index); *
* <p>For an enumerated attribute that is not a notation, the
* parser will report the type as "NMTOKEN".</p>
/** *
* Look up an attribute's value by index. * @param index The attribute index (zero-based).
* * @return The attribute's type as a string, or null if the
* <p>If the attribute value is a list of tokens (IDREFS, * index is out of range.
* ENTITIES, or NMTOKENS), the tokens will be concatenated * @see #getLength
* into a single string with each token separated by a */
* single space.</p> public abstract String getType (int index);
*
* @param index The attribute index (zero-based).
* @return The attribute's value as a string, or null if the /**
* index is out of range. * Look up an attribute's value by index.
* @see #getLength *
*/ * <p>If the attribute value is a list of tokens (IDREFS,
public abstract String getValue (int index); * ENTITIES, or NMTOKENS), the tokens will be concatenated
* into a single string with each token separated by a
* single space.</p>
*
//////////////////////////////////////////////////////////////////// * @param index The attribute index (zero-based).
// Name-based query. * @return The attribute's value as a string, or null if the
//////////////////////////////////////////////////////////////////// * index is out of range.
* @see #getLength
*/
/** public abstract String getValue (int index);
* Look up the index of an attribute by Namespace name.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI. ////////////////////////////////////////////////////////////////////
* @param localName The attribute's local name. // Name-based query.
* @return The index of the attribute, or -1 if it does not ////////////////////////////////////////////////////////////////////
* appear in the list.
*/
public int getIndex (String uri, String localPart); /**
* Look up the index of an attribute by Namespace name.
*
/** * @param uri The Namespace URI, or the empty string if
* Look up the index of an attribute by XML 1.0 qualified name. * the name has no Namespace URI.
* * @param localName The attribute's local name.
* @param qName The qualified (prefixed) name. * @return The index of the attribute, or -1 if it does not
* @return The index of the attribute, or -1 if it does not * appear in the list.
* appear in the list. */
*/ public int getIndex (String uri, String localName);
public int getIndex (String qName);
/**
/** * Look up the index of an attribute by XML 1.0 qualified name.
* Look up an attribute's type by Namespace name. *
* * @param qName The qualified (prefixed) name.
* <p>See {@link #getType(int) getType(int)} for a description * @return The index of the attribute, or -1 if it does not
* of the possible types.</p> * appear in the list.
* */
* @param uri The Namespace URI, or the empty String if the public int getIndex (String qName);
* name has no Namespace URI.
* @param localName The local name of the attribute.
* @return The attribute type as a string, or null if the /**
* attribute is not in the list or if Namespace * Look up an attribute's type by Namespace name.
* processing is not being performed. *
*/ * <p>See {@link #getType(int) getType(int)} for a description
public abstract String getType (String uri, String localName); * of the possible types.</p>
*
* @param uri The Namespace URI, or the empty String if the
/** * name has no Namespace URI.
* Look up an attribute's type by XML 1.0 qualified name. * @param localName The local name of the attribute.
* * @return The attribute type as a string, or null if the
* <p>See {@link #getType(int) getType(int)} for a description * attribute is not in the list or if Namespace
* of the possible types.</p> * processing is not being performed.
* */
* @param qName The XML 1.0 qualified name. public abstract String getType (String uri, String localName);
* @return The attribute type as a string, or null if the
* attribute is not in the list or if qualified names
* are not available. /**
*/ * Look up an attribute's type by XML 1.0 qualified name.
public abstract String getType (String qName); *
* <p>See {@link #getType(int) getType(int)} for a description
* of the possible types.</p>
/** *
* Look up an attribute's value by Namespace name. * @param qName The XML 1.0 qualified name.
* * @return The attribute type as a string, or null if the
* <p>See {@link #getValue(int) getValue(int)} for a description * attribute is not in the list or if qualified names
* of the possible values.</p> * are not available.
* */
* @param uri The Namespace URI, or the empty String if the public abstract String getType (String qName);
* name has no Namespace URI.
* @param localName The local name of the attribute.
* @return The attribute value as a string, or null if the /**
* attribute is not in the list. * Look up an attribute's value by Namespace name.
*/ *
public abstract String getValue (String uri, String localName); * <p>See {@link #getValue(int) getValue(int)} for a description
* of the possible values.</p>
*
/** * @param uri The Namespace URI, or the empty String if the
* Look up an attribute's value by XML 1.0 qualified name. * name has no Namespace URI.
* * @param localName The local name of the attribute.
* <p>See {@link #getValue(int) getValue(int)} for a description * @return The attribute value as a string, or null if the
* of the possible values.</p> * attribute is not in the list.
* */
* @param qName The XML 1.0 qualified name. public abstract String getValue (String uri, String localName);
* @return The attribute value as a string, or null if the
* attribute is not in the list or if qualified names
* are not available. /**
*/ * Look up an attribute's value by XML 1.0 qualified name.
public abstract String getValue (String qName); *
* <p>See {@link #getValue(int) getValue(int)} for a description
} * of the possible values.</p>
*
// end of Attributes.java * @param qName The XML 1.0 qualified name.
* @return The attribute value as a string, or null if the
* attribute is not in the list or if qualified names
* are not available.
*/
public abstract String getValue (String qName);
}
// end of Attributes.java
// ContentHandler.java - handle main document content. // ContentHandler.java - handle main document content.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the public domain. // Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: ContentHandler.java,v 1.1 2000/10/02 02:43:16 sboag Exp $
// $Id: ContentHandler.java,v 1.4.2.9 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Receive notification of the logical content of a document. /**
* * Receive notification of the logical content of a document.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This is the main interface that most SAX applications * for further information.
* implement: if the application needs to be informed of basic parsing * </blockquote>
* events, it implements this interface and registers an instance with *
* the SAX parser using the {@link org.xml.sax.XMLReader#setContentHandler * <p>This is the main interface that most SAX applications
* setContentHandler} method. The parser uses the instance to report * implement: if the application needs to be informed of basic parsing
* basic document-related events like the start and end of elements * events, it implements this interface and registers an instance with
* and character data.</p> * the SAX parser using the {@link org.xml.sax.XMLReader#setContentHandler
* * setContentHandler} method. The parser uses the instance to report
* <p>The order of events in this interface is very important, and * basic document-related events like the start and end of elements
* mirrors the order of information in the document itself. For * and character data.</p>
* example, all of an element's content (character data, processing *
* instructions, and/or subelements) will appear, in order, between * <p>The order of events in this interface is very important, and
* the startElement event and the corresponding endElement event.</p> * mirrors the order of information in the document itself. For
* * example, all of an element's content (character data, processing
* <p>This interface is similar to the now-deprecated SAX 1.0 * instructions, and/or subelements) will appear, in order, between
* DocumentHandler interface, but it adds support for Namespaces * the startElement event and the corresponding endElement event.</p>
* and for reporting skipped entities (in non-validating XML *
* processors).</p> * <p>This interface is similar to the now-deprecated SAX 1.0
* * DocumentHandler interface, but it adds support for Namespaces
* <p>Implementors should note that there is also a Java class * and for reporting skipped entities (in non-validating XML
* {@link java.net.ContentHandler ContentHandler} in the java.net * processors).</p>
* package; that means that it's probably a bad idea to do</p> *
* * <p>Implementors should note that there is also a Java class
* <blockquote> * {@link java.net.ContentHandler ContentHandler} in the java.net
* import java.net.*; * package; that means that it's probably a bad idea to do</p>
* import org.xml.sax.*; *
* </blockquote> * <blockquote>
* * import java.net.*;
* <p>In fact, "import ...*" is usually a sign of sloppy programming * import org.xml.sax.*;
* anyway, so the user should consider this a feature rather than a * </blockquote>
* bug.</p> *
* * <p>In fact, "import ...*" is usually a sign of sloppy programming
* @since SAX 2.0 * anyway, so the user should consider this a feature rather than a
* @author David Megginson, * bug.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.XMLReader * @author David Megginson
* @see org.xml.sax.DTDHandler * @version 2.0.1 (sax2r2)
* @see org.xml.sax.ErrorHandler * @see org.xml.sax.XMLReader
*/ * @see org.xml.sax.DTDHandler
public interface ContentHandler * @see org.xml.sax.ErrorHandler
{ */
public interface ContentHandler
/** {
* Receive an object for locating the origin of SAX document events.
* /**
* <p>SAX parsers are strongly encouraged (though not absolutely * Receive an object for locating the origin of SAX document events.
* required) to supply a locator: if it does so, it must supply *
* the locator to the application by invoking this method before * <p>SAX parsers are strongly encouraged (though not absolutely
* invoking any of the other methods in the ContentHandler * required) to supply a locator: if it does so, it must supply
* interface.</p> * the locator to the application by invoking this method before
* * invoking any of the other methods in the ContentHandler
* <p>The locator allows the application to determine the end * interface.</p>
* position of any document-related event, even if the parser is *
* not reporting an error. Typically, the application will * <p>The locator allows the application to determine the end
* use this information for reporting its own errors (such as * position of any document-related event, even if the parser is
* character content that does not match an application's * not reporting an error. Typically, the application will
* business rules). The information returned by the locator * use this information for reporting its own errors (such as
* is probably not sufficient for use with a search engine.</p> * character content that does not match an application's
* * business rules). The information returned by the locator
* <p>Note that the locator will return correct information only * is probably not sufficient for use with a search engine.</p>
* during the invocation of the events in this interface. The *
* application should not attempt to use it at any other time.</p> * <p>Note that the locator will return correct information only
* * during the invocation of the events in this interface. The
* @param locator An object that can return the location of * application should not attempt to use it at any other time.</p>
* any SAX document event. *
* @see org.xml.sax.Locator * @param locator An object that can return the location of
*/ * any SAX document event.
public void setDocumentLocator (Locator locator); * @see org.xml.sax.Locator
*/
public void setDocumentLocator (Locator locator);
/**
* Receive notification of the beginning of a document.
* /**
* <p>The SAX parser will invoke this method only once, before any * Receive notification of the beginning of a document.
* other methods in this interface or in {@link org.xml.sax.DTDHandler *
* DTDHandler} (except for {@link #setDocumentLocator * <p>The SAX parser will invoke this method only once, before any
* setDocumentLocator}).</p> * other event callbacks (except for {@link #setDocumentLocator
* * setDocumentLocator}).</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see #endDocument * wrapping another exception.
*/ * @see #endDocument
public void startDocument () */
throws SAXException; public void startDocument ()
throws SAXException;
/**
* Receive notification of the end of a document. /**
* * Receive notification of the end of a document.
* <p>The SAX parser will invoke this method only once, and it will *
* be the last method invoked during the parse. The parser shall * <p>The SAX parser will invoke this method only once, and it will
* not invoke this method until it has either abandoned parsing * be the last method invoked during the parse. The parser shall
* (because of an unrecoverable error) or reached the end of * not invoke this method until it has either abandoned parsing
* input.</p> * (because of an unrecoverable error) or reached the end of
* * input.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see #startDocument * wrapping another exception.
*/ * @see #startDocument
public void endDocument() */
throws SAXException; public void endDocument()
throws SAXException;
/**
* Begin the scope of a prefix-URI Namespace mapping. /**
* * Begin the scope of a prefix-URI Namespace mapping.
* <p>The information from this event is not necessary for *
* normal Namespace processing: the SAX XML reader will * <p>The information from this event is not necessary for
* automatically replace prefixes for element and attribute * normal Namespace processing: the SAX XML reader will
* names when the <code>http://xml.org/sax/features/namespaces</code> * automatically replace prefixes for element and attribute
* feature is <var>true</var> (the default).</p> * names when the <code>http://xml.org/sax/features/namespaces</code>
* * feature is <var>true</var> (the default).</p>
* <p>There are cases, however, when applications need to *
* use prefixes in character data or in attribute values, * <p>There are cases, however, when applications need to
* where they cannot safely be expanded automatically; the * use prefixes in character data or in attribute values,
* start/endPrefixMapping event supplies the information * where they cannot safely be expanded automatically; the
* to the application to expand prefixes in those contexts * start/endPrefixMapping event supplies the information
* itself, if necessary.</p> * to the application to expand prefixes in those contexts
* * itself, if necessary.</p>
* <p>Note that start/endPrefixMapping events are not *
* guaranteed to be properly nested relative to each-other: * <p>Note that start/endPrefixMapping events are not
* all startPrefixMapping events will occur before the * guaranteed to be properly nested relative to each other:
* corresponding {@link #startElement startElement} event, * all startPrefixMapping events will occur immediately before the
* and all {@link #endPrefixMapping endPrefixMapping} * corresponding {@link #startElement startElement} event,
* events will occur after the corresponding {@link #endElement * and all {@link #endPrefixMapping endPrefixMapping}
* endElement} event, but their order is not otherwise * events will occur immediately after the corresponding
* guaranteed.</p> * {@link #endElement endElement} event,
* * but their order is not otherwise
* <p>There should never be start/endPrefixMapping events for the * guaranteed.</p>
* "xml" prefix, since it is predeclared and immutable.</p> *
* * <p>There should never be start/endPrefixMapping events for the
* @param prefix The Namespace prefix being declared. * "xml" prefix, since it is predeclared and immutable.</p>
* @param uri The Namespace URI the prefix is mapped to. *
* @exception org.xml.sax.SAXException The client may throw * @param prefix The Namespace prefix being declared.
* an exception during processing. * An empty string is used for the default element namespace,
* @see #endPrefixMapping * which has no prefix.
* @see #startElement * @param uri The Namespace URI the prefix is mapped to.
*/ * @exception org.xml.sax.SAXException The client may throw
public void startPrefixMapping (String prefix, String uri) * an exception during processing.
throws SAXException; * @see #endPrefixMapping
* @see #startElement
*/
/** public void startPrefixMapping (String prefix, String uri)
* End the scope of a prefix-URI mapping. throws SAXException;
*
* <p>See {@link #startPrefixMapping startPrefixMapping} for
* details. This event will always occur after the corresponding /**
* {@link #endElement endElement} event, but the order of * End the scope of a prefix-URI mapping.
* {@link #endPrefixMapping endPrefixMapping} events is not otherwise *
* guaranteed.</p> * <p>See {@link #startPrefixMapping startPrefixMapping} for
* * details. These events will always occur immediately after the
* @param prefix The prefix that was being mapping. * corresponding {@link #endElement endElement} event, but the order of
* @exception org.xml.sax.SAXException The client may throw * {@link #endPrefixMapping endPrefixMapping} events is not otherwise
* an exception during processing. * guaranteed.</p>
* @see #startPrefixMapping *
* @see #endElement * @param prefix The prefix that was being mapping.
*/ * This is the empty string when a default mapping scope ends.
public void endPrefixMapping (String prefix) * @exception org.xml.sax.SAXException The client may throw
throws SAXException; * an exception during processing.
* @see #startPrefixMapping
* @see #endElement
/** */
* Receive notification of the beginning of an element. public void endPrefixMapping (String prefix)
* throws SAXException;
* <p>The Parser will invoke this method at the beginning of every
* element in the XML document; there will be a corresponding
* {@link #endElement endElement} event for every startElement event /**
* (even when the element is empty). All of the element's content will be * Receive notification of the beginning of an element.
* reported, in order, before the corresponding endElement *
* event.</p> * <p>The Parser will invoke this method at the beginning of every
* * element in the XML document; there will be a corresponding
* <p>This event allows up to three name components for each * {@link #endElement endElement} event for every startElement event
* element:</p> * (even when the element is empty). All of the element's content will be
* * reported, in order, before the corresponding endElement
* <ol> * event.</p>
* <li>the Namespace URI;</li> *
* <li>the local name; and</li> * <p>This event allows up to three name components for each
* <li>the qualified (prefixed) name.</li> * element:</p>
* </ol> *
* * <ol>
* <p>Any or all of these may be provided, depending on the * <li>the Namespace URI;</li>
* values of the <var>http://xml.org/sax/features/namespaces</var> * <li>the local name; and</li>
* and the <var>http://xml.org/sax/features/namespace-prefixes</var> * <li>the qualified (prefixed) name.</li>
* properties:</p> * </ol>
* *
* <ul> * <p>Any or all of these may be provided, depending on the
* <li>the Namespace URI and local name are required when * values of the <var>http://xml.org/sax/features/namespaces</var>
* the namespaces property is <var>true</var> (the default), and are * and the <var>http://xml.org/sax/features/namespace-prefixes</var>
* optional when the namespaces property is <var>false</var> (if one is * properties:</p>
* specified, both must be);</li> *
* <li>the qualified name is required when the namespace-prefixes property * <ul>
* is <var>true</var>, and is optional when the namespace-prefixes property * <li>the Namespace URI and local name are required when
* is <var>false</var> (the default).</li> * the namespaces property is <var>true</var> (the default), and are
* </ul> * optional when the namespaces property is <var>false</var> (if one is
* * specified, both must be);</li>
* <p>Note that the attribute list provided will contain only * <li>the qualified name is required when the namespace-prefixes property
* attributes with explicit values (specified or defaulted): * is <var>true</var>, and is optional when the namespace-prefixes property
* #IMPLIED attributes will be omitted. The attribute list * is <var>false</var> (the default).</li>
* will contain attributes used for Namespace declarations * </ul>
* (xmlns* attributes) only if the *
* <code>http://xml.org/sax/features/namespace-prefixes</code> * <p>Note that the attribute list provided will contain only
* property is true (it is false by default, and support for a * attributes with explicit values (specified or defaulted):
* true value is optional).</p> * #IMPLIED attributes will be omitted. The attribute list
* * will contain attributes used for Namespace declarations
* @param uri The Namespace URI, or the empty string if the * (xmlns* attributes) only if the
* element has no Namespace URI or if Namespace * <code>http://xml.org/sax/features/namespace-prefixes</code>
* processing is not being performed. * property is true (it is false by default, and support for a
* @param localName The local name (without prefix), or the * true value is optional).</p>
* empty string if Namespace processing is not being *
* performed. * <p>Like {@link #characters characters()}, attribute values may have
* @param qName The qualified name (with prefix), or the * characters that need more than one <code>char</code> value. </p>
* empty string if qualified names are not available. *
* @param atts The attributes attached to the element. If * @param uri The Namespace URI, or the empty string if the
* there are no attributes, it shall be an empty * element has no Namespace URI or if Namespace
* Attributes object. * processing is not being performed.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param localName The local name (without prefix), or the
* wrapping another exception. * empty string if Namespace processing is not being
* @see #endElement * performed.
* @see org.xml.sax.Attributes * @param qName The qualified name (with prefix), or the
*/ * empty string if qualified names are not available.
public void startElement (String namespaceURI, String localName, * @param atts The attributes attached to the element. If
String qName, Attributes atts) * there are no attributes, it shall be an empty
throws SAXException; * Attributes object.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
/** * @see #endElement
* Receive notification of the end of an element. * @see org.xml.sax.Attributes
* */
* <p>The SAX parser will invoke this method at the end of every public void startElement (String uri, String localName,
* element in the XML document; there will be a corresponding String qName, Attributes atts)
* {@link #startElement startElement} event for every endElement throws SAXException;
* event (even when the element is empty).</p>
*
* <p>For information on the names, see startElement.</p> /**
* * Receive notification of the end of an element.
* @param uri The Namespace URI, or the empty string if the *
* element has no Namespace URI or if Namespace * <p>The SAX parser will invoke this method at the end of every
* processing is not being performed. * element in the XML document; there will be a corresponding
* @param localName The local name (without prefix), or the * {@link #startElement startElement} event for every endElement
* empty string if Namespace processing is not being * event (even when the element is empty).</p>
* performed. *
* @param qName The qualified XML 1.0 name (with prefix), or the * <p>For information on the names, see startElement.</p>
* empty string if qualified names are not available. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param uri The Namespace URI, or the empty string if the
* wrapping another exception. * element has no Namespace URI or if Namespace
*/ * processing is not being performed.
public void endElement (String namespaceURI, String localName, * @param localName The local name (without prefix), or the
String qName) * empty string if Namespace processing is not being
throws SAXException; * performed.
* @param qName The qualified XML 1.0 name (with prefix), or the
* empty string if qualified names are not available.
/** * @exception org.xml.sax.SAXException Any SAX exception, possibly
* Receive notification of character data. * wrapping another exception.
* */
* <p>The Parser will call this method to report each chunk of public void endElement (String uri, String localName,
* character data. SAX parsers may return all contiguous character String qName)
* data in a single chunk, or they may split it into several throws SAXException;
* chunks; however, all of the characters in any single event
* must come from the same external entity so that the Locator
* provides useful information.</p> /**
* * Receive notification of character data.
* <p>The application must not attempt to read from the array *
* outside of the specified range.</p> * <p>The Parser will call this method to report each chunk of
* * character data. SAX parsers may return all contiguous character
* <p>Note that some parsers will report whitespace in element * data in a single chunk, or they may split it into several
* content using the {@link #ignorableWhitespace ignorableWhitespace} * chunks; however, all of the characters in any single event
* method rather than this one (validating parsers <em>must</em> * must come from the same external entity so that the Locator
* do so).</p> * provides useful information.</p>
* *
* @param ch The characters from the XML document. * <p>The application must not attempt to read from the array
* @param start The start position in the array. * outside of the specified range.</p>
* @param length The number of characters to read from the array. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * <p>Individual characters may consist of more than one Java
* wrapping another exception. * <code>char</code> value. There are two important cases where this
* @see #ignorableWhitespace * happens, because characters can't be represented in just sixteen bits.
* @see org.xml.sax.Locator * In one case, characters are represented in a <em>Surrogate Pair</em>,
*/ * using two special Unicode values. Such characters are in the so-called
public void characters (char ch[], int start, int length) * "Astral Planes", with a code point above U+FFFF. A second case involves
throws SAXException; * composite characters, such as a base character combining with one or
* more accent characters. </p>
*
/** * <p> Your code should not assume that algorithms using
* Receive notification of ignorable whitespace in element content. * <code>char</code>-at-a-time idioms will be working in character
* * units; in some cases they will split characters. This is relevant
* <p>Validating Parsers must use this method to report each chunk * wherever XML permits arbitrary characters, such as attribute values,
* of whitespace in element content (see the W3C XML 1.0 recommendation, * processing instruction data, and comments as well as in data reported
* section 2.10): non-validating parsers may also use this method * from this method. It's also generally relevant whenever Java code
* if they are capable of parsing and using content models.</p> * manipulates internationalized text; the issue isn't unique to XML.</p>
* *
* <p>SAX parsers may return all contiguous whitespace in a single * <p>Note that some parsers will report whitespace in element
* chunk, or they may split it into several chunks; however, all of * content using the {@link #ignorableWhitespace ignorableWhitespace}
* the characters in any single event must come from the same * method rather than this one (validating parsers <em>must</em>
* external entity, so that the Locator provides useful * do so).</p>
* information.</p> *
* * @param ch The characters from the XML document.
* <p>The application must not attempt to read from the array * @param start The start position in the array.
* outside of the specified range.</p> * @param length The number of characters to read from the array.
* * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @param ch The characters from the XML document. * wrapping another exception.
* @param start The start position in the array. * @see #ignorableWhitespace
* @param length The number of characters to read from the array. * @see org.xml.sax.Locator
* @exception org.xml.sax.SAXException Any SAX exception, possibly */
* wrapping another exception. public void characters (char ch[], int start, int length)
* @see #characters throws SAXException;
*/
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException; /**
* Receive notification of ignorable whitespace in element content.
*
/** * <p>Validating Parsers must use this method to report each chunk
* Receive notification of a processing instruction. * of whitespace in element content (see the W3C XML 1.0 recommendation,
* * section 2.10): non-validating parsers may also use this method
* <p>The Parser will invoke this method once for each processing * if they are capable of parsing and using content models.</p>
* instruction found: note that processing instructions may occur *
* before or after the main document element.</p> * <p>SAX parsers may return all contiguous whitespace in a single
* * chunk, or they may split it into several chunks; however, all of
* <p>A SAX parser must never report an XML declaration (XML 1.0, * the characters in any single event must come from the same
* section 2.8) or a text declaration (XML 1.0, section 4.3.1) * external entity, so that the Locator provides useful
* using this method.</p> * information.</p>
* *
* @param target The processing instruction target. * <p>The application must not attempt to read from the array
* @param data The processing instruction data, or null if * outside of the specified range.</p>
* none was supplied. The data does not include any *
* whitespace separating it from the target. * @param ch The characters from the XML document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param start The start position in the array.
* wrapping another exception. * @param length The number of characters to read from the array.
*/ * @exception org.xml.sax.SAXException Any SAX exception, possibly
public void processingInstruction (String target, String data) * wrapping another exception.
throws SAXException; * @see #characters
*/
public void ignorableWhitespace (char ch[], int start, int length)
/** throws SAXException;
* Receive notification of a skipped entity.
*
* <p>The Parser will invoke this method once for each entity /**
* skipped. Non-validating processors may skip entities if they * Receive notification of a processing instruction.
* have not seen the declarations (because, for example, the *
* entity was declared in an external DTD subset). All processors * <p>The Parser will invoke this method once for each processing
* may skip external entities, depending on the values of the * instruction found: note that processing instructions may occur
* <code>http://xml.org/sax/features/external-general-entities</code> * before or after the main document element.</p>
* and the *
* <code>http://xml.org/sax/features/external-parameter-entities</code> * <p>A SAX parser must never report an XML declaration (XML 1.0,
* properties.</p> * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
* * using this method.</p>
* @param name The name of the skipped entity. If it is a *
* parameter entity, the name will begin with '%', and if * <p>Like {@link #characters characters()}, processing instruction
* it is the external DTD subset, it will be the string * data may have characters that need more than one <code>char</code>
* "[dtd]". * value. </p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param target The processing instruction target.
*/ * @param data The processing instruction data, or null if
public void skippedEntity (String name) * none was supplied. The data does not include any
throws SAXException; * whitespace separating it from the target.
} * @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
// end of ContentHandler.java */
public void processingInstruction (String target, String data)
throws SAXException;
/**
* Receive notification of a skipped entity.
* This is not called for entity references within markup constructs
* such as element start tags or markup declarations. (The XML
* recommendation requires reporting skipped external entities.
* SAX also reports internal entity expansion/non-expansion, except
* within markup constructs.)
*
* <p>The Parser will invoke this method each time the entity is
* skipped. Non-validating processors may skip entities if they
* have not seen the declarations (because, for example, the
* entity was declared in an external DTD subset). All processors
* may skip external entities, depending on the values of the
* <code>http://xml.org/sax/features/external-general-entities</code>
* and the
* <code>http://xml.org/sax/features/external-parameter-entities</code>
* properties.</p>
*
* @param name The name of the skipped entity. If it is a
* parameter entity, the name will begin with '%', and if
* it is the external DTD subset, it will be the string
* "[dtd]".
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
public void skippedEntity (String name)
throws SAXException;
}
// end of ContentHandler.java
// SAX DTD handler. // SAX DTD handler.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: DTDHandler.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: DTDHandler.java,v 1.5.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Receive notification of basic DTD-related events. /**
* * Receive notification of basic DTD-related events.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>If a SAX application needs information about notations and * for further information.
* unparsed entities, then the application implements this * </blockquote>
* interface and registers an instance with the SAX parser using *
* the parser's setDTDHandler method. The parser uses the * <p>If a SAX application needs information about notations and
* instance to report notation and unparsed entity declarations to * unparsed entities, then the application implements this
* the application.</p> * interface and registers an instance with the SAX parser using
* * the parser's setDTDHandler method. The parser uses the
* <p>Note that this interface includes only those DTD events that * instance to report notation and unparsed entity declarations to
* the XML recommendation <em>requires</em> processors to report: * the application.</p>
* notation and unparsed entity declarations.</p> *
* * <p>Note that this interface includes only those DTD events that
* <p>The SAX parser may report these events in any order, regardless * the XML recommendation <em>requires</em> processors to report:
* of the order in which the notations and unparsed entities were * notation and unparsed entity declarations.</p>
* declared; however, all DTD events must be reported after the *
* document handler's startDocument event, and before the first * <p>The SAX parser may report these events in any order, regardless
* startElement event.</p> * of the order in which the notations and unparsed entities were
* * declared; however, all DTD events must be reported after the
* <p>It is up to the application to store the information for * document handler's startDocument event, and before the first
* future use (perhaps in a hash table or object tree). * startElement event.
* If the application encounters attributes of type "NOTATION", * (If the {@link org.xml.sax.ext.LexicalHandler LexicalHandler} is
* "ENTITY", or "ENTITIES", it can use the information that it * used, these events must also be reported before the endDTD event.)
* obtained through this interface to find the entity and/or * </p>
* notation corresponding with the attribute value.</p> *
* * <p>It is up to the application to store the information for
* @since SAX 1.0 * future use (perhaps in a hash table or object tree).
* @author David Megginson, * If the application encounters attributes of type "NOTATION",
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * "ENTITY", or "ENTITIES", it can use the information that it
* @version 2.0 * obtained through this interface to find the entity and/or
* @see org.xml.sax.Parser#setDTDHandler * notation corresponding with the attribute value.</p>
* @see org.xml.sax.HandlerBase *
*/ * @since SAX 1.0
public interface DTDHandler { * @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.XMLReader#setDTDHandler
/** */
* Receive notification of a notation declaration event. public interface DTDHandler {
*
* <p>It is up to the application to record the notation for later
* reference, if necessary.</p> /**
* * Receive notification of a notation declaration event.
* <p>At least one of publicId and systemId must be non-null. *
* If a system identifier is present, and it is a URL, the SAX * <p>It is up to the application to record the notation for later
* parser must resolve it fully before passing it to the * reference, if necessary;
* application through this event.</p> * notations may appear as attribute values and in unparsed entity
* * declarations, and are sometime used with processing instruction
* <p>There is no guarantee that the notation declaration will be * target names.</p>
* reported before any unparsed entities that use it.</p> *
* * <p>At least one of publicId and systemId must be non-null.
* @param name The notation name. * If a system identifier is present, and it is a URL, the SAX
* @param publicId The notation's public identifier, or null if * parser must resolve it fully before passing it to the
* none was given. * application through this event.</p>
* @param systemId The notation's system identifier, or null if *
* none was given. * <p>There is no guarantee that the notation declaration will be
* @exception org.xml.sax.SAXException Any SAX exception, possibly * reported before any unparsed entities that use it.</p>
* wrapping another exception. *
* @see #unparsedEntityDecl * @param name The notation name.
* @see org.xml.sax.AttributeList * @param publicId The notation's public identifier, or null if
*/ * none was given.
public abstract void notationDecl (String name, * @param systemId The notation's system identifier, or null if
String publicId, * none was given.
String systemId) * @exception org.xml.sax.SAXException Any SAX exception, possibly
throws SAXException; * wrapping another exception.
* @see #unparsedEntityDecl
* @see org.xml.sax.Attributes
/** */
* Receive notification of an unparsed entity declaration event. public abstract void notationDecl (String name,
* String publicId,
* <p>Note that the notation name corresponds to a notation String systemId)
* reported by the {@link #notationDecl notationDecl} event. throws SAXException;
* It is up to the application to record the entity for later
* reference, if necessary.</p>
* /**
* <p>If the system identifier is a URL, the parser must resolve it * Receive notification of an unparsed entity declaration event.
* fully before passing it to the application.</p> *
* * <p>Note that the notation name corresponds to a notation
* @exception org.xml.sax.SAXException Any SAX exception, possibly * reported by the {@link #notationDecl notationDecl} event.
* wrapping another exception. * It is up to the application to record the entity for later
* @param name The unparsed entity's name. * reference, if necessary;
* @param publicId The entity's public identifier, or null if none * unparsed entities may appear as attribute values.
* was given. * </p>
* @param systemId The entity's system identifier. *
* @param notation name The name of the associated notation. * <p>If the system identifier is a URL, the parser must resolve it
* @see #notationDecl * fully before passing it to the application.</p>
* @see org.xml.sax.AttributeList *
*/ * @exception org.xml.sax.SAXException Any SAX exception, possibly
public abstract void unparsedEntityDecl (String name, * wrapping another exception.
String publicId, * @param name The unparsed entity's name.
String systemId, * @param publicId The entity's public identifier, or null if none
String notationName) * was given.
throws SAXException; * @param systemId The entity's system identifier.
* @param notationName The name of the associated notation.
} * @see #notationDecl
* @see org.xml.sax.Attributes
// end of DTDHandler.java */
public abstract void unparsedEntityDecl (String name,
String publicId,
String systemId,
String notationName)
throws SAXException;
}
// end of DTDHandler.java
// SAX document handler. // SAX document handler.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: DocumentHandler.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: DocumentHandler.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Receive notification of general document events. /**
* * Receive notification of general document events.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This was the main event-handling interface for SAX1; in * for further information.
* SAX2, it has been replaced by {@link org.xml.sax.ContentHandler * </blockquote>
* ContentHandler}, which provides Namespace support and reporting *
* of skipped entities. This interface is included in SAX2 only * <p>This was the main event-handling interface for SAX1; in
* to support legacy SAX1 applications.</p> * SAX2, it has been replaced by {@link org.xml.sax.ContentHandler
* * ContentHandler}, which provides Namespace support and reporting
* <p>The order of events in this interface is very important, and * of skipped entities. This interface is included in SAX2 only
* mirrors the order of information in the document itself. For * to support legacy SAX1 applications.</p>
* example, all of an element's content (character data, processing *
* instructions, and/or subelements) will appear, in order, between * <p>The order of events in this interface is very important, and
* the startElement event and the corresponding endElement event.</p> * mirrors the order of information in the document itself. For
* * example, all of an element's content (character data, processing
* <p>Application writers who do not want to implement the entire * instructions, and/or subelements) will appear, in order, between
* interface can derive a class from HandlerBase, which implements * the startElement event and the corresponding endElement event.</p>
* the default functionality; parser writers can instantiate *
* HandlerBase to obtain a default handler. The application can find * <p>Application writers who do not want to implement the entire
* the location of any document event using the Locator interface * interface can derive a class from HandlerBase, which implements
* supplied by the Parser through the setDocumentLocator method.</p> * the default functionality; parser writers can instantiate
* * HandlerBase to obtain a default handler. The application can find
* @deprecated This interface has been replaced by the SAX2 * the location of any document event using the Locator interface
* {@link org.xml.sax.ContentHandler ContentHandler} * supplied by the Parser through the setDocumentLocator method.</p>
* interface, which includes Namespace support. *
* @since SAX 1.0 * @deprecated This interface has been replaced by the SAX2
* @author David Megginson, * {@link org.xml.sax.ContentHandler ContentHandler}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * interface, which includes Namespace support.
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.Parser#setDocumentHandler * @author David Megginson
* @see org.xml.sax.Locator * @version 2.0.1 (sax2r2)
* @see org.xml.sax.HandlerBase * @see org.xml.sax.Parser#setDocumentHandler
*/ * @see org.xml.sax.Locator
public interface DocumentHandler { * @see org.xml.sax.HandlerBase
*/
public interface DocumentHandler {
/**
* Receive an object for locating the origin of SAX document events.
* /**
* <p>SAX parsers are strongly encouraged (though not absolutely * Receive an object for locating the origin of SAX document events.
* required) to supply a locator: if it does so, it must supply *
* the locator to the application by invoking this method before * <p>SAX parsers are strongly encouraged (though not absolutely
* invoking any of the other methods in the DocumentHandler * required) to supply a locator: if it does so, it must supply
* interface.</p> * the locator to the application by invoking this method before
* * invoking any of the other methods in the DocumentHandler
* <p>The locator allows the application to determine the end * interface.</p>
* position of any document-related event, even if the parser is *
* not reporting an error. Typically, the application will * <p>The locator allows the application to determine the end
* use this information for reporting its own errors (such as * position of any document-related event, even if the parser is
* character content that does not match an application's * not reporting an error. Typically, the application will
* business rules). The information returned by the locator * use this information for reporting its own errors (such as
* is probably not sufficient for use with a search engine.</p> * character content that does not match an application's
* * business rules). The information returned by the locator
* <p>Note that the locator will return correct information only * is probably not sufficient for use with a search engine.</p>
* during the invocation of the events in this interface. The *
* application should not attempt to use it at any other time.</p> * <p>Note that the locator will return correct information only
* * during the invocation of the events in this interface. The
* @param locator An object that can return the location of * application should not attempt to use it at any other time.</p>
* any SAX document event. *
* @see org.xml.sax.Locator * @param locator An object that can return the location of
*/ * any SAX document event.
public abstract void setDocumentLocator (Locator locator); * @see org.xml.sax.Locator
*/
public abstract void setDocumentLocator (Locator locator);
/**
* Receive notification of the beginning of a document.
* /**
* <p>The SAX parser will invoke this method only once, before any * Receive notification of the beginning of a document.
* other methods in this interface or in DTDHandler (except for *
* setDocumentLocator).</p> * <p>The SAX parser will invoke this method only once, before any
* * other methods in this interface or in DTDHandler (except for
* @exception org.xml.sax.SAXException Any SAX exception, possibly * setDocumentLocator).</p>
* wrapping another exception. *
*/ * @exception org.xml.sax.SAXException Any SAX exception, possibly
public abstract void startDocument () * wrapping another exception.
throws SAXException; */
public abstract void startDocument ()
throws SAXException;
/**
* Receive notification of the end of a document.
* /**
* <p>The SAX parser will invoke this method only once, and it will * Receive notification of the end of a document.
* be the last method invoked during the parse. The parser shall *
* not invoke this method until it has either abandoned parsing * <p>The SAX parser will invoke this method only once, and it will
* (because of an unrecoverable error) or reached the end of * be the last method invoked during the parse. The parser shall
* input.</p> * not invoke this method until it has either abandoned parsing
* * (because of an unrecoverable error) or reached the end of
* @exception org.xml.sax.SAXException Any SAX exception, possibly * input.</p>
* wrapping another exception. *
*/ * @exception org.xml.sax.SAXException Any SAX exception, possibly
public abstract void endDocument () * wrapping another exception.
throws SAXException; */
public abstract void endDocument ()
throws SAXException;
/**
* Receive notification of the beginning of an element.
* /**
* <p>The Parser will invoke this method at the beginning of every * Receive notification of the beginning of an element.
* element in the XML document; there will be a corresponding *
* endElement() event for every startElement() event (even when the * <p>The Parser will invoke this method at the beginning of every
* element is empty). All of the element's content will be * element in the XML document; there will be a corresponding
* reported, in order, before the corresponding endElement() * endElement() event for every startElement() event (even when the
* event.</p> * element is empty). All of the element's content will be
* * reported, in order, before the corresponding endElement()
* <p>If the element name has a namespace prefix, the prefix will * event.</p>
* still be attached. Note that the attribute list provided will *
* contain only attributes with explicit values (specified or * <p>If the element name has a namespace prefix, the prefix will
* defaulted): #IMPLIED attributes will be omitted.</p> * still be attached. Note that the attribute list provided will
* * contain only attributes with explicit values (specified or
* @param name The element type name. * defaulted): #IMPLIED attributes will be omitted.</p>
* @param atts The attributes attached to the element, if any. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param name The element type name.
* wrapping another exception. * @param atts The attributes attached to the element, if any.
* @see #endElement * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see org.xml.sax.AttributeList * wrapping another exception.
*/ * @see #endElement
public abstract void startElement (String name, AttributeList atts) * @see org.xml.sax.AttributeList
throws SAXException; */
public abstract void startElement (String name, AttributeList atts)
throws SAXException;
/**
* Receive notification of the end of an element.
* /**
* <p>The SAX parser will invoke this method at the end of every * Receive notification of the end of an element.
* element in the XML document; there will be a corresponding *
* startElement() event for every endElement() event (even when the * <p>The SAX parser will invoke this method at the end of every
* element is empty).</p> * element in the XML document; there will be a corresponding
* * startElement() event for every endElement() event (even when the
* <p>If the element name has a namespace prefix, the prefix will * element is empty).</p>
* still be attached to the name.</p> *
* * <p>If the element name has a namespace prefix, the prefix will
* @param name The element type name * still be attached to the name.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param name The element type name
*/ * @exception org.xml.sax.SAXException Any SAX exception, possibly
public abstract void endElement (String name) * wrapping another exception.
throws SAXException; */
public abstract void endElement (String name)
throws SAXException;
/**
* Receive notification of character data.
* /**
* <p>The Parser will call this method to report each chunk of * Receive notification of character data.
* character data. SAX parsers may return all contiguous character *
* data in a single chunk, or they may split it into several * <p>The Parser will call this method to report each chunk of
* chunks; however, all of the characters in any single event * character data. SAX parsers may return all contiguous character
* must come from the same external entity, so that the Locator * data in a single chunk, or they may split it into several
* provides useful information.</p> * chunks; however, all of the characters in any single event
* * must come from the same external entity, so that the Locator
* <p>The application must not attempt to read from the array * provides useful information.</p>
* outside of the specified range.</p> *
* * <p>The application must not attempt to read from the array
* <p>Note that some parsers will report whitespace using the * outside of the specified range.</p>
* ignorableWhitespace() method rather than this one (validating *
* parsers must do so).</p> * <p>Note that some parsers will report whitespace using the
* * ignorableWhitespace() method rather than this one (validating
* @param ch The characters from the XML document. * parsers must do so).</p>
* @param start The start position in the array. *
* @param length The number of characters to read from the array. * @param ch The characters from the XML document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param start The start position in the array.
* wrapping another exception. * @param length The number of characters to read from the array.
* @see #ignorableWhitespace * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see org.xml.sax.Locator * wrapping another exception.
*/ * @see #ignorableWhitespace
public abstract void characters (char ch[], int start, int length) * @see org.xml.sax.Locator
throws SAXException; */
public abstract void characters (char ch[], int start, int length)
throws SAXException;
/**
* Receive notification of ignorable whitespace in element content.
* /**
* <p>Validating Parsers must use this method to report each chunk * Receive notification of ignorable whitespace in element content.
* of ignorable whitespace (see the W3C XML 1.0 recommendation, *
* section 2.10): non-validating parsers may also use this method * <p>Validating Parsers must use this method to report each chunk
* if they are capable of parsing and using content models.</p> * of ignorable whitespace (see the W3C XML 1.0 recommendation,
* * section 2.10): non-validating parsers may also use this method
* <p>SAX parsers may return all contiguous whitespace in a single * if they are capable of parsing and using content models.</p>
* chunk, or they may split it into several chunks; however, all of *
* the characters in any single event must come from the same * <p>SAX parsers may return all contiguous whitespace in a single
* external entity, so that the Locator provides useful * chunk, or they may split it into several chunks; however, all of
* information.</p> * the characters in any single event must come from the same
* * external entity, so that the Locator provides useful
* <p>The application must not attempt to read from the array * information.</p>
* outside of the specified range.</p> *
* * <p>The application must not attempt to read from the array
* @param ch The characters from the XML document. * outside of the specified range.</p>
* @param start The start position in the array. *
* @param length The number of characters to read from the array. * @param ch The characters from the XML document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param start The start position in the array.
* wrapping another exception. * @param length The number of characters to read from the array.
* @see #characters * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public abstract void ignorableWhitespace (char ch[], int start, int length) * @see #characters
throws SAXException; */
public abstract void ignorableWhitespace (char ch[], int start, int length)
throws SAXException;
/**
* Receive notification of a processing instruction.
* /**
* <p>The Parser will invoke this method once for each processing * Receive notification of a processing instruction.
* instruction found: note that processing instructions may occur *
* before or after the main document element.</p> * <p>The Parser will invoke this method once for each processing
* * instruction found: note that processing instructions may occur
* <p>A SAX parser should never report an XML declaration (XML 1.0, * before or after the main document element.</p>
* section 2.8) or a text declaration (XML 1.0, section 4.3.1) *
* using this method.</p> * <p>A SAX parser should never report an XML declaration (XML 1.0,
* * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
* @param target The processing instruction target. * using this method.</p>
* @param data The processing instruction data, or null if *
* none was supplied. * @param target The processing instruction target.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param data The processing instruction data, or null if
* wrapping another exception. * none was supplied.
*/ * @exception org.xml.sax.SAXException Any SAX exception, possibly
public abstract void processingInstruction (String target, String data) * wrapping another exception.
throws SAXException; */
public abstract void processingInstruction (String target, String data)
} throws SAXException;
// end of DocumentHandler.java }
// end of DocumentHandler.java
// SAX entity resolver. // SAX entity resolver.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: EntityResolver.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: EntityResolver.java,v 1.7.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
import java.io.IOException;
import java.io.IOException;
/**
* Basic interface for resolving entities. /**
* * Basic interface for resolving entities.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>If a SAX application needs to implement customized handling * for further information.
* for external entities, it must implement this interface and * </blockquote>
* register an instance with the SAX driver using the *
* {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver} * <p>If a SAX application needs to implement customized handling
* method.</p> * for external entities, it must implement this interface and
* * register an instance with the SAX driver using the
* <p>The XML reader will then allow the application to intercept any * {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
* external entities (including the external DTD subset and external * method.</p>
* parameter entities, if any) before including them.</p> *
* * <p>The XML reader will then allow the application to intercept any
* <p>Many SAX applications will not need to implement this interface, * external entities (including the external DTD subset and external
* but it will be especially useful for applications that build * parameter entities, if any) before including them.</p>
* XML documents from databases or other specialised input sources, *
* or for applications that use URI types other than URLs.</p> * <p>Many SAX applications will not need to implement this interface,
* * but it will be especially useful for applications that build
* <p>The following resolver would provide the application * XML documents from databases or other specialised input sources,
* with a special character stream for the entity with the system * or for applications that use URI types other than URLs.</p>
* identifier "http://www.myhost.com/today":</p> *
* * <p>The following resolver would provide the application
* <pre> * with a special character stream for the entity with the system
* import org.xml.sax.EntityResolver; * identifier "http://www.myhost.com/today":</p>
* import org.xml.sax.InputSource; *
* * <pre>
* public class MyResolver implements EntityResolver { * import org.xml.sax.EntityResolver;
* public InputSource resolveEntity (String publicId, String systemId) * import org.xml.sax.InputSource;
* { *
* if (systemId.equals("http://www.myhost.com/today")) { * public class MyResolver implements EntityResolver {
* // return a special input source * public InputSource resolveEntity (String publicId, String systemId)
* MyReader reader = new MyReader(); * {
* return new InputSource(reader); * if (systemId.equals("http://www.myhost.com/today")) {
* } else { * // return a special input source
* // use the default behaviour * MyReader reader = new MyReader();
* return null; * return new InputSource(reader);
* } * } else {
* } * // use the default behaviour
* } * return null;
* </pre> * }
* * }
* <p>The application can also use this interface to redirect system * }
* identifiers to local URIs or to look up replacements in a catalog * </pre>
* (possibly by using the public identifier).</p> *
* * <p>The application can also use this interface to redirect system
* @since SAX 1.0 * identifiers to local URIs or to look up replacements in a catalog
* @author David Megginson, * (possibly by using the public identifier).</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.Parser#setEntityResolver * @author David Megginson
* @see org.xml.sax.InputSource * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.XMLReader#setEntityResolver
public interface EntityResolver { * @see org.xml.sax.InputSource
*/
public interface EntityResolver {
/**
* Allow the application to resolve external entities.
* /**
* <p>The Parser will call this method before opening any external * Allow the application to resolve external entities.
* entity except the top-level document entity (including the *
* external DTD subset, external entities referenced within the * <p>The parser will call this method before opening any external
* DTD, and external entities referenced within the document * entity except the top-level document entity. Such entities include
* element): the application may request that the parser resolve * the external DTD subset and external parameter entities referenced
* the entity itself, that it use an alternative URI, or that it * within the DTD (in either case, only if the parser reads external
* use an entirely different input source.</p> * parameter entities), and external general entities referenced
* * within the document element (if the parser reads external general
* <p>Application writers can use this method to redirect external * entities). The application may request that the parser locate
* system identifiers to secure and/or local URIs, to look up * the entity itself, that it use an alternative URI, or that it
* public identifiers in a catalogue, or to read an entity from a * use data provided by the application (as a character or byte
* database or other input source (including, for example, a dialog * input stream).</p>
* box).</p> *
* * <p>Application writers can use this method to redirect external
* <p>If the system identifier is a URL, the SAX parser must * system identifiers to secure and/or local URIs, to look up
* resolve it fully before reporting it to the application.</p> * public identifiers in a catalogue, or to read an entity from a
* * database or other input source (including, for example, a dialog
* @param publicId The public identifier of the external entity * box). Neither XML nor SAX specifies a preferred policy for using
* being referenced, or null if none was supplied. * public or system IDs to resolve resources. However, SAX specifies
* @param systemId The system identifier of the external entity * how to interpret any InputSource returned by this method, and that
* being referenced. * if none is returned, then the system ID will be dereferenced as
* @return An InputSource object describing the new input source, * a URL. </p>
* or null to request that the parser open a regular *
* URI connection to the system identifier. * <p>If the system identifier is a URL, the SAX parser must
* @exception org.xml.sax.SAXException Any SAX exception, possibly * resolve it fully before reporting it to the application.</p>
* wrapping another exception. *
* @exception java.io.IOException A Java-specific IO exception, * @param publicId The public identifier of the external entity
* possibly the result of creating a new InputStream * being referenced, or null if none was supplied.
* or Reader for the InputSource. * @param systemId The system identifier of the external entity
* @see org.xml.sax.InputSource * being referenced.
*/ * @return An InputSource object describing the new input source,
public abstract InputSource resolveEntity (String publicId, * or null to request that the parser open a regular
String systemId) * URI connection to the system identifier.
throws SAXException, IOException; * @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
} * @exception java.io.IOException A Java-specific IO exception,
* possibly the result of creating a new InputStream
// end of EntityResolver.java * or Reader for the InputSource.
* @see org.xml.sax.InputSource
*/
public abstract InputSource resolveEntity (String publicId,
String systemId)
throws SAXException, IOException;
}
// end of EntityResolver.java
// SAX error handler. // SAX error handler.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: ErrorHandler.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: ErrorHandler.java,v 1.4.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Basic interface for SAX error handlers. /**
* * Basic interface for SAX error handlers.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>If a SAX application needs to implement customized error * for further information.
* handling, it must implement this interface and then register an * </blockquote>
* instance with the XML reader using the *
* {@link org.xml.sax.XMLReader#setErrorHandler setErrorHandler} * <p>If a SAX application needs to implement customized error
* method. The parser will then report all errors and warnings * handling, it must implement this interface and then register an
* through this interface.</p> * instance with the XML reader using the
* * {@link org.xml.sax.XMLReader#setErrorHandler setErrorHandler}
* <p><strong>WARNING:</strong> If an application does <em>not</em> * method. The parser will then report all errors and warnings
* register an ErrorHandler, XML parsing errors will go unreported * through this interface.</p>
* and bizarre behaviour may result.</p> *
* * <p><strong>WARNING:</strong> If an application does <em>not</em>
* <p>For XML processing errors, a SAX driver must use this interface * register an ErrorHandler, XML parsing errors will go unreported
* instead of throwing an exception: it is up to the application * and bizarre behaviour may result.</p>
* to decide whether to throw an exception for different types of *
* errors and warnings. Note, however, that there is no requirement that * <p>For XML processing errors, a SAX driver must use this interface
* the parser continue to provide useful information after a call to * instead of throwing an exception: it is up to the application
* {@link #fatalError fatalError} (in other words, a SAX driver class * to decide whether to throw an exception for different types of
* could catch an exception and report a fatalError).</p> * errors and warnings. Note, however, that there is no requirement that
* * the parser continue to provide useful information after a call to
* @since SAX 1.0 * {@link #fatalError fatalError} (in other words, a SAX driver class
* @author David Megginson, * could catch an exception and report a fatalError).</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.Parser#setErrorHandler * @author David Megginson
* @see org.xml.sax.SAXParseException * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.XMLReader#setErrorHandler
public interface ErrorHandler { * @see org.xml.sax.SAXParseException
*/
public interface ErrorHandler {
/**
* Receive notification of a warning.
* /**
* <p>SAX parsers will use this method to report conditions that * Receive notification of a warning.
* are not errors or fatal errors as defined by the XML 1.0 *
* recommendation. The default behaviour is to take no action.</p> * <p>SAX parsers will use this method to report conditions that
* * are not errors or fatal errors as defined by the XML 1.0
* <p>The SAX parser must continue to provide normal parsing events * recommendation. The default behaviour is to take no action.</p>
* after invoking this method: it should still be possible for the *
* application to process the document through to the end.</p> * <p>The SAX parser must continue to provide normal parsing events
* * after invoking this method: it should still be possible for the
* <p>Filters may use this method to report other, non-XML warnings * application to process the document through to the end.</p>
* as well.</p> *
* * <p>Filters may use this method to report other, non-XML warnings
* @param exception The warning information encapsulated in a * as well.</p>
* SAX parse exception. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param exception The warning information encapsulated in a
* wrapping another exception. * SAX parse exception.
* @see org.xml.sax.SAXParseException * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public abstract void warning (SAXParseException exception) * @see org.xml.sax.SAXParseException
throws SAXException; */
public abstract void warning (SAXParseException exception)
throws SAXException;
/**
* Receive notification of a recoverable error.
* /**
* <p>This corresponds to the definition of "error" in section 1.2 * Receive notification of a recoverable error.
* of the W3C XML 1.0 Recommendation. For example, a validating *
* parser would use this callback to report the violation of a * <p>This corresponds to the definition of "error" in section 1.2
* validity constraint. The default behaviour is to take no * of the W3C XML 1.0 Recommendation. For example, a validating
* action.</p> * parser would use this callback to report the violation of a
* * validity constraint. The default behaviour is to take no
* <p>The SAX parser must continue to provide normal parsing events * action.</p>
* after invoking this method: it should still be possible for the *
* application to process the document through to the end. If the * <p>The SAX parser must continue to provide normal parsing events
* application cannot do so, then the parser should report a fatal * after invoking this method: it should still be possible for the
* error even if the XML 1.0 recommendation does not require it to * application to process the document through to the end. If the
* do so.</p> * application cannot do so, then the parser should report a fatal
* * error even if the XML 1.0 recommendation does not require it to
* <p>Filters may use this method to report other, non-XML errors * do so.</p>
* as well.</p> *
* * <p>Filters may use this method to report other, non-XML errors
* @param exception The error information encapsulated in a * as well.</p>
* SAX parse exception. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param exception The error information encapsulated in a
* wrapping another exception. * SAX parse exception.
* @see org.xml.sax.SAXParseException * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public abstract void error (SAXParseException exception) * @see org.xml.sax.SAXParseException
throws SAXException; */
public abstract void error (SAXParseException exception)
throws SAXException;
/**
* Receive notification of a non-recoverable error.
* /**
* <p>This corresponds to the definition of "fatal error" in * Receive notification of a non-recoverable error.
* section 1.2 of the W3C XML 1.0 Recommendation. For example, a *
* parser would use this callback to report the violation of a * <p>This corresponds to the definition of "fatal error" in
* well-formedness constraint.</p> * section 1.2 of the W3C XML 1.0 Recommendation. For example, a
* * parser would use this callback to report the violation of a
* <p>The application must assume that the document is unusable * well-formedness constraint.</p>
* after the parser has invoked this method, and should continue *
* (if at all) only for the sake of collecting addition error * <p>The application must assume that the document is unusable
* messages: in fact, SAX parsers are free to stop reporting any * after the parser has invoked this method, and should continue
* other events once this method has been invoked.</p> * (if at all) only for the sake of collecting addition error
* * messages: in fact, SAX parsers are free to stop reporting any
* @param exception The error information encapsulated in a * other events once this method has been invoked.</p>
* SAX parse exception. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param exception The error information encapsulated in a
* wrapping another exception. * SAX parse exception.
* @see org.xml.sax.SAXParseException * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public abstract void fatalError (SAXParseException exception) * @see org.xml.sax.SAXParseException
throws SAXException; */
public abstract void fatalError (SAXParseException exception)
} throws SAXException;
// end of ErrorHandler.java }
// end of ErrorHandler.java
// SAX default handler base class. // SAX default handler base class.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: HandlerBase.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: HandlerBase.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Default base class for handlers. /**
* * Default base class for handlers.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class implements the default behaviour for four SAX1 * for further information.
* interfaces: EntityResolver, DTDHandler, DocumentHandler, * </blockquote>
* and ErrorHandler. It is now obsolete, but is included in SAX2 to *
* support legacy SAX1 applications. SAX2 applications should use * <p>This class implements the default behaviour for four SAX1
* the {@link org.xml.sax.helpers.DefaultHandler DefaultHandler} * interfaces: EntityResolver, DTDHandler, DocumentHandler,
* class instead.</p> * and ErrorHandler. It is now obsolete, but is included in SAX2 to
* * support legacy SAX1 applications. SAX2 applications should use
* <p>Application writers can extend this class when they need to * the {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
* implement only part of an interface; parser writers can * class instead.</p>
* instantiate this class to provide default handlers when the *
* application has not supplied its own.</p> * <p>Application writers can extend this class when they need to
* * implement only part of an interface; parser writers can
* <p>Note that the use of this class is optional.</p> * instantiate this class to provide default handlers when the
* * application has not supplied its own.</p>
* @deprecated This class works with the deprecated *
* {@link org.xml.sax.DocumentHandler DocumentHandler} * <p>Note that the use of this class is optional.</p>
* interface. It has been replaced by the SAX2 *
* {@link org.xml.sax.helpers.DefaultHandler DefaultHandler} * @deprecated This class works with the deprecated
* class. * {@link org.xml.sax.DocumentHandler DocumentHandler}
* @since SAX 1.0 * interface. It has been replaced by the SAX2
* @author David Megginson, * {@link org.xml.sax.helpers.DefaultHandler DefaultHandler}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * class.
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.EntityResolver * @author David Megginson
* @see org.xml.sax.DTDHandler * @version 2.0.1 (sax2r2)
* @see org.xml.sax.DocumentHandler * @see org.xml.sax.EntityResolver
* @see org.xml.sax.ErrorHandler * @see org.xml.sax.DTDHandler
*/ * @see org.xml.sax.DocumentHandler
public class HandlerBase * @see org.xml.sax.ErrorHandler
implements EntityResolver, DTDHandler, DocumentHandler, ErrorHandler */
{ public class HandlerBase
implements EntityResolver, DTDHandler, DocumentHandler, ErrorHandler
{
////////////////////////////////////////////////////////////////////
// Default implementation of the EntityResolver interface.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Default implementation of the EntityResolver interface.
/** ////////////////////////////////////////////////////////////////////
* Resolve an external entity.
* /**
* <p>Always return null, so that the parser will use the system * Resolve an external entity.
* identifier provided in the XML document. This method implements *
* the SAX default behaviour: application writers can override it * <p>Always return null, so that the parser will use the system
* in a subclass to do special translations such as catalog lookups * identifier provided in the XML document. This method implements
* or URI redirection.</p> * the SAX default behaviour: application writers can override it
* * in a subclass to do special translations such as catalog lookups
* @param publicId The public identifier, or null if none is * or URI redirection.</p>
* available. *
* @param systemId The system identifier provided in the XML * @param publicId The public identifer, or null if none is
* document. * available.
* @return The new input source, or null to require the * @param systemId The system identifier provided in the XML
* default behaviour. * document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @return The new input source, or null to require the
* wrapping another exception. * default behaviour.
* @see org.xml.sax.EntityResolver#resolveEntity * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public InputSource resolveEntity (String publicId, String systemId) * @see org.xml.sax.EntityResolver#resolveEntity
throws SAXException */
{ public InputSource resolveEntity (String publicId, String systemId)
return null; throws SAXException
} {
return null;
}
////////////////////////////////////////////////////////////////////
// Default implementation of DTDHandler interface.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Default implementation of DTDHandler interface.
////////////////////////////////////////////////////////////////////
/**
* Receive notification of a notation declaration.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of a notation declaration.
* method in a subclass if they wish to keep track of the notations *
* declared in a document.</p> * <p>By default, do nothing. Application writers may override this
* * method in a subclass if they wish to keep track of the notations
* @param name The notation name. * declared in a document.</p>
* @param publicId The notation public identifier, or null if not *
* available. * @param name The notation name.
* @param systemId The notation system identifier. * @param publicId The notation public identifier, or null if not
* @see org.xml.sax.DTDHandler#notationDecl * available.
*/ * @param systemId The notation system identifier.
public void notationDecl (String name, String publicId, String systemId) * @see org.xml.sax.DTDHandler#notationDecl
{ */
// no op public void notationDecl (String name, String publicId, String systemId)
} {
// no op
}
/**
* Receive notification of an unparsed entity declaration.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of an unparsed entity declaration.
* method in a subclass to keep track of the unparsed entities *
* declared in a document.</p> * <p>By default, do nothing. Application writers may override this
* * method in a subclass to keep track of the unparsed entities
* @param name The entity name. * declared in a document.</p>
* @param publicId The entity public identifier, or null if not *
* available. * @param name The entity name.
* @param systemId The entity system identifier. * @param publicId The entity public identifier, or null if not
* @param notationName The name of the associated notation. * available.
* @see org.xml.sax.DTDHandler#unparsedEntityDecl * @param systemId The entity system identifier.
*/ * @param notationName The name of the associated notation.
public void unparsedEntityDecl (String name, String publicId, * @see org.xml.sax.DTDHandler#unparsedEntityDecl
String systemId, String notationName) */
{ public void unparsedEntityDecl (String name, String publicId,
// no op String systemId, String notationName)
} {
// no op
}
////////////////////////////////////////////////////////////////////
// Default implementation of DocumentHandler interface.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Default implementation of DocumentHandler interface.
////////////////////////////////////////////////////////////////////
/**
* Receive a Locator object for document events.
* /**
* <p>By default, do nothing. Application writers may override this * Receive a Locator object for document events.
* method in a subclass if they wish to store the locator for use *
* with other document events.</p> * <p>By default, do nothing. Application writers may override this
* * method in a subclass if they wish to store the locator for use
* @param locator A locator for all SAX document events. * with other document events.</p>
* @see org.xml.sax.DocumentHandler#setDocumentLocator *
* @see org.xml.sax.Locator * @param locator A locator for all SAX document events.
*/ * @see org.xml.sax.DocumentHandler#setDocumentLocator
public void setDocumentLocator (Locator locator) * @see org.xml.sax.Locator
{ */
// no op public void setDocumentLocator (Locator locator)
} {
// no op
}
/**
* Receive notification of the beginning of the document.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of the beginning of the document.
* method in a subclass to take specific actions at the beginning *
* of a document (such as allocating the root node of a tree or * <p>By default, do nothing. Application writers may override this
* creating an output file).</p> * method in a subclass to take specific actions at the beginning
* * of a document (such as allocating the root node of a tree or
* @exception org.xml.sax.SAXException Any SAX exception, possibly * creating an output file).</p>
* wrapping another exception. *
* @see org.xml.sax.DocumentHandler#startDocument * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void startDocument () * @see org.xml.sax.DocumentHandler#startDocument
throws SAXException */
{ public void startDocument ()
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of the end of the document.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of the end of the document.
* method in a subclass to take specific actions at the beginning *
* of a document (such as finalising a tree or closing an output * <p>By default, do nothing. Application writers may override this
* file).</p> * method in a subclass to take specific actions at the beginning
* * of a document (such as finalising a tree or closing an output
* @exception org.xml.sax.SAXException Any SAX exception, possibly * file).</p>
* wrapping another exception. *
* @see org.xml.sax.DocumentHandler#endDocument * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void endDocument () * @see org.xml.sax.DocumentHandler#endDocument
throws SAXException */
{ public void endDocument ()
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of the start of an element.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of the start of an element.
* method in a subclass to take specific actions at the start of *
* each element (such as allocating a new tree node or writing * <p>By default, do nothing. Application writers may override this
* output to a file).</p> * method in a subclass to take specific actions at the start of
* * each element (such as allocating a new tree node or writing
* @param name The element type name. * output to a file).</p>
* @param attributes The specified or defaulted attributes. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param name The element type name.
* wrapping another exception. * @param attributes The specified or defaulted attributes.
* @see org.xml.sax.DocumentHandler#startElement * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void startElement (String name, AttributeList attributes) * @see org.xml.sax.DocumentHandler#startElement
throws SAXException */
{ public void startElement (String name, AttributeList attributes)
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of the end of an element.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of the end of an element.
* method in a subclass to take specific actions at the end of *
* each element (such as finalising a tree node or writing * <p>By default, do nothing. Application writers may override this
* output to a file).</p> * method in a subclass to take specific actions at the end of
* * each element (such as finalising a tree node or writing
* @param name The element type name. * output to a file).</p>
* @param attributes The specified or defaulted attributes. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param name The element type name.
* wrapping another exception. * @param attributes The specified or defaulted attributes.
* @see org.xml.sax.DocumentHandler#endElement * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void endElement (String name) * @see org.xml.sax.DocumentHandler#endElement
throws SAXException */
{ public void endElement (String name)
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of character data inside an element.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of character data inside an element.
* method to take specific actions for each chunk of character data *
* (such as adding the data to a node or buffer, or printing it to * <p>By default, do nothing. Application writers may override this
* a file).</p> * method to take specific actions for each chunk of character data
* * (such as adding the data to a node or buffer, or printing it to
* @param ch The characters. * a file).</p>
* @param start The start position in the character array. *
* @param length The number of characters to use from the * @param ch The characters.
* character array. * @param start The start position in the character array.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param length The number of characters to use from the
* wrapping another exception. * character array.
* @see org.xml.sax.DocumentHandler#characters * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void characters (char ch[], int start, int length) * @see org.xml.sax.DocumentHandler#characters
throws SAXException */
{ public void characters (char ch[], int start, int length)
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of ignorable whitespace in element content.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of ignorable whitespace in element content.
* method to take specific actions for each chunk of ignorable *
* whitespace (such as adding data to a node or buffer, or printing * <p>By default, do nothing. Application writers may override this
* it to a file).</p> * method to take specific actions for each chunk of ignorable
* * whitespace (such as adding data to a node or buffer, or printing
* @param ch The whitespace characters. * it to a file).</p>
* @param start The start position in the character array. *
* @param length The number of characters to use from the * @param ch The whitespace characters.
* character array. * @param start The start position in the character array.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param length The number of characters to use from the
* wrapping another exception. * character array.
* @see org.xml.sax.DocumentHandler#ignorableWhitespace * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void ignorableWhitespace (char ch[], int start, int length) * @see org.xml.sax.DocumentHandler#ignorableWhitespace
throws SAXException */
{ public void ignorableWhitespace (char ch[], int start, int length)
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of a processing instruction.
* /**
* <p>By default, do nothing. Application writers may override this * Receive notification of a processing instruction.
* method in a subclass to take specific actions for each *
* processing instruction, such as setting status variables or * <p>By default, do nothing. Application writers may override this
* invoking other methods.</p> * method in a subclass to take specific actions for each
* * processing instruction, such as setting status variables or
* @param target The processing instruction target. * invoking other methods.</p>
* @param data The processing instruction data, or null if *
* none is supplied. * @param target The processing instruction target.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param data The processing instruction data, or null if
* wrapping another exception. * none is supplied.
* @see org.xml.sax.DocumentHandler#processingInstruction * @exception org.xml.sax.SAXException Any SAX exception, possibly
*/ * wrapping another exception.
public void processingInstruction (String target, String data) * @see org.xml.sax.DocumentHandler#processingInstruction
throws SAXException */
{ public void processingInstruction (String target, String data)
// no op throws SAXException
} {
// no op
}
////////////////////////////////////////////////////////////////////
// Default implementation of the ErrorHandler interface.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Default implementation of the ErrorHandler interface.
////////////////////////////////////////////////////////////////////
/**
* Receive notification of a parser warning.
* /**
* <p>The default implementation does nothing. Application writers * Receive notification of a parser warning.
* may override this method in a subclass to take specific actions *
* for each warning, such as inserting the message in a log file or * <p>The default implementation does nothing. Application writers
* printing it to the console.</p> * may override this method in a subclass to take specific actions
* * for each warning, such as inserting the message in a log file or
* @param e The warning information encoded as an exception. * printing it to the console.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param e The warning information encoded as an exception.
* @see org.xml.sax.ErrorHandler#warning * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see org.xml.sax.SAXParseException * wrapping another exception.
*/ * @see org.xml.sax.ErrorHandler#warning
public void warning (SAXParseException e) * @see org.xml.sax.SAXParseException
throws SAXException */
{ public void warning (SAXParseException e)
// no op throws SAXException
} {
// no op
}
/**
* Receive notification of a recoverable parser error.
* /**
* <p>The default implementation does nothing. Application writers * Receive notification of a recoverable parser error.
* may override this method in a subclass to take specific actions *
* for each error, such as inserting the message in a log file or * <p>The default implementation does nothing. Application writers
* printing it to the console.</p> * may override this method in a subclass to take specific actions
* * for each error, such as inserting the message in a log file or
* @param e The warning information encoded as an exception. * printing it to the console.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param e The warning information encoded as an exception.
* @see org.xml.sax.ErrorHandler#warning * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see org.xml.sax.SAXParseException * wrapping another exception.
*/ * @see org.xml.sax.ErrorHandler#warning
public void error (SAXParseException e) * @see org.xml.sax.SAXParseException
throws SAXException */
{ public void error (SAXParseException e)
// no op throws SAXException
} {
// no op
}
/**
* Report a fatal XML parsing error.
* /**
* <p>The default implementation throws a SAXParseException. * Report a fatal XML parsing error.
* Application writers may override this method in a subclass if *
* they need to take specific actions for each fatal error (such as * <p>The default implementation throws a SAXParseException.
* collecting all of the errors into a single report): in any case, * Application writers may override this method in a subclass if
* the application must stop all regular processing when this * they need to take specific actions for each fatal error (such as
* method is invoked, since the document is no longer reliable, and * collecting all of the errors into a single report): in any case,
* the parser may no longer report parsing events.</p> * the application must stop all regular processing when this
* * method is invoked, since the document is no longer reliable, and
* @param e The error information encoded as an exception. * the parser may no longer report parsing events.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param e The error information encoded as an exception.
* @see org.xml.sax.ErrorHandler#fatalError * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see org.xml.sax.SAXParseException * wrapping another exception.
*/ * @see org.xml.sax.ErrorHandler#fatalError
public void fatalError (SAXParseException e) * @see org.xml.sax.SAXParseException
throws SAXException */
{ public void fatalError (SAXParseException e)
throw e; throws SAXException
} {
throw e;
} }
// end of HandlerBase.java }
// end of HandlerBase.java
// SAX input source. // SAX input source.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: InputSource.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: InputSource.java,v 1.5.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
import java.io.Reader;
import java.io.InputStream; import java.io.Reader;
import java.io.InputStream;
/**
* A single input source for an XML entity. /**
* * A single input source for an XML entity.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class allows a SAX application to encapsulate information * for further information.
* about an input source in a single object, which may include * </blockquote>
* a public identifier, a system identifier, a byte stream (possibly *
* with a specified encoding), and/or a character stream.</p> * <p>This class allows a SAX application to encapsulate information
* * about an input source in a single object, which may include
* <p>There are two places that the application will deliver this * a public identifier, a system identifier, a byte stream (possibly
* input source to the parser: as the argument to the Parser.parse * with a specified encoding), and/or a character stream.</p>
* method, or as the return value of the EntityResolver.resolveEntity *
* method.</p> * <p>There are two places that the application can deliver an
* * input source to the parser: as the argument to the Parser.parse
* <p>The SAX parser will use the InputSource object to determine how * method, or as the return value of the EntityResolver.resolveEntity
* to read XML input. If there is a character stream available, the * method.</p>
* parser will read that stream directly; if not, the parser will use *
* a byte stream, if available; if neither a character stream nor a * <p>The SAX parser will use the InputSource object to determine how
* byte stream is available, the parser will attempt to open a URI * to read XML input. If there is a character stream available, the
* connection to the resource identified by the system * parser will read that stream directly, disregarding any text
* identifier.</p> * encoding declaration found in that stream.
* * If there is no character stream, but there is
* <p>An InputSource object belongs to the application: the SAX parser * a byte stream, the parser will use that byte stream, using the
* shall never modify it in any way (it may modify a copy if * encoding specified in the InputSource or else (if no encoding is
* necessary).</p> * specified) autodetecting the character encoding using an algorithm
* * such as the one in the XML specification. If neither a character
* @since SAX 1.0 * stream nor a
* @author David Megginson, * byte stream is available, the parser will attempt to open a URI
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * connection to the resource identified by the system
* @version 2.0 * identifier.</p>
* @see org.xml.sax.Parser#parse *
* @see org.xml.sax.EntityResolver#resolveEntity * <p>An InputSource object belongs to the application: the SAX parser
* @see java.io.InputStream * shall never modify it in any way (it may modify a copy if
* @see java.io.Reader * necessary). However, standard processing of both byte and
*/ * character streams is to close them on as part of end-of-parse cleanup,
public class InputSource { * so applications should not attempt to re-use such streams after they
* have been handed to a parser. </p>
/** *
* Zero-argument default constructor. * @since SAX 1.0
* * @author David Megginson
* @see #setPublicId * @version 2.0.1 (sax2r2)
* @see #setSystemId * @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)
* @see #setByteStream * @see org.xml.sax.EntityResolver#resolveEntity
* @see #setCharacterStream * @see java.io.InputStream
* @see #setEncoding * @see java.io.Reader
*/ */
public InputSource () public class InputSource {
{
} /**
* Zero-argument default constructor.
*
/** * @see #setPublicId
* Create a new input source with a system identifier. * @see #setSystemId
* * @see #setByteStream
* <p>Applications may use setPublicId to include a * @see #setCharacterStream
* public identifier as well, or setEncoding to specify * @see #setEncoding
* the character encoding, if known.</p> */
* public InputSource ()
* <p>If the system identifier is a URL, it must be full resolved.</p> {
* }
* @param systemId The system identifier (URI).
* @see #setPublicId
* @see #setSystemId /**
* @see #setByteStream * Create a new input source with a system identifier.
* @see #setEncoding *
* @see #setCharacterStream * <p>Applications may use setPublicId to include a
*/ * public identifier as well, or setEncoding to specify
public InputSource (String systemId) * the character encoding, if known.</p>
{ *
setSystemId(systemId); * <p>If the system identifier is a URL, it must be fully
} * resolved (it may not be a relative URL).</p>
*
* @param systemId The system identifier (URI).
/** * @see #setPublicId
* Create a new input source with a byte stream. * @see #setSystemId
* * @see #setByteStream
* <p>Application writers may use setSystemId to provide a base * @see #setEncoding
* for resolving relative URIs, setPublicId to include a * @see #setCharacterStream
* public identifier, and/or setEncoding to specify the object's */
* character encoding.</p> public InputSource (String systemId)
* {
* @param byteStream The raw byte stream containing the document. setSystemId(systemId);
* @see #setPublicId }
* @see #setSystemId
* @see #setEncoding
* @see #setByteStream /**
* @see #setCharacterStream * Create a new input source with a byte stream.
*/ *
public InputSource (InputStream byteStream) * <p>Application writers should use setSystemId() to provide a base
{ * for resolving relative URIs, may use setPublicId to include a
setByteStream(byteStream); * public identifier, and may use setEncoding to specify the object's
} * character encoding.</p>
*
* @param byteStream The raw byte stream containing the document.
/** * @see #setPublicId
* Create a new input source with a character stream. * @see #setSystemId
* * @see #setEncoding
* <p>Application writers may use setSystemId() to provide a base * @see #setByteStream
* for resolving relative URIs, and setPublicId to include a * @see #setCharacterStream
* public identifier.</p> */
* public InputSource (InputStream byteStream)
* <p>The character stream shall not include a byte order mark.</p> {
* setByteStream(byteStream);
* @see #setPublicId }
* @see #setSystemId
* @see #setByteStream
* @see #setCharacterStream /**
*/ * Create a new input source with a character stream.
public InputSource (Reader characterStream) *
{ * <p>Application writers should use setSystemId() to provide a base
setCharacterStream(characterStream); * for resolving relative URIs, and may use setPublicId to include a
} * public identifier.</p>
*
* <p>The character stream shall not include a byte order mark.</p>
/** *
* Set the public identifier for this input source. * @see #setPublicId
* * @see #setSystemId
* <p>The public identifier is always optional: if the application * @see #setByteStream
* writer includes one, it will be provided as part of the * @see #setCharacterStream
* location information.</p> */
* public InputSource (Reader characterStream)
* @param publicId The public identifier as a string. {
* @see #getPublicId setCharacterStream(characterStream);
* @see org.xml.sax.Locator#getPublicId }
* @see org.xml.sax.SAXParseException#getPublicId
*/
public void setPublicId (String publicId) /**
{ * Set the public identifier for this input source.
this.publicId = publicId; *
} * <p>The public identifier is always optional: if the application
* writer includes one, it will be provided as part of the
* location information.</p>
/** *
* Get the public identifier for this input source. * @param publicId The public identifier as a string.
* * @see #getPublicId
* @return The public identifier, or null if none was supplied. * @see org.xml.sax.Locator#getPublicId
* @see #setPublicId * @see org.xml.sax.SAXParseException#getPublicId
*/ */
public String getPublicId () public void setPublicId (String publicId)
{ {
return publicId; this.publicId = publicId;
} }
/** /**
* Set the system identifier for this input source. * Get the public identifier for this input source.
* *
* <p>The system identifier is optional if there is a byte stream * @return The public identifier, or null if none was supplied.
* or a character stream, but it is still useful to provide one, * @see #setPublicId
* since the application can use it to resolve relative URIs */
* and can include it in error messages and warnings (the parser public String getPublicId ()
* will attempt to open a connection to the URI only if {
* there is no byte stream or character stream specified).</p> return publicId;
* }
* <p>If the application knows the character encoding of the
* object pointed to by the system identifier, it can register
* the encoding using the setEncoding method.</p> /**
* * Set the system identifier for this input source.
* <p>If the system ID is a URL, it must be fully resolved.</p> *
* * <p>The system identifier is optional if there is a byte stream
* @param systemId The system identifier as a string. * or a character stream, but it is still useful to provide one,
* @see #setEncoding * since the application can use it to resolve relative URIs
* @see #getSystemId * and can include it in error messages and warnings (the parser
* @see org.xml.sax.Locator#getSystemId * will attempt to open a connection to the URI only if
* @see org.xml.sax.SAXParseException#getSystemId * there is no byte stream or character stream specified).</p>
*/ *
public void setSystemId (String systemId) * <p>If the application knows the character encoding of the
{ * object pointed to by the system identifier, it can register
this.systemId = systemId; * the encoding using the setEncoding method.</p>
} *
* <p>If the system identifier is a URL, it must be fully
* resolved (it may not be a relative URL).</p>
/** *
* Get the system identifier for this input source. * @param systemId The system identifier as a string.
* * @see #setEncoding
* <p>The getEncoding method will return the character encoding * @see #getSystemId
* of the object pointed to, or null if unknown.</p> * @see org.xml.sax.Locator#getSystemId
* * @see org.xml.sax.SAXParseException#getSystemId
* <p>If the system ID is a URL, it will be fully resolved.</p> */
* public void setSystemId (String systemId)
* @return The system identifier. {
* @see #setSystemId this.systemId = systemId;
* @see #getEncoding }
*/
public String getSystemId ()
{ /**
return systemId; * Get the system identifier for this input source.
} *
* <p>The getEncoding method will return the character encoding
* of the object pointed to, or null if unknown.</p>
/** *
* Set the byte stream for this input source. * <p>If the system ID is a URL, it will be fully resolved.</p>
* *
* <p>The SAX parser will ignore this if there is also a character * @return The system identifier, or null if none was supplied.
* stream specified, but it will use a byte stream in preference * @see #setSystemId
* to opening a URI connection itself.</p> * @see #getEncoding
* */
* <p>If the application knows the character encoding of the public String getSystemId ()
* byte stream, it should set it with the setEncoding method.</p> {
* return systemId;
* @param byteStream A byte stream containing an XML document or }
* other entity.
* @see #setEncoding
* @see #getByteStream /**
* @see #getEncoding * Set the byte stream for this input source.
* @see java.io.InputStream *
*/ * <p>The SAX parser will ignore this if there is also a character
public void setByteStream (InputStream byteStream) * stream specified, but it will use a byte stream in preference
{ * to opening a URI connection itself.</p>
this.byteStream = byteStream; *
} * <p>If the application knows the character encoding of the
* byte stream, it should set it with the setEncoding method.</p>
*
/** * @param byteStream A byte stream containing an XML document or
* Get the byte stream for this input source. * other entity.
* * @see #setEncoding
* <p>The getEncoding method will return the character * @see #getByteStream
* encoding for this byte stream, or null if unknown.</p> * @see #getEncoding
* * @see java.io.InputStream
* @return The byte stream, or null if none was supplied. */
* @see #getEncoding public void setByteStream (InputStream byteStream)
* @see #setByteStream {
*/ this.byteStream = byteStream;
public InputStream getByteStream () }
{
return byteStream;
} /**
* Get the byte stream for this input source.
*
/** * <p>The getEncoding method will return the character
* Set the character encoding, if known. * encoding for this byte stream, or null if unknown.</p>
* *
* <p>The encoding must be a string acceptable for an * @return The byte stream, or null if none was supplied.
* XML encoding declaration (see section 4.3.3 of the XML 1.0 * @see #getEncoding
* recommendation).</p> * @see #setByteStream
* */
* <p>This method has no effect when the application provides a public InputStream getByteStream ()
* character stream.</p> {
* return byteStream;
* @param encoding A string describing the character encoding. }
* @see #setSystemId
* @see #setByteStream
* @see #getEncoding /**
*/ * Set the character encoding, if known.
public void setEncoding (String encoding) *
{ * <p>The encoding must be a string acceptable for an
this.encoding = encoding; * XML encoding declaration (see section 4.3.3 of the XML 1.0
} * recommendation).</p>
*
* <p>This method has no effect when the application provides a
/** * character stream.</p>
* Get the character encoding for a byte stream or URI. *
* * @param encoding A string describing the character encoding.
* @return The encoding, or null if none was supplied. * @see #setSystemId
* @see #setByteStream * @see #setByteStream
* @see #getSystemId * @see #getEncoding
* @see #getByteStream */
*/ public void setEncoding (String encoding)
public String getEncoding () {
{ this.encoding = encoding;
return encoding; }
}
/**
/** * Get the character encoding for a byte stream or URI.
* Set the character stream for this input source. * This value will be ignored when the application provides a
* * character stream.
* <p>If there is a character stream specified, the SAX parser *
* will ignore any byte stream and will not attempt to open * @return The encoding, or null if none was supplied.
* a URI connection to the system identifier.</p> * @see #setByteStream
* * @see #getSystemId
* @param characterStream The character stream containing the * @see #getByteStream
* XML document or other entity. */
* @see #getCharacterStream public String getEncoding ()
* @see java.io.Reader {
*/ return encoding;
public void setCharacterStream (Reader characterStream) }
{
this.characterStream = characterStream;
} /**
* Set the character stream for this input source.
*
/** * <p>If there is a character stream specified, the SAX parser
* Get the character stream for this input source. * will ignore any byte stream and will not attempt to open
* * a URI connection to the system identifier.</p>
* @return The character stream, or null if none was supplied. *
* @see #setCharacterStream * @param characterStream The character stream containing the
*/ * XML document or other entity.
public Reader getCharacterStream () * @see #getCharacterStream
{ * @see java.io.Reader
return characterStream; */
} public void setCharacterStream (Reader characterStream)
{
this.characterStream = characterStream;
}
////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////// /**
* Get the character stream for this input source.
private String publicId; *
private String systemId; * @return The character stream, or null if none was supplied.
private InputStream byteStream; * @see #setCharacterStream
private String encoding; */
private Reader characterStream; public Reader getCharacterStream ()
{
} return characterStream;
}
// end of InputSource.java
////////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////////
private String publicId;
private String systemId;
private InputStream byteStream;
private String encoding;
private Reader characterStream;
}
// end of InputSource.java
// SAX locator interface for document events. // SAX locator interface for document events.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: Locator.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: Locator.java,v 1.4.2.5 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Interface for associating a SAX event with a document location. /**
* * Interface for associating a SAX event with a document location.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>If a SAX parser provides location information to the SAX * for further information.
* application, it does so by implementing this interface and then * </blockquote>
* passing an instance to the application using the content *
* handler's {@link org.xml.sax.ContentHandler#setDocumentLocator * <p>If a SAX parser provides location information to the SAX
* setDocumentLocator} method. The application can use the * application, it does so by implementing this interface and then
* object to obtain the location of any other content handler event * passing an instance to the application using the content
* in the XML source document.</p> * handler's {@link org.xml.sax.ContentHandler#setDocumentLocator
* * setDocumentLocator} method. The application can use the
* <p>Note that the results returned by the object will be valid only * object to obtain the location of any other SAX event
* during the scope of each content handler method: the application * in the XML source document.</p>
* will receive unpredictable results if it attempts to use the *
* locator at any other time.</p> * <p>Note that the results returned by the object will be valid only
* * during the scope of each callback method: the application
* <p>SAX parsers are not required to supply a locator, but they are * will receive unpredictable results if it attempts to use the
* very strongly encouraged to do so. If the parser supplies a * locator at any other time, or after parsing completes.</p>
* locator, it must do so before reporting any other document events. *
* If no locator has been set by the time the application receives * <p>SAX parsers are not required to supply a locator, but they are
* the {@link org.xml.sax.ContentHandler#startDocument startDocument} * very strongly encouraged to do so. If the parser supplies a
* event, the application should assume that a locator is not * locator, it must do so before reporting any other document events.
* available.</p> * If no locator has been set by the time the application receives
* * the {@link org.xml.sax.ContentHandler#startDocument startDocument}
* @since SAX 1.0 * event, the application should assume that a locator is not
* @author David Megginson, * available.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.ContentHandler#setDocumentLocator * @author David Megginson
*/ * @version 2.0.1 (sax2r2)
public interface Locator { * @see org.xml.sax.ContentHandler#setDocumentLocator
*/
public interface Locator {
/**
* Return the public identifier for the current document event.
* /**
* <p>The return value is the public identifier of the document * Return the public identifier for the current document event.
* entity or of the external parsed entity in which the markup *
* triggering the event appears.</p> * <p>The return value is the public identifier of the document
* * entity or of the external parsed entity in which the markup
* @return A string containing the public identifier, or * triggering the event appears.</p>
* null if none is available. *
* @see #getSystemId * @return A string containing the public identifier, or
*/ * null if none is available.
public abstract String getPublicId (); * @see #getSystemId
*/
public abstract String getPublicId ();
/**
* Return the system identifier for the current document event.
* /**
* <p>The return value is the system identifier of the document * Return the system identifier for the current document event.
* entity or of the external parsed entity in which the markup *
* triggering the event appears.</p> * <p>The return value is the system identifier of the document
* * entity or of the external parsed entity in which the markup
* <p>If the system identifier is a URL, the parser must resolve it * triggering the event appears.</p>
* fully before passing it to the application.</p> *
* * <p>If the system identifier is a URL, the parser must resolve it
* @return A string containing the system identifier, or null * fully before passing it to the application. For example, a file
* if none is available. * name must always be provided as a <em>file:...</em> URL, and other
* @see #getPublicId * kinds of relative URI are also resolved against their bases.</p>
*/ *
public abstract String getSystemId (); * @return A string containing the system identifier, or null
* if none is available.
* @see #getPublicId
/** */
* Return the line number where the current document event ends. public abstract String getSystemId ();
*
* <p><strong>Warning:</strong> The return value from the method
* is intended only as an approximation for the sake of error /**
* reporting; it is not intended to provide sufficient information * Return the line number where the current document event ends.
* to edit the character content of the original XML document.</p> * Lines are delimited by line ends, which are defined in
* * the XML specification.
* <p>The return value is an approximation of the line number *
* in the document entity or external parsed entity where the * <p><strong>Warning:</strong> The return value from the method
* markup triggering the event appears.</p> * is intended only as an approximation for the sake of diagnostics;
* * it is not intended to provide sufficient information
* <p>If possible, the SAX driver should provide the line position * to edit the character content of the original XML document.
* of the first character after the text associated with the document * In some cases, these "line" numbers match what would be displayed
* event. The first line in the document is line 1.</p> * as columns, and in others they may not match the source text
* * due to internal entity expansion. </p>
* @return The line number, or -1 if none is available. *
* @see #getColumnNumber * <p>The return value is an approximation of the line number
*/ * in the document entity or external parsed entity where the
public abstract int getLineNumber (); * markup triggering the event appears.</p>
*
* <p>If possible, the SAX driver should provide the line position
/** * of the first character after the text associated with the document
* Return the column number where the current document event ends. * event. The first line is line 1.</p>
* *
* <p><strong>Warning:</strong> The return value from the method * @return The line number, or -1 if none is available.
* is intended only as an approximation for the sake of error * @see #getColumnNumber
* reporting; it is not intended to provide sufficient information */
* to edit the character content of the original XML document.</p> public abstract int getLineNumber ();
*
* <p>The return value is an approximation of the column number
* in the document entity or external parsed entity where the /**
* markup triggering the event appears.</p> * Return the column number where the current document event ends.
* * This is one-based number of Java <code>char</code> values since
* <p>If possible, the SAX driver should provide the line position * the last line end.
* of the first character after the text associated with the document *
* event.</p> * <p><strong>Warning:</strong> The return value from the method
* * is intended only as an approximation for the sake of diagnostics;
* <p>If possible, the SAX driver should provide the line position * it is not intended to provide sufficient information
* of the first character after the text associated with the document * to edit the character content of the original XML document.
* event. The first column in each line is column 1.</p> * For example, when lines contain combining character sequences, wide
* * characters, surrogate pairs, or bi-directional text, the value may
* @return The column number, or -1 if none is available. * not correspond to the column in a text editor's display. </p>
* @see #getLineNumber *
*/ * <p>The return value is an approximation of the column number
public abstract int getColumnNumber (); * in the document entity or external parsed entity where the
* markup triggering the event appears.</p>
} *
* <p>If possible, the SAX driver should provide the line position
// end of Locator.java * of the first character after the text associated with the document
* event. The first column in each line is column 1.</p>
*
* @return The column number, or -1 if none is available.
* @see #getLineNumber
*/
public abstract int getColumnNumber ();
}
// end of Locator.java
// SAX parser interface. // SAX parser interface.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: Parser.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: Parser.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
import java.io.IOException;
import java.util.Locale; import java.io.IOException;
import java.util.Locale;
/**
* Basic interface for SAX (Simple API for XML) parsers. /**
* * Basic interface for SAX (Simple API for XML) parsers.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This was the main event supplier interface for SAX1; it has * for further information.
* been replaced in SAX2 by {@link org.xml.sax.XMLReader XMLReader}, * </blockquote>
* which includes Namespace support and sophisticated configurability *
* and extensibility.</p> * <p>This was the main event supplier interface for SAX1; it has
* * been replaced in SAX2 by {@link org.xml.sax.XMLReader XMLReader},
* <p>All SAX1 parsers must implement this basic interface: it allows * which includes Namespace support and sophisticated configurability
* applications to register handlers for different types of events * and extensibility.</p>
* and to initiate a parse from a URI, or a character stream.</p> *
* * <p>All SAX1 parsers must implement this basic interface: it allows
* <p>All SAX1 parsers must also implement a zero-argument constructor * applications to register handlers for different types of events
* (though other constructors are also allowed).</p> * and to initiate a parse from a URI, or a character stream.</p>
* *
* <p>SAX1 parsers are reusable but not re-entrant: the application * <p>All SAX1 parsers must also implement a zero-argument constructor
* may reuse a parser object (possibly with a different input source) * (though other constructors are also allowed).</p>
* once the first parse has completed successfully, but it may not *
* invoke the parse() methods recursively within a parse.</p> * <p>SAX1 parsers are reusable but not re-entrant: the application
* * may reuse a parser object (possibly with a different input source)
* @deprecated This interface has been replaced by the SAX2 * once the first parse has completed successfully, but it may not
* {@link org.xml.sax.XMLReader XMLReader} * invoke the parse() methods recursively within a parse.</p>
* interface, which includes Namespace support. *
* @since SAX 1.0 * @deprecated This interface has been replaced by the SAX2
* @author David Megginson, * {@link org.xml.sax.XMLReader XMLReader}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * interface, which includes Namespace support.
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.EntityResolver * @author David Megginson
* @see org.xml.sax.DTDHandler * @version 2.0.1 (sax2r2)
* @see org.xml.sax.DocumentHandler * @see org.xml.sax.EntityResolver
* @see org.xml.sax.ErrorHandler * @see org.xml.sax.DTDHandler
* @see org.xml.sax.HandlerBase * @see org.xml.sax.DocumentHandler
* @see org.xml.sax.InputSource * @see org.xml.sax.ErrorHandler
*/ * @see org.xml.sax.HandlerBase
public interface Parser * @see org.xml.sax.InputSource
{ */
public interface Parser
/** {
* Allow an application to request a locale for errors and warnings.
* /**
* <p>SAX parsers are not required to provide localisation for errors * Allow an application to request a locale for errors and warnings.
* and warnings; if they cannot support the requested locale, *
* however, they must throw a SAX exception. Applications may * <p>SAX parsers are not required to provide localisation for errors
* not request a locale change in the middle of a parse.</p> * and warnings; if they cannot support the requested locale,
* * however, they must throw a SAX exception. Applications may
* @param locale A Java Locale object. * not request a locale change in the middle of a parse.</p>
* @exception org.xml.sax.SAXException Throws an exception *
* (using the previous or default locale) if the * @param locale A Java Locale object.
* requested locale is not supported. * @exception org.xml.sax.SAXException Throws an exception
* @see org.xml.sax.SAXException * (using the previous or default locale) if the
* @see org.xml.sax.SAXParseException * requested locale is not supported.
*/ * @see org.xml.sax.SAXException
public abstract void setLocale (Locale locale) * @see org.xml.sax.SAXParseException
throws SAXException; */
public abstract void setLocale (Locale locale)
throws SAXException;
/**
* Allow an application to register a custom entity resolver.
* /**
* <p>If the application does not register an entity resolver, the * Allow an application to register a custom entity resolver.
* SAX parser will resolve system identifiers and open connections *
* to entities itself (this is the default behaviour implemented in * <p>If the application does not register an entity resolver, the
* HandlerBase).</p> * SAX parser will resolve system identifiers and open connections
* * to entities itself (this is the default behaviour implemented in
* <p>Applications may register a new or different entity resolver * HandlerBase).</p>
* in the middle of a parse, and the SAX parser must begin using *
* the new resolver immediately.</p> * <p>Applications may register a new or different entity resolver
* * in the middle of a parse, and the SAX parser must begin using
* @param resolver The object for resolving entities. * the new resolver immediately.</p>
* @see EntityResolver *
* @see HandlerBase * @param resolver The object for resolving entities.
*/ * @see EntityResolver
public abstract void setEntityResolver (EntityResolver resolver); * @see HandlerBase
*/
public abstract void setEntityResolver (EntityResolver resolver);
/**
* Allow an application to register a DTD event handler.
* /**
* <p>If the application does not register a DTD handler, all DTD * Allow an application to register a DTD event handler.
* events reported by the SAX parser will be silently *
* ignored (this is the default behaviour implemented by * <p>If the application does not register a DTD handler, all DTD
* HandlerBase).</p> * events reported by the SAX parser will be silently
* * ignored (this is the default behaviour implemented by
* <p>Applications may register a new or different * HandlerBase).</p>
* handler in the middle of a parse, and the SAX parser must *
* begin using the new handler immediately.</p> * <p>Applications may register a new or different
* * handler in the middle of a parse, and the SAX parser must
* @param handler The DTD handler. * begin using the new handler immediately.</p>
* @see DTDHandler *
* @see HandlerBase * @param handler The DTD handler.
*/ * @see DTDHandler
public abstract void setDTDHandler (DTDHandler handler); * @see HandlerBase
*/
public abstract void setDTDHandler (DTDHandler handler);
/**
* Allow an application to register a document event handler.
* /**
* <p>If the application does not register a document handler, all * Allow an application to register a document event handler.
* document events reported by the SAX parser will be silently *
* ignored (this is the default behaviour implemented by * <p>If the application does not register a document handler, all
* HandlerBase).</p> * document events reported by the SAX parser will be silently
* * ignored (this is the default behaviour implemented by
* <p>Applications may register a new or different handler in the * HandlerBase).</p>
* middle of a parse, and the SAX parser must begin using the new *
* handler immediately.</p> * <p>Applications may register a new or different handler in the
* * middle of a parse, and the SAX parser must begin using the new
* @param handler The document handler. * handler immediately.</p>
* @see DocumentHandler *
* @see HandlerBase * @param handler The document handler.
*/ * @see DocumentHandler
public abstract void setDocumentHandler (DocumentHandler handler); * @see HandlerBase
*/
public abstract void setDocumentHandler (DocumentHandler handler);
/**
* Allow an application to register an error event handler.
* /**
* <p>If the application does not register an error event handler, * Allow an application to register an error event handler.
* all error events reported by the SAX parser will be silently *
* ignored, except for fatalError, which will throw a SAXException * <p>If the application does not register an error event handler,
* (this is the default behaviour implemented by HandlerBase).</p> * all error events reported by the SAX parser will be silently
* * ignored, except for fatalError, which will throw a SAXException
* <p>Applications may register a new or different handler in the * (this is the default behaviour implemented by HandlerBase).</p>
* middle of a parse, and the SAX parser must begin using the new *
* handler immediately.</p> * <p>Applications may register a new or different handler in the
* * middle of a parse, and the SAX parser must begin using the new
* @param handler The error handler. * handler immediately.</p>
* @see ErrorHandler *
* @see SAXException * @param handler The error handler.
* @see HandlerBase * @see ErrorHandler
*/ * @see SAXException
public abstract void setErrorHandler (ErrorHandler handler); * @see HandlerBase
*/
public abstract void setErrorHandler (ErrorHandler handler);
/**
* Parse an XML document.
* /**
* <p>The application can use this method to instruct the SAX parser * Parse an XML document.
* to begin parsing an XML document from any valid input *
* source (a character stream, a byte stream, or a URI).</p> * <p>The application can use this method to instruct the SAX parser
* * to begin parsing an XML document from any valid input
* <p>Applications may not invoke this method while a parse is in * source (a character stream, a byte stream, or a URI).</p>
* progress (they should create a new Parser instead for each *
* additional XML document). Once a parse is complete, an * <p>Applications may not invoke this method while a parse is in
* application may reuse the same Parser object, possibly with a * progress (they should create a new Parser instead for each
* different input source.</p> * additional XML document). Once a parse is complete, an
* * application may reuse the same Parser object, possibly with a
* @param source The input source for the top-level of the * different input source.</p>
* XML document. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param source The input source for the top-level of the
* wrapping another exception. * XML document.
* @exception java.io.IOException An IO exception from the parser, * @exception org.xml.sax.SAXException Any SAX exception, possibly
* possibly from a byte stream or character stream * wrapping another exception.
* supplied by the application. * @exception java.io.IOException An IO exception from the parser,
* @see org.xml.sax.InputSource * possibly from a byte stream or character stream
* @see #parse(java.lang.String) * supplied by the application.
* @see #setEntityResolver * @see org.xml.sax.InputSource
* @see #setDTDHandler * @see #parse(java.lang.String)
* @see #setDocumentHandler * @see #setEntityResolver
* @see #setErrorHandler * @see #setDTDHandler
*/ * @see #setDocumentHandler
public abstract void parse (InputSource source) * @see #setErrorHandler
throws SAXException, IOException; */
public abstract void parse (InputSource source)
throws SAXException, IOException;
/**
* Parse an XML document from a system identifier (URI).
* /**
* <p>This method is a shortcut for the common case of reading a * Parse an XML document from a system identifier (URI).
* document from a system identifier. It is the exact *
* equivalent of the following:</p> * <p>This method is a shortcut for the common case of reading a
* * document from a system identifier. It is the exact
* <pre> * equivalent of the following:</p>
* parse(new InputSource(systemId)); *
* </pre> * <pre>
* * parse(new InputSource(systemId));
* <p>If the system identifier is a URL, it must be fully resolved * </pre>
* by the application before it is passed to the parser.</p> *
* * <p>If the system identifier is a URL, it must be fully resolved
* @param systemId The system identifier (URI). * by the application before it is passed to the parser.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param systemId The system identifier (URI).
* @exception java.io.IOException An IO exception from the parser, * @exception org.xml.sax.SAXException Any SAX exception, possibly
* possibly from a byte stream or character stream * wrapping another exception.
* supplied by the application. * @exception java.io.IOException An IO exception from the parser,
* @see #parse(org.xml.sax.InputSource) * possibly from a byte stream or character stream
*/ * supplied by the application.
public abstract void parse (String systemId) * @see #parse(org.xml.sax.InputSource)
throws SAXException, IOException; */
public abstract void parse (String systemId)
} throws SAXException, IOException;
// end of Parser.java }
// end of Parser.java
// SAX exception class. // SAX exception class.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: SAXException.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: SAXException.java,v 1.4.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Encapsulate a general SAX error or warning. /**
* * Encapsulate a general SAX error or warning.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class can contain basic error or warning information from * for further information.
* either the XML parser or the application: a parser writer or * </blockquote>
* application writer can subclass it to provide additional *
* functionality. SAX handlers may throw this exception or * <p>This class can contain basic error or warning information from
* any exception subclassed from it.</p> * either the XML parser or the application: a parser writer or
* * application writer can subclass it to provide additional
* <p>If the application needs to pass through other types of * functionality. SAX handlers may throw this exception or
* exceptions, it must wrap those exceptions in a SAXException * any exception subclassed from it.</p>
* or an exception derived from a SAXException.</p> *
* * <p>If the application needs to pass through other types of
* <p>If the parser or application needs to include information about a * exceptions, it must wrap those exceptions in a SAXException
* specific location in an XML document, it should use the * or an exception derived from a SAXException.</p>
* {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p> *
* * <p>If the parser or application needs to include information about a
* @since SAX 1.0 * specific location in an XML document, it should use the
* @author David Megginson, * {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.SAXParseException * @author David Megginson
*/ * @version 2.0.1 (sax2r2)
public class SAXException extends Exception { * @see org.xml.sax.SAXParseException
*/
public class SAXException extends Exception {
/**
* Create a new SAXException.
* /**
* @param message The error or warning message. * Create a new SAXException.
* @see org.xml.sax.Parser#setLocale */
*/ public SAXException ()
public SAXException (String message) { {
super(message); super();
this.exception = null; this.exception = null;
} }
/** /**
* Create a new SAXException wrapping an existing exception. * Create a new SAXException.
* *
* <p>The existing exception will be embedded in the new * @param message The error or warning message.
* one, and its message will become the default message for */
* the SAXException.</p> public SAXException (String message) {
* super(message);
* @param e The exception to be wrapped in a SAXException. this.exception = null;
*/ }
public SAXException (Exception e)
{
super(); /**
this.exception = e; * Create a new SAXException wrapping an existing exception.
} *
* <p>The existing exception will be embedded in the new
* one, and its message will become the default message for
/** * the SAXException.</p>
* Create a new SAXException from an existing exception. *
* * @param e The exception to be wrapped in a SAXException.
* <p>The existing exception will be embedded in the new */
* one, but the new exception will have its own message.</p> public SAXException (Exception e)
* {
* @param message The detail message. super();
* @param e The exception to be wrapped in a SAXException. this.exception = e;
* @see org.xml.sax.Parser#setLocale }
*/
public SAXException (String message, Exception e)
{ /**
super(message); * Create a new SAXException from an existing exception.
this.exception = e; *
} * <p>The existing exception will be embedded in the new
* one, but the new exception will have its own message.</p>
*
/** * @param message The detail message.
* Return a detail message for this exception. * @param e The exception to be wrapped in a SAXException.
* */
* <p>If there is an embedded exception, and if the SAXException public SAXException (String message, Exception e)
* has no detail message of its own, this method will return {
* the detail message from the embedded exception.</p> super(message);
* this.exception = e;
* @return The error or warning message. }
* @see org.xml.sax.Parser#setLocale
*/
public String getMessage () /**
{ * Return a detail message for this exception.
String message = super.getMessage(); *
* <p>If there is an embedded exception, and if the SAXException
if (message == null && exception != null) { * has no detail message of its own, this method will return
return exception.getMessage(); * the detail message from the embedded exception.</p>
} else { *
return message; * @return The error or warning message.
} */
} public String getMessage ()
{
String message = super.getMessage();
/**
* Return the embedded exception, if any. if (message == null && exception != null) {
* return exception.getMessage();
* @return The embedded exception, or null if there is none. } else {
*/ return message;
public Exception getException () }
{ }
return exception;
}
/**
* Return the embedded exception, if any.
/** *
* Override toString to pick up any embedded exception. * @return The embedded exception, or null if there is none.
* */
* @return A string representation of this exception. public Exception getException ()
*/ {
public String toString () return exception;
{ }
if (exception != null) {
return exception.toString();
} else { /**
return super.toString(); * Override toString to pick up any embedded exception.
} *
} * @return A string representation of this exception.
*/
public String toString ()
{
////////////////////////////////////////////////////////////////////// if (exception != null) {
// Internal state. return exception.toString();
////////////////////////////////////////////////////////////////////// } else {
return super.toString();
}
/** }
* @serial The embedded exception if tunnelling, or null.
*/
private Exception exception;
//////////////////////////////////////////////////////////////////////
} // Internal state.
//////////////////////////////////////////////////////////////////////
// end of SAXException.java
/**
* @serial The embedded exception if tunnelling, or null.
*/
private Exception exception;
}
// end of SAXException.java
// SAXNotRecognizedException.java - unrecognized feature or value. // SAXNotRecognizedException.java - unrecognized feature or value.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the Public Domain. // Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: SAXNotRecognizedException.java,v 1.1 2000/10/02 02:43:17 sboag Exp $
// $Id: SAXNotRecognizedException.java,v 1.4.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Exception class for an unrecognized identifier. /**
* * Exception class for an unrecognized identifier.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>An XMLReader will throw this exception when it finds an * for further information.
* unrecognized feature or property identifier; SAX applications and * </blockquote>
* extensions may use this class for other, similar purposes.</p> *
* * <p>An XMLReader will throw this exception when it finds an
* @since SAX 2.0 * unrecognized feature or property identifier; SAX applications and
* @author David Megginson, * extensions may use this class for other, similar purposes.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.SAXNotSupportedException * @author David Megginson
*/ * @version 2.0.1 (sax2r2)
public class SAXNotRecognizedException extends SAXException * @see org.xml.sax.SAXNotSupportedException
{ */
public class SAXNotRecognizedException extends SAXException
/** {
* Construct a new exception with the given message.
* /**
* @param message The text message of the exception. * Default constructor.
*/ */
public SAXNotRecognizedException (String message) public SAXNotRecognizedException ()
{ {
super(message); super();
} }
}
/**
// end of SAXNotRecognizedException.java * Construct a new exception with the given message.
*
* @param message The text message of the exception.
*/
public SAXNotRecognizedException (String message)
{
super(message);
}
}
// end of SAXNotRecognizedException.java
// SAXNotSupportedException.java - unsupported feature or value. // SAXNotSupportedException.java - unsupported feature or value.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the Public Domain. // Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: SAXNotSupportedException.java,v 1.1 2000/10/02 02:43:17 sboag Exp $
// $Id: SAXNotSupportedException.java,v 1.4.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Exception class for an unsupported operation. /**
* * Exception class for an unsupported operation.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>An XMLReader will throw this exception when it recognizes a * for further information.
* feature or property identifier, but cannot perform the requested * </blockquote>
* operation (setting a state or value). Other SAX2 applications and *
* extensions may use this class for similar purposes.</p> * <p>An XMLReader will throw this exception when it recognizes a
* * feature or property identifier, but cannot perform the requested
* @since SAX 2.0 * operation (setting a state or value). Other SAX2 applications and
* @author David Megginson, * extensions may use this class for similar purposes.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.SAXNotRecognizedException * @author David Megginson
*/ * @version 2.0.1 (sax2r2)
public class SAXNotSupportedException extends SAXException * @see org.xml.sax.SAXNotRecognizedException
{ */
public class SAXNotSupportedException extends SAXException
/** {
* Construct a new exception with the given message.
* /**
* @param message The text message of the exception. * Construct a new exception with no message.
*/ */
public SAXNotSupportedException (String message) public SAXNotSupportedException ()
{ {
super(message); super();
} }
}
/**
// end of SAXNotSupportedException.java * Construct a new exception with the given message.
*
* @param message The text message of the exception.
*/
public SAXNotSupportedException (String message)
{
super(message);
}
}
// end of SAXNotSupportedException.java
// SAX exception class. // SAX exception class.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: SAXParseException.java,v 1.1 2000/10/02 02:43:17 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: SAXParseException.java,v 1.3.2.5 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Encapsulate an XML parse error or warning. /**
* * Encapsulate an XML parse error or warning.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This exception will include information for locating the error * for further information.
* in the original XML document. Note that although the application * </blockquote>
* will receive a SAXParseException as the argument to the handlers *
* in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface, * <p>This exception may include information for locating the error
* the application is not actually required to throw the exception; * in the original XML document, as if it came from a {@link Locator}
* instead, it can simply read the information in it and take a * object. Note that although the application
* different action.</p> * will receive a SAXParseException as the argument to the handlers
* * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
* <p>Since this exception is a subclass of {@link org.xml.sax.SAXException * the application is not actually required to throw the exception;
* SAXException}, it inherits the ability to wrap another exception.</p> * instead, it can simply read the information in it and take a
* * different action.</p>
* @since SAX 1.0 *
* @author David Megginson, * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * SAXException}, it inherits the ability to wrap another exception.</p>
* @version 2.0 *
* @see org.xml.sax.SAXException * @since SAX 1.0
* @see org.xml.sax.Locator * @author David Megginson
* @see org.xml.sax.ErrorHandler * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.SAXException
public class SAXParseException extends SAXException { * @see org.xml.sax.Locator
* @see org.xml.sax.ErrorHandler
*/
////////////////////////////////////////////////////////////////////// public class SAXParseException extends SAXException {
// Constructors.
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Constructors.
/** //////////////////////////////////////////////////////////////////////
* Create a new SAXParseException from a message and a Locator.
*
* <p>This constructor is especially useful when an application is /**
* creating its own exception from within a {@link org.xml.sax.ContentHandler * Create a new SAXParseException from a message and a Locator.
* ContentHandler} callback.</p> *
* * <p>This constructor is especially useful when an application is
* @param message The error or warning message. * creating its own exception from within a {@link org.xml.sax.ContentHandler
* @param locator The locator object for the error or warning (may be * ContentHandler} callback.</p>
* null). *
* @see org.xml.sax.Locator * @param message The error or warning message.
* @see org.xml.sax.Parser#setLocale * @param locator The locator object for the error or warning (may be
*/ * null).
public SAXParseException (String message, Locator locator) { * @see org.xml.sax.Locator
super(message); */
if (locator != null) { public SAXParseException (String message, Locator locator) {
init(locator.getPublicId(), locator.getSystemId(), super(message);
locator.getLineNumber(), locator.getColumnNumber()); if (locator != null) {
} else { init(locator.getPublicId(), locator.getSystemId(),
init(null, null, -1, -1); locator.getLineNumber(), locator.getColumnNumber());
} } else {
} init(null, null, -1, -1);
}
}
/**
* Wrap an existing exception in a SAXParseException.
* /**
* <p>This constructor is especially useful when an application is * Wrap an existing exception in a SAXParseException.
* creating its own exception from within a {@link org.xml.sax.ContentHandler *
* ContentHandler} callback, and needs to wrap an existing exception that is not a * <p>This constructor is especially useful when an application is
* subclass of {@link org.xml.sax.SAXException SAXException}.</p> * creating its own exception from within a {@link org.xml.sax.ContentHandler
* * ContentHandler} callback, and needs to wrap an existing exception that is not a
* @param message The error or warning message, or null to * subclass of {@link org.xml.sax.SAXException SAXException}.</p>
* use the message from the embedded exception. *
* @param locator The locator object for the error or warning (may be * @param message The error or warning message, or null to
* null). * use the message from the embedded exception.
* @param e Any exception. * @param locator The locator object for the error or warning (may be
* @see org.xml.sax.Locator * null).
* @see org.xml.sax.Parser#setLocale * @param e Any exception.
*/ * @see org.xml.sax.Locator
public SAXParseException (String message, Locator locator, */
Exception e) { public SAXParseException (String message, Locator locator,
super(message, e); Exception e) {
if (locator != null) { super(message, e);
init(locator.getPublicId(), locator.getSystemId(), if (locator != null) {
locator.getLineNumber(), locator.getColumnNumber()); init(locator.getPublicId(), locator.getSystemId(),
} else { locator.getLineNumber(), locator.getColumnNumber());
init(null, null, -1, -1); } else {
} init(null, null, -1, -1);
} }
}
/**
* Create a new SAXParseException. /**
* * Create a new SAXParseException.
* <p>This constructor is most useful for parser writers.</p> *
* * <p>This constructor is most useful for parser writers.</p>
* <p>If the system identifier is a URL, the parser must resolve it *
* fully before creating the exception.</p> * <p>All parameters except the message are as if
* * they were provided by a {@link Locator}. For example, if the
* @param message The error or warning message. * system identifier is a URL (including relative filename), the
* @param publicId The public identifier of the entity that generated * caller must resolve it fully before creating the exception.</p>
* the error or warning. *
* @param systemId The system identifier of the entity that generated *
* the error or warning. * @param message The error or warning message.
* @param lineNumber The line number of the end of the text that * @param publicId The public identifer of the entity that generated
* caused the error or warning. * the error or warning.
* @param columnNumber The column number of the end of the text that * @param systemId The system identifer of the entity that generated
* cause the error or warning. * the error or warning.
* @see org.xml.sax.Parser#setLocale * @param lineNumber The line number of the end of the text that
*/ * caused the error or warning.
public SAXParseException (String message, String publicId, String systemId, * @param columnNumber The column number of the end of the text that
int lineNumber, int columnNumber) * cause the error or warning.
{ */
super(message); public SAXParseException (String message, String publicId, String systemId,
init(publicId, systemId, lineNumber, columnNumber); int lineNumber, int columnNumber)
} {
super(message);
init(publicId, systemId, lineNumber, columnNumber);
/** }
* Create a new SAXParseException with an embedded exception.
*
* <p>This constructor is most useful for parser writers who /**
* need to wrap an exception that is not a subclass of * Create a new SAXParseException with an embedded exception.
* {@link org.xml.sax.SAXException SAXException}.</p> *
* * <p>This constructor is most useful for parser writers who
* <p>If the system identifier is a URL, the parser must resolve it * need to wrap an exception that is not a subclass of
* fully before creating the exception.</p> * {@link org.xml.sax.SAXException SAXException}.</p>
* *
* @param message The error or warning message, or null to use * <p>All parameters except the message and exception are as if
* the message from the embedded exception. * they were provided by a {@link Locator}. For example, if the
* @param publicId The public identifier of the entity that generated * system identifier is a URL (including relative filename), the
* the error or warning. * caller must resolve it fully before creating the exception.</p>
* @param systemId The system identifier of the entity that generated *
* the error or warning. * @param message The error or warning message, or null to use
* @param lineNumber The line number of the end of the text that * the message from the embedded exception.
* caused the error or warning. * @param publicId The public identifer of the entity that generated
* @param columnNumber The column number of the end of the text that * the error or warning.
* cause the error or warning. * @param systemId The system identifer of the entity that generated
* @param e Another exception to embed in this one. * the error or warning.
* @see org.xml.sax.Parser#setLocale * @param lineNumber The line number of the end of the text that
*/ * caused the error or warning.
public SAXParseException (String message, String publicId, String systemId, * @param columnNumber The column number of the end of the text that
int lineNumber, int columnNumber, Exception e) * cause the error or warning.
{ * @param e Another exception to embed in this one.
super(message, e); */
init(publicId, systemId, lineNumber, columnNumber); public SAXParseException (String message, String publicId, String systemId,
} int lineNumber, int columnNumber, Exception e)
{
super(message, e);
/** init(publicId, systemId, lineNumber, columnNumber);
* Internal initialization method. }
*
* @param publicId The public identifier of the entity which generated the exception,
* or null. /**
* @param systemId The system identifier of the entity which generated the exception, * Internal initialization method.
* or null. *
* @param lineNumber The line number of the error, or -1. * @param publicId The public identifier of the entity which generated the exception,
* @param columnNumber The column number of the error, or -1. * or null.
*/ * @param systemId The system identifier of the entity which generated the exception,
private void init (String publicId, String systemId, * or null.
int lineNumber, int columnNumber) * @param lineNumber The line number of the error, or -1.
{ * @param columnNumber The column number of the error, or -1.
this.publicId = publicId; */
this.systemId = systemId; private void init (String publicId, String systemId,
this.lineNumber = lineNumber; int lineNumber, int columnNumber)
this.columnNumber = columnNumber; {
} this.publicId = publicId;
this.systemId = systemId;
this.lineNumber = lineNumber;
/** this.columnNumber = columnNumber;
* Get the public identifier of the entity where the exception occurred. }
*
* @return A string containing the public identifier, or null
* if none is available. /**
* @see org.xml.sax.Locator#getPublicId * Get the public identifier of the entity where the exception occurred.
*/ *
public String getPublicId () * @return A string containing the public identifier, or null
{ * if none is available.
return this.publicId; * @see org.xml.sax.Locator#getPublicId
} */
public String getPublicId ()
{
/** return this.publicId;
* Get the system identifier of the entity where the exception occurred. }
*
* <p>If the system identifier is a URL, it will be resolved
* fully.</p> /**
* * Get the system identifier of the entity where the exception occurred.
* @return A string containing the system identifier, or null *
* if none is available. * <p>If the system identifier is a URL, it will have been resolved
* @see org.xml.sax.Locator#getSystemId * fully.</p>
*/ *
public String getSystemId () * @return A string containing the system identifier, or null
{ * if none is available.
return this.systemId; * @see org.xml.sax.Locator#getSystemId
} */
public String getSystemId ()
{
/** return this.systemId;
* The line number of the end of the text where the exception occurred. }
*
* @return An integer representing the line number, or -1
* if none is available. /**
* @see org.xml.sax.Locator#getLineNumber * The line number of the end of the text where the exception occurred.
*/ *
public int getLineNumber () * <p>The first line is line 1.</p>
{ *
return this.lineNumber; * @return An integer representing the line number, or -1
} * if none is available.
* @see org.xml.sax.Locator#getLineNumber
*/
/** public int getLineNumber ()
* The column number of the end of the text where the exception occurred. {
* return this.lineNumber;
* <p>The first column in a line is position 1.</p> }
*
* @return An integer representing the column number, or -1
* if none is available. /**
* @see org.xml.sax.Locator#getColumnNumber * The column number of the end of the text where the exception occurred.
*/ *
public int getColumnNumber () * <p>The first column in a line is position 1.</p>
{ *
return this.columnNumber; * @return An integer representing the column number, or -1
} * if none is available.
* @see org.xml.sax.Locator#getColumnNumber
*/
public int getColumnNumber ()
////////////////////////////////////////////////////////////////////// {
// Internal state. return this.columnNumber;
////////////////////////////////////////////////////////////////////// }
/**
* @serial The public identifier, or null. //////////////////////////////////////////////////////////////////////
* @see #getPublicId // Internal state.
*/ //////////////////////////////////////////////////////////////////////
private String publicId;
/**
/** * @serial The public identifier, or null.
* @serial The system identifier, or null. * @see #getPublicId
* @see #getSystemId */
*/ private String publicId;
private String systemId;
/**
/** * @serial The system identifier, or null.
* @serial The line number, or -1. * @see #getSystemId
* @see #getLineNumber */
*/ private String systemId;
private int lineNumber;
/**
/** * @serial The line number, or -1.
* @serial The column number, or -1. * @see #getLineNumber
* @see #getColumnNumber */
*/ private int lineNumber;
private int columnNumber;
} /**
* @serial The column number, or -1.
// end of SAXParseException.java * @see #getColumnNumber
*/
private int columnNumber;
}
// end of SAXParseException.java
// XMLFilter.java - filter SAX2 events. // XMLFilter.java - filter SAX2 events.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the Public Domain. // Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: XMLFilter.java,v 1.1 2000/10/02 02:43:17 sboag Exp $
// $Id: XMLFilter.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
/**
* Interface for an XML filter. /**
* * Interface for an XML filter.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>An XML filter is like an XML reader, except that it obtains its * for further information.
* events from another XML reader rather than a primary source like * </blockquote>
* an XML document or database. Filters can modify a stream of *
* events as they pass on to the final application.</p> * <p>An XML filter is like an XML reader, except that it obtains its
* * events from another XML reader rather than a primary source like
* <p>The XMLFilterImpl helper class provides a convenient base * an XML document or database. Filters can modify a stream of
* for creating SAX2 filters, by passing on all {@link org.xml.sax.EntityResolver * events as they pass on to the final application.</p>
* EntityResolver}, {@link org.xml.sax.DTDHandler DTDHandler}, *
* {@link org.xml.sax.ContentHandler ContentHandler} and {@link org.xml.sax.ErrorHandler * <p>The XMLFilterImpl helper class provides a convenient base
* ErrorHandler} events automatically.</p> * for creating SAX2 filters, by passing on all {@link org.xml.sax.EntityResolver
* * EntityResolver}, {@link org.xml.sax.DTDHandler DTDHandler},
* @since SAX 2.0 * {@link org.xml.sax.ContentHandler ContentHandler} and {@link org.xml.sax.ErrorHandler
* @author David Megginson, * ErrorHandler} events automatically.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.helpers.XMLFilterImpl * @author David Megginson
*/ * @version 2.0.1 (sax2r2)
public interface XMLFilter extends XMLReader * @see org.xml.sax.helpers.XMLFilterImpl
{ */
public interface XMLFilter extends XMLReader
/** {
* Set the parent reader.
* /**
* <p>This method allows the application to link the filter to * Set the parent reader.
* a parent reader (which may be another filter). The argument *
* may not be null.</p> * <p>This method allows the application to link the filter to
* * a parent reader (which may be another filter). The argument
* @param parent The parent reader. * may not be null.</p>
*/ *
public abstract void setParent (XMLReader parent); * @param parent The parent reader.
*/
public abstract void setParent (XMLReader parent);
/**
* Get the parent reader.
* /**
* <p>This method allows the application to query the parent * Get the parent reader.
* reader (which may be another filter). It is generally a *
* bad idea to perform any operations on the parent reader * <p>This method allows the application to query the parent
* directly: they should all pass through this filter.</p> * reader (which may be another filter). It is generally a
* * bad idea to perform any operations on the parent reader
* @return The parent filter, or null if none has been set. * directly: they should all pass through this filter.</p>
*/ *
public abstract XMLReader getParent (); * @return The parent filter, or null if none has been set.
*/
} public abstract XMLReader getParent ();
// end of XMLFilter.java }
// end of XMLFilter.java
// XMLReader.java - read an XML document. // XMLReader.java - read an XML document.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the Public Domain. // Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: XMLReader.java,v 1.1 2000/10/02 02:43:17 sboag Exp $
// $Id: XMLReader.java,v 1.3.2.5 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax;
package org.xml.sax;
import java.io.IOException;
import java.io.IOException;
/**
* Interface for reading an XML document using callbacks. /**
* * Interface for reading an XML document using callbacks.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p><strong>Note:</strong> despite its name, this interface does * for further information.
* <em>not</em> extend the standard Java {@link java.io.Reader Reader} * </blockquote>
* interface, because reading XML is a fundamentally different activity *
* than reading character data.</p> * <p><strong>Note:</strong> despite its name, this interface does
* * <em>not</em> extend the standard Java {@link java.io.Reader Reader}
* <p>XMLReader is the interface that an XML parser's SAX2 driver must * interface, because reading XML is a fundamentally different activity
* implement. This interface allows an application to set and * than reading character data.</p>
* query features and properties in the parser, to register *
* event handlers for document processing, and to initiate * <p>XMLReader is the interface that an XML parser's SAX2 driver must
* a document parse.</p> * implement. This interface allows an application to set and
* * query features and properties in the parser, to register
* <p>All SAX interfaces are assumed to be synchronous: the * event handlers for document processing, and to initiate
* {@link #parse parse} methods must not return until parsing * a document parse.</p>
* is complete, and readers must wait for an event-handler callback *
* to return before reporting the next event.</p> * <p>All SAX interfaces are assumed to be synchronous: the
* * {@link #parse parse} methods must not return until parsing
* <p>This interface replaces the (now deprecated) SAX 1.0 {@link * is complete, and readers must wait for an event-handler callback
* org.xml.sax.Parser Parser} interface. The XMLReader interface * to return before reporting the next event.</p>
* contains two important enhancements over the old Parser *
* interface:</p> * <p>This interface replaces the (now deprecated) SAX 1.0 {@link
* * org.xml.sax.Parser Parser} interface. The XMLReader interface
* <ol> * contains two important enhancements over the old Parser
* <li>it adds a standard way to query and set features and * interface (as well as some minor ones):</p>
* properties; and</li> *
* <li>it adds Namespace support, which is required for many * <ol>
* higher-level XML standards.</li> * <li>it adds a standard way to query and set features and
* </ol> * properties; and</li>
* * <li>it adds Namespace support, which is required for many
* <p>There are adapters available to convert a SAX1 Parser to * higher-level XML standards.</li>
* a SAX2 XMLReader and vice-versa.</p> * </ol>
* *
* @since SAX 2.0 * <p>There are adapters available to convert a SAX1 Parser to
* @author David Megginson, * a SAX2 XMLReader and vice-versa.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.XMLFilter * @author David Megginson
* @see org.xml.sax.helpers.ParserAdapter * @version 2.0.1 (sax2r2)
* @see org.xml.sax.helpers.XMLReaderAdapter * @see org.xml.sax.XMLFilter
*/ * @see org.xml.sax.helpers.ParserAdapter
public interface XMLReader * @see org.xml.sax.helpers.XMLReaderAdapter
{ */
public interface XMLReader
{
////////////////////////////////////////////////////////////////////
// Configuration.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Configuration.
////////////////////////////////////////////////////////////////////
/**
* Look up the value of a feature.
* /**
* <p>The feature name is any fully-qualified URI. It is * Look up the value of a feature flag.
* possible for an XMLReader to recognize a feature name but *
* to be unable to return its value; this is especially true * <p>The feature name is any fully-qualified URI. It is
* in the case of an adapter for a SAX1 Parser, which has * possible for an XMLReader to recognize a feature name but
* no way of knowing whether the underlying parser is * temporarily be unable to return its value.
* performing validation or expanding external entities.</p> * Some feature values may be available only in specific
* * contexts, such as before, during, or after a parse.
* <p>All XMLReaders are required to recognize the * Also, some feature values may not be programmatically accessible.
* http://xml.org/sax/features/namespaces and the * (In the case of an adapter for SAX1 {@link Parser}, there is no
* http://xml.org/sax/features/namespace-prefixes feature names.</p> * implementation-independent way to expose whether the underlying
* * parser is performing validation, expanding external entities,
* <p>Some feature values may be available only in specific * and so forth.) </p>
* contexts, such as before, during, or after a parse.</p> *
* * <p>All XMLReaders are required to recognize the
* <p>Typical usage is something like this:</p> * http://xml.org/sax/features/namespaces and the
* * http://xml.org/sax/features/namespace-prefixes feature names.</p>
* <pre> *
* XMLReader r = new MySAXDriver(); * <p>Typical usage is something like this:</p>
* *
* // try to activate validation * <pre>
* try { * XMLReader r = new MySAXDriver();
* r.setFeature("http://xml.org/sax/features/validation", true); *
* } catch (SAXException e) { * // try to activate validation
* System.err.println("Cannot activate validation."); * try {
* } * r.setFeature("http://xml.org/sax/features/validation", true);
* * } catch (SAXException e) {
* // register event handlers * System.err.println("Cannot activate validation.");
* r.setContentHandler(new MyContentHandler()); * }
* r.setErrorHandler(new MyErrorHandler()); *
* * // register event handlers
* // parse the first document * r.setContentHandler(new MyContentHandler());
* try { * r.setErrorHandler(new MyErrorHandler());
* r.parse("http://www.foo.com/mydoc.xml"); *
* } catch (IOException e) { * // parse the first document
* System.err.println("I/O exception reading XML document"); * try {
* } catch (SAXException e) { * r.parse("http://www.foo.com/mydoc.xml");
* System.err.println("XML exception reading document."); * } catch (IOException e) {
* } * System.err.println("I/O exception reading XML document");
* </pre> * } catch (SAXException e) {
* * System.err.println("XML exception reading document.");
* <p>Implementors are free (and encouraged) to invent their own features, * }
* using names built on their own URIs.</p> * </pre>
* *
* @param name The feature name, which is a fully-qualified URI. * <p>Implementors are free (and encouraged) to invent their own features,
* @return The current state of the feature (true or false). * using names built on their own URIs.</p>
* @exception org.xml.sax.SAXNotRecognizedException When the *
* XMLReader does not recognize the feature name. * @param name The feature name, which is a fully-qualified URI.
* @exception org.xml.sax.SAXNotSupportedException When the * @return The current value of the feature (true or false).
* XMLReader recognizes the feature name but * @exception org.xml.sax.SAXNotRecognizedException If the feature
* cannot determine its value at this time. * value can't be assigned or retrieved.
* @see #setFeature * @exception org.xml.sax.SAXNotSupportedException When the
*/ * XMLReader recognizes the feature name but
public boolean getFeature (String name) * cannot determine its value at this time.
throws SAXNotRecognizedException, SAXNotSupportedException; * @see #setFeature
*/
public boolean getFeature (String name)
/** throws SAXNotRecognizedException, SAXNotSupportedException;
* Set the state of a feature.
*
* <p>The feature name is any fully-qualified URI. It is /**
* possible for an XMLReader to recognize a feature name but * Set the value of a feature flag.
* to be unable to set its value; this is especially true *
* in the case of an adapter for a SAX1 {@link org.xml.sax.Parser Parser}, * <p>The feature name is any fully-qualified URI. It is
* which has no way of affecting whether the underlying parser is * possible for an XMLReader to expose a feature value but
* validating, for example.</p> * to be unable to change the current value.
* * Some feature values may be immutable or mutable only
* <p>All XMLReaders are required to support setting * in specific contexts, such as before, during, or after
* http://xml.org/sax/features/namespaces to true and * a parse.</p>
* http://xml.org/sax/features/namespace-prefixes to false.</p> *
* * <p>All XMLReaders are required to support setting
* <p>Some feature values may be immutable or mutable only * http://xml.org/sax/features/namespaces to true and
* in specific contexts, such as before, during, or after * http://xml.org/sax/features/namespace-prefixes to false.</p>
* a parse.</p> *
* * @param name The feature name, which is a fully-qualified URI.
* @param name The feature name, which is a fully-qualified URI. * @param value The requested value of the feature (true or false).
* @param state The requested state of the feature (true or false). * @exception org.xml.sax.SAXNotRecognizedException If the feature
* @exception org.xml.sax.SAXNotRecognizedException When the * value can't be assigned or retrieved.
* XMLReader does not recognize the feature name. * @exception org.xml.sax.SAXNotSupportedException When the
* @exception org.xml.sax.SAXNotSupportedException When the * XMLReader recognizes the feature name but
* XMLReader recognizes the feature name but * cannot set the requested value.
* cannot set the requested value. * @see #getFeature
* @see #getFeature */
*/ public void setFeature (String name, boolean value)
public void setFeature (String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException;
throws SAXNotRecognizedException, SAXNotSupportedException;
/**
/** * Look up the value of a property.
* Look up the value of a property. *
* * <p>The property name is any fully-qualified URI. It is
* <p>The property name is any fully-qualified URI. It is * possible for an XMLReader to recognize a property name but
* possible for an XMLReader to recognize a property name but * temporarily be unable to return its value.
* to be unable to return its state; this is especially true * Some property values may be available only in specific
* in the case of an adapter for a SAX1 {@link org.xml.sax.Parser * contexts, such as before, during, or after a parse.</p>
* Parser}.</p> *
* * <p>XMLReaders are not required to recognize any specific
* <p>XMLReaders are not required to recognize any specific * property names, though an initial core set is documented for
* property names, though an initial core set is documented for * SAX2.</p>
* SAX2.</p> *
* * <p>Implementors are free (and encouraged) to invent their own properties,
* <p>Some property values may be available only in specific * using names built on their own URIs.</p>
* contexts, such as before, during, or after a parse.</p> *
* * @param name The property name, which is a fully-qualified URI.
* <p>Implementors are free (and encouraged) to invent their own properties, * @return The current value of the property.
* using names built on their own URIs.</p> * @exception org.xml.sax.SAXNotRecognizedException If the property
* * value can't be assigned or retrieved.
* @param name The property name, which is a fully-qualified URI. * @exception org.xml.sax.SAXNotSupportedException When the
* @return The current value of the property. * XMLReader recognizes the property name but
* @exception org.xml.sax.SAXNotRecognizedException When the * cannot determine its value at this time.
* XMLReader does not recognize the property name. * @see #setProperty
* @exception org.xml.sax.SAXNotSupportedException When the */
* XMLReader recognizes the property name but public Object getProperty (String name)
* cannot determine its value at this time. throws SAXNotRecognizedException, SAXNotSupportedException;
* @see #setProperty
*/
public Object getProperty (String name) /**
throws SAXNotRecognizedException, SAXNotSupportedException; * Set the value of a property.
*
* <p>The property name is any fully-qualified URI. It is
/** * possible for an XMLReader to recognize a property name but
* Set the value of a property. * to be unable to change the current value.
* * Some property values may be immutable or mutable only
* <p>The property name is any fully-qualified URI. It is * in specific contexts, such as before, during, or after
* possible for an XMLReader to recognize a property name but * a parse.</p>
* to be unable to set its value; this is especially true *
* in the case of an adapter for a SAX1 {@link org.xml.sax.Parser * <p>XMLReaders are not required to recognize setting
* Parser}.</p> * any specific property names, though a core set is defined by
* * SAX2.</p>
* <p>XMLReaders are not required to recognize setting *
* any specific property names, though a core set is provided with * <p>This method is also the standard mechanism for setting
* SAX2.</p> * extended handlers.</p>
* *
* <p>Some property values may be immutable or mutable only * @param name The property name, which is a fully-qualified URI.
* in specific contexts, such as before, during, or after * @param value The requested value for the property.
* a parse.</p> * @exception org.xml.sax.SAXNotRecognizedException If the property
* * value can't be assigned or retrieved.
* <p>This method is also the standard mechanism for setting * @exception org.xml.sax.SAXNotSupportedException When the
* extended handlers.</p> * XMLReader recognizes the property name but
* * cannot set the requested value.
* @param name The property name, which is a fully-qualified URI. */
* @param state The requested value for the property. public void setProperty (String name, Object value)
* @exception org.xml.sax.SAXNotRecognizedException When the throws SAXNotRecognizedException, SAXNotSupportedException;
* XMLReader does not recognize the property name.
* @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader recognizes the property name but
* cannot set the requested value. ////////////////////////////////////////////////////////////////////
*/ // Event handlers.
public void setProperty (String name, Object value) ////////////////////////////////////////////////////////////////////
throws SAXNotRecognizedException, SAXNotSupportedException;
/**
* Allow an application to register an entity resolver.
//////////////////////////////////////////////////////////////////// *
// Event handlers. * <p>If the application does not register an entity resolver,
//////////////////////////////////////////////////////////////////// * the XMLReader will perform its own default resolution.</p>
*
* <p>Applications may register a new or different resolver in the
/** * middle of a parse, and the SAX parser must begin using the new
* Allow an application to register an entity resolver. * resolver immediately.</p>
* *
* <p>If the application does not register an entity resolver, * @param resolver The entity resolver.
* the XMLReader will perform its own default resolution.</p> * @see #getEntityResolver
* */
* <p>Applications may register a new or different resolver in the public void setEntityResolver (EntityResolver resolver);
* middle of a parse, and the SAX parser must begin using the new
* resolver immediately.</p>
* /**
* @param resolver The entity resolver. * Return the current entity resolver.
* @exception java.lang.NullPointerException If the resolver *
* argument is null. * @return The current entity resolver, or null if none
* @see #getEntityResolver * has been registered.
*/ * @see #setEntityResolver
public void setEntityResolver (EntityResolver resolver); */
public EntityResolver getEntityResolver ();
/**
* Return the current entity resolver. /**
* * Allow an application to register a DTD event handler.
* @return The current entity resolver, or null if none *
* has been registered. * <p>If the application does not register a DTD handler, all DTD
* @see #setEntityResolver * events reported by the SAX parser will be silently ignored.</p>
*/ *
public EntityResolver getEntityResolver (); * <p>Applications may register a new or different handler in the
* middle of a parse, and the SAX parser must begin using the new
* handler immediately.</p>
/** *
* Allow an application to register a DTD event handler. * @param handler The DTD handler.
* * @see #getDTDHandler
* <p>If the application does not register a DTD handler, all DTD */
* events reported by the SAX parser will be silently ignored.</p> public void setDTDHandler (DTDHandler handler);
*
* <p>Applications may register a new or different handler in the
* middle of a parse, and the SAX parser must begin using the new /**
* handler immediately.</p> * Return the current DTD handler.
* *
* @param handler The DTD handler. * @return The current DTD handler, or null if none
* @exception java.lang.NullPointerException If the handler * has been registered.
* argument is null. * @see #setDTDHandler
* @see #getDTDHandler */
*/ public DTDHandler getDTDHandler ();
public void setDTDHandler (DTDHandler handler);
/**
/** * Allow an application to register a content event handler.
* Return the current DTD handler. *
* * <p>If the application does not register a content handler, all
* @return The current DTD handler, or null if none * content events reported by the SAX parser will be silently
* has been registered. * ignored.</p>
* @see #setDTDHandler *
*/ * <p>Applications may register a new or different handler in the
public DTDHandler getDTDHandler (); * middle of a parse, and the SAX parser must begin using the new
* handler immediately.</p>
*
/** * @param handler The content handler.
* Allow an application to register a content event handler. * @see #getContentHandler
* */
* <p>If the application does not register a content handler, all public void setContentHandler (ContentHandler handler);
* content events reported by the SAX parser will be silently
* ignored.</p>
* /**
* <p>Applications may register a new or different handler in the * Return the current content handler.
* middle of a parse, and the SAX parser must begin using the new *
* handler immediately.</p> * @return The current content handler, or null if none
* * has been registered.
* @param handler The content handler. * @see #setContentHandler
* @exception java.lang.NullPointerException If the handler */
* argument is null. public ContentHandler getContentHandler ();
* @see #getContentHandler
*/
public void setContentHandler (ContentHandler handler); /**
* Allow an application to register an error event handler.
*
/** * <p>If the application does not register an error handler, all
* Return the current content handler. * error events reported by the SAX parser will be silently
* * ignored; however, normal processing may not continue. It is
* @return The current content handler, or null if none * highly recommended that all SAX applications implement an
* has been registered. * error handler to avoid unexpected bugs.</p>
* @see #setContentHandler *
*/ * <p>Applications may register a new or different handler in the
public ContentHandler getContentHandler (); * middle of a parse, and the SAX parser must begin using the new
* handler immediately.</p>
*
/** * @param handler The error handler.
* Allow an application to register an error event handler. * @see #getErrorHandler
* */
* <p>If the application does not register an error handler, all public void setErrorHandler (ErrorHandler handler);
* error events reported by the SAX parser will be silently
* ignored; however, normal processing may not continue. It is
* highly recommended that all SAX applications implement an /**
* error handler to avoid unexpected bugs.</p> * Return the current error handler.
* *
* <p>Applications may register a new or different handler in the * @return The current error handler, or null if none
* middle of a parse, and the SAX parser must begin using the new * has been registered.
* handler immediately.</p> * @see #setErrorHandler
* */
* @param handler The error handler. public ErrorHandler getErrorHandler ();
* @exception java.lang.NullPointerException If the handler
* argument is null.
* @see #getErrorHandler
*/ ////////////////////////////////////////////////////////////////////
public void setErrorHandler (ErrorHandler handler); // Parsing.
////////////////////////////////////////////////////////////////////
/** /**
* Return the current error handler. * Parse an XML document.
* *
* @return The current error handler, or null if none * <p>The application can use this method to instruct the XML
* has been registered. * reader to begin parsing an XML document from any valid input
* @see #setErrorHandler * source (a character stream, a byte stream, or a URI).</p>
*/ *
public ErrorHandler getErrorHandler (); * <p>Applications may not invoke this method while a parse is in
* progress (they should create a new XMLReader instead for each
* nested XML document). Once a parse is complete, an
* application may reuse the same XMLReader object, possibly with a
//////////////////////////////////////////////////////////////////// * different input source.</p>
// Parsing. *
//////////////////////////////////////////////////////////////////// * <p>During the parse, the XMLReader will provide information
* about the XML document through the registered event
/** * handlers.</p>
* Parse an XML document. *
* * <p>This method is synchronous: it will not return until parsing
* <p>The application can use this method to instruct the XML * has ended. If a client application wants to terminate
* reader to begin parsing an XML document from any valid input * parsing early, it should throw an exception.</p>
* source (a character stream, a byte stream, or a URI).</p> *
* * @param source The input source for the top-level of the
* <p>Applications may not invoke this method while a parse is in * XML document.
* progress (they should create a new XMLReader instead for each * @exception org.xml.sax.SAXException Any SAX exception, possibly
* nested XML document). Once a parse is complete, an * wrapping another exception.
* application may reuse the same XMLReader object, possibly with a * @exception java.io.IOException An IO exception from the parser,
* different input source.</p> * possibly from a byte stream or character stream
* * supplied by the application.
* <p>During the parse, the XMLReader will provide information * @see org.xml.sax.InputSource
* about the XML document through the registered event * @see #parse(java.lang.String)
* handlers.</p> * @see #setEntityResolver
* * @see #setDTDHandler
* <p>This method is synchronous: it will not return until parsing * @see #setContentHandler
* has ended. If a client application wants to terminate * @see #setErrorHandler
* parsing early, it should throw an exception.</p> */
* public void parse (InputSource input)
* @param source The input source for the top-level of the throws IOException, SAXException;
* XML document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception. /**
* @exception java.io.IOException An IO exception from the parser, * Parse an XML document from a system identifier (URI).
* possibly from a byte stream or character stream *
* supplied by the application. * <p>This method is a shortcut for the common case of reading a
* @see org.xml.sax.InputSource * document from a system identifier. It is the exact
* @see #parse(java.lang.String) * equivalent of the following:</p>
* @see #setEntityResolver *
* @see #setDTDHandler * <pre>
* @see #setContentHandler * parse(new InputSource(systemId));
* @see #setErrorHandler * </pre>
*/ *
public void parse (InputSource input) * <p>If the system identifier is a URL, it must be fully resolved
throws IOException, SAXException; * by the application before it is passed to the parser.</p>
*
* @param systemId The system identifier (URI).
/** * @exception org.xml.sax.SAXException Any SAX exception, possibly
* Parse an XML document from a system identifier (URI). * wrapping another exception.
* * @exception java.io.IOException An IO exception from the parser,
* <p>This method is a shortcut for the common case of reading a * possibly from a byte stream or character stream
* document from a system identifier. It is the exact * supplied by the application.
* equivalent of the following:</p> * @see #parse(org.xml.sax.InputSource)
* */
* <pre> public void parse (String systemId)
* parse(new InputSource(systemId)); throws IOException, SAXException;
* </pre>
* }
* <p>If the system identifier is a URL, it must be fully resolved
* by the application before it is passed to the parser.</p>
*
* @param systemId The system identifier (URI).
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @exception java.io.IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
* @see #parse(org.xml.sax.InputSource)
*/
public void parse (String systemId)
throws IOException, SAXException;
}
// end of XMLReader.java
// DeclHandler.java - Optional handler for DTD declaration events. // DeclHandler.java - Optional handler for DTD declaration events.
// Public Domain: no warranty. // http://www.saxproject.org
// $Id: DeclHandler.java,v 1.1 2000/10/02 02:43:19 sboag Exp $ // Public Domain: no warranty.
// $Id: DeclHandler.java,v 1.2.2.5 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.ext;
package org.xml.sax.ext;
import org.xml.sax.SAXException;
import org.xml.sax.SAXException;
/**
* SAX2 extension handler for DTD declaration events. /**
* * SAX2 extension handler for DTD declaration events.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This is an optional extension handler for SAX2 to provide * for further information.
* information about DTD declarations in an XML document. XML * </blockquote>
* readers are not required to support this handler.</p> *
* * <p>This is an optional extension handler for SAX2 to provide more
* <p>Note that data-related DTD declarations (unparsed entities and * complete information about DTD declarations in an XML document.
* notations) are already reported through the {@link * XML readers are not required to recognize this handler, and it
* org.xml.sax.DTDHandler DTDHandler} interface.</p> * is not part of core-only SAX2 distributions.</p>
* *
* <p>If you are using the declaration handler together with a lexical * <p>Note that data-related DTD declarations (unparsed entities and
* handler, all of the events will occur between the * notations) are already reported through the {@link
* {@link org.xml.sax.ext.LexicalHandler#startDTD startDTD} and the * org.xml.sax.DTDHandler DTDHandler} interface.</p>
* {@link org.xml.sax.ext.LexicalHandler#endDTD endDTD} events.</p> *
* * <p>If you are using the declaration handler together with a lexical
* <p>To set the DeclHandler for an XML reader, use the * handler, all of the events will occur between the
* {@link org.xml.sax.XMLReader#setProperty setProperty} method * {@link org.xml.sax.ext.LexicalHandler#startDTD startDTD} and the
* with the propertyId "http://xml.org/sax/handlers/DeclHandler". * {@link org.xml.sax.ext.LexicalHandler#endDTD endDTD} events.</p>
* If the reader does not support declaration events, it will throw a *
* {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException} * <p>To set the DeclHandler for an XML reader, use the
* or a * {@link org.xml.sax.XMLReader#setProperty setProperty} method
* {@link org.xml.sax.SAXNotSupportedException SAXNotSupportedException} * with the property name
* when you attempt to register the handler.</p> * <code>http://xml.org/sax/properties/declaration-handler</code>
* * and an object implementing this interface (or null) as the value.
* @since SAX 2.0 * If the reader does not report declaration events, it will throw a
* @author David Megginson, * {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * when you attempt to register the handler.</p>
* @version 2.0beta *
* @see org.xml.sax.XMLReader * @since SAX 2.0 (extensions 1.0)
*/ * @author David Megginson
public interface DeclHandler * @version 2.0.1 (sax2r2)
{ */
public interface DeclHandler
/** {
* Report an element type declaration.
* /**
* <p>The content model will consist of the string "EMPTY", the * Report an element type declaration.
* string "ANY", or a parenthesised group, optionally followed *
* by an occurrence indicator. The model will be normalized so * <p>The content model will consist of the string "EMPTY", the
* that all whitespace is removed,and will include the enclosing * string "ANY", or a parenthesised group, optionally followed
* parentheses.</p> * by an occurrence indicator. The model will be normalized so
* * that all parameter entities are fully resolved and all whitespace
* @param name The element type name. * is removed,and will include the enclosing parentheses. Other
* @param model The content model as a normalized string. * normalization (such as removing redundant parentheses or
* @exception SAXException The application may raise an exception. * simplifying occurrence indicators) is at the discretion of the
*/ * parser.</p>
public abstract void elementDecl (String name, String model) *
throws SAXException; * @param name The element type name.
* @param model The content model as a normalized string.
* @exception SAXException The application may raise an exception.
/** */
* Report an attribute type declaration. public abstract void elementDecl (String name, String model)
* throws SAXException;
* <p>Only the effective (first) declaration for an attribute will
* be reported. The type will be one of the strings "CDATA",
* "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", /**
* "ENTITIES", or "NOTATION", or a parenthesized token group with * Report an attribute type declaration.
* the separator "|" and all whitespace removed.</p> *
* * <p>Only the effective (first) declaration for an attribute will
* @param eName The name of the associated element. * be reported. The type will be one of the strings "CDATA",
* @param aName The name of the attribute. * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",
* @param type A string representing the attribute type. * "ENTITIES", a parenthesized token group with
* @param valueDefault A string representing the attribute default * the separator "|" and all whitespace removed, or the word
* ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if * "NOTATION" followed by a space followed by a parenthesized
* none of these applies. * token group with all whitespace removed.</p>
* @param value A string representing the attribute's default value, *
* or null if there is none. * <p>The value will be the value as reported to applications,
* @exception SAXException The application may raise an exception. * appropriately normalized and with entity and character
*/ * references expanded. </p>
public abstract void attributeDecl (String eName, *
String aName, * @param eName The name of the associated element.
String type, * @param aName The name of the attribute.
String valueDefault, * @param type A string representing the attribute type.
String value) * @param mode A string representing the attribute defaulting mode
throws SAXException; * ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
* none of these applies.
* @param value A string representing the attribute's default value,
/** * or null if there is none.
* Report an internal entity declaration. * @exception SAXException The application may raise an exception.
* */
* <p>Only the effective (first) declaration for each entity public abstract void attributeDecl (String eName,
* will be reported.</p> String aName,
* String type,
* @param name The name of the entity. If it is a parameter String mode,
* entity, the name will begin with '%'. String value)
* @param value The replacement text of the entity. throws SAXException;
* @exception SAXException The application may raise an exception.
* @see #externalEntityDecl
* @see org.xml.sax.DTDHandler#unparsedEntityDecl /**
*/ * Report an internal entity declaration.
public abstract void internalEntityDecl (String name, String value) *
throws SAXException; * <p>Only the effective (first) declaration for each entity
* will be reported. All parameter entities in the value
* will be expanded, but general entities will not.</p>
/** *
* Report a parsed external entity declaration. * @param name The name of the entity. If it is a parameter
* * entity, the name will begin with '%'.
* <p>Only the effective (first) declaration for each entity * @param value The replacement text of the entity.
* will be reported.</p> * @exception SAXException The application may raise an exception.
* * @see #externalEntityDecl
* @param name The name of the entity. If it is a parameter * @see org.xml.sax.DTDHandler#unparsedEntityDecl
* entity, the name will begin with '%'. */
* @param publicId The declared public identifier of the entity, or public abstract void internalEntityDecl (String name, String value)
* null if none was declared. throws SAXException;
* @param systemId The declared system identifier of the entity.
* @exception SAXException The application may raise an exception.
* @see #internalEntityDecl /**
* @see org.xml.sax.DTDHandler#unparsedEntityDecl * Report a parsed external entity declaration.
*/ *
public abstract void externalEntityDecl (String name, String publicId, * <p>Only the effective (first) declaration for each entity
String systemId) * will be reported.</p>
throws SAXException; *
* @param name The name of the entity. If it is a parameter
} * entity, the name will begin with '%'.
* @param publicId The declared public identifier of the entity, or
// end of DeclHandler.java * null if none was declared.
* @param systemId The declared system identifier of the entity.
* @exception SAXException The application may raise an exception.
* @see #internalEntityDecl
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public abstract void externalEntityDecl (String name, String publicId,
String systemId)
throws SAXException;
}
// end of DeclHandler.java
// LexicalHandler.java - optional handler for lexical parse events. // LexicalHandler.java - optional handler for lexical parse events.
// Public Domain: no warranty. // http://www.saxproject.org
// $Id: LexicalHandler.java,v 1.1 2000/10/02 02:43:20 sboag Exp $ // Public Domain: no warranty.
// $Id: LexicalHandler.java,v 1.2.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.ext;
package org.xml.sax.ext;
import org.xml.sax.SAXException;
import org.xml.sax.SAXException;
/**
* SAX2 extension handler for lexical events. /**
* * SAX2 extension handler for lexical events.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This is an optional extension handler for SAX2 to provide * for further information.
* lexical information about an XML document, such as comments * </blockquote>
* and CDATA section boundaries; XML readers are not required to *
* support this handler.</p> * <p>This is an optional extension handler for SAX2 to provide
* * lexical information about an XML document, such as comments
* <p>The events in the lexical handler apply to the entire document, * and CDATA section boundaries.
* not just to the document element, and all lexical handler events * XML readers are not required to recognize this handler, and it
* must appear between the content handler's startDocument and * is not part of core-only SAX2 distributions.</p>
* endDocument events.</p> *
* * <p>The events in the lexical handler apply to the entire document,
* <p>To set the LexicalHandler for an XML reader, use the * not just to the document element, and all lexical handler events
* {@link org.xml.sax.XMLReader#setProperty setProperty} method * must appear between the content handler's startDocument and
* with the propertyId "http://xml.org/sax/handlers/LexicalHandler". * endDocument events.</p>
* If the reader does not support lexical events, it will throw a *
* {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException} * <p>To set the LexicalHandler for an XML reader, use the
* or a * {@link org.xml.sax.XMLReader#setProperty setProperty} method
* {@link org.xml.sax.SAXNotSupportedException SAXNotSupportedException} * with the property name
* when you attempt to register the handler.</p> * <code>http://xml.org/sax/properties/lexical-handler</code>
* * and an object implementing this interface (or null) as the value.
* @since SAX 2.0 * If the reader does not report lexical events, it will throw a
* @author David Megginson, * {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * when you attempt to register the handler.</p>
* @version 2.0beta *
* @see org.xml.sax.XMLReader#setProperty * @since SAX 2.0 (extensions 1.0)
* @see org.xml.sax.SAXNotRecognizedException * @author David Megginson
* @see org.xml.sax.SAXNotSupportedException * @version 2.0.1 (sax2r2)
*/ */
public interface LexicalHandler public interface LexicalHandler
{ {
/** /**
* Report the start of DTD declarations, if any. * Report the start of DTD declarations, if any.
* *
* <p>Any declarations are assumed to be in the internal subset * <p>This method is intended to report the beginning of the
* unless otherwise indicated by a {@link #startEntity startEntity} * DOCTYPE declaration; if the document has no DOCTYPE declaration,
* event.</p> * this method will not be invoked.</p>
* *
* <p>Note that the start/endDTD events will appear within * <p>All declarations reported through
* the start/endDocument events from ContentHandler and * {@link org.xml.sax.DTDHandler DTDHandler} or
* before the first startElement event.</p> * {@link org.xml.sax.ext.DeclHandler DeclHandler} events must appear
* * between the startDTD and {@link #endDTD endDTD} events.
* @param name The document type name. * Declarations are assumed to belong to the internal DTD subset
* @param publicId The declared public identifier for the * unless they appear between {@link #startEntity startEntity}
* external DTD subset, or null if none was declared. * and {@link #endEntity endEntity} events. Comments and
* @param systemId The declared system identifier for the * processing instructions from the DTD should also be reported
* external DTD subset, or null if none was declared. * between the startDTD and endDTD events, in their original
* @exception SAXException The application may raise an * order of (logical) occurrence; they are not required to
* exception. * appear in their correct locations relative to DTDHandler
* @see #endDTD * or DeclHandler events, however.</p>
* @see #startEntity *
*/ * <p>Note that the start/endDTD events will appear within
public abstract void startDTD (String name, String publicId, * the start/endDocument events from ContentHandler and
String systemId) * before the first
throws SAXException; * {@link org.xml.sax.ContentHandler#startElement startElement}
* event.</p>
*
/** * @param name The document type name.
* Report the end of DTD declarations. * @param publicId The declared public identifier for the
* * external DTD subset, or null if none was declared.
* @exception SAXException The application may raise an exception. * @param systemId The declared system identifier for the
* @see #startDTD * external DTD subset, or null if none was declared.
*/ * (Note that this is not resolved against the document
public abstract void endDTD () * base URI.)
throws SAXException; * @exception SAXException The application may raise an
* exception.
* @see #endDTD
/** * @see #startEntity
* Report the beginning of an entity in content. */
* public abstract void startDTD (String name, String publicId,
* <p><strong>NOTE:</entity> entity references in attribute String systemId)
* values -- and the start and end of the document entity -- throws SAXException;
* are never reported.</p>
*
* <p>The start and end of the external DTD subset are reported /**
* using the pseudo-name "[dtd]". All other events must be * Report the end of DTD declarations.
* properly nested within start/end entity events.</p> *
* * <p>This method is intended to report the end of the
* <p>Note that skipped entities will be reported through the * DOCTYPE declaration; if the document has no DOCTYPE declaration,
* {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity} * this method will not be invoked.</p>
* event, which is part of the ContentHandler interface.</p> *
* * @exception SAXException The application may raise an exception.
* @param name The name of the entity. If it is a parameter * @see #startDTD
* entity, the name will begin with '%'. */
* @exception SAXException The application may raise an exception. public abstract void endDTD ()
* @see #endEntity throws SAXException;
* @see org.xml.sax.ext.DeclHandler#internalEntityDecl
* @see org.xml.sax.ext.DeclHandler#externalEntityDecl
*/ /**
public abstract void startEntity (String name) * Report the beginning of some internal and external XML entities.
throws SAXException; *
* <p>The reporting of parameter entities (including
* the external DTD subset) is optional, and SAX2 drivers that
/** * report LexicalHandler events may not implement it; you can use the
* Report the end of an entity. * <code
* * >http://xml.org/sax/features/lexical-handler/parameter-entities</code>
* @param name The name of the entity that is ending. * feature to query or control the reporting of parameter entities.</p>
* @exception SAXException The application may raise an exception. *
* @see #startEntity * <p>General entities are reported with their regular names,
*/ * parameter entities have '%' prepended to their names, and
public abstract void endEntity (String name) * the external DTD subset has the pseudo-entity name "[dtd]".</p>
throws SAXException; *
* <p>When a SAX2 driver is providing these events, all other
* events must be properly nested within start/end entity
/** * events. There is no additional requirement that events from
* Report the start of a CDATA section. * {@link org.xml.sax.ext.DeclHandler DeclHandler} or
* * {@link org.xml.sax.DTDHandler DTDHandler} be properly ordered.</p>
* <p>The contents of the CDATA section will be reported through *
* the regular {@link org.xml.sax.ContentHandler#characters * <p>Note that skipped entities will be reported through the
* characters} event.</p> * {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity}
* * event, which is part of the ContentHandler interface.</p>
* @exception SAXException The application may raise an exception. *
* @see #endCDATA * <p>Because of the streaming event model that SAX uses, some
*/ * entity boundaries cannot be reported under any
public abstract void startCDATA () * circumstances:</p>
throws SAXException; *
* <ul>
* <li>general entities within attribute values</li>
/** * <li>parameter entities within declarations</li>
* Report the end of a CDATA section. * </ul>
* *
* @exception SAXException The application may raise an exception. * <p>These will be silently expanded, with no indication of where
* @see #startCDATA * the original entity boundaries were.</p>
*/ *
public abstract void endCDATA () * <p>Note also that the boundaries of character references (which
throws SAXException; * are not really entities anyway) are not reported.</p>
*
* <p>All start/endEntity events must be properly nested.
/** *
* Report an XML comment anywhere in the document. * @param name The name of the entity. If it is a parameter
* * entity, the name will begin with '%', and if it is the
* <p>This callback will be used for comments inside or outside the * external DTD subset, it will be "[dtd]".
* document element, including comments in the external DTD * @exception SAXException The application may raise an exception.
* subset (if read).</p> * @see #endEntity
* * @see org.xml.sax.ext.DeclHandler#internalEntityDecl
* @param ch An array holding the characters in the comment. * @see org.xml.sax.ext.DeclHandler#externalEntityDecl
* @param start The starting position in the array. */
* @param length The number of characters to use from the array. public abstract void startEntity (String name)
* @exception SAXException The application may raise an exception. throws SAXException;
*/
public abstract void comment (char ch[], int start, int length)
throws SAXException; /**
* Report the end of an entity.
} *
* @param name The name of the entity that is ending.
// end of LexicalHandler.java * @exception SAXException The application may raise an exception.
* @see #startEntity
*/
public abstract void endEntity (String name)
throws SAXException;
/**
* Report the start of a CDATA section.
*
* <p>The contents of the CDATA section will be reported through
* the regular {@link org.xml.sax.ContentHandler#characters
* characters} event; this event is intended only to report
* the boundary.</p>
*
* @exception SAXException The application may raise an exception.
* @see #endCDATA
*/
public abstract void startCDATA ()
throws SAXException;
/**
* Report the end of a CDATA section.
*
* @exception SAXException The application may raise an exception.
* @see #startCDATA
*/
public abstract void endCDATA ()
throws SAXException;
/**
* Report an XML comment anywhere in the document.
*
* <p>This callback will be used for comments inside or outside the
* document element, including comments in the external DTD
* subset (if read). Comments in the DTD must be properly
* nested inside start/endDTD and start/endEntity events (if
* used).</p>
*
* @param ch An array holding the characters in the comment.
* @param start The starting position in the array.
* @param length The number of characters to use from the array.
* @exception SAXException The application may raise an exception.
*/
public abstract void comment (char ch[], int start, int length)
throws SAXException;
}
// end of LexicalHandler.java
<HTML><HEAD>
</HEAD><BODY>
<p>
This package contains interfaces to optional SAX2 handlers.
<p>See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
for more information about SAX.</p>
<p>
The package is independent of the SAX2 core, though the functionality
exposed generally needs to be implemented within a parser.
That independence has several consequences:</p>
<ul>
<li>SAX2 drivers are <em>not</em> required to recognize these handlers,
and you cannot assume that the class files will be present in every SAX2
installation.</li>
<li>This package may be updated independently of SAX2 (i.e. new
handlers may be added without updating SAX2 itself).</li>
<li>The handlers are not implemented by the SAX2
<code>org.xml.sax.helpers.DefaultHandler</code> or
<code>org.xml.sax.helpers.XMLFilterImpl</code> classes.
You can subclass these if you need such behaviour.</li>
<li>The handlers need to be registered differently than regular SAX2
handlers.</li>
</ul>
<p>This package, SAX2-ext, is a standardized extension to SAX2. It is
designed both to allow SAX parsers to pass certain types of information
to applications, and to serve as a simple model for other SAX2 parser
extension packages. Not all such extension packages should need to
be recognized directly by parsers, however.
As an example, most schema systems can be cleanly layered on top
of parsers supporting the standardized SAX2 interfaces. </p>
<p><strong>NOTE:</strong> this package alone does add any
functionality; it simply provides optional interfaces for SAX2 drivers
to use. You must use a SAX2 driver that recognizes these interfaces if
you actually want to have access to lexical and declaration
information.</p>
</BODY></HTML>
// SAX default implementation for AttributeList. // SAX default implementation for AttributeList.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: AttributeListImpl.java,v 1.1 2000/10/02 02:43:20 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: AttributeListImpl.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import org.xml.sax.AttributeList;
import org.xml.sax.AttributeList;
import java.util.Vector;
import java.util.Vector;
/**
* Default implementation for AttributeList. /**
* * Default implementation for AttributeList.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>AttributeList implements the deprecated SAX1 {@link * for further information.
* org.xml.sax.AttributeList AttributeList} interface, and has been * </blockquote>
* replaced by the new SAX2 {@link org.xml.sax.helpers.AttributesImpl *
* AttributesImpl} interface.</p> * <p>AttributeList implements the deprecated SAX1 {@link
* * org.xml.sax.AttributeList AttributeList} interface, and has been
* <p>This class provides a convenience implementation of the SAX * replaced by the new SAX2 {@link org.xml.sax.helpers.AttributesImpl
* {@link org.xml.sax.AttributeList AttributeList} interface. This * AttributesImpl} interface.</p>
* implementation is useful both for SAX parser writers, who can use *
* it to provide attributes to the application, and for SAX application * <p>This class provides a convenience implementation of the SAX
* writers, who can use it to create a persistent copy of an element's * {@link org.xml.sax.AttributeList AttributeList} interface. This
* attribute specifications:</p> * implementation is useful both for SAX parser writers, who can use
* * it to provide attributes to the application, and for SAX application
* <pre> * writers, who can use it to create a persistent copy of an element's
* private AttributeList myatts; * attribute specifications:</p>
* *
* public void startElement (String name, AttributeList atts) * <pre>
* { * private AttributeList myatts;
* // create a persistent copy of the attribute list *
* // for use outside this method * public void startElement (String name, AttributeList atts)
* myatts = new AttributeListImpl(atts); * {
* [...] * // create a persistent copy of the attribute list
* } * // for use outside this method
* </pre> * myatts = new AttributeListImpl(atts);
* * [...]
* <p>Please note that SAX parsers are not required to use this * }
* class to provide an implementation of AttributeList; it is * </pre>
* supplied only as an optional convenience. In particular, *
* parser writers are encouraged to invent more efficient * <p>Please note that SAX parsers are not required to use this
* implementations.</p> * class to provide an implementation of AttributeList; it is
* * supplied only as an optional convenience. In particular,
* @deprecated This class implements a deprecated interface, * parser writers are encouraged to invent more efficient
* {@link org.xml.sax.AttributeList AttributeList}; * implementations.</p>
* that interface has been replaced by *
* {@link org.xml.sax.Attributes Attributes}, * @deprecated This class implements a deprecated interface,
* which is implemented in the * {@link org.xml.sax.AttributeList AttributeList};
* {@link org.xml.sax.helpers.AttributesImpl * that interface has been replaced by
* AttributesImpl} helper class. * {@link org.xml.sax.Attributes Attributes},
* @since SAX 1.0 * which is implemented in the
* @author David Megginson, * {@link org.xml.sax.helpers.AttributesImpl
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * AttributesImpl} helper class.
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.AttributeList * @author David Megginson
* @see org.xml.sax.DocumentHandler#startElement * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.AttributeList
public class AttributeListImpl implements AttributeList * @see org.xml.sax.DocumentHandler#startElement
{ */
public class AttributeListImpl implements AttributeList
/** {
* Create an empty attribute list.
* /**
* <p>This constructor is most useful for parser writers, who * Create an empty attribute list.
* will use it to create a single, reusable attribute list that *
* can be reset with the clear method between elements.</p> * <p>This constructor is most useful for parser writers, who
* * will use it to create a single, reusable attribute list that
* @see #addAttribute * can be reset with the clear method between elements.</p>
* @see #clear *
*/ * @see #addAttribute
public AttributeListImpl () * @see #clear
{ */
} public AttributeListImpl ()
{
}
/**
* Construct a persistent copy of an existing attribute list.
* /**
* <p>This constructor is most useful for application writers, * Construct a persistent copy of an existing attribute list.
* who will use it to create a persistent copy of an existing *
* attribute list.</p> * <p>This constructor is most useful for application writers,
* * who will use it to create a persistent copy of an existing
* @param atts The attribute list to copy * attribute list.</p>
* @see org.xml.sax.DocumentHandler#startElement *
*/ * @param atts The attribute list to copy
public AttributeListImpl (AttributeList atts) * @see org.xml.sax.DocumentHandler#startElement
{ */
setAttributeList(atts); public AttributeListImpl (AttributeList atts)
} {
setAttributeList(atts);
}
////////////////////////////////////////////////////////////////////
// Methods specific to this class.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Methods specific to this class.
////////////////////////////////////////////////////////////////////
/**
* Set the attribute list, discarding previous contents.
* /**
* <p>This method allows an application writer to reuse an * Set the attribute list, discarding previous contents.
* attribute list easily.</p> *
* * <p>This method allows an application writer to reuse an
* @param atts The attribute list to copy. * attribute list easily.</p>
*/ *
public void setAttributeList (AttributeList atts) * @param atts The attribute list to copy.
{ */
int count = atts.getLength(); public void setAttributeList (AttributeList atts)
{
clear(); int count = atts.getLength();
for (int i = 0; i < count; i++) { clear();
addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i));
} for (int i = 0; i < count; i++) {
} addAttribute(atts.getName(i), atts.getType(i), atts.getValue(i));
}
}
/**
* Add an attribute to an attribute list.
* /**
* <p>This method is provided for SAX parser writers, to allow them * Add an attribute to an attribute list.
* to build up an attribute list incrementally before delivering *
* it to the application.</p> * <p>This method is provided for SAX parser writers, to allow them
* * to build up an attribute list incrementally before delivering
* @param name The attribute name. * it to the application.</p>
* @param type The attribute type ("NMTOKEN" for an enumeration). *
* @param value The attribute value (must not be null). * @param name The attribute name.
* @see #removeAttribute * @param type The attribute type ("NMTOKEN" for an enumeration).
* @see org.xml.sax.DocumentHandler#startElement * @param value The attribute value (must not be null).
*/ * @see #removeAttribute
public void addAttribute (String name, String type, String value) * @see org.xml.sax.DocumentHandler#startElement
{ */
names.addElement(name); public void addAttribute (String name, String type, String value)
types.addElement(type); {
values.addElement(value); names.addElement(name);
} types.addElement(type);
values.addElement(value);
}
/**
* Remove an attribute from the list.
* /**
* <p>SAX application writers can use this method to filter an * Remove an attribute from the list.
* attribute out of an AttributeList. Note that invoking this *
* method will change the length of the attribute list and * <p>SAX application writers can use this method to filter an
* some of the attribute's indices.</p> * attribute out of an AttributeList. Note that invoking this
* * method will change the length of the attribute list and
* <p>If the requested attribute is not in the list, this is * some of the attribute's indices.</p>
* a no-op.</p> *
* * <p>If the requested attribute is not in the list, this is
* @param name The attribute name. * a no-op.</p>
* @see #addAttribute *
*/ * @param name The attribute name.
public void removeAttribute (String name) * @see #addAttribute
{ */
int i = names.indexOf(name); public void removeAttribute (String name)
{
if (i >= 0) { int i = names.indexOf(name);
names.removeElementAt(i);
types.removeElementAt(i); if (i >= 0) {
values.removeElementAt(i); names.removeElementAt(i);
} types.removeElementAt(i);
} values.removeElementAt(i);
}
}
/**
* Clear the attribute list.
* /**
* <p>SAX parser writers can use this method to reset the attribute * Clear the attribute list.
* list between DocumentHandler.startElement events. Normally, *
* it will make sense to reuse the same AttributeListImpl object * <p>SAX parser writers can use this method to reset the attribute
* rather than allocating a new one each time.</p> * list between DocumentHandler.startElement events. Normally,
* * it will make sense to reuse the same AttributeListImpl object
* @see org.xml.sax.DocumentHandler#startElement * rather than allocating a new one each time.</p>
*/ *
public void clear () * @see org.xml.sax.DocumentHandler#startElement
{ */
names.removeAllElements(); public void clear ()
types.removeAllElements(); {
values.removeAllElements(); names.removeAllElements();
} types.removeAllElements();
values.removeAllElements();
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.AttributeList
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.AttributeList
////////////////////////////////////////////////////////////////////
/**
* Return the number of attributes in the list.
* /**
* @return The number of attributes in the list. * Return the number of attributes in the list.
* @see org.xml.sax.AttributeList#getLength *
*/ * @return The number of attributes in the list.
public int getLength () * @see org.xml.sax.AttributeList#getLength
{ */
return names.size(); public int getLength ()
} {
return names.size();
}
/**
* Get the name of an attribute (by position).
* /**
* @param i The position of the attribute in the list. * Get the name of an attribute (by position).
* @return The attribute name as a string, or null if there *
* is no attribute at that position. * @param i The position of the attribute in the list.
* @see org.xml.sax.AttributeList#getName(int) * @return The attribute name as a string, or null if there
*/ * is no attribute at that position.
public String getName (int i) * @see org.xml.sax.AttributeList#getName(int)
{ */
if (i < 0) { public String getName (int i)
return null; {
} if (i < 0) {
try { return null;
return (String)names.elementAt(i); }
} catch (ArrayIndexOutOfBoundsException e) { try {
return null; return (String)names.elementAt(i);
} } catch (ArrayIndexOutOfBoundsException e) {
} return null;
}
}
/**
* Get the type of an attribute (by position).
* /**
* @param i The position of the attribute in the list. * Get the type of an attribute (by position).
* @return The attribute type as a string ("NMTOKEN" for an *
* enumeration, and "CDATA" if no declaration was * @param i The position of the attribute in the list.
* read), or null if there is no attribute at * @return The attribute type as a string ("NMTOKEN" for an
* that position. * enumeration, and "CDATA" if no declaration was
* @see org.xml.sax.AttributeList#getType(int) * read), or null if there is no attribute at
*/ * that position.
public String getType (int i) * @see org.xml.sax.AttributeList#getType(int)
{ */
if (i < 0) { public String getType (int i)
return null; {
} if (i < 0) {
try { return null;
return (String)types.elementAt(i); }
} catch (ArrayIndexOutOfBoundsException e) { try {
return null; return (String)types.elementAt(i);
} } catch (ArrayIndexOutOfBoundsException e) {
} return null;
}
}
/**
* Get the value of an attribute (by position).
* /**
* @param i The position of the attribute in the list. * Get the value of an attribute (by position).
* @return The attribute value as a string, or null if *
* there is no attribute at that position. * @param i The position of the attribute in the list.
* @see org.xml.sax.AttributeList#getValue(int) * @return The attribute value as a string, or null if
*/ * there is no attribute at that position.
public String getValue (int i) * @see org.xml.sax.AttributeList#getValue(int)
{ */
if (i < 0) { public String getValue (int i)
return null; {
} if (i < 0) {
try { return null;
return (String)values.elementAt(i); }
} catch (ArrayIndexOutOfBoundsException e) { try {
return null; return (String)values.elementAt(i);
} } catch (ArrayIndexOutOfBoundsException e) {
} return null;
}
}
/**
* Get the type of an attribute (by name).
* /**
* @param name The attribute name. * Get the type of an attribute (by name).
* @return The attribute type as a string ("NMTOKEN" for an *
* enumeration, and "CDATA" if no declaration was * @param name The attribute name.
* read). * @return The attribute type as a string ("NMTOKEN" for an
* @see org.xml.sax.AttributeList#getType(java.lang.String) * enumeration, and "CDATA" if no declaration was
*/ * read).
public String getType (String name) * @see org.xml.sax.AttributeList#getType(java.lang.String)
{ */
return getType(names.indexOf(name)); public String getType (String name)
} {
return getType(names.indexOf(name));
}
/**
* Get the value of an attribute (by name).
* /**
* @param name The attribute name. * Get the value of an attribute (by name).
* @see org.xml.sax.AttributeList#getValue(java.lang.String) *
*/ * @param name The attribute name.
public String getValue (String name) * @see org.xml.sax.AttributeList#getValue(java.lang.String)
{ */
return getValue(names.indexOf(name)); public String getValue (String name)
} {
return getValue(names.indexOf(name));
}
////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Internal state.
Vector names = new Vector(); ////////////////////////////////////////////////////////////////////
Vector types = new Vector();
Vector values = new Vector(); Vector names = new Vector();
Vector types = new Vector();
} Vector values = new Vector();
// end of AttributeListImpl.java }
// end of AttributeListImpl.java
// AttributesImpl.java - default implementation of Attributes. // AttributesImpl.java - default implementation of Attributes.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the public domain. // Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: AttributesImpl.java,v 1.2 2001/05/31 16:03:17 garyp Exp $
// $Id: AttributesImpl.java,v 1.6.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import org.xml.sax.Attributes;
import org.xml.sax.Attributes;
/**
* Default implementation of the Attributes interface. /**
* * Default implementation of the Attributes interface.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class provides a default implementation of the SAX2 * for further information.
* {@link org.xml.sax.Attributes Attributes} interface, with the * </blockquote>
* addition of manipulators so that the list can be modified or *
* reused.</p> * <p>This class provides a default implementation of the SAX2
* * {@link org.xml.sax.Attributes Attributes} interface, with the
* <p>There are two typical uses of this class:</p> * addition of manipulators so that the list can be modified or
* * reused.</p>
* <ol> *
* <li>to take a persistent snapshot of an Attributes object * <p>There are two typical uses of this class:</p>
* in a {@link org.xml.sax.ContentHandler#startElement startElement} event; or</li> *
* <li>to construct or modify an Attributes object in a SAX2 driver or filter.</li> * <ol>
* </ol> * <li>to take a persistent snapshot of an Attributes object
* * in a {@link org.xml.sax.ContentHandler#startElement startElement} event; or</li>
* <p>This class replaces the now-deprecated SAX1 {@link * <li>to construct or modify an Attributes object in a SAX2 driver or filter.</li>
* org.xml.sax.helpers.AttributeListImpl AttributeListImpl} * </ol>
* class; in addition to supporting the updated Attributes *
* interface rather than the deprecated {@link org.xml.sax.AttributeList * <p>This class replaces the now-deprecated SAX1 {@link
* AttributeList} interface, it also includes a much more efficient * org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
* implementation using a single array rather than a set of Vectors.</p> * class; in addition to supporting the updated Attributes
* * interface rather than the deprecated {@link org.xml.sax.AttributeList
* @since SAX 2.0 * AttributeList} interface, it also includes a much more efficient
* @author David Megginson, * implementation using a single array rather than a set of Vectors.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
*/ * @author David Megginson
public class AttributesImpl implements Attributes * @version 2.0.1 (sax2r2)
{ */
public class AttributesImpl implements Attributes
{
////////////////////////////////////////////////////////////////////
// Constructors.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Constructors.
////////////////////////////////////////////////////////////////////
/**
* Construct a new, empty AttributesImpl object.
*/ /**
public AttributesImpl () * Construct a new, empty AttributesImpl object.
{ */
length = 0; public AttributesImpl ()
data = null; {
} length = 0;
data = null;
}
/**
* Copy an existing Attributes object.
* /**
* <p>This constructor is especially useful inside a * Copy an existing Attributes object.
* {@link org.xml.sax.ContentHandler#startElement startElement} event.</p> *
* * <p>This constructor is especially useful inside a
* @param atts The existing Attributes object. * {@link org.xml.sax.ContentHandler#startElement startElement} event.</p>
*/ *
public AttributesImpl (Attributes atts) * @param atts The existing Attributes object.
{ */
setAttributes(atts); public AttributesImpl (Attributes atts)
} {
setAttributes(atts);
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Attributes.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Attributes.
////////////////////////////////////////////////////////////////////
/**
* Return the number of attributes in the list.
* /**
* @return The number of attributes in the list. * Return the number of attributes in the list.
* @see org.xml.sax.Attributes#getLength *
*/ * @return The number of attributes in the list.
public int getLength () * @see org.xml.sax.Attributes#getLength
{ */
return length; public int getLength ()
} {
return length;
}
/**
* Return an attribute's Namespace URI.
* /**
* @param index The attribute's index (zero-based). * Return an attribute's Namespace URI.
* @return The Namespace URI, the empty string if none is *
* available, or null if the index is out of range. * @param index The attribute's index (zero-based).
* @see org.xml.sax.Attributes#getURI * @return The Namespace URI, the empty string if none is
*/ * available, or null if the index is out of range.
public String getURI (int index) * @see org.xml.sax.Attributes#getURI
{ */
if (index >= 0 && index < length) { public String getURI (int index)
return data[index*5]; {
} else { if (index >= 0 && index < length) {
return null; return data[index*5];
} } else {
} return null;
}
}
/**
* Return an attribute's local name.
* /**
* @param index The attribute's index (zero-based). * Return an attribute's local name.
* @return The attribute's local name, the empty string if *
* none is available, or null if the index if out of range. * @param index The attribute's index (zero-based).
* @see org.xml.sax.Attributes#getLocalName * @return The attribute's local name, the empty string if
*/ * none is available, or null if the index if out of range.
public String getLocalName (int index) * @see org.xml.sax.Attributes#getLocalName
{ */
if (index >= 0 && index < length) { public String getLocalName (int index)
return data[index*5+1]; {
} else { if (index >= 0 && index < length) {
return null; return data[index*5+1];
} } else {
} return null;
}
}
/**
* Return an attribute's qualified (prefixed) name.
* /**
* @param index The attribute's index (zero-based). * Return an attribute's qualified (prefixed) name.
* @return The attribute's qualified name, the empty string if *
* none is available, or null if the index is out of bounds. * @param index The attribute's index (zero-based).
* @see org.xml.sax.Attributes#getQName * @return The attribute's qualified name, the empty string if
*/ * none is available, or null if the index is out of bounds.
public String getQName (int index) * @see org.xml.sax.Attributes#getQName
{ */
if (index >= 0 && index < length) { public String getQName (int index)
return data[index*5+2]; {
} else { if (index >= 0 && index < length) {
return null; return data[index*5+2];
} } else {
} return null;
}
}
/**
* Return an attribute's type by index.
* /**
* @param index The attribute's index (zero-based). * Return an attribute's type by index.
* @return The attribute's type, "CDATA" if the type is unknown, or null *
* if the index is out of bounds. * @param index The attribute's index (zero-based).
* @see org.xml.sax.Attributes#getType(int) * @return The attribute's type, "CDATA" if the type is unknown, or null
*/ * if the index is out of bounds.
public String getType (int index) * @see org.xml.sax.Attributes#getType(int)
{ */
if (index >= 0 && index < length) { public String getType (int index)
return data[index*5+3]; {
} else { if (index >= 0 && index < length) {
return null; return data[index*5+3];
} } else {
} return null;
}
}
/**
* Return an attribute's value by index.
* /**
* @param index The attribute's index (zero-based). * Return an attribute's value by index.
* @return The attribute's value or null if the index is out of bounds. *
* @see org.xml.sax.Attributes#getValue(int) * @param index The attribute's index (zero-based).
*/ * @return The attribute's value or null if the index is out of bounds.
public String getValue (int index) * @see org.xml.sax.Attributes#getValue(int)
{ */
if (index >= 0 && index < length) { public String getValue (int index)
return data[index*5+4]; {
} else { if (index >= 0 && index < length) {
return null; return data[index*5+4];
} } else {
} return null;
}
}
/**
* Look up an attribute's index by Namespace name.
* /**
* <p>In many cases, it will be more efficient to look up the name once and * Look up an attribute's index by Namespace name.
* use the index query methods rather than using the name query methods *
* repeatedly.</p> * <p>In many cases, it will be more efficient to look up the name once and
* * use the index query methods rather than using the name query methods
* @param uri The attribute's Namespace URI, or the empty * repeatedly.</p>
* string if none is available. *
* @param localName The attribute's local name. * @param uri The attribute's Namespace URI, or the empty
* @return The attribute's index, or -1 if none matches. * string if none is available.
* @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String) * @param localName The attribute's local name.
*/ * @return The attribute's index, or -1 if none matches.
public int getIndex (String uri, String localName) * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)
{ */
int max = length * 5; public int getIndex (String uri, String localName)
for (int i = 0; i < max; i += 5) { {
if (data[i].equals(uri) && data[i+1].equals(localName)) { int max = length * 5;
return i / 5; for (int i = 0; i < max; i += 5) {
} if (data[i].equals(uri) && data[i+1].equals(localName)) {
} return i / 5;
return -1; }
} }
return -1;
}
/**
* Look up an attribute's index by qualified (prefixed) name.
* /**
* @param qName The qualified name. * Look up an attribute's index by qualified (prefixed) name.
* @return The attribute's index, or -1 if none matches. *
* @see org.xml.sax.Attributes#getIndex(java.lang.String) * @param qName The qualified name.
*/ * @return The attribute's index, or -1 if none matches.
public int getIndex (String qName) * @see org.xml.sax.Attributes#getIndex(java.lang.String)
{ */
int max = length * 5; public int getIndex (String qName)
for (int i = 0; i < max; i += 5) { {
if (data[i+2].equals(qName)) { int max = length * 5;
return i / 5; for (int i = 0; i < max; i += 5) {
} if (data[i+2].equals(qName)) {
} return i / 5;
return -1; }
} }
return -1;
}
/**
* Look up an attribute's type by Namespace-qualified name.
* /**
* @param uri The Namespace URI, or the empty string for a name * Look up an attribute's type by Namespace-qualified name.
* with no explicit Namespace URI. *
* @param localName The local name. * @param uri The Namespace URI, or the empty string for a name
* @return The attribute's type, or null if there is no * with no explicit Namespace URI.
* matching attribute. * @param localName The local name.
* @see org.xml.sax.Attributes#getType(java.lang.String,java.lang.String) * @return The attribute's type, or null if there is no
*/ * matching attribute.
public String getType (String uri, String localName) * @see org.xml.sax.Attributes#getType(java.lang.String,java.lang.String)
{ */
int max = length * 5; public String getType (String uri, String localName)
for (int i = 0; i < max; i += 5) { {
if (data[i].equals(uri) && data[i+1].equals(localName)) { int max = length * 5;
return data[i+3]; for (int i = 0; i < max; i += 5) {
} if (data[i].equals(uri) && data[i+1].equals(localName)) {
} return data[i+3];
return null; }
} }
return null;
}
/**
* Look up an attribute's type by qualified (prefixed) name.
* /**
* @param qName The qualified name. * Look up an attribute's type by qualified (prefixed) name.
* @return The attribute's type, or null if there is no *
* matching attribute. * @param qName The qualified name.
* @see org.xml.sax.Attributes#getType(java.lang.String) * @return The attribute's type, or null if there is no
*/ * matching attribute.
public String getType (String qName) * @see org.xml.sax.Attributes#getType(java.lang.String)
{ */
int max = length * 5; public String getType (String qName)
for (int i = 0; i < max; i += 5) { {
if (data[i+2].equals(qName)) { int max = length * 5;
return data[i+3]; for (int i = 0; i < max; i += 5) {
} if (data[i+2].equals(qName)) {
} return data[i+3];
return null; }
} }
return null;
}
/**
* Look up an attribute's value by Namespace-qualified name.
* /**
* @param uri The Namespace URI, or the empty string for a name * Look up an attribute's value by Namespace-qualified name.
* with no explicit Namespace URI. *
* @param localName The local name. * @param uri The Namespace URI, or the empty string for a name
* @return The attribute's value, or null if there is no * with no explicit Namespace URI.
* matching attribute. * @param localName The local name.
* @see org.xml.sax.Attributes#getValue(java.lang.String,java.lang.String) * @return The attribute's value, or null if there is no
*/ * matching attribute.
public String getValue (String uri, String localName) * @see org.xml.sax.Attributes#getValue(java.lang.String,java.lang.String)
{ */
int max = length * 5; public String getValue (String uri, String localName)
for (int i = 0; i < max; i += 5) { {
if (data[i].equals(uri) && data[i+1].equals(localName)) { int max = length * 5;
return data[i+4]; for (int i = 0; i < max; i += 5) {
} if (data[i].equals(uri) && data[i+1].equals(localName)) {
} return data[i+4];
return null; }
} }
return null;
}
/**
* Look up an attribute's value by qualified (prefixed) name.
* /**
* @param qName The qualified name. * Look up an attribute's value by qualified (prefixed) name.
* @return The attribute's value, or null if there is no *
* matching attribute. * @param qName The qualified name.
* @see org.xml.sax.Attributes#getValue(java.lang.String) * @return The attribute's value, or null if there is no
*/ * matching attribute.
public String getValue (String qName) * @see org.xml.sax.Attributes#getValue(java.lang.String)
{ */
int max = length * 5; public String getValue (String qName)
for (int i = 0; i < max; i += 5) { {
if (data[i+2].equals(qName)) { int max = length * 5;
return data[i+4]; for (int i = 0; i < max; i += 5) {
} if (data[i+2].equals(qName)) {
} return data[i+4];
return null; }
} }
return null;
}
////////////////////////////////////////////////////////////////////
// Manipulators.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Manipulators.
////////////////////////////////////////////////////////////////////
/**
* Clear the attribute list for reuse.
* /**
* <p>Note that no memory is actually freed by this call: * Clear the attribute list for reuse.
* the current arrays are kept so that they can be *
* reused.</p> * <p>Note that little memory is freed by this call:
*/ * the current array is kept so it can be
public void clear () * reused.</p>
{ */
length = 0; public void clear ()
} {
if (data != null) {
for (int i = 0; i < (length * 5); i++)
/** data [i] = null;
* Copy an entire Attributes object. }
* length = 0;
* <p>It may be more efficient to reuse an existing object }
* rather than constantly allocating new ones.</p>
*
* @param atts The attributes to copy. /**
*/ * Copy an entire Attributes object.
public void setAttributes (Attributes atts) *
{ * <p>It may be more efficient to reuse an existing object
clear(); * rather than constantly allocating new ones.</p>
length = atts.getLength(); *
data = new String[length*5]; * @param atts The attributes to copy.
for (int i = 0; i < length; i++) { */
data[i*5] = atts.getURI(i); public void setAttributes (Attributes atts)
data[i*5+1] = atts.getLocalName(i); {
data[i*5+2] = atts.getQName(i); clear();
data[i*5+3] = atts.getType(i); length = atts.getLength();
data[i*5+4] = atts.getValue(i); if (length > 0) {
} data = new String[length*5];
} for (int i = 0; i < length; i++) {
data[i*5] = atts.getURI(i);
data[i*5+1] = atts.getLocalName(i);
/** data[i*5+2] = atts.getQName(i);
* Add an attribute to the end of the list. data[i*5+3] = atts.getType(i);
* data[i*5+4] = atts.getValue(i);
* <p>For the sake of speed, this method does no checking }
* to see if the attribute is already in the list: that is }
* the responsibility of the application.</p> }
*
* @param uri The Namespace URI, or the empty string if
* none is available or Namespace processing is not /**
* being performed. * Add an attribute to the end of the list.
* @param localName The local name, or the empty string if *
* Namespace processing is not being performed. * <p>For the sake of speed, this method does no checking
* @param qName The qualified (prefixed) name, or the empty string * to see if the attribute is already in the list: that is
* if qualified names are not available. * the responsibility of the application.</p>
* @param type The attribute type as a string. *
* @param value The attribute value. * @param uri The Namespace URI, or the empty string if
*/ * none is available or Namespace processing is not
public void addAttribute (String uri, String localName, String qName, * being performed.
String type, String value) * @param localName The local name, or the empty string if
{ * Namespace processing is not being performed.
ensureCapacity(length+1); * @param qName The qualified (prefixed) name, or the empty string
data[length*5] = uri; * if qualified names are not available.
data[length*5+1] = localName; * @param type The attribute type as a string.
data[length*5+2] = qName; * @param value The attribute value.
data[length*5+3] = type; */
data[length*5+4] = value; public void addAttribute (String uri, String localName, String qName,
length++; String type, String value)
} {
ensureCapacity(length+1);
data[length*5] = uri;
/** data[length*5+1] = localName;
* Set an attribute in the list. data[length*5+2] = qName;
* data[length*5+3] = type;
* <p>For the sake of speed, this method does no checking data[length*5+4] = value;
* for name conflicts or well-formedness: such checks are the length++;
* responsibility of the application.</p> }
*
* @param index The index of the attribute (zero-based).
* @param uri The Namespace URI, or the empty string if /**
* none is available or Namespace processing is not * Set an attribute in the list.
* being performed. *
* @param localName The local name, or the empty string if * <p>For the sake of speed, this method does no checking
* Namespace processing is not being performed. * for name conflicts or well-formedness: such checks are the
* @param qName The qualified name, or the empty string * responsibility of the application.</p>
* if qualified names are not available. *
* @param type The attribute type as a string. * @param index The index of the attribute (zero-based).
* @param value The attribute value. * @param uri The Namespace URI, or the empty string if
* @exception java.lang.ArrayIndexOutOfBoundsException When the * none is available or Namespace processing is not
* supplied index does not point to an attribute * being performed.
* in the list. * @param localName The local name, or the empty string if
*/ * Namespace processing is not being performed.
public void setAttribute (int index, String uri, String localName, * @param qName The qualified name, or the empty string
String qName, String type, String value) * if qualified names are not available.
{ * @param type The attribute type as a string.
if (index >= 0 && index < length) { * @param value The attribute value.
data[index*5] = uri; * @exception java.lang.ArrayIndexOutOfBoundsException When the
data[index*5+1] = localName; * supplied index does not point to an attribute
data[index*5+2] = qName; * in the list.
data[index*5+3] = type; */
data[index*5+4] = value; public void setAttribute (int index, String uri, String localName,
} else { String qName, String type, String value)
badIndex(index); {
} if (index >= 0 && index < length) {
} data[index*5] = uri;
data[index*5+1] = localName;
data[index*5+2] = qName;
/** data[index*5+3] = type;
* Remove an attribute from the list. data[index*5+4] = value;
* } else {
* @param index The index of the attribute (zero-based). badIndex(index);
* @exception java.lang.ArrayIndexOutOfBoundsException When the }
* supplied index does not point to an attribute }
* in the list.
*/
public void removeAttribute (int index) /**
{ * Remove an attribute from the list.
if (index >= 0 && index < length) { *
data[index*5] = null; * @param index The index of the attribute (zero-based).
data[index*5+1] = null; * @exception java.lang.ArrayIndexOutOfBoundsException When the
data[index*5+2] = null; * supplied index does not point to an attribute
data[index*5+3] = null; * in the list.
data[index*5+4] = null; */
if (index < length - 1) { public void removeAttribute (int index)
System.arraycopy(data, (index+1)*5, data, index*5, {
(length-index-1)*5); if (index >= 0 && index < length) {
} if (index < length - 1) {
length--; System.arraycopy(data, (index+1)*5, data, index*5,
} else { (length-index-1)*5);
badIndex(index); }
} index = (length - 1) * 5;
} data [index++] = null;
data [index++] = null;
data [index++] = null;
/** data [index++] = null;
* Set the Namespace URI of a specific attribute. data [index] = null;
* length--;
* @param index The index of the attribute (zero-based). } else {
* @param uri The attribute's Namespace URI, or the empty badIndex(index);
* string for none. }
* @exception java.lang.ArrayIndexOutOfBoundsException When the }
* supplied index does not point to an attribute
* in the list.
*/ /**
public void setURI (int index, String uri) * Set the Namespace URI of a specific attribute.
{ *
if (index >= 0 && index < length) { * @param index The index of the attribute (zero-based).
data[index*5] = uri; * @param uri The attribute's Namespace URI, or the empty
} else { * string for none.
badIndex(index); * @exception java.lang.ArrayIndexOutOfBoundsException When the
} * supplied index does not point to an attribute
} * in the list.
*/
public void setURI (int index, String uri)
/** {
* Set the local name of a specific attribute. if (index >= 0 && index < length) {
* data[index*5] = uri;
* @param index The index of the attribute (zero-based). } else {
* @param localName The attribute's local name, or the empty badIndex(index);
* string for none. }
* @exception java.lang.ArrayIndexOutOfBoundsException When the }
* supplied index does not point to an attribute
* in the list.
*/ /**
public void setLocalName (int index, String localName) * Set the local name of a specific attribute.
{ *
if (index >= 0 && index < length) { * @param index The index of the attribute (zero-based).
data[index*5+1] = localName; * @param localName The attribute's local name, or the empty
} else { * string for none.
badIndex(index); * @exception java.lang.ArrayIndexOutOfBoundsException When the
} * supplied index does not point to an attribute
} * in the list.
*/
public void setLocalName (int index, String localName)
/** {
* Set the qualified name of a specific attribute. if (index >= 0 && index < length) {
* data[index*5+1] = localName;
* @param index The index of the attribute (zero-based). } else {
* @param qName The attribute's qualified name, or the empty badIndex(index);
* string for none. }
* @exception java.lang.ArrayIndexOutOfBoundsException When the }
* supplied index does not point to an attribute
* in the list.
*/ /**
public void setQName (int index, String qName) * Set the qualified name of a specific attribute.
{ *
if (index >= 0 && index < length) { * @param index The index of the attribute (zero-based).
data[index*5+2] = qName; * @param qName The attribute's qualified name, or the empty
} else { * string for none.
badIndex(index); * @exception java.lang.ArrayIndexOutOfBoundsException When the
} * supplied index does not point to an attribute
} * in the list.
*/
public void setQName (int index, String qName)
/** {
* Set the type of a specific attribute. if (index >= 0 && index < length) {
* data[index*5+2] = qName;
* @param index The index of the attribute (zero-based). } else {
* @param type The attribute's type. badIndex(index);
* @exception java.lang.ArrayIndexOutOfBoundsException When the }
* supplied index does not point to an attribute }
* in the list.
*/
public void setType (int index, String type) /**
{ * Set the type of a specific attribute.
if (index >= 0 && index < length) { *
data[index*5+3] = type; * @param index The index of the attribute (zero-based).
} else { * @param type The attribute's type.
badIndex(index); * @exception java.lang.ArrayIndexOutOfBoundsException When the
} * supplied index does not point to an attribute
} * in the list.
*/
public void setType (int index, String type)
/** {
* Set the value of a specific attribute. if (index >= 0 && index < length) {
* data[index*5+3] = type;
* @param index The index of the attribute (zero-based). } else {
* @param value The attribute's value. badIndex(index);
* @exception java.lang.ArrayIndexOutOfBoundsException When the }
* supplied index does not point to an attribute }
* in the list.
*/
public void setValue (int index, String value) /**
{ * Set the value of a specific attribute.
if (index >= 0 && index < length) { *
data[index*5+4] = value; * @param index The index of the attribute (zero-based).
} else { * @param value The attribute's value.
badIndex(index); * @exception java.lang.ArrayIndexOutOfBoundsException When the
} * supplied index does not point to an attribute
} * in the list.
*/
public void setValue (int index, String value)
{
//////////////////////////////////////////////////////////////////// if (index >= 0 && index < length) {
// Internal methods. data[index*5+4] = value;
//////////////////////////////////////////////////////////////////// } else {
badIndex(index);
}
/** }
* Ensure the internal array's capacity.
*
* @param n The minimum number of attributes that the array must
* be able to hold. ////////////////////////////////////////////////////////////////////
*/ // Internal methods.
private void ensureCapacity (int n) ////////////////////////////////////////////////////////////////////
{
if (n > 0 && data == null) {
data = new String[25]; /**
} * Ensure the internal array's capacity.
*
int max = data.length; * @param n The minimum number of attributes that the array must
if (max >= n * 5) { * be able to hold.
return; */
} private void ensureCapacity (int n) {
if (n <= 0) {
return;
while (max < n * 5) { }
max *= 2; int max;
} if (data == null || data.length == 0) {
String newData[] = new String[max]; max = 25;
System.arraycopy(data, 0, newData, 0, length*5); }
data = newData; else if (data.length >= n * 5) {
} return;
}
else {
/** max = data.length;
* Report a bad array index in a manipulator. }
* while (max < n * 5) {
* @param index The index to report. max *= 2;
* @exception java.lang.ArrayIndexOutOfBoundsException Always. }
*/
private void badIndex (int index) String newData[] = new String[max];
throws ArrayIndexOutOfBoundsException if (length > 0) {
{ System.arraycopy(data, 0, newData, 0, length*5);
String msg = }
"Attempt to modify attribute at illegal index: " + index; data = newData;
throw new ArrayIndexOutOfBoundsException(msg); }
}
/**
* Report a bad array index in a manipulator.
//////////////////////////////////////////////////////////////////// *
// Internal state. * @param index The index to report.
//////////////////////////////////////////////////////////////////// * @exception java.lang.ArrayIndexOutOfBoundsException Always.
*/
int length; private void badIndex (int index)
String data []; throws ArrayIndexOutOfBoundsException
{
} String msg =
"Attempt to modify attribute at illegal index: " + index;
// end of AttributesImpl.java throw new ArrayIndexOutOfBoundsException(msg);
}
////////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////////
int length;
String data [];
}
// end of AttributesImpl.java
// DefaultHandler.java - default implementation of the core handlers. // DefaultHandler.java - default implementation of the core handlers.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the public domain. // Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: DefaultHandler.java,v 1.1 2000/10/02 02:43:20 sboag Exp $
// $Id: DefaultHandler.java,v 1.5.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import org.xml.sax.InputSource;
import org.xml.sax.Locator; import java.io.IOException;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver; import org.xml.sax.InputSource;
import org.xml.sax.DTDHandler; import org.xml.sax.Locator;
import org.xml.sax.ContentHandler; import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler; import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException; import org.xml.sax.DTDHandler;
import org.xml.sax.SAXParseException; import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
/** import org.xml.sax.SAXParseException;
* Default base class for SAX2 event handlers.
*
* <blockquote> /**
* <em>This module, both source code and documentation, is in the * Default base class for SAX2 event handlers.
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> *
* </blockquote> * <blockquote>
* * <em>This module, both source code and documentation, is in the
* <p>This class is available as a convenience base class for SAX2 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* applications: it provides default implementations for all of the * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* callbacks in the four core SAX2 handler classes:</p> * for further information.
* * </blockquote>
* <ul> *
* <li>{@link org.xml.sax.EntityResolver EntityResolver}</li> * <p>This class is available as a convenience base class for SAX2
* <li>{@link org.xml.sax.DTDHandler DTDHandler}</li> * applications: it provides default implementations for all of the
* <li>{@link org.xml.sax.ContentHandler ContentHandler}</li> * callbacks in the four core SAX2 handler classes:</p>
* <li>{@link org.xml.sax.ErrorHandler ErrorHandler}</li> *
* </ul> * <ul>
* * <li>{@link org.xml.sax.EntityResolver EntityResolver}</li>
* <p>Application writers can extend this class when they need to * <li>{@link org.xml.sax.DTDHandler DTDHandler}</li>
* implement only part of an interface; parser writers can * <li>{@link org.xml.sax.ContentHandler ContentHandler}</li>
* instantiate this class to provide default handlers when the * <li>{@link org.xml.sax.ErrorHandler ErrorHandler}</li>
* application has not supplied its own.</p> * </ul>
* *
* <p>This class replaces the deprecated SAX1 * <p>Application writers can extend this class when they need to
* {@link org.xml.sax.HandlerBase HandlerBase} class.</p> * implement only part of an interface; parser writers can
* * instantiate this class to provide default handlers when the
* @since SAX 2.0 * application has not supplied its own.</p>
* @author David Megginson, *
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * <p>This class replaces the deprecated SAX1
* @version 2.0 * {@link org.xml.sax.HandlerBase HandlerBase} class.</p>
* @see org.xml.sax.EntityResolver *
* @see org.xml.sax.DTDHandler * @since SAX 2.0
* @see org.xml.sax.ContentHandler * @author David Megginson,
* @see org.xml.sax.ErrorHandler * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.EntityResolver
public class DefaultHandler * @see org.xml.sax.DTDHandler
implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler * @see org.xml.sax.ContentHandler
{ * @see org.xml.sax.ErrorHandler
*/
public class DefaultHandler
//////////////////////////////////////////////////////////////////// implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler
// Default implementation of the EntityResolver interface. {
////////////////////////////////////////////////////////////////////
/** ////////////////////////////////////////////////////////////////////
* Resolve an external entity. // Default implementation of the EntityResolver interface.
* ////////////////////////////////////////////////////////////////////
* <p>Always return null, so that the parser will use the system
* identifier provided in the XML document. This method implements /**
* the SAX default behaviour: application writers can override it * Resolve an external entity.
* in a subclass to do special translations such as catalog lookups *
* or URI redirection.</p> * <p>Always return null, so that the parser will use the system
* * identifier provided in the XML document. This method implements
* @param publicId The public identifier, or null if none is * the SAX default behaviour: application writers can override it
* available. * in a subclass to do special translations such as catalog lookups
* @param systemId The system identifier provided in the XML * or URI redirection.</p>
* document. *
* @return The new input source, or null to require the * @param publicId The public identifer, or null if none is
* default behaviour. * available.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @param systemId The system identifier provided in the XML
* wrapping another exception. * document.
* @see org.xml.sax.EntityResolver#resolveEntity * @return The new input source, or null to require the
*/ * default behaviour.
public InputSource resolveEntity (String publicId, String systemId) * @exception java.io.IOException If there is an error setting
throws SAXException * up the new input source.
{ * @exception org.xml.sax.SAXException Any SAX exception, possibly
return null; * wrapping another exception.
} * @see org.xml.sax.EntityResolver#resolveEntity
*/
public InputSource resolveEntity (String publicId, String systemId)
throws IOException, SAXException
//////////////////////////////////////////////////////////////////// {
// Default implementation of DTDHandler interface. return null;
//////////////////////////////////////////////////////////////////// }
/**
* Receive notification of a notation declaration. ////////////////////////////////////////////////////////////////////
* // Default implementation of DTDHandler interface.
* <p>By default, do nothing. Application writers may override this ////////////////////////////////////////////////////////////////////
* method in a subclass if they wish to keep track of the notations
* declared in a document.</p>
* /**
* @param name The notation name. * Receive notification of a notation declaration.
* @param publicId The notation public identifier, or null if not *
* available. * <p>By default, do nothing. Application writers may override this
* @param systemId The notation system identifier. * method in a subclass if they wish to keep track of the notations
* @exception org.xml.sax.SAXException Any SAX exception, possibly * declared in a document.</p>
* wrapping another exception. *
* @see org.xml.sax.DTDHandler#notationDecl * @param name The notation name.
*/ * @param publicId The notation public identifier, or null if not
public void notationDecl (String name, String publicId, String systemId) * available.
throws SAXException * @param systemId The notation system identifier.
{ * @exception org.xml.sax.SAXException Any SAX exception, possibly
// no op * wrapping another exception.
} * @see org.xml.sax.DTDHandler#notationDecl
*/
public void notationDecl (String name, String publicId, String systemId)
/** throws SAXException
* Receive notification of an unparsed entity declaration. {
* // no op
* <p>By default, do nothing. Application writers may override this }
* method in a subclass to keep track of the unparsed entities
* declared in a document.</p>
* /**
* @param name The entity name. * Receive notification of an unparsed entity declaration.
* @param publicId The entity public identifier, or null if not *
* available. * <p>By default, do nothing. Application writers may override this
* @param systemId The entity system identifier. * method in a subclass to keep track of the unparsed entities
* @param notationName The name of the associated notation. * declared in a document.</p>
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * @param name The entity name.
* @see org.xml.sax.DTDHandler#unparsedEntityDecl * @param publicId The entity public identifier, or null if not
*/ * available.
public void unparsedEntityDecl (String name, String publicId, * @param systemId The entity system identifier.
String systemId, String notationName) * @param notationName The name of the associated notation.
throws SAXException * @exception org.xml.sax.SAXException Any SAX exception, possibly
{ * wrapping another exception.
// no op * @see org.xml.sax.DTDHandler#unparsedEntityDecl
} */
public void unparsedEntityDecl (String name, String publicId,
String systemId, String notationName)
throws SAXException
//////////////////////////////////////////////////////////////////// {
// Default implementation of ContentHandler interface. // no op
//////////////////////////////////////////////////////////////////// }
/**
* Receive a Locator object for document events. ////////////////////////////////////////////////////////////////////
* // Default implementation of ContentHandler interface.
* <p>By default, do nothing. Application writers may override this ////////////////////////////////////////////////////////////////////
* method in a subclass if they wish to store the locator for use
* with other document events.</p>
* /**
* @param locator A locator for all SAX document events. * Receive a Locator object for document events.
* @see org.xml.sax.ContentHandler#setDocumentLocator *
* @see org.xml.sax.Locator * <p>By default, do nothing. Application writers may override this
*/ * method in a subclass if they wish to store the locator for use
public void setDocumentLocator (Locator locator) * with other document events.</p>
{ *
// no op * @param locator A locator for all SAX document events.
} * @see org.xml.sax.ContentHandler#setDocumentLocator
* @see org.xml.sax.Locator
*/
/** public void setDocumentLocator (Locator locator)
* Receive notification of the beginning of the document. {
* // no op
* <p>By default, do nothing. Application writers may override this }
* method in a subclass to take specific actions at the beginning
* of a document (such as allocating the root node of a tree or
* creating an output file).</p> /**
* * Receive notification of the beginning of the document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * <p>By default, do nothing. Application writers may override this
* @see org.xml.sax.ContentHandler#startDocument * method in a subclass to take specific actions at the beginning
*/ * of a document (such as allocating the root node of a tree or
public void startDocument () * creating an output file).</p>
throws SAXException *
{ * @exception org.xml.sax.SAXException Any SAX exception, possibly
// no op * wrapping another exception.
} * @see org.xml.sax.ContentHandler#startDocument
*/
public void startDocument ()
/** throws SAXException
* Receive notification of the end of the document. {
* // no op
* <p>By default, do nothing. Application writers may override this }
* method in a subclass to take specific actions at the end
* of a document (such as finalising a tree or closing an output
* file).</p> /**
* * Receive notification of the end of the document.
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * <p>By default, do nothing. Application writers may override this
* @see org.xml.sax.ContentHandler#endDocument * method in a subclass to take specific actions at the end
*/ * of a document (such as finalising a tree or closing an output
public void endDocument () * file).</p>
throws SAXException *
{ * @exception org.xml.sax.SAXException Any SAX exception, possibly
// no op * wrapping another exception.
} * @see org.xml.sax.ContentHandler#endDocument
*/
public void endDocument ()
/** throws SAXException
* Receive notification of the start of a Namespace mapping. {
* // no op
* <p>By default, do nothing. Application writers may override this }
* method in a subclass to take specific actions at the start of
* each Namespace prefix scope (such as storing the prefix mapping).</p>
* /**
* @param prefix The Namespace prefix being declared. * Receive notification of the start of a Namespace mapping.
* @param uri The Namespace URI mapped to the prefix. *
* @exception org.xml.sax.SAXException Any SAX exception, possibly * <p>By default, do nothing. Application writers may override this
* wrapping another exception. * method in a subclass to take specific actions at the start of
* @see org.xml.sax.ContentHandler#startPrefixMapping * each Namespace prefix scope (such as storing the prefix mapping).</p>
*/ *
public void startPrefixMapping (String prefix, String uri) * @param prefix The Namespace prefix being declared.
throws SAXException * @param uri The Namespace URI mapped to the prefix.
{ * @exception org.xml.sax.SAXException Any SAX exception, possibly
// no op * wrapping another exception.
} * @see org.xml.sax.ContentHandler#startPrefixMapping
*/
public void startPrefixMapping (String prefix, String uri)
/** throws SAXException
* Receive notification of the end of a Namespace mapping. {
* // no op
* <p>By default, do nothing. Application writers may override this }
* method in a subclass to take specific actions at the end of
* each prefix mapping.</p>
* /**
* @param prefix The Namespace prefix being declared. * Receive notification of the end of a Namespace mapping.
* @exception org.xml.sax.SAXException Any SAX exception, possibly *
* wrapping another exception. * <p>By default, do nothing. Application writers may override this
* @see org.xml.sax.ContentHandler#endPrefixMapping * method in a subclass to take specific actions at the end of
*/ * each prefix mapping.</p>
public void endPrefixMapping (String prefix) *
throws SAXException * @param prefix The Namespace prefix being declared.
{ * @exception org.xml.sax.SAXException Any SAX exception, possibly
// no op * wrapping another exception.
} * @see org.xml.sax.ContentHandler#endPrefixMapping
*/
public void endPrefixMapping (String prefix)
/** throws SAXException
* Receive notification of the start of an element. {
* // no op
* <p>By default, do nothing. Application writers may override this }
* method in a subclass to take specific actions at the start of
* each element (such as allocating a new tree node or writing
* output to a file).</p> /**
* * Receive notification of the start of an element.
* @param name The element type name. *
* @param attributes The specified or defaulted attributes. * <p>By default, do nothing. Application writers may override this
* @exception org.xml.sax.SAXException Any SAX exception, possibly * method in a subclass to take specific actions at the start of
* wrapping another exception. * each element (such as allocating a new tree node or writing
* @see org.xml.sax.ContentHandler#startElement * output to a file).</p>
*/ *
public void startElement (String uri, String localName, * @param uri The Namespace URI, or the empty string if the
String qName, Attributes attributes) * element has no Namespace URI or if Namespace
throws SAXException * processing is not being performed.
{ * @param localName The local name (without prefix), or the
// no op * empty string if Namespace processing is not being
} * performed.
* @param qName The qualified name (with prefix), or the
* empty string if qualified names are not available.
/** * @param atts The attributes attached to the element. If
* Receive notification of the end of an element. * there are no attributes, it shall be an empty
* * Attributes object.
* <p>By default, do nothing. Application writers may override this * @exception org.xml.sax.SAXException Any SAX exception, possibly
* method in a subclass to take specific actions at the end of * wrapping another exception.
* each element (such as finalising a tree node or writing * @see org.xml.sax.ContentHandler#startElement
* output to a file).</p> */
* public void startElement (String uri, String localName,
* @param name The element type name. String qName, Attributes attributes)
* @param attributes The specified or defaulted attributes. throws SAXException
* @exception org.xml.sax.SAXException Any SAX exception, possibly {
* wrapping another exception. // no op
* @see org.xml.sax.ContentHandler#endElement }
*/
public void endElement (String uri, String localName, String qName)
throws SAXException /**
{ * Receive notification of the end of an element.
// no op *
} * <p>By default, do nothing. Application writers may override this
* method in a subclass to take specific actions at the end of
* each element (such as finalising a tree node or writing
/** * output to a file).</p>
* Receive notification of character data inside an element. *
* * @param uri The Namespace URI, or the empty string if the
* <p>By default, do nothing. Application writers may override this * element has no Namespace URI or if Namespace
* method to take specific actions for each chunk of character data * processing is not being performed.
* (such as adding the data to a node or buffer, or printing it to * @param localName The local name (without prefix), or the
* a file).</p> * empty string if Namespace processing is not being
* * performed.
* @param ch The characters. * @param qName The qualified name (with prefix), or the
* @param start The start position in the character array. * empty string if qualified names are not available.
* @param length The number of characters to use from the * @exception org.xml.sax.SAXException Any SAX exception, possibly
* character array. * wrapping another exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @see org.xml.sax.ContentHandler#endElement
* wrapping another exception. */
* @see org.xml.sax.ContentHandler#characters public void endElement (String uri, String localName, String qName)
*/ throws SAXException
public void characters (char ch[], int start, int length) {
throws SAXException // no op
{ }
// no op
}
/**
* Receive notification of character data inside an element.
/** *
* Receive notification of ignorable whitespace in element content. * <p>By default, do nothing. Application writers may override this
* * method to take specific actions for each chunk of character data
* <p>By default, do nothing. Application writers may override this * (such as adding the data to a node or buffer, or printing it to
* method to take specific actions for each chunk of ignorable * a file).</p>
* whitespace (such as adding data to a node or buffer, or printing *
* it to a file).</p> * @param ch The characters.
* * @param start The start position in the character array.
* @param ch The whitespace characters. * @param length The number of characters to use from the
* @param start The start position in the character array. * character array.
* @param length The number of characters to use from the * @exception org.xml.sax.SAXException Any SAX exception, possibly
* character array. * wrapping another exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @see org.xml.sax.ContentHandler#characters
* wrapping another exception. */
* @see org.xml.sax.ContentHandler#ignorableWhitespace public void characters (char ch[], int start, int length)
*/ throws SAXException
public void ignorableWhitespace (char ch[], int start, int length) {
throws SAXException // no op
{ }
// no op
}
/**
* Receive notification of ignorable whitespace in element content.
/** *
* Receive notification of a processing instruction. * <p>By default, do nothing. Application writers may override this
* * method to take specific actions for each chunk of ignorable
* <p>By default, do nothing. Application writers may override this * whitespace (such as adding data to a node or buffer, or printing
* method in a subclass to take specific actions for each * it to a file).</p>
* processing instruction, such as setting status variables or *
* invoking other methods.</p> * @param ch The whitespace characters.
* * @param start The start position in the character array.
* @param target The processing instruction target. * @param length The number of characters to use from the
* @param data The processing instruction data, or null if * character array.
* none is supplied. * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @exception org.xml.sax.SAXException Any SAX exception, possibly * wrapping another exception.
* wrapping another exception. * @see org.xml.sax.ContentHandler#ignorableWhitespace
* @see org.xml.sax.ContentHandler#processingInstruction */
*/ public void ignorableWhitespace (char ch[], int start, int length)
public void processingInstruction (String target, String data) throws SAXException
throws SAXException {
{ // no op
// no op }
}
/**
/** * Receive notification of a processing instruction.
* Receive notification of a skipped entity. *
* * <p>By default, do nothing. Application writers may override this
* <p>By default, do nothing. Application writers may override this * method in a subclass to take specific actions for each
* method in a subclass to take specific actions for each * processing instruction, such as setting status variables or
* processing instruction, such as setting status variables or * invoking other methods.</p>
* invoking other methods.</p> *
* * @param target The processing instruction target.
* @param name The name of the skipped entity. * @param data The processing instruction data, or null if
* @exception org.xml.sax.SAXException Any SAX exception, possibly * none is supplied.
* wrapping another exception. * @exception org.xml.sax.SAXException Any SAX exception, possibly
* @see org.xml.sax.ContentHandler#processingInstruction * wrapping another exception.
*/ * @see org.xml.sax.ContentHandler#processingInstruction
public void skippedEntity (String name) */
throws SAXException public void processingInstruction (String target, String data)
{ throws SAXException
// no op {
} // no op
}
//////////////////////////////////////////////////////////////////// /**
// Default implementation of the ErrorHandler interface. * Receive notification of a skipped entity.
//////////////////////////////////////////////////////////////////// *
* <p>By default, do nothing. Application writers may override this
* method in a subclass to take specific actions for each
/** * processing instruction, such as setting status variables or
* Receive notification of a parser warning. * invoking other methods.</p>
* *
* <p>The default implementation does nothing. Application writers * @param name The name of the skipped entity.
* may override this method in a subclass to take specific actions * @exception org.xml.sax.SAXException Any SAX exception, possibly
* for each warning, such as inserting the message in a log file or * wrapping another exception.
* printing it to the console.</p> * @see org.xml.sax.ContentHandler#processingInstruction
* */
* @param e The warning information encoded as an exception. public void skippedEntity (String name)
* @exception org.xml.sax.SAXException Any SAX exception, possibly throws SAXException
* wrapping another exception. {
* @see org.xml.sax.ErrorHandler#warning // no op
* @see org.xml.sax.SAXParseException }
*/
public void warning (SAXParseException e)
throws SAXException
{ ////////////////////////////////////////////////////////////////////
// no op // Default implementation of the ErrorHandler interface.
} ////////////////////////////////////////////////////////////////////
/** /**
* Receive notification of a recoverable parser error. * Receive notification of a parser warning.
* *
* <p>The default implementation does nothing. Application writers * <p>The default implementation does nothing. Application writers
* may override this method in a subclass to take specific actions * may override this method in a subclass to take specific actions
* for each error, such as inserting the message in a log file or * for each warning, such as inserting the message in a log file or
* printing it to the console.</p> * printing it to the console.</p>
* *
* @param e The warning information encoded as an exception. * @param e The warning information encoded as an exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception. * wrapping another exception.
* @see org.xml.sax.ErrorHandler#warning * @see org.xml.sax.ErrorHandler#warning
* @see org.xml.sax.SAXParseException * @see org.xml.sax.SAXParseException
*/ */
public void error (SAXParseException e) public void warning (SAXParseException e)
throws SAXException throws SAXException
{ {
// no op // no op
} }
/** /**
* Report a fatal XML parsing error. * Receive notification of a recoverable parser error.
* *
* <p>The default implementation throws a SAXParseException. * <p>The default implementation does nothing. Application writers
* Application writers may override this method in a subclass if * may override this method in a subclass to take specific actions
* they need to take specific actions for each fatal error (such as * for each error, such as inserting the message in a log file or
* collecting all of the errors into a single report): in any case, * printing it to the console.</p>
* the application must stop all regular processing when this *
* method is invoked, since the document is no longer reliable, and * @param e The warning information encoded as an exception.
* the parser may no longer report parsing events.</p> * @exception org.xml.sax.SAXException Any SAX exception, possibly
* * wrapping another exception.
* @param e The error information encoded as an exception. * @see org.xml.sax.ErrorHandler#warning
* @exception org.xml.sax.SAXException Any SAX exception, possibly * @see org.xml.sax.SAXParseException
* wrapping another exception. */
* @see org.xml.sax.ErrorHandler#fatalError public void error (SAXParseException e)
* @see org.xml.sax.SAXParseException throws SAXException
*/ {
public void fatalError (SAXParseException e) // no op
throws SAXException }
{
throw e;
} /**
* Report a fatal XML parsing error.
} *
* <p>The default implementation throws a SAXParseException.
// end of DefaultHandler.java * Application writers may override this method in a subclass if
* they need to take specific actions for each fatal error (such as
* collecting all of the errors into a single report): in any case,
* the application must stop all regular processing when this
* method is invoked, since the document is no longer reliable, and
* the parser may no longer report parsing events.</p>
*
* @param e The error information encoded as an exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see org.xml.sax.ErrorHandler#fatalError
* @see org.xml.sax.SAXParseException
*/
public void fatalError (SAXParseException e)
throws SAXException
{
throw e;
}
}
// end of DefaultHandler.java
// SAX default implementation for Locator. // SAX default implementation for Locator.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: LocatorImpl.java,v 1.1 2000/10/02 02:43:20 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: LocatorImpl.java,v 1.3.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import org.xml.sax.Locator;
import org.xml.sax.Locator;
/**
* Provide an optional convenience implementation of Locator. /**
* * Provide an optional convenience implementation of Locator.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class is available mainly for application writers, who * for further information.
* can use it to make a persistent snapshot of a locator at any * </blockquote>
* point during a document parse:</p> *
* * <p>This class is available mainly for application writers, who
* <pre> * can use it to make a persistent snapshot of a locator at any
* Locator locator; * point during a document parse:</p>
* Locator startloc; *
* * <pre>
* public void setLocator (Locator locator) * Locator locator;
* { * Locator startloc;
* // note the locator *
* this.locator = locator; * public void setLocator (Locator locator)
* } * {
* * // note the locator
* public void startDocument () * this.locator = locator;
* { * }
* // save the location of the start of the document *
* // for future use. * public void startDocument ()
* Locator startloc = new LocatorImpl(locator); * {
* } * // save the location of the start of the document
*</pre> * // for future use.
* * Locator startloc = new LocatorImpl(locator);
* <p>Normally, parser writers will not use this class, since it * }
* is more efficient to provide location information only when *</pre>
* requested, rather than constantly updating a Locator object.</p> *
* * <p>Normally, parser writers will not use this class, since it
* @since SAX 1.0 * is more efficient to provide location information only when
* @author David Megginson, * requested, rather than constantly updating a Locator object.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.Locator Locator * @author David Megginson
*/ * @version 2.0.1 (sax2r2)
public class LocatorImpl implements Locator * @see org.xml.sax.Locator Locator
{ */
public class LocatorImpl implements Locator
{
/**
* Zero-argument constructor.
* /**
* <p>This will not normally be useful, since the main purpose * Zero-argument constructor.
* of this class is to make a snapshot of an existing Locator.</p> *
*/ * <p>This will not normally be useful, since the main purpose
public LocatorImpl () * of this class is to make a snapshot of an existing Locator.</p>
{ */
} public LocatorImpl ()
{
}
/**
* Copy constructor.
* /**
* <p>Create a persistent copy of the current state of a locator. * Copy constructor.
* When the original locator changes, this copy will still keep *
* the original values (and it can be used outside the scope of * <p>Create a persistent copy of the current state of a locator.
* DocumentHandler methods).</p> * When the original locator changes, this copy will still keep
* * the original values (and it can be used outside the scope of
* @param locator The locator to copy. * DocumentHandler methods).</p>
*/ *
public LocatorImpl (Locator locator) * @param locator The locator to copy.
{ */
setPublicId(locator.getPublicId()); public LocatorImpl (Locator locator)
setSystemId(locator.getSystemId()); {
setLineNumber(locator.getLineNumber()); setPublicId(locator.getPublicId());
setColumnNumber(locator.getColumnNumber()); setSystemId(locator.getSystemId());
} setLineNumber(locator.getLineNumber());
setColumnNumber(locator.getColumnNumber());
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Locator
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Locator
////////////////////////////////////////////////////////////////////
/**
* Return the saved public identifier.
* /**
* @return The public identifier as a string, or null if none * Return the saved public identifier.
* is available. *
* @see org.xml.sax.Locator#getPublicId * @return The public identifier as a string, or null if none
* @see #setPublicId * is available.
*/ * @see org.xml.sax.Locator#getPublicId
public String getPublicId () * @see #setPublicId
{ */
return publicId; public String getPublicId ()
} {
return publicId;
}
/**
* Return the saved system identifier.
* /**
* @return The system identifier as a string, or null if none * Return the saved system identifier.
* is available. *
* @see org.xml.sax.Locator#getSystemId * @return The system identifier as a string, or null if none
* @see #setSystemId * is available.
*/ * @see org.xml.sax.Locator#getSystemId
public String getSystemId () * @see #setSystemId
{ */
return systemId; public String getSystemId ()
} {
return systemId;
}
/**
* Return the saved line number (1-based).
* /**
* @return The line number as an integer, or -1 if none is available. * Return the saved line number (1-based).
* @see org.xml.sax.Locator#getLineNumber *
* @see #setLineNumber * @return The line number as an integer, or -1 if none is available.
*/ * @see org.xml.sax.Locator#getLineNumber
public int getLineNumber () * @see #setLineNumber
{ */
return lineNumber; public int getLineNumber ()
} {
return lineNumber;
}
/**
* Return the saved column number (1-based).
* /**
* @return The column number as an integer, or -1 if none is available. * Return the saved column number (1-based).
* @see org.xml.sax.Locator#getColumnNumber *
* @see #setColumnNumber * @return The column number as an integer, or -1 if none is available.
*/ * @see org.xml.sax.Locator#getColumnNumber
public int getColumnNumber () * @see #setColumnNumber
{ */
return columnNumber; public int getColumnNumber ()
} {
return columnNumber;
}
////////////////////////////////////////////////////////////////////
// Setters for the properties (not in org.xml.sax.Locator)
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Setters for the properties (not in org.xml.sax.Locator)
////////////////////////////////////////////////////////////////////
/**
* Set the public identifier for this locator.
* /**
* @param publicId The new public identifier, or null * Set the public identifier for this locator.
* if none is available. *
* @see #getPublicId * @param publicId The new public identifier, or null
*/ * if none is available.
public void setPublicId (String publicId) * @see #getPublicId
{ */
this.publicId = publicId; public void setPublicId (String publicId)
} {
this.publicId = publicId;
}
/**
* Set the system identifier for this locator.
* /**
* @param systemId The new system identifier, or null * Set the system identifier for this locator.
* if none is available. *
* @see #getSystemId * @param systemId The new system identifier, or null
*/ * if none is available.
public void setSystemId (String systemId) * @see #getSystemId
{ */
this.systemId = systemId; public void setSystemId (String systemId)
} {
this.systemId = systemId;
}
/**
* Set the line number for this locator (1-based).
* /**
* @param lineNumber The line number, or -1 if none is available. * Set the line number for this locator (1-based).
* @see #getLineNumber *
*/ * @param lineNumber The line number, or -1 if none is available.
public void setLineNumber (int lineNumber) * @see #getLineNumber
{ */
this.lineNumber = lineNumber; public void setLineNumber (int lineNumber)
} {
this.lineNumber = lineNumber;
}
/**
* Set the column number for this locator (1-based).
* /**
* @param columnNumber The column number, or -1 if none is available. * Set the column number for this locator (1-based).
* @see #getColumnNumber *
*/ * @param columnNumber The column number, or -1 if none is available.
public void setColumnNumber (int columnNumber) * @see #getColumnNumber
{ */
this.columnNumber = columnNumber; public void setColumnNumber (int columnNumber)
} {
this.columnNumber = columnNumber;
}
////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Internal state.
private String publicId; ////////////////////////////////////////////////////////////////////
private String systemId;
private int lineNumber; private String publicId;
private int columnNumber; private String systemId;
private int lineNumber;
} private int columnNumber;
// end of LocatorImpl.java }
// end of LocatorImpl.java
// NamespaceSupport.java - generic Namespace support for SAX. // NamespaceSupport.java - generic Namespace support for SAX.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// This class is in the Public Domain. NO WARRANTY! // Written by David Megginson
// This class is in the Public Domain. NO WARRANTY!
// $Id: NamespaceSupport.java,v 1.1 2000/10/02 02:43:20 sboag Exp $
// $Id: NamespaceSupport.java,v 1.6.2.5 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import java.util.EmptyStackException;
import java.util.Enumeration; import java.util.EmptyStackException;
import java.util.Hashtable; import java.util.Enumeration;
import java.util.Vector; import java.util.Hashtable;
import java.util.Vector;
/**
* Encapsulate Namespace logic for use by SAX drivers. /**
* * Encapsulate Namespace logic for use by applications using SAX,
* <blockquote> * or internally by SAX drivers.
* <em>This module, both source code and documentation, is in the *
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <blockquote>
* </blockquote> * <em>This module, both source code and documentation, is in the
* * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* <p>This class encapsulates the logic of Namespace processing: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* it tracks the declarations currently in force for each context * for further information.
* and automatically processes qualified XML 1.0 names into their * </blockquote>
* Namespace parts; it can also be used in reverse for generating *
* XML 1.0 from Namespaces.</p> * <p>This class encapsulates the logic of Namespace processing:
* * it tracks the declarations currently in force for each context
* <p>Namespace support objects are reusable, but the reset method * and automatically processes qualified XML 1.0 names into their
* must be invoked between each session.</p> * Namespace parts; it can also be used in reverse for generating
* * XML 1.0 from Namespaces.</p>
* <p>Here is a simple session:</p> *
* * <p>Namespace support objects are reusable, but the reset method
* <pre> * must be invoked between each session.</p>
* String parts[] = new String[3]; *
* NamespaceSupport support = new NamespaceSupport(); * <p>Here is a simple session:</p>
* *
* support.pushContext(); * <pre>
* support.declarePrefix("", "http://www.w3.org/1999/xhtml"); * String parts[] = new String[3];
* support.declarePrefix("dc", "http://www.purl.org/dc#"); * NamespaceSupport support = new NamespaceSupport();
* *
* String parts[] = support.processName("p", parts, false); * support.pushContext();
* System.out.println("Namespace URI: " + parts[0]); * support.declarePrefix("", "http://www.w3.org/1999/xhtml");
* System.out.println("Local name: " + parts[1]); * support.declarePrefix("dc", "http://www.purl.org/dc#");
* System.out.println("Raw name: " + parts[2]); *
* parts = support.processName("p", parts, false);
* String parts[] = support.processName("dc:title", parts, false); * System.out.println("Namespace URI: " + parts[0]);
* System.out.println("Namespace URI: " + parts[0]); * System.out.println("Local name: " + parts[1]);
* System.out.println("Local name: " + parts[1]); * System.out.println("Raw name: " + parts[2]);
* System.out.println("Raw name: " + parts[2]); *
* parts = support.processName("dc:title", parts, false);
* support.popContext(); * System.out.println("Namespace URI: " + parts[0]);
* </pre> * System.out.println("Local name: " + parts[1]);
* * System.out.println("Raw name: " + parts[2]);
* <p>Note that this class is optimized for the use case where most *
* elements do not contain Namespace declarations: if the same * support.popContext();
* prefix/URI mapping is repeated for each context (for example), this * </pre>
* class will be somewhat less efficient.</p> *
* * <p>Note that this class is optimized for the use case where most
* @since SAX 2.0 * elements do not contain Namespace declarations: if the same
* @author David Megginson, * prefix/URI mapping is repeated for each context (for example), this
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * class will be somewhat less efficient.</p>
* @version 2.0 *
*/ * <p>Although SAX drivers (parsers) may choose to use this class to
public class NamespaceSupport * implement namespace handling, they are not required to do so.
{ * Applications must track namespace information themselves if they
* want to use namespace information.
*
//////////////////////////////////////////////////////////////////// * @since SAX 2.0
// Constants. * @author David Megginson
//////////////////////////////////////////////////////////////////// * @version 2.0.1 (sax2r2)
*/
public class NamespaceSupport
/** {
* The XML Namespace as a constant.
*
* <p>This is the Namespace URI that is automatically mapped ////////////////////////////////////////////////////////////////////
* to the "xml" prefix.</p> // Constants.
*/ ////////////////////////////////////////////////////////////////////
public final static String XMLNS =
"http://www.w3.org/XML/1998/namespace";
/**
* The XML Namespace URI as a constant.
/** * The value is <code>http://www.w3.org/XML/1998/namespace</code>
* An empty enumeration. * as defined in the XML Namespaces specification.
*/ *
private final static Enumeration EMPTY_ENUMERATION = * <p>This is the Namespace URI that is automatically mapped
new Vector().elements(); * to the "xml" prefix.</p>
*/
public final static String XMLNS =
//////////////////////////////////////////////////////////////////// "http://www.w3.org/XML/1998/namespace";
// Constructor.
////////////////////////////////////////////////////////////////////
/**
* An empty enumeration.
/** */
* Create a new Namespace support object. private final static Enumeration EMPTY_ENUMERATION =
*/ new Vector().elements();
public NamespaceSupport ()
{
reset(); ////////////////////////////////////////////////////////////////////
} // Constructor.
////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////// /**
// Context management. * Create a new Namespace support object.
//////////////////////////////////////////////////////////////////// */
public NamespaceSupport ()
{
/** reset();
* Reset this Namespace support object for reuse. }
*
* <p>It is necessary to invoke this method before reusing the
* Namespace support object for a new session.</p>
*/ ////////////////////////////////////////////////////////////////////
public void reset () // Context management.
{ ////////////////////////////////////////////////////////////////////
contexts = new Context[32];
contextPos = 0;
contexts[contextPos] = currentContext = new Context(); /**
currentContext.declarePrefix("xml", XMLNS); * Reset this Namespace support object for reuse.
} *
* <p>It is necessary to invoke this method before reusing the
* Namespace support object for a new session.</p>
/** */
* Start a new Namespace context. public void reset ()
* {
* <p>Normally, you should push a new context at the beginning contexts = new Context[32];
* of each XML element: the new context will automatically inherit contextPos = 0;
* the declarations of its parent context, but it will also keep contexts[contextPos] = currentContext = new Context();
* track of which declarations were made within this context.</p> currentContext.declarePrefix("xml", XMLNS);
* }
* <p>The Namespace support object always starts with a base context
* already in force: in this context, only the "xml" prefix is
* declared.</p> /**
* * Start a new Namespace context.
* @see #popContext * The new context will automatically inherit
*/ * the declarations of its parent context, but it will also keep
public void pushContext () * track of which declarations were made within this context.
{ *
int max = contexts.length; * <p>Event callback code should start a new context once per element.
contextPos++; * This means being ready to call this in either of two places.
* For elements that don't include namespace declarations, the
// Extend the array if necessary * <em>ContentHandler.startElement()</em> callback is the right place.
if (contextPos >= max) { * For elements with such a declaration, it'd done in the first
Context newContexts[] = new Context[max*2]; * <em>ContentHandler.startPrefixMapping()</em> callback.
System.arraycopy(contexts, 0, newContexts, 0, max); * A boolean flag can be used to
max *= 2; * track whether a context has been started yet. When either of
contexts = newContexts; * those methods is called, it checks the flag to see if a new context
} * needs to be started. If so, it starts the context and sets the
* flag. After <em>ContentHandler.startElement()</em>
// Allocate the context if necessary. * does that, it always clears the flag.
currentContext = contexts[contextPos]; *
if (currentContext == null) { * <p>Normally, SAX drivers would push a new context at the beginning
contexts[contextPos] = currentContext = new Context(); * of each XML element. Then they perform a first pass over the
} * attributes to process all namespace declarations, making
* <em>ContentHandler.startPrefixMapping()</em> callbacks.
// Set the parent, if any. * Then a second pass is made, to determine the namespace-qualified
if (contextPos > 0) { * names for all attributes and for the element name.
currentContext.setParent(contexts[contextPos - 1]); * Finally all the information for the
} * <em>ContentHandler.startElement()</em> callback is available,
} * so it can then be made.
*
* <p>The Namespace support object always starts with a base context
/** * already in force: in this context, only the "xml" prefix is
* Revert to the previous Namespace context. * declared.</p>
* *
* <p>Normally, you should pop the context at the end of each * @see org.xml.sax.ContentHandler
* XML element. After popping the context, all Namespace prefix * @see #popContext
* mappings that were previously in force are restored.</p> */
* public void pushContext ()
* <p>You must not attempt to declare additional Namespace {
* prefixes after popping a context, unless you push another int max = contexts.length;
* context first.</p>
* contexts [contextPos].declsOK = false;
* @see #pushContext contextPos++;
*/
public void popContext () // Extend the array if necessary
{ if (contextPos >= max) {
contextPos--; Context newContexts[] = new Context[max*2];
if (contextPos < 0) { System.arraycopy(contexts, 0, newContexts, 0, max);
throw new EmptyStackException(); max *= 2;
} contexts = newContexts;
currentContext = contexts[contextPos]; }
}
// Allocate the context if necessary.
currentContext = contexts[contextPos];
if (currentContext == null) {
//////////////////////////////////////////////////////////////////// contexts[contextPos] = currentContext = new Context();
// Operations within a context. }
////////////////////////////////////////////////////////////////////
// Set the parent, if any.
if (contextPos > 0) {
/** currentContext.setParent(contexts[contextPos - 1]);
* Declare a Namespace prefix. }
* }
* <p>This method declares a prefix in the current Namespace
* context; the prefix will remain in force until this context
* is popped, unless it is shadowed in a descendant context.</p> /**
* * Revert to the previous Namespace context.
* <p>To declare a default Namespace, use the empty string. The *
* prefix must not be "xml" or "xmlns".</p> * <p>Normally, you should pop the context at the end of each
* * XML element. After popping the context, all Namespace prefix
* <p>Note that you must <em>not</em> declare a prefix after * mappings that were previously in force are restored.</p>
* you've pushed and popped another Namespace.</p> *
* * <p>You must not attempt to declare additional Namespace
* <p>Note that there is an asymmetry in this library: while {@link * prefixes after popping a context, unless you push another
* #getPrefix getPrefix} will not return the default "" prefix, * context first.</p>
* even if you have declared one; to check for a default prefix, *
* you have to look it up explicitly using {@link #getURI getURI}. * @see #pushContext
* This asymmetry exists to make it easier to look up prefixes */
* for attribute names, where the default prefix is not allowed.</p> public void popContext ()
* {
* @param prefix The prefix to declare, or null for the empty contexts[contextPos].clear();
* string. contextPos--;
* @param uri The Namespace URI to associate with the prefix. if (contextPos < 0) {
* @return true if the prefix was legal, false otherwise throw new EmptyStackException();
* @see #processName }
* @see #getURI currentContext = contexts[contextPos];
* @see #getPrefix }
*/
public boolean declarePrefix (String prefix, String uri)
{
if (prefix.equals("xml") || prefix.equals("xmlns")) { ////////////////////////////////////////////////////////////////////
return false; // Operations within a context.
} else { ////////////////////////////////////////////////////////////////////
currentContext.declarePrefix(prefix, uri);
return true;
} /**
} * Declare a Namespace prefix. All prefixes must be declared
* before they are referenced. For example, a SAX driver (parser)
* would scan an element's attributes
/** * in two passes: first for namespace declarations,
* Process a raw XML 1.0 name. * then a second pass using {@link #processName processName()} to
* * interpret prefixes against (potentially redefined) prefixes.
* <p>This method processes a raw XML 1.0 name in the current *
* context by removing the prefix and looking it up among the * <p>This method declares a prefix in the current Namespace
* prefixes currently declared. The return value will be the * context; the prefix will remain in force until this context
* array supplied by the caller, filled in as follows:</p> * is popped, unless it is shadowed in a descendant context.</p>
* *
* <dl> * <p>To declare the default element Namespace, use the empty string as
* <dt>parts[0]</dt> * the prefix.</p>
* <dd>The Namespace URI, or an empty string if none is *
* in use.</dd> * <p>Note that you must <em>not</em> declare a prefix after
* <dt>parts[1]</dt> * you've pushed and popped another Namespace context, or
* <dd>The local name (without prefix).</dd> * treated the declarations phase as complete by processing
* <dt>parts[2]</dt> * a prefixed name.</p>
* <dd>The original raw name.</dd> *
* </dl> * <p>Note that there is an asymmetry in this library: {@link
* * #getPrefix getPrefix} will not return the "" prefix,
* <p>All of the strings in the array will be internalized. If * even if you have declared a default element namespace.
* the raw name has a prefix that has not been declared, then * To check for a default namespace,
* the return value will be null.</p> * you have to look it up explicitly using {@link #getURI getURI}.
* * This asymmetry exists to make it easier to look up prefixes
* <p>Note that attribute names are processed differently than * for attribute names, where the default prefix is not allowed.</p>
* element names: an unprefixed element name will received the *
* default Namespace (if any), while an unprefixed element name * @param prefix The prefix to declare, or the empty string to
* will not.</p> * indicate the default element namespace. This may never have
* * the value "xml" or "xmlns".
* @param qName The raw XML 1.0 name to be processed. * @param uri The Namespace URI to associate with the prefix.
* @param parts An array supplied by the caller, capable of * @return true if the prefix was legal, false otherwise
* holding at least three members. * @exception IllegalStateException when a prefix is declared
* @param isAttribute A flag indicating whether this is an * after looking up a name in the context, or after pushing
* attribute name (true) or an element name (false). * another context on top of it.
* @return The supplied array holding three internalized strings *
* representing the Namespace URI (or empty string), the * @see #processName
* local name, and the raw XML 1.0 name; or null if there * @see #getURI
* is an undeclared prefix. * @see #getPrefix
* @see #declarePrefix */
* @see java.lang.String#intern */ public boolean declarePrefix (String prefix, String uri)
public String [] processName (String qName, String parts[], {
boolean isAttribute) if (prefix.equals("xml") || prefix.equals("xmlns")) {
{ return false;
String myParts[] = currentContext.processName(qName, isAttribute); } else {
if (myParts == null) { currentContext.declarePrefix(prefix, uri);
return null; return true;
} else { }
parts[0] = myParts[0]; }
parts[1] = myParts[1];
parts[2] = myParts[2];
return parts; /**
} * Process a raw XML 1.0 name, after all declarations in the current
} * context have been handled by {@link #declarePrefix declarePrefix()}.
*
* <p>This method processes a raw XML 1.0 name in the current
/** * context by removing the prefix and looking it up among the
* Look up a prefix and get the currently-mapped Namespace URI. * prefixes currently declared. The return value will be the
* * array supplied by the caller, filled in as follows:</p>
* <p>This method looks up the prefix in the current context. *
* Use the empty string ("") for the default Namespace.</p> * <dl>
* * <dt>parts[0]</dt>
* @param prefix The prefix to look up. * <dd>The Namespace URI, or an empty string if none is
* @return The associated Namespace URI, or null if the prefix * in use.</dd>
* is undeclared in this context. * <dt>parts[1]</dt>
* @see #getPrefix * <dd>The local name (without prefix).</dd>
* @see #getPrefixes * <dt>parts[2]</dt>
*/ * <dd>The original raw name.</dd>
public String getURI (String prefix) * </dl>
{ *
return currentContext.getURI(prefix); * <p>All of the strings in the array will be internalized. If
} * the raw name has a prefix that has not been declared, then
* the return value will be null.</p>
*
/** * <p>Note that attribute names are processed differently than
* Return an enumeration of all prefixes currently declared. * element names: an unprefixed element name will received the
* * default Namespace (if any), while an unprefixed attribute name
* <p><strong>Note:</strong> if there is a default prefix, it will not be * will not.</p>
* returned in this enumeration; check for the default prefix *
* using the {@link #getURI getURI} with an argument of "".</p> * @param qName The raw XML 1.0 name to be processed.
* * @param parts An array supplied by the caller, capable of
* @return An enumeration of all prefixes declared in the * holding at least three members.
* current context except for the empty (default) * @param isAttribute A flag indicating whether this is an
* prefix. * attribute name (true) or an element name (false).
* @see #getDeclaredPrefixes * @return The supplied array holding three internalized strings
* @see #getURI * representing the Namespace URI (or empty string), the
*/ * local name, and the raw XML 1.0 name; or null if there
public Enumeration getPrefixes () * is an undeclared prefix.
{ * @see #declarePrefix
return currentContext.getPrefixes(); * @see java.lang.String#intern */
} public String [] processName (String qName, String parts[],
boolean isAttribute)
{
/** String myParts[] = currentContext.processName(qName, isAttribute);
* Return one of the prefixes mapped to a Namespace URI. if (myParts == null) {
* return null;
* <p>If more than one prefix is currently mapped to the same } else {
* URI, this method will make an arbitrary selection; if you parts[0] = myParts[0];
* want all of the prefixes, use the {@link #getPrefixes} parts[1] = myParts[1];
* method instead.</p> parts[2] = myParts[2];
* return parts;
* <p><strong>Note:</strong> this will never return the empty (default) prefix; }
* to check for a default prefix, use the {@link #getURI getURI} }
* method with an argument of "".</p>
*
* @param uri The Namespace URI. /**
* @param isAttribute true if this prefix is for an attribute * Look up a prefix and get the currently-mapped Namespace URI.
* (and the default Namespace is not allowed). *
* @return One of the prefixes currently mapped to the URI supplied, * <p>This method looks up the prefix in the current context.
* or null if none is mapped or if the URI is assigned to * Use the empty string ("") for the default Namespace.</p>
* the default Namespace. *
* @see #getPrefixes(java.lang.String) * @param prefix The prefix to look up.
* @see #getURI * @return The associated Namespace URI, or null if the prefix
*/ * is undeclared in this context.
public String getPrefix (String uri) * @see #getPrefix
{ * @see #getPrefixes
return currentContext.getPrefix(uri); */
} public String getURI (String prefix)
{
return currentContext.getURI(prefix);
/** }
* Return an enumeration of all prefixes currently declared for a URI.
*
* <p>This method returns prefixes mapped to a specific Namespace /**
* URI. The xml: prefix will be included. If you want only one * Return an enumeration of all prefixes currently declared.
* prefix that's mapped to the Namespace URI, and you don't care *
* which one you get, use the {@link #getPrefix getPrefix} * <p><strong>Note:</strong> if there is a default prefix, it will not be
* method instead.</p> * returned in this enumeration; check for the default prefix
* * using the {@link #getURI getURI} with an argument of "".</p>
* <p><strong>Note:</strong> the empty (default) prefix is <em>never</em> included *
* in this enumeration; to check for the presence of a default * @return An enumeration of all prefixes declared in the
* Namespace, use the {@link #getURI getURI} method with an * current context except for the empty (default)
* argument of "".</p> * prefix.
* * @see #getDeclaredPrefixes
* @param uri The Namespace URI. * @see #getURI
* @return An enumeration of all prefixes declared in the */
* current context. public Enumeration getPrefixes ()
* @see #getPrefix {
* @see #getDeclaredPrefixes return currentContext.getPrefixes();
* @see #getURI }
*/
public Enumeration getPrefixes (String uri)
{ /**
Vector prefixes = new Vector(); * Return one of the prefixes mapped to a Namespace URI.
Enumeration allPrefixes = getPrefixes(); *
while (allPrefixes.hasMoreElements()) { * <p>If more than one prefix is currently mapped to the same
String prefix = (String)allPrefixes.nextElement(); * URI, this method will make an arbitrary selection; if you
if (uri.equals(getURI(prefix))) { * want all of the prefixes, use the {@link #getPrefixes}
prefixes.addElement(prefix); * method instead.</p>
} *
} * <p><strong>Note:</strong> this will never return the empty (default) prefix;
return prefixes.elements(); * to check for a default prefix, use the {@link #getURI getURI}
} * method with an argument of "".</p>
*
* @param uri The Namespace URI.
/** * @param isAttribute true if this prefix is for an attribute
* Return an enumeration of all prefixes declared in this context. * (and the default Namespace is not allowed).
* * @return One of the prefixes currently mapped to the URI supplied,
* <p>The empty (default) prefix will be included in this * or null if none is mapped or if the URI is assigned to
* enumeration; note that this behaviour differs from that of * the default Namespace.
* {@link #getPrefix} and {@link #getPrefixes}.</p> * @see #getPrefixes(java.lang.String)
* * @see #getURI
* @return An enumeration of all prefixes declared in this */
* context. public String getPrefix (String uri)
* @see #getPrefixes {
* @see #getURI return currentContext.getPrefix(uri);
*/ }
public Enumeration getDeclaredPrefixes ()
{
return currentContext.getDeclaredPrefixes(); /**
} * Return an enumeration of all prefixes currently declared for a URI.
*
* <p>This method returns prefixes mapped to a specific Namespace
* URI. The xml: prefix will be included. If you want only one
//////////////////////////////////////////////////////////////////// * prefix that's mapped to the Namespace URI, and you don't care
// Internal state. * which one you get, use the {@link #getPrefix getPrefix}
//////////////////////////////////////////////////////////////////// * method instead.</p>
*
private Context contexts[]; * <p><strong>Note:</strong> the empty (default) prefix is <em>never</em> included
private Context currentContext; * in this enumeration; to check for the presence of a default
private int contextPos; * Namespace, use the {@link #getURI getURI} method with an
* argument of "".</p>
*
* @param uri The Namespace URI.
//////////////////////////////////////////////////////////////////// * @return An enumeration of all prefixes declared in the
// Internal classes. * current context.
//////////////////////////////////////////////////////////////////// * @see #getPrefix
* @see #getDeclaredPrefixes
/** * @see #getURI
* Internal class for a single Namespace context. */
* public Enumeration getPrefixes (String uri)
* <p>This module caches and reuses Namespace contexts, so the number allocated {
* will be equal to the element depth of the document, not to the total Vector prefixes = new Vector();
* number of elements (i.e. 5-10 rather than tens of thousands).</p> Enumeration allPrefixes = getPrefixes();
*/ while (allPrefixes.hasMoreElements()) {
final class Context { String prefix = (String)allPrefixes.nextElement();
if (uri.equals(getURI(prefix))) {
/** prefixes.addElement(prefix);
* Create the root-level Namespace context. }
*/ }
Context () return prefixes.elements();
{ }
copyTables();
}
/**
* Return an enumeration of all prefixes declared in this context.
/** *
* (Re)set the parent of this Namespace context. * <p>The empty (default) prefix will be included in this
* * enumeration; note that this behaviour differs from that of
* @param context The parent Namespace context object. * {@link #getPrefix} and {@link #getPrefixes}.</p>
*/ *
void setParent (Context parent) * @return An enumeration of all prefixes declared in this
{ * context.
this.parent = parent; * @see #getPrefixes
declarations = null; * @see #getURI
prefixTable = parent.prefixTable; */
uriTable = parent.uriTable; public Enumeration getDeclaredPrefixes ()
elementNameTable = parent.elementNameTable; {
attributeNameTable = parent.attributeNameTable; return currentContext.getDeclaredPrefixes();
defaultNS = parent.defaultNS; }
tablesDirty = false;
}
////////////////////////////////////////////////////////////////////
/** // Internal state.
* Declare a Namespace prefix for this context. ////////////////////////////////////////////////////////////////////
*
* @param prefix The prefix to declare. private Context contexts[];
* @param uri The associated Namespace URI. private Context currentContext;
* @see org.xml.sax.helpers.NamespaceSupport#declarePrefix private int contextPos;
*/
void declarePrefix (String prefix, String uri)
{
// Lazy processing... ////////////////////////////////////////////////////////////////////
if (!tablesDirty) { // Internal classes.
copyTables(); ////////////////////////////////////////////////////////////////////
}
if (declarations == null) { /**
declarations = new Vector(); * Internal class for a single Namespace context.
} *
* <p>This module caches and reuses Namespace contexts,
prefix = prefix.intern(); * so the number allocated
uri = uri.intern(); * will be equal to the element depth of the document, not to the total
if ("".equals(prefix)) { * number of elements (i.e. 5-10 rather than tens of thousands).
if ("".equals(uri)) { * Also, data structures used to represent contexts are shared when
defaultNS = null; * possible (child contexts without declarations) to further reduce
} else { * the amount of memory that's consumed.
defaultNS = uri; * </p>
} */
} else { final class Context {
prefixTable.put(prefix, uri);
uriTable.put(uri, prefix); // may wipe out another prefix /**
} * Create the root-level Namespace context.
declarations.addElement(prefix); */
} Context ()
{
copyTables();
/** }
* Process a raw XML 1.0 name in this context.
*
* @param qName The raw XML 1.0 name. /**
* @param isAttribute true if this is an attribute name. * (Re)set the parent of this Namespace context.
* @return An array of three strings containing the * The context must either have been freshly constructed,
* URI part (or empty string), the local part, * or must have been cleared.
* and the raw name, all internalized, or null *
* if there is an undeclared prefix. * @param context The parent Namespace context object.
* @see org.xml.sax.helpers.NamespaceSupport#processName */
*/ void setParent (Context parent)
String [] processName (String qName, boolean isAttribute) {
{ this.parent = parent;
String name[]; declarations = null;
Hashtable table; prefixTable = parent.prefixTable;
uriTable = parent.uriTable;
// Select the appropriate table. elementNameTable = parent.elementNameTable;
if (isAttribute) { attributeNameTable = parent.attributeNameTable;
table = elementNameTable; defaultNS = parent.defaultNS;
} else { declSeen = false;
table = attributeNameTable; declsOK = true;
} }
// Start by looking in the cache, and /**
// return immediately if the name * Makes associated state become collectible,
// is already known in this content * invalidating this context.
name = (String[])table.get(qName); * {@link #setParent} must be called before
if (name != null) { * this context may be used again.
return name; */
} void clear ()
{
// We haven't seen this name in this parent = null;
// context before. prefixTable = null;
name = new String[3]; uriTable = null;
int index = qName.indexOf(':'); elementNameTable = null;
attributeNameTable = null;
defaultNS = null;
// No prefix. }
if (index == -1) {
if (isAttribute || defaultNS == null) {
name[0] = ""; /**
} else { * Declare a Namespace prefix for this context.
name[0] = defaultNS; *
} * @param prefix The prefix to declare.
name[1] = qName.intern(); * @param uri The associated Namespace URI.
name[2] = name[1]; * @see org.xml.sax.helpers.NamespaceSupport#declarePrefix
} */
void declarePrefix (String prefix, String uri)
// Prefix {
else { // Lazy processing...
String prefix = qName.substring(0, index); if (!declsOK)
String local = qName.substring(index+1); throw new IllegalStateException (
String uri; "can't declare any more prefixes in this context");
if ("".equals(prefix)) { if (!declSeen) {
uri = defaultNS; copyTables();
} else { }
uri = (String)prefixTable.get(prefix); if (declarations == null) {
} declarations = new Vector();
if (uri == null) { }
return null;
} prefix = prefix.intern();
name[0] = uri; uri = uri.intern();
name[1] = local.intern(); if ("".equals(prefix)) {
name[2] = qName.intern(); if ("".equals(uri)) {
} defaultNS = null;
} else {
// Save in the cache for future use. defaultNS = uri;
table.put(name[2], name); }
tablesDirty = true; } else {
return name; prefixTable.put(prefix, uri);
} uriTable.put(uri, prefix); // may wipe out another prefix
}
declarations.addElement(prefix);
/** }
* Look up the URI associated with a prefix in this context.
*
* @param prefix The prefix to look up. /**
* @return The associated Namespace URI, or null if none is * Process a raw XML 1.0 name in this context.
* declared. *
* @see org.xml.sax.helpers.NamespaceSupport#getURI * @param qName The raw XML 1.0 name.
*/ * @param isAttribute true if this is an attribute name.
String getURI (String prefix) * @return An array of three strings containing the
{ * URI part (or empty string), the local part,
if ("".equals(prefix)) { * and the raw name, all internalized, or null
return defaultNS; * if there is an undeclared prefix.
} else if (prefixTable == null) { * @see org.xml.sax.helpers.NamespaceSupport#processName
return null; */
} else { String [] processName (String qName, boolean isAttribute)
return (String)prefixTable.get(prefix); {
} String name[];
} Hashtable table;
// detect errors in call sequence
/** declsOK = false;
* Look up one of the prefixes associated with a URI in this context.
* // Select the appropriate table.
* <p>Since many prefixes may be mapped to the same URI, if (isAttribute) {
* the return value may be unreliable.</p> table = attributeNameTable;
* } else {
* @param uri The URI to look up. table = elementNameTable;
* @return The associated prefix, or null if none is declared. }
* @see org.xml.sax.helpers.NamespaceSupport#getPrefix
*/ // Start by looking in the cache, and
String getPrefix (String uri) // return immediately if the name
{ // is already known in this content
if (uriTable == null) { name = (String[])table.get(qName);
return null; if (name != null) {
} else { return name;
return (String)uriTable.get(uri); }
}
} // We haven't seen this name in this
// context before. Maybe in the parent
// context, but we can't assume prefix
/** // bindings are the same.
* Return an enumeration of prefixes declared in this context. name = new String[3];
* name[2] = qName.intern();
* @return An enumeration of prefixes (possibly empty). int index = qName.indexOf(':');
* @see org.xml.sax.helpers.NamespaceSupport#getDeclaredPrefixes
*/
Enumeration getDeclaredPrefixes () // No prefix.
{ if (index == -1) {
if (declarations == null) { if (isAttribute || defaultNS == null) {
return EMPTY_ENUMERATION; name[0] = "";
} else { } else {
return declarations.elements(); name[0] = defaultNS;
} }
} name[1] = name[2];
}
/** // Prefix
* Return an enumeration of all prefixes currently in force. else {
* String prefix = qName.substring(0, index);
* <p>The default prefix, if in force, is <em>not</em> String local = qName.substring(index+1);
* returned, and will have to be checked for separately.</p> String uri;
* if ("".equals(prefix)) {
* @return An enumeration of prefixes (never empty). uri = defaultNS;
* @see org.xml.sax.helpers.NamespaceSupport#getPrefixes } else {
*/ uri = (String)prefixTable.get(prefix);
Enumeration getPrefixes () }
{ if (uri == null) {
if (prefixTable == null) { return null;
return EMPTY_ENUMERATION; }
} else { name[0] = uri;
return prefixTable.keys(); name[1] = local.intern();
} }
}
// Save in the cache for future use.
// (Could be shared with parent context...)
table.put(name[2], name);
//////////////////////////////////////////////////////////////// return name;
// Internal methods. }
////////////////////////////////////////////////////////////////
/**
/** * Look up the URI associated with a prefix in this context.
* Copy on write for the internal tables in this context. *
* * @param prefix The prefix to look up.
* <p>This class is optimized for the normal case where most * @return The associated Namespace URI, or null if none is
* elements do not contain Namespace declarations.</p> * declared.
*/ * @see org.xml.sax.helpers.NamespaceSupport#getURI
private void copyTables () */
{ String getURI (String prefix)
if (prefixTable != null) { {
prefixTable = (Hashtable)prefixTable.clone(); if ("".equals(prefix)) {
} else { return defaultNS;
prefixTable = new Hashtable(); } else if (prefixTable == null) {
} return null;
if (uriTable != null) { } else {
uriTable = (Hashtable)uriTable.clone(); return (String)prefixTable.get(prefix);
} else { }
uriTable = new Hashtable(); }
}
elementNameTable = new Hashtable();
attributeNameTable = new Hashtable(); /**
tablesDirty = true; * Look up one of the prefixes associated with a URI in this context.
} *
* <p>Since many prefixes may be mapped to the same URI,
* the return value may be unreliable.</p>
*
//////////////////////////////////////////////////////////////// * @param uri The URI to look up.
// Protected state. * @return The associated prefix, or null if none is declared.
//////////////////////////////////////////////////////////////// * @see org.xml.sax.helpers.NamespaceSupport#getPrefix
*/
Hashtable prefixTable; String getPrefix (String uri)
Hashtable uriTable; {
Hashtable elementNameTable; if (uriTable == null) {
Hashtable attributeNameTable; return null;
String defaultNS = null; } else {
return (String)uriTable.get(uri);
}
}
////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////// /**
* Return an enumeration of prefixes declared in this context.
private Vector declarations = null; *
private boolean tablesDirty = false; * @return An enumeration of prefixes (possibly empty).
private Context parent = null; * @see org.xml.sax.helpers.NamespaceSupport#getDeclaredPrefixes
} */
} Enumeration getDeclaredPrefixes ()
{
// end of NamespaceSupport.java if (declarations == null) {
return EMPTY_ENUMERATION;
} else {
return declarations.elements();
}
}
/**
* Return an enumeration of all prefixes currently in force.
*
* <p>The default prefix, if in force, is <em>not</em>
* returned, and will have to be checked for separately.</p>
*
* @return An enumeration of prefixes (never empty).
* @see org.xml.sax.helpers.NamespaceSupport#getPrefixes
*/
Enumeration getPrefixes ()
{
if (prefixTable == null) {
return EMPTY_ENUMERATION;
} else {
return prefixTable.keys();
}
}
////////////////////////////////////////////////////////////////
// Internal methods.
////////////////////////////////////////////////////////////////
/**
* Copy on write for the internal tables in this context.
*
* <p>This class is optimized for the normal case where most
* elements do not contain Namespace declarations.</p>
*/
private void copyTables ()
{
if (prefixTable != null) {
prefixTable = (Hashtable)prefixTable.clone();
} else {
prefixTable = new Hashtable();
}
if (uriTable != null) {
uriTable = (Hashtable)uriTable.clone();
} else {
uriTable = new Hashtable();
}
elementNameTable = new Hashtable();
attributeNameTable = new Hashtable();
declSeen = true;
}
////////////////////////////////////////////////////////////////
// Protected state.
////////////////////////////////////////////////////////////////
Hashtable prefixTable;
Hashtable uriTable;
Hashtable elementNameTable;
Hashtable attributeNameTable;
String defaultNS = null;
boolean declsOK = true;
////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////
private Vector declarations = null;
private boolean declSeen = false;
private Context parent = null;
}
}
// end of NamespaceSupport.java
// NewInstance.java - create a new instance of a class by name.
// http://www.saxproject.org
// Written by Edwin Goei, edwingo@apache.org
// and by David Brownell, dbrownell@users.sourceforge.net
// NO WARRANTY! This class is in the Public Domain.
// $Id: NewInstance.java,v 1.1.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* Create a new instance of a class by name.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* for further information.
* </blockquote>
*
* <p>This class contains a static method for creating an instance of a
* class from an explicit class name. It tries to use the thread's context
* ClassLoader if possible and falls back to using
* Class.forName(String).</p>
*
* <p>This code is designed to compile and run on JDK version 1.1 and later
* including versions of Java 2.</p>
*
* @author Edwin Goei, David Brownell
* @version 2.0.1 (sax2r2)
*/
class NewInstance {
/**
* Creates a new instance of the specified class name
*
* Package private so this code is not exposed at the API level.
*/
static Object newInstance (ClassLoader classLoader, String className)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException
{
Class driverClass;
if (classLoader == null) {
driverClass = Class.forName(className);
} else {
driverClass = classLoader.loadClass(className);
}
return driverClass.newInstance();
}
/**
* Figure out which ClassLoader to use. For JDK 1.2 and later use
* the context ClassLoader.
*/
static ClassLoader getClassLoader ()
{
Method m = null;
try {
m = Thread.class.getMethod("getContextClassLoader", null);
} catch (NoSuchMethodException e) {
// Assume that we are running JDK 1.1, use the current ClassLoader
return NewInstance.class.getClassLoader();
}
try {
return (ClassLoader) m.invoke(Thread.currentThread(), null);
} catch (IllegalAccessException e) {
// assert(false)
throw new UnknownError(e.getMessage());
} catch (InvocationTargetException e) {
// assert(e.getTargetException() instanceof SecurityException)
throw new UnknownError(e.getMessage());
}
}
}
// ParserAdapter.java - adapt a SAX1 Parser to a SAX2 XMLReader. // ParserAdapter.java - adapt a SAX1 Parser to a SAX2 XMLReader.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the public domain. // Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: ParserAdapter.java,v 1.1 2000/10/02 02:43:20 sboag Exp $
// $Id: ParserAdapter.java,v 1.8.2.4 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import java.io.IOException;
import java.util.Enumeration; import java.io.IOException;
import java.util.Enumeration;
import org.xml.sax.Parser; // deprecated import java.util.Vector;
import org.xml.sax.InputSource;
import org.xml.sax.Locator; import org.xml.sax.Parser; // deprecated
import org.xml.sax.AttributeList; // deprecated import org.xml.sax.InputSource;
import org.xml.sax.EntityResolver; import org.xml.sax.Locator;
import org.xml.sax.DTDHandler; import org.xml.sax.AttributeList; // deprecated
import org.xml.sax.DocumentHandler; // deprecated import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler; import org.xml.sax.DTDHandler;
import org.xml.sax.SAXException; import org.xml.sax.DocumentHandler; // deprecated
import org.xml.sax.SAXParseException; import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.SAXParseException;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler; import org.xml.sax.XMLReader;
import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.Attributes;
import org.xml.sax.SAXNotSupportedException; import org.xml.sax.ContentHandler;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
/**
* Adapt a SAX1 Parser as a SAX2 XMLReader.
* /**
* <blockquote> * Adapt a SAX1 Parser as a SAX2 XMLReader.
* <em>This module, both source code and documentation, is in the *
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <blockquote>
* </blockquote> * <em>This module, both source code and documentation, is in the
* * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* <p>This class wraps a SAX1 {@link org.xml.sax.Parser Parser} * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* and makes it act as a SAX2 {@link org.xml.sax.XMLReader XMLReader}, * for further information.
* with feature, property, and Namespace support. Note * </blockquote>
* that it is not possible to report {@link org.xml.sax.ContentHandler#skippedEntity *
* skippedEntity} events, since SAX1 does not make that information available.</p> * <p>This class wraps a SAX1 {@link org.xml.sax.Parser Parser}
* * and makes it act as a SAX2 {@link org.xml.sax.XMLReader XMLReader},
* <p>This adapter does not test for duplicate Namespace-qualified * with feature, property, and Namespace support. Note
* attribute names.</p> * that it is not possible to report {@link org.xml.sax.ContentHandler#skippedEntity
* * skippedEntity} events, since SAX1 does not make that information available.</p>
* @since SAX 2.0 *
* @author David Megginson, * <p>This adapter does not test for duplicate Namespace-qualified
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * attribute names.</p>
* @version 2.0 *
* @see org.xml.sax.helpers.XMLReaderAdapter * @since SAX 2.0
* @see org.xml.sax.XMLReader * @author David Megginson
* @see org.xml.sax.Parser * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.helpers.XMLReaderAdapter
public class ParserAdapter implements XMLReader, DocumentHandler * @see org.xml.sax.XMLReader
{ * @see org.xml.sax.Parser
*/
public class ParserAdapter implements XMLReader, DocumentHandler
//////////////////////////////////////////////////////////////////// {
// Constructors.
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Constructors.
/** ////////////////////////////////////////////////////////////////////
* Construct a new parser adapter.
*
* <p>Use the "org.xml.sax.parser" property to locate the /**
* embedded SAX1 driver.</p> * Construct a new parser adapter.
* *
* @exception org.xml.sax.SAXException If the embedded driver * <p>Use the "org.xml.sax.parser" property to locate the
* cannot be instantiated or if the * embedded SAX1 driver.</p>
* org.xml.sax.parser property is not specified. *
*/ * @exception SAXException If the embedded driver
public ParserAdapter () * cannot be instantiated or if the
throws SAXException * org.xml.sax.parser property is not specified.
{ */
super(); public ParserAdapter ()
throws SAXException
String driver = System.getProperty("org.xml.sax.parser"); {
super();
try {
setup(ParserFactory.makeParser()); String driver = System.getProperty("org.xml.sax.parser");
} catch (ClassNotFoundException e1) {
throw new try {
SAXException("Cannot find SAX1 driver class " + setup(ParserFactory.makeParser());
driver, e1); } catch (ClassNotFoundException e1) {
} catch (IllegalAccessException e2) { throw new
throw new SAXException("Cannot find SAX1 driver class " +
SAXException("SAX1 driver class " + driver, e1);
driver + } catch (IllegalAccessException e2) {
" found but cannot be loaded", e2); throw new
} catch (InstantiationException e3) { SAXException("SAX1 driver class " +
throw new driver +
SAXException("SAX1 driver class " + " found but cannot be loaded", e2);
driver + } catch (InstantiationException e3) {
" loaded but cannot be instantiated", e3); throw new
} catch (ClassCastException e4) { SAXException("SAX1 driver class " +
throw new driver +
SAXException("SAX1 driver class " + " loaded but cannot be instantiated", e3);
driver + } catch (ClassCastException e4) {
" does not implement org.xml.sax.Parser"); throw new
} catch (NullPointerException e5) { SAXException("SAX1 driver class " +
throw new driver +
SAXException("System property org.xml.sax.parser not specified"); " does not implement org.xml.sax.Parser");
} } catch (NullPointerException e5) {
} throw new
SAXException("System property org.xml.sax.parser not specified");
}
/** }
* Construct a new parser adapter.
*
* <p>Note that the embedded parser cannot be changed once the /**
* adapter is created; to embed a different parser, allocate * Construct a new parser adapter.
* a new ParserAdapter.</p> *
* * <p>Note that the embedded parser cannot be changed once the
* @param parser The SAX1 parser to embed. * adapter is created; to embed a different parser, allocate
* @exception java.lang.NullPointerException If the parser parameter * a new ParserAdapter.</p>
* is null. *
*/ * @param parser The SAX1 parser to embed.
public ParserAdapter (Parser parser) * @exception java.lang.NullPointerException If the parser parameter
{ * is null.
super(); */
setup(parser); public ParserAdapter (Parser parser)
} {
super();
setup(parser);
/** }
* Internal setup method.
*
* @param parser The embedded parser. /**
* @exception java.lang.NullPointerException If the parser parameter * Internal setup method.
* is null. *
*/ * @param parser The embedded parser.
private void setup (Parser parser) * @exception java.lang.NullPointerException If the parser parameter
{ * is null.
if (parser == null) { */
throw new private void setup (Parser parser)
NullPointerException("Parser argument must not be null"); {
} if (parser == null) {
this.parser = parser; throw new
atts = new AttributesImpl(); NullPointerException("Parser argument must not be null");
nsSupport = new NamespaceSupport(); }
attAdapter = new AttributeListAdapter(); this.parser = parser;
} atts = new AttributesImpl();
nsSupport = new NamespaceSupport();
attAdapter = new AttributeListAdapter();
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.XMLReader.
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.XMLReader.
// ////////////////////////////////////////////////////////////////////
// Internal constants for the sake of convenience.
//
private final static String FEATURES = "http://xml.org/sax/features/"; //
private final static String NAMESPACES = FEATURES + "namespaces"; // Internal constants for the sake of convenience.
private final static String NAMESPACE_PREFIXES = FEATURES + "namespace-prefixes"; //
private final static String VALIDATION = FEATURES + "validation"; private final static String FEATURES = "http://xml.org/sax/features/";
private final static String EXTERNAL_GENERAL = private final static String NAMESPACES = FEATURES + "namespaces";
FEATURES + "external-general-entities"; private final static String NAMESPACE_PREFIXES = FEATURES + "namespace-prefixes";
private final static String EXTERNAL_PARAMETER =
FEATURES + "external-parameter-entities";
/**
* Set a feature flag for the parser.
/** *
* Set a feature for the parser. * <p>The only features recognized are namespaces and
* * namespace-prefixes.</p>
* <p>The only features supported are namespaces and *
* namespace-prefixes.</p> * @param name The feature name, as a complete URI.
* * @param value The requested feature value.
* @param name The feature name, as a complete URI. * @exception SAXNotRecognizedException If the feature
* @param state The requested feature state. * can't be assigned or retrieved.
* @exception org.xml.sax.SAXNotRecognizedException If the feature * @exception SAXNotSupportedException If the feature
* name is not known. * can't be assigned that value.
* @exception org.xml.sax.SAXNotSupportedException If the feature * @see org.xml.sax.XMLReader#setFeature
* state is not supported. */
* @see org.xml.sax.XMLReader#setFeature public void setFeature (String name, boolean value)
*/ throws SAXNotRecognizedException, SAXNotSupportedException
public void setFeature (String name, boolean state) {
throws SAXNotRecognizedException, SAXNotSupportedException if (name.equals(NAMESPACES)) {
{ checkNotParsing("feature", name);
if (name.equals(NAMESPACES)) { namespaces = value;
checkNotParsing("feature", name); if (!namespaces && !prefixes) {
namespaces = state; prefixes = true;
if (!namespaces && !prefixes) { }
prefixes = true; } else if (name.equals(NAMESPACE_PREFIXES)) {
} checkNotParsing("feature", name);
} else if (name.equals(NAMESPACE_PREFIXES)) { prefixes = value;
checkNotParsing("feature", name); if (!prefixes && !namespaces) {
prefixes = state; namespaces = true;
if (!prefixes && !namespaces) { }
namespaces = true; } else {
} throw new SAXNotRecognizedException("Feature: " + name);
} else if (name.equals(VALIDATION) || }
name.equals(EXTERNAL_GENERAL) || }
name.equals(EXTERNAL_PARAMETER)) {
throw new SAXNotSupportedException("Feature: " + name);
} else { /**
throw new SAXNotRecognizedException("Feature: " + name); * Check a parser feature flag.
} *
} * <p>The only features recognized are namespaces and
* namespace-prefixes.</p>
*
/** * @param name The feature name, as a complete URI.
* Check a parser feature. * @return The current feature value.
* * @exception SAXNotRecognizedException If the feature
* <p>The only features supported are namespaces and * value can't be assigned or retrieved.
* namespace-prefixes.</p> * @exception SAXNotSupportedException If the
* * feature is not currently readable.
* @param name The feature name, as a complete URI. * @see org.xml.sax.XMLReader#setFeature
* @return The current feature state. */
* @exception org.xml.sax.SAXNotRecognizedException If the feature public boolean getFeature (String name)
* name is not known. throws SAXNotRecognizedException, SAXNotSupportedException
* @exception org.xml.sax.SAXNotSupportedException If querying the {
* feature state is not supported. if (name.equals(NAMESPACES)) {
* @see org.xml.sax.XMLReader#setFeature return namespaces;
*/ } else if (name.equals(NAMESPACE_PREFIXES)) {
public boolean getFeature (String name) return prefixes;
throws SAXNotRecognizedException, SAXNotSupportedException } else {
{ throw new SAXNotRecognizedException("Feature: " + name);
if (name.equals(NAMESPACES)) { }
return namespaces; }
} else if (name.equals(NAMESPACE_PREFIXES)) {
return prefixes;
} else if (name.equals(VALIDATION) || /**
name.equals(EXTERNAL_GENERAL) || * Set a parser property.
name.equals(EXTERNAL_PARAMETER)) { *
throw new SAXNotSupportedException("Feature: " + name); * <p>No properties are currently recognized.</p>
} else { *
throw new SAXNotRecognizedException("Feature: " + name); * @param name The property name.
} * @param value The property value.
} * @exception SAXNotRecognizedException If the property
* value can't be assigned or retrieved.
* @exception SAXNotSupportedException If the property
/** * can't be assigned that value.
* Set a parser property. * @see org.xml.sax.XMLReader#setProperty
* */
* <p>No special properties are currently supported.</p> public void setProperty (String name, Object value)
* throws SAXNotRecognizedException, SAXNotSupportedException
* @param name The property name. {
* @param value The property value. throw new SAXNotRecognizedException("Property: " + name);
* @exception org.xml.sax.SAXNotRecognizedException If the feature }
* name is not known.
* @exception org.xml.sax.SAXNotSupportedException If the feature
* state is not supported. /**
* @see org.xml.sax.XMLReader#setProperty * Get a parser property.
*/ *
public void setProperty (String name, Object value) * <p>No properties are currently recognized.</p>
throws SAXNotRecognizedException, SAXNotSupportedException *
{ * @param name The property name.
throw new SAXNotRecognizedException("Property: " + name); * @return The property value.
} * @exception SAXNotRecognizedException If the property
* value can't be assigned or retrieved.
* @exception SAXNotSupportedException If the property
/** * value is not currently readable.
* Get a parser property. * @see org.xml.sax.XMLReader#getProperty
* */
* <p>No special properties are currently supported.</p> public Object getProperty (String name)
* throws SAXNotRecognizedException, SAXNotSupportedException
* @param name The property name. {
* @return The property value. throw new SAXNotRecognizedException("Property: " + name);
* @exception org.xml.sax.SAXNotRecognizedException If the feature }
* name is not known.
* @exception org.xml.sax.SAXNotSupportedException If the feature
* state is not supported. /**
* @see org.xml.sax.XMLReader#getProperty * Set the entity resolver.
*/ *
public Object getProperty (String name) * @param resolver The new entity resolver.
throws SAXNotRecognizedException, SAXNotSupportedException * @see org.xml.sax.XMLReader#setEntityResolver
{ */
throw new SAXNotRecognizedException("Property: " + name); public void setEntityResolver (EntityResolver resolver)
} {
entityResolver = resolver;
}
/**
* Set the entity resolver.
* /**
* @param resolver The new entity resolver. * Return the current entity resolver.
* @exception java.lang.NullPointerException If the entity resolver *
* parameter is null. * @return The current entity resolver, or null if none was supplied.
* @see org.xml.sax.XMLReader#setEntityResolver * @see org.xml.sax.XMLReader#getEntityResolver
*/ */
public void setEntityResolver (EntityResolver resolver) public EntityResolver getEntityResolver ()
{ {
if (resolver == null) { return entityResolver;
throw new NullPointerException("Null entity resolver"); }
}
entityResolver = resolver;
} /**
* Set the DTD handler.
*
/** * @param resolver The new DTD handler.
* Return the current entity resolver. * @see org.xml.sax.XMLReader#setEntityResolver
* */
* @return The current entity resolver, or null if none was supplied. public void setDTDHandler (DTDHandler handler)
* @see org.xml.sax.XMLReader#getEntityResolver {
*/ dtdHandler = handler;
public EntityResolver getEntityResolver () }
{
return entityResolver;
} /**
* Return the current DTD handler.
*
/** * @return The current DTD handler, or null if none was supplied.
* Set the DTD handler. * @see org.xml.sax.XMLReader#getEntityResolver
* */
* @param resolver The new DTD handler. public DTDHandler getDTDHandler ()
* @exception java.lang.NullPointerException If the DTD handler {
* parameter is null. return dtdHandler;
* @see org.xml.sax.XMLReader#setEntityResolver }
*/
public void setDTDHandler (DTDHandler handler)
{ /**
if (handler == null) { * Set the content handler.
throw new NullPointerException("Null DTD handler"); *
} * @param resolver The new content handler.
dtdHandler = handler; * @see org.xml.sax.XMLReader#setEntityResolver
} */
public void setContentHandler (ContentHandler handler)
{
/** contentHandler = handler;
* Return the current DTD handler. }
*
* @return The current DTD handler, or null if none was supplied.
* @see org.xml.sax.XMLReader#getEntityResolver /**
*/ * Return the current content handler.
public DTDHandler getDTDHandler () *
{ * @return The current content handler, or null if none was supplied.
return dtdHandler; * @see org.xml.sax.XMLReader#getEntityResolver
} */
public ContentHandler getContentHandler ()
{
/** return contentHandler;
* Set the content handler. }
*
* @param resolver The new content handler.
* @exception java.lang.NullPointerException If the content handler /**
* parameter is null. * Set the error handler.
* @see org.xml.sax.XMLReader#setEntityResolver *
*/ * @param resolver The new error handler.
public void setContentHandler (ContentHandler handler) * @see org.xml.sax.XMLReader#setEntityResolver
{ */
if (handler == null) { public void setErrorHandler (ErrorHandler handler)
throw new NullPointerException("Null content handler"); {
} errorHandler = handler;
contentHandler = handler; }
}
/**
/** * Return the current error handler.
* Return the current content handler. *
* * @return The current error handler, or null if none was supplied.
* @return The current content handler, or null if none was supplied. * @see org.xml.sax.XMLReader#getEntityResolver
* @see org.xml.sax.XMLReader#getEntityResolver */
*/ public ErrorHandler getErrorHandler ()
public ContentHandler getContentHandler () {
{ return errorHandler;
return contentHandler; }
}
/**
/** * Parse an XML document.
* Set the error handler. *
* * @param systemId The absolute URL of the document.
* @param resolver The new error handler. * @exception java.io.IOException If there is a problem reading
* @exception java.lang.NullPointerException If the error handler * the raw content of the document.
* parameter is null. * @exception SAXException If there is a problem
* @see org.xml.sax.XMLReader#setEntityResolver * processing the document.
*/ * @see #parse(org.xml.sax.InputSource)
public void setErrorHandler (ErrorHandler handler) * @see org.xml.sax.Parser#parse(java.lang.String)
{ */
if (handler == null) { public void parse (String systemId)
throw new NullPointerException("Null error handler"); throws IOException, SAXException
} {
errorHandler = handler; parse(new InputSource(systemId));
} }
/** /**
* Return the current error handler. * Parse an XML document.
* *
* @return The current error handler, or null if none was supplied. * @param input An input source for the document.
* @see org.xml.sax.XMLReader#getEntityResolver * @exception java.io.IOException If there is a problem reading
*/ * the raw content of the document.
public ErrorHandler getErrorHandler () * @exception SAXException If there is a problem
{ * processing the document.
return errorHandler; * @see #parse(java.lang.String)
} * @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)
*/
public void parse (InputSource input)
/** throws IOException, SAXException
* Parse an XML document. {
* if (parsing) {
* @param systemId The absolute URL of the document. throw new SAXException("Parser is already in use");
* @exception java.io.IOException If there is a problem reading }
* the raw content of the document. setupParser();
* @exception org.xml.sax.SAXException If there is a problem parsing = true;
* processing the document. try {
* @see #parse(org.xml.sax.InputSource) parser.parse(input);
* @see org.xml.sax.Parser#parse(java.lang.String) } finally {
*/ parsing = false;
public void parse (String systemId) }
throws IOException, SAXException parsing = false;
{ }
parse(new InputSource(systemId));
}
////////////////////////////////////////////////////////////////////
/** // Implementation of org.xml.sax.DocumentHandler.
* Parse an XML document. ////////////////////////////////////////////////////////////////////
*
* @param input An input source for the document.
* @exception java.io.IOException If there is a problem reading /**
* the raw content of the document. * Adapter implementation method; do not call.
* @exception org.xml.sax.SAXException If there is a problem * Adapt a SAX1 document locator event.
* processing the document. *
* @see #parse(java.lang.String) * @param locator A document locator.
* @see org.xml.sax.Parser#parse(org.xml.sax.InputSource) * @see org.xml.sax.ContentHandler#setDocumentLocator
*/ */
public void parse (InputSource input) public void setDocumentLocator (Locator locator)
throws IOException, SAXException {
{ this.locator = locator;
if (parsing) { if (contentHandler != null) {
throw new SAXException("Parser is already in use"); contentHandler.setDocumentLocator(locator);
} }
setupParser(); }
parsing = true;
try {
parser.parse(input); /**
} finally { * Adapter implementation method; do not call.
parsing = false; * Adapt a SAX1 start document event.
} *
parsing = false; * @exception SAXException The client may raise a
} * processing exception.
* @see org.xml.sax.DocumentHandler#startDocument
*/
public void startDocument ()
//////////////////////////////////////////////////////////////////// throws SAXException
// Implementation of org.xml.sax.DocumentHandler. {
//////////////////////////////////////////////////////////////////// if (contentHandler != null) {
contentHandler.startDocument();
}
/** }
* Adapt a SAX1 document locator event.
*
* @param locator A document locator. /**
* @see org.xml.sax.ContentHandler#setDocumentLocator * Adapter implementation method; do not call.
*/ * Adapt a SAX1 end document event.
public void setDocumentLocator (Locator locator) *
{ * @exception SAXException The client may raise a
this.locator = locator; * processing exception.
if (contentHandler != null) { * @see org.xml.sax.DocumentHandler#endDocument
contentHandler.setDocumentLocator(locator); */
} public void endDocument ()
} throws SAXException
{
if (contentHandler != null) {
/** contentHandler.endDocument();
* Adapt a SAX1 start document event. }
* }
* @exception org.xml.sax.SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#startDocument /**
*/ * Adapter implementation method; do not call.
public void startDocument () * Adapt a SAX1 startElement event.
throws SAXException *
{ * <p>If necessary, perform Namespace processing.</p>
if (contentHandler != null) { *
contentHandler.startDocument(); * @param qName The qualified (prefixed) name.
} * @param qAtts The XML 1.0 attribute list (with qnames).
} * @exception SAXException The client may raise a
* processing exception.
*/
/** public void startElement (String qName, AttributeList qAtts)
* Adapt a SAX1 end document event. throws SAXException
* {
* @exception org.xml.sax.SAXException The client may raise a // These are exceptions from the
* processing exception. // first pass; they should be
* @see org.xml.sax.DocumentHandler#endDocument // ignored if there's a second pass,
*/ // but reported otherwise.
public void endDocument () Vector exceptions = null;
throws SAXException
{ // If we're not doing Namespace
if (contentHandler != null) { // processing, dispatch this quickly.
contentHandler.endDocument(); if (!namespaces) {
} if (contentHandler != null) {
} attAdapter.setAttributeList(qAtts);
contentHandler.startElement("", "", qName.intern(),
attAdapter);
/** }
* Adapt a SAX1 startElement event. return;
* }
* <p>If necessary, perform Namespace processing.</p>
*
* @param qName The qualified (prefixed) name. // OK, we're doing Namespace processing.
* @param qAtts The XML 1.0 attribute list (with qnames). nsSupport.pushContext();
*/ int length = qAtts.getLength();
public void startElement (String qName, AttributeList qAtts)
throws SAXException // First pass: handle NS decls
{ for (int i = 0; i < length; i++) {
// If we're not doing Namespace String attQName = qAtts.getName(i);
// processing, dispatch this quickly.
if (!namespaces) { if (!attQName.startsWith("xmlns"))
if (contentHandler != null) { continue;
attAdapter.setAttributeList(qAtts); // Could be a declaration...
contentHandler.startElement("", "", qName.intern(), String prefix;
attAdapter); int n = attQName.indexOf(':');
}
return; // xmlns=...
} if (n == -1 && attQName.length () == 5) {
prefix = "";
} else if (n != 5) {
// OK, we're doing Namespace processing. // XML namespaces spec doesn't discuss "xmlnsf:oo"
nsSupport.pushContext(); // (and similarly named) attributes ... at most, warn
boolean seenDecl = false; continue;
atts.clear(); } else // xmlns:foo=...
prefix = attQName.substring(n+1);
// Take a first pass and copy all
// attributes into the SAX2 attribute String value = qAtts.getValue(i);
// list, noting any Namespace if (!nsSupport.declarePrefix(prefix, value)) {
// declarations. reportError("Illegal Namespace prefix: " + prefix);
int length = qAtts.getLength(); continue;
for (int i = 0; i < length; i++) { }
String attQName = qAtts.getName(i); if (contentHandler != null)
String type = qAtts.getType(i); contentHandler.startPrefixMapping(prefix, value);
String value = qAtts.getValue(i); }
// Found a declaration... // Second pass: copy all relevant
if (attQName.startsWith("xmlns")) { // attributes into the SAX2 AttributeList
String prefix; // using updated prefix bindings
int n = attQName.indexOf(':'); atts.clear();
if (n == -1) { for (int i = 0; i < length; i++) {
prefix = ""; String attQName = qAtts.getName(i);
} else { String type = qAtts.getType(i);
prefix = attQName.substring(n+1); String value = qAtts.getValue(i);
}
if (!nsSupport.declarePrefix(prefix, value)) { // Declaration?
reportError("Illegal Namespace prefix: " + prefix); if (attQName.startsWith("xmlns")) {
} String prefix;
if (contentHandler != null) { int n = attQName.indexOf(':');
contentHandler.startPrefixMapping(prefix, value);
} if (n == -1 && attQName.length () == 5) {
// We may still have to add this to prefix = "";
// the list. } else if (n != 5) {
if (prefixes) { // XML namespaces spec doesn't discuss "xmlnsf:oo"
atts.addAttribute("", "", attQName.intern(), // (and similarly named) attributes ... ignore
type, value); prefix = null;
} } else {
seenDecl = true; prefix = attQName.substring(n+1);
}
// This isn't a declaration. // Yes, decl: report or prune
} else { if (prefix != null) {
String attName[] = processName(attQName, true); if (prefixes)
atts.addAttribute(attName[0], attName[1], attName[2], atts.addAttribute("", "", attQName.intern(),
type, value); type, value);
} continue;
} }
}
// If there was a Namespace declaration,
// we have to make a second pass just // Not a declaration -- report
// to be safe -- this will happen very try {
// rarely, possibly only once for each String attName[] = processName(attQName, true, true);
// document. atts.addAttribute(attName[0], attName[1], attName[2],
if (seenDecl) { type, value);
length = atts.getLength(); } catch (SAXException e) {
for (int i = 0; i < length; i++) { if (exceptions == null)
String attQName = atts.getQName(i); exceptions = new Vector();
if (!attQName.startsWith("xmlns")) { exceptions.addElement(e);
String attName[] = processName(attQName, true); atts.addAttribute("", attQName, attQName, type, value);
atts.setURI(i, attName[0]); }
atts.setLocalName(i, attName[1]); }
}
} // now handle the deferred exception reports
} if (exceptions != null && errorHandler != null) {
for (int i = 0; i < exceptions.size(); i++)
// OK, finally report the event. errorHandler.error((SAXParseException)
if (contentHandler != null) { (exceptions.elementAt(i)));
String name[] = processName(qName, false); }
contentHandler.startElement(name[0], name[1], name[2], atts);
} // OK, finally report the event.
} if (contentHandler != null) {
String name[] = processName(qName, false, false);
contentHandler.startElement(name[0], name[1], name[2], atts);
/** }
* Adapt a SAX1 end element event. }
*
* @param qName The qualified (prefixed) name.
* @exception org.xml.sax.SAXException The client may raise a /**
* processing exception. * Adapter implementation method; do not call.
* @see org.xml.sax.DocumentHandler#endElement * Adapt a SAX1 end element event.
*/ *
public void endElement (String qName) * @param qName The qualified (prefixed) name.
throws SAXException * @exception SAXException The client may raise a
{ * processing exception.
// If we're not doing Namespace * @see org.xml.sax.DocumentHandler#endElement
// processing, dispatch this quickly. */
if (!namespaces) { public void endElement (String qName)
if (contentHandler != null) { throws SAXException
contentHandler.endElement("", "", qName.intern()); {
} // If we're not doing Namespace
return; // processing, dispatch this quickly.
} if (!namespaces) {
if (contentHandler != null) {
// Split the name. contentHandler.endElement("", "", qName.intern());
String names[] = processName(qName, false); }
if (contentHandler != null) { return;
contentHandler.endElement(names[0], names[1], names[2]); }
Enumeration prefixes = nsSupport.getDeclaredPrefixes();
while (prefixes.hasMoreElements()) { // Split the name.
String prefix = (String)prefixes.nextElement(); String names[] = processName(qName, false, false);
contentHandler.endPrefixMapping(prefix); if (contentHandler != null) {
} contentHandler.endElement(names[0], names[1], names[2]);
} Enumeration prefixes = nsSupport.getDeclaredPrefixes();
nsSupport.popContext(); while (prefixes.hasMoreElements()) {
} String prefix = (String)prefixes.nextElement();
contentHandler.endPrefixMapping(prefix);
}
/** }
* Adapt a SAX1 characters event. nsSupport.popContext();
* }
* @param ch An array of characters.
* @param start The starting position in the array.
* @param length The number of characters to use. /**
* @exception org.xml.sax.SAXException The client may raise a * Adapter implementation method; do not call.
* processing exception. * Adapt a SAX1 characters event.
* @see org.xml.sax.DocumentHandler#characters *
*/ * @param ch An array of characters.
public void characters (char ch[], int start, int length) * @param start The starting position in the array.
throws SAXException * @param length The number of characters to use.
{ * @exception SAXException The client may raise a
if (contentHandler != null) { * processing exception.
contentHandler.characters(ch, start, length); * @see org.xml.sax.DocumentHandler#characters
} */
} public void characters (char ch[], int start, int length)
throws SAXException
{
/** if (contentHandler != null) {
* Adapt a SAX1 ignorable whitespace event. contentHandler.characters(ch, start, length);
* }
* @param ch An array of characters. }
* @param start The starting position in the array.
* @param length The number of characters to use.
* @exception org.xml.sax.SAXException The client may raise a /**
* processing exception. * Adapter implementation method; do not call.
* @see org.xml.sax.DocumentHandler#ignorableWhitespace * Adapt a SAX1 ignorable whitespace event.
*/ *
public void ignorableWhitespace (char ch[], int start, int length) * @param ch An array of characters.
throws SAXException * @param start The starting position in the array.
{ * @param length The number of characters to use.
if (contentHandler != null) { * @exception SAXException The client may raise a
contentHandler.ignorableWhitespace(ch, start, length); * processing exception.
} * @see org.xml.sax.DocumentHandler#ignorableWhitespace
} */
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException
/** {
* Adapt a SAX1 processing instruction event. if (contentHandler != null) {
* contentHandler.ignorableWhitespace(ch, start, length);
* @param target The processing instruction target. }
* @param data The remainder of the processing instruction }
* @exception org.xml.sax.SAXException The client may raise a
* processing exception.
* @see org.xml.sax.DocumentHandler#processingInstruction /**
*/ * Adapter implementation method; do not call.
public void processingInstruction (String target, String data) * Adapt a SAX1 processing instruction event.
throws SAXException *
{ * @param target The processing instruction target.
if (contentHandler != null) { * @param data The remainder of the processing instruction
contentHandler.processingInstruction(target, data); * @exception SAXException The client may raise a
} * processing exception.
} * @see org.xml.sax.DocumentHandler#processingInstruction
*/
public void processingInstruction (String target, String data)
throws SAXException
//////////////////////////////////////////////////////////////////// {
// Internal utility methods. if (contentHandler != null) {
//////////////////////////////////////////////////////////////////// contentHandler.processingInstruction(target, data);
}
}
/**
* Initialize the parser before each run.
*/
private void setupParser () ////////////////////////////////////////////////////////////////////
{ // Internal utility methods.
nsSupport.reset(); ////////////////////////////////////////////////////////////////////
if (entityResolver != null) {
parser.setEntityResolver(entityResolver); /**
} * Initialize the parser before each run.
if (dtdHandler != null) { */
parser.setDTDHandler(dtdHandler); private void setupParser ()
} {
if (errorHandler != null) { nsSupport.reset();
parser.setErrorHandler(errorHandler);
} if (entityResolver != null) {
parser.setDocumentHandler(this); parser.setEntityResolver(entityResolver);
locator = null; }
} if (dtdHandler != null) {
parser.setDTDHandler(dtdHandler);
}
/** if (errorHandler != null) {
* Process a qualified (prefixed) name. parser.setErrorHandler(errorHandler);
* }
* <p>If the name has an undeclared prefix, use only the qname parser.setDocumentHandler(this);
* and make an ErrorHandler.error callback in case the app is locator = null;
* interested.</p> }
*
* @param qName The qualified (prefixed) name.
* @param isAttribute true if this is an attribute name. /**
* @return The name split into three parts. * Process a qualified (prefixed) name.
* @exception org.xml.sax.SAXException The client may throw *
* an exception if there is an error callback. * <p>If the name has an undeclared prefix, use only the qname
*/ * and make an ErrorHandler.error callback in case the app is
private String [] processName (String qName, boolean isAttribute) * interested.</p>
throws SAXException *
{ * @param qName The qualified (prefixed) name.
String parts[] = nsSupport.processName(qName, nameParts, * @param isAttribute true if this is an attribute name.
isAttribute); * @return The name split into three parts.
if (parts == null) { * @exception SAXException The client may throw
parts = new String[3]; * an exception if there is an error callback.
parts[2] = qName.intern(); */
reportError("Undeclared prefix: " + qName); private String [] processName (String qName, boolean isAttribute,
} boolean useException)
return parts; throws SAXException
} {
String parts[] = nsSupport.processName(qName, nameParts,
isAttribute);
/** if (parts == null) {
* Report a non-fatal error. if (useException)
* throw makeException("Undeclared prefix: " + qName);
* @param message The error message. reportError("Undeclared prefix: " + qName);
* @exception org.xml.sax.SAXException The client may throw parts = new String[3];
* an exception. parts[0] = parts[1] = "";
*/ parts[2] = qName.intern();
void reportError (String message) }
throws SAXException return parts;
{ }
if (errorHandler == null) {
return;
} /**
* Report a non-fatal error.
SAXParseException e; *
if (locator != null) { * @param message The error message.
e = new SAXParseException(message, locator); * @exception SAXException The client may throw
} else { * an exception.
e = new SAXParseException(message, null, null, -1, -1); */
} void reportError (String message)
errorHandler.error(e); throws SAXException
} {
if (errorHandler != null)
errorHandler.error(makeException(message));
/** }
* Throw an exception if we are parsing.
*
* <p>Use this method to detect illegal feature or /**
* property changes.</p> * Construct an exception for the current context.
* *
* @param type The type of thing (feature or property). * @param message The error message.
* @param name The feature or property name. */
* @exception org.xml.sax.SAXNotSupportedException If a private SAXParseException makeException (String message)
* document is currently being parsed. {
*/ if (locator != null) {
private void checkNotParsing (String type, String name) return new SAXParseException(message, locator);
throws SAXNotSupportedException } else {
{ return new SAXParseException(message, null, null, -1, -1);
if (parsing) { }
throw new SAXNotSupportedException("Cannot change " + }
type + ' ' +
name + " while parsing");
/**
} * Throw an exception if we are parsing.
} *
* <p>Use this method to detect illegal feature or
* property changes.</p>
*
//////////////////////////////////////////////////////////////////// * @param type The type of thing (feature or property).
// Internal state. * @param name The feature or property name.
//////////////////////////////////////////////////////////////////// * @exception SAXNotSupportedException If a
* document is currently being parsed.
private NamespaceSupport nsSupport; */
private AttributeListAdapter attAdapter; private void checkNotParsing (String type, String name)
throws SAXNotSupportedException
private boolean parsing = false; {
private String nameParts[] = new String[3]; if (parsing) {
throw new SAXNotSupportedException("Cannot change " +
private Parser parser = null; type + ' ' +
name + " while parsing");
private AttributesImpl atts = null;
}
// Features }
private boolean namespaces = true;
private boolean prefixes = false;
// Properties ////////////////////////////////////////////////////////////////////
// Internal state.
// Handlers ////////////////////////////////////////////////////////////////////
Locator locator;
private NamespaceSupport nsSupport;
EntityResolver entityResolver = null; private AttributeListAdapter attAdapter;
DTDHandler dtdHandler = null;
ContentHandler contentHandler = null; private boolean parsing = false;
ErrorHandler errorHandler = null; private String nameParts[] = new String[3];
private Parser parser = null;
//////////////////////////////////////////////////////////////////// private AttributesImpl atts = null;
// Inner class to wrap an AttributeList when not doing NS proc.
//////////////////////////////////////////////////////////////////// // Features
private boolean namespaces = true;
private boolean prefixes = false;
/**
* Adapt a SAX1 AttributeList as a SAX2 Attributes object. // Properties
*
* <p>This class is in the Public Domain, and comes with NO // Handlers
* WARRANTY of any kind.</p> Locator locator;
*
* <p>This wrapper class is used only when Namespace support EntityResolver entityResolver = null;
* is disabled -- it provides pretty much a direct mapping DTDHandler dtdHandler = null;
* from SAX1 to SAX2, except that names and types are ContentHandler contentHandler = null;
* interned whenever requested.</p> ErrorHandler errorHandler = null;
*/
final class AttributeListAdapter implements Attributes
{
////////////////////////////////////////////////////////////////////
/** // Inner class to wrap an AttributeList when not doing NS proc.
* Construct a new adapter. ////////////////////////////////////////////////////////////////////
*/
AttributeListAdapter ()
{ /**
} * Adapt a SAX1 AttributeList as a SAX2 Attributes object.
*
* <p>This class is in the Public Domain, and comes with NO
/** * WARRANTY of any kind.</p>
* Set the embedded AttributeList. *
* * <p>This wrapper class is used only when Namespace support
* <p>This method must be invoked before any of the others * is disabled -- it provides pretty much a direct mapping
* can be used.</p> * from SAX1 to SAX2, except that names and types are
* * interned whenever requested.</p>
* @param The SAX1 attribute list (with qnames). */
*/ final class AttributeListAdapter implements Attributes
void setAttributeList (AttributeList qAtts) {
{
this.qAtts = qAtts; /**
} * Construct a new adapter.
*/
AttributeListAdapter ()
/** {
* Return the length of the attribute list. }
*
* @return The number of attributes in the list.
* @see org.xml.sax.Attributes#getLength /**
*/ * Set the embedded AttributeList.
public int getLength () *
{ * <p>This method must be invoked before any of the others
return qAtts.getLength(); * can be used.</p>
} *
* @param The SAX1 attribute list (with qnames).
*/
/** void setAttributeList (AttributeList qAtts)
* Return the Namespace URI of the specified attribute. {
* this.qAtts = qAtts;
* @param The attribute's index. }
* @return Always the empty string.
* @see org.xml.sax.Attributes#getURI
*/ /**
public String getURI (int i) * Return the length of the attribute list.
{ *
return ""; * @return The number of attributes in the list.
} * @see org.xml.sax.Attributes#getLength
*/
public int getLength ()
/** {
* Return the local name of the specified attribute. return qAtts.getLength();
* }
* @param The attribute's index.
* @return Always the empty string.
* @see org.xml.sax.Attributes#getLocalName /**
*/ * Return the Namespace URI of the specified attribute.
public String getLocalName (int i) *
{ * @param The attribute's index.
return ""; * @return Always the empty string.
} * @see org.xml.sax.Attributes#getURI
*/
public String getURI (int i)
/** {
* Return the qualified (prefixed) name of the specified attribute. return "";
* }
* @param The attribute's index.
* @return The attribute's qualified name, internalized.
*/ /**
public String getQName (int i) * Return the local name of the specified attribute.
{ *
return qAtts.getName(i).intern(); * @param The attribute's index.
} * @return Always the empty string.
* @see org.xml.sax.Attributes#getLocalName
*/
/** public String getLocalName (int i)
* Return the type of the specified attribute. {
* return "";
* @param The attribute's index. }
* @return The attribute's type as an internalized string.
*/
public String getType (int i) /**
{ * Return the qualified (prefixed) name of the specified attribute.
return qAtts.getType(i).intern(); *
} * @param The attribute's index.
* @return The attribute's qualified name, internalized.
*/
/** public String getQName (int i)
* Return the value of the specified attribute. {
* return qAtts.getName(i).intern();
* @param The attribute's index. }
* @return The attribute's value.
*/
public String getValue (int i) /**
{ * Return the type of the specified attribute.
return qAtts.getValue(i); *
} * @param The attribute's index.
* @return The attribute's type as an internalized string.
*/
/** public String getType (int i)
* Look up an attribute index by Namespace name. {
* return qAtts.getType(i).intern();
* @param uri The Namespace URI or the empty string. }
* @param localName The local name.
* @return The attributes index, or -1 if none was found.
* @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String) /**
*/ * Return the value of the specified attribute.
public int getIndex (String uri, String localName) *
{ * @param The attribute's index.
return -1; * @return The attribute's value.
} */
public String getValue (int i)
{
/** return qAtts.getValue(i);
* Look up an attribute index by qualified (prefixed) name. }
*
* @param qName The qualified name.
* @return The attributes index, or -1 if none was found. /**
* @see org.xml.sax.Attributes#getIndex(java.lang.String) * Look up an attribute index by Namespace name.
*/ *
public int getIndex (String qName) * @param uri The Namespace URI or the empty string.
{ * @param localName The local name.
int max = atts.getLength(); * @return The attributes index, or -1 if none was found.
for (int i = 0; i < max; i++) { * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)
if (qAtts.getName(i).equals(qName)) { */
return i; public int getIndex (String uri, String localName)
} {
} return -1;
return -1; }
}
/**
/** * Look up an attribute index by qualified (prefixed) name.
* Look up the type of an attribute by Namespace name. *
* * @param qName The qualified name.
* @param uri The Namespace URI * @return The attributes index, or -1 if none was found.
* @param localName The local name. * @see org.xml.sax.Attributes#getIndex(java.lang.String)
* @return The attribute's type as an internalized string. */
*/ public int getIndex (String qName)
public String getType (String uri, String localName) {
{ int max = atts.getLength();
return null; for (int i = 0; i < max; i++) {
} if (qAtts.getName(i).equals(qName)) {
return i;
}
/** }
* Look up the type of an attribute by qualified (prefixed) name. return -1;
* }
* @param qName The qualified name.
* @return The attribute's type as an internalized string.
*/ /**
public String getType (String qName) * Look up the type of an attribute by Namespace name.
{ *
return qAtts.getType(qName).intern(); * @param uri The Namespace URI
} * @param localName The local name.
* @return The attribute's type as an internalized string.
*/
/** public String getType (String uri, String localName)
* Look up the value of an attribute by Namespace name. {
* return null;
* @param uri The Namespace URI }
* @param localName The local name.
* @return The attribute's value.
*/ /**
public String getValue (String uri, String localName) * Look up the type of an attribute by qualified (prefixed) name.
{ *
return null; * @param qName The qualified name.
} * @return The attribute's type as an internalized string.
*/
public String getType (String qName)
/** {
* Look up the value of an attribute by qualified (prefixed) name. return qAtts.getType(qName).intern();
* }
* @param qName The qualified name.
* @return The attribute's value.
*/ /**
public String getValue (String qName) * Look up the value of an attribute by Namespace name.
{ *
return qAtts.getValue(qName); * @param uri The Namespace URI
} * @param localName The local name.
* @return The attribute's value.
private AttributeList qAtts; */
} public String getValue (String uri, String localName)
} {
return null;
// end of ParserAdapter.java }
/**
* Look up the value of an attribute by qualified (prefixed) name.
*
* @param qName The qualified name.
* @return The attribute's value.
*/
public String getValue (String qName)
{
return qAtts.getValue(qName);
}
private AttributeList qAtts;
}
}
// end of ParserAdapter.java
// SAX parser factory. // SAX parser factory.
// No warranty; no copyright -- use this as you will. // http://www.saxproject.org
// $Id: ParserFactory.java,v 1.1 2000/10/02 02:43:20 sboag Exp $ // No warranty; no copyright -- use this as you will.
// $Id: ParserFactory.java,v 1.4.2.3 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import java.lang.ClassNotFoundException;
import java.lang.IllegalAccessException; import java.lang.ClassNotFoundException;
import java.lang.InstantiationException; import java.lang.IllegalAccessException;
import java.lang.SecurityException; import java.lang.InstantiationException;
import java.lang.ClassCastException; import java.lang.SecurityException;
import java.lang.ClassCastException;
import org.xml.sax.Parser;
import org.xml.sax.Parser;
/**
* Java-specific class for dynamically loading SAX parsers. /**
* * Java-specific class for dynamically loading SAX parsers.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p><strong>Note:</strong> This class is designed to work with the now-deprecated * for further information.
* SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use * </blockquote>
* {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p> *
* * <p><strong>Note:</strong> This class is designed to work with the now-deprecated
* <p>ParserFactory is not part of the platform-independent definition * SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
* of SAX; it is an additional convenience class designed * {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
* specifically for Java XML application writers. SAX applications *
* can use the static methods in this class to allocate a SAX parser * <p>ParserFactory is not part of the platform-independent definition
* dynamically at run-time based either on the value of the * of SAX; it is an additional convenience class designed
* `org.xml.sax.parser' system property or on a string containing the class * specifically for Java XML application writers. SAX applications
* name.</p> * can use the static methods in this class to allocate a SAX parser
* * dynamically at run-time based either on the value of the
* <p>Note that the application still requires an XML parser that * `org.xml.sax.parser' system property or on a string containing the class
* implements SAX1.</p> * name.</p>
* *
* @deprecated This class works with the deprecated * <p>Note that the application still requires an XML parser that
* {@link org.xml.sax.Parser Parser} * implements SAX1.</p>
* interface. *
* @since SAX 1.0 * @deprecated This class works with the deprecated
* @author David Megginson, * {@link org.xml.sax.Parser Parser}
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * interface.
* @version 2.0 * @since SAX 1.0
* @see org.xml.sax.Parser * @author David Megginson
* @see java.lang.Class * @version 2.0.1 (sax2r2)
*/ */
public class ParserFactory { public class ParserFactory {
/** /**
* Private null constructor. * Private null constructor.
*/ */
private ParserFactory () private ParserFactory ()
{ {
} }
/** /**
* Create a new SAX parser using the `org.xml.sax.parser' system property. * Create a new SAX parser using the `org.xml.sax.parser' system property.
* *
* <p>The named class must exist and must implement the * <p>The named class must exist and must implement the
* {@link org.xml.sax.Parser Parser} interface.</p> * {@link org.xml.sax.Parser Parser} interface.</p>
* *
* @exception java.lang.NullPointerException There is no value * @exception java.lang.NullPointerException There is no value
* for the `org.xml.sax.parser' system property. * for the `org.xml.sax.parser' system property.
* @exception java.lang.ClassNotFoundException The SAX parser * @exception java.lang.ClassNotFoundException The SAX parser
* class was not found (check your CLASSPATH). * class was not found (check your CLASSPATH).
* @exception IllegalAccessException The SAX parser class was * @exception IllegalAccessException The SAX parser class was
* found, but you do not have permission to load * found, but you do not have permission to load
* it. * it.
* @exception InstantiationException The SAX parser class was * @exception InstantiationException The SAX parser class was
* found but could not be instantiated. * found but could not be instantiated.
* @exception java.lang.ClassCastException The SAX parser class * @exception java.lang.ClassCastException The SAX parser class
* was found and instantiated, but does not implement * was found and instantiated, but does not implement
* org.xml.sax.Parser. * org.xml.sax.Parser.
* @see #makeParser(java.lang.String) * @see #makeParser(java.lang.String)
* @see org.xml.sax.Parser * @see org.xml.sax.Parser
*/ */
public static Parser makeParser () public static Parser makeParser ()
throws ClassNotFoundException, throws ClassNotFoundException,
IllegalAccessException, IllegalAccessException,
InstantiationException, InstantiationException,
NullPointerException, NullPointerException,
ClassCastException ClassCastException
{ {
String className = System.getProperty("org.xml.sax.parser"); String className = System.getProperty("org.xml.sax.parser");
if (className == null) { if (className == null) {
throw new NullPointerException("No value for sax.parser property"); throw new NullPointerException("No value for sax.parser property");
} else { } else {
return makeParser(className); return makeParser(className);
} }
} }
/** /**
* Create a new SAX parser object using the class name provided. * Create a new SAX parser object using the class name provided.
* *
* <p>The named class must exist and must implement the * <p>The named class must exist and must implement the
* {@link org.xml.sax.Parser Parser} interface.</p> * {@link org.xml.sax.Parser Parser} interface.</p>
* *
* @param className A string containing the name of the * @param className A string containing the name of the
* SAX parser class. * SAX parser class.
* @exception java.lang.ClassNotFoundException The SAX parser * @exception java.lang.ClassNotFoundException The SAX parser
* class was not found (check your CLASSPATH). * class was not found (check your CLASSPATH).
* @exception IllegalAccessException The SAX parser class was * @exception IllegalAccessException The SAX parser class was
* found, but you do not have permission to load * found, but you do not have permission to load
* it. * it.
* @exception InstantiationException The SAX parser class was * @exception InstantiationException The SAX parser class was
* found but could not be instantiated. * found but could not be instantiated.
* @exception java.lang.ClassCastException The SAX parser class * @exception java.lang.ClassCastException The SAX parser class
* was found and instantiated, but does not implement * was found and instantiated, but does not implement
* org.xml.sax.Parser. * org.xml.sax.Parser.
* @see #makeParser() * @see #makeParser()
* @see org.xml.sax.Parser * @see org.xml.sax.Parser
*/ */
public static Parser makeParser (String className) public static Parser makeParser (String className)
throws ClassNotFoundException, throws ClassNotFoundException,
IllegalAccessException, IllegalAccessException,
InstantiationException, InstantiationException,
ClassCastException ClassCastException
{ {
return (Parser)(Class.forName(className).newInstance()); return (Parser) NewInstance.newInstance (
} NewInstance.getClassLoader (), className);
}
}
}
// end of ParserFactory.java
// XMLFilterImpl.java - base SAX2 filter implementation. // XMLFilterImpl.java - base SAX2 filter implementation.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the Public Domain. // Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: XMLFilterImpl.java,v 1.1 2000/10/02 02:43:20 sboag Exp $
// $Id: XMLFilterImpl.java,v 1.3.2.7 2002/01/29 21:34:14 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import java.io.IOException;
import java.io.IOException;
import org.xml.sax.XMLReader;
import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader;
import org.xml.sax.InputSource; import org.xml.sax.XMLFilter;
import org.xml.sax.Locator; import org.xml.sax.InputSource;
import org.xml.sax.Attributes; import org.xml.sax.Locator;
import org.xml.sax.EntityResolver; import org.xml.sax.Attributes;
import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver;
import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler;
import org.xml.sax.ErrorHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException; import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXException;
import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXParseException;
import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXNotRecognizedException;
/**
* Base class for deriving an XML filter. /**
* * Base class for deriving an XML filter.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class is designed to sit between an {@link org.xml.sax.XMLReader * for further information.
* XMLReader} and the client application's event handlers. By default, it * </blockquote>
* does nothing but pass requests up to the reader and events *
* on to the handlers unmodified, but subclasses can override * <p>This class is designed to sit between an {@link org.xml.sax.XMLReader
* specific methods to modify the event stream or the configuration * XMLReader} and the client application's event handlers. By default, it
* requests as they pass through.</p> * does nothing but pass requests up to the reader and events
* * on to the handlers unmodified, but subclasses can override
* @since SAX 2.0 * specific methods to modify the event stream or the configuration
* @author David Megginson, * requests as they pass through.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.XMLFilter * @author David Megginson
* @see org.xml.sax.XMLReader * @version 2.0.1 (sax2r2)
* @see org.xml.sax.EntityResolver * @see org.xml.sax.XMLFilter
* @see org.xml.sax.DTDHandler * @see org.xml.sax.XMLReader
* @see org.xml.sax.ContentHandler * @see org.xml.sax.EntityResolver
* @see org.xml.sax.ErrorHandler * @see org.xml.sax.DTDHandler
*/ * @see org.xml.sax.ContentHandler
public class XMLFilterImpl * @see org.xml.sax.ErrorHandler
implements XMLFilter, EntityResolver, DTDHandler, ContentHandler, ErrorHandler */
{ public class XMLFilterImpl
implements XMLFilter, EntityResolver, DTDHandler, ContentHandler, ErrorHandler
{
////////////////////////////////////////////////////////////////////
// Constructors.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Constructors.
////////////////////////////////////////////////////////////////////
/**
* Construct an empty XML filter, with no parent.
* /**
* <p>This filter will have no parent: you must assign a parent * Construct an empty XML filter, with no parent.
* before you start a parse or do any configuration with *
* setFeature or setProperty.</p> * <p>This filter will have no parent: you must assign a parent
* * before you start a parse or do any configuration with
* @see org.xml.sax.XMLReader#setFeature * setFeature or setProperty, unless you use this as a pure event
* @see org.xml.sax.XMLReader#setProperty * consumer rather than as an {@link XMLReader}.</p>
*/ *
public XMLFilterImpl () * @see org.xml.sax.XMLReader#setFeature
{ * @see org.xml.sax.XMLReader#setProperty
super(); * @see #setParent
} */
public XMLFilterImpl ()
{
/** super();
* Construct an XML filter with the specified parent. }
*
* @see #setParent
* @see #getParent /**
*/ * Construct an XML filter with the specified parent.
public XMLFilterImpl (XMLReader parent) *
{ * @see #setParent
super(); * @see #getParent
setParent(parent); */
} public XMLFilterImpl (XMLReader parent)
{
super();
setParent(parent);
//////////////////////////////////////////////////////////////////// }
// Implementation of org.xml.sax.XMLFilter.
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
/** // Implementation of org.xml.sax.XMLFilter.
* Set the parent reader. ////////////////////////////////////////////////////////////////////
*
* <p>This is the {@link org.xml.sax.XMLReader XMLReader} from which
* this filter will obtain its events and to which it will pass its /**
* configuration requests. The parent may itself be another filter.</p> * Set the parent reader.
* *
* <p>If there is no parent reader set, any attempt to parse * <p>This is the {@link org.xml.sax.XMLReader XMLReader} from which
* or to set or get a feature or property will fail.</p> * this filter will obtain its events and to which it will pass its
* * configuration requests. The parent may itself be another filter.</p>
* @param parent The parent XML reader. *
* @exception java.lang.NullPointerException If the parent is null. * <p>If there is no parent reader set, any attempt to parse
* @see #getParent * or to set or get a feature or property will fail.</p>
*/ *
public void setParent (XMLReader parent) * @param parent The parent XML reader.
{ * @see #getParent
if (parent == null) { */
throw new NullPointerException("Null parent"); public void setParent (XMLReader parent)
} {
this.parent = parent; this.parent = parent;
} }
/** /**
* Get the parent reader. * Get the parent reader.
* *
* @return The parent XML reader, or null if none is set. * @return The parent XML reader, or null if none is set.
* @see #setParent * @see #setParent
*/ */
public XMLReader getParent () public XMLReader getParent ()
{ {
return parent; return parent;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.XMLReader. // Implementation of org.xml.sax.XMLReader.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
/** /**
* Set the state of a feature. * Set the value of a feature.
* *
* <p>This will always fail if the parent is null.</p> * <p>This will always fail if the parent is null.</p>
* *
* @param name The feature name. * @param name The feature name.
* @param state The requested feature state. * @param value The requested feature value.
* @exception org.xml.sax.SAXNotRecognizedException When the * @exception org.xml.sax.SAXNotRecognizedException If the feature
* XMLReader does not recognize the feature name. * value can't be assigned or retrieved from the parent.
* @exception org.xml.sax.SAXNotSupportedException When the * @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader recognizes the feature name but * parent recognizes the feature name but
* cannot set the requested value. * cannot set the requested value.
* @see org.xml.sax.XMLReader#setFeature */
*/ public void setFeature (String name, boolean value)
public void setFeature (String name, boolean state) throws SAXNotRecognizedException, SAXNotSupportedException
throws SAXNotRecognizedException, SAXNotSupportedException {
{ if (parent != null) {
if (parent != null) { parent.setFeature(name, value);
parent.setFeature(name, state); } else {
} else { throw new SAXNotRecognizedException("Feature: " + name);
throw new SAXNotRecognizedException("Feature: " + name); }
} }
}
/**
/** * Look up the value of a feature.
* Look up the state of a feature. *
* * <p>This will always fail if the parent is null.</p>
* <p>This will always fail if the parent is null.</p> *
* * @param name The feature name.
* @param name The feature name. * @return The current value of the feature.
* @return The current state of the feature. * @exception org.xml.sax.SAXNotRecognizedException If the feature
* @exception org.xml.sax.SAXNotRecognizedException When the * value can't be assigned or retrieved from the parent.
* XMLReader does not recognize the feature name. * @exception org.xml.sax.SAXNotSupportedException When the
* @exception org.xml.sax.SAXNotSupportedException When the * parent recognizes the feature name but
* XMLReader recognizes the feature name but * cannot determine its value at this time.
* cannot determine its state at this time. */
* @see org.xml.sax.XMLReader#getFeature public boolean getFeature (String name)
*/ throws SAXNotRecognizedException, SAXNotSupportedException
public boolean getFeature (String name) {
throws SAXNotRecognizedException, SAXNotSupportedException if (parent != null) {
{ return parent.getFeature(name);
if (parent != null) { } else {
return parent.getFeature(name); throw new SAXNotRecognizedException("Feature: " + name);
} else { }
throw new SAXNotRecognizedException("Feature: " + name); }
}
}
/**
* Set the value of a property.
/** *
* Set the value of a property. * <p>This will always fail if the parent is null.</p>
* *
* <p>This will always fail if the parent is null.</p> * @param name The property name.
* * @param value The requested property value.
* @param name The property name. * @exception org.xml.sax.SAXNotRecognizedException If the property
* @param state The requested property value. * value can't be assigned or retrieved from the parent.
* @exception org.xml.sax.SAXNotRecognizedException When the * @exception org.xml.sax.SAXNotSupportedException When the
* XMLReader does not recognize the property name. * parent recognizes the property name but
* @exception org.xml.sax.SAXNotSupportedException When the * cannot set the requested value.
* XMLReader recognizes the property name but */
* cannot set the requested value. public void setProperty (String name, Object value)
* @see org.xml.sax.XMLReader#setProperty throws SAXNotRecognizedException, SAXNotSupportedException
*/ {
public void setProperty (String name, Object value) if (parent != null) {
throws SAXNotRecognizedException, SAXNotSupportedException parent.setProperty(name, value);
{ } else {
if (parent != null) { throw new SAXNotRecognizedException("Property: " + name);
parent.setProperty(name, value); }
} else { }
throw new SAXNotRecognizedException("Property: " + name);
}
} /**
* Look up the value of a property.
*
/** * @param name The property name.
* Look up the value of a property. * @return The current value of the property.
* * @exception org.xml.sax.SAXNotRecognizedException If the property
* @param name The property name. * value can't be assigned or retrieved from the parent.
* @return The current value of the property. * @exception org.xml.sax.SAXNotSupportedException When the
* @exception org.xml.sax.SAXNotRecognizedException When the * parent recognizes the property name but
* XMLReader does not recognize the feature name. * cannot determine its value at this time.
* @exception org.xml.sax.SAXNotSupportedException When the */
* XMLReader recognizes the property name but public Object getProperty (String name)
* cannot determine its value at this time. throws SAXNotRecognizedException, SAXNotSupportedException
* @see org.xml.sax.XMLReader#setFeature {
*/ if (parent != null) {
public Object getProperty (String name) return parent.getProperty(name);
throws SAXNotRecognizedException, SAXNotSupportedException } else {
{ throw new SAXNotRecognizedException("Property: " + name);
if (parent != null) { }
return parent.getProperty(name); }
} else {
throw new SAXNotRecognizedException("Property: " + name);
} /**
} * Set the entity resolver.
*
* @param resolver The new entity resolver.
/** */
* Set the entity resolver. public void setEntityResolver (EntityResolver resolver)
* {
* @param resolver The new entity resolver. entityResolver = resolver;
* @exception java.lang.NullPointerException If the resolver }
* is null.
* @see org.xml.sax.XMLReader#setEntityResolver
*/ /**
public void setEntityResolver (EntityResolver resolver) * Get the current entity resolver.
{ *
if (resolver == null) { * @return The current entity resolver, or null if none was set.
throw new NullPointerException("Null entity resolver"); */
} else { public EntityResolver getEntityResolver ()
entityResolver = resolver; {
} return entityResolver;
} }
/** /**
* Get the current entity resolver. * Set the DTD event handler.
* *
* @return The current entity resolver, or null if none was set. * @param resolver The new DTD handler.
* @see org.xml.sax.XMLReader#getEntityResolver */
*/ public void setDTDHandler (DTDHandler handler)
public EntityResolver getEntityResolver () {
{ dtdHandler = handler;
return entityResolver; }
}
/**
/** * Get the current DTD event handler.
* Set the DTD event handler. *
* * @return The current DTD handler, or null if none was set.
* @param resolver The new DTD handler. */
* @exception java.lang.NullPointerException If the handler public DTDHandler getDTDHandler ()
* is null. {
* @see org.xml.sax.XMLReader#setDTDHandler return dtdHandler;
*/ }
public void setDTDHandler (DTDHandler handler)
{
if (handler == null) { /**
throw new NullPointerException("Null DTD handler"); * Set the content event handler.
} else { *
dtdHandler = handler; * @param resolver The new content handler.
} */
} public void setContentHandler (ContentHandler handler)
{
contentHandler = handler;
/** }
* Get the current DTD event handler.
*
* @return The current DTD handler, or null if none was set. /**
* @see org.xml.sax.XMLReader#getDTDHandler * Get the content event handler.
*/ *
public DTDHandler getDTDHandler () * @return The current content handler, or null if none was set.
{ */
return dtdHandler; public ContentHandler getContentHandler ()
} {
return contentHandler;
}
/**
* Set the content event handler.
* /**
* @param resolver The new content handler. * Set the error event handler.
* @exception java.lang.NullPointerException If the handler *
* is null. * @param handle The new error handler.
* @see org.xml.sax.XMLReader#setContentHandler */
*/ public void setErrorHandler (ErrorHandler handler)
public void setContentHandler (ContentHandler handler) {
{ errorHandler = handler;
if (handler == null) { }
throw new NullPointerException("Null content handler");
} else {
contentHandler = handler; /**
} * Get the current error event handler.
} *
* @return The current error handler, or null if none was set.
*/
/** public ErrorHandler getErrorHandler ()
* Get the content event handler. {
* return errorHandler;
* @return The current content handler, or null if none was set. }
* @see org.xml.sax.XMLReader#getContentHandler
*/
public ContentHandler getContentHandler () /**
{ * Parse a document.
return contentHandler; *
} * @param input The input source for the document entity.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
/** * @exception java.io.IOException An IO exception from the parser,
* Set the error event handler. * possibly from a byte stream or character stream
* * supplied by the application.
* @param handle The new error handler. */
* @exception java.lang.NullPointerException If the handler public void parse (InputSource input)
* is null. throws SAXException, IOException
* @see org.xml.sax.XMLReader#setErrorHandler {
*/ setupParse();
public void setErrorHandler (ErrorHandler handler) parent.parse(input);
{ }
if (handler == null) {
throw new NullPointerException("Null error handler");
} else { /**
errorHandler = handler; * Parse a document.
} *
} * @param systemId The system identifier as a fully-qualified URI.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
/** * @exception java.io.IOException An IO exception from the parser,
* Get the current error event handler. * possibly from a byte stream or character stream
* * supplied by the application.
* @return The current error handler, or null if none was set. */
* @see org.xml.sax.XMLReader#getErrorHandler public void parse (String systemId)
*/ throws SAXException, IOException
public ErrorHandler getErrorHandler () {
{ parse(new InputSource(systemId));
return errorHandler; }
}
/** ////////////////////////////////////////////////////////////////////
* Parse a document. // Implementation of org.xml.sax.EntityResolver.
* ////////////////////////////////////////////////////////////////////
* @param input The input source for the document entity.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception. /**
* @exception java.io.IOException An IO exception from the parser, * Filter an external entity resolution.
* possibly from a byte stream or character stream *
* supplied by the application. * @param publicId The entity's public identifier, or null.
* @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource) * @param systemId The entity's system identifier.
*/ * @return A new InputSource or null for the default.
public void parse (InputSource input) * @exception org.xml.sax.SAXException The client may throw
throws SAXException, IOException * an exception during processing.
{ * @exception java.io.IOException The client may throw an
setupParse(); * I/O-related exception while obtaining the
parent.parse(input); * new InputSource.
} */
public InputSource resolveEntity (String publicId, String systemId)
throws SAXException, IOException
/** {
* Parse a document. if (entityResolver != null) {
* return entityResolver.resolveEntity(publicId, systemId);
* @param systemId The system identifier as a fully-qualified URI. } else {
* @exception org.xml.sax.SAXException Any SAX exception, possibly return null;
* wrapping another exception. }
* @exception java.io.IOException An IO exception from the parser, }
* possibly from a byte stream or character stream
* supplied by the application.
* @see org.xml.sax.XMLReader#parse(java.lang.String)
*/ ////////////////////////////////////////////////////////////////////
public void parse (String systemId) // Implementation of org.xml.sax.DTDHandler.
throws SAXException, IOException ////////////////////////////////////////////////////////////////////
{
parse(new InputSource(systemId));
} /**
* Filter a notation declaration event.
*
* @param name The notation name.
//////////////////////////////////////////////////////////////////// * @param publicId The notation's public identifier, or null.
// Implementation of org.xml.sax.EntityResolver. * @param systemId The notation's system identifier, or null.
//////////////////////////////////////////////////////////////////// * @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
*/
/** public void notationDecl (String name, String publicId, String systemId)
* Filter an external entity resolution. throws SAXException
* {
* @param publicId The entity's public identifier, or null. if (dtdHandler != null) {
* @param systemId The entity's system identifier. dtdHandler.notationDecl(name, publicId, systemId);
* @return A new InputSource or null for the default. }
* @exception org.xml.sax.SAXException The client may throw }
* an exception during processing.
* @exception java.io.IOException The client may throw an
* I/O-related exception while obtaining the /**
* new InputSource. * Filter an unparsed entity declaration event.
* @see org.xml.sax.EntityResolver#resolveEntity *
*/ * @param name The entity name.
public InputSource resolveEntity (String publicId, String systemId) * @param publicId The entity's public identifier, or null.
throws SAXException, IOException * @param systemId The entity's system identifier, or null.
{ * @param notationName The name of the associated notation.
if (entityResolver != null) { * @exception org.xml.sax.SAXException The client may throw
return entityResolver.resolveEntity(publicId, systemId); * an exception during processing.
} else { */
return null; public void unparsedEntityDecl (String name, String publicId,
} String systemId, String notationName)
} throws SAXException
{
if (dtdHandler != null) {
dtdHandler.unparsedEntityDecl(name, publicId, systemId,
//////////////////////////////////////////////////////////////////// notationName);
// Implementation of org.xml.sax.DTDHandler. }
//////////////////////////////////////////////////////////////////// }
/**
* Filter a notation declaration event. ////////////////////////////////////////////////////////////////////
* // Implementation of org.xml.sax.ContentHandler.
* @param name The notation name. ////////////////////////////////////////////////////////////////////
* @param publicId The notation's public identifier, or null.
* @param systemId The notation's system identifier, or null.
* @exception org.xml.sax.SAXException The client may throw /**
* an exception during processing. * Filter a new document locator event.
* @see org.xml.sax.DTDHandler#notationDecl *
*/ * @param locator The document locator.
public void notationDecl (String name, String publicId, String systemId) */
throws SAXException public void setDocumentLocator (Locator locator)
{ {
if (dtdHandler != null) { this.locator = locator;
dtdHandler.notationDecl(name, publicId, systemId); if (contentHandler != null) {
} contentHandler.setDocumentLocator(locator);
} }
}
/**
* Filter an unparsed entity declaration event. /**
* * Filter a start document event.
* @param name The entity name. *
* @param publicId The entity's public identifier, or null. * @exception org.xml.sax.SAXException The client may throw
* @param systemId The entity's system identifier, or null. * an exception during processing.
* @param notationName The name of the associated notation. */
* @exception org.xml.sax.SAXException The client may throw public void startDocument ()
* an exception during processing. throws SAXException
* @see org.xml.sax.DTDHandler#unparsedEntityDecl {
*/ if (contentHandler != null) {
public void unparsedEntityDecl (String name, String publicId, contentHandler.startDocument();
String systemId, String notationName) }
throws SAXException }
{
if (dtdHandler != null) {
dtdHandler.unparsedEntityDecl(name, publicId, systemId, /**
notationName); * Filter an end document event.
} *
} * @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
*/
public void endDocument ()
//////////////////////////////////////////////////////////////////// throws SAXException
// Implementation of org.xml.sax.ContentHandler. {
//////////////////////////////////////////////////////////////////// if (contentHandler != null) {
contentHandler.endDocument();
}
/** }
* Filter a new document locator event.
*
* @param locator The document locator. /**
* @see org.xml.sax.ContentHandler#setDocumentLocator * Filter a start Namespace prefix mapping event.
*/ *
public void setDocumentLocator (Locator locator) * @param prefix The Namespace prefix.
{ * @param uri The Namespace URI.
this.locator = locator; * @exception org.xml.sax.SAXException The client may throw
if (contentHandler != null) { * an exception during processing.
contentHandler.setDocumentLocator(locator); */
} public void startPrefixMapping (String prefix, String uri)
} throws SAXException
{
if (contentHandler != null) {
/** contentHandler.startPrefixMapping(prefix, uri);
* Filter a start document event. }
* }
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#startDocument /**
*/ * Filter an end Namespace prefix mapping event.
public void startDocument () *
throws SAXException * @param prefix The Namespace prefix.
{ * @exception org.xml.sax.SAXException The client may throw
if (contentHandler != null) { * an exception during processing.
contentHandler.startDocument(); */
} public void endPrefixMapping (String prefix)
} throws SAXException
{
if (contentHandler != null) {
/** contentHandler.endPrefixMapping(prefix);
* Filter an end document event. }
* }
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#endDocument /**
*/ * Filter a start element event.
public void endDocument () *
throws SAXException * @param uri The element's Namespace URI, or the empty string.
{ * @param localName The element's local name, or the empty string.
if (contentHandler != null) { * @param qName The element's qualified (prefixed) name, or the empty
contentHandler.endDocument(); * string.
} * @param atts The element's attributes.
} * @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
*/
/** public void startElement (String uri, String localName, String qName,
* Filter a start Namespace prefix mapping event. Attributes atts)
* throws SAXException
* @param prefix The Namespace prefix. {
* @param uri The Namespace URI. if (contentHandler != null) {
* @exception org.xml.sax.SAXException The client may throw contentHandler.startElement(uri, localName, qName, atts);
* an exception during processing. }
* @see org.xml.sax.ContentHandler#startPrefixMapping }
*/
public void startPrefixMapping (String prefix, String uri)
throws SAXException /**
{ * Filter an end element event.
if (contentHandler != null) { *
contentHandler.startPrefixMapping(prefix, uri); * @param uri The element's Namespace URI, or the empty string.
} * @param localName The element's local name, or the empty string.
} * @param qName The element's qualified (prefixed) name, or the empty
* string.
* @exception org.xml.sax.SAXException The client may throw
/** * an exception during processing.
* Filter an end Namespace prefix mapping event. */
* public void endElement (String uri, String localName, String qName)
* @param prefix The Namespace prefix. throws SAXException
* @exception org.xml.sax.SAXException The client may throw {
* an exception during processing. if (contentHandler != null) {
* @see org.xml.sax.ContentHandler#endPrefixMapping contentHandler.endElement(uri, localName, qName);
*/ }
public void endPrefixMapping (String prefix) }
throws SAXException
{
if (contentHandler != null) { /**
contentHandler.endPrefixMapping(prefix); * Filter a character data event.
} *
} * @param ch An array of characters.
* @param start The starting position in the array.
* @param length The number of characters to use from the array.
/** * @exception org.xml.sax.SAXException The client may throw
* Filter a start element event. * an exception during processing.
* */
* @param uri The element's Namespace URI, or the empty string. public void characters (char ch[], int start, int length)
* @param localName The element's local name, or the empty string. throws SAXException
* @param qName The element's qualified (prefixed) name, or the empty {
* string. if (contentHandler != null) {
* @param atts The element's attributes. contentHandler.characters(ch, start, length);
* @exception org.xml.sax.SAXException The client may throw }
* an exception during processing. }
* @see org.xml.sax.ContentHandler#startElement
*/
public void startElement (String uri, String localName, String qName, /**
Attributes atts) * Filter an ignorable whitespace event.
throws SAXException *
{ * @param ch An array of characters.
if (contentHandler != null) { * @param start The starting position in the array.
contentHandler.startElement(uri, localName, qName, atts); * @param length The number of characters to use from the array.
} * @exception org.xml.sax.SAXException The client may throw
} * an exception during processing.
*/
public void ignorableWhitespace (char ch[], int start, int length)
/** throws SAXException
* Filter an end element event. {
* if (contentHandler != null) {
* @param uri The element's Namespace URI, or the empty string. contentHandler.ignorableWhitespace(ch, start, length);
* @param localName The element's local name, or the empty string. }
* @param qName The element's qualified (prefixed) name, or the empty }
* string.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing. /**
* @see org.xml.sax.ContentHandler#endElement * Filter a processing instruction event.
*/ *
public void endElement (String uri, String localName, String qName) * @param target The processing instruction target.
throws SAXException * @param data The text following the target.
{ * @exception org.xml.sax.SAXException The client may throw
if (contentHandler != null) { * an exception during processing.
contentHandler.endElement(uri, localName, qName); */
} public void processingInstruction (String target, String data)
} throws SAXException
{
if (contentHandler != null) {
/** contentHandler.processingInstruction(target, data);
* Filter a character data event. }
* }
* @param ch An array of characters.
* @param start The starting position in the array.
* @param length The number of characters to use from the array. /**
* @exception org.xml.sax.SAXException The client may throw * Filter a skipped entity event.
* an exception during processing. *
* @see org.xml.sax.ContentHandler#characters * @param name The name of the skipped entity.
*/ * @exception org.xml.sax.SAXException The client may throw
public void characters (char ch[], int start, int length) * an exception during processing.
throws SAXException */
{ public void skippedEntity (String name)
if (contentHandler != null) { throws SAXException
contentHandler.characters(ch, start, length); {
} if (contentHandler != null) {
} contentHandler.skippedEntity(name);
}
}
/**
* Filter an ignorable whitespace event.
*
* @param ch An array of characters. ////////////////////////////////////////////////////////////////////
* @param start The starting position in the array. // Implementation of org.xml.sax.ErrorHandler.
* @param length The number of characters to use from the array. ////////////////////////////////////////////////////////////////////
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ContentHandler#ignorableWhitespace /**
*/ * Filter a warning event.
public void ignorableWhitespace (char ch[], int start, int length) *
throws SAXException * @param e The warning as an exception.
{ * @exception org.xml.sax.SAXException The client may throw
if (contentHandler != null) { * an exception during processing.
contentHandler.ignorableWhitespace(ch, start, length); */
} public void warning (SAXParseException e)
} throws SAXException
{
if (errorHandler != null) {
/** errorHandler.warning(e);
* Filter a processing instruction event. }
* }
* @param target The processing instruction target.
* @param data The text following the target.
* @exception org.xml.sax.SAXException The client may throw /**
* an exception during processing. * Filter an error event.
* @see org.xml.sax.ContentHandler#processingInstruction *
*/ * @param e The error as an exception.
public void processingInstruction (String target, String data) * @exception org.xml.sax.SAXException The client may throw
throws SAXException * an exception during processing.
{ */
if (contentHandler != null) { public void error (SAXParseException e)
contentHandler.processingInstruction(target, data); throws SAXException
} {
} if (errorHandler != null) {
errorHandler.error(e);
}
/** }
* Filter a skipped entity event.
*
* @param name The name of the skipped entity. /**
* @exception org.xml.sax.SAXException The client may throw * Filter a fatal error event.
* an exception during processing. *
* @see org.xml.sax.ContentHandler#skippedEntity * @param e The error as an exception.
*/ * @exception org.xml.sax.SAXException The client may throw
public void skippedEntity (String name) * an exception during processing.
throws SAXException */
{ public void fatalError (SAXParseException e)
if (contentHandler != null) { throws SAXException
contentHandler.skippedEntity(name); {
} if (errorHandler != null) {
} errorHandler.fatalError(e);
}
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.ErrorHandler.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Internal methods.
////////////////////////////////////////////////////////////////////
/**
* Filter a warning event.
* /**
* @param e The nwarning as an exception. * Set up before a parse.
* @exception org.xml.sax.SAXException The client may throw *
* an exception during processing. * <p>Before every parse, check whether the parent is
* @see org.xml.sax.ErrorHandler#warning * non-null, and re-register the filter for all of the
*/ * events.</p>
public void warning (SAXParseException e) */
throws SAXException private void setupParse ()
{ {
if (errorHandler != null) { if (parent == null) {
errorHandler.warning(e); throw new NullPointerException("No parent for filter");
} }
} parent.setEntityResolver(this);
parent.setDTDHandler(this);
parent.setContentHandler(this);
/** parent.setErrorHandler(this);
* Filter an error event. }
*
* @param e The error as an exception.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing. ////////////////////////////////////////////////////////////////////
* @see org.xml.sax.ErrorHandler#error // Internal state.
*/ ////////////////////////////////////////////////////////////////////
public void error (SAXParseException e)
throws SAXException private XMLReader parent = null;
{ private Locator locator = null;
if (errorHandler != null) { private EntityResolver entityResolver = null;
errorHandler.error(e); private DTDHandler dtdHandler = null;
} private ContentHandler contentHandler = null;
} private ErrorHandler errorHandler = null;
}
/**
* Filter a fatal error event. // end of XMLFilterImpl.java
*
* @param e The error as an exception.
* @exception org.xml.sax.SAXException The client may throw
* an exception during processing.
* @see org.xml.sax.ErrorHandler#fatalError
*/
public void fatalError (SAXParseException e)
throws SAXException
{
if (errorHandler != null) {
errorHandler.fatalError(e);
}
}
////////////////////////////////////////////////////////////////////
// Internal methods.
////////////////////////////////////////////////////////////////////
/**
* Set up before a parse.
*
* <p>Before every parse, check whether the parent is
* non-null, and re-register the filter for all of the
* events.</p>
*/
private void setupParse ()
{
if (parent == null) {
throw new NullPointerException("No parent for filter");
}
parent.setEntityResolver(this);
parent.setDTDHandler(this);
parent.setContentHandler(this);
parent.setErrorHandler(this);
}
////////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////////
private XMLReader parent = null;
private Locator locator = null;
private EntityResolver entityResolver = null;
private DTDHandler dtdHandler = null;
private ContentHandler contentHandler = null;
private ErrorHandler errorHandler = null;
}
// end of XMLFilterImpl.java
// XMLReaderAdapter.java - adapt an SAX2 XMLReader to a SAX1 Parser // XMLReaderAdapter.java - adapt an SAX2 XMLReader to a SAX1 Parser
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the public domain. // Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: XMLReaderAdapter.java,v 1.1 2000/10/02 02:43:20 sboag Exp $
// $Id: XMLReaderAdapter.java,v 1.5.2.3 2002/01/29 21:34:15 dbrownell Exp $
package org.xml.sax.helpers;
package org.xml.sax.helpers;
import java.io.IOException;
import java.util.Locale; import java.io.IOException;
import java.util.Locale;
import org.xml.sax.Parser; // deprecated
import org.xml.sax.Locator; import org.xml.sax.Parser; // deprecated
import org.xml.sax.InputSource; import org.xml.sax.Locator;
import org.xml.sax.AttributeList; // deprecated import org.xml.sax.InputSource;
import org.xml.sax.EntityResolver; import org.xml.sax.AttributeList; // deprecated
import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver;
import org.xml.sax.DocumentHandler; // deprecated import org.xml.sax.DTDHandler;
import org.xml.sax.ErrorHandler; import org.xml.sax.DocumentHandler; // deprecated
import org.xml.sax.SAXException; import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.Attributes; import org.xml.sax.XMLReader;
import org.xml.sax.ContentHandler; import org.xml.sax.Attributes;
import org.xml.sax.SAXNotSupportedException; import org.xml.sax.ContentHandler;
import org.xml.sax.SAXNotSupportedException;
/**
* Adapt a SAX2 XMLReader as a SAX1 Parser. /**
* * Adapt a SAX2 XMLReader as a SAX1 Parser.
* <blockquote> *
* <em>This module, both source code and documentation, is in the * <blockquote>
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * <em>This module, both source code and documentation, is in the
* </blockquote> * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* <p>This class wraps a SAX2 {@link org.xml.sax.XMLReader XMLReader} * for further information.
* and makes it act as a SAX1 {@link org.xml.sax.Parser Parser}. The XMLReader * </blockquote>
* must support a true value for the *
* http://xml.org/sax/features/namespace-prefixes property or parsing will fail * <p>This class wraps a SAX2 {@link org.xml.sax.XMLReader XMLReader}
* with a {@link org.xml.sax.SAXException SAXException}; if the XMLReader * and makes it act as a SAX1 {@link org.xml.sax.Parser Parser}. The XMLReader
* supports a false value for the http://xml.org/sax/features/namespaces * must support a true value for the
* property, that will also be used to improve efficiency.</p> * http://xml.org/sax/features/namespace-prefixes property or parsing will fail
* * with a {@link org.xml.sax.SAXException SAXException}; if the XMLReader
* @since SAX 2.0 * supports a false value for the http://xml.org/sax/features/namespaces
* @author David Megginson, * property, that will also be used to improve efficiency.</p>
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> *
* @version 2.0 * @since SAX 2.0
* @see org.xml.sax.Parser * @author David Megginson
* @see org.xml.sax.XMLReader * @version 2.0.1 (sax2r2)
*/ * @see org.xml.sax.Parser
public class XMLReaderAdapter implements Parser, ContentHandler * @see org.xml.sax.XMLReader
{ */
public class XMLReaderAdapter implements Parser, ContentHandler
{
////////////////////////////////////////////////////////////////////
// Constructor.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Constructor.
////////////////////////////////////////////////////////////////////
/**
* Create a new adapter.
* /**
* <p>Use the "org.xml.sax.driver" property to locate the SAX2 * Create a new adapter.
* driver to embed.</p> *
* * <p>Use the "org.xml.sax.driver" property to locate the SAX2
* @exception org.xml.sax.SAXException If the embedded driver * driver to embed.</p>
* cannot be instantiated or if the *
* org.xml.sax.driver property is not specified. * @exception org.xml.sax.SAXException If the embedded driver
*/ * cannot be instantiated or if the
public XMLReaderAdapter () * org.xml.sax.driver property is not specified.
throws SAXException */
{ public XMLReaderAdapter ()
setup(XMLReaderFactory.createXMLReader()); throws SAXException
} {
setup(XMLReaderFactory.createXMLReader());
}
/**
* Create a new adapter.
* /**
* <p>Create a new adapter, wrapped around a SAX2 XMLReader. * Create a new adapter.
* The adapter will make the XMLReader act like a SAX1 *
* Parser.</p> * <p>Create a new adapter, wrapped around a SAX2 XMLReader.
* * The adapter will make the XMLReader act like a SAX1
* @param xmlReader The SAX2 XMLReader to wrap. * Parser.</p>
* @exception java.lang.NullPointerException If the argument is null. *
*/ * @param xmlReader The SAX2 XMLReader to wrap.
public XMLReaderAdapter (XMLReader xmlReader) * @exception java.lang.NullPointerException If the argument is null.
{ */
setup(xmlReader); public XMLReaderAdapter (XMLReader xmlReader)
} {
setup(xmlReader);
}
/**
* Internal setup.
* /**
* @param xmlReader The embedded XMLReader. * Internal setup.
*/ *
private void setup (XMLReader xmlReader) * @param xmlReader The embedded XMLReader.
{ */
if (xmlReader == null) { private void setup (XMLReader xmlReader)
throw new NullPointerException("XMLReader must not be null"); {
} if (xmlReader == null) {
this.xmlReader = xmlReader; throw new NullPointerException("XMLReader must not be null");
qAtts = new AttributesAdapter(); }
} this.xmlReader = xmlReader;
qAtts = new AttributesAdapter();
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Parser.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Parser.
////////////////////////////////////////////////////////////////////
/**
* Set the locale for error reporting.
* /**
* <p>This is not supported in SAX2, and will always throw * Set the locale for error reporting.
* an exception.</p> *
* * <p>This is not supported in SAX2, and will always throw
* @param The locale for error reporting. * an exception.</p>
* @see org.xml.sax.Parser#setLocale *
*/ * @param The locale for error reporting.
public void setLocale (Locale locale) * @see org.xml.sax.Parser#setLocale
throws SAXException * @exception org.xml.sax.SAXException Thrown unless overridden.
{ */
throw new SAXNotSupportedException("setLocale not supported"); public void setLocale (Locale locale)
} throws SAXException
{
throw new SAXNotSupportedException("setLocale not supported");
/** }
* Register the entity resolver.
*
* @param resolver The new resolver. /**
* @see org.xml.sax.Parser#setEntityResolver * Register the entity resolver.
*/ *
public void setEntityResolver (EntityResolver resolver) * @param resolver The new resolver.
{ * @see org.xml.sax.Parser#setEntityResolver
xmlReader.setEntityResolver(resolver); */
} public void setEntityResolver (EntityResolver resolver)
{
xmlReader.setEntityResolver(resolver);
/** }
* Register the DTD event handler.
*
* @param handler The new DTD event handler. /**
* @see org.xml.sax.Parser#setDTDHandler * Register the DTD event handler.
*/ *
public void setDTDHandler (DTDHandler handler) * @param handler The new DTD event handler.
{ * @see org.xml.sax.Parser#setDTDHandler
xmlReader.setDTDHandler(handler); */
} public void setDTDHandler (DTDHandler handler)
{
xmlReader.setDTDHandler(handler);
/** }
* Register the SAX1 document event handler.
*
* <p>Note that the SAX1 document handler has no Namespace /**
* support.</p> * Register the SAX1 document event handler.
* *
* @param handler The new SAX1 document event handler. * <p>Note that the SAX1 document handler has no Namespace
* @see org.xml.sax.Parser#setDocumentHandler * support.</p>
*/ *
public void setDocumentHandler (DocumentHandler handler) * @param handler The new SAX1 document event handler.
{ * @see org.xml.sax.Parser#setDocumentHandler
documentHandler = handler; */
} public void setDocumentHandler (DocumentHandler handler)
{
documentHandler = handler;
/** }
* Register the error event handler.
*
* @param handler The new error event handler. /**
* @see org.xml.sax.Parser#setErrorHandler * Register the error event handler.
*/ *
public void setErrorHandler (ErrorHandler handler) * @param handler The new error event handler.
{ * @see org.xml.sax.Parser#setErrorHandler
xmlReader.setErrorHandler(handler); */
} public void setErrorHandler (ErrorHandler handler)
{
xmlReader.setErrorHandler(handler);
/** }
* Parse the document.
*
* <p>This method will throw an exception if the embedded /**
* XMLReader does not support the * Parse the document.
* http://xml.org/sax/features/namespace-prefixes property.</p> *
* * <p>This method will throw an exception if the embedded
* @param systemId The absolute URL of the document. * XMLReader does not support the
* @exception java.io.IOException If there is a problem reading * http://xml.org/sax/features/namespace-prefixes property.</p>
* the raw content of the document. *
* @exception org.xml.sax.SAXException If there is a problem * @param systemId The absolute URL of the document.
* processing the document. * @exception java.io.IOException If there is a problem reading
* @see #parse(org.xml.sax.InputSource) * the raw content of the document.
* @see org.xml.sax.Parser#parse(java.lang.String) * @exception org.xml.sax.SAXException If there is a problem
*/ * processing the document.
public void parse (String systemId) * @see #parse(org.xml.sax.InputSource)
throws IOException, SAXException * @see org.xml.sax.Parser#parse(java.lang.String)
{ */
parse(new InputSource(systemId)); public void parse (String systemId)
} throws IOException, SAXException
{
parse(new InputSource(systemId));
/** }
* Parse the document.
*
* <p>This method will throw an exception if the embedded /**
* XMLReader does not support the * Parse the document.
* http://xml.org/sax/features/namespace-prefixes property.</p> *
* * <p>This method will throw an exception if the embedded
* @param input An input source for the document. * XMLReader does not support the
* @exception java.io.IOException If there is a problem reading * http://xml.org/sax/features/namespace-prefixes property.</p>
* the raw content of the document. *
* @exception org.xml.sax.SAXException If there is a problem * @param input An input source for the document.
* processing the document. * @exception java.io.IOException If there is a problem reading
* @see #parse(java.lang.String) * the raw content of the document.
* @see org.xml.sax.Parser#parse(org.xml.sax.InputSource) * @exception org.xml.sax.SAXException If there is a problem
*/ * processing the document.
public void parse (InputSource input) * @see #parse(java.lang.String)
throws IOException, SAXException * @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)
{ */
setupXMLReader(); public void parse (InputSource input)
xmlReader.parse(input); throws IOException, SAXException
} {
setupXMLReader();
xmlReader.parse(input);
/** }
* Set up the XML reader.
*/
private void setupXMLReader () /**
throws SAXException * Set up the XML reader.
{ */
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); private void setupXMLReader ()
try { throws SAXException
xmlReader.setFeature("http://xml.org/sax/features/namespaces", {
false); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
} catch (SAXException e) { try {
// NO OP: it's just extra information, and we can ignore it xmlReader.setFeature("http://xml.org/sax/features/namespaces",
} false);
xmlReader.setContentHandler(this); } catch (SAXException e) {
} // NO OP: it's just extra information, and we can ignore it
}
xmlReader.setContentHandler(this);
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.ContentHandler.
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.ContentHandler.
/** ////////////////////////////////////////////////////////////////////
* Set a document locator.
*
* @param locator The document locator. /**
* @see org.xml.sax.ContentHandler#setDocumentLocator * Set a document locator.
*/ *
public void setDocumentLocator (Locator locator) * @param locator The document locator.
{ * @see org.xml.sax.ContentHandler#setDocumentLocator
documentHandler.setDocumentLocator(locator); */
} public void setDocumentLocator (Locator locator)
{
if (documentHandler != null)
/** documentHandler.setDocumentLocator(locator);
* Start document event. }
*
* @exception org.xml.sax.SAXException The client may raise a
* processing exception. /**
* @see org.xml.sax.ContentHandler#startDocument * Start document event.
*/ *
public void startDocument () * @exception org.xml.sax.SAXException The client may raise a
throws SAXException * processing exception.
{ * @see org.xml.sax.ContentHandler#startDocument
documentHandler.startDocument(); */
} public void startDocument ()
throws SAXException
{
/** if (documentHandler != null)
* End document event. documentHandler.startDocument();
* }
* @exception org.xml.sax.SAXException The client may raise a
* processing exception.
* @see org.xml.sax.ContentHandler#endDocument /**
*/ * End document event.
public void endDocument () *
throws SAXException * @exception org.xml.sax.SAXException The client may raise a
{ * processing exception.
documentHandler.endDocument(); * @see org.xml.sax.ContentHandler#endDocument
} */
public void endDocument ()
throws SAXException
/** {
* Adapt a SAX2 start prefix mapping event. if (documentHandler != null)
* documentHandler.endDocument();
* @param prefix The prefix being mapped. }
* @param uri The Namespace URI being mapped to.
* @see org.xml.sax.ContentHandler#startPrefixMapping
*/ /**
public void startPrefixMapping (String prefix, String uri) * Adapt a SAX2 start prefix mapping event.
{ *
} * @param prefix The prefix being mapped.
* @param uri The Namespace URI being mapped to.
* @see org.xml.sax.ContentHandler#startPrefixMapping
/** */
* Adapt a SAX2 end prefix mapping event. public void startPrefixMapping (String prefix, String uri)
* {
* @param prefix The prefix being mapped. }
* @see org.xml.sax.ContentHandler#endPrefixMapping
*/
public void endPrefixMapping (String prefix) /**
{ * Adapt a SAX2 end prefix mapping event.
} *
* @param prefix The prefix being mapped.
* @see org.xml.sax.ContentHandler#endPrefixMapping
/** */
* Adapt a SAX2 start element event. public void endPrefixMapping (String prefix)
* {
* @param uri The Namespace URI. }
* @param localName The Namespace local name.
* @param qName The qualified (prefixed) name.
* @param atts The SAX2 attributes. /**
* @exception org.xml.sax.SAXException The client may raise a * Adapt a SAX2 start element event.
* processing exception. *
* @see org.xml.sax.ContentHandler#endDocument * @param uri The Namespace URI.
*/ * @param localName The Namespace local name.
public void startElement (String uri, String localName, * @param qName The qualified (prefixed) name.
String qName, Attributes atts) * @param atts The SAX2 attributes.
throws SAXException * @exception org.xml.sax.SAXException The client may raise a
{ * processing exception.
qAtts.setAttributes(atts); * @see org.xml.sax.ContentHandler#endDocument
documentHandler.startElement(qName, qAtts); */
} public void startElement (String uri, String localName,
String qName, Attributes atts)
throws SAXException
/** {
* Adapt a SAX2 end element event. if (documentHandler != null) {
* qAtts.setAttributes(atts);
* @param uri The Namespace URI. documentHandler.startElement(qName, qAtts);
* @param localName The Namespace local name. }
* @param qName The qualified (prefixed) name. }
* @exception org.xml.sax.SAXException The client may raise a
* processing exception.
* @see org.xml.sax.ContentHandler#endElement /**
*/ * Adapt a SAX2 end element event.
public void endElement (String uri, String localName, *
String qName) * @param uri The Namespace URI.
throws SAXException * @param localName The Namespace local name.
{ * @param qName The qualified (prefixed) name.
documentHandler.endElement(qName); * @exception org.xml.sax.SAXException The client may raise a
} * processing exception.
* @see org.xml.sax.ContentHandler#endElement
*/
/** public void endElement (String uri, String localName,
* Adapt a SAX2 characters event. String qName)
* throws SAXException
* @param ch An array of characters. {
* @param start The starting position in the array. if (documentHandler != null)
* @param length The number of characters to use. documentHandler.endElement(qName);
* @exception org.xml.sax.SAXException The client may raise a }
* processing exception.
* @see org.xml.sax.ContentHandler#characters
*/ /**
public void characters (char ch[], int start, int length) * Adapt a SAX2 characters event.
throws SAXException *
{ * @param ch An array of characters.
documentHandler.characters(ch, start, length); * @param start The starting position in the array.
} * @param length The number of characters to use.
* @exception org.xml.sax.SAXException The client may raise a
* processing exception.
/** * @see org.xml.sax.ContentHandler#characters
* Adapt a SAX2 ignorable whitespace event. */
* public void characters (char ch[], int start, int length)
* @param ch An array of characters. throws SAXException
* @param start The starting position in the array. {
* @param length The number of characters to use. if (documentHandler != null)
* @exception org.xml.sax.SAXException The client may raise a documentHandler.characters(ch, start, length);
* processing exception. }
* @see org.xml.sax.ContentHandler#ignorableWhitespace
*/
public void ignorableWhitespace (char ch[], int start, int length) /**
throws SAXException * Adapt a SAX2 ignorable whitespace event.
{ *
documentHandler.ignorableWhitespace(ch, start, length); * @param ch An array of characters.
} * @param start The starting position in the array.
* @param length The number of characters to use.
* @exception org.xml.sax.SAXException The client may raise a
/** * processing exception.
* Adapt a SAX2 processing instruction event. * @see org.xml.sax.ContentHandler#ignorableWhitespace
* */
* @param target The processing instruction target. public void ignorableWhitespace (char ch[], int start, int length)
* @param data The remainder of the processing instruction throws SAXException
* @exception org.xml.sax.SAXException The client may raise a {
* processing exception. if (documentHandler != null)
* @see org.xml.sax.ContentHandler#processingInstruction documentHandler.ignorableWhitespace(ch, start, length);
*/ }
public void processingInstruction (String target, String data)
throws SAXException
{ /**
documentHandler.processingInstruction(target, data); * Adapt a SAX2 processing instruction event.
} *
* @param target The processing instruction target.
* @param data The remainder of the processing instruction
/** * @exception org.xml.sax.SAXException The client may raise a
* Adapt a SAX2 skipped entity event. * processing exception.
* * @see org.xml.sax.ContentHandler#processingInstruction
* @param name The name of the skipped entity. */
* @see org.xml.sax.ContentHandler#skippedEntity public void processingInstruction (String target, String data)
*/ throws SAXException
public void skippedEntity (String name) {
throws SAXException if (documentHandler != null)
{ documentHandler.processingInstruction(target, data);
} }
/**
//////////////////////////////////////////////////////////////////// * Adapt a SAX2 skipped entity event.
// Internal state. *
//////////////////////////////////////////////////////////////////// * @param name The name of the skipped entity.
* @see org.xml.sax.ContentHandler#skippedEntity
XMLReader xmlReader; * @exception org.xml.sax.SAXException Throwable by subclasses.
DocumentHandler documentHandler; */
AttributesAdapter qAtts; public void skippedEntity (String name)
throws SAXException
{
}
////////////////////////////////////////////////////////////////////
// Internal class.
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Internal state.
/** ////////////////////////////////////////////////////////////////////
* Internal class to wrap a SAX2 Attributes object for SAX1.
*/ XMLReader xmlReader;
final class AttributesAdapter implements AttributeList DocumentHandler documentHandler;
{ AttributesAdapter qAtts;
AttributesAdapter ()
{
}
////////////////////////////////////////////////////////////////////
// Internal class.
/** ////////////////////////////////////////////////////////////////////
* Set the embedded Attributes object.
*
* @param The embedded SAX2 Attributes. /**
*/ * Internal class to wrap a SAX2 Attributes object for SAX1.
void setAttributes (Attributes attributes) */
{ final class AttributesAdapter implements AttributeList
this.attributes = attributes; {
} AttributesAdapter ()
{
}
/**
* Return the number of attributes.
* /**
* @return The length of the attribute list. * Set the embedded Attributes object.
* @see org.xml.sax.AttributeList#getLength *
*/ * @param The embedded SAX2 Attributes.
public int getLength () */
{ void setAttributes (Attributes attributes)
return attributes.getLength(); {
} this.attributes = attributes;
}
/**
* Return the qualified (prefixed) name of an attribute by position. /**
* * Return the number of attributes.
* @return The qualified name. *
* @see org.xml.sax.AttributeList#getName * @return The length of the attribute list.
*/ * @see org.xml.sax.AttributeList#getLength
public String getName (int i) */
{ public int getLength ()
return attributes.getQName(i); {
} return attributes.getLength();
}
/**
* Return the type of an attribute by position. /**
* * Return the qualified (prefixed) name of an attribute by position.
* @return The type. *
* @see org.xml.sax.AttributeList#getType(int) * @return The qualified name.
*/ * @see org.xml.sax.AttributeList#getName
public String getType (int i) */
{ public String getName (int i)
return attributes.getType(i); {
} return attributes.getQName(i);
}
/**
* Return the value of an attribute by position. /**
* * Return the type of an attribute by position.
* @return The value. *
* @see org.xml.sax.AttributeList#getValue(int) * @return The type.
*/ * @see org.xml.sax.AttributeList#getType(int)
public String getValue (int i) */
{ public String getType (int i)
return attributes.getValue(i); {
} return attributes.getType(i);
}
/**
* Return the type of an attribute by qualified (prefixed) name. /**
* * Return the value of an attribute by position.
* @return The type. *
* @see org.xml.sax.AttributeList#getType(java.lang.String) * @return The value.
*/ * @see org.xml.sax.AttributeList#getValue(int)
public String getType (String qName) */
{ public String getValue (int i)
return attributes.getType(qName); {
} return attributes.getValue(i);
}
/**
* Return the value of an attribute by qualified (prefixed) name. /**
* * Return the type of an attribute by qualified (prefixed) name.
* @return The value. *
* @see org.xml.sax.AttributeList#getValue(java.lang.String) * @return The type.
*/ * @see org.xml.sax.AttributeList#getType(java.lang.String)
public String getValue (String qName) */
{ public String getType (String qName)
return attributes.getValue(qName); {
} return attributes.getType(qName);
}
private Attributes attributes;
}
/**
} * Return the value of an attribute by qualified (prefixed) name.
*
// end of XMLReaderAdapter.java * @return The value.
* @see org.xml.sax.AttributeList#getValue(java.lang.String)
*/
public String getValue (String qName)
{
return attributes.getValue(qName);
}
private Attributes attributes;
}
}
// end of XMLReaderAdapter.java
// XMLReaderFactory.java - factory for creating a new reader. // XMLReaderFactory.java - factory for creating a new reader.
// Written by David Megginson, sax@megginson.com // http://www.saxproject.org
// NO WARRANTY! This class is in the Public Domain. // Written by David Megginson
// and by David Brownell
// $Id: XMLReaderFactory.java,v 1.1 2000/10/02 02:43:20 sboag Exp $ // NO WARRANTY! This class is in the Public Domain.
package org.xml.sax.helpers; // $Id: XMLReaderFactory.java,v 1.5.2.4 2002/01/29 21:34:15 dbrownell Exp $
import org.xml.sax.Parser;
import org.xml.sax.XMLReader; package org.xml.sax.helpers;
import org.xml.sax.SAXException; import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/** import org.xml.sax.XMLReader;
* Factory for creating an XML reader. import org.xml.sax.SAXException;
*
* <blockquote>
* <em>This module, both source code and documentation, is in the /**
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em> * Factory for creating an XML reader.
* </blockquote> *
* * <blockquote>
* <p>This class contains static methods for creating an XML reader * <em>This module, both source code and documentation, is in the
* from an explicit class name, or for creating an XML reader based * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* on the value of the <code>org.xml.sax.driver</code> system * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
* property:</p> * for further information.
* * </blockquote>
* <pre> *
* try { * <p>This class contains static methods for creating an XML reader
* XMLReader myReader = XMLReaderFactory.createXMLReader(); * from an explicit class name, or based on runtime defaults:</p>
* } catch (SAXException e) { *
* System.err.println(e.getMessage()); * <pre>
* } * try {
* </pre> * XMLReader myReader = XMLReaderFactory.createXMLReader();
* * } catch (SAXException e) {
* <p>Note that these methods will not be usable in environments where * System.err.println(e.getMessage());
* system properties are not accessible or where the application or * }
* applet is not permitted to load classes dynamically.</p> * </pre>
* *
* <p><strong>Note to implementors:</strong> SAX implementations in specialized * <p><strong>Note to Distributions bundled with parsers:</strong>
* environments may replace this class with a different one optimized for the * You should modify the implementation of the no-arguments
* environment, as long as its method signatures remain the same.</p> * <em>createXMLReader</em> to handle cases where the external
* * configuration mechanisms aren't set up. That method should do its
* @since SAX 2.0 * best to return a parser when one is in the class path, even when
* @author David Megginson, * nothing bound its class name to <code>org.xml.sax.driver</code> so
* <a href="mailto:sax@megginson.com">sax@megginson.com</a> * those configuration mechanisms would see it.</p>
* @version 2.0 *
* @see org.xml.sax.XMLReader * @since SAX 2.0
*/ * @author David Megginson, David Brownell
final public class XMLReaderFactory * @version 2.0.1 (sax2r2)
{ */
final public class XMLReaderFactory
/** {
* Private constructor. /**
* * Private constructor.
* <p>This constructor prevents the class from being instantiated.</p> *
*/ * <p>This constructor prevents the class from being instantiated.</p>
private XMLReaderFactory () */
{ private XMLReaderFactory ()
} {
}
/** private static final String property = "org.xml.sax.driver";
* Attempt to create an XML reader from a system property.
* /**
* <p>This method uses the value of the system property * Attempt to create an XMLReader from system defaults.
* "org.xml.sax.driver" as the full name of a Java class * In environments which can support it, the name of the XMLReader
* and tries to instantiate that class as a SAX2 * class is determined by trying each these options in order, and
* XMLReader.</p> * using the first one which succeeds:</p> <ul>
* *
* <p>Note that many Java interpreters allow system properties * <li>If the system property <code>org.xml.sax.driver</code>
* to be specified on the command line.</p> * has a value, that is used as an XMLReader class name. </li>
* *
* @return A new XMLReader. * <li>The JAR "Services API" is used to look for a class name
* @exception org.xml.sax.SAXException If the value of the * in the <em>META-INF/services/org.xml.sax.driver</em> file in
* "org.xml.sax.driver" system property is null, * jarfiles available to the runtime.</li>
* or if the class cannot be loaded and instantiated. *
* @see #createXMLReader(java.lang.String) * <li> SAX parser distributions are strongly encouraged to provide
*/ * a default XMLReader class name that will take effect only when
public static XMLReader createXMLReader () * previous options (on this list) are not successful.</li>
throws SAXException *
{ * <li>Finally, if {@link ParserFactory#makeParser()} can
String className = System.getProperty("org.xml.sax.driver"); * return a system default SAX1 parser, that parser is wrapped in
if (className == null) { * a {@link ParserAdapter}. (This is a migration aid for SAX1
Parser parser; * environments, where the <code>org.xml.sax.parser</code> system
try { * property will often be usable.) </li>
parser = ParserFactory.makeParser(); *
} catch (Exception e) { * </ul>
parser = null; *
} * <p> In environments such as small embedded systems, which can not
if (parser == null) { * support that flexibility, other mechanisms to determine the default
throw new * may be used. </p>
SAXException("System property org.xml.sax.driver not specified"); *
} else { * <p>Note that many Java environments allow system properties to be
return new ParserAdapter(parser); * initialized on a command line. This means that <em>in most cases</em>
} * setting a good value for that property ensures that calls to this
} else { * method will succeed, except when security policies intervene.
return createXMLReader(className); * This will also maximize application portability to older SAX
} * environments, with less robust implementations of this method.
} * </p>
*
* @return A new XMLReader.
/** * @exception org.xml.sax.SAXException If no default XMLReader class
* Attempt to create an XML reader from a class name. * can be identified and instantiated.
* * @see #createXMLReader(java.lang.String)
* <p>Given a class name, this method attempts to load */
* and instantiate the class as an XML reader.</p> public static XMLReader createXMLReader ()
* throws SAXException
* @return A new XML reader. {
* @exception org.xml.sax.SAXException If the class cannot be String className = null;
* loaded, instantiated, and cast to XMLReader. ClassLoader loader = NewInstance.getClassLoader ();
* @see #createXMLReader()
*/ // 1. try the JVM-instance-wide system property
public static XMLReader createXMLReader (String className) try { className = System.getProperty (property); }
throws SAXException catch (Exception e) { /* normally fails for applets */ }
{
try { // 2. if that fails, try META-INF/services/
return (XMLReader)(Class.forName(className).newInstance()); if (className == null) {
} catch (ClassNotFoundException e1) { try {
throw new SAXException("SAX2 driver class " + className + String service = "META-INF/services/" + property;
" not found", e1); InputStream in;
} catch (IllegalAccessException e2) { BufferedReader reader;
throw new SAXException("SAX2 driver class " + className +
" found but cannot be loaded", e2); if (loader == null)
} catch (InstantiationException e3) { in = ClassLoader.getSystemResourceAsStream (service);
throw new SAXException("SAX2 driver class " + className + else
" loaded but cannot be instantiated (no empty public constructor?)", in = loader.getResourceAsStream (service);
e3);
} catch (ClassCastException e4) { if (in != null) {
throw new SAXException("SAX2 driver class " + className + reader = new BufferedReader (
" does not implement XMLReader", e4); new InputStreamReader (in, "UTF8"));
} className = reader.readLine ();
in.close ();
} }
} catch (Exception e) {
} }
}
// end of XMLReaderFactory.java
// 3. Distro-specific fallback
if (className == null) {
// BEGIN DISTRIBUTION-SPECIFIC
// EXAMPLE:
// className = "com.example.sax.XmlReader";
// or a $JAVA_HOME/jre/lib/*properties setting...
// END DISTRIBUTION-SPECIFIC
}
// do we know the XMLReader implementation class yet?
if (className != null)
return loadClass (loader, className);
// 4. panic -- adapt any SAX1 parser
try {
return new ParserAdapter (ParserFactory.makeParser ());
} catch (Exception e) {
throw new SAXException ("Can't create default XMLReader; "
+ "is system property org.xml.sax.driver set?");
}
}
/**
* Attempt to create an XML reader from a class name.
*
* <p>Given a class name, this method attempts to load
* and instantiate the class as an XML reader.</p>
*
* <p>Note that this method will not be usable in environments where
* the caller (perhaps an applet) is not permitted to load classes
* dynamically.</p>
*
* @return A new XML reader.
* @exception org.xml.sax.SAXException If the class cannot be
* loaded, instantiated, and cast to XMLReader.
* @see #createXMLReader()
*/
public static XMLReader createXMLReader (String className)
throws SAXException
{
return loadClass (NewInstance.getClassLoader (), className);
}
private static XMLReader loadClass (ClassLoader loader, String className)
throws SAXException
{
try {
return (XMLReader) NewInstance.newInstance (loader, className);
} catch (ClassNotFoundException e1) {
throw new SAXException("SAX2 driver class " + className +
" not found", e1);
} catch (IllegalAccessException e2) {
throw new SAXException("SAX2 driver class " + className +
" found but cannot be loaded", e2);
} catch (InstantiationException e3) {
throw new SAXException("SAX2 driver class " + className +
" loaded but cannot be instantiated (no empty public constructor?)",
e3);
} catch (ClassCastException e4) {
throw new SAXException("SAX2 driver class " + className +
" does not implement XMLReader", e4);
}
}
}
<HTML><HEAD>
<!-- $Id: package.html,v 1.3.2.1 2001/11/09 20:32:58 dbrownell Exp $ -->
</HEAD><BODY>
<p>This package contains "helper" classes, including
support for bootstrapping SAX-based applications.
<p>See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
for more information about SAX.</p>
</BODY></HTML>
<html><head>
<!-- $Id: package.html,v 1.2.2.2 2002/01/12 21:42:21 dbrownell Exp $ -->
</head><body>
<p> This package provides the core SAX APIs.
Some SAX1 APIs are deprecated to encourage integration of
namespace-awareness into designs of new applications
and into maintainance of existing infrastructure. </p>
<p>See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
for more information about SAX.</p>
<h2> SAX2 Standard Feature Flags </h2>
<p> One of the essential characteristics of SAX2 is that it added
feature flags which can be used to examine and perhaps modify
parser modes, in particular modes such as validation.
Since features are identified by (absolute) URIs, anyone
can define such features.
Currently defined standard feature URIs have the prefix
<code>http://xml.org/sax/features/</code> before an identifier such as
<code>validation</code>. Turn features on or off using
<em>setFeature</em>. Those standard identifiers are: </p>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
<tr align="center" bgcolor="#ccccff">
<th>Feature ID</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>external-general-entities</td>
<td><em>unspecified</em></td>
<td> Reports whether this parser processes external
general entities; always true if validating</td>
</tr>
<tr>
<td>external-parameter-entities</td>
<td><em>unspecified</em></td>
<td> Reports whether this parser processes external
parameter entities; always true if validating</td>
</tr>
<tr>
<td>lexical-handler/parameter-entities</td>
<td><em>unspecified</em></td>
<td> true indicates that the LexicalHandler will report the
beginning and end of parameter entities
</td>
</tr>
<tr>
<td>namespaces</td>
<td>true</td>
<td> true indicates namespace URIs and unprefixed local names
for element and attribute names will be available </td>
</tr>
<tr>
<td>namespace-prefixes</td>
<td>false</td>
<td> true indicates XML 1.0 names (with prefixes) and attributes
(including <em>xmlns*</em> attributes) will be available </td>
</tr>
<tr>
<td>string-interning</td>
<td><em>unspecified</em></td>
<td> true if all XML names (for elements, prefixes, attributes,
entities, notations, and local names),
as well as Namespace URIs, will have been interned
using <em>java.lang.String.intern</em>. This supports fast
testing of equality/inequality against string constants.</td>
</tr>
<tr>
<td>validation</td>
<td><em>unspecified</em></td>
<td> controls whether the parser is reporting all validity
errors; if true, all external entities will be read. </td>
</tr>
</table>
<p> Support for the default values of the
<em>namespaces</em> and <em>namespace-prefixes</em>
properties is required.
</p>
<p> For default values not specified by SAX2,
each XMLReader implementation specifies its default,
or may choose not to expose the feature flag.
Unless otherwise specified here,
implementations may support changing current values
of these standard feature flags, but not while parsing.
</p>
<h2> SAX2 Standard Handler and Property IDs </h2>
<p> For parser interface characteristics that are described
as objects, a separate namespace is defined. The
objects in this namespace are again identified by URI, and
the standard property URIs have the prefix
<code>http://xml.org/sax/properties/</code> before an identifier such as
<code>lexical-handler</code> or
<code>dom-node</code>. Manage those properties using
<em>setProperty()</em>. Those identifiers are: </p>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
<tr align="center" bgcolor="#ccccff">
<th>Property ID</th>
<th>Description</th>
</tr>
<tr>
<td>declaration-handler</td>
<td> Used to see most DTD declarations except those treated
as lexical ("document element name is ...") or which are
mandatory for all SAX parsers (<em>DTDHandler</em>).
The Object must implement <a href="ext/DeclHandler.html"
><em>org.xml.sax.ext.DeclHandler</em></a>.
</td>
</tr>
<tr>
<td>dom-node</td>
<td> For "DOM Walker" style parsers, which ignore their
<em>parser.parse()</em> parameters, this is used to
specify the DOM (sub)tree being walked by the parser.
The Object must implement the
<em>org.w3c.dom.Node</em> interface.
</td>
</tr>
<tr>
<td>lexical-handler</td>
<td> Used to see some syntax events that are essential in some
applications: comments, CDATA delimeters, selected general
entity inclusions, and the start and end of the DTD
(and declaration of document element name).
The Object must implement <a href="ext/LexicalHandler.html"
><em>org.xml.sax.ext.LexicalHandler</em></a>.
</td>
</tr>
<tr>
<td>xml-string</td>
<td> Readable only during a parser callback, this exposes a <b>TBS</b>
chunk of characters responsible for the current event. </td>
</tr>
</table>
<p> All of these standard properties are optional;
XMLReader implementations need not support them.
</p>
</body></html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment