]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2861: Allow resource loading from jar
authorSimon Steiner <ssteiner@apache.org>
Mon, 5 Sep 2022 08:54:25 +0000 (08:54 +0000)
committerSimon Steiner <ssteiner@apache.org>
Mon, 5 Sep 2022 08:54:25 +0000 (08:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1903877 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java

index a6fbfafc9749235e4061c8c950737153e67605a4..470f2e4ba7a0dd25a974f4ecae19630767003585 100644 (file)
@@ -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);
+        }
     }
 
     /**
index c5dee2f7c8695df199ee60e55edb4a8ee8d099b0..5bab320f68ccb1149174e392d1e2a07ceef0a3b6 100644 (file)
@@ -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");
+    }
 }