aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/apps/FOURIResolver.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/apps/FOURIResolver.java')
-rw-r--r--src/java/org/apache/fop/apps/FOURIResolver.java39
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;
}
/**