Commit 8d06274e by Tom Tromey

[multiple changes]

2005-03-26  Chris Burdess  <dog@gnu.org>

	* gnu/xml/dom/DomNode.java (notifyNode): grow listener array as
	required.

2005-03-13  Michael Koch  <konqueror@gmx.de>

	* gnu/xml/aelfred2/XmlParser.java: Fixed typo.

2005-03-11  Chris Burdess  <dog@gnu.org>

	* gnu/xml/aelfred2/SAXDriver.java: Corrected bug handling URI
	warnings.

2005-02-27  Chris Burdess  <dog@gnu.org>

	* gnu/xml/aelfred2/JAXPFactory.java,
	gnu/xml/aelfred2/SAXDriver.java,
	gnu/xml/aelfred2/XmlParser.java,
	gnu/xml/aelfred2/XmlReader.java: Applied GNU Classpath source code
	formatting conventions. Replaced arrays of Object with struct-like
	classes for easier maintainability. Made SAXDriver.stringInterning
	package private to allow access from XmlParser inside the loop without
	a method call overhead.

2005-03-11  Chris Burdess  <dog@gnu.org>

	* gnu/xml/aelfred2/SAXDriver.java: Corrected bug handling URI
	warnings.

From-SVN: r97200
parent 1fff69c9
2005-03-26 Chris Burdess <dog@gnu.org>
* gnu/xml/dom/DomNode.java (notifyNode): grow listener array as
required.
2005-03-13 Michael Koch <konqueror@gmx.de>
* gnu/xml/aelfred2/XmlParser.java: Fixed typo.
2005-03-11 Chris Burdess <dog@gnu.org>
* gnu/xml/aelfred2/SAXDriver.java: Corrected bug handling URI
warnings.
2005-02-27 Chris Burdess <dog@gnu.org>
* gnu/xml/aelfred2/JAXPFactory.java,
gnu/xml/aelfred2/SAXDriver.java,
gnu/xml/aelfred2/XmlParser.java,
gnu/xml/aelfred2/XmlReader.java: Applied GNU Classpath source code
formatting conventions. Replaced arrays of Object with struct-like
classes for easier maintainability. Made SAXDriver.stringInterning
package private to allow access from XmlParser inside the loop without
a method call overhead.
2005-03-11 Chris Burdess <dog@gnu.org>
* gnu/xml/aelfred2/SAXDriver.java: Corrected bug handling URI
warnings.
2005-03-28 Alexandre Oliva <aoliva@redhat.com> 2005-03-28 Alexandre Oliva <aoliva@redhat.com>
* configure.ac: Revert 2005-03-25's patch. Propagate MULTIlib * configure.ac: Revert 2005-03-25's patch. Propagate MULTIlib
......
...@@ -60,35 +60,38 @@ import javax.xml.parsers.SAXParserFactory; ...@@ -60,35 +60,38 @@ import javax.xml.parsers.SAXParserFactory;
* *
* @author David Brownell * @author David Brownell
*/ */
public final class JAXPFactory extends SAXParserFactory public final class JAXPFactory
extends SAXParserFactory
{ {
private Hashtable flags = new Hashtable ();
private Hashtable flags = new Hashtable();
/** /**
* Constructs a factory which normally returns a non-validating * Constructs a factory which normally returns a non-validating
* parser. * parser.
*/ */
public JAXPFactory () { } public JAXPFactory()
{
}
public SAXParser newSAXParser () public SAXParser newSAXParser()
throws ParserConfigurationException, SAXException throws ParserConfigurationException, SAXException
{ {
JaxpParser jaxp = new JaxpParser (); JaxpParser jaxp = new JaxpParser();
Enumeration e = flags.keys (); Enumeration e = flags.keys();
XMLReader parser = jaxp.getXMLReader (); XMLReader parser = jaxp.getXMLReader();
parser.setFeature ( parser.setFeature(SAXDriver.FEATURE + "namespaces",
SAXDriver.FEATURE + "namespaces", isNamespaceAware());
isNamespaceAware ()); parser.setFeature(SAXDriver.FEATURE + "validation",
parser.setFeature ( isValidating());
SAXDriver.FEATURE + "validation",
isValidating ());
// that makes SAX2 feature flags trump JAXP // that makes SAX2 feature flags trump JAXP
while (e.hasMoreElements ()) { while (e.hasMoreElements())
String uri = (String) e.nextElement (); {
Boolean value = (Boolean) flags.get (uri); String uri = (String) e.nextElement();
parser.setFeature (uri, value.booleanValue ()); Boolean value = (Boolean) flags.get(uri);
parser.setFeature(uri, value.booleanValue());
} }
return jaxp; return jaxp;
...@@ -96,101 +99,133 @@ public final class JAXPFactory extends SAXParserFactory ...@@ -96,101 +99,133 @@ public final class JAXPFactory extends SAXParserFactory
// yes, this "feature transfer" mechanism doesn't play well // yes, this "feature transfer" mechanism doesn't play well
public void setFeature (String name, boolean value) public void setFeature(String name, boolean value)
throws throws ParserConfigurationException, SAXNotRecognizedException,
ParserConfigurationException,
SAXNotRecognizedException,
SAXNotSupportedException SAXNotSupportedException
{ {
try { try
{
// force "early" detection of errors where possible // force "early" detection of errors where possible
// (flags can't necessarily be set before parsing) // (flags can't necessarily be set before parsing)
new JaxpParser ().getXMLReader ().setFeature (name, value); new JaxpParser().getXMLReader().setFeature(name, value);
flags.put (name, new Boolean (value)); flags.put(name, new Boolean(value));
} catch (SAXNotRecognizedException e) { }
throw new SAXNotRecognizedException (name); catch (SAXNotRecognizedException e)
} catch (SAXNotSupportedException e) { {
throw new SAXNotSupportedException (name); throw new SAXNotRecognizedException(name);
} catch (Exception e) { }
throw new ParserConfigurationException ( catch (SAXNotSupportedException e)
e.getClass ().getName () {
throw new SAXNotSupportedException(name);
}
catch (Exception e)
{
throw new ParserConfigurationException(e.getClass().getName()
+ ": " + ": "
+ e.getMessage ()); + e.getMessage());
} }
} }
public boolean getFeature (String name) public boolean getFeature(String name)
throws throws ParserConfigurationException, SAXNotRecognizedException,
ParserConfigurationException,
SAXNotRecognizedException,
SAXNotSupportedException SAXNotSupportedException
{ {
Boolean value = (Boolean) flags.get (name); Boolean value = (Boolean) flags.get(name);
if (value != null) if (value != null)
return value.booleanValue (); {
return value.booleanValue();
}
else else
try { {
return new JaxpParser ().getXMLReader ().getFeature (name); try
} catch (SAXNotRecognizedException e) { {
throw new SAXNotRecognizedException (name); return new JaxpParser().getXMLReader().getFeature(name);
} catch (SAXNotSupportedException e) { }
throw new SAXNotSupportedException (name); catch (SAXNotRecognizedException e)
} catch (SAXException e) { {
throw new ParserConfigurationException ( throw new SAXNotRecognizedException(name);
e.getClass ().getName () }
catch (SAXNotSupportedException e)
{
throw new SAXNotSupportedException(name);
}
catch (SAXException e)
{
throw new ParserConfigurationException(e.getClass().getName()
+ ": " + ": "
+ e.getMessage ()); + e.getMessage());
}
} }
} }
private static class JaxpParser extends SAXParser private static class JaxpParser
extends SAXParser
{ {
private XmlReader ae2 = new XmlReader ();
private XmlReader ae2 = new XmlReader();
private XMLReaderAdapter parser = null; private XMLReaderAdapter parser = null;
JaxpParser () { } JaxpParser()
{
}
public void setProperty (String id, Object value) public void setProperty(String id, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ ae2.setProperty (id, value); } {
ae2.setProperty(id, value);
}
public Object getProperty (String id) public Object getProperty(String id)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ return ae2.getProperty (id); } {
return ae2.getProperty(id);
}
public Parser getParser () public Parser getParser()
throws SAXException throws SAXException
{ {
if (parser == null) if (parser == null)
parser = new XMLReaderAdapter (ae2); {
parser = new XMLReaderAdapter(ae2);
}
return parser; return parser;
} }
public XMLReader getXMLReader () public XMLReader getXMLReader ()
throws SAXException throws SAXException
{ return ae2; } {
return ae2;
}
public boolean isNamespaceAware () public boolean isNamespaceAware()
{
try
{
return ae2.getFeature(SAXDriver.FEATURE + "namespaces");
}
catch (Exception e)
{ {
try { throw new Error();
return ae2.getFeature (SAXDriver.FEATURE + "namespaces");
} catch (Exception e) {
throw new Error ();
} }
} }
public boolean isValidating () public boolean isValidating()
{ {
try { try
return ae2.getFeature (SAXDriver.FEATURE + "validation"); {
} catch (Exception e) { return ae2.getFeature(SAXDriver.FEATURE + "validation");
throw new Error (); }
catch (Exception e)
{
throw new Error();
} }
} }
// TODO isXIncludeAware() // TODO isXIncludeAware()
} }
} }
...@@ -60,15 +60,11 @@ import java.net.URL; ...@@ -60,15 +60,11 @@ import java.net.URL;
import java.util.Locale; import java.util.Locale;
import java.util.Stack; import java.util.Stack;
// maintaining 1.1 compatibility for now ... more portable, PJava, etc
// Iterator, Hashmap and ArrayList ought to be faster
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Vector;
import org.xml.sax.*; import org.xml.sax.*;
import org.xml.sax.ext.*; import org.xml.sax.ext.*;
...@@ -135,7 +131,8 @@ import org.xml.sax.helpers.NamespaceSupport; ...@@ -135,7 +131,8 @@ import org.xml.sax.helpers.NamespaceSupport;
final public class SAXDriver final public class SAXDriver
implements Locator, Attributes2, XMLReader, Parser, AttributeList implements Locator, Attributes2, XMLReader, Parser, AttributeList
{ {
private final DefaultHandler2 base = new DefaultHandler2 ();
private final DefaultHandler2 base = new DefaultHandler2();
private XmlParser parser; private XmlParser parser;
private EntityResolver entityResolver = base; private EntityResolver entityResolver = base;
...@@ -158,27 +155,31 @@ final public class SAXDriver ...@@ -158,27 +155,31 @@ final public class SAXDriver
private boolean extPE = true; private boolean extPE = true;
private boolean resolveAll = true; private boolean resolveAll = true;
private boolean useResolver2 = true; private boolean useResolver2 = true;
private boolean stringInterning = true;
// package private to allow (read-only) access in XmlParser
boolean stringInterning = true;
private int attributeCount; private int attributeCount;
private boolean attributes; private boolean attributes;
private String nsTemp []; private String[] nsTemp;
private NamespaceSupport prefixStack; private NamespaceSupport prefixStack;
// //
// Constructor. // Constructor.
// //
/** Constructs a SAX Parser. */ /**
public SAXDriver () * Constructs a SAX Parser.
*/
public SAXDriver()
{ {
reset (); reset();
} }
private void reset () private void reset()
{ {
elementName = null; elementName = null;
entityStack = new Stack (); entityStack = new Stack();
attributesList = Collections.synchronizedList(new ArrayList()); attributesList = Collections.synchronizedList(new ArrayList());
attributeCount = 0; attributeCount = 0;
attributes = false; attributes = false;
...@@ -196,21 +197,21 @@ final public class SAXDriver ...@@ -196,21 +197,21 @@ final public class SAXDriver
* only locales using the English language are supported. * only locales using the English language are supported.
* @param locale The locale for which diagnostics will be generated * @param locale The locale for which diagnostics will be generated
*/ */
public void setLocale (Locale locale) public void setLocale(Locale locale)
throws SAXException throws SAXException
{ {
if ("en".equals (locale.getLanguage ())) if ("en".equals(locale.getLanguage()))
return ; {
return;
}
throw new SAXException ("AElfred2 only supports English locales."); throw new SAXException ("AElfred2 only supports English locales.");
} }
/** /**
* <b>SAX2</b>: Returns the object used when resolving external * <b>SAX2</b>: Returns the object used when resolving external
* entities during parsing (both general and parameter entities). * entities during parsing (both general and parameter entities).
*/ */
public EntityResolver getEntityResolver () public EntityResolver getEntityResolver()
{ {
return (entityResolver == base) ? null : entityResolver; return (entityResolver == base) ? null : entityResolver;
} }
...@@ -219,23 +220,28 @@ final public class SAXDriver ...@@ -219,23 +220,28 @@ final public class SAXDriver
* <b>SAX1, SAX2</b>: Set the entity resolver for this parser. * <b>SAX1, SAX2</b>: Set the entity resolver for this parser.
* @param handler The object to receive entity events. * @param handler The object to receive entity events.
*/ */
public void setEntityResolver (EntityResolver resolver) public void setEntityResolver(EntityResolver resolver)
{ {
if (resolver instanceof EntityResolver2) if (resolver instanceof EntityResolver2)
{
resolver2 = (EntityResolver2) resolver; resolver2 = (EntityResolver2) resolver;
}
else else
{
resolver2 = null; resolver2 = null;
}
if (resolver == null) if (resolver == null)
{
resolver = base; resolver = base;
}
entityResolver = resolver; entityResolver = resolver;
} }
/** /**
* <b>SAX2</b>: Returns the object used to process declarations related * <b>SAX2</b>: Returns the object used to process declarations related
* to notations and unparsed entities. * to notations and unparsed entities.
*/ */
public DTDHandler getDTDHandler () public DTDHandler getDTDHandler()
{ {
return (dtdHandler == base) ? null : dtdHandler; return (dtdHandler == base) ? null : dtdHandler;
} }
...@@ -244,10 +250,12 @@ final public class SAXDriver ...@@ -244,10 +250,12 @@ final public class SAXDriver
* <b>SAX1, SAX2</b>: Set the DTD handler for this parser. * <b>SAX1, SAX2</b>: Set the DTD handler for this parser.
* @param handler The object to receive DTD events. * @param handler The object to receive DTD events.
*/ */
public void setDTDHandler (DTDHandler handler) public void setDTDHandler(DTDHandler handler)
{ {
if (handler == null) if (handler == null)
{
handler = base; handler = base;
}
this.dtdHandler = handler; this.dtdHandler = handler;
} }
...@@ -264,9 +272,9 @@ final public class SAXDriver ...@@ -264,9 +272,9 @@ final public class SAXDriver
* *
* @param handler The object to receive document events. * @param handler The object to receive document events.
*/ */
public void setDocumentHandler (DocumentHandler handler) public void setDocumentHandler(DocumentHandler handler)
{ {
contentHandler = new Adapter (handler); contentHandler = new Adapter(handler);
xmlNames = true; xmlNames = true;
} }
...@@ -274,9 +282,9 @@ final public class SAXDriver ...@@ -274,9 +282,9 @@ final public class SAXDriver
* <b>SAX2</b>: Returns the object used to report the logical * <b>SAX2</b>: Returns the object used to report the logical
* content of an XML document. * content of an XML document.
*/ */
public ContentHandler getContentHandler () public ContentHandler getContentHandler()
{ {
return contentHandler == base ? null : contentHandler; return (contentHandler == base) ? null : contentHandler;
} }
/** /**
...@@ -285,10 +293,12 @@ final public class SAXDriver ...@@ -285,10 +293,12 @@ final public class SAXDriver
* this content handler will supplant it (but XML 1.0 style name * this content handler will supplant it (but XML 1.0 style name
* reporting may remain enabled). * reporting may remain enabled).
*/ */
public void setContentHandler (ContentHandler handler) public void setContentHandler(ContentHandler handler)
{ {
if (handler == null) if (handler == null)
{
handler = base; handler = base;
}
contentHandler = handler; contentHandler = handler;
} }
...@@ -296,10 +306,12 @@ final public class SAXDriver ...@@ -296,10 +306,12 @@ final public class SAXDriver
* <b>SAX1, SAX2</b>: Set the error handler for this parser. * <b>SAX1, SAX2</b>: Set the error handler for this parser.
* @param handler The object to receive error events. * @param handler The object to receive error events.
*/ */
public void setErrorHandler (ErrorHandler handler) public void setErrorHandler(ErrorHandler handler)
{ {
if (handler == null) if (handler == null)
{
handler = base; handler = base;
}
this.errorHandler = handler; this.errorHandler = handler;
} }
...@@ -307,9 +319,10 @@ final public class SAXDriver ...@@ -307,9 +319,10 @@ final public class SAXDriver
* <b>SAX2</b>: Returns the object used to receive callbacks for XML * <b>SAX2</b>: Returns the object used to receive callbacks for XML
* errors of all levels (fatal, nonfatal, warning); this is never null; * errors of all levels (fatal, nonfatal, warning); this is never null;
*/ */
public ErrorHandler getErrorHandler () public ErrorHandler getErrorHandler()
{ return errorHandler == base ? null : errorHandler; } {
return (errorHandler == base) ? null : errorHandler;
}
/** /**
* <b>SAX1, SAX2</b>: Auxiliary API to parse an XML document, used mostly * <b>SAX1, SAX2</b>: Auxiliary API to parse an XML document, used mostly
...@@ -327,52 +340,65 @@ final public class SAXDriver ...@@ -327,52 +340,65 @@ final public class SAXDriver
* @exception IOException IOExceptions are normally through through * @exception IOException IOExceptions are normally through through
* the parser if there are problems reading the source document. * the parser if there are problems reading the source document.
*/ */
public void parse (InputSource source) public void parse(InputSource source)
throws SAXException, IOException throws SAXException, IOException
{ {
synchronized (base) { synchronized (base)
parser = new XmlParser (); {
parser = new XmlParser();
if (namespaces) if (namespaces)
prefixStack = new NamespaceSupport (); {
prefixStack = new NamespaceSupport();
}
else if (!xmlNames) else if (!xmlNames)
throw new IllegalStateException (); {
parser.setHandler (this); throw new IllegalStateException();
}
try { parser.setHandler(this);
try
{
Reader r = source.getCharacterStream(); Reader r = source.getCharacterStream();
InputStream in = source.getByteStream(); InputStream in = source.getByteStream();
parser.doParse(source.getSystemId(),
parser.doParse (source.getSystemId (), source.getPublicId(),
source.getPublicId (),
r, r,
in, in,
source.getEncoding ()); source.getEncoding());
} catch (SAXException e) { }
catch (SAXException e)
{
throw e; throw e;
} catch (IOException e) { }
catch (IOException e)
{
throw e; throw e;
} catch (RuntimeException e) { }
catch (RuntimeException e)
{
throw e; throw e;
} catch (Exception e) { }
throw new SAXParseException (e.getMessage (), this, e); catch (Exception e)
} finally { {
contentHandler.endDocument (); throw new SAXParseException(e.getMessage(), this, e);
}
finally
{
contentHandler.endDocument();
reset(); reset();
} }
} }
} }
/** /**
* <b>SAX1, SAX2</b>: Preferred API to parse an XML document, using a * <b>SAX1, SAX2</b>: Preferred API to parse an XML document, using a
* system identifier (URI). * system identifier (URI).
*/ */
public void parse (String systemId) public void parse(String systemId)
throws SAXException, IOException throws SAXException, IOException
{ {
parse (new InputSource (systemId)); parse(new InputSource(systemId));
} }
// //
...@@ -387,63 +413,92 @@ final public class SAXDriver ...@@ -387,63 +413,92 @@ final public class SAXDriver
* @exception SAXNotRecognizedException thrown if the feature flag * @exception SAXNotRecognizedException thrown if the feature flag
* is neither built in, nor yet assigned. * is neither built in, nor yet assigned.
*/ */
public boolean getFeature (String featureId) public boolean getFeature(String featureId)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
if ((FEATURE + "validation").equals (featureId)) if ((FEATURE + "validation").equals(featureId))
{
return false; return false;
}
// external entities (both types) are optionally included // external entities (both types) are optionally included
if ((FEATURE + "external-general-entities").equals (featureId)) if ((FEATURE + "external-general-entities").equals(featureId))
{
return extGE; return extGE;
if ((FEATURE + "external-parameter-entities") .equals (featureId)) }
if ((FEATURE + "external-parameter-entities").equals(featureId))
{
return extPE; return extPE;
}
// element/attribute names are as written in document; no mangling // element/attribute names are as written in document; no mangling
if ((FEATURE + "namespace-prefixes").equals (featureId)) if ((FEATURE + "namespace-prefixes").equals(featureId))
{
return xmlNames; return xmlNames;
}
// report element/attribute namespaces? // report element/attribute namespaces?
if ((FEATURE + "namespaces").equals (featureId)) if ((FEATURE + "namespaces").equals(featureId))
{
return namespaces; return namespaces;
}
// all PEs and GEs are reported // all PEs and GEs are reported
if ((FEATURE + "lexical-handler/parameter-entities").equals (featureId)) if ((FEATURE + "lexical-handler/parameter-entities").equals(featureId))
{
return true; return true;
}
// default is true // default is true
if ((FEATURE + "string-interning").equals (featureId)) if ((FEATURE + "string-interning").equals(featureId))
{
return stringInterning; return stringInterning;
}
// EXTENSIONS 1.1 // EXTENSIONS 1.1
// always returns isSpecified info // always returns isSpecified info
if ((FEATURE + "use-attributes2").equals (featureId)) if ((FEATURE + "use-attributes2").equals(featureId))
{
return true; return true;
}
// meaningful between startDocument/endDocument // meaningful between startDocument/endDocument
if ((FEATURE + "is-standalone").equals (featureId)) { if ((FEATURE + "is-standalone").equals(featureId))
{
if (parser == null) if (parser == null)
throw new SAXNotSupportedException (featureId); {
return parser.isStandalone (); throw new SAXNotSupportedException(featureId);
}
return parser.isStandalone();
} }
// optionally don't absolutize URIs in declarations // optionally don't absolutize URIs in declarations
if ((FEATURE + "resolve-dtd-uris").equals (featureId)) if ((FEATURE + "resolve-dtd-uris").equals(featureId))
{
return resolveAll; return resolveAll;
}
// optionally use resolver2 interface methods, if possible // optionally use resolver2 interface methods, if possible
if ((FEATURE + "use-entity-resolver2").equals (featureId)) if ((FEATURE + "use-entity-resolver2").equals(featureId))
{
return useResolver2; return useResolver2;
}
throw new SAXNotRecognizedException (featureId); throw new SAXNotRecognizedException(featureId);
} }
// package private // package private
DeclHandler getDeclHandler () { return declHandler; } DeclHandler getDeclHandler()
{
return declHandler;
}
// package private // package private
boolean resolveURIs () { return resolveAll; } boolean resolveURIs()
{
return resolveAll;
}
/** /**
* <b>SAX2</b>: Returns the specified property. * <b>SAX2</b>: Returns the specified property.
...@@ -451,24 +506,28 @@ final public class SAXDriver ...@@ -451,24 +506,28 @@ final public class SAXDriver
* @exception SAXNotRecognizedException thrown if the property value * @exception SAXNotRecognizedException thrown if the property value
* is neither built in, nor yet stored. * is neither built in, nor yet stored.
*/ */
public Object getProperty (String propertyId) public Object getProperty(String propertyId)
throws SAXNotRecognizedException throws SAXNotRecognizedException
{ {
if ((PROPERTY + "declaration-handler").equals (propertyId)) if ((PROPERTY + "declaration-handler").equals(propertyId))
return declHandler == base ? null : declHandler; {
return (declHandler == base) ? null : declHandler;
}
if ((PROPERTY + "lexical-handler").equals (propertyId)) if ((PROPERTY + "lexical-handler").equals(propertyId))
return lexicalHandler == base ? null : lexicalHandler; {
return (lexicalHandler == base) ? null : lexicalHandler;
}
// unknown properties // unknown properties
throw new SAXNotRecognizedException (propertyId); throw new SAXNotRecognizedException(propertyId);
} }
/** /**
* <b>SAX2</b>: Sets the state of feature flags in this parser. Some * <b>SAX2</b>: Sets the state of feature flags in this parser. Some
* built-in feature flags are mutable. * built-in feature flags are mutable.
*/ */
public void setFeature (String featureId, boolean value) public void setFeature(String featureId, boolean value)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
boolean state; boolean state;
...@@ -477,83 +536,110 @@ final public class SAXDriver ...@@ -477,83 +536,110 @@ final public class SAXDriver
state = getFeature (featureId); state = getFeature (featureId);
if (state == value) if (state == value)
{
return; return;
}
if (parser != null) if (parser != null)
throw new SAXNotSupportedException ("not while parsing"); {
throw new SAXNotSupportedException("not while parsing");
}
if ((FEATURE + "namespace-prefixes").equals (featureId)) { if ((FEATURE + "namespace-prefixes").equals(featureId))
{
// in this implementation, this only affects xmlns reporting // in this implementation, this only affects xmlns reporting
xmlNames = value; xmlNames = value;
// forcibly prevent illegal parser state // forcibly prevent illegal parser state
if (!xmlNames) if (!xmlNames)
{
namespaces = true; namespaces = true;
}
return; return;
} }
if ((FEATURE + "namespaces").equals (featureId)) { if ((FEATURE + "namespaces").equals(featureId))
{
namespaces = value; namespaces = value;
// forcibly prevent illegal parser state // forcibly prevent illegal parser state
if (!namespaces) if (!namespaces)
{
xmlNames = true; xmlNames = true;
}
return; return;
} }
if ((FEATURE + "external-general-entities").equals (featureId)) { if ((FEATURE + "external-general-entities").equals(featureId))
{
extGE = value; extGE = value;
return; return;
} }
if ((FEATURE + "external-parameter-entities") .equals (featureId)) { if ((FEATURE + "external-parameter-entities").equals(featureId))
{
extPE = value; extPE = value;
return; return;
} }
if ((FEATURE + "resolve-dtd-uris").equals (featureId)) { if ((FEATURE + "resolve-dtd-uris").equals(featureId))
{
resolveAll = value; resolveAll = value;
return; return;
} }
if ((FEATURE + "use-entity-resolver2").equals (featureId)) { if ((FEATURE + "use-entity-resolver2").equals(featureId))
{
useResolver2 = value; useResolver2 = value;
return; return;
} }
throw new SAXNotRecognizedException (featureId); throw new SAXNotRecognizedException(featureId);
} }
/** /**
* <b>SAX2</b>: Assigns the specified property. Like SAX1 handlers, * <b>SAX2</b>: Assigns the specified property. Like SAX1 handlers,
* these may be changed at any time. * these may be changed at any time.
*/ */
public void setProperty (String propertyId, Object value) public void setProperty(String propertyId, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
// see if the property is recognized // see if the property is recognized
getProperty (propertyId); getProperty(propertyId);
// Properties with a defined value, we just change it if we can. // Properties with a defined value, we just change it if we can.
if ((PROPERTY + "declaration-handler").equals (propertyId)) { if ((PROPERTY + "declaration-handler").equals(propertyId))
{
if (value == null) if (value == null)
{
declHandler = base; declHandler = base;
else if (! (value instanceof DeclHandler)) }
throw new SAXNotSupportedException (propertyId); else if (!(value instanceof DeclHandler))
{
throw new SAXNotSupportedException(propertyId);
}
else else
{
declHandler = (DeclHandler) value; declHandler = (DeclHandler) value;
}
return ; return ;
} }
if ((PROPERTY + "lexical-handler").equals (propertyId)) { if ((PROPERTY + "lexical-handler").equals(propertyId))
{
if (value == null) if (value == null)
{
lexicalHandler = base; lexicalHandler = base;
else if (! (value instanceof LexicalHandler)) }
throw new SAXNotSupportedException (propertyId); else if (!(value instanceof LexicalHandler))
{
throw new SAXNotSupportedException(propertyId);
}
else else
{
lexicalHandler = (LexicalHandler) value; lexicalHandler = (LexicalHandler) value;
return ;
} }
return;
throw new SAXNotSupportedException (propertyId);
} }
throw new SAXNotSupportedException(propertyId);
}
// //
// This is where the driver receives XmlParser callbacks and translates // This is where the driver receives XmlParser callbacks and translates
...@@ -561,12 +647,12 @@ final public class SAXDriver ...@@ -561,12 +647,12 @@ final public class SAXDriver
// SAX2 support. // SAX2 support.
// //
void startDocument () void startDocument()
throws SAXException throws SAXException
{ {
contentHandler.setDocumentLocator (this); contentHandler.setDocumentLocator(this);
contentHandler.startDocument (); contentHandler.startDocument();
attributesList.clear (); attributesList.clear();
} }
void xmlDecl(String version, void xmlDecl(String version,
...@@ -584,19 +670,23 @@ final public class SAXDriver ...@@ -584,19 +670,23 @@ final public class SAXDriver
} }
} }
void skippedEntity (String name) void skippedEntity(String name)
throws SAXException throws SAXException
{ contentHandler.skippedEntity (name); } {
contentHandler.skippedEntity(name);
}
InputSource getExternalSubset (String name, String baseURI) InputSource getExternalSubset(String name, String baseURI)
throws SAXException, IOException throws SAXException, IOException
{ {
if (resolver2 == null || !useResolver2 || !extPE) if (resolver2 == null || !useResolver2 || !extPE)
{
return null; return null;
return resolver2.getExternalSubset (name, baseURI); }
return resolver2.getExternalSubset(name, baseURI);
} }
InputSource resolveEntity (boolean isPE, String name, InputSource resolveEntity(boolean isPE, String name,
InputSource in, String baseURI) InputSource in, String baseURI)
throws SAXException, IOException throws SAXException, IOException
{ {
...@@ -604,64 +694,83 @@ final public class SAXDriver ...@@ -604,64 +694,83 @@ final public class SAXDriver
// external entities might be skipped // external entities might be skipped
if (isPE && !extPE) if (isPE && !extPE)
{
return null; return null;
}
if (!isPE && !extGE) if (!isPE && !extGE)
{
return null; return null;
}
// ... or not // ... or not
lexicalHandler.startEntity (name); lexicalHandler.startEntity(name);
if (resolver2 != null && useResolver2) { if (resolver2 != null && useResolver2)
source = resolver2.resolveEntity (name, in.getPublicId (), {
baseURI, in.getSystemId ()); source = resolver2.resolveEntity(name, in.getPublicId(),
if (source == null) { baseURI, in.getSystemId());
in.setSystemId (absolutize (baseURI, if (source == null)
in.getSystemId (), false)); {
in.setSystemId(absolutize(baseURI,
in.getSystemId(), false));
source = in; source = in;
} }
} else { }
in.setSystemId (absolutize (baseURI, in.getSystemId (), false)); else
source = entityResolver.resolveEntity (in.getPublicId (), {
in.getSystemId ()); in.setSystemId(absolutize(baseURI, in.getSystemId(), false));
source = entityResolver.resolveEntity(in.getPublicId(),
in.getSystemId());
if (source == null) if (source == null)
{
source = in; source = in;
} }
startExternalEntity (name, source.getSystemId (), true); }
startExternalEntity(name, source.getSystemId(), true);
return source; return source;
} }
// absolutize a system ID relative to the specified base URI // absolutize a system ID relative to the specified base URI
// (temporarily) package-visible for external entity decls // (temporarily) package-visible for external entity decls
String absolutize (String baseURI, String systemId, boolean nice) String absolutize(String baseURI, String systemId, boolean nice)
throws MalformedURLException, SAXException throws MalformedURLException, SAXException
{ {
// FIXME normalize system IDs -- when? // FIXME normalize system IDs -- when?
// - Convert to UTF-8 // - Convert to UTF-8
// - Map reserved and non-ASCII characters to %HH // - Map reserved and non-ASCII characters to %HH
try { try
if (baseURI == null) { {
if (baseURI == null)
{
if (XmlParser.uriWarnings)
{
warn ("No base URI; hope this SYSTEM id is absolute: " warn ("No base URI; hope this SYSTEM id is absolute: "
+ systemId); + systemId);
return new URL (systemId).toString (); }
} else return new URL(systemId).toString();
return new URL (new URL (baseURI), systemId).toString (); }
else
} catch (MalformedURLException e) { {
return new URL(new URL(baseURI), systemId).toString();
}
}
catch (MalformedURLException e)
{
// Let unknown URI schemes pass through unless we need // Let unknown URI schemes pass through unless we need
// the JVM to map them to i/o streams for us... // the JVM to map them to i/o streams for us...
if (!nice) if (!nice)
{
throw e; throw e;
}
// sometimes sysids for notations or unparsed entities // sometimes sysids for notations or unparsed entities
// aren't really URIs... // aren't really URIs...
warn ("Can't absolutize SYSTEM id: " + e.getMessage ()); warn("Can't absolutize SYSTEM id: " + e.getMessage());
return systemId; return systemId;
} }
} }
void startExternalEntity (String name, String systemId, void startExternalEntity(String name, String systemId, boolean stackOnly)
boolean stackOnly)
throws SAXException throws SAXException
{ {
// The following warning was deleted because the application has the // The following warning was deleted because the application has the
...@@ -672,34 +781,38 @@ final public class SAXDriver ...@@ -672,34 +781,38 @@ final public class SAXDriver
warn ("URI was not reported to parser for entity " + name); warn ("URI was not reported to parser for entity " + name);
*/ */
if (!stackOnly) // spliced [dtd] needs startEntity if (!stackOnly) // spliced [dtd] needs startEntity
lexicalHandler.startEntity (name); {
entityStack.push (systemId); lexicalHandler.startEntity(name);
}
entityStack.push(systemId);
} }
void endExternalEntity (String name) void endExternalEntity(String name)
throws SAXException throws SAXException
{ {
if (!"[document]".equals (name)) if (!"[document]".equals(name))
lexicalHandler.endEntity (name); {
entityStack.pop (); lexicalHandler.endEntity(name);
}
entityStack.pop();
} }
void startInternalEntity (String name) void startInternalEntity(String name)
throws SAXException throws SAXException
{ {
lexicalHandler.startEntity (name); lexicalHandler.startEntity(name);
} }
void endInternalEntity (String name) void endInternalEntity(String name)
throws SAXException throws SAXException
{ {
lexicalHandler.endEntity (name); lexicalHandler.endEntity(name);
} }
void doctypeDecl (String name, String publicId, String systemId) void doctypeDecl(String name, String publicId, String systemId)
throws SAXException throws SAXException
{ {
lexicalHandler.startDTD (name, publicId, systemId); lexicalHandler.startDTD(name, publicId, systemId);
// ... the "name" is a declaration and should be given // ... the "name" is a declaration and should be given
// to the DeclHandler (but sax2 doesn't). // to the DeclHandler (but sax2 doesn't).
...@@ -709,50 +822,60 @@ final public class SAXDriver ...@@ -709,50 +822,60 @@ final public class SAXDriver
// doesn't provide the internal subset "pre-parse" // doesn't provide the internal subset "pre-parse"
} }
void notationDecl (String name, String ids []) void notationDecl(String name, String publicId, String systemId,
String baseUri)
throws SAXException throws SAXException
{ {
try { try
dtdHandler.notationDecl (name, ids [0], {
(resolveAll && ids [1] != null) dtdHandler.notationDecl(name, publicId,
? absolutize (ids [2], ids [1], true) (resolveAll && systemId != null)
: ids [1]); ? absolutize(baseUri, systemId, true)
} catch (IOException e) { : systemId);
}
catch (IOException e)
{
// "can't happen" // "can't happen"
throw new SAXParseException (e.getMessage (), this, e); throw new SAXParseException(e.getMessage(), this, e);
} }
} }
void unparsedEntityDecl (String name, String ids [], String notation) void unparsedEntityDecl(String name, String publicId, String systemId,
String baseUri, String notation)
throws SAXException throws SAXException
{ {
try { try
dtdHandler.unparsedEntityDecl (name, ids [0], {
dtdHandler.unparsedEntityDecl(name, publicId,
resolveAll resolveAll
? absolutize (ids [2], ids [1], true) ? absolutize(baseUri, systemId, true)
: ids [1], : systemId,
notation); notation);
} catch (IOException e) { }
catch (IOException e)
{
// "can't happen" // "can't happen"
throw new SAXParseException (e.getMessage (), this, e); throw new SAXParseException(e.getMessage(), this, e);
} }
} }
void endDoctype () void endDoctype()
throws SAXException throws SAXException
{ {
lexicalHandler.endDTD (); lexicalHandler.endDTD();
} }
private void declarePrefix (String prefix, String uri) private void declarePrefix(String prefix, String uri)
throws SAXException throws SAXException
{ {
int index = uri.indexOf (':'); int index = uri.indexOf(':');
// many versions of nwalsh docbook stylesheets // many versions of nwalsh docbook stylesheets
// have bogus URLs; so this can't be an error... // have bogus URLs; so this can't be an error...
if (index < 1 && uri.length () != 0) if (index < 1 && uri.length() != 0)
warn ("relative URI for namespace: " + uri); {
warn("relative URI for namespace: " + uri);
}
// FIXME: char [0] must be ascii alpha; chars [1..index] // FIXME: char [0] must be ascii alpha; chars [1..index]
// must be ascii alphanumeric or in "+-." [RFC 2396] // must be ascii alphanumeric or in "+-." [RFC 2396]
...@@ -762,88 +885,126 @@ final public class SAXDriver ...@@ -762,88 +885,126 @@ final public class SAXDriver
boolean prefixEquality = prefix.equals("xml"); boolean prefixEquality = prefix.equals("xml");
boolean uriEquality = uri.equals("http://www.w3.org/XML/1998/namespace"); boolean uriEquality = uri.equals("http://www.w3.org/XML/1998/namespace");
if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality)) if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality))
fatal ("xml is by definition bound to the namespace name " + {
fatal("xml is by definition bound to the namespace name " +
"http://www.w3.org/XML/1998/namespace"); "http://www.w3.org/XML/1998/namespace");
}
//xmlns prefix declaration is illegal but xml prefix declaration is llegal... //xmlns prefix declaration is illegal but xml prefix declaration is llegal...
if (prefixEquality && uriEquality) if (prefixEquality && uriEquality)
{
return; return;
}
//name for xmlns prefix must be http://www.w3.org/2000/xmlns/ //name for xmlns prefix must be http://www.w3.org/2000/xmlns/
prefixEquality = prefix.equals("xmlns"); prefixEquality = prefix.equals("xmlns");
uriEquality = uri.equals("http://www.w3.org/2000/xmlns/"); uriEquality = uri.equals("http://www.w3.org/2000/xmlns/");
if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality)) if ((prefixEquality || uriEquality) && !(prefixEquality && uriEquality))
{
fatal("http://www.w3.org/2000/xmlns/ is by definition bound" + fatal("http://www.w3.org/2000/xmlns/ is by definition bound" +
" to prefix xmlns"); " to prefix xmlns");
}
//even if the uri is http://www.w3.org/2000/xmlns/ it is illegal to declare it //even if the uri is http://www.w3.org/2000/xmlns/
// it is illegal to declare it
if (prefixEquality && uriEquality) if (prefixEquality && uriEquality)
{
fatal ("declaring the xmlns prefix is illegal"); fatal ("declaring the xmlns prefix is illegal");
}
uri = uri.intern (); uri = uri.intern();
prefixStack.declarePrefix (prefix, uri); prefixStack.declarePrefix(prefix, uri);
contentHandler.startPrefixMapping (prefix, uri); contentHandler.startPrefixMapping(prefix, uri);
} }
void attribute (String qname, String value, boolean isSpecified) void attribute(String qname, String value, boolean isSpecified)
throws SAXException throws SAXException
{ {
if (!attributes) { if (!attributes)
{
attributes = true; attributes = true;
if (namespaces) if (namespaces)
prefixStack.pushContext (); {
prefixStack.pushContext();
}
} }
// process namespace decls immediately; // process namespace decls immediately;
// then maybe forget this as an attribute // then maybe forget this as an attribute
if (namespaces) { if (namespaces)
{
int index; int index;
// default NS declaration? // default NS declaration?
if (getFeature (FEATURE + "string-interning")) { if (stringInterning)
if ("xmlns" == qname) { {
declarePrefix ("", value); if ("xmlns" == qname)
{
declarePrefix("", value);
if (!xmlNames) if (!xmlNames)
{
return; return;
} }
}
// NS prefix declaration? // NS prefix declaration?
else if ((index = qname.indexOf (':')) == 5 else if ((index = qname.indexOf(':')) == 5
&& qname.startsWith ("xmlns")) { && qname.startsWith("xmlns"))
String prefix = qname.substring (6); {
String prefix = qname.substring(6);
if (prefix.equals("")) if (prefix.equals(""))
fatal ("missing prefix in namespace declaration attribute"); {
if (value.length () == 0) { fatal("missing prefix " +
verror ("missing URI in namespace declaration attribute: " "in namespace declaration attribute");
}
if (value.length() == 0)
{
verror("missing URI in namespace declaration attribute: "
+ qname); + qname);
} else }
declarePrefix (prefix, value); else
{
declarePrefix(prefix, value);
}
if (!xmlNames) if (!xmlNames)
{
return; return;
} }
} else { }
if ("xmlns".equals(qname)) { }
declarePrefix ("", value); else
{
if ("xmlns".equals(qname))
{
declarePrefix("", value);
if (!xmlNames) if (!xmlNames)
{
return; return;
} }
}
// NS prefix declaration? // NS prefix declaration?
else if ((index = qname.indexOf (':')) == 5 else if ((index = qname.indexOf(':')) == 5
&& qname.startsWith ("xmlns")) { && qname.startsWith("xmlns"))
String prefix = qname.substring (6); {
String prefix = qname.substring(6);
if (value.length () == 0) { if (value.length() == 0)
verror ("missing URI in namespace decl attribute: " {
verror("missing URI in namespace decl attribute: "
+ qname); + qname);
} else }
declarePrefix (prefix, value); else
{
declarePrefix(prefix, value);
}
if (!xmlNames) if (!xmlNames)
{
return; return;
} }
} }
} }
}
// remember this attribute ... // remember this attribute ...
attributeCount++; attributeCount++;
// attribute type comes from querying parser's DTD records // attribute type comes from querying parser's DTD records
...@@ -851,7 +1012,7 @@ final public class SAXDriver ...@@ -851,7 +1012,7 @@ final public class SAXDriver
} }
void startElement (String elname) void startElement(String elname)
throws SAXException throws SAXException
{ {
ContentHandler handler = contentHandler; ContentHandler handler = contentHandler;
...@@ -869,43 +1030,62 @@ final public class SAXDriver ...@@ -869,43 +1030,62 @@ final public class SAXDriver
// the context, and two chunks of name processing. // the context, and two chunks of name processing.
// //
if (!attributes) { if (!attributes)
{
if (namespaces) if (namespaces)
prefixStack.pushContext (); {
} else if (namespaces) { prefixStack.pushContext();
}
}
else if (namespaces)
{
// now we can patch up namespace refs; we saw all the // now we can patch up namespace refs; we saw all the
// declarations, so now we'll do the Right Thing // declarations, so now we'll do the Right Thing
Iterator itt = attributesList.iterator (); Iterator itt = attributesList.iterator();
while(itt.hasNext()) while (itt.hasNext())
{ {
Attribute attribute = (Attribute) itt.next(); Attribute attribute = (Attribute) itt.next();
String qname = attribute.name; String qname = attribute.name;
int index; int index;
// default NS declaration? // default NS declaration?
if (getFeature (FEATURE + "string-interning")) { if (stringInterning)
{
if ("xmlns" == qname) if ("xmlns" == qname)
{
continue; continue;
} else { }
}
else
{
if ("xmlns".equals(qname)) if ("xmlns".equals(qname))
{
continue; continue;
} }
}
//Illegal in the new Namespaces Draft //Illegal in the new Namespaces Draft
//should it be only in 1.1 docs?? //should it be only in 1.1 docs??
if (qname.equals (":")) if (qname.equals (":"))
fatal ("namespace names consisting of a single colon " + {
fatal("namespace names consisting of a single colon " +
"character are invalid"); "character are invalid");
index = qname.indexOf (':'); }
index = qname.indexOf(':');
// NS prefix declaration? // NS prefix declaration?
if (index == 5 && qname.startsWith ("xmlns")) if (index == 5 && qname.startsWith("xmlns"))
{
continue; continue;
}
// it's not a NS decl; patch namespace info items // it's not a NS decl; patch namespace info items
if (prefixStack.processName (qname, nsTemp, true) == null) if (prefixStack.processName(qname, nsTemp, true) == null)
fatal ("undeclared attribute prefix in: " + qname); {
else { fatal("undeclared attribute prefix in: " + qname);
}
else
{
attribute.nameSpace = nsTemp[0]; attribute.nameSpace = nsTemp[0];
attribute.localName = nsTemp[1]; attribute.localName = nsTemp[1];
} }
...@@ -914,87 +1094,98 @@ final public class SAXDriver ...@@ -914,87 +1094,98 @@ final public class SAXDriver
// save element name so attribute callbacks work // save element name so attribute callbacks work
elementName = elname; elementName = elname;
if (namespaces) { if (namespaces)
if (prefixStack.processName (elname, nsTemp, false) == null) { {
fatal ("undeclared element prefix in: " + elname); if (prefixStack.processName(elname, nsTemp, false) == null)
nsTemp [0] = nsTemp [1] = ""; {
} fatal("undeclared element prefix in: " + elname);
handler.startElement (nsTemp [0], nsTemp [1], elname, this); nsTemp[0] = nsTemp[1] = "";
} else }
handler.startElement ("", "", elname, this); handler.startElement(nsTemp[0], nsTemp[1], elname, this);
}
else
{
handler.startElement("", "", elname, this);
}
// elementName = null; // elementName = null;
// elements with no attributes are pretty common! // elements with no attributes are pretty common!
if (attributes) { if (attributes)
{
attributesList.clear(); attributesList.clear();
attributeCount = 0; attributeCount = 0;
attributes = false; attributes = false;
} }
} }
void endElement (String elname) void endElement(String elname)
throws SAXException throws SAXException
{ {
ContentHandler handler = contentHandler; ContentHandler handler = contentHandler;
if (!namespaces) { if (!namespaces)
handler.endElement ("", "", elname); {
handler.endElement("", "", elname);
return; return;
} }
prefixStack.processName (elname, nsTemp, false); prefixStack.processName(elname, nsTemp, false);
handler.endElement (nsTemp [0], nsTemp [1], elname); handler.endElement(nsTemp[0], nsTemp[1], elname);
Enumeration prefixes = prefixStack.getDeclaredPrefixes (); Enumeration prefixes = prefixStack.getDeclaredPrefixes();
while (prefixes.hasMoreElements ()) while (prefixes.hasMoreElements())
handler.endPrefixMapping ((String) prefixes.nextElement ()); {
prefixStack.popContext (); handler.endPrefixMapping((String) prefixes.nextElement());
}
prefixStack.popContext();
} }
void startCDATA () void startCDATA()
throws SAXException throws SAXException
{ {
lexicalHandler.startCDATA (); lexicalHandler.startCDATA();
} }
void charData (char ch[], int start, int length) void charData(char[] ch, int start, int length)
throws SAXException throws SAXException
{ {
contentHandler.characters (ch, start, length); contentHandler.characters(ch, start, length);
} }
void endCDATA () void endCDATA()
throws SAXException throws SAXException
{ {
lexicalHandler.endCDATA (); lexicalHandler.endCDATA();
} }
void ignorableWhitespace (char ch[], int start, int length) void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException throws SAXException
{ {
contentHandler.ignorableWhitespace (ch, start, length); contentHandler.ignorableWhitespace(ch, start, length);
} }
void processingInstruction (String target, String data) void processingInstruction(String target, String data)
throws SAXException throws SAXException
{ {
contentHandler.processingInstruction (target, data); contentHandler.processingInstruction(target, data);
} }
void comment (char ch[], int start, int length) void comment(char[] ch, int start, int length)
throws SAXException throws SAXException
{ {
if (lexicalHandler != base) if (lexicalHandler != base)
lexicalHandler.comment (ch, start, length); {
lexicalHandler.comment(ch, start, length);
}
} }
void fatal (String message) void fatal(String message)
throws SAXException throws SAXException
{ {
SAXParseException fatal; SAXParseException fatal;
fatal = new SAXParseException (message, this); fatal = new SAXParseException(message, this);
errorHandler.fatalError (fatal); errorHandler.fatalError(fatal);
// Even if the application can continue ... we can't! // Even if the application can continue ... we can't!
throw fatal; throw fatal;
...@@ -1002,25 +1193,24 @@ final public class SAXDriver ...@@ -1002,25 +1193,24 @@ final public class SAXDriver
// We can safely report a few validity errors that // We can safely report a few validity errors that
// make layered SAX2 DTD validation more conformant // make layered SAX2 DTD validation more conformant
void verror (String message) void verror(String message)
throws SAXException throws SAXException
{ {
SAXParseException err; SAXParseException err;
err = new SAXParseException (message, this); err = new SAXParseException(message, this);
errorHandler.error (err); errorHandler.error(err);
} }
void warn (String message) void warn(String message)
throws SAXException throws SAXException
{ {
SAXParseException err; SAXParseException err;
err = new SAXParseException (message, this); err = new SAXParseException(message, this);
errorHandler.warning (err); errorHandler.warning(err);
} }
// //
// Implementation of org.xml.sax.Attributes. // Implementation of org.xml.sax.Attributes.
// //
...@@ -1029,7 +1219,7 @@ final public class SAXDriver ...@@ -1029,7 +1219,7 @@ final public class SAXDriver
* <b>SAX1 AttributeList, SAX2 Attributes</b> method * <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser); * (don't invoke on parser);
*/ */
public int getLength () public int getLength()
{ {
return attributesList.size(); return attributesList.size();
} }
...@@ -1037,7 +1227,7 @@ final public class SAXDriver ...@@ -1037,7 +1227,7 @@ final public class SAXDriver
/** /**
* <b>SAX2 Attributes</b> method (don't invoke on parser); * <b>SAX2 Attributes</b> method (don't invoke on parser);
*/ */
public String getURI (int index) public String getURI(int index)
{ {
if (index < 0 || index >= attributesList.size()) if (index < 0 || index >= attributesList.size())
{ {
...@@ -1049,7 +1239,7 @@ final public class SAXDriver ...@@ -1049,7 +1239,7 @@ final public class SAXDriver
/** /**
* <b>SAX2 Attributes</b> method (don't invoke on parser); * <b>SAX2 Attributes</b> method (don't invoke on parser);
*/ */
public String getLocalName (int index) public String getLocalName(int index)
{ {
if (index < 0 || index >= attributesList.size()) if (index < 0 || index >= attributesList.size())
{ {
...@@ -1070,7 +1260,7 @@ final public class SAXDriver ...@@ -1070,7 +1260,7 @@ final public class SAXDriver
/** /**
* <b>SAX2 Attributes</b> method (don't invoke on parser); * <b>SAX2 Attributes</b> method (don't invoke on parser);
*/ */
public String getQName (int index) public String getQName(int index)
{ {
if (index < 0 || index >= attributesList.size()) if (index < 0 || index >= attributesList.size())
{ {
...@@ -1083,7 +1273,7 @@ final public class SAXDriver ...@@ -1083,7 +1273,7 @@ final public class SAXDriver
/** /**
* <b>SAX1 AttributeList</b> method (don't invoke on parser); * <b>SAX1 AttributeList</b> method (don't invoke on parser);
*/ */
public String getName (int index) public String getName(int index)
{ {
return getQName(index); return getQName(index);
} }
...@@ -1092,7 +1282,7 @@ final public class SAXDriver ...@@ -1092,7 +1282,7 @@ final public class SAXDriver
* <b>SAX1 AttributeList, SAX2 Attributes</b> method * <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser); * (don't invoke on parser);
*/ */
public String getType (int index) public String getType(int index)
{ {
if (index < 0 || index >= attributesList.size()) if (index < 0 || index >= attributesList.size())
{ {
...@@ -1111,12 +1301,11 @@ final public class SAXDriver ...@@ -1111,12 +1301,11 @@ final public class SAXDriver
return type; return type;
} }
/** /**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method * <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser); * (don't invoke on parser);
*/ */
public String getValue (int index) public String getValue(int index)
{ {
if (index < 0 || index >= attributesList.size()) if (index < 0 || index >= attributesList.size())
{ {
...@@ -1125,11 +1314,10 @@ final public class SAXDriver ...@@ -1125,11 +1314,10 @@ final public class SAXDriver
return ((Attribute) attributesList.get(index)).value; return ((Attribute) attributesList.get(index)).value;
} }
/** /**
* <b>SAX2 Attributes</b> method (don't invoke on parser); * <b>SAX2 Attributes</b> method (don't invoke on parser);
*/ */
public int getIndex (String uri, String local) public int getIndex(String uri, String local)
{ {
int length = getLength(); int length = getLength();
...@@ -1147,11 +1335,10 @@ final public class SAXDriver ...@@ -1147,11 +1335,10 @@ final public class SAXDriver
return -1; return -1;
} }
/** /**
* <b>SAX2 Attributes</b> method (don't invoke on parser); * <b>SAX2 Attributes</b> method (don't invoke on parser);
*/ */
public int getIndex (String xmlName) public int getIndex(String xmlName)
{ {
int length = getLength(); int length = getLength();
...@@ -1165,11 +1352,10 @@ final public class SAXDriver ...@@ -1165,11 +1352,10 @@ final public class SAXDriver
return -1; return -1;
} }
/** /**
* <b>SAX2 Attributes</b> method (don't invoke on parser); * <b>SAX2 Attributes</b> method (don't invoke on parser);
*/ */
public String getType (String uri, String local) public String getType(String uri, String local)
{ {
int index = getIndex(uri, local); int index = getIndex(uri, local);
...@@ -1180,12 +1366,11 @@ final public class SAXDriver ...@@ -1180,12 +1366,11 @@ final public class SAXDriver
return getType(index); return getType(index);
} }
/** /**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method * <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser); * (don't invoke on parser);
*/ */
public String getType (String xmlName) public String getType(String xmlName)
{ {
int index = getIndex(xmlName); int index = getIndex(xmlName);
...@@ -1196,11 +1381,10 @@ final public class SAXDriver ...@@ -1196,11 +1381,10 @@ final public class SAXDriver
return getType(index); return getType(index);
} }
/** /**
* <b>SAX Attributes</b> method (don't invoke on parser); * <b>SAX Attributes</b> method (don't invoke on parser);
*/ */
public String getValue (String uri, String local) public String getValue(String uri, String local)
{ {
int index = getIndex(uri, local); int index = getIndex(uri, local);
...@@ -1211,12 +1395,11 @@ final public class SAXDriver ...@@ -1211,12 +1395,11 @@ final public class SAXDriver
return getValue(index); return getValue(index);
} }
/** /**
* <b>SAX1 AttributeList, SAX2 Attributes</b> method * <b>SAX1 AttributeList, SAX2 Attributes</b> method
* (don't invoke on parser); * (don't invoke on parser);
*/ */
public String getValue (String xmlName) public String getValue(String xmlName)
{ {
int index = getIndex(xmlName); int index = getIndex(xmlName);
...@@ -1227,20 +1410,20 @@ final public class SAXDriver ...@@ -1227,20 +1410,20 @@ final public class SAXDriver
return getValue(index); return getValue(index);
} }
// //
// Implementation of org.xml.sax.ext.Attributes2 // Implementation of org.xml.sax.ext.Attributes2
// //
/** @return false unless the attribute was declared in the DTD. /** @return false unless the attribute was declared in the DTD.
* @throws java.lang.ArrayIndexOutOfBoundsException * @throws java.lang.ArrayIndexOutOfBoundsException
* When the supplied index does not identify an attribute. * When the supplied index does not identify an attribute.
*/ */
public boolean isDeclared (int index) public boolean isDeclared(int index)
{ {
if (index < 0 || index >= attributeCount) if (index < 0 || index >= attributeCount)
throw new ArrayIndexOutOfBoundsException (); {
throw new ArrayIndexOutOfBoundsException();
}
String type = parser.getAttributeType(elementName, getQName(index)); String type = parser.getAttributeType(elementName, getQName(index));
return (type != null); return (type != null);
} }
...@@ -1249,11 +1432,13 @@ final public class SAXDriver ...@@ -1249,11 +1432,13 @@ final public class SAXDriver
* @throws java.lang.IllegalArgumentException * @throws java.lang.IllegalArgumentException
* When the supplied names do not identify an attribute. * When the supplied names do not identify an attribute.
*/ */
public boolean isDeclared (String qName) public boolean isDeclared(String qName)
{ {
int index = getIndex (qName); int index = getIndex(qName);
if (index < 0) if (index < 0)
throw new IllegalArgumentException (); {
throw new IllegalArgumentException();
}
String type = parser.getAttributeType(elementName, qName); String type = parser.getAttributeType(elementName, qName);
return (type != null); return (type != null);
} }
...@@ -1262,17 +1447,16 @@ final public class SAXDriver ...@@ -1262,17 +1447,16 @@ final public class SAXDriver
* @throws java.lang.IllegalArgumentException * @throws java.lang.IllegalArgumentException
* When the supplied names do not identify an attribute. * When the supplied names do not identify an attribute.
*/ */
public boolean isDeclared (String uri, String localName) public boolean isDeclared(String uri, String localName)
{ {
int index = getIndex (uri, localName); int index = getIndex(uri, localName);
return isDeclared(index); return isDeclared(index);
} }
/** /**
* <b>SAX-ext Attributes2</b> method (don't invoke on parser); * <b>SAX-ext Attributes2</b> method (don't invoke on parser);
*/ */
public boolean isSpecified (int index) public boolean isSpecified(int index)
{ {
return ((Attribute) attributesList.get(index)).specified; return ((Attribute) attributesList.get(index)).specified;
} }
...@@ -1280,7 +1464,7 @@ final public class SAXDriver ...@@ -1280,7 +1464,7 @@ final public class SAXDriver
/** /**
* <b>SAX-ext Attributes2</b> method (don't invoke on parser); * <b>SAX-ext Attributes2</b> method (don't invoke on parser);
*/ */
public boolean isSpecified (String uri, String local) public boolean isSpecified(String uri, String local)
{ {
int index = getIndex (uri, local); int index = getIndex (uri, local);
return isSpecified(index); return isSpecified(index);
...@@ -1289,13 +1473,12 @@ final public class SAXDriver ...@@ -1289,13 +1473,12 @@ final public class SAXDriver
/** /**
* <b>SAX-ext Attributes2</b> method (don't invoke on parser); * <b>SAX-ext Attributes2</b> method (don't invoke on parser);
*/ */
public boolean isSpecified (String xmlName) public boolean isSpecified(String xmlName)
{ {
int index = getIndex (xmlName); int index = getIndex (xmlName);
return isSpecified(index); return isSpecified(index);
} }
// //
// Implementation of org.xml.sax.Locator. // Implementation of org.xml.sax.Locator.
// //
...@@ -1303,7 +1486,7 @@ final public class SAXDriver ...@@ -1303,7 +1486,7 @@ final public class SAXDriver
/** /**
* <b>SAX Locator</b> method (don't invoke on parser); * <b>SAX Locator</b> method (don't invoke on parser);
*/ */
public String getPublicId () public String getPublicId()
{ {
return null; // FIXME track public IDs too return null; // FIXME track public IDs too
} }
...@@ -1311,85 +1494,114 @@ final public class SAXDriver ...@@ -1311,85 +1494,114 @@ final public class SAXDriver
/** /**
* <b>SAX Locator</b> method (don't invoke on parser); * <b>SAX Locator</b> method (don't invoke on parser);
*/ */
public String getSystemId () public String getSystemId()
{
if (entityStack.empty())
{ {
if (entityStack.empty ())
return null; return null;
}
else else
return (String) entityStack.peek (); {
return (String) entityStack.peek();
}
} }
/** /**
* <b>SAX Locator</b> method (don't invoke on parser); * <b>SAX Locator</b> method (don't invoke on parser);
*/ */
public int getLineNumber () public int getLineNumber()
{ {
return parser.getLineNumber (); return parser.getLineNumber();
} }
/** /**
* <b>SAX Locator</b> method (don't invoke on parser); * <b>SAX Locator</b> method (don't invoke on parser);
*/ */
public int getColumnNumber () public int getColumnNumber()
{ {
return parser.getColumnNumber (); return parser.getColumnNumber();
} }
// adapter between SAX2 content handler and SAX1 document handler callbacks // adapter between SAX2 content handler and SAX1 document handler callbacks
private static class Adapter implements ContentHandler private static class Adapter
implements ContentHandler
{ {
private DocumentHandler docHandler;
Adapter (DocumentHandler dh) private DocumentHandler docHandler;
{ docHandler = dh; }
Adapter(DocumentHandler dh)
{
docHandler = dh;
}
public void setDocumentLocator (Locator l) public void setDocumentLocator(Locator l)
{ docHandler.setDocumentLocator (l); } {
docHandler.setDocumentLocator(l);
}
public void startDocument () throws SAXException public void startDocument()
{ docHandler.startDocument (); } throws SAXException
{
docHandler.startDocument();
}
public void processingInstruction (String target, String data) public void processingInstruction(String target, String data)
throws SAXException throws SAXException
{ docHandler.processingInstruction (target, data); } {
docHandler.processingInstruction(target, data);
}
public void startPrefixMapping (String prefix, String uri) public void startPrefixMapping(String prefix, String uri)
{ /* ignored */ } {
/* ignored */
}
public void startElement ( public void startElement(String namespace,
String namespace,
String local, String local,
String name, String name,
Attributes attrs Attributes attrs)
) throws SAXException throws SAXException
{ docHandler.startElement (name, (AttributeList) attrs); } {
docHandler.startElement(name, (AttributeList) attrs);
}
public void characters (char buf [], int offset, int len) public void characters(char[] buf, int offset, int len)
throws SAXException throws SAXException
{ docHandler.characters (buf, offset, len); } {
docHandler.characters(buf, offset, len);
}
public void ignorableWhitespace (char buf [], int offset, int len) public void ignorableWhitespace(char[] buf, int offset, int len)
throws SAXException throws SAXException
{ docHandler.ignorableWhitespace (buf, offset, len); } {
docHandler.ignorableWhitespace(buf, offset, len);
}
public void skippedEntity (String name) public void skippedEntity(String name)
{ /* ignored */ } {
/* ignored */
}
public void endElement (String u, String l, String name) public void endElement(String u, String l, String name)
throws SAXException throws SAXException
{ docHandler.endElement (name); } {
docHandler.endElement(name);
}
public void endPrefixMapping (String prefix) public void endPrefixMapping(String prefix)
{ /* ignored */ } {
/* ignored */
}
public void endDocument () throws SAXException public void endDocument()
{ docHandler.endDocument (); } throws SAXException
{
docHandler.endDocument();
}
} }
}
class Attribute private static class Attribute
{ {
String name; String name;
String value; String value;
...@@ -1404,5 +1616,7 @@ class Attribute ...@@ -1404,5 +1616,7 @@ class Attribute
this.nameSpace = ""; this.nameSpace = "";
this.specified = specified; this.specified = specified;
} }
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -70,136 +70,169 @@ import gnu.xml.pipeline.ValidationConsumer; ...@@ -70,136 +70,169 @@ import gnu.xml.pipeline.ValidationConsumer;
* *
* @author David Brownell * @author David Brownell
*/ */
public final class XmlReader implements XMLReader public final class XmlReader
implements XMLReader
{ {
private SAXDriver aelfred2 = new SAXDriver ();
private EventFilter filter = new EventFilter (); static class FatalErrorHandler
extends DefaultHandler2
{
public void error(SAXParseException e)
throws SAXException
{
throw e;
}
}
private SAXDriver aelfred2 = new SAXDriver();
private EventFilter filter = new EventFilter();
private boolean isValidating; private boolean isValidating;
private boolean active; private boolean active;
/**
/** Constructs a SAX Parser. */ * Constructs a SAX Parser.
public XmlReader () */
{ } public XmlReader()
{
}
/** /**
* Constructs a SAX Parser, optionally treating validity errors * Constructs a SAX Parser, optionally treating validity errors
* as if they were fatal errors. * as if they were fatal errors.
*/ */
public XmlReader (boolean invalidIsFatal) public XmlReader(boolean invalidIsFatal)
{ {
if (invalidIsFatal) if (invalidIsFatal)
setErrorHandler (new DefaultHandler2 () { {
public void error (SAXParseException e) setErrorHandler(new FatalErrorHandler());
throws SAXException }
{ throw e; }
});
} }
/** /**
* <b>SAX2</b>: Returns the object used to report the logical * <b>SAX2</b>: Returns the object used to report the logical
* content of an XML document. * content of an XML document.
*/ */
public ContentHandler getContentHandler () public ContentHandler getContentHandler()
{ return filter.getContentHandler (); } {
return filter.getContentHandler();
}
/** /**
* <b>SAX2</b>: Assigns the object used to report the logical * <b>SAX2</b>: Assigns the object used to report the logical
* content of an XML document. * content of an XML document.
* @exception IllegalStateException if called mid-parse * @exception IllegalStateException if called mid-parse
*/ */
public void setContentHandler (ContentHandler handler) public void setContentHandler(ContentHandler handler)
{ {
if (active) if (active)
throw new IllegalStateException ("already parsing"); {
filter.setContentHandler (handler); throw new IllegalStateException("already parsing");
}
filter.setContentHandler(handler);
} }
/** /**
* <b>SAX2</b>: Returns the object used to process declarations related * <b>SAX2</b>: Returns the object used to process declarations related
* to notations and unparsed entities. * to notations and unparsed entities.
*/ */
public DTDHandler getDTDHandler () public DTDHandler getDTDHandler()
{ return filter.getDTDHandler (); } {
return filter.getDTDHandler();
}
/** /**
* <b>SAX1</b> Assigns DTD handler * <b>SAX1</b> Assigns DTD handler
* @exception IllegalStateException if called mid-parse * @exception IllegalStateException if called mid-parse
*/ */
public void setDTDHandler (DTDHandler handler) public void setDTDHandler(DTDHandler handler)
{ {
if (active) if (active)
throw new IllegalStateException ("already parsing"); {
filter.setDTDHandler (handler); throw new IllegalStateException("already parsing");
}
filter.setDTDHandler(handler);
} }
/** /**
* <b>SAX2</b>: Returns the object used when resolving external * <b>SAX2</b>: Returns the object used when resolving external
* entities during parsing (both general and parameter entities). * entities during parsing (both general and parameter entities).
*/ */
public EntityResolver getEntityResolver () public EntityResolver getEntityResolver()
{ return aelfred2.getEntityResolver (); } {
return aelfred2.getEntityResolver();
}
/** <b>SAX1</b> Assigns parser's entity resolver */ /**
public void setEntityResolver (EntityResolver handler) * <b>SAX1</b> Assigns parser's entity resolver
{ aelfred2.setEntityResolver (handler); } */
public void setEntityResolver(EntityResolver handler)
{
aelfred2.setEntityResolver(handler);
}
/** /**
* <b>SAX2</b>: Returns the object used to receive callbacks for XML * <b>SAX2</b>: Returns the object used to receive callbacks for XML
* errors of all levels (fatal, nonfatal, warning); this is never null; * errors of all levels (fatal, nonfatal, warning); this is never null;
*/ */
public ErrorHandler getErrorHandler () public ErrorHandler getErrorHandler()
{ return aelfred2.getErrorHandler (); } {
return aelfred2.getErrorHandler();
}
/** /**
* <b>SAX1</b> Assigns error handler * <b>SAX1</b> Assigns error handler
* @exception IllegalStateException if called mid-parse * @exception IllegalStateException if called mid-parse
*/ */
public void setErrorHandler (ErrorHandler handler) public void setErrorHandler(ErrorHandler handler)
{ {
if (active) if (active)
throw new IllegalStateException ("already parsing"); {
aelfred2.setErrorHandler (handler); throw new IllegalStateException("already parsing");
}
aelfred2.setErrorHandler(handler);
} }
/** /**
* <b>SAX2</b>: Assigns the specified property. * <b>SAX2</b>: Assigns the specified property.
* @exception IllegalStateException if called mid-parse * @exception IllegalStateException if called mid-parse
*/ */
public void setProperty (String propertyId, Object value) public void setProperty(String propertyId, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
if (active) if (active)
throw new IllegalStateException ("already parsing"); {
if (getProperty (propertyId) != value) throw new IllegalStateException("already parsing");
filter.setProperty (propertyId, value); }
if (getProperty(propertyId) != value)
{
filter.setProperty(propertyId, value);
}
} }
/** /**
* <b>SAX2</b>: Returns the specified property. * <b>SAX2</b>: Returns the specified property.
*/ */
public Object getProperty (String propertyId) public Object getProperty(String propertyId)
throws SAXNotRecognizedException throws SAXNotRecognizedException
{ {
if ((SAXDriver.PROPERTY + "declaration-handler") if ((SAXDriver.PROPERTY + "declaration-handler").equals(propertyId)
.equals (propertyId) || (SAXDriver.PROPERTY + "lexical-handler").equals(propertyId))
|| (SAXDriver.PROPERTY + "lexical-handler") {
.equals (propertyId)) return filter.getProperty(propertyId);
return filter.getProperty (propertyId); }
throw new SAXNotRecognizedException (propertyId); throw new SAXNotRecognizedException(propertyId);
} }
private void forceValidating () private void forceValidating()
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
aelfred2.setFeature ( aelfred2.setFeature(SAXDriver.FEATURE + "namespace-prefixes",
SAXDriver.FEATURE + "namespace-prefixes",
true); true);
aelfred2.setFeature ( aelfred2.setFeature(SAXDriver.FEATURE + "external-general-entities",
SAXDriver.FEATURE + "external-general-entities",
true); true);
aelfred2.setFeature ( aelfred2.setFeature(SAXDriver.FEATURE + "external-parameter-entities",
SAXDriver.FEATURE + "external-parameter-entities",
true); true);
} }
...@@ -208,22 +241,32 @@ public final class XmlReader implements XMLReader ...@@ -208,22 +241,32 @@ public final class XmlReader implements XMLReader
* Note that this parser requires reporting of namespace prefixes when * Note that this parser requires reporting of namespace prefixes when
* validating. * validating.
*/ */
public void setFeature (String featureId, boolean state) public void setFeature(String featureId, boolean state)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
boolean value = getFeature (featureId); boolean value = getFeature(featureId);
if (state == value) if (state == value)
{
return; return;
}
if ((SAXDriver.FEATURE + "validation").equals (featureId)) { if ((SAXDriver.FEATURE + "validation").equals(featureId))
{
if (active) if (active)
throw new SAXNotSupportedException ("already parsing"); {
throw new SAXNotSupportedException("already parsing");
}
if (state) if (state)
forceValidating (); {
forceValidating();
}
isValidating = state; isValidating = state;
} else }
aelfred2.setFeature (featureId, state); else
{
aelfred2.setFeature(featureId, state);
}
} }
/** /**
...@@ -233,13 +276,15 @@ public final class XmlReader implements XMLReader ...@@ -233,13 +276,15 @@ public final class XmlReader implements XMLReader
* *
* @see SAXDriver * @see SAXDriver
*/ */
public boolean getFeature (String featureId) public boolean getFeature(String featureId)
throws SAXNotRecognizedException, SAXNotSupportedException throws SAXNotRecognizedException, SAXNotSupportedException
{ {
if ((SAXDriver.FEATURE + "validation").equals (featureId)) if ((SAXDriver.FEATURE + "validation").equals(featureId))
{
return isValidating; return isValidating;
}
return aelfred2.getFeature (featureId); return aelfred2.getFeature(featureId);
} }
/** /**
...@@ -247,18 +292,20 @@ public final class XmlReader implements XMLReader ...@@ -247,18 +292,20 @@ public final class XmlReader implements XMLReader
* only locales using the English language are supported. * only locales using the English language are supported.
* @param locale The locale for which diagnostics will be generated * @param locale The locale for which diagnostics will be generated
*/ */
public void setLocale (Locale locale) public void setLocale(Locale locale)
throws SAXException throws SAXException
{ aelfred2.setLocale (locale); } {
aelfred2.setLocale(locale);
}
/** /**
* <b>SAX1</b>: Preferred API to parse an XML document, using a * <b>SAX1</b>: Preferred API to parse an XML document, using a
* system identifier (URI). * system identifier (URI).
*/ */
public void parse (String systemId) public void parse(String systemId)
throws SAXException, IOException throws SAXException, IOException
{ {
parse (new InputSource (systemId)); parse(new InputSource(systemId));
} }
/** /**
...@@ -276,40 +323,52 @@ public final class XmlReader implements XMLReader ...@@ -276,40 +323,52 @@ public final class XmlReader implements XMLReader
* @exception IOException IOExceptions are normally through through * @exception IOException IOExceptions are normally through through
* the parser if there are problems reading the source document. * the parser if there are problems reading the source document.
*/ */
public void parse (InputSource source) public void parse(InputSource source)
throws SAXException, IOException throws SAXException, IOException
{ {
EventFilter next; EventFilter next;
boolean nsdecls; boolean nsdecls;
synchronized (aelfred2) { synchronized (aelfred2)
{
if (active) if (active)
throw new IllegalStateException ("already parsing"); {
throw new IllegalStateException("already parsing");
}
active = true; active = true;
} }
// set up the output pipeline // set up the output pipeline
if (isValidating) { if (isValidating)
forceValidating (); {
next = new ValidationConsumer (filter); forceValidating();
} else next = new ValidationConsumer(filter);
}
else
{
next = filter; next = filter;
}
// connect pipeline and error handler // connect pipeline and error handler
// don't let _this_ call to bind() affect xmlns* attributes // don't let _this_ call to bind() affect xmlns* attributes
nsdecls = aelfred2.getFeature ( nsdecls = aelfred2.getFeature(SAXDriver.FEATURE + "namespace-prefixes");
SAXDriver.FEATURE + "namespace-prefixes"); EventFilter.bind(aelfred2, next);
EventFilter.bind (aelfred2, next);
if (!nsdecls) if (!nsdecls)
aelfred2.setFeature ( {
SAXDriver.FEATURE + "namespace-prefixes", aelfred2.setFeature(SAXDriver.FEATURE + "namespace-prefixes",
false); false);
}
// parse, clean up // parse, clean up
try { try
aelfred2.parse (source); {
} finally { aelfred2.parse(source);
}
finally
{
active = false; active = false;
} }
} }
} }
...@@ -1686,13 +1686,16 @@ public abstract class DomNode ...@@ -1686,13 +1686,16 @@ public abstract class DomNode
{ {
continue; continue;
} }
if (count < notificationSet.length) if (count >= notificationSet.length)
{ {
notificationSet[count++] = rec; // very simple growth algorithm
int len = Math.max(notificationSet.length, 1);
ListenerRecord[] tmp = new ListenerRecord[len * 2];
System.arraycopy(notificationSet, 0, tmp, 0,
notificationSet.length);
notificationSet = tmp;
} }
else notificationSet[count++] = rec;
// XXX fire up some cheap growth algorithm
throw new RuntimeException("Event notification set size exceeded");
} }
// Notify just those listeners // Notify just those listeners
......
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