summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--gnu/xml/dom/DomDocumentBuilderFactory.java35
-rw-r--r--gnu/xml/stream/XIncludeFilter.java13
-rw-r--r--gnu/xml/stream/XMLParser.java56
4 files changed, 98 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 06fb192a5..6ccae2488 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-02-06 Chris Burdess <dog@gnu.org>
+
+ Fixes PR 27710.
+ * gnu/xml/dom/DomDocumentBuilderFactory.java: Fall back to synchronous
+ LSParser if implementation does not support asynchronous.
+ * gnu/xml/stream/XMLParser.java,
+ gnu/xml/stream/XIncludeFilter.java: Use custom code instead of
+ java.net.URL to resolve to an an absolute URI, to avoid nonexistent
+ protocol handler problems.
+
2007-02-05 Andrew Haley <aph@redhat.com>
PR cp-tools/30706
diff --git a/gnu/xml/dom/DomDocumentBuilderFactory.java b/gnu/xml/dom/DomDocumentBuilderFactory.java
index 023478580..4d2828af8 100644
--- a/gnu/xml/dom/DomDocumentBuilderFactory.java
+++ b/gnu/xml/dom/DomDocumentBuilderFactory.java
@@ -43,6 +43,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMConfiguration;
+import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
@@ -84,8 +85,38 @@ public class DomDocumentBuilderFactory
public DocumentBuilder newDocumentBuilder()
throws ParserConfigurationException
{
- LSParser parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS,
- "http://www.w3.org/TR/REC-xml");
+ LSParser parser = null;
+ try
+ {
+ parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS,
+ "http://www.w3.org/TR/REC-xml");
+ }
+ catch (DOMException e)
+ {
+ if (e.code == DOMException.NOT_SUPPORTED_ERR)
+ {
+ // Fall back to synchronous parser
+ try
+ {
+ parser = ls.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
+ "http://www.w3.org/TR/REC-xml");
+ }
+ catch (DOMException e2)
+ {
+ ParserConfigurationException pce =
+ new ParserConfigurationException();
+ pce.initCause(e2);
+ throw pce;
+ }
+ }
+ else
+ {
+ ParserConfigurationException pce =
+ new ParserConfigurationException();
+ pce.initCause(e);
+ throw pce;
+ }
+ }
DOMConfiguration config = parser.getDomConfig();
setParameter(config, "namespaces",
isNamespaceAware() ? Boolean.TRUE : Boolean.FALSE);
diff --git a/gnu/xml/stream/XIncludeFilter.java b/gnu/xml/stream/XIncludeFilter.java
index 7e707820d..86961faea 100644
--- a/gnu/xml/stream/XIncludeFilter.java
+++ b/gnu/xml/stream/XIncludeFilter.java
@@ -42,7 +42,6 @@ import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashSet;
@@ -122,17 +121,7 @@ class XIncludeFilter
boolean expandERefs)
{
super(reader);
- try
- {
- this.systemId = XMLParser.absolutize(null, systemId);
- }
- catch (MalformedURLException e)
- {
- RuntimeException e2 = new RuntimeException("unsupported URL: " +
- systemId);
- e2.initCause(e);
- throw e2;
- }
+ this.systemId = XMLParser.absolutize(null, systemId);
this.namespaceAware = namespaceAware;
this.validating = validating;
this.expandERefs = expandERefs;
diff --git a/gnu/xml/stream/XMLParser.java b/gnu/xml/stream/XMLParser.java
index ef3779944..663a300f8 100644
--- a/gnu/xml/stream/XMLParser.java
+++ b/gnu/xml/stream/XMLParser.java
@@ -1592,7 +1592,6 @@ public class XMLParser
* @param href the (absolute or relative) URL to resolve
*/
public static String absolutize(String base, String href)
- throws MalformedURLException
{
if (href == null)
return null;
@@ -1622,7 +1621,60 @@ public class XMLParser
if (!base.endsWith("/"))
base += "/";
}
- return new URL(new URL(base), href).toString();
+ // We can't use java.net.URL here to do the parsing, as it searches for
+ // a protocol handler. A protocol handler may not be registered for the
+ // URL scheme here. Do it manually.
+ //
+ // Set aside scheme and host portion of base URL
+ String basePrefix = null;
+ ci = base.indexOf(':');
+ if (ci > 1 && isURLScheme(base.substring(0, ci)))
+ {
+ if (base.length() > (ci + 3) &&
+ base.charAt(ci + 1) == '/' &&
+ base.charAt(ci + 2) == '/')
+ {
+ int si = base.indexOf('/', ci + 3);
+ if (si == -1)
+ base = null;
+ else
+ {
+ basePrefix = base.substring(0, si);
+ base = base.substring(si);
+ }
+ }
+ else
+ base = null;
+ }
+ if (base == null) // unknown or malformed base URL, use href
+ return href;
+ if (href.startsWith("/")) // absolute href pathname
+ return (basePrefix == null) ? href : basePrefix + href;
+ // relative href pathname
+ if (!base.endsWith("/"))
+ {
+ int lsi = base.lastIndexOf('/');
+ if (lsi == -1)
+ base = "/";
+ else
+ base = base.substring(0, lsi + 1);
+ }
+ while (href.startsWith("../") || href.startsWith("./"))
+ {
+ if (href.startsWith("../"))
+ {
+ // strip last path component from base
+ int lsi = base.lastIndexOf('/', base.length() - 2);
+ if (lsi > -1)
+ base = base.substring(0, lsi + 1);
+ href = href.substring(3); // strip ../ prefix
+ }
+ else
+ {
+ href = href.substring(2); // strip ./ prefix
+ }
+ }
+ return (basePrefix == null) ? base + href : basePrefix + base + href;
}
/**