summaryrefslogtreecommitdiffstats
path: root/fop-core/src
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2022-09-05 08:54:25 +0000
committerSimon Steiner <ssteiner@apache.org>2022-09-05 08:54:25 +0000
commitb76f5ecf37ff2548cbc2d4700baefaf15d69559c (patch)
treeaf726398d721bfd74225a75cda718d316cef4303 /fop-core/src
parent48731c7b37ff54b5b0b3c89d5a85f3f9a49f387d (diff)
downloadxmlgraphics-fop-b76f5ecf37ff2548cbc2d4700baefaf15d69559c.tar.gz
xmlgraphics-fop-b76f5ecf37ff2548cbc2d4700baefaf15d69559c.zip
FOP-2861: Allow resource loading from jar
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1903877 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src')
-rw-r--r--fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java8
-rw-r--r--fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java17
2 files changed, 18 insertions, 7 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java b/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
index a6fbfafc9..470f2e4ba 100644
--- a/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
+++ b/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
@@ -22,8 +22,10 @@ package org.apache.fop.apps.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
@@ -110,7 +112,11 @@ public class InternalResourceResolver {
* @return the resolved URI
*/
public URI resolveFromBase(URI uri) {
- return baseUri.resolve(uri);
+ try {
+ return new URL(baseUri.toURL(), uri.toString()).toURI();
+ } catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) {
+ return baseUri.resolve(uri);
+ }
}
/**
diff --git a/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java b/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
index c5dee2f7c..5bab320f6 100644
--- a/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
@@ -46,12 +46,10 @@ import org.apache.xmlgraphics.util.io.Base64EncodeStream;
public class URIResolverWrapperTestCase {
private static final List<String> BASE_URIS = Collections.unmodifiableList(Arrays.asList(
- new String[] {
- ".",
- "../",
- "some/path",
- "file:///absolute/file/path"}
- ));
+ ".",
+ "../",
+ "some/path",
+ "file:///absolute/file/path"));
private URI base;
@@ -151,4 +149,11 @@ public class URIResolverWrapperTestCase {
// PASS
}
}
+
+ @Test
+ public void testJarUri() {
+ URI uri = new InternalResourceResolver(URI.create("jar:file:/home/my.jar!/fop.xconf"), null)
+ .resolveFromBase(URI.create("x"));
+ assertEquals(uri.toString(), "jar:file:/home/my.jar!/x");
+ }
}