summaryrefslogtreecommitdiff
path: root/gnu/xml/stream/XMLParser.java
diff options
context:
space:
mode:
authorChris Burdess <dog@bluezoo.org>2007-02-06 10:10:44 +0000
committerChris Burdess <dog@bluezoo.org>2007-02-06 10:10:44 +0000
commitcf12e2e28924d702a73f9115582c35853b777bb2 (patch)
tree52426a6331d902341b8ef0620e686f6b66a6020c /gnu/xml/stream/XMLParser.java
parent8ec89110843ddbd32e8f4abcf4d515ca9972655e (diff)
downloadclasspath-cf12e2e28924d702a73f9115582c35853b777bb2.tar.gz
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.
Diffstat (limited to 'gnu/xml/stream/XMLParser.java')
-rw-r--r--gnu/xml/stream/XMLParser.java56
1 files changed, 54 insertions, 2 deletions
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;
}
/**