? gnu/xml/validation Index: gnu/xml/stream/SAXParser.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/stream/SAXParser.java,v retrieving revision 1.16 diff -u -r1.16 SAXParser.java --- gnu/xml/stream/SAXParser.java 23 Jan 2006 09:17:16 -0000 1.16 +++ gnu/xml/stream/SAXParser.java 31 Jan 2006 14:55:13 -0000 @@ -904,7 +904,16 @@ InputSource input = entityResolver.resolveEntity(publicId, systemId); if (input != null) - return input.getByteStream(); + { + InputStream in = input.getByteStream(); + if (in == null) + { + String newSystemId = input.getSystemId(); + if (newSystemId != null && !newSystemId.equals(systemId)) + in = XMLParser.resolve(newSystemId); + } + return in; + } } catch (SAXException e) { Index: gnu/xml/stream/UnicodeReader.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/stream/UnicodeReader.java,v retrieving revision 1.2 diff -u -r1.2 UnicodeReader.java --- gnu/xml/stream/UnicodeReader.java 8 Jan 2006 21:47:03 -0000 1.2 +++ gnu/xml/stream/UnicodeReader.java 31 Jan 2006 14:55:13 -0000 @@ -45,7 +45,7 @@ * * @author Chris Burdess */ -class UnicodeReader +public class UnicodeReader { final Reader in; Index: gnu/xml/stream/XIncludeFilter.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/stream/XIncludeFilter.java,v retrieving revision 1.5 diff -u -r1.5 XIncludeFilter.java --- gnu/xml/stream/XIncludeFilter.java 7 Jan 2006 15:57:45 -0000 1.5 +++ gnu/xml/stream/XIncludeFilter.java 31 Jan 2006 14:55:13 -0000 @@ -42,6 +42,7 @@ 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; @@ -121,7 +122,17 @@ boolean expandERefs) { super(reader); - this.systemId = XMLParser.absolutize(null, systemId); + try + { + this.systemId = XMLParser.absolutize(null, systemId); + } + catch (MalformedURLException e) + { + RuntimeException e2 = new RuntimeException("unsupported URL: " + + systemId); + e2.initCause(e); + throw e2; + } this.namespaceAware = namespaceAware; this.validating = validating; this.expandERefs = expandERefs; Index: gnu/xml/stream/XMLParser.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/xml/stream/XMLParser.java,v retrieving revision 1.22 diff -u -r1.22 XMLParser.java --- gnu/xml/stream/XMLParser.java 16 Jan 2006 16:23:20 -0000 1.22 +++ gnu/xml/stream/XMLParser.java 31 Jan 2006 14:55:13 -0000 @@ -1484,7 +1484,6 @@ { if (!externalEntities) return; - InputStream in = null; String url = absolutize(input.systemId, ids.systemId); // Check for recursion for (Iterator i = inputStack.iterator(); i.hasNext(); ) @@ -1497,7 +1496,8 @@ } if (name == null || "".equals(name)) report = false; - if (in == null && url != null && resolver != null) + InputStream in = null; + if (resolver != null) { if (resolver instanceof XMLResolver2) in = ((XMLResolver2) resolver).resolve(ids.publicId, url); @@ -1535,12 +1535,13 @@ * @param base the current base URL * @param href the (absolute or relative) URL to resolve */ - static String absolutize(String base, String href) + public static String absolutize(String base, String href) + throws MalformedURLException { if (href == null) return null; int ci = href.indexOf(':'); - if (ci > 1 && isLowercaseAscii(href.substring(0, ci))) + if (ci > 1 && isURLScheme(href.substring(0, ci))) { // href is absolute already return href; @@ -1565,40 +1566,23 @@ if (!base.endsWith("/")) base += "/"; } - if (href.startsWith("/")) - { - if (base.startsWith("file:")) - return "file://" + href; - int i = base.indexOf("://"); - if (i != -1) - { - i = base.indexOf('/', i + 3); - if (i != -1) - base = base.substring(0, i); - } - } - else - { - while (href.startsWith("..")) - { - int i = base.lastIndexOf('/', base.length() - 2); - if (i != -1) - base = base.substring(0, i + 1); - href = href.substring(2); - if (href.startsWith("/")) - href = href.substring(1); - } - } - return base + href; + return new URL(new URL(base), href).toString(); } - private static boolean isLowercaseAscii(String text) + /** + * Indicates whether the specified characters match the scheme portion of + * a URL. + * @see RFC 1738 section 2.1 + */ + private static boolean isURLScheme(String text) { int len = text.length(); for (int i = 0; i < len; i++) { char c = text.charAt(i); - if (c < 97 || c > 122) + if (c == '+' || c == '.' || c == '-') + continue; + if (c < 65 || (c > 90 && c < 97) || c > 122) return false; } return true; @@ -1607,7 +1591,7 @@ /** * Returns an input stream for the given URL. */ - private InputStream resolve(String url) + static InputStream resolve(String url) throws IOException { try @@ -1618,6 +1602,12 @@ { return null; } + catch (IOException e) + { + IOException e2 = new IOException("error resolving " + url); + e2.initCause(e); + throw e2; + } } /**