]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Moved the I/O interfaces to XGC and updated code with new resolution mechanism
authorMehdi Houshmand <mehdi@apache.org>
Wed, 19 Sep 2012 15:37:57 +0000 (15:37 +0000)
committerMehdi Houshmand <mehdi@apache.org>
Wed, 19 Sep 2012 15:37:57 +0000 (15:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_XGC_URI_Resolution@1387645 13f79535-47bb-0310-9956-ffa450edef68

31 files changed:
examples/plan/src/org/apache/fop/plan/PreloaderPlan.java
src/java/org/apache/fop/afp/AFPStreamer.java
src/java/org/apache/fop/apps/EnvironmentProfile.java
src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java
src/java/org/apache/fop/apps/FOUserAgent.java
src/java/org/apache/fop/apps/FopConfParser.java
src/java/org/apache/fop/apps/FopFactory.java
src/java/org/apache/fop/apps/FopFactoryBuilder.java
src/java/org/apache/fop/apps/FopFactoryConfig.java
src/java/org/apache/fop/apps/io/InternalResourceResolver.java
src/java/org/apache/fop/apps/io/Resource.java [deleted file]
src/java/org/apache/fop/apps/io/ResourceResolver.java [deleted file]
src/java/org/apache/fop/apps/io/ResourceResolverFactory.java
src/java/org/apache/fop/apps/io/TempResourceResolver.java [deleted file]
src/java/org/apache/fop/apps/io/TempResourceURIGenerator.java [deleted file]
src/java/org/apache/fop/area/CachedRenderPagesModel.java
src/java/org/apache/fop/fonts/FontManagerConfigurator.java
src/java/org/apache/fop/image/loader/batik/PreloaderSVG.java
src/java/org/apache/fop/image/loader/batik/PreloaderWMF.java
src/java/org/apache/fop/render/ps/PSDocumentHandler.java
src/java/org/apache/fop/servlet/FopServlet.java
test/java/org/apache/fop/URIResolutionTestCase.java
test/java/org/apache/fop/apps/EnvironmentalProfileFactoryTestCase.java
test/java/org/apache/fop/apps/MutableConfig.java
test/java/org/apache/fop/apps/io/BaseURIResolutionTest.java
test/java/org/apache/fop/apps/io/FontURIResolver.java
test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java
test/java/org/apache/fop/apps/io/TestingResourceResolver.java
test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
test/java/org/apache/fop/intermediate/TestAssistant.java
test/java/org/apache/fop/pdf/PDFFactoryTestCase.java

index 8544ce544c012956d4a57f0d762811f432198f80..d88658c37b160728b93dfff16260c4d4085f103a 100644 (file)
@@ -43,6 +43,7 @@ import org.apache.xmlgraphics.image.loader.ImageSize;
 import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader;
 import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
 import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.io.XmlSourceUtil;
 
 import org.apache.fop.util.DefaultErrorListener;
 import org.apache.fop.util.UnclosableInputStream;
index fb2b282f6be9d310db703f058464475a8b4d4d07..5e6b5a79e04b776a68a80d6d4f8e249da3c29118 100644 (file)
@@ -32,10 +32,11 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.io.TempResourceURIGenerator;
+
 import org.apache.fop.afp.modca.ResourceGroup;
 import org.apache.fop.afp.modca.StreamedResourceGroup;
 import org.apache.fop.apps.io.InternalResourceResolver;
-import org.apache.fop.apps.io.TempResourceURIGenerator;
 
 /**
  * Manages the streaming of the AFP output
index c964120e35a3eb9b4ced1b99bb8fe2fc05ca337c..1a585353e8c3e8c3fcc0b704a8654dbc03744dc9 100644 (file)
@@ -21,7 +21,9 @@ package org.apache.fop.apps;
 
 import java.net.URI;
 
-import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.fonts.FontManager;
 
 /**
@@ -52,4 +54,7 @@ public interface EnvironmentProfile {
      * @return the default base URI
      */
     URI getDefaultBaseURI();
+
+    /** @see FopFactoryConfig#getFallbackResolver() */
+    FallbackResolver getFallbackResolver();
 }
index 9ba7632d248c6fc8a2bff99bcfdc404e018ee9e1..922ecff4bf3ac11185ba8d5782775ae1ba8e9bbb 100644 (file)
@@ -21,8 +21,12 @@ package org.apache.fop.apps;
 
 import java.net.URI;
 
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.RestrictedFallbackResolver;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.UnrestrictedFallbackResolver;
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.io.InternalResourceResolver;
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.FontCacheManager;
 import org.apache.fop.fonts.FontCacheManagerFactory;
@@ -51,7 +55,8 @@ public final class EnvironmentalProfileFactory {
         return new Profile(defaultBaseUri, resourceResolver,
                 createFontManager(defaultBaseUri, resourceResolver,
                         FontDetectorFactory.createDefault(),
-                        FontCacheManagerFactory.createDefault()));
+                        FontCacheManagerFactory.createDefault()),
+                new UnrestrictedFallbackResolver());
     }
 
     /**
@@ -67,7 +72,8 @@ public final class EnvironmentalProfileFactory {
         return new Profile(defaultBaseUri, resourceResolver,
                 createFontManager(defaultBaseUri, resourceResolver,
                         FontDetectorFactory.createDisabled(),
-                        FontCacheManagerFactory.createDisabled()));
+                        FontCacheManagerFactory.createDisabled()),
+                new RestrictedFallbackResolver());
     }
 
     private static final class Profile implements EnvironmentProfile {
@@ -78,8 +84,10 @@ public final class EnvironmentalProfileFactory {
 
         private final URI defaultBaseURI;
 
+        private final FallbackResolver fallbackResolver;
+
         private Profile(URI defaultBaseURI, ResourceResolver resourceResolver,
-                FontManager fontManager) {
+                FontManager fontManager, FallbackResolver fallbackResolver) {
             if (defaultBaseURI == null) {
                 throw new IllegalArgumentException("Default base URI must not be null");
             }
@@ -92,6 +100,7 @@ public final class EnvironmentalProfileFactory {
             this.defaultBaseURI = defaultBaseURI;
             this.resourceResolver = resourceResolver;
             this.fontManager = fontManager;
+            this.fallbackResolver = fallbackResolver;
         }
 
         public ResourceResolver getResourceResolver() {
@@ -105,6 +114,10 @@ public final class EnvironmentalProfileFactory {
         public URI getDefaultBaseURI() {
             return defaultBaseURI;
         }
+
+        public FallbackResolver getFallbackResolver() {
+            return fallbackResolver;
+        }
     }
 
     private static FontManager createFontManager(URI defaultBaseUri, ResourceResolver resourceResolver,
index 0ed5b722802a797ee2333beb4ffd71428c18cb4b..68064343eccd7a4274bbcb35a21ace8ebaa56ef7 100644 (file)
@@ -131,21 +131,7 @@ public class FOUserAgent {
     /** Set of keywords applicable to this document. */
     protected String keywords = null;
 
-    private ImageSessionContext imageSessionContext = new AbstractImageSessionContext() {
-
-        public ImageContext getParentContext() {
-            return factory;
-        }
-
-        public float getTargetResolution() {
-            return FOUserAgent.this.getTargetResolution();
-        }
-
-        public Source resolveURI(String uri) {
-            return FOUserAgent.this.resolveURI(uri);
-        }
-
-    };
+    private final ImageSessionContext imageSessionContext;
 
     /**
      * Main constructor. <b>This constructor should not be called directly. Please use the
@@ -154,11 +140,25 @@ public class FOUserAgent {
      * @param resourceResolver the resolver used to acquire resources
      * @see org.apache.fop.apps.FopFactory
      */
-    FOUserAgent(FopFactory factory, InternalResourceResolver resourceResolver) {
+    FOUserAgent(final FopFactory factory, InternalResourceResolver resourceResolver) {
         this.factory = factory;
         this.resourceResolver = resourceResolver;
         setTargetResolution(factory.getTargetResolution());
         setAccessibility(factory.isAccessibilityEnabled());
+        imageSessionContext = new AbstractImageSessionContext(factory.getFallbackResolver()) {
+
+            public ImageContext getParentContext() {
+                return factory;
+            }
+
+            public float getTargetResolution() {
+                return FOUserAgent.this.getTargetResolution();
+            }
+
+            public Source resolveURI(String uri) {
+                return FOUserAgent.this.resolveURI(uri);
+            }
+        };
     }
 
     /**
index c6e3dbd19cc5ff32ecf7bad159971290e7fbbcf1..b4918ef3080128f5d6b9ccdc5713046c0b14cfda 100644 (file)
@@ -39,9 +39,9 @@ import org.apache.commons.logging.LogFactory;
 
 import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry;
 import org.apache.xmlgraphics.image.loader.util.Penalty;
+import org.apache.xmlgraphics.io.ResourceResolver;
 
 import org.apache.fop.apps.io.InternalResourceResolver;
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.FontManagerConfigurator;
 import org.apache.fop.hyphenation.HyphenationTreeCache;
index 80c957f9ffddccbc3a0c9737b953110ce16ca89c..6bc744b7e4db34133036f07925f384c188e10d07 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFactory;
 
 import org.apache.xmlgraphics.image.loader.ImageContext;
 import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
 import org.apache.xmlgraphics.util.UnitConv;
 
 import org.apache.fop.apps.io.InternalResourceResolver;
@@ -418,6 +419,11 @@ public final class FopFactory implements ImageContext {
         return config.getFontManager();
     }
 
+    /** @see FopFactoryConfig#getFallbackResolver() */
+    FallbackResolver getFallbackResolver() {
+        return config.getFallbackResolver();
+    }
+
     /**
      * Returns the color space cache for this instance.
      * <p>
index cfc47496c9b3df2abea4053c4e3a18350db0ee84..b1fd5e979cacc52f47b40c49ed5142b312b50884 100644 (file)
@@ -30,8 +30,9 @@ import org.apache.avalon.framework.configuration.Configuration;
 
 import org.apache.xmlgraphics.image.loader.ImageContext;
 import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
+import org.apache.xmlgraphics.io.ResourceResolver;
 
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
@@ -464,6 +465,10 @@ public final class FopFactoryBuilder {
         public Map<String, String> getHyphenationPatternNames() {
             return hyphPatNames;
         }
+
+        public FallbackResolver getFallbackResolver() {
+            return enviro.getFallbackResolver();
+        }
     }
 
     private interface FopFactoryConfigBuilder {
index 60e8d98e7275fe6e2d3c2ff2507452f128f9ffd6..d3ea3127f391c4d4be88a908df58c07ab28a36f5 100644 (file)
@@ -26,8 +26,9 @@ import java.util.Set;
 import org.apache.avalon.framework.configuration.Configuration;
 
 import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
+import org.apache.xmlgraphics.io.ResourceResolver;
 
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
 
@@ -163,4 +164,11 @@ public interface FopFactoryConfig {
 
     /** @return the hyphenation pattern names */
     Map<String, String> getHyphenationPatternNames();
+
+    /**
+     * Controls the mechanisms that are used in the event that {@link javax.xml.transform.Source}
+     * used for resources couldn't be read.
+     * @return the fallback resolver
+     */
+    FallbackResolver getFallbackResolver();
 }
index 4d664c8f5ebc19daff5682051613d00278f934cf..af0a26478273bb225098044c9fde92e37fbda08a 100644 (file)
@@ -29,12 +29,14 @@ import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
 import org.apache.xmlgraphics.util.uri.DataURIResolver;
 
 /**
  * This object holds the base URI from which to resolve URIs against as well as the resolver for
  * resource acquisition. It also does some URI sanitization of common URI syntactical errors. This
- * class takes in a {@link org.apache.fop.apps.io.ResourceResolver} and delegates all relevant
+ * class takes in a {@link org.apache.xmlgraphics.io.ResourceResolver} and delegates all relevant
  * URIs to it.
  */
 public class InternalResourceResolver {
diff --git a/src/java/org/apache/fop/apps/io/Resource.java b/src/java/org/apache/fop/apps/io/Resource.java
deleted file mode 100644 (file)
index 0a8b8c2..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.apps.io;
-
-import java.io.FilterInputStream;
-import java.io.InputStream;
-
-/**
- * This class represents a resolved resource.  The type property is used by FOP to identify the resource
- *  content.
- *
- */
-public class Resource extends FilterInputStream {
-
-    private final String type;
-
-    /**
-     * @param type resource type
-     * @param inputStream input stream of the resource
-     */
-    public Resource(String type, InputStream inputStream) {
-        super(inputStream);
-        this.type = type;
-    }
-
-    /**
-     * Constructs a resource of 'unknown' type.
-     *
-     * @param inputStream input stream of the resource
-     */
-    public Resource(InputStream inputStream) {
-        this("unknown", inputStream);
-    }
-
-    /**
-     * @return the resource type
-     */
-    public String getType() {
-        return this.type;
-    }
-
-}
diff --git a/src/java/org/apache/fop/apps/io/ResourceResolver.java b/src/java/org/apache/fop/apps/io/ResourceResolver.java
deleted file mode 100644 (file)
index a3a9cf0..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.apps.io;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-
-/**
- * Implementations of this resource resolver allow FOP users to control the URI resolution
- * mechanism. All resource and output stream acquisition goes through this when its implementation
- * is given to the {@link org.apache.fop.apps.EnvironmentProfile}.
- */
-public interface ResourceResolver {
-
-    /**
-     * Get a resource given the URI pointing to said resource.
-     *
-     * @param uri the resource URI
-     * @return the resource
-     * @throws IOException if an I/O error occured during resource acquisition
-     */
-    Resource getResource(URI uri) throws IOException;
-
-    /**
-     * Gets an output stream of a given URI.
-     *
-     * @param uri the output stream URI
-     * @return the output stream
-     * @throws IOException if an I/O error occured while creating an output stream
-     */
-    OutputStream getOutputStream(URI uri) throws IOException;
-
-}
index 72eac456da530cb795f85d53d3d38c01b3e4f895..cdc9438b94d0f4cf3248889dd56bbeaa28a4ffb4 100644 (file)
@@ -28,6 +28,11 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
+import org.apache.xmlgraphics.io.TempResourceResolver;
+import org.apache.xmlgraphics.io.TempResourceURIGenerator;
+
 /**
  * A factory class for {@link ResourceResolver}s.
  */
@@ -70,10 +75,10 @@ public final class ResourceResolverFactory {
     }
 
     /**
-     * Creates a temporary-resource-schema aware resource resolver. Temporary resource URIs are
+     * Creates a temporary-resource-scheme aware resource resolver. Temporary resource URIs are
      * created by {@link TempResourceURIGenerator}.
      *
-     * @param tempResourceResolver the temporary-resource-schema resolver to use
+     * @param tempResourceResolver the temporary-resource-scheme resolver to use
      * @param defaultResourceResolver the default resource resolver to use
      * @return the ressource resolver
      */
@@ -84,17 +89,17 @@ public final class ResourceResolverFactory {
     }
 
     /**
-     * This creates the builder class for binding URI schemas to implementations of
-     * {@link ResourceResolver}. This allows users to define their own URI schemas such that they
+     * This creates the builder class for binding URI schemes to implementations of
+     * {@link ResourceResolver}. This allows users to define their own URI schemes such that they
      * have finer control over the acquisition of resources.
      *
      * @param defaultResolver the default resource resolver that should be used in the event that
-     * none of the other registered resolvers match the schema
-     * @return the schema aware {@link ResourceResolver} builder
+     * none of the other registered resolvers match the scheme
+     * @return the scheme aware {@link ResourceResolver} builder
      */
-    public static SchemaAwareResourceResolverBuilder createSchemaAwareResourceResolverBuilder(
+    public static SchemeAwareResourceResolverBuilder createSchemeAwareResourceResolverBuilder(
             ResourceResolver defaultResolver) {
-        return new SchemaAwareResourceResolverBuilderImpl(defaultResolver);
+        return new SchemeAwareResourceResolverBuilderImpl(defaultResolver);
     }
 
     private static final class DefaultResourceResolver implements ResourceResolver {
@@ -132,13 +137,13 @@ public final class ResourceResolverFactory {
             this.defaultResourceResolver = defaultResourceResolver;
         }
 
-        private static boolean isTempUri(URI uri) {
-            return TempResourceURIGenerator.isTempUri(uri);
+        private static boolean isTempURI(URI uri) {
+            return TempResourceURIGenerator.isTempURI(uri);
         }
 
         /** {@inheritDoc} */
         public Resource getResource(URI uri) throws IOException {
-            if (isTempUri(uri)) {
+            if (isTempURI(uri)) {
                 return tempResourceResolver.getResource(uri.getPath());
             } else {
                 return defaultResourceResolver.getResource(uri);
@@ -147,7 +152,7 @@ public final class ResourceResolverFactory {
 
         /** {@inheritDoc} */
         public OutputStream getOutputStream(URI uri) throws IOException {
-            if (isTempUri(uri)) {
+            if (isTempURI(uri)) {
                 return tempResourceResolver.getOutputStream(uri.getPath());
             } else {
                 return defaultResourceResolver.getOutputStream(uri);
@@ -188,23 +193,23 @@ public final class ResourceResolverFactory {
         }
     }
 
-    private static final class SchemaAwareResourceResolver implements ResourceResolver {
+    private static final class SchemeAwareResourceResolver implements ResourceResolver {
 
-        private final Map<String, ResourceResolver> schemaHandlingResourceResolvers;
+        private final Map<String, ResourceResolver> schemeHandlingResourceResolvers;
 
         private final ResourceResolver defaultResolver;
 
-        private SchemaAwareResourceResolver(
-                Map<String, ResourceResolver> schemaHandlingResourceResolvers,
+        private SchemeAwareResourceResolver(
+                Map<String, ResourceResolver> schemEHandlingResourceResolvers,
                 ResourceResolver defaultResolver) {
-            this.schemaHandlingResourceResolvers = schemaHandlingResourceResolvers;
+            this.schemeHandlingResourceResolvers = schemEHandlingResourceResolvers;
             this.defaultResolver = defaultResolver;
         }
 
-        private ResourceResolver getResourceResolverForSchema(URI uri) {
-            String schema = uri.getScheme();
-            if (schemaHandlingResourceResolvers.containsKey(schema)) {
-                return schemaHandlingResourceResolvers.get(schema);
+        private ResourceResolver getResourceResolverForScheme(URI uri) {
+            String scheme = uri.getScheme();
+            if (schemeHandlingResourceResolvers.containsKey(scheme)) {
+                return schemeHandlingResourceResolvers.get(scheme);
             } else {
                 return defaultResolver;
             }
@@ -212,58 +217,58 @@ public final class ResourceResolverFactory {
 
         /** {@inheritDoc} */
         public Resource getResource(URI uri) throws IOException {
-            return getResourceResolverForSchema(uri).getResource(uri);
+            return getResourceResolverForScheme(uri).getResource(uri);
         }
 
         /** {@inheritDoc} */
         public OutputStream getOutputStream(URI uri) throws IOException {
-            return getResourceResolverForSchema(uri).getOutputStream(uri);
+            return getResourceResolverForScheme(uri).getOutputStream(uri);
         }
     }
 
     /**
      * Implementations of this interface will be builders for {@link ResourceResolver}, they bind
-     * URI schemas to their respective resolver. This gives users more control over the mechanisms
+     * URI schemes to their respective resolver. This gives users more control over the mechanisms
      * by which URIs are resolved.
      * <p>
      * Here is an example of how this could be used:
      * </p>
      * <p><code>
-     * SchemaAwareResourceResolverBuilder builder
-     *      = ResourceResolverFactory.createSchemaAwareResourceResolverBuilder(defaultResolver);
-     * builder.registerResourceResolverForSchema("test", testResolver);
-     * builder.registerResourceResolverForSchema("anotherTest", test2Resolver);
+     * SchemeAwareResourceResolverBuilder builder
+     *      = ResourceResolverFactory.createSchemeAwareResourceResolverBuilder(defaultResolver);
+     * builder.registerResourceResolverForScheme("test", testResolver);
+     * builder.registerResourceResolverForScheme("anotherTest", test2Resolver);
      * ResourceResolver resolver = builder.build();
      * </code></p>
      * This will result in all URIs for the form "test:///..." will be resolved using the
      * <code>testResolver</code> object; URIs of the form "anotherTest:///..." will be resolved
      * using <code>test2Resolver</code>; all other URIs will be resolved from the defaultResolver.
      */
-    public interface SchemaAwareResourceResolverBuilder {
+    public interface SchemeAwareResourceResolverBuilder {
 
         /**
-         * Register a schema with its respective {@link ResourceResolver}. This resolver will be
-         * used as the only resolver for the specified schema.
+         * Register a scheme with its respective {@link ResourceResolver}. This resolver will be
+         * used as the only resolver for the specified scheme.
          *
-         * @param schema the schema to be used with the given resolver
+         * @param scheme the scheme to be used with the given resolver
          * @param resourceResolver the resource resolver
          */
-        void registerResourceResolverForSchema(String schema, ResourceResolver resourceResolver);
+        void registerResourceResolverForScheme(String scheme, ResourceResolver resourceResolver);
 
         /**
          * Builds a {@link ResourceResolver} that will delegate to the respective resource resolver
-         * when a registered URI schema is given
+         * when a registered URI scheme is given
          *
-         * @return a resolver that delegates to the appropriate schema resolver
+         * @return a resolver that delegates to the appropriate scheme resolver
          */
         ResourceResolver build();
     }
 
-    private static final class CompletedSchemaAwareResourceResolverBuilder
-            implements SchemaAwareResourceResolverBuilder {
+    private static final class CompletedSchemeAwareResourceResolverBuilder
+            implements SchemeAwareResourceResolverBuilder {
 
-        private static final SchemaAwareResourceResolverBuilder INSTANCE
-                = new CompletedSchemaAwareResourceResolverBuilder();
+        private static final SchemeAwareResourceResolverBuilder INSTANCE
+                = new CompletedSchemeAwareResourceResolverBuilder();
 
         /** {@inheritDoc} */
         public ResourceResolver build() {
@@ -271,59 +276,58 @@ public final class ResourceResolverFactory {
         }
 
         /** {@inheritDoc} */
-        public void registerResourceResolverForSchema(String schema,
+        public void registerResourceResolverForScheme(String scheme,
                 ResourceResolver resourceResolver) {
             throw new IllegalStateException("Resource resolver already built");
         }
     }
 
-    private static final class ActiveSchemaAwareResourceResolverBuilder
-            implements SchemaAwareResourceResolverBuilder {
+    private static final class ActiveSchemeAwareResourceResolverBuilder
+            implements SchemeAwareResourceResolverBuilder {
 
-        private final Map<String, ResourceResolver> schemaHandlingResourceResolvers
+        private final Map<String, ResourceResolver> schemeHandlingResourceResolvers
                 = new HashMap<String, ResourceResolver>();
 
         private final ResourceResolver defaultResolver;
 
-        private ActiveSchemaAwareResourceResolverBuilder(ResourceResolver defaultResolver) {
+        private ActiveSchemeAwareResourceResolverBuilder(ResourceResolver defaultResolver) {
             this.defaultResolver = defaultResolver;
         }
 
         /** {@inheritDoc} */
-        public void registerResourceResolverForSchema(String schema,
+        public void registerResourceResolverForScheme(String scheme,
                 ResourceResolver resourceResolver) {
-            schemaHandlingResourceResolvers.put(schema, resourceResolver);
+            schemeHandlingResourceResolvers.put(scheme, resourceResolver);
         }
 
         /** {@inheritDoc} */
         public ResourceResolver build() {
-            return new SchemaAwareResourceResolver(
-                    Collections.unmodifiableMap(schemaHandlingResourceResolvers), defaultResolver);
+            return new SchemeAwareResourceResolver(
+                    Collections.unmodifiableMap(schemeHandlingResourceResolvers), defaultResolver);
         }
 
     }
 
-    private static final class SchemaAwareResourceResolverBuilderImpl
-            implements SchemaAwareResourceResolverBuilder {
+    private static final class SchemeAwareResourceResolverBuilderImpl
+            implements SchemeAwareResourceResolverBuilder {
 
-        private SchemaAwareResourceResolverBuilder delegate;
+        private SchemeAwareResourceResolverBuilder delegate;
 
-        private SchemaAwareResourceResolverBuilderImpl(ResourceResolver defaultResolver) {
-            this.delegate = new ActiveSchemaAwareResourceResolverBuilder(defaultResolver);
+        private SchemeAwareResourceResolverBuilderImpl(ResourceResolver defaultResolver) {
+            this.delegate = new ActiveSchemeAwareResourceResolverBuilder(defaultResolver);
         }
 
         /** {@inheritDoc} */
-        public void registerResourceResolverForSchema(String schema,
+        public void registerResourceResolverForScheme(String scheme,
                 ResourceResolver resourceResolver) {
-            delegate.registerResourceResolverForSchema(schema, resourceResolver);
+            delegate.registerResourceResolverForScheme(scheme, resourceResolver);
         }
 
         /** {@inheritDoc} */
         public ResourceResolver build() {
             ResourceResolver resourceResolver = delegate.build();
-            delegate = CompletedSchemaAwareResourceResolverBuilder.INSTANCE;
+            delegate = CompletedSchemeAwareResourceResolverBuilder.INSTANCE;
             return resourceResolver;
         }
     }
-
 }
diff --git a/src/java/org/apache/fop/apps/io/TempResourceResolver.java b/src/java/org/apache/fop/apps/io/TempResourceResolver.java
deleted file mode 100644 (file)
index cf307fa..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.apps.io;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * Implementations of this interface resolve URIs for temporary files used by FOP. The temporary-
- * resource URI scheme comes from {@link TempResourceURIGenerator#TMP_SCHEMA}.
- */
-public interface TempResourceResolver {
-
-    /**
-     * Get a temporary-resource given the URI pointing to said resource.
-     *
-     * @param uri the resource URI
-     * @return the resource
-     * @throws IOException if an I/O error occured during resource acquisition
-     */
-    Resource getResource(String uri) throws IOException;
-
-    /**
-     * Gets an temporary-output stream of a given URI.
-     *
-     * @param uri the output stream URI
-     * @return the output stream
-     * @throws IOException if an I/O error occured while creating an output stream
-     */
-    OutputStream getOutputStream(String uri) throws IOException;
-}
diff --git a/src/java/org/apache/fop/apps/io/TempResourceURIGenerator.java b/src/java/org/apache/fop/apps/io/TempResourceURIGenerator.java
deleted file mode 100644 (file)
index 8e6c360..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.fop.apps.io;
-
-import java.net.URI;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Creates a URI for any temporary resource used within FOP.
- */
-public final class TempResourceURIGenerator {
-
-    public static final String TMP_SCHEMA = "tmp";
-
-    private final String tempURIPrefix;
-
-    private final AtomicLong counter;
-
-    /**
-     * @param uriPrefix a prefix used to name the unique URI
-     */
-    public TempResourceURIGenerator(String uriPrefix) {
-        counter = new AtomicLong();
-        tempURIPrefix = URI.create(TMP_SCHEMA + ":///" + uriPrefix).toASCIIString();
-    }
-
-    /**
-     * Generate a unique URI for a temporary resource
-     * @return the URI
-     */
-    public URI generate() {
-        return URI.create(tempURIPrefix + getUniqueId());
-    }
-
-    private String getUniqueId() {
-        return Long.toHexString(counter.getAndIncrement());
-    }
-
-    public static boolean isTempUri(URI uri) {
-        return TMP_SCHEMA.equals(uri.getScheme());
-    }
-}
index fcc82cdd3f17b4b27b534580148a518ed5aeaaea..0837e5ae5443f1bc4bff028de679eaafc4f95e1d 100644 (file)
@@ -35,9 +35,10 @@ import org.xml.sax.SAXException;
 
 import org.apache.commons.io.IOUtils;
 
+import org.apache.xmlgraphics.io.TempResourceURIGenerator;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.io.TempResourceURIGenerator;
 import org.apache.fop.fonts.FontInfo;
 
 /**
index cf9296826061745b2fbd1eecd73303c32422467f..fc2ce06a643efa7f6d102ff8987eb45520e83475 100644 (file)
@@ -29,9 +29,10 @@ import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.io.InternalResourceResolver;
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.substitute.FontSubstitutions;
 import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator;
index 022ff462f3a6dc2f5986926a34809ca1c3ef66f2..3aa340a4a7bafeff44fe01dabe90e97c96ac949a 100644 (file)
@@ -45,6 +45,7 @@ import org.apache.xmlgraphics.image.loader.ImageSize;
 import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader;
 import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
 import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.io.XmlSourceUtil;
 import org.apache.xmlgraphics.util.MimeConstants;
 import org.apache.xmlgraphics.util.UnitConv;
 
@@ -79,7 +80,7 @@ public class PreloaderSVG extends AbstractImagePreloader {
             }
         }
         if (info != null) {
-            ImageUtil.closeQuietly(src); //Image is fully read
+            XmlSourceUtil.closeQuietly(src); //Image is fully read
         }
         return info;
     }
@@ -119,7 +120,7 @@ public class PreloaderSVG extends AbstractImagePreloader {
                     DOMSource domSrc = (DOMSource)src;
                     doc = (SVGDocument)domSrc.getNode();
                 } else {
-                    in = new UnclosableInputStream(ImageUtil.needInputStream(src));
+                    in = new UnclosableInputStream(XmlSourceUtil.needInputStream(src));
                     int length = in.available();
                     in.mark(length + 1);
                     SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
index 3bef0f41dd646dbb822608bbe526d188b863a01f..43341cbe66bbcdc68042daacb91c34434af8968f 100644 (file)
@@ -38,6 +38,7 @@ import org.apache.xmlgraphics.image.loader.ImageInfo;
 import org.apache.xmlgraphics.image.loader.ImageSize;
 import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader;
 import org.apache.xmlgraphics.image.loader.util.ImageUtil;
+import org.apache.xmlgraphics.io.XmlSourceUtil;
 
 import org.apache.fop.util.UnclosableInputStream;
 
@@ -69,7 +70,7 @@ public class PreloaderWMF extends AbstractImagePreloader {
             }
         }
         if (info != null) {
-            ImageUtil.closeQuietly(src); //Image is fully read
+            XmlSourceUtil.closeQuietly(src); //Image is fully read
         }
         return info;
     }
@@ -88,7 +89,7 @@ public class PreloaderWMF extends AbstractImagePreloader {
                 ImageContext context) {
             // parse document and get the size attributes of the svg element
 
-            InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
+            InputStream in = new UnclosableInputStream(XmlSourceUtil.needInputStream(src));
             try {
                 in.mark(4 + 1);
 
index 0ec5fdda67ee33d378da5f19b1131a6159acf998..897ed8fb826689e026de0817c42f7208bb9a2519 100644 (file)
@@ -39,6 +39,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.io.TempResourceURIGenerator;
 import org.apache.xmlgraphics.java2d.Dimension2DDouble;
 import org.apache.xmlgraphics.ps.DSCConstants;
 import org.apache.xmlgraphics.ps.PSDictionary;
@@ -53,7 +54,6 @@ import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
 import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
 
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.apps.io.TempResourceURIGenerator;
 import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
index 9dcf10a2becd018cd2330309213eb1d281a771cb..c65b6af3b16885f43d880fbdace6a61b4802a84e 100644 (file)
@@ -41,14 +41,15 @@ import javax.xml.transform.stream.StreamSource;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.FopFactoryBuilder;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.apps.io.Resource;
-import org.apache.fop.apps.io.ResourceResolver;
 
 /**
  * Example servlet to generate a PDF from a servlet.
index f1dd89725f5f94b20d7fb2c4ace6ceff2a5c91ad..e1015306efe778bf844fc049e6f2a54e37e3b4ee 100644 (file)
@@ -46,14 +46,15 @@ import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.xpath.XPathAPI;
 import org.apache.xpath.objects.XObject;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.FopFactoryBuilder;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.apps.io.Resource;
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.render.xml.XMLRenderer;
 
index 7b033969bb7438d1ed3655d65404c81b0ab222d2..e94403e71103423eea04e7e7cb739c09fece06e2 100644 (file)
@@ -21,11 +21,12 @@ import java.net.URI;
 
 import org.junit.Test;
 
-import org.apache.fop.apps.io.ResourceResolver;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 public class EnvironmentalProfileFactoryTestCase {
 
     private final URI testURI = URI.create("this.is.purely.for.test.purposes");
index 79f038f24756d9ea179306facf330640420c147e..3ff3c10fa82a103c1ab59a3064430be6225598a8 100644 (file)
@@ -24,8 +24,9 @@ import java.util.Set;
 import org.apache.avalon.framework.configuration.Configuration;
 
 import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
+import org.apache.xmlgraphics.io.ResourceResolver;
 
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.fonts.FontManager;
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
 
@@ -130,4 +131,8 @@ public final class MutableConfig implements FopFactoryConfig {
     public Map<String, String> getHyphenationPatternNames() {
         return delegate.getHyphenationPatternNames();
     }
+
+    public FallbackResolver getFallbackResolver() {
+        return delegate.getFallbackResolver();
+    }
 }
index ee337c39da70f78755f76a8872742d056f0df9c2..2131407c10672c09cedf371907090b8cb32710ee 100644 (file)
@@ -37,6 +37,8 @@ import org.xml.sax.SAXException;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
index d6f836783680aeb946746022e133e789cb281397..40d6c7402a4394d046957d2a0f4f81c5e52b8521 100644 (file)
@@ -39,6 +39,8 @@ import org.apache.fop.apps.PDFRendererConfBuilder;
 
 import static org.junit.Assert.assertTrue;
 
+import org.apache.xmlgraphics.io.Resource;
+
 public class FontURIResolver extends BaseURIResolutionTest {
 
     public enum Event {
index b6b2eea00e40b9ec6b50014cd944df68c30ab1b4..6ae34b4f94dc8e0e680170469b1579a304881d4b 100644 (file)
@@ -36,6 +36,10 @@ import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
+import org.apache.xmlgraphics.io.TempResourceResolver;
+
 public class ResourceResolverFactoryTestCase {
 
     private static final byte[] DATA = new byte[]{(byte) 0, (byte) 1, (byte) 2};
@@ -193,10 +197,10 @@ public class ResourceResolverFactoryTestCase {
         final ResourceResolver sut;
 
         TestCreateSchemaAwareResourceResolverBuilderHelper() {
-            ResourceResolverFactory.SchemaAwareResourceResolverBuilder builder
-                    = ResourceResolverFactory.createSchemaAwareResourceResolverBuilder(
+            ResourceResolverFactory.SchemeAwareResourceResolverBuilder builder
+                    = ResourceResolverFactory.createSchemeAwareResourceResolverBuilder(
                             defaultResourceResolver);
-            builder.registerResourceResolverForSchema(SCHEMA, registedResourceResolver);
+            builder.registerResourceResolverForScheme(SCHEMA, registedResourceResolver);
             sut = builder.build();
 
         }
index 532353337436566686ad7e4cd14095a4634ba3be..f1cd06138a29bb85c8d774e262d4e0f67f8f213e 100644 (file)
@@ -24,6 +24,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 abstract class TestingResourceResolver implements ResourceResolver {
 
     private final Map<URI, Object> checker;
index 440b16abb1f62d8e37fc2a331eeb7989ce1ff497..b2044e3b92461ab4dc7275a735ae987898422e4a 100644 (file)
@@ -35,6 +35,8 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 public class URIResolverWrapperTestCase {
 
     private static final List<String> BASE_URIS = Collections.unmodifiableList(Arrays.asList(
index 2be41dca1b65919e3b328dc6dbdbe3dcb7602b75..2b138de55b2f963cdc6e33970c0e39a5563da990 100644 (file)
@@ -42,8 +42,11 @@ import org.w3c.dom.Element;
 import org.apache.xpath.XPathAPI;
 import org.apache.xpath.objects.XObject;
 
+import org.apache.fop.apps.EnvironmentProfile;
+import org.apache.fop.apps.EnvironmentalProfileFactory;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.FopFactoryBuilder;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 
 /**
  * Helper class for running FOP tests.
@@ -115,7 +118,10 @@ public class TestAssistant {
     public FopFactory getFopFactory(Document testDoc) {
         boolean base14KerningEnabled = isBase14KerningEnabled(testDoc);
         boolean strictValidation = isStrictValidation(testDoc);
-        FopFactoryBuilder builder = new FopFactoryBuilder(testDir.getParentFile().toURI());
+        EnvironmentProfile envProfile = EnvironmentalProfileFactory.createRestrictedIO(
+                testDir.getParentFile().toURI(),
+                ResourceResolverFactory.createDefaultResourceResolver());
+        FopFactoryBuilder builder = new FopFactoryBuilder(envProfile);
         builder.setStrictFOValidation(strictValidation);
         builder.getFontManager().setBase14KerningEnabled(base14KerningEnabled);
         return builder.build();
index 971471fa2e0d350771c463bf68375e469dcba4d6..5e4b9e2e4475d7dac5d7acca7247a3ded7bab1bd 100644 (file)
@@ -26,8 +26,9 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.io.InternalResourceResolver;
-import org.apache.fop.apps.io.ResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.CIDSet;
 import org.apache.fop.fonts.CIDSubset;