diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2007-02-27 09:16:14 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2007-02-27 09:16:14 +0000 |
commit | aa1c8ff8ba92eedc86fec8c85a349ab6e529c6d6 (patch) | |
tree | d217db8b3abc8cd5e8a8da56ac247ac2f032f6dd /src | |
parent | fb98aa33d9f7f3b1370e1256301419d389b80bad (diff) | |
download | xmlgraphics-fop-aa1c8ff8ba92eedc86fec8c85a349ab6e529c6d6.tar.gz xmlgraphics-fop-aa1c8ff8ba92eedc86fec8c85a349ab6e529c6d6.zip |
Add an ending slash to base URLs when they don't have one, in order to better match user expectations.
Submitted by: Adrian Cumiskey (fop-dev AT cumiskey DOT com)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@512185 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/apps/FOURIResolver.java | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/apps/FOURIResolver.java b/src/java/org/apache/fop/apps/FOURIResolver.java index db0cae75e..5b66ffa57 100644 --- a/src/java/org/apache/fop/apps/FOURIResolver.java +++ b/src/java/org/apache/fop/apps/FOURIResolver.java @@ -87,7 +87,12 @@ public class FOURIResolver log.error("Could not convert filename to URL: " + mfue.getMessage()); } } else { - URL baseURL = toBaseURL(base); + URL baseURL = null; + try { + baseURL = toBaseURL(base); + } catch (MalformedURLException mfue) { + log.error("Error with base URL \"" + base + "\"): " + mfue.getMessage()); + } if (baseURL == null) { // We don't have a valid baseURL just use the URL as given try { @@ -155,7 +160,7 @@ public class FOURIResolver //Note: This is on "debug" level since the caller is supposed to handle this log.debug("File not found: " + effURL); } catch (java.io.IOException ioe) { - log.error("Error with opening URL '" + href + "': " + ioe.getMessage()); + log.error("Error with opening URL '" + effURL + "': " + ioe.getMessage()); } return null; } @@ -201,15 +206,20 @@ public class FOURIResolver * @param baseURL the base URL * @returns the base URL as java.net.URL */ - private URL toBaseURL(String baseURL) { - try { - return new URL(baseURL == null - ? new java.io.File("").toURL().toExternalForm() - : baseURL); - } catch (MalformedURLException mfue) { - log.error("Error with base URL \"" + baseURL + "\"): " + mfue.getMessage()); + private URL toBaseURL(String base) throws MalformedURLException { + if (base == null) { + return new java.io.File("").toURL(); } - return null; + if (!base.endsWith("/")) { + // The behavior described by RFC 3986 regarding resolution of relative + // references may be misleading for normal users: + // file://path/to/resources + myResource.res -> file://path/to/myResource.res + // file://path/to/resources/ + myResource.res -> file://path/to/resources/myResource.res + // We assume that even when the ending slash is missing, users have the second + // example in mind + base += "/"; + } + return new URL(base); } /** |