[kaffe] Unwanted SAXParseException
Ito Kazumitsu
kaz at maczuka.gcd.org
Fri Oct 17 17:15:03 PDT 2003
Hi,
I found a case where GNU JAXP throws unwanted SAXParseExceptions.
The test case is attached below. When using Sun's JAXP or
Xerces, such exceptions are not thrown.
Also attached is my suggested patch, which I am going to
apply to the source imported to Kaffe.
bash-2.05b$ cat TestEntityResolver.java
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import java.net.URL;
import java.io.File;
public class TestEntityResolver {
public static void main(String[] args) throws Exception {
String url = (new File(args[0])).toURL().toString();
SAXParserFactory factory = SAXParserFactory.newInstance();
XMLReader xr = factory.newSAXParser().getXMLReader();
xr.setErrorHandler(new MyHandler());
xr.setEntityResolver(new MyResolver());
try {
xr.parse(url);
}
catch (SAXParseException e) {
System.err.println(e);
}
}
private static class MyResolver implements EntityResolver {
public InputSource resolveEntity (String publicId, String systemId) {
try {
return new InputSource((new URL(systemId)).openStream());
}
catch (Exception e) {
return null;
}
}
}
private static class MyHandler extends DefaultHandler {
public void warning(SAXParseException e) {
System.err.println(e);
}
}
}
bash-2.05b$ cat test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Test PUBLIC "" "test.dtd">
<Test />
bash-2.05b$ cat test.dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT Test (A)* >
bash-2.05b$ java TestEntityResolver test.xml
org.xml.sax.SAXParseException: URI was not reported to parser for entity [dtd]
org.xml.sax.SAXParseException: missing system ID, using test.dtd
And here is my patch:
bash-2.05b$ diff -u gnu/xml/aelfred2/SAXDriver.java.orig gnu/xml/aelfred2/SAXDriver.java
--- gnu/xml/aelfred2/SAXDriver.java.orig Sat Oct 18 08:37:57 2003
+++ gnu/xml/aelfred2/SAXDriver.java Sat Oct 18 08:43:42 2003
@@ -596,6 +596,8 @@
in.getSystemId ());
if (source == null)
source = in;
+ else if (source.getSystemId () == null)
+ source.setSystemId (in.getSystemId ());
}
startExternalEntity (name, source.getSystemId (), true);
return source;
More information about the kaffe
mailing list