diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-03-10 16:16:31 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-03-10 16:16:31 +0000 |
commit | 095587e4686e38529186856ba87f0553b0fa4981 (patch) | |
tree | 4157c69e9233f52720a0169aebc0d1ea0af64d20 /src/java | |
parent | 1914db175fda0d8776f686cf8409ddf4a5d6e5e6 (diff) | |
download | xmlgraphics-fop-095587e4686e38529186856ba87f0553b0fa4981.tar.gz xmlgraphics-fop-095587e4686e38529186856ba87f0553b0fa4981.zip |
Restored ability to specify any URI base URI (URL), not just file URLs. For file URLs and file paths there's still a check whether the directory exists.
Enabled FontBaseBadTestCase.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@752153 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/fop/apps/FOURIResolver.java | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/java/org/apache/fop/apps/FOURIResolver.java b/src/java/org/apache/fop/apps/FOURIResolver.java index 58f527abe..f96711d31 100644 --- a/src/java/org/apache/fop/apps/FOURIResolver.java +++ b/src/java/org/apache/fop/apps/FOURIResolver.java @@ -24,6 +24,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -32,8 +34,10 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamSource; +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.apache.xmlgraphics.util.io.Base64EncodeStream; import org.apache.xmlgraphics.util.uri.CommonURIResolver; @@ -74,20 +78,31 @@ public class FOURIResolver implements javax.xml.transform.URIResolver { base += "/"; } File dir = new File(base); - try { - base = (dir.isDirectory() ? dir.toURI().toURL() : new URL(base)).toExternalForm(); - } catch (MalformedURLException mfue) { - String message = mfue.getMessage(); - if (!dir.isDirectory()) { - message = "base " + base + " is not a directory and not a valid URL: " + message; - mfue = new MalformedURLException(message); + if (dir.isDirectory()) { + return dir.toURI().toASCIIString(); + } else { + URI baseURI; + try { + baseURI = new URI(base); + String scheme = baseURI.getScheme(); + boolean directoryExists = true; + if ("file".equals(scheme)) { + dir = FileUtils.toFile(baseURI.toURL()); + directoryExists = dir.isDirectory(); + } + if (scheme == null || !directoryExists) { + String message = "base " + base + " is not a valid directory"; + if (throwExceptions) { + throw new MalformedURLException(message); + } + log.error(message); + } + return baseURI.toASCIIString(); + } catch (URISyntaxException e) { + //TODO not ideal: our base URLs are actually base URIs. + throw new MalformedURLException(e.getMessage()); } - if (throwExceptions) { - throw mfue; - } - log.error(message); } - return base; } /** |