Commit b0fa81ee by Tom Tromey Committed by Tom Tromey

Major merge with Classpath.

	Removed many duplicate files.
	* HACKING: Updated.x
	* classpath: Imported new directory.
	* standard.omit: New file.
	* Makefile.in, aclocal.m4, configure: Rebuilt.
	* sources.am: New file.
	* configure.ac: Run Classpath configure script.  Moved code around
	to support.  Disable xlib AWT peers (temporarily).
	* Makefile.am (SUBDIRS): Added 'classpath'
	(JAVAC): Removed.
	(AM_CPPFLAGS): Added more -I options.
	(BOOTCLASSPATH): Simplified.
	Completely redid how sources are built.
	Include sources.am.
	* include/Makefile.am (tool_include__HEADERS): Removed jni.h.
	* include/jni.h: Removed (in Classpath).
	* scripts/classes.pl: Updated to look at built classes.
	* scripts/makemake.tcl: New file.
	* testsuite/libjava.jni/jni.exp (gcj_jni_compile_c_to_so): Added
	-I options.
	(gcj_jni_invocation_compile_c_to_binary): Likewise.

From-SVN: r102082
parent ea54b293

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

2005-07-15 Tom Tromey <tromey@redhat.com>
Major merge with Classpath.
Removed many duplicate files.
* HACKING: Updated.x
* classpath: Imported new directory.
* standard.omit: New file.
* Makefile.in, aclocal.m4, configure: Rebuilt.
* sources.am: New file.
* configure.ac: Run Classpath configure script. Moved code around
to support. Disable xlib AWT peers (temporarily).
* Makefile.am (SUBDIRS): Added 'classpath'
(JAVAC): Removed.
(AM_CPPFLAGS): Added more -I options.
(BOOTCLASSPATH): Simplified.
Completely redid how sources are built.
Include sources.am.
* include/Makefile.am (tool_include__HEADERS): Removed jni.h.
* include/jni.h: Removed (in Classpath).
* scripts/classes.pl: Updated to look at built classes.
* scripts/makemake.tcl: New file.
* testsuite/libjava.jni/jni.exp (gcj_jni_compile_c_to_so): Added
-I options.
(gcj_jni_invocation_compile_c_to_binary): Likewise.
2005-07-15 Scott Gilbertson <scottg@mantatest.com>
* gnu/awt/xlib/XCanvasPeer.java (attributes): New field.
......
......@@ -7,36 +7,46 @@ explained in this HACKING file. Please add them if you discover them :)
--
A lot of the standard library files come from the GNU Classpath project.
<http://www.gnu.org/software/classpath/>
The libgcj and Classpath project have officially merged, but the merge
is not yet complete. Our eventual goal is for Classpath to be an upstream
source provider for libgcj, however it will be some time before this becomes
reality: libgcj and Classpath have different implementations of many core
java classes. In order to merge them, we need to select the best (most
efficient, cleanest) implementation of each method/class/package, resolve
any conflicts created by the merge, and test the final result.
The merged files can be recognized by the standard Classpath copyright
comments at the top of the file. If you make changes to these files
then you should also check in the fix to Classpath. For small changes
it may be easier to send a patch to the classpath mailinglist. For
large changes, if you have direct write access to the libgcj tree,
then you will also need to get a Classpath account and do the work
yourself.
<http://mail.gnu.org/mailman/listinfo/classpath/>
<mailto:classpath@gnu.org>
If you merge a libgcj class with a classpath class then you must update the
copyright notice at the top of the file so others can see that this is a
shared libgcj/classpath file.
libgcj uses GNU Classpath as an upstream provider. Snapshots of
Classpath are imported into the libgcj source tree. Some classes are
overridden by local versions; these files still appear in the libgcj
tree.
To import a new release:
- Check out a classpath snapshot
- Use auto* to create configure, Makefile.in, etc
You have to make sure to use the gcc libtool.m4 and gcc lt* scripts
cd .../classpath
cp ../../lt* .
aclocal -I m4 -I ../..
autoconf
autoheader
automake
rm -rf autom4te.cache
- Test everything first. The simplest way to do this is by overlaying
the checked out classpath on your gcc tree and then doing a build.
- Use 'cvs import' to import. The vendor tag is 'CLASSPATH'. For the
release tag, if this is a released classpath version, use something
like 'classpath-import-VERSION'; otherwise something like
'classpath-import-DATE'.
Be sure to use -ko and -I\!
- Remove any files that were deleted in Classpath
- Run 'scripts/makemake.tcl > sources.am' in the source tree
- Run automake for libgcj
Over time we plan to remove as many of the remaining divergences as
possible.
File additions and deletions require running scripts/makemake.tcl
before running automake.
--
If you need to add new java files to libgcj then you have to edit the
Makefile.am file in the top (libjava) directory. And run automake.
Tom Tromey adds:
If you add a class to java.lang, java.io, or java.util
(including sub-packages, like java.lang.ref).
......@@ -45,8 +55,10 @@ If you add a class to java.lang, java.io, or java.util
* Go to the `namespace java' line, and delete that entire block (the
entire contents of the namespace)
* Then insert the output of `perl ../scripts/classes.pl' into the file
at that point.
* Then insert the output of `perl scripts/classes.pl' into the file
at that point. This must be run from the build tree, in
<build>/classpath/lib; it uses the .class file name to determine
what to print.
If you're generating a patch there is a program you can get to do an
offline `cvs add' (it will fake an `add' if you don't have write
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
## Input file for automake to generate the Makefile.in used by configure
# May be used by various substitution variables.
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
SUBDIRS = sax w3c_dom
# Work around what appears to be a GNU make bug handling MAKEFLAGS
# values defined in terms of make variables, as is the case for CC and
# friends when we are called from the top level Makefile.
AM_MAKEFLAGS = \
"AR_FLAGS=$(AR_FLAGS)" \
"CC_FOR_BUILD=$(CC_FOR_BUILD)" \
"CFLAGS=$(CFLAGS)" \
"CXXFLAGS=$(CXXFLAGS)" \
"CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
"INSTALL=$(INSTALL)" \
"INSTALL_DATA=$(INSTALL_DATA)" \
"INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
"INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
"LDFLAGS=$(LDFLAGS)" \
"LIBCFLAGS=$(LIBCFLAGS)" \
"LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
"MAKE=$(MAKE)" \
"MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
"PICFLAG=$(PICFLAG)" \
"PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
"SHELL=$(SHELL)" \
"EXPECT=$(EXPECT)" \
"RUNTEST=$(RUNTEST)" \
"RUNTESTFLAGS=$(RUNTESTFLAGS)" \
"exec_prefix=$(exec_prefix)" \
"infodir=$(infodir)" \
"libdir=$(libdir)" \
"prefix=$(prefix)" \
"tooldir=$(tooldir)" \
"AR=$(AR)" \
"AS=$(AS)" \
"CC=$(CC)" \
"CXX=$(CXX)" \
"LD=$(LD)" \
"LIBCFLAGS=$(LIBCFLAGS)" \
"NM=$(NM)" \
"PICFLAG=$(PICFLAG)" \
"RANLIB=$(RANLIB)" \
"DESTDIR=$(DESTDIR)"
This directory contains libraries maintained externally to GNU Classpath.
See the README files in the subdirectories for more information.
## Process this file with automake to produce Makefile.in.
AUTOMAKE_OPTIONS = foreign subdir-objects
# May be used by various substitution variables.
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
## The compiler with whatever flags we want for both -c and -C
## compiles.
GCJ_WITH_FLAGS = $(GCJ) --encoding=UTF-8 -Wno-deprecated -fclasspath= -fbootclasspath=$(BOOTCLASSPATH)
BOOTCLASSPATH = $(here)'$(CLASSPATH_SEPARATOR)'$(srcdir)'$(CLASSPATH_SEPARATOR)'$(top_srcdir)'$(CLASSPATH_SEPARATOR)'$(top_builddir)
AM_GCJFLAGS = \
-B$(top_builddir) \
@LIBGCJ_JAVAFLAGS@ \
-fclasspath= -fbootclasspath=$(BOOTCLASSPATH) \
--encoding=UTF-8 \
-Wno-deprecated
BUILT_SOURCES = classes.stamp
sax.jar: classes.stamp
find org -name '*.class' -print | $(ZIP) -cfME@ $@
classes.stamp: $(source_files)
here=`pwd`; cd $(srcdir); \
$(GCJ_WITH_FLAGS) -C -d $$here $(source_files)
echo > classes.stamp
mostlyclean-local:
-find . -name '*.class' | xargs rm
-rm classes.stamp sax.jar
noinst_LTLIBRARIES = libsax-gcj.la
libsax_gcj_la_SOURCES = sax.jar
libsax_gcj_la_GCJFLAGS = -findirect-dispatch -fbootstrap-classes $(AM_GCJFLAGS)
source_files = \
org/xml/sax/SAXNotSupportedException.java \
org/xml/sax/helpers/NamespaceSupport.java \
org/xml/sax/helpers/AttributesImpl.java \
org/xml/sax/helpers/LocatorImpl.java \
org/xml/sax/helpers/DefaultHandler.java \
org/xml/sax/helpers/AttributeListImpl.java \
org/xml/sax/helpers/ParserFactory.java \
org/xml/sax/helpers/NewInstance.java \
org/xml/sax/helpers/XMLFilterImpl.java \
org/xml/sax/helpers/ParserAdapter.java \
org/xml/sax/helpers/XMLReaderAdapter.java \
org/xml/sax/helpers/XMLReaderFactory.java \
org/xml/sax/HandlerBase.java \
org/xml/sax/SAXException.java \
org/xml/sax/ContentHandler.java \
org/xml/sax/SAXNotRecognizedException.java \
org/xml/sax/ErrorHandler.java \
org/xml/sax/AttributeList.java \
org/xml/sax/Locator.java \
org/xml/sax/Attributes.java \
org/xml/sax/SAXParseException.java \
org/xml/sax/XMLFilter.java \
org/xml/sax/EntityResolver.java \
org/xml/sax/XMLReader.java \
org/xml/sax/ext/Locator2.java \
org/xml/sax/ext/LexicalHandler.java \
org/xml/sax/ext/Attributes2Impl.java \
org/xml/sax/ext/DeclHandler.java \
org/xml/sax/ext/Attributes2.java \
org/xml/sax/ext/EntityResolver2.java \
org/xml/sax/ext/Locator2Impl.java \
org/xml/sax/ext/DefaultHandler2.java \
org/xml/sax/InputSource.java \
org/xml/sax/DocumentHandler.java \
org/xml/sax/DTDHandler.java \
org/xml/sax/Parser.java
Simple API for XML (SAX), a standard application interface for processing XML.
SAX is not maintained as part of GNU Classpath, but is used with GNU Classpath.
Last imported version sax2r3 final from http://www.saxproject.org/
All files are distributed with the following short notice:
NO WARRANTY! This class is in the Public Domain.
The www.saxproject.org explains:
Copyright Status
SAX is free!
In fact, it's not possible to own a license to SAX, since it's been
placed in the public domain.
No Warranty
Because SAX is released to the public domain, there is no warranty
for the design or for the software implementation, to the extent
permitted by applicable law. Except when otherwise stated in writing
the copyright holders and/or other parties provide SAX "as is" without
warranty of any kind, either expressed or implied, including, but not
limited to, the implied warranties of merchantability and fitness for
a particular purpose. The entire risk as to the quality and
performance of SAX is with you. Should SAX prove defective, you assume
the cost of all necessary servicing, repair or correction.
In no event unless required by applicable law or agreed to in
writing will any copyright holder, or any other party who may modify
and/or redistribute SAX, be liable to you for damages, including any
general, special, incidental or consequential damages arising out of
the use or inability to use SAX (including but not limited to loss of
data or data being rendered inaccurate or losses sustained by you or
third parties or a failure of the SAX to operate with any other
programs), even if such holder or other party has been advised of the
possibility of such damages.
Copyright Disclaimers
This page includes statements to that effect by David Megginson, who
would have been able to claim copyright for the original work.
SAX 1.0
Version 1.0 of the Simple API for XML (SAX), created collectively by
the membership of the XML-DEV mailing list, is hereby released into
the public domain.
No one owns SAX: you may use it freely in both commercial and
non-commercial applications, bundle it with your software
distribution, include it on a CD-ROM, list the source code in a book,
mirror the documentation at your own web site, or use it in any other
way you see fit.
David Megginson, sax@megginson.com
1998-05-11
SAX 2.0
I hereby abandon any property rights to SAX 2.0 (the Simple API for
XML), and release all of the SAX 2.0 source code, compiled code, and
documentation contained in this distribution into the Public
Domain. SAX comes with NO WARRANTY or guarantee of fitness for any
purpose.
David Megginson, david@megginson.com
2000-05-05
// SAX Attribute List Interface.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: AttributeList.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Interface for an element's attribute specifications.
*
* <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 is the original SAX1 interface for reporting an element's
* attributes. Unlike the new {@link org.xml.sax.Attributes Attributes}
* interface, it does not support Namespace-related information.</p>
*
* <p>When an attribute list is supplied as part of a
* {@link org.xml.sax.DocumentHandler#startElement startElement}
* event, the list will return valid results only during the
* scope of the event; once the event handler returns control
* to the parser, the attribute list is invalid. To save a
* persistent copy of the attribute list, use the SAX1
* {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
* helper class.</p>
*
* <p>An attribute list includes only attributes that have been
* specified or defaulted: #IMPLIED attributes will not be included.</p>
*
* <p>There are two ways for the SAX application to obtain information
* from the AttributeList. First, it can iterate through the entire
* list:</p>
*
* <pre>
* public void startElement (String name, AttributeList atts) {
* 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.)
*
* <p>As an alternative, the application can request the value or
* type of specific attributes:</p>
*
* <pre>
* public void startElement (String name, AttributeList atts) {
* String identifier = atts.getValue("id");
* String label = atts.getValue("label");
* [...]
* }
* </pre>
*
* @deprecated This interface has been replaced by the SAX2
* {@link org.xml.sax.Attributes Attributes}
* interface, which includes Namespace support.
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.DocumentHandler#startElement startElement
* @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
*/
public interface AttributeList {
////////////////////////////////////////////////////////////////////
// Iteration methods.
////////////////////////////////////////////////////////////////////
/**
* Return the number of attributes in this list.
*
* <p>The SAX parser may provide attributes in any
* arbitrary order, regardless of the order in which they were
* declared or specified. The number of attributes may be
* zero.</p>
*
* @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
* same attribute twice. Attributes without values (those declared
* #IMPLIED without a value specified in the start tag) will be
* omitted from the list.</p>
*
* <p>If the attribute name has a namespace prefix, the prefix
* will still be attached.</p>
*
* @param i The index of the attribute in the list (starting at 0).
* @return The name of the indexed attribute, or null
* if the index is out of range.
* @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",
* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
* or "NOTATION" (always in upper case).</p>
*
* <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>
*
* <p>For an enumerated attribute that is not a notation, the
* parser will report the type as "NMTOKEN".</p>
*
* @param i The index of the attribute in the list (starting at 0).
* @return The attribute type as a string, or
* null if the index is out of range.
* @see #getLength
* @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,
* ENTITIES, or NMTOKENS), the tokens will be concatenated
* into a single string separated by whitespace.</p>
*
* @param i The index of the attribute in the list (starting at 0).
* @return The attribute value as a string, or
* null if the index is out of range.
* @see #getLength
* @see #getValue(java.lang.String)
*/
public abstract String getValue (int i);
////////////////////////////////////////////////////////////////////
// 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
* getType(int).</p>
*
* <p>If the attribute name has a namespace prefix in the document,
* the application must include the prefix here.</p>
*
* @param name The name of the attribute.
* @return The attribute type as a string, or null if no
* such attribute exists.
* @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
* getValue(int).</p>
*
* <p>If the attribute name has a namespace prefix in the document,
* the application must include the prefix here.</p>
*
* @param name the name of the attribute to return
* @return The attribute value as a string, or null if
* no such attribute exists.
* @see #getValue(int)
*/
public abstract String getValue (String name);
}
// end of AttributeList.java
// Attributes.java - attribute list with Namespace support
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the public domain.
// $Id: Attributes.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Interface for a list of XML attributes.
*
* <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 interface allows access to a list of attributes in
* three different ways:</p>
*
* <ol>
* <li>by attribute index;</li>
* <li>by Namespace-qualified name; or</li>
* <li>by qualified (prefixed) name.</li>
* </ol>
*
* <p>The list will not contain attributes that were declared
* #IMPLIED but not specified in the start tag. It will also not
* contain attributes used as Namespace declarations (xmlns*) unless
* the <code>http://xml.org/sax/features/namespace-prefixes</code>
* feature is set to <var>true</var> (it is <var>false</var> by
* default).
* Because SAX2 conforms to the original "Namespaces in XML"
* recommendation, it normally does not
* give namespace declaration attributes a namespace URI.
* </p>
*
* <p>Some SAX2 parsers may support using an optional feature flag
* (<code>http://xml.org/sax/features/xmlns-uris</code>) to request
* that those attributes be given URIs, conforming to a later
* backwards-incompatible revision of that recommendation. (The
* attribute's "local name" will be the prefix, or "xmlns" when
* defining a default element namespace.) For portability, handler
* code should always resolve that conflict, rather than requiring
* parsers that can change the setting of that feature flag. </p>
*
* <p>If the namespace-prefixes feature (see above) is
* <var>false</var>, access by qualified name may not be available; if
* the <code>http://xml.org/sax/features/namespaces</code> feature is
* <var>false</var>, access by Namespace-qualified names may not be
* available.</p>
*
* <p>This interface replaces the now-deprecated SAX1 {@link
* org.xml.sax.AttributeList AttributeList} interface, which does not
* contain Namespace support. In addition to Namespace support, it
* adds the <var>getIndex</var> methods (below).</p>
*
* <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
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.helpers.AttributesImpl
* @see org.xml.sax.ext.DeclHandler#attributeDecl
*/
public interface Attributes
{
////////////////////////////////////////////////////////////////////
// Indexed access.
////////////////////////////////////////////////////////////////////
/**
* Return the number of attributes in the list.
*
* <p>Once you know the number of attributes, you can iterate
* through the list.</p>
*
* @return The number of attributes in the list.
* @see #getURI(int)
* @see #getLocalName(int)
* @see #getQName(int)
* @see #getType(int)
* @see #getValue(int)
*/
public abstract int getLength ();
/**
* Look up an attribute's Namespace URI by index.
*
* @param index The attribute index (zero-based).
* @return The Namespace URI, or the empty string if none
* is available, or null if the index is out of
* range.
* @see #getLength
*/
public abstract String getURI (int index);
/**
* Look up an attribute's local name by index.
*
* @param index The attribute index (zero-based).
* @return The local name, or the empty string if Namespace
* processing is not being performed, or null
* if the index is out of range.
* @see #getLength
*/
public abstract String getLocalName (int index);
/**
* Look up an attribute's XML qualified (prefixed) name by index.
*
* @param index The attribute index (zero-based).
* @return The XML qualified name, or the empty string
* if none is available, or null if the index
* is out of range.
* @see #getLength
*/
public abstract String getQName (int index);
/**
* Look up an attribute's type by index.
*
* <p>The attribute type is one of the strings "CDATA", "ID",
* "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
* or "NOTATION" (always in upper case).</p>
*
* <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 Recommendation
* (clause 3.3.3, "Attribute-Value Normalization").</p>
*
* <p>For an enumerated attribute that is not a notation, the
* parser will report the type as "NMTOKEN".</p>
*
* @param index The attribute index (zero-based).
* @return The attribute's type as a string, or null if the
* index is out of range.
* @see #getLength
*/
public abstract String getType (int index);
/**
* Look up an attribute's value by index.
*
* <p>If the attribute value is a list of tokens (IDREFS,
* 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).
* @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);
////////////////////////////////////////////////////////////////////
// Name-based query.
////////////////////////////////////////////////////////////////////
/**
* 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.
* @return The index of the attribute, or -1 if it does not
* appear in the list.
*/
public int getIndex (String uri, String localName);
/**
* Look up the index of an attribute by XML qualified (prefixed) name.
*
* @param qName The qualified (prefixed) name.
* @return The index of the attribute, or -1 if it does not
* appear in the list.
*/
public int getIndex (String qName);
/**
* Look up an attribute's type by Namespace name.
*
* <p>See {@link #getType(int) getType(int)} for a description
* of the possible types.</p>
*
* @param uri The Namespace URI, or the empty String if the
* 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
* processing is not being performed.
*/
public abstract String getType (String uri, String localName);
/**
* Look up an attribute's type by XML qualified (prefixed) name.
*
* <p>See {@link #getType(int) getType(int)} for a description
* of the possible types.</p>
*
* @param qName The XML qualified name.
* @return The attribute type as a string, or null if the
* attribute is not in the list or if qualified names
* are not available.
*/
public abstract String getType (String qName);
/**
* Look up an attribute's value by Namespace name.
*
* <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
* 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.
*/
public abstract String getValue (String uri, String localName);
/**
* Look up an attribute's value by XML qualified (prefixed) name.
*
* <p>See {@link #getValue(int) getValue(int)} for a description
* of the possible values.</p>
*
* @param qName The XML 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
// SAX DTD handler.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: DTDHandler.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Receive notification of basic DTD-related events.
*
* <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>If a SAX application needs information about notations and
* unparsed entities, then the application implements this
* interface and registers an instance with the SAX parser using
* the parser's setDTDHandler method. The parser uses the
* instance to report notation and unparsed entity declarations to
* the application.</p>
*
* <p>Note that this interface includes only those DTD events that
* the XML recommendation <em>requires</em> processors to report:
* notation and unparsed entity declarations.</p>
*
* <p>The SAX parser may report these events in any order, regardless
* of the order in which the notations and unparsed entities were
* declared; however, all DTD events must be reported after the
* document handler's startDocument event, and before the first
* startElement event.
* (If the {@link org.xml.sax.ext.LexicalHandler LexicalHandler} is
* used, these events must also be reported before the endDTD event.)
* </p>
*
* <p>It is up to the application to store the information for
* future use (perhaps in a hash table or object tree).
* If the application encounters attributes of type "NOTATION",
* "ENTITY", or "ENTITIES", it can use the information that it
* obtained through this interface to find the entity and/or
* notation corresponding with the attribute value.</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.XMLReader#setDTDHandler
*/
public interface DTDHandler {
/**
* Receive notification of a notation declaration event.
*
* <p>It is up to the application to record the notation for later
* reference, if necessary;
* notations may appear as attribute values and in unparsed entity
* declarations, and are sometime used with processing instruction
* target names.</p>
*
* <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
* parser must resolve it fully before passing it to the
* application through this event.</p>
*
* <p>There is no guarantee that the notation declaration will be
* reported before any unparsed entities that use it.</p>
*
* @param name The notation name.
* @param publicId The notation's public identifier, or null if
* none was given.
* @param systemId The notation's system identifier, or null if
* none was given.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #unparsedEntityDecl
* @see org.xml.sax.Attributes
*/
public abstract void notationDecl (String name,
String publicId,
String systemId)
throws SAXException;
/**
* Receive notification of an unparsed entity declaration event.
*
* <p>Note that the notation name corresponds to a notation
* reported by the {@link #notationDecl notationDecl} event.
* It is up to the application to record the entity for later
* reference, if necessary;
* unparsed entities may appear as attribute values.
* </p>
*
* <p>If the system identifier is a URL, the parser must resolve it
* fully before passing it to the application.</p>
*
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @param name The unparsed entity's name.
* @param publicId The entity's public identifier, or null if none
* was given.
* @param systemId The entity's system identifier.
* @param notationName The name of the associated notation.
* @see #notationDecl
* @see org.xml.sax.Attributes
*/
public abstract void unparsedEntityDecl (String name,
String publicId,
String systemId,
String notationName)
throws SAXException;
}
// end of DTDHandler.java
// SAX document handler.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: DocumentHandler.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Receive notification of general document events.
*
* <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 was the main event-handling interface for SAX1; in
* SAX2, it has been replaced by {@link org.xml.sax.ContentHandler
* ContentHandler}, which provides Namespace support and reporting
* of skipped entities. This interface is included in SAX2 only
* to support legacy SAX1 applications.</p>
*
* <p>The order of events in this interface is very important, and
* mirrors the order of information in the document itself. For
* example, all of an element's content (character data, processing
* instructions, and/or subelements) will appear, in order, between
* the startElement event and the corresponding endElement event.</p>
*
* <p>Application writers who do not want to implement the entire
* interface can derive a class from HandlerBase, which implements
* the default functionality; parser writers can instantiate
* HandlerBase to obtain a default handler. The application can find
* the location of any document event using the Locator interface
* supplied by the Parser through the setDocumentLocator method.</p>
*
* @deprecated This interface has been replaced by the SAX2
* {@link org.xml.sax.ContentHandler ContentHandler}
* interface, which includes Namespace support.
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.Parser#setDocumentHandler
* @see org.xml.sax.Locator
* @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
* required) to supply a locator: if it does so, it must supply
* the locator to the application by invoking this method before
* invoking any of the other methods in the DocumentHandler
* interface.</p>
*
* <p>The locator allows the application to determine the end
* position of any document-related event, even if the parser is
* not reporting an error. Typically, the application will
* use this information for reporting its own errors (such as
* character content that does not match an application's
* business rules). The information returned by the locator
* is probably not sufficient for use with a search engine.</p>
*
* <p>Note that the locator will return correct information only
* during the invocation of the events in this interface. The
* application should not attempt to use it at any other time.</p>
*
* @param locator An object that can return the location of
* any SAX document event.
* @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
* other methods in this interface or in DTDHandler (except for
* setDocumentLocator).</p>
*
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
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
* be the last method invoked during the parse. The parser shall
* not invoke this method until it has either abandoned parsing
* (because of an unrecoverable error) or reached the end of
* input.</p>
*
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
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
* element in the XML document; there will be a corresponding
* endElement() event for every startElement() event (even when the
* element is empty). All of the element's content will be
* reported, in order, before the corresponding endElement()
* event.</p>
*
* <p>If the element name has a namespace prefix, the prefix will
* still be attached. Note that the attribute list provided will
* contain only attributes with explicit values (specified or
* defaulted): #IMPLIED attributes will be omitted.</p>
*
* @param name The element type name.
* @param atts The attributes attached to the element, if any.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #endElement
* @see org.xml.sax.AttributeList
*/
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
* element in the XML document; there will be a corresponding
* startElement() event for every endElement() event (even when the
* element is empty).</p>
*
* <p>If the element name has a namespace prefix, the prefix will
* still be attached to the name.</p>
*
* @param name The element type name
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
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
* character data. SAX parsers may return all contiguous character
* data in a single chunk, or they may split it into several
* 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>
*
* <p>The application must not attempt to read from the array
* outside of the specified range.</p>
*
* <p>Note that some parsers will report whitespace using the
* ignorableWhitespace() method rather than this one (validating
* parsers must do so).</p>
*
* @param ch The characters from the XML document.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #ignorableWhitespace
* @see org.xml.sax.Locator
*/
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
* of ignorable whitespace (see the W3C XML 1.0 recommendation,
* section 2.10): non-validating parsers may also use this method
* if they are capable of parsing and using content models.</p>
*
* <p>SAX parsers may return all contiguous whitespace in a single
* chunk, or they may split it into several 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>
*
* <p>The application must not attempt to read from the array
* outside of the specified range.</p>
*
* @param ch The characters from the XML document.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #characters
*/
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
* instruction found: note that processing instructions may occur
* before or after the main document element.</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)
* using this method.</p>
*
* @param target The processing instruction target.
* @param data The processing instruction data, or null if
* none was supplied.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
public abstract void processingInstruction (String target, String data)
throws SAXException;
}
// end of DocumentHandler.java
// SAX entity resolver.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: EntityResolver.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
import java.io.IOException;
/**
* Basic interface for resolving entities.
*
* <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>If a SAX application needs to implement customized handling
* for external entities, it must implement this interface and
* register an instance with the SAX driver using the
* {@link org.xml.sax.XMLReader#setEntityResolver setEntityResolver}
* method.</p>
*
* <p>The XML reader will then allow the application to intercept any
* external entities (including the external DTD subset and external
* parameter entities, if any) before including them.</p>
*
* <p>Many SAX applications will not need to implement this interface,
* but it will be especially useful for applications that build
* XML documents from databases or other specialised input sources,
* or for applications that use URI types other than URLs.</p>
*
* <p>The following resolver would provide the application
* with a special character stream for the entity with the system
* identifier "http://www.myhost.com/today":</p>
*
* <pre>
* import org.xml.sax.EntityResolver;
* import org.xml.sax.InputSource;
*
* public class MyResolver implements EntityResolver {
* public InputSource resolveEntity (String publicId, String systemId)
* {
* if (systemId.equals("http://www.myhost.com/today")) {
* // return a special input source
* MyReader reader = new MyReader();
* 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
* (possibly by using the public identifier).</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.XMLReader#setEntityResolver
* @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
* entity except the top-level document entity. Such entities include
* the external DTD subset and external parameter entities referenced
* within the DTD (in either case, only if the parser reads external
* parameter entities), and external general entities referenced
* within the document element (if the parser reads external general
* entities). The application may request that the parser locate
* the entity itself, that it use an alternative URI, or that it
* use data provided by the application (as a character or byte
* input stream).</p>
*
* <p>Application writers can use this method to redirect external
* system identifiers to secure and/or local URIs, to look up
* public identifiers in a catalogue, or to read an entity from a
* database or other input source (including, for example, a dialog
* box). Neither XML nor SAX specifies a preferred policy for using
* public or system IDs to resolve resources. However, SAX specifies
* how to interpret any InputSource returned by this method, and that
* if none is returned, then the system ID will be dereferenced as
* a URL. </p>
*
* <p>If the system identifier is a URL, the SAX parser must
* resolve it fully before reporting it to the application.</p>
*
* @param publicId The public identifier of the external entity
* being referenced, or null if none was supplied.
* @param systemId The system identifier of the external entity
* being referenced.
* @return An InputSource object describing the new input source,
* or null to request that the parser open a regular
* URI connection to the system identifier.
* @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
* 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.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: ErrorHandler.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Basic interface for SAX error handlers.
*
* <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>If a SAX application needs to implement customized error
* handling, it must implement this interface and then register an
* instance with the XML reader using the
* {@link org.xml.sax.XMLReader#setErrorHandler setErrorHandler}
* method. The parser will then report all errors and warnings
* through this interface.</p>
*
* <p><strong>WARNING:</strong> If an application does <em>not</em>
* register an ErrorHandler, XML parsing errors will go unreported,
* except that <em>SAXParseException</em>s will be thrown for fatal errors.
* In order to detect validity errors, an ErrorHandler that does something
* with {@link #error error()} calls must be registered.</p>
*
* <p>For XML processing errors, a SAX driver must use this interface
* in preference to throwing an exception: it is up to the application
* to decide whether to throw an exception for different types of
* errors and warnings. Note, however, that there is no requirement that
* the parser continue to report additional errors after a call to
* {@link #fatalError fatalError}. In other words, a SAX driver class
* may throw an exception after reporting any fatalError.
* Also parsers may throw appropriate exceptions for non-XML errors.
* For example, {@link XMLReader#parse XMLReader.parse()} would throw
* an IOException for errors accessing entities or the document.</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1+ (sax2r3pre1)
* @see org.xml.sax.XMLReader#setErrorHandler
* @see org.xml.sax.SAXParseException
*/
public interface ErrorHandler {
/**
* Receive notification of a warning.
*
* <p>SAX parsers will use this method to report conditions that
* are not errors or fatal errors as defined by the XML
* recommendation. The default behaviour is to take no
* action.</p>
*
* <p>The SAX parser must continue to provide normal parsing events
* after invoking this method: it should still be possible for the
* application to process the document through to the end.</p>
*
* <p>Filters may use this method to report other, non-XML warnings
* as well.</p>
*
* @param exception The warning information encapsulated in a
* SAX parse exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see org.xml.sax.SAXParseException
*/
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
* of the W3C XML 1.0 Recommendation. For example, a validating
* parser would use this callback to report the violation of a
* validity constraint. The default behaviour is to take no
* action.</p>
*
* <p>The SAX parser must continue to provide normal parsing
* events after invoking this method: it should still be possible
* for the application to process the document through to the end.
* If the application cannot do so, then the parser should report
* a fatal error even if the XML recommendation does not require
* it to do so.</p>
*
* <p>Filters may use this method to report other, non-XML errors
* as well.</p>
*
* @param exception The error information encapsulated in a
* SAX parse exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see org.xml.sax.SAXParseException
*/
public abstract void error (SAXParseException exception)
throws SAXException;
/**
* Receive notification of a non-recoverable error.
*
* <p><strong>There is an apparent contradiction between the
* documentation for this method and the documentation for {@link
* org.xml.sax.ContentHandler#endDocument}. Until this ambiguity
* is resolved in a future major release, clients should make no
* assumptions about whether endDocument() will or will not be
* invoked when the parser has reported a fatalError() or thrown
* an exception.</strong></p>
*
* <p>This corresponds to the definition of "fatal error" in
* section 1.2 of the W3C XML 1.0 Recommendation. For example, a
* parser would use this callback to report the violation of a
* well-formedness constraint.</p>
*
* <p>The application must assume that the document is unusable
* after the parser has invoked this method, and should continue
* (if at all) only for the sake of collecting additional error
* messages: in fact, SAX parsers are free to stop reporting any
* other events once this method has been invoked.</p>
*
* @param exception The error information encapsulated in a
* SAX parse exception.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see org.xml.sax.SAXParseException
*/
public abstract void fatalError (SAXParseException exception)
throws SAXException;
}
// end of ErrorHandler.java
// SAX locator interface for document events.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: Locator.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Interface for associating a SAX event with a document location.
*
* <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>If a SAX parser provides location information to the SAX
* application, it does so by implementing this interface and then
* passing an instance to the application using the content
* handler's {@link org.xml.sax.ContentHandler#setDocumentLocator
* setDocumentLocator} method. The application can use the
* object to obtain the location of any other SAX event
* in the XML source document.</p>
*
* <p>Note that the results returned by the object will be valid only
* during the scope of each callback method: the application
* will receive unpredictable results if it attempts to use the
* locator at any other time, or after parsing completes.</p>
*
* <p>SAX parsers are not required to supply a locator, but they are
* very strongly encouraged to do so. If the parser supplies a
* locator, it must do so before reporting any other document events.
* If no locator has been set by the time the application receives
* the {@link org.xml.sax.ContentHandler#startDocument startDocument}
* event, the application should assume that a locator is not
* available.</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @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
* entity or of the external parsed entity in which the markup
* triggering the event appears.</p>
*
* @return A string containing the public identifier, or
* null if none is available.
* @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
* entity or of the external parsed entity in which the markup
* triggering the event appears.</p>
*
* <p>If the system identifier is a URL, the parser must resolve it
* fully before passing it to the application. For example, a file
* name must always be provided as a <em>file:...</em> URL, and other
* kinds of relative URI are also resolved against their bases.</p>
*
* @return A string containing the system identifier, or null
* if none is available.
* @see #getPublicId
*/
public abstract String getSystemId ();
/**
* Return the line number where the current document event ends.
* Lines are delimited by line ends, which are defined in
* the XML specification.
*
* <p><strong>Warning:</strong> The return value from the method
* is intended only as an approximation for the sake of diagnostics;
* it is not intended to provide sufficient information
* to edit the character content of the original XML document.
* In some cases, these "line" numbers match what would be displayed
* as columns, and in others they may not match the source text
* due to internal entity expansion. </p>
*
* <p>The return value is an approximation of the line number
* 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
* of the first character after the text associated with the document
* event. The first line is line 1.</p>
*
* @return The line number, or -1 if none is available.
* @see #getColumnNumber
*/
public abstract int getLineNumber ();
/**
* Return the column number where the current document event ends.
* This is one-based number of Java <code>char</code> values since
* the last line end.
*
* <p><strong>Warning:</strong> The return value from the method
* is intended only as an approximation for the sake of diagnostics;
* it is not intended to provide sufficient information
* to edit the character content of the original XML document.
* For example, when lines contain combining character sequences, wide
* characters, surrogate pairs, or bi-directional text, the value may
* not correspond to the column in a text editor's display. </p>
*
* <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>
*
* <p>If possible, the SAX driver should provide the line position
* 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.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: Parser.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
import java.io.IOException;
import java.util.Locale;
/**
* Basic interface for SAX (Simple API for XML) parsers.
*
* <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 was the main event supplier interface for SAX1; it has
* been replaced in SAX2 by {@link org.xml.sax.XMLReader XMLReader},
* which includes Namespace support and sophisticated configurability
* and extensibility.</p>
*
* <p>All SAX1 parsers must implement this basic interface: it allows
* applications to register handlers for different types of events
* and to initiate a parse from a URI, or a character stream.</p>
*
* <p>All SAX1 parsers must also implement a zero-argument constructor
* (though other constructors are also allowed).</p>
*
* <p>SAX1 parsers are reusable but not re-entrant: the application
* may reuse a parser object (possibly with a different input source)
* once the first parse has completed successfully, but it may not
* invoke the parse() methods recursively within a parse.</p>
*
* @deprecated This interface has been replaced by the SAX2
* {@link org.xml.sax.XMLReader XMLReader}
* interface, which includes Namespace support.
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.EntityResolver
* @see org.xml.sax.DTDHandler
* @see org.xml.sax.DocumentHandler
* @see org.xml.sax.ErrorHandler
* @see org.xml.sax.HandlerBase
* @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
* and warnings; if they cannot support the requested locale,
* however, they must throw a SAX exception. Applications may
* not request a locale change in the middle of a parse.</p>
*
* @param locale A Java Locale object.
* @exception org.xml.sax.SAXException Throws an exception
* (using the previous or default locale) if the
* requested locale is not supported.
* @see org.xml.sax.SAXException
* @see org.xml.sax.SAXParseException
*/
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
* SAX parser will resolve system identifiers and open connections
* to entities itself (this is the default behaviour implemented in
* HandlerBase).</p>
*
* <p>Applications may register a new or different entity resolver
* in the middle of a parse, and the SAX parser must begin using
* the new resolver immediately.</p>
*
* @param resolver The object for resolving entities.
* @see EntityResolver
* @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
* events reported by the SAX parser will be silently
* ignored (this is the default behaviour implemented by
* HandlerBase).</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 handler immediately.</p>
*
* @param handler The DTD handler.
* @see DTDHandler
* @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
* document events reported by the SAX parser will be silently
* ignored (this is the default behaviour implemented by
* HandlerBase).</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
* handler immediately.</p>
*
* @param handler The document handler.
* @see DocumentHandler
* @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,
* all error events reported by the SAX parser will be silently
* ignored, except for fatalError, which will throw a SAXException
* (this is the default behaviour implemented by HandlerBase).</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
* handler immediately.</p>
*
* @param handler The error handler.
* @see ErrorHandler
* @see SAXException
* @see HandlerBase
*/
public abstract void setErrorHandler (ErrorHandler handler);
/**
* Parse an XML document.
*
* <p>The application can use this method to instruct the SAX parser
* to begin parsing an XML document from any valid input
* source (a character stream, a byte stream, or a URI).</p>
*
* <p>Applications may not invoke this method while a parse is in
* progress (they should create a new Parser instead for each
* additional XML document). Once a parse is complete, an
* application may reuse the same Parser object, possibly with a
* different input source.</p>
*
* @param source The input source for the top-level of the
* XML document.
* @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 org.xml.sax.InputSource
* @see #parse(java.lang.String)
* @see #setEntityResolver
* @see #setDTDHandler
* @see #setDocumentHandler
* @see #setErrorHandler
*/
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
* document from a system identifier. It is the exact
* equivalent of the following:</p>
*
* <pre>
* parse(new InputSource(systemId));
* </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 abstract void parse (String systemId)
throws SAXException, IOException;
}
// end of Parser.java
// SAX exception class.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: SAXException.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Encapsulate a general SAX error or warning.
*
* <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 can contain basic error or warning information from
* either the XML parser or the application: a parser writer or
* application writer can subclass it to provide additional
* functionality. SAX handlers may throw this exception or
* any exception subclassed from it.</p>
*
* <p>If the application needs to pass through other types of
* exceptions, it must wrap those exceptions in a SAXException
* or an exception derived from a SAXException.</p>
*
* <p>If the parser or application needs to include information about a
* specific location in an XML document, it should use the
* {@link org.xml.sax.SAXParseException SAXParseException} subclass.</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.SAXParseException
*/
public class SAXException extends Exception {
/**
* Create a new SAXException.
*/
public SAXException ()
{
super();
this.exception = null;
}
/**
* Create a new SAXException.
*
* @param message The error or warning message.
*/
public SAXException (String message) {
super(message);
this.exception = null;
}
/**
* 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>
*
* @param e The exception to be wrapped in a SAXException.
*/
public SAXException (Exception e)
{
super();
this.exception = e;
}
/**
* Create a new SAXException from an existing exception.
*
* <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.
* @param e The exception to be wrapped in a SAXException.
*/
public SAXException (String message, Exception e)
{
super(message);
this.exception = e;
}
/**
* Return a detail message for this exception.
*
* <p>If there is an embedded exception, and if the SAXException
* has no detail message of its own, this method will return
* the detail message from the embedded exception.</p>
*
* @return The error or warning message.
*/
public String getMessage ()
{
String message = super.getMessage();
if (message == null && exception != null) {
return exception.getMessage();
} else {
return message;
}
}
/**
* Return the embedded exception, if any.
*
* @return The embedded exception, or null if there is none.
*/
public Exception getException ()
{
return exception;
}
/**
* Override toString to pick up any embedded exception.
*
* @return A string representation of this exception.
*/
public String toString ()
{
if (exception != null) {
return exception.toString();
} else {
return super.toString();
}
}
//////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////////
/**
* @serial The embedded exception if tunnelling, or null.
*/
private Exception exception;
}
// end of SAXException.java
// SAXNotRecognizedException.java - unrecognized feature or value.
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: SAXNotRecognizedException.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Exception class for an unrecognized identifier.
*
* <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>An XMLReader will throw this exception when it finds an
* unrecognized feature or property identifier; SAX applications and
* extensions may use this class for other, similar purposes.</p>
*
* @since SAX 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.SAXNotSupportedException
*/
public class SAXNotRecognizedException extends SAXException
{
/**
* Default constructor.
*/
public SAXNotRecognizedException ()
{
super();
}
/**
* 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.
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: SAXNotSupportedException.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Exception class for an unsupported operation.
*
* <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>An XMLReader will throw this exception when it recognizes a
* feature or property identifier, but cannot perform the requested
* operation (setting a state or value). Other SAX2 applications and
* extensions may use this class for similar purposes.</p>
*
* @since SAX 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.SAXNotRecognizedException
*/
public class SAXNotSupportedException extends SAXException
{
/**
* Construct a new exception with no message.
*/
public SAXNotSupportedException ()
{
super();
}
/**
* 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.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: SAXParseException.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Encapsulate an XML parse error or warning.
*
* <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 exception may include information for locating the error
* in the original XML document, as if it came from a {@link Locator}
* object. Note that although the application
* will receive a SAXParseException as the argument to the handlers
* in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
* the application is not actually required to throw the exception;
* instead, it can simply read the information in it and take a
* different action.</p>
*
* <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
* SAXException}, it inherits the ability to wrap another exception.</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.SAXException
* @see org.xml.sax.Locator
* @see org.xml.sax.ErrorHandler
*/
public class SAXParseException extends SAXException {
//////////////////////////////////////////////////////////////////////
// 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
* ContentHandler} callback.</p>
*
* @param message The error or warning message.
* @param locator The locator object for the error or warning (may be
* null).
* @see org.xml.sax.Locator
*/
public SAXParseException (String message, Locator locator) {
super(message);
if (locator != null) {
init(locator.getPublicId(), locator.getSystemId(),
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
* 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
* subclass of {@link org.xml.sax.SAXException SAXException}.</p>
*
* @param message The error or warning message, or null to
* use the message from the embedded exception.
* @param locator The locator object for the error or warning (may be
* null).
* @param e Any exception.
* @see org.xml.sax.Locator
*/
public SAXParseException (String message, Locator locator,
Exception e) {
super(message, e);
if (locator != null) {
init(locator.getPublicId(), locator.getSystemId(),
locator.getLineNumber(), locator.getColumnNumber());
} else {
init(null, null, -1, -1);
}
}
/**
* Create a new SAXParseException.
*
* <p>This constructor is most useful for parser writers.</p>
*
* <p>All parameters except the message are as if
* they were provided by a {@link Locator}. For example, if the
* system identifier is a URL (including relative filename), the
* caller must resolve it fully before creating the exception.</p>
*
*
* @param message The error or warning message.
* @param publicId The public identifier of the entity that generated
* the error or warning.
* @param systemId The system identifier of the entity that generated
* the error or warning.
* @param lineNumber The line number of the end of the text that
* caused the error or warning.
* @param columnNumber The column number of the end of the text that
* cause the error or warning.
*/
public SAXParseException (String message, String publicId, String systemId,
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
* {@link org.xml.sax.SAXException SAXException}.</p>
*
* <p>All parameters except the message and exception are as if
* they were provided by a {@link Locator}. For example, if the
* system identifier is a URL (including relative filename), the
* caller must resolve it fully before creating the exception.</p>
*
* @param message The error or warning message, or null to use
* the message from the embedded exception.
* @param publicId The public identifier of the entity that generated
* the error or warning.
* @param systemId The system identifier of the entity that generated
* the error or warning.
* @param lineNumber The line number of the end of the text that
* caused the error or warning.
* @param columnNumber The column number of the end of the text that
* cause the error or warning.
* @param e Another exception to embed in this one.
*/
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,
* or null.
* @param lineNumber The line number of the error, or -1.
* @param columnNumber The column number of the error, or -1.
*/
private void init (String publicId, String systemId,
int lineNumber, int 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
*/
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 have been resolved
* fully.</p>
*
* @return A string containing the system identifier, or null
* if none is available.
* @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.
*
* <p>The first line is line 1.</p>
*
* @return An integer representing the line number, or -1
* if none is available.
* @see org.xml.sax.Locator#getLineNumber
*/
public int getLineNumber ()
{
return this.lineNumber;
}
/**
* The column number of the end of the text where the exception occurred.
*
* <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
*/
public int getColumnNumber ()
{
return this.columnNumber;
}
//////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////////
/**
* @serial The public identifier, or null.
* @see #getPublicId
*/
private String publicId;
/**
* @serial The system identifier, or null.
* @see #getSystemId
*/
private String systemId;
/**
* @serial The line number, or -1.
* @see #getLineNumber
*/
private int lineNumber;
/**
* @serial The column number, or -1.
* @see #getColumnNumber
*/
private int columnNumber;
}
// end of SAXParseException.java
// XMLFilter.java - filter SAX2 events.
// http://www.saxproject.org
// Written by David Megginson
// NO WARRANTY! This class is in the Public Domain.
// $Id: XMLFilter.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax;
/**
* Interface for an XML filter.
*
* <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>An XML filter is like an XML reader, except that it obtains its
* events from another XML reader rather than a primary source like
* an XML document or database. Filters can modify a stream of
* events as they pass on to the final application.</p>
*
* <p>The XMLFilterImpl helper class provides a convenient base
* for creating SAX2 filters, by passing on all {@link org.xml.sax.EntityResolver
* EntityResolver}, {@link org.xml.sax.DTDHandler DTDHandler},
* {@link org.xml.sax.ContentHandler ContentHandler} and {@link org.xml.sax.ErrorHandler
* ErrorHandler} events automatically.</p>
*
* @since SAX 2.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @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
* a parent reader (which may be another filter). The argument
* may not be null.</p>
*
* @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
* reader (which may be another filter). It is generally a
* bad idea to perform any operations on the parent reader
* directly: they should all pass through this filter.</p>
*
* @return The parent filter, or null if none has been set.
*/
public abstract XMLReader getParent ();
}
// end of XMLFilter.java
// Attributes2.java - extended Attributes
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: Attributes2.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import org.xml.sax.Attributes;
/**
* SAX2 extension to augment the per-attribute information
* provided though {@link Attributes}.
* If an implementation supports this extension, the attributes
* provided in {@link org.xml.sax.ContentHandler#startElement
* ContentHandler.startElement() } will implement this interface,
* and the <em>http://xml.org/sax/features/use-attributes2</em>
* feature flag will have the value <em>true</em>.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* </blockquote>
*
* <p> XMLReader implementations are not required to support this
* information, and it is not part of core-only SAX2 distributions.</p>
*
* <p>Note that if an attribute was defaulted (<em>!isSpecified()</em>)
* it will of necessity also have been declared (<em>isDeclared()</em>)
* in the DTD.
* Similarly if an attribute's type is anything except CDATA, then it
* must have been declared.
* </p>
*
* @since SAX 2.0 (extensions 1.1 alpha)
* @author David Brownell
* @version TBS
*/
public interface Attributes2 extends Attributes
{
/**
* Returns false unless the attribute was declared in the DTD.
* This helps distinguish two kinds of attributes that SAX reports
* as CDATA: ones that were declared (and hence are usually valid),
* and those that were not (and which are never valid).
*
* @param index The attribute index (zero-based).
* @return true if the attribute was declared in the DTD,
* false otherwise.
* @exception java.lang.ArrayIndexOutOfBoundsException When the
* supplied index does not identify an attribute.
*/
public boolean isDeclared (int index);
/**
* Returns false unless the attribute was declared in the DTD.
* This helps distinguish two kinds of attributes that SAX reports
* as CDATA: ones that were declared (and hence are usually valid),
* and those that were not (and which are never valid).
*
* @param qName The XML qualified (prefixed) name.
* @return true if the attribute was declared in the DTD,
* false otherwise.
* @exception java.lang.IllegalArgumentException When the
* supplied name does not identify an attribute.
*/
public boolean isDeclared (String qName);
/**
* Returns false unless the attribute was declared in the DTD.
* This helps distinguish two kinds of attributes that SAX reports
* as CDATA: ones that were declared (and hence are usually valid),
* and those that were not (and which are never valid).
*
* <p>Remember that since DTDs do not "understand" namespaces, the
* namespace URI associated with an attribute may not have come from
* the DTD. The declaration will have applied to the attribute's
* <em>qName</em>.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localName The attribute's local name.
* @return true if the attribute was declared in the DTD,
* false otherwise.
* @exception java.lang.IllegalArgumentException When the
* supplied names do not identify an attribute.
*/
public boolean isDeclared (String uri, String localName);
/**
* Returns true unless the attribute value was provided
* by DTD defaulting.
*
* @param index The attribute index (zero-based).
* @return true if the value was found in the XML text,
* false if the value was provided by DTD defaulting.
* @exception java.lang.ArrayIndexOutOfBoundsException When the
* supplied index does not identify an attribute.
*/
public boolean isSpecified (int index);
/**
* Returns true unless the attribute value was provided
* by DTD defaulting.
*
* <p>Remember that since DTDs do not "understand" namespaces, the
* namespace URI associated with an attribute may not have come from
* the DTD. The declaration will have applied to the attribute's
* <em>qName</em>.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localName The attribute's local name.
* @return true if the value was found in the XML text,
* false if the value was provided by DTD defaulting.
* @exception java.lang.IllegalArgumentException When the
* supplied names do not identify an attribute.
*/
public boolean isSpecified (String uri, String localName);
/**
* Returns true unless the attribute value was provided
* by DTD defaulting.
*
* @param qName The XML qualified (prefixed) name.
* @return true if the value was found in the XML text,
* false if the value was provided by DTD defaulting.
* @exception java.lang.IllegalArgumentException When the
* supplied name does not identify an attribute.
*/
public boolean isSpecified (String qName);
}
// Attributes2Impl.java - extended AttributesImpl
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: Attributes2Impl.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
/**
* SAX2 extension helper for additional Attributes information,
* implementing the {@link Attributes2} interface.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* </blockquote>
*
* <p>This is not part of core-only SAX2 distributions.</p>
*
* <p>The <em>specified</em> flag for each attribute will always
* be true, unless it has been set to false in the copy constructor
* or using {@link #setSpecified}.
* Similarly, the <em>declared</em> flag for each attribute will
* always be false, except for defaulted attributes (<em>specified</em>
* is false), non-CDATA attributes, or when it is set to true using
* {@link #setDeclared}.
* If you change an attribute's type by hand, you may need to modify
* its <em>declared</em> flag to match.
* </p>
*
* @since SAX 2.0 (extensions 1.1 alpha)
* @author David Brownell
* @version TBS
*/
public class Attributes2Impl extends AttributesImpl implements Attributes2
{
private boolean declared [];
private boolean specified [];
/**
* Construct a new, empty Attributes2Impl object.
*/
public Attributes2Impl () { }
/**
* Copy an existing Attributes or Attributes2 object.
* If the object implements Attributes2, values of the
* <em>specified</em> and <em>declared</em> flags for each
* attribute are copied.
* Otherwise the flag values are defaulted to assume no DTD was used,
* unless there is evidence to the contrary (such as attributes with
* type other than CDATA, which must have been <em>declared</em>).
*
* <p>This constructor is especially useful inside a
* {@link org.xml.sax.ContentHandler#startElement startElement} event.</p>
*
* @param atts The existing Attributes object.
*/
public Attributes2Impl (Attributes atts)
{
super (atts);
}
////////////////////////////////////////////////////////////////////
// Implementation of Attributes2
////////////////////////////////////////////////////////////////////
/**
* Returns the current value of the attribute's "declared" flag.
*/
// javadoc mostly from interface
public boolean isDeclared (int index)
{
if (index < 0 || index >= getLength ())
throw new ArrayIndexOutOfBoundsException (
"No attribute at index: " + index);
return declared [index];
}
/**
* Returns the current value of the attribute's "declared" flag.
*/
// javadoc mostly from interface
public boolean isDeclared (String uri, String localName)
{
int index = getIndex (uri, localName);
if (index < 0)
throw new IllegalArgumentException (
"No such attribute: local=" + localName
+ ", namespace=" + uri);
return declared [index];
}
/**
* Returns the current value of the attribute's "declared" flag.
*/
// javadoc mostly from interface
public boolean isDeclared (String qName)
{
int index = getIndex (qName);
if (index < 0)
throw new IllegalArgumentException (
"No such attribute: " + qName);
return declared [index];
}
/**
* Returns the current value of an attribute's "specified" flag.
*
* @param index The attribute index (zero-based).
* @return current flag value
* @exception java.lang.ArrayIndexOutOfBoundsException When the
* supplied index does not identify an attribute.
*/
public boolean isSpecified (int index)
{
if (index < 0 || index >= getLength ())
throw new ArrayIndexOutOfBoundsException (
"No attribute at index: " + index);
return specified [index];
}
/**
* Returns the current value of an attribute's "specified" flag.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localName The attribute's local name.
* @return current flag value
* @exception java.lang.IllegalArgumentException When the
* supplied names do not identify an attribute.
*/
public boolean isSpecified (String uri, String localName)
{
int index = getIndex (uri, localName);
if (index < 0)
throw new IllegalArgumentException (
"No such attribute: local=" + localName
+ ", namespace=" + uri);
return specified [index];
}
/**
* Returns the current value of an attribute's "specified" flag.
*
* @param qName The XML qualified (prefixed) name.
* @return current flag value
* @exception java.lang.IllegalArgumentException When the
* supplied name does not identify an attribute.
*/
public boolean isSpecified (String qName)
{
int index = getIndex (qName);
if (index < 0)
throw new IllegalArgumentException (
"No such attribute: " + qName);
return specified [index];
}
////////////////////////////////////////////////////////////////////
// Manipulators
////////////////////////////////////////////////////////////////////
/**
* Copy an entire Attributes object. The "specified" flags are
* assigned as true, and "declared" flags as false (except when
* an attribute's type is not CDATA),
* unless the object is an Attributes2 object.
* In that case those flag values are all copied.
*
* @see AttributesImpl#setAttributes
*/
public void setAttributes (Attributes atts)
{
int length = atts.getLength ();
super.setAttributes (atts);
declared = new boolean [length];
specified = new boolean [length];
if (atts instanceof Attributes2) {
Attributes2 a2 = (Attributes2) atts;
for (int i = 0; i < length; i++) {
declared [i] = a2.isDeclared (i);
specified [i] = a2.isSpecified (i);
}
} else {
for (int i = 0; i < length; i++) {
declared [i] = !"CDATA".equals (atts.getType (i));
specified [i] = true;
}
}
}
/**
* Add an attribute to the end of the list, setting its
* "specified" flag to true. To set that flag's value
* to false, use {@link #setSpecified}.
*
* <p>Unless the attribute <em>type</em> is CDATA, this attribute
* is marked as being declared in the DTD. To set that flag's value
* to true for CDATA attributes, use {@link #setDeclared}.
*
* @see AttributesImpl#addAttribute
*/
public void addAttribute (String uri, String localName, String qName,
String type, String value)
{
super.addAttribute (uri, localName, qName, type, value);
int length = getLength ();
if (length < specified.length) {
boolean newFlags [];
newFlags = new boolean [length];
System.arraycopy (declared, 0, newFlags, 0, declared.length);
declared = newFlags;
newFlags = new boolean [length];
System.arraycopy (specified, 0, newFlags, 0, specified.length);
specified = newFlags;
}
specified [length - 1] = true;
declared [length - 1] = !"CDATA".equals (type);
}
// javadoc entirely from superclass
public void removeAttribute (int index)
{
int origMax = getLength () - 1;
super.removeAttribute (index);
if (index != origMax) {
System.arraycopy (declared, index + 1, declared, index,
origMax - index);
System.arraycopy (specified, index + 1, specified, index,
origMax - index);
}
}
/**
* Assign a value to the "declared" flag of a specific attribute.
* This is normally needed only for attributes of type CDATA,
* including attributes whose type is changed to or from CDATA.
*
* @param index The index of the attribute (zero-based).
* @param value The desired flag value.
* @exception java.lang.ArrayIndexOutOfBoundsException When the
* supplied index does not identify an attribute.
* @see #setType
*/
public void setDeclared (int index, boolean value)
{
if (index < 0 || index >= getLength ())
throw new ArrayIndexOutOfBoundsException (
"No attribute at index: " + index);
declared [index] = value;
}
/**
* Assign a value to the "specified" flag of a specific attribute.
* This is the only way this flag can be cleared, except clearing
* by initialization with the copy constructor.
*
* @param index The index of the attribute (zero-based).
* @param value The desired flag value.
* @exception java.lang.ArrayIndexOutOfBoundsException When the
* supplied index does not identify an attribute.
*/
public void setSpecified (int index, boolean value)
{
if (index < 0 || index >= getLength ())
throw new ArrayIndexOutOfBoundsException (
"No attribute at index: " + index);
specified [index] = value;
}
}
// DeclHandler.java - Optional handler for DTD declaration events.
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: DeclHandler.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import org.xml.sax.SAXException;
/**
* SAX2 extension handler for DTD declaration events.
*
* <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 is an optional extension handler for SAX2 to provide more
* complete information about DTD declarations in an XML document.
* XML readers are not required to recognize this handler, and it
* is not part of core-only SAX2 distributions.</p>
*
* <p>Note that data-related DTD declarations (unparsed entities and
* notations) are already reported through the {@link
* org.xml.sax.DTDHandler DTDHandler} interface.</p>
*
* <p>If you are using the declaration handler together with a lexical
* handler, all of the events will occur between the
* {@link org.xml.sax.ext.LexicalHandler#startDTD startDTD} and the
* {@link org.xml.sax.ext.LexicalHandler#endDTD endDTD} events.</p>
*
* <p>To set the DeclHandler for an XML reader, use the
* {@link org.xml.sax.XMLReader#setProperty setProperty} method
* with the property name
* <code>http://xml.org/sax/properties/declaration-handler</code>
* and an object implementing this interface (or null) as the value.
* If the reader does not report declaration events, it will throw a
* {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
* when you attempt to register the handler.</p>
*
* @since SAX 2.0 (extensions 1.0)
* @author David Megginson
* @version 2.0.1 (sax2r2)
*/
public interface DeclHandler
{
/**
* Report an element type declaration.
*
* <p>The content model will consist of the string "EMPTY", the
* string "ANY", or a parenthesised group, optionally followed
* by an occurrence indicator. The model will be normalized so
* that all parameter entities are fully resolved and all whitespace
* is removed,and will include the enclosing parentheses. Other
* normalization (such as removing redundant parentheses or
* simplifying occurrence indicators) is at the discretion of the
* parser.</p>
*
* @param name The element type name.
* @param model The content model as a normalized string.
* @exception SAXException The application may raise an exception.
*/
public abstract void elementDecl (String name, String model)
throws SAXException;
/**
* Report an attribute type declaration.
*
* <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", a parenthesized token group with
* the separator "|" and all whitespace removed, or the word
* "NOTATION" followed by a space followed by a parenthesized
* token group with all whitespace removed.</p>
*
* <p>The value will be the value as reported to applications,
* appropriately normalized and with entity and character
* references expanded. </p>
*
* @param eName The name of the associated element.
* @param aName The name of the attribute.
* @param type A string representing the attribute type.
* @param mode A string representing the attribute defaulting mode
* ("#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.
* @exception SAXException The application may raise an exception.
*/
public abstract void attributeDecl (String eName,
String aName,
String type,
String mode,
String value)
throws SAXException;
/**
* Report an internal entity declaration.
*
* <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>
*
* @param name The name of the entity. If it is a parameter
* entity, the name will begin with '%'.
* @param value The replacement text of the entity.
* @exception SAXException The application may raise an exception.
* @see #externalEntityDecl
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public abstract void internalEntityDecl (String name, String value)
throws SAXException;
/**
* Report a parsed external entity declaration.
*
* <p>Only the effective (first) declaration for each entity
* will be reported.</p>
*
* <p>If the system identifier is a URL, the parser must resolve it
* fully before passing it to the application.</p>
*
* @param name The name of the entity. If it is a parameter
* entity, the name will begin with '%'.
* @param publicId The entity's public identifier, or null if none
* was given.
* @param systemId The entity's system identifier.
* @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
// DefaultHandler2.java - extended DefaultHandler
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: DefaultHandler2.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import java.io.IOException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* This class extends the SAX2 base handler class to support the
* SAX2 {@link LexicalHandler}, {@link DeclHandler}, and
* {@link EntityResolver2} extensions. Except for overriding the
* original SAX1 {@link DefaultHandler#resolveEntity resolveEntity()}
* method the added handler methods just return. Subclassers may
* override everything on a method-by-method basis.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* </blockquote>
*
* <p> <em>Note:</em> this class might yet learn that the
* <em>ContentHandler.setDocumentLocator()</em> call might be passed a
* {@link Locator2} object, and that the
* <em>ContentHandler.startElement()</em> call might be passed a
* {@link Attributes2} object.
*
* @since SAX 2.0 (extensions 1.1 alpha)
* @author David Brownell
* @version TBS
*/
public class DefaultHandler2 extends DefaultHandler
implements LexicalHandler, DeclHandler, EntityResolver2
{
/** Constructs a handler which ignores all parsing events. */
public DefaultHandler2 () { }
// SAX2 ext-1.0 LexicalHandler
public void startCDATA ()
throws SAXException
{}
public void endCDATA ()
throws SAXException
{}
public void startDTD (String name, String publicId, String systemId)
throws SAXException
{}
public void endDTD ()
throws SAXException
{}
public void startEntity (String name)
throws SAXException
{}
public void endEntity (String name)
throws SAXException
{}
public void comment (char ch [], int start, int length)
throws SAXException
{ }
// SAX2 ext-1.0 DeclHandler
public void attributeDecl (String eName, String aName,
String type, String mode, String value)
throws SAXException
{}
public void elementDecl (String name, String model)
throws SAXException
{}
public void externalEntityDecl (String name,
String publicId, String systemId)
throws SAXException
{}
public void internalEntityDecl (String name, String value)
throws SAXException
{}
// SAX2 ext-1.1 EntityResolver2
/**
* Tells the parser that if no external subset has been declared
* in the document text, none should be used.
*/
public InputSource getExternalSubset (String name, String baseURI)
throws SAXException, IOException
{ return null; }
/**
* Tells the parser to resolve the systemId against the baseURI
* and read the entity text from that resulting absolute URI.
* Note that because the older
* {@link DefaultHandler#resolveEntity DefaultHandler.resolveEntity()},
* method is overridden to call this one, this method may sometimes
* be invoked with null <em>name</em> and <em>baseURI</em>, and
* with the <em>systemId</em> already absolutized.
*/
public InputSource resolveEntity (String name, String publicId,
String baseURI, String systemId)
throws SAXException, IOException
{ return null; }
// SAX1 EntityResolver
/**
* Invokes
* {@link EntityResolver2#resolveEntity EntityResolver2.resolveEntity()}
* with null entity name and base URI.
* You only need to override that method to use this class.
*/
public InputSource resolveEntity (String publicId, String systemId)
throws SAXException, IOException
{ return resolveEntity (null, publicId, null, systemId); }
}
// EntityResolver2.java - Extended SAX entity resolver.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: EntityResolver2.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import java.io.IOException;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;
/**
* Extended interface for mapping external entity references to input
* sources, or providing a missing external subset. The
* {@link XMLReader#setEntityResolver XMLReader.setEntityResolver()} method
* is used to provide implementations of this interface to parsers.
* When a parser uses the methods in this interface, the
* {@link EntityResolver2#resolveEntity EntityResolver2.resolveEntity()}
* method (in this interface) is used <em>instead of</em> the older (SAX 1.0)
* {@link EntityResolver#resolveEntity EntityResolver.resolveEntity()} method.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* </blockquote>
*
* <p>If a SAX application requires the customized handling which this
* interface defines for external entities, it must ensure that it uses
* an XMLReader with the
* <em>http://xml.org/sax/features/use-entity-resolver2</em> feature flag
* set to <em>true</em> (which is its default value when the feature is
* recognized). If that flag is unrecognized, or its value is false,
* or the resolver does not implement this interface, then only the
* {@link EntityResolver} method will be used.
* </p>
*
* <p>That supports three categories of application that modify entity
* resolution. <em>Old Style</em> applications won't know about this interface;
* they will provide an EntityResolver.
* <em>Transitional Mode</em> provide an EntityResolver2 and automatically
* get the benefit of its methods in any systems (parsers or other tools)
* supporting it, due to polymorphism.
* Both <em>Old Style</em> and <em>Transitional Mode</em> applications will
* work with any SAX2 parser.
* <em>New style</em> applications will fail to run except on SAX2 parsers
* that support this particular feature.
* They will insist that feature flag have a value of "true", and the
* EntityResolver2 implementation they provide might throw an exception
* if the original SAX 1.0 style entity resolution method is invoked.
* </p>
*
* @see org.xml.sax.XMLReader#setEntityResolver
*
* @since SAX 2.0 (extensions 1.1 alpha)
* @author David Brownell
* @version TBD
*/
public interface EntityResolver2 extends EntityResolver
{
/**
* Allows applications to provide an external subset for documents
* that don't explicitly define one. Documents with DOCTYPE declarations
* that omit an external subset can thus augment the declarations
* available for validation, entity processing, and attribute processing
* (normalization, defaulting, and reporting types including ID).
* This augmentation is reported
* through the {@link LexicalHandler#startDTD startDTD()} method as if
* the document text had originally included the external subset;
* this callback is made before any internal subset data or errors
* are reported.</p>
*
* <p>This method can also be used with documents that have no DOCTYPE
* declaration. When the root element is encountered,
* but no DOCTYPE declaration has been seen, this method is
* invoked. If it returns a value for the external subset, that root
* element is declared to be the root element, giving the effect of
* splicing a DOCTYPE declaration at the end the prolog of a document
* that could not otherwise be valid. The sequence of parser callbacks
* in that case logically resembles this:</p>
*
* <pre>
* ... comments and PIs from the prolog (as usual)
* startDTD ("rootName", source.getPublicId (), source.getSystemId ());
* startEntity ("[dtd]");
* ... declarations, comments, and PIs from the external subset
* endEntity ("[dtd]");
* endDTD ();
* ... then the rest of the document (as usual)
* startElement (..., "rootName", ...);
* </pre>
*
* <p>Note that the InputSource gets no further resolution.
* Implementations of this method may wish to invoke
* {@link #resolveEntity resolveEntity()} to gain benefits such as use
* of local caches of DTD entities. Also, this method will never be
* used by a (non-validating) processor that is not including external
* parameter entities. </p>
*
* <p>Uses for this method include facilitating data validation when
* interoperating with XML processors that would always require
* undesirable network accesses for external entities, or which for
* other reasons adopt a "no DTDs" policy.
* Non-validation motives include forcing documents to include DTDs so
* that attributes are handled consistently.
* For example, an XPath processor needs to know which attibutes have
* type "ID" before it can process a widely used type of reference.</p>
*
* <p><strong>Warning:</strong> Returning an external subset modifies
* the input document. By providing definitions for general entities,
* it can make a malformed document appear to be well formed.
* </p>
*
* @param name Identifies the document root element. This name comes
* from a DOCTYPE declaration (where available) or from the actual
* root element.
* @param baseURI The document's base URI, serving as an additional
* hint for selecting the external subset. This is always an absolute
* URI, unless it is null because the XMLReader was given an InputSource
* without one.
*
* @return An InputSource object describing the new external subset
* to be used by the parser, or null to indicate that no external
* subset is provided.
*
* @exception SAXException Any SAX exception, possibly wrapping
* another exception.
* @exception IOException Probably indicating a failure to create
* a new InputStream or Reader, or an illegal URL.
*/
public InputSource getExternalSubset (String name, String baseURI)
throws SAXException, IOException;
/**
* Allows applications to map references to external entities into input
* sources, or tell the parser it should use conventional URI resolution.
* This method is only called for external entities which have been
* properly declared.
* This method provides more flexibility than the {@link EntityResolver}
* interface, supporting implementations of more complex catalogue
* schemes such as the one defined by the <a href=
"http://www.oasis-open.org/committees/entity/spec-2001-08-06.html"
>OASIS XML Catalogs</a> specification.</p>
*
* <p>Parsers configured to use this resolver method will call it
* to determine the input source to use for any external entity
* being included because of a reference in the XML text.
* That excludes the document entity, and any external entity returned
* by {@link #getExternalSubset getExternalSubset()}.
* When a (non-validating) processor is configured not to include
* a class of entities (parameter or general) through use of feature
* flags, this method is not invoked for such entities. </p>
*
* <p>Note that the entity naming scheme used here is the same one
* used in the {@link LexicalHandler}, or in the {@link
org.xml.sax.ContentHandler#skippedEntity
ContentHandler.skippedEntity()}
* method. </p>
*
* @param name Identifies the external entity being resolved.
* Either "[dtd]" for the external subset, or a name starting
* with "%" to indicate a parameter entity, or else the name of
* a general entity. This is never null when invoked by a SAX2
* parser.
* @param publicId The public identifier of the external entity being
* referenced (normalized as required by the XML specification), or
* null if none was supplied.
* @param baseURI The URI with respect to which relative systemIDs
* are interpreted. This is always an absolute URI, unless it is
* null (likely because the XMLReader was given an InputSource without
* one). This URI is defined by the XML specification to be the one
* associated with the "&lt;" starting the relevant declaration.
* @param systemId The system identifier of the external entity
* being referenced; either a relative or absolute URI.
* This is never null when invoked by a SAX2 parser; only declared
* entities, and any external subset, are resolved by such parsers.
*
* @return An InputSource object describing the new input source to
* be used by the parser. Returning null directs the parser to
* resolve the system ID against the base URI and open a connection
* to resulting URI.
*
* @exception SAXException Any SAX exception, possibly wrapping
* another exception.
* @exception IOException Probably indicating a failure to create
* a new InputStream or Reader, or an illegal URL.
*/
public InputSource resolveEntity (
String name,
String publicId,
String baseURI,
String systemId
) throws SAXException, IOException;
}
// LexicalHandler.java - optional handler for lexical parse events.
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: LexicalHandler.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import org.xml.sax.SAXException;
/**
* SAX2 extension handler for lexical events.
*
* <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 is an optional extension handler for SAX2 to provide
* lexical information about an XML document, such as comments
* and CDATA section boundaries.
* XML readers are not required to recognize this handler, and it
* is not part of core-only SAX2 distributions.</p>
*
* <p>The events in the lexical handler apply to the entire document,
* not just to the document element, and all lexical handler events
* must appear between the content handler's startDocument and
* endDocument events.</p>
*
* <p>To set the LexicalHandler for an XML reader, use the
* {@link org.xml.sax.XMLReader#setProperty setProperty} method
* with the property name
* <code>http://xml.org/sax/properties/lexical-handler</code>
* and an object implementing this interface (or null) as the value.
* If the reader does not report lexical events, it will throw a
* {@link org.xml.sax.SAXNotRecognizedException SAXNotRecognizedException}
* when you attempt to register the handler.</p>
*
* @since SAX 2.0 (extensions 1.0)
* @author David Megginson
* @version 2.0.1 (sax2r2)
*/
public interface LexicalHandler
{
/**
* Report the start of DTD declarations, if any.
*
* <p>This method is intended to report the beginning of the
* DOCTYPE declaration; if the document has no DOCTYPE declaration,
* this method will not be invoked.</p>
*
* <p>All declarations reported through
* {@link org.xml.sax.DTDHandler DTDHandler} or
* {@link org.xml.sax.ext.DeclHandler DeclHandler} events must appear
* between the startDTD and {@link #endDTD endDTD} events.
* Declarations are assumed to belong to the internal DTD subset
* unless they appear between {@link #startEntity startEntity}
* and {@link #endEntity endEntity} events. Comments and
* processing instructions from the DTD should also be reported
* between the startDTD and endDTD events, in their original
* order of (logical) occurrence; they are not required to
* appear in their correct locations relative to DTDHandler
* or DeclHandler events, however.</p>
*
* <p>Note that the start/endDTD events will appear within
* the start/endDocument events from ContentHandler and
* before the first
* {@link org.xml.sax.ContentHandler#startElement startElement}
* event.</p>
*
* @param name The document type name.
* @param publicId The declared public identifier for the
* external DTD subset, or null if none was declared.
* @param systemId The declared system identifier for the
* external DTD subset, or null if none was declared.
* (Note that this is not resolved against the document
* base URI.)
* @exception SAXException The application may raise an
* exception.
* @see #endDTD
* @see #startEntity
*/
public abstract void startDTD (String name, String publicId,
String systemId)
throws SAXException;
/**
* Report the end of DTD declarations.
*
* <p>This method is intended to report the end of the
* DOCTYPE declaration; if the document has no DOCTYPE declaration,
* this method will not be invoked.</p>
*
* @exception SAXException The application may raise an exception.
* @see #startDTD
*/
public abstract void endDTD ()
throws SAXException;
/**
* Report the beginning of some internal and external XML entities.
*
* <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
* <code
* >http://xml.org/sax/features/lexical-handler/parameter-entities</code>
* feature to query or control the reporting of parameter entities.</p>
*
* <p>General entities are reported with their regular names,
* parameter entities have '%' prepended to their names, and
* the external DTD subset has the pseudo-entity name "[dtd]".</p>
*
* <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
* {@link org.xml.sax.ext.DeclHandler DeclHandler} or
* {@link org.xml.sax.DTDHandler DTDHandler} be properly ordered.</p>
*
* <p>Note that skipped entities will be reported through the
* {@link org.xml.sax.ContentHandler#skippedEntity skippedEntity}
* event, which is part of the ContentHandler interface.</p>
*
* <p>Because of the streaming event model that SAX uses, some
* entity boundaries cannot be reported under any
* circumstances:</p>
*
* <ul>
* <li>general entities within attribute values</li>
* <li>parameter entities within declarations</li>
* </ul>
*
* <p>These will be silently expanded, with no indication of where
* the original entity boundaries were.</p>
*
* <p>Note also that the boundaries of character references (which
* are not really entities anyway) are not reported.</p>
*
* <p>All start/endEntity events must be properly nested.
*
* @param name The name of the entity. If it is a parameter
* entity, the name will begin with '%', and if it is the
* external DTD subset, it will be "[dtd]".
* @exception SAXException The application may raise an exception.
* @see #endEntity
* @see org.xml.sax.ext.DeclHandler#internalEntityDecl
* @see org.xml.sax.ext.DeclHandler#externalEntityDecl
*/
public abstract void startEntity (String name)
throws SAXException;
/**
* Report the end of an entity.
*
* @param name The name of the entity that is ending.
* @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
// Locator2.java - extended Locator
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: Locator2.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import org.xml.sax.Locator;
/**
* SAX2 extension to augment the entity information provided
* though a {@link Locator}.
* If an implementation supports this extension, the Locator
* provided in {@link org.xml.sax.ContentHandler#setDocumentLocator
* ContentHandler.setDocumentLocator() } will implement this
* interface, and the
* <em>http://xml.org/sax/features/use-locator2</em> feature
* flag will have the value <em>true</em>.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* </blockquote>
*
* <p> XMLReader implementations are not required to support this
* information, and it is not part of core-only SAX2 distributions.</p>
*
* @since SAX 2.0 (extensions 1.1 alpha)
* @author David Brownell
* @version TBS
*/
public interface Locator2 extends Locator
{
/**
* Returns the version of XML used for the entity. This will
* normally be the identifier from the current entity's
* <em>&lt;?xml&nbsp;version='...'&nbsp;...?&gt;</em> declaration,
* or be defaulted by the parser.
*
* @return Identifier for the XML version being used to interpret
* the entity's text, or null if that information is not yet
* available in the current parsing state.
*/
public String getXMLVersion ();
/**
* Returns the name of the character encoding for the entity.
* If the encoding was declared externally (for example, in a MIME
* Content-Type header), that will be the name returned. Else if there
* was an <em>&lt;?xml&nbsp;...encoding='...'?&gt;</em> declaration at
* the start of the document, that encoding name will be returned.
* Otherwise the encoding will been inferred (normally to be UTF-8, or
* some UTF-16 variant), and that inferred name will be returned.
*
* <p>When an {@link org.xml.sax.InputSource InputSource} is used
* to provide an entity's character stream, this method returns the
* encoding provided in that input stream.
*
* <p> Note that some recent W3C specifications require that text
* in some encodings be normalized, using Unicode Normalization
* Form C, before processing. Such normalization must be performed
* by applications, and would normally be triggered based on the
* value returned by this method.
*
* <p> Encoding names may be those used by the underlying JVM,
* and comparisons should be case-insensitive.
*
* @return Name of the character encoding being used to interpret
* * the entity's text, or null if this was not provided for a *
* character stream passed through an InputSource or is otherwise
* not yet available in the current parsing state.
*/
public String getEncoding ();
}
// Locator2Impl.java - extended LocatorImpl
// http://www.saxproject.org
// Public Domain: no warranty.
// $Id: Locator2Impl.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.ext;
import org.xml.sax.Locator;
import org.xml.sax.helpers.LocatorImpl;
/**
* SAX2 extension helper for holding additional Entity information,
* implementing the {@link Locator2} interface.
*
* <blockquote>
* <em>This module, both source code and documentation, is in the
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
* </blockquote>
*
* <p> This is not part of core-only SAX2 distributions.</p>
*
* @since SAX 2.0.2
* @author David Brownell
* @version TBS
*/
public class Locator2Impl extends LocatorImpl implements Locator2
{
private String encoding;
private String version;
/**
* Construct a new, empty Locator2Impl object.
* This will not normally be useful, since the main purpose
* of this class is to make a snapshot of an existing Locator.
*/
public Locator2Impl () { }
/**
* Copy an existing Locator or Locator2 object.
* If the object implements Locator2, values of the
* <em>encoding</em> and <em>version</em>strings are copied,
* otherwise they set to <em>null</em>.
*
* @param locator The existing Locator object.
*/
public Locator2Impl (Locator locator)
{
super (locator);
if (locator instanceof Locator2) {
Locator2 l2 = (Locator2) locator;
version = l2.getXMLVersion ();
encoding = l2.getEncoding ();
}
}
////////////////////////////////////////////////////////////////////
// Locator2 method implementations
////////////////////////////////////////////////////////////////////
/**
* Returns the current value of the version property.
*
* @see #setXMLVersion
*/
public String getXMLVersion ()
{ return version; }
/**
* Returns the current value of the encoding property.
*
* @see #setEncoding
*/
public String getEncoding ()
{ return encoding; }
////////////////////////////////////////////////////////////////////
// Setters
////////////////////////////////////////////////////////////////////
/**
* Assigns the current value of the version property.
*
* @param version the new "version" value
* @see #getXMLVersion
*/
public void setXMLVersion (String version)
{ this.version = version; }
/**
* Assigns the current value of the encoding property.
*
* @param encoding the new "encoding" value
* @see #getEncoding
*/
public void setEncoding (String encoding)
{ this.encoding = encoding; }
}
<HTML><HEAD>
<!-- $Id: package.html,v 1.1 2004/12/23 22:38:42 mark Exp $ -->
</HEAD><BODY>
<p>
This package contains interfaces to SAX2 facilities that
conformant SAX drivers won't necessarily support.
<p>See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
for more information about SAX.</p>
<p> This package is independent of the SAX2 core, though the functionality
exposed generally needs to be implemented within a parser core.
That independence has several consequences:</p>
<ul>
<li>SAX2 drivers are <em>not</em> required to recognize these handlers.
</li>
<li>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 and classes may be added without updating SAX2 itself).</li>
<li>The new 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 behavior, or
use the helper classes found here.</li>
<li>The handlers need to be registered differently than core 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 validation systems can be cleanly layered on top
of parsers supporting the standardized SAX2 interfaces. </p>
</BODY></HTML>
// SAX default implementation for AttributeList.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: AttributeListImpl.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.helpers;
import org.xml.sax.AttributeList;
import java.util.Vector;
/**
* Default implementation for AttributeList.
*
* <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>AttributeList implements the deprecated SAX1 {@link
* org.xml.sax.AttributeList AttributeList} interface, and has been
* replaced by the new SAX2 {@link org.xml.sax.helpers.AttributesImpl
* AttributesImpl} interface.</p>
*
* <p>This class provides a convenience implementation of the SAX
* {@link org.xml.sax.AttributeList AttributeList} interface. This
* implementation is useful both for SAX parser writers, who can use
* it to provide attributes to the application, and for SAX application
* writers, who can use it to create a persistent copy of an element's
* attribute specifications:</p>
*
* <pre>
* private AttributeList myatts;
*
* public void startElement (String name, AttributeList atts)
* {
* // create a persistent copy of the attribute list
* // for use outside this method
* myatts = new AttributeListImpl(atts);
* [...]
* }
* </pre>
*
* <p>Please note that SAX parsers are not required to use this
* class to provide an implementation of AttributeList; it is
* supplied only as an optional convenience. In particular,
* parser writers are encouraged to invent more efficient
* implementations.</p>
*
* @deprecated This class implements a deprecated interface,
* {@link org.xml.sax.AttributeList AttributeList};
* that interface has been replaced by
* {@link org.xml.sax.Attributes Attributes},
* which is implemented in the
* {@link org.xml.sax.helpers.AttributesImpl
* AttributesImpl} helper class.
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @see org.xml.sax.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
* will use it to create a single, reusable attribute list that
* can be reset with the clear method between elements.</p>
*
* @see #addAttribute
* @see #clear
*/
public AttributeListImpl ()
{
}
/**
* Construct a persistent copy of an existing attribute list.
*
* <p>This constructor is most useful for application writers,
* who will use it to create a persistent copy of an existing
* attribute list.</p>
*
* @param atts The attribute list to copy
* @see org.xml.sax.DocumentHandler#startElement
*/
public AttributeListImpl (AttributeList atts)
{
setAttributeList(atts);
}
////////////////////////////////////////////////////////////////////
// Methods specific to this class.
////////////////////////////////////////////////////////////////////
/**
* Set the attribute list, discarding previous contents.
*
* <p>This method allows an application writer to reuse an
* attribute list easily.</p>
*
* @param atts The attribute list to copy.
*/
public void setAttributeList (AttributeList atts)
{
int count = atts.getLength();
clear();
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
* to build up an attribute list incrementally before delivering
* it to the application.</p>
*
* @param name The attribute name.
* @param type The attribute type ("NMTOKEN" for an enumeration).
* @param value The attribute value (must not be null).
* @see #removeAttribute
* @see org.xml.sax.DocumentHandler#startElement
*/
public void addAttribute (String name, String type, String 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
* attribute out of an AttributeList. Note that invoking this
* method will change the length of the attribute list and
* some of the attribute's indices.</p>
*
* <p>If the requested attribute is not in the list, this is
* a no-op.</p>
*
* @param name The attribute name.
* @see #addAttribute
*/
public void removeAttribute (String name)
{
int i = names.indexOf(name);
if (i >= 0) {
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
* list between DocumentHandler.startElement events. Normally,
* it will make sense to reuse the same AttributeListImpl object
* rather than allocating a new one each time.</p>
*
* @see org.xml.sax.DocumentHandler#startElement
*/
public void clear ()
{
names.removeAllElements();
types.removeAllElements();
values.removeAllElements();
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.AttributeList
////////////////////////////////////////////////////////////////////
/**
* Return the number of attributes in the list.
*
* @return The number of attributes in the list.
* @see org.xml.sax.AttributeList#getLength
*/
public int getLength ()
{
return names.size();
}
/**
* Get the name of an attribute (by position).
*
* @param i The position of the attribute in the list.
* @return The attribute name as a string, or null if there
* is no attribute at that position.
* @see org.xml.sax.AttributeList#getName(int)
*/
public String getName (int i)
{
if (i < 0) {
return null;
}
try {
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.
* @return The attribute type as a string ("NMTOKEN" for an
* enumeration, and "CDATA" if no declaration was
* read), or null if there is no attribute at
* that position.
* @see org.xml.sax.AttributeList#getType(int)
*/
public String getType (int i)
{
if (i < 0) {
return null;
}
try {
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.
* @return The attribute value as a string, or null if
* there is no attribute at that position.
* @see org.xml.sax.AttributeList#getValue(int)
*/
public String getValue (int i)
{
if (i < 0) {
return null;
}
try {
return (String)values.elementAt(i);
} catch (ArrayIndexOutOfBoundsException e) {
return null;
}
}
/**
* Get the type of an attribute (by name).
*
* @param name The attribute name.
* @return The attribute type as a string ("NMTOKEN" for an
* enumeration, and "CDATA" if no declaration was
* read).
* @see org.xml.sax.AttributeList#getType(java.lang.String)
*/
public String getType (String name)
{
return getType(names.indexOf(name));
}
/**
* Get the value of an attribute (by name).
*
* @param name The attribute name.
* @see org.xml.sax.AttributeList#getValue(java.lang.String)
*/
public String getValue (String name)
{
return getValue(names.indexOf(name));
}
////////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////////
Vector names = new Vector();
Vector types = new Vector();
Vector values = new Vector();
}
// end of AttributeListImpl.java
// SAX default implementation for Locator.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: LocatorImpl.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.helpers;
import org.xml.sax.Locator;
/**
* Provide an optional convenience implementation of Locator.
*
* <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 is available mainly for application writers, who
* can use it to make a persistent snapshot of a locator at any
* point during a document parse:</p>
*
* <pre>
* Locator locator;
* Locator startloc;
*
* public void setLocator (Locator locator)
* {
* // note the locator
* this.locator = locator;
* }
*
* public void startDocument ()
* {
* // save the location of the start of the document
* // for future use.
* Locator startloc = new LocatorImpl(locator);
* }
*</pre>
*
* <p>Normally, parser writers will not use this class, since it
* is more efficient to provide location information only when
* requested, rather than constantly updating a Locator object.</p>
*
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
* @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
* 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.
* When the original locator changes, this copy will still keep
* the original values (and it can be used outside the scope of
* DocumentHandler methods).</p>
*
* @param locator The locator to copy.
*/
public LocatorImpl (Locator locator)
{
setPublicId(locator.getPublicId());
setSystemId(locator.getSystemId());
setLineNumber(locator.getLineNumber());
setColumnNumber(locator.getColumnNumber());
}
////////////////////////////////////////////////////////////////////
// Implementation of org.xml.sax.Locator
////////////////////////////////////////////////////////////////////
/**
* Return the saved public identifier.
*
* @return The public identifier as a string, or null if none
* is available.
* @see org.xml.sax.Locator#getPublicId
* @see #setPublicId
*/
public String getPublicId ()
{
return publicId;
}
/**
* Return the saved system identifier.
*
* @return The system identifier as a string, or null if none
* is available.
* @see org.xml.sax.Locator#getSystemId
* @see #setSystemId
*/
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.
* @see org.xml.sax.Locator#getLineNumber
* @see #setLineNumber
*/
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.
* @see org.xml.sax.Locator#getColumnNumber
* @see #setColumnNumber
*/
public int getColumnNumber ()
{
return columnNumber;
}
////////////////////////////////////////////////////////////////////
// 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
* if none is available.
* @see #getPublicId
*/
public void setPublicId (String publicId)
{
this.publicId = publicId;
}
/**
* Set the system identifier for this locator.
*
* @param systemId The new system identifier, or null
* if none is available.
* @see #getSystemId
*/
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.
* @see #getLineNumber
*/
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.
* @see #getColumnNumber
*/
public void setColumnNumber (int columnNumber)
{
this.columnNumber = columnNumber;
}
////////////////////////////////////////////////////////////////////
// Internal state.
////////////////////////////////////////////////////////////////////
private String publicId;
private String systemId;
private int lineNumber;
private int columnNumber;
}
// end of LocatorImpl.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 2004/12/23 22:38:42 mark 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());
}
}
}
// SAX parser factory.
// http://www.saxproject.org
// No warranty; no copyright -- use this as you will.
// $Id: ParserFactory.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.helpers;
import java.lang.ClassNotFoundException;
import java.lang.IllegalAccessException;
import java.lang.InstantiationException;
import java.lang.SecurityException;
import java.lang.ClassCastException;
import org.xml.sax.Parser;
/**
* Java-specific class for dynamically loading SAX parsers.
*
* <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><strong>Note:</strong> This class is designed to work with the now-deprecated
* SAX1 {@link org.xml.sax.Parser Parser} class. SAX2 applications should use
* {@link org.xml.sax.helpers.XMLReaderFactory XMLReaderFactory} instead.</p>
*
* <p>ParserFactory is not part of the platform-independent definition
* of SAX; it is an additional convenience class designed
* specifically for Java XML application writers. SAX applications
* can use the static methods in this class to allocate a SAX parser
* dynamically at run-time based either on the value of the
* `org.xml.sax.parser' system property or on a string containing the class
* name.</p>
*
* <p>Note that the application still requires an XML parser that
* implements SAX1.</p>
*
* @deprecated This class works with the deprecated
* {@link org.xml.sax.Parser Parser}
* interface.
* @since SAX 1.0
* @author David Megginson
* @version 2.0.1 (sax2r2)
*/
public class ParserFactory {
/**
* Private null constructor.
*/
private ParserFactory ()
{
}
/**
* Create a new SAX parser using the `org.xml.sax.parser' system property.
*
* <p>The named class must exist and must implement the
* {@link org.xml.sax.Parser Parser} interface.</p>
*
* @exception java.lang.NullPointerException There is no value
* for the `org.xml.sax.parser' system property.
* @exception java.lang.ClassNotFoundException The SAX parser
* class was not found (check your CLASSPATH).
* @exception IllegalAccessException The SAX parser class was
* found, but you do not have permission to load
* it.
* @exception InstantiationException The SAX parser class was
* found but could not be instantiated.
* @exception java.lang.ClassCastException The SAX parser class
* was found and instantiated, but does not implement
* org.xml.sax.Parser.
* @see #makeParser(java.lang.String)
* @see org.xml.sax.Parser
*/
public static Parser makeParser ()
throws ClassNotFoundException,
IllegalAccessException,
InstantiationException,
NullPointerException,
ClassCastException
{
String className = System.getProperty("org.xml.sax.parser");
if (className == null) {
throw new NullPointerException("No value for sax.parser property");
} else {
return makeParser(className);
}
}
/**
* Create a new SAX parser object using the class name provided.
*
* <p>The named class must exist and must implement the
* {@link org.xml.sax.Parser Parser} interface.</p>
*
* @param className A string containing the name of the
* SAX parser class.
* @exception java.lang.ClassNotFoundException The SAX parser
* class was not found (check your CLASSPATH).
* @exception IllegalAccessException The SAX parser class was
* found, but you do not have permission to load
* it.
* @exception InstantiationException The SAX parser class was
* found but could not be instantiated.
* @exception java.lang.ClassCastException The SAX parser class
* was found and instantiated, but does not implement
* org.xml.sax.Parser.
* @see #makeParser()
* @see org.xml.sax.Parser
*/
public static Parser makeParser (String className)
throws ClassNotFoundException,
IllegalAccessException,
InstantiationException,
ClassCastException
{
return (Parser) NewInstance.newInstance (
NewInstance.getClassLoader (), className);
}
}
// XMLReaderFactory.java - factory for creating a new reader.
// http://www.saxproject.org
// Written by David Megginson
// and by David Brownell
// NO WARRANTY! This class is in the Public Domain.
// $Id: XMLReaderFactory.java,v 1.1 2004/12/23 22:38:42 mark Exp $
package org.xml.sax.helpers;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;
/**
* Factory for creating an XML reader.
*
* <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 static methods for creating an XML reader
* from an explicit class name, or based on runtime defaults:</p>
*
* <pre>
* try {
* XMLReader myReader = XMLReaderFactory.createXMLReader();
* } catch (SAXException e) {
* System.err.println(e.getMessage());
* }
* </pre>
*
* <p><strong>Note to Distributions bundled with parsers:</strong>
* You should modify the implementation of the no-arguments
* <em>createXMLReader</em> to handle cases where the external
* configuration mechanisms aren't set up. That method should do its
* best to return a parser when one is in the class path, even when
* nothing bound its class name to <code>org.xml.sax.driver</code> so
* those configuration mechanisms would see it.</p>
*
* @since SAX 2.0
* @author David Megginson, David Brownell
* @version 2.0.1 (sax2r2)
*/
final public class XMLReaderFactory
{
/**
* Private constructor.
*
* <p>This constructor prevents the class from being instantiated.</p>
*/
private XMLReaderFactory ()
{
}
private static final String property = "org.xml.sax.driver";
/**
* Attempt to create an XMLReader from system defaults.
* In environments which can support it, the name of the XMLReader
* class is determined by trying each these options in order, and
* using the first one which succeeds:</p> <ul>
*
* <li>If the system property <code>org.xml.sax.driver</code>
* has a value, that is used as an XMLReader class name. </li>
*
* <li>The JAR "Services API" is used to look for a class name
* in the <em>META-INF/services/org.xml.sax.driver</em> file in
* jarfiles available to the runtime.</li>
*
* <li> SAX parser distributions are strongly encouraged to provide
* a default XMLReader class name that will take effect only when
* previous options (on this list) are not successful.</li>
*
* <li>Finally, if {@link ParserFactory#makeParser()} can
* return a system default SAX1 parser, that parser is wrapped in
* a {@link ParserAdapter}. (This is a migration aid for SAX1
* environments, where the <code>org.xml.sax.parser</code> system
* property will often be usable.) </li>
*
* </ul>
*
* <p> In environments such as small embedded systems, which can not
* support that flexibility, other mechanisms to determine the default
* may be used. </p>
*
* <p>Note that many Java environments allow system properties to be
* 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
* method will succeed, except when security policies intervene.
* 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
* can be identified and instantiated.
* @see #createXMLReader(java.lang.String)
*/
public static XMLReader createXMLReader ()
throws SAXException
{
String className = null;
ClassLoader loader = NewInstance.getClassLoader ();
// 1. try the JVM-instance-wide system property
try { className = System.getProperty (property); }
catch (RuntimeException e) { /* normally fails for applets */ }
// 2. if that fails, try META-INF/services/
if (className == null) {
try {
String service = "META-INF/services/" + property;
InputStream in;
BufferedReader reader;
if (loader == null)
in = ClassLoader.getSystemResourceAsStream (service);
else
in = loader.getResourceAsStream (service);
if (in != null) {
reader = new BufferedReader (
new InputStreamReader (in, "UTF8"));
className = reader.readLine ();
in.close ();
}
} catch (Exception e) {
}
}
// 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);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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