]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Predominantly clean up and javadocs, very little functional change here
authorMehdi Houshmand <mehdi@apache.org>
Fri, 22 Jun 2012 08:27:42 +0000 (08:27 +0000)
committerMehdi Houshmand <mehdi@apache.org>
Fri, 22 Jun 2012 08:27:42 +0000 (08:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1352800 13f79535-47bb-0310-9956-ffa450edef68

23 files changed:
src/java/org/apache/fop/afp/AFPResourceLevel.java
src/java/org/apache/fop/afp/AFPStreamer.java
src/java/org/apache/fop/afp/fonts/CharacterSet.java
src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java
src/java/org/apache/fop/afp/fonts/CharacterSetType.java
src/java/org/apache/fop/afp/fonts/CharactersetEncoder.java
src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java
src/java/org/apache/fop/apps/FOUserAgent.java
src/java/org/apache/fop/apps/FopFactory.java
src/java/org/apache/fop/apps/io/InternalResourceResolver.java
src/java/org/apache/fop/apps/io/ResourceResolver.java
src/java/org/apache/fop/apps/io/ResourceResolverFactory.java
src/java/org/apache/fop/fonts/FontManagerConfigurator.java
src/java/org/apache/fop/render/pdf/PDFRendererConfig.java
src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
src/java/org/apache/fop/svg/PDFDocumentGraphics2DConfigurator.java
test/java/org/apache/fop/BasicPDFTranscoderTestCase.java
test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
test/java/org/apache/fop/afp/fonts/CharactersetEncoderTestCase.java
test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java
test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java
test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
test/java/org/apache/fop/render/pdf/PDFRendererConfiguratorTestCase.java

index 7dcff1183f818dd7ad016a12d0bf255fa70a5f88..860ca3d26f52f014196cd0c0a14a8634281e6074 100644 (file)
@@ -145,18 +145,18 @@ public class AFPResourceLevel {
     }
 
     /**
-     * Returns the destination file path of the external resource group file
+     * Returns the URI of the external resource group.
      *
-     * @return the destination file path of the external resource group file
+     * @return the destination URI of the external resource group
      */
-    public URI getExternalUri() {
+    public URI getExternalURI() {
         return this.extUri;
     }
 
     /**
-     * Sets the external destination of the resource
+     * Sets the URI of the external resource group.
      *
-     * @param filePath the external resource group file
+     * @param filePath the URI of the external resource group
      */
     public void setExternalUri(URI uri) {
         this.extUri = uri;
index 2ee341b5b62a9328c6c127f052412d9972cbc788..072dc17960da76875a6298b02f320b7b1671098d 100644 (file)
@@ -34,8 +34,8 @@ import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.afp.modca.ResourceGroup;
 import org.apache.fop.afp.modca.StreamedResourceGroup;
-import org.apache.fop.apps.io.TempResourceURIGenerator;
 import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.TempResourceURIGenerator;
 
 /**
  * Manages the streaming of the AFP output
@@ -119,7 +119,7 @@ public class AFPStreamer implements Streamable {
             return null;
         }
         if (level.isExternal()) {
-            URI uri = level.getExternalUri();
+            URI uri = level.getExternalURI();
             if (uri == null) {
                 LOG.warn("No file path provided for external resource, using default.");
                 uri = defaultResourceGroupUri;
index 8881a2649c4f5437b8c7ed33f120b30ab7b9765a..49e7f99bab562e45eed5bc0ea582fbc2279bbf6e 100644 (file)
@@ -115,7 +115,7 @@ public class CharacterSet {
         }
         this.codePage = codePage;
         this.encoding = encoding;
-        this.encoder = CharactersetEncoder.newInstance(encoding, charsetType);
+        this.encoder = charsetType.getEncoder(encoding);
         this.accessor = accessor;
 
         this.characterSetOrientations = new HashMap<String, CharacterSetOrientation>(4);
index e145de74538971fa42acd2876303562bcb9c968f..7331178f521acc745e779f2a220e540cb2243559 100644 (file)
@@ -40,6 +40,7 @@ import org.apache.fop.afp.AFPConstants;
 import org.apache.fop.afp.AFPEventProducer;
 import org.apache.fop.afp.util.AFPResourceAccessor;
 import org.apache.fop.afp.util.StructuredFieldReader;
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.Typeface;
 
 /**
@@ -148,7 +149,7 @@ public abstract class CharacterSetBuilder {
             throws IOException {
         URI uri;
         try {
-            uri = new URI(uriStr.trim());
+            uri = InternalResourceResolver.cleanURI(uriStr.trim());
         } catch (URISyntaxException e) {
             throw new MalformedURLException("Invalid uri: " + uriStr + " (" + e.getMessage() + ")");
         }
index 8eaaa089bffde8f2b6751f445ec0254e471857e8..060d949ac41a13ee779f77c7a5613275a8594248 100644 (file)
 
 package org.apache.fop.afp.fonts;
 
+import org.apache.fop.afp.fonts.CharactersetEncoder.DefaultEncoder;
+import org.apache.fop.afp.fonts.CharactersetEncoder.EbcdicDoubleByteLineDataEncoder;
+
 /**
  * An enumeration of AFP characterset types.
  */
 public enum CharacterSetType {
     /** Double byte character sets; these do NOT have the shift-in;shift-out operators */
-    DOUBLE_BYTE,
+    DOUBLE_BYTE {
+        @Override
+        CharactersetEncoder getEncoder(String encoding) {
+            return new DefaultEncoder(encoding, true);
+        }
+    },
     /** Double byte character sets; these can have the shift-in;shift-out operators */
-    DOUBLE_BYTE_LINE_DATA,
-    SINGLE_BYTE;
+    DOUBLE_BYTE_LINE_DATA {
+        @Override
+        CharactersetEncoder getEncoder(String encoding) {
+            return new EbcdicDoubleByteLineDataEncoder(encoding);
+        }
+    },
+    SINGLE_BYTE {
+        @Override
+        CharactersetEncoder getEncoder(String encoding) {
+            return new DefaultEncoder(encoding, false);
+        }
+    };
+
+    /**
+     * Returns the character-set encoder
+     *
+     * @param encoding
+     * @return
+     */
+    abstract CharactersetEncoder getEncoder(String encoding);
 }
index f101bdab47858b87b7152bfaa8201a435a59a8a9..983c308cd19402d8836b1e5ca1f32cb371661808 100644 (file)
@@ -87,7 +87,7 @@ public abstract class CharactersetEncoder {
      */
     public static EncodedChars encodeSBCS(CharSequence chars, String encoding)
             throws CharacterCodingException {
-        CharactersetEncoder encoder = newInstance(encoding, CharacterSetType.SINGLE_BYTE);
+        CharactersetEncoder encoder = CharacterSetType.SINGLE_BYTE.getEncoder(encoding);
         return encoder.encode(chars);
     }
 
@@ -97,8 +97,8 @@ public abstract class CharactersetEncoder {
      * sequence it will return its EBCDIC code-point, however, the "Shift In - Shift Out" operators
      * are removed from the sequence of bytes. These are only used in Line Data.
      */
-    private static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder {
-        private EbcdicDoubleByteLineDataEncoder(String encoding) {
+    static final class EbcdicDoubleByteLineDataEncoder extends CharactersetEncoder {
+        EbcdicDoubleByteLineDataEncoder(String encoding) {
             super(encoding);
         }
         @Override
@@ -115,10 +115,10 @@ public abstract class CharactersetEncoder {
      * the primary format for most Latin character sets. This can also be used for Unicode double-
      * byte character sets (DBCS).
      */
-    private static final class DefaultEncoder extends CharactersetEncoder {
+    static final class DefaultEncoder extends CharactersetEncoder {
         private final boolean isDBCS;
 
-        private DefaultEncoder(String encoding, boolean isDBCS) {
+        DefaultEncoder(String encoding, boolean isDBCS) {
             super(encoding);
             this.isDBCS = isDBCS;
         }
@@ -129,24 +129,6 @@ public abstract class CharactersetEncoder {
         }
     }
 
-    /**
-     * Returns an new instance of a {@link CharactersetEncoder}.
-     *
-     * @param encoding the encoding for the underlying character encoder
-     * @param isEbcdicDBCS whether or not this wraps a double-byte EBCDIC code page.
-     * @return the CharactersetEncoder
-     */
-    static CharactersetEncoder newInstance(String encoding, CharacterSetType charsetType) {
-        switch (charsetType) {
-        case DOUBLE_BYTE_LINE_DATA:
-            return new EbcdicDoubleByteLineDataEncoder(encoding);
-        case DOUBLE_BYTE:
-            return new DefaultEncoder(encoding, true);
-        default:
-            return new DefaultEncoder(encoding, false);
-        }
-    }
-
     /**
      * A container for encoded character bytes
      */
index 9133e81dd5aed8bb45cba8d1202315ddcb27c381..374074b8a41413bba20c6286272b5631b20173a2 100644 (file)
@@ -21,8 +21,9 @@ package org.apache.fop.apps;
 
 import java.net.URI;
 
-import org.apache.fop.apps.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;
 import org.apache.fop.fonts.FontDetector;
@@ -105,7 +106,8 @@ public final class EnvironmentalProfileFactory {
 
     private static FontManager createFontManager(URI defaultBaseUri, ResourceResolver resourceResolver,
             FontDetector fontDetector, FontCacheManager fontCacheManager) {
-        return new FontManager(new InternalResourceResolver(defaultBaseUri, resourceResolver), fontDetector,
-                fontCacheManager);
+        InternalResourceResolver internalResolver = ResourceResolverFactory.createInternalResourceResolver(
+                defaultBaseUri, resourceResolver);
+        return new FontManager(internalResolver, fontDetector, fontCacheManager);
     }
 }
index fc9287401177a5781709c30d483abd97623d6a65..488b6247457dd82efc6341fafd018da26e3d4bd9 100644 (file)
@@ -402,11 +402,12 @@ public class FOUserAgent {
      * @return A {@link javax.xml.transform.Source} object, or null if the URI
      * cannot be resolved.
      */
-    public Source resolveURI(String uri) {
-        // TODO: What do we want to do when resources aren't found???
+    public StreamSource resolveURI(String uri) {
+        // TODO: What do we want to do when resources aren't found??? We also need to remove this
+        // method entirely
         try {
             // Have to do this so we can resolve data URIs
-            Source src = new StreamSource(resourceResolver.getResource(uri));
+            StreamSource src = new StreamSource(resourceResolver.getResource(uri));
             src.setSystemId(uri);
             return src;
         } catch (URISyntaxException use) {
index a149d593cf94cc2e47be1ed4cf5fe722a39eaf1c..ec72669579537ba29586f32ad93062c00ec0c96e 100644 (file)
@@ -39,6 +39,7 @@ import org.apache.xmlgraphics.image.loader.ImageManager;
 import org.apache.xmlgraphics.util.UnitConv;
 
 import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.ElementMappingRegistry;
 import org.apache.fop.fonts.FontManager;
@@ -88,7 +89,8 @@ public final class FopFactory implements ImageContext {
 
     private FopFactory(FopFactoryConfig config) {
         this.config = config;
-        this.resolver = new InternalResourceResolver(config.getBaseURI(), config.getResourceResolver());
+        this.resolver = ResourceResolverFactory.createInternalResourceResolver(config.getBaseURI(),
+                config.getResourceResolver());
         this.elementMappingRegistry = new ElementMappingRegistry(this);
         this.colorSpaceCache = new ColorSpaceCache(resolver);
         this.rendererFactory = new RendererFactory(config.preferRenderer());
index 4ea391c8a325f4b24a150f97bd9dfbb6d66ab7da..4d664c8f5ebc19daff5682051613d00278f934cf 100644 (file)
@@ -39,16 +39,16 @@ import org.apache.xmlgraphics.util.uri.DataURIResolver;
  */
 public class InternalResourceResolver {
     private final URI baseUri;
-    private final ResourceResolver uriResolver;
+    private final ResourceResolver resourceResolver;
     private final DataURIResolver dataSchemeResolver = new DataURIResolver();
 
     /**
      * @param baseUri the base URI from which to resolve relative URIs
-     * @param uriResolver the resolver to delegate to
+     * @param resourceResolver the resolver to delegate to
      */
-    public InternalResourceResolver(URI baseUri, ResourceResolver uriResolver) {
+    InternalResourceResolver(URI baseUri, ResourceResolver resourceResolver) {
         this.baseUri = baseUri;
-        this.uriResolver = uriResolver;
+        this.resourceResolver = resourceResolver;
     }
 
     /**
@@ -87,7 +87,7 @@ public class InternalResourceResolver {
         if (uri.getScheme() != null && uri.getScheme().startsWith("data")) {
             return new Resource(resolveDataURI(uri.toASCIIString()));
         }
-        return uriResolver.getResource(resolveFromBase(uri));
+        return resourceResolver.getResource(resolveFromBase(uri));
     }
 
     /**
@@ -98,7 +98,7 @@ public class InternalResourceResolver {
      * @throws IOException if an I/O error occurrred
      */
     public OutputStream getOutputStream(URI uri) throws IOException {
-        return uriResolver.getOutputStream(resolveFromBase(uri));
+        return resourceResolver.getOutputStream(resolveFromBase(uri));
     }
 
     /**
index 3d20aaebc8099227322f9b868330788fa8a28532..a3a9cf0c3f55e637ecc23bc6c69c74f346274ded 100644 (file)
@@ -23,10 +23,29 @@ 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 2e6c8af39193b7fa8a6e7ddeffdbffb8b7031ea9..881db20f71b701af37bbfdbe2d9278e030b992a7 100644 (file)
@@ -28,24 +28,59 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * A factory class for {@link ResourceResolver}s.
+ */
 public final class ResourceResolverFactory {
 
     private ResourceResolverFactory() {
     }
 
+    /**
+     * Returns the default resource resolver, this is most basic resolver which can be used when
+     * no there are no I/O or file access restrictions.
+     *
+     * @return the default resource resolver
+     */
     public static ResourceResolver createDefaultResourceResolver() {
         return DefaultResourceResolver.INSTANCE;
     }
 
-    public static ResourceResolver createTempAwareResourceResolver(TempResourceResolver tempResourceResolver,
-            ResourceResolver defaultResourceResolver) {
-        return new TempAwareResourceResolver(tempResourceResolver, defaultResourceResolver);
+    /**
+     * A helper merthod that creates an internal resource resolver using the default resover:
+     * {@link ResourceResolverFactory#createDefaultResourceResolver()}.
+     *
+     * @param baseURI the base URI from which to resolve URIs
+     * @return the default internal resource resolver
+     */
+    public static InternalResourceResolver createDefaultInternalResourceResolver(URI baseURI) {
+        return new InternalResourceResolver(baseURI, createDefaultResourceResolver());
     }
 
-    public static InternalResourceResolver createDefaultWrapper() {
-        // Not sure if this is the right place for this, but I don't have any better ideas as of yet
-        URI thisUri = new File(".").getAbsoluteFile().toURI();
-        return new InternalResourceResolver(thisUri, new DefaultResourceResolver());
+    /**
+     * Creates an interal resource resolver given a base URI and a resource resolver.
+     *
+     * @param baseURI the base URI from which to resolve URIs
+     * @param resolver the resource resolver
+     * @return the internal resource resolver
+     */
+    public static InternalResourceResolver createInternalResourceResolver(URI baseURI,
+            ResourceResolver resolver) {
+        return new InternalResourceResolver(baseURI, resolver);
+    }
+
+    /**
+     * Creates a temporary-resource-schema aware resource resolver. Temporary resource URIs are
+     * created by {@link TempResourceURIGenerator}.
+     *
+     * @param tempResourceResolver the temporary-resource-schema resolver to use
+     * @param defaultResourceResolver the default resource resolver to use
+     * @return the ressource resolver
+     */
+    public static ResourceResolver createTempAwareResourceResolver(
+            TempResourceResolver tempResourceResolver,
+            ResourceResolver defaultResourceResolver) {
+        return new TempAwareResourceResolver(tempResourceResolver, defaultResourceResolver);
     }
 
     public static SchemaAwareResourceResolverBuilder createSchemaAwareResourceResolverBuilder(
@@ -53,16 +88,14 @@ public final class ResourceResolverFactory {
         return new SchemaAwareResourceResolverBuilderImpl(defaultResolver);
     }
 
-
-
     private static final class DefaultResourceResolver implements ResourceResolver {
 
         private static final ResourceResolver INSTANCE = new DefaultResourceResolver();
 
         private final TempAwareResourceResolver delegate;
 
-        private  DefaultResourceResolver() {
-            delegate = new  TempAwareResourceResolver(new DefaultTempResourceResolver(),
+        private DefaultResourceResolver() {
+            delegate = new TempAwareResourceResolver(new DefaultTempResourceResolver(),
                     new NormalResourceResolver());
         }
 
@@ -123,7 +156,6 @@ public final class ResourceResolverFactory {
 
         public OutputStream getOutputStream(String id) throws IOException {
             File file = getTempFile(id);
-            // TODO handle error
             file.createNewFile();
             return new FileOutputStream(file);
         }
@@ -145,7 +177,8 @@ public final class ResourceResolverFactory {
 
         private final ResourceResolver defaultResolver;
 
-        private SchemaAwareResourceResolver(Map<String, ResourceResolver> schemaHandlingResourceResolvers,
+        private SchemaAwareResourceResolver(
+                Map<String, ResourceResolver> schemaHandlingResourceResolvers,
                 ResourceResolver defaultResolver) {
             this.schemaHandlingResourceResolvers = schemaHandlingResourceResolvers;
             this.defaultResolver = defaultResolver;
@@ -177,7 +210,7 @@ public final class ResourceResolverFactory {
     }
 
     private static final class CompletedSchemaAwareResourceResolverBuilder
-    implements SchemaAwareResourceResolverBuilder {
+            implements SchemaAwareResourceResolverBuilder {
 
         private static final SchemaAwareResourceResolverBuilder INSTANCE
                 = new CompletedSchemaAwareResourceResolverBuilder();
@@ -193,7 +226,7 @@ public final class ResourceResolverFactory {
     }
 
     private static final class ActiveSchemaAwareResourceResolverBuilder
-    implements SchemaAwareResourceResolverBuilder {
+            implements SchemaAwareResourceResolverBuilder {
 
         private final Map<String, ResourceResolver> schemaHandlingResourceResolvers
                 = new HashMap<String, ResourceResolver>();
@@ -204,7 +237,8 @@ public final class ResourceResolverFactory {
             this.defaultResolver = defaultResolver;
         }
 
-        public void registerResourceResolverForSchema(String schema, ResourceResolver resourceResolver) {
+        public void registerResourceResolverForSchema(String schema,
+                ResourceResolver resourceResolver) {
             schemaHandlingResourceResolvers.put(schema, resourceResolver);
         }
 
@@ -216,7 +250,7 @@ public final class ResourceResolverFactory {
     }
 
     private static final class SchemaAwareResourceResolverBuilderImpl
-    implements SchemaAwareResourceResolverBuilder {
+            implements SchemaAwareResourceResolverBuilder {
 
         private SchemaAwareResourceResolverBuilder delegate;
 
@@ -224,7 +258,8 @@ public final class ResourceResolverFactory {
             this.delegate = new ActiveSchemaAwareResourceResolverBuilder(defaultResolver);
         }
 
-        public void registerResourceResolverForSchema(String schema, ResourceResolver resourceResolver) {
+        public void registerResourceResolverForSchema(String schema,
+                ResourceResolver resourceResolver) {
             delegate.registerResourceResolverForSchema(schema, resourceResolver);
         }
 
index 0def335a1cbf47dd5a382371730621fc6ece70ef..c4fe1944474132ab65bd361c29f862e911426967 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
 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;
 import org.apache.fop.util.LogUtil;
@@ -89,13 +90,14 @@ public class FontManagerConfigurator {
             try {
                 URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base").getValue(
                         null));
-                fontManager.setResourceResolver(new InternalResourceResolver(
+                fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
                         defaultBaseUri.resolve(fontBase), resourceResolver));
             } catch (URISyntaxException use) {
                 LogUtil.handleException(log, use, true);
             }
         } else {
-            fontManager.setResourceResolver(new InternalResourceResolver(defaultBaseUri, resourceResolver));
+            fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
+                    defaultBaseUri, resourceResolver));
         }
 
         // [GA] permit configuration control over base14 kerning; without this,
index 0337ef5a7a5ad776f8e3042a0085168cc5dd238c..ffb092b33766ec787c8ab472b74a1e4ef40235fb 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.render.pdf;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.EnumMap;
 import java.util.HashMap;
@@ -33,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.DefaultFontConfig;
 import org.apache.fop.fonts.DefaultFontConfig.DefaultFontConfigParser;
 import org.apache.fop.pdf.PDFAMode;
@@ -98,8 +101,8 @@ public final class PDFRendererConfig implements RendererConfig {
         return (PDFEncryptionParams) configOptions.get(ENCRYPTION_PARAMS);
     }
 
-    public String getOutputProfileURI() {
-        return (String) configOptions.get(OUTPUT_PROFILE);
+    public URI getOutputProfileURI() {
+        return (URI) configOptions.get(OUTPUT_PROFILE);
     }
 
     public Boolean getDisableSRGBColorSpace() {
@@ -171,12 +174,13 @@ public final class PDFRendererConfig implements RendererConfig {
                     }
                     put(ENCRYPTION_PARAMS, encryptionConfig);
                 }
-                // TODO: Check this, I'm pretty sure the getChild(Str, bool) should be false!!!
-                put(OUTPUT_PROFILE, parseConfig(cfg, OUTPUT_PROFILE));
+                put(OUTPUT_PROFILE, InternalResourceResolver.cleanURI(parseConfig(cfg, OUTPUT_PROFILE)));
                 put(DISABLE_SRGB_COLORSPACE, Boolean.valueOf(parseConfig(cfg, DISABLE_SRGB_COLORSPACE)));
                 put(VERSION, getPDFDocVersion(cfg));
             } catch (ConfigurationException e) {
                 LogUtil.handleException(LOG, e, strict);
+            } catch (URISyntaxException use) {
+                LogUtil.handleException(LOG, use, strict);
             }
         }
 
index daffe2d3f608fe54635c7e52ad759f0c5cb103f9..2a6a364e6357b94ac226b4e6affee6cf58d6b76a 100644 (file)
@@ -24,17 +24,14 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Map;
 
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.xmlgraphics.image.loader.util.ImageUtil;
 import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 import org.apache.xmlgraphics.xmp.Metadata;
 import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
@@ -42,6 +39,7 @@ import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
 
 import org.apache.fop.accessibility.Accessibility;
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fo.extensions.xmp.XMPMetadata;
 import org.apache.fop.pdf.PDFAMode;
 import org.apache.fop.pdf.PDFArray;
@@ -118,7 +116,7 @@ class PDFRenderingUtil {
     private boolean disableSRGBColorSpace = false;
 
     /** Optional URI to an output profile to be used. */
-    private String outputProfileURI;
+    private URI outputProfileURI;
 
     private Version maxPDFVersion;
 
@@ -198,7 +196,7 @@ class PDFRenderingUtil {
         }
         s = (String) userAgent.getRendererOption(OUTPUT_PROFILE);
         if (s != null) {
-            this.outputProfileURI = s;
+            this.outputProfileURI = URI.create(s);
         }
         Object disableSRGBColorSpace = userAgent.getRendererOption(DISABLE_SRGB_COLORSPACE);
         if (disableSRGBColorSpace != null) {
@@ -230,7 +228,7 @@ class PDFRenderingUtil {
      * Sets the output color profile for the PDF renderer.
      * @param outputProfileURI the URI to the output color profile
      */
-    public void setOutputProfileURI(String outputProfileURI) {
+    public void setOutputProfileURI(URI outputProfileURI) {
         this.outputProfileURI = outputProfileURI;
     }
 
@@ -303,15 +301,7 @@ class PDFRenderingUtil {
         InputStream in = null;
         if (this.outputProfileURI != null) {
             this.outputProfile = pdfDoc.getFactory().makePDFICCStream();
-            Source src = getUserAgent().resolveURI(this.outputProfileURI);
-            if (src == null) {
-                throw new IOException("Output profile not found: " + this.outputProfileURI);
-            }
-            if (src instanceof StreamSource) {
-                in = ((StreamSource)src).getInputStream();
-            } else {
-                in = new URL(src.getSystemId()).openStream();
-            }
+            in = getUserAgent().getResourceResolver().getResource(outputProfileURI);
             try {
                 profile = ColorProfileUtil.getICC_Profile(in);
             } finally {
@@ -471,8 +461,13 @@ class PDFRenderingUtil {
         //Create embedded file
         PDFEmbeddedFile file = new PDFEmbeddedFile();
         this.pdfDoc.registerObject(file);
-        Source src = getUserAgent().resolveURI(embeddedFile.getSrc());
-        InputStream in = ImageUtil.getInputStream(src);
+        URI srcURI;
+        try {
+            srcURI = InternalResourceResolver.cleanURI(embeddedFile.getSrc());
+        } catch (URISyntaxException use) {
+            throw new RuntimeException(use);
+        }
+        InputStream in = getUserAgent().getResourceResolver().getResource(srcURI);
         if (in == null) {
             throw new FileNotFoundException(embeddedFile.getSrc());
         }
index 2199df4f9f3704b3421f899961a8b1174bc22b7e..e5eba3ea290af8e63d71bd0be77db592a9336f40 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.svg;
 
+import java.io.File;
+import java.net.URI;
 import java.util.List;
 
 import org.apache.avalon.framework.configuration.Configuration;
@@ -85,7 +87,8 @@ public class PDFDocumentGraphics2DConfigurator {
         FontInfo fontInfo = new FontInfo();
         final boolean strict = false;
         if (cfg != null) {
-            InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultWrapper();
+            URI thisUri = new File(".").getAbsoluteFile().toURI();
+            InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultInternalResourceResolver(thisUri);
             //TODO The following could be optimized by retaining the FontManager somewhere
             FontManager fontManager = new FontManager(resourceResolver, FontDetectorFactory.createDefault(),
                     FontCacheManagerFactory.createDefault());
index de35db94e75ad69d5c135925048284b5d0a032ac..0f20a196725e825857d964ca26e9a96c457b73bc 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.fop;
 
 import org.apache.batik.transcoder.Transcoder;
+
 import org.apache.fop.svg.PDFTranscoder;
 
 /**
index 27a3a41d074951f8f7e4b513cb82f7ad2d326192..21540221fc03148ed72958375efb08dff1a4ecde 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.fop.afp;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 
 import org.junit.Before;
@@ -41,7 +42,8 @@ public class AFPResourceManagerTestCase {
 
     @Before
     public void setUp() throws IOException {
-        sut = new AFPResourceManager(ResourceResolverFactory.createDefaultWrapper());
+        sut = new AFPResourceManager(ResourceResolverFactory.createDefaultInternalResourceResolver(
+                                                            new File(".").toURI()));
         AFPPaintingState paintingState = new AFPPaintingState();
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         DataStream stream = sut.createDataStream(paintingState, outStream);
index 6d0daa2bea51f6683dcbe8e6fd6dc3481a935271..ee2fd7876f1dd1f21dceca0d3b1de4f746bf0778 100644 (file)
@@ -39,9 +39,8 @@ public class CharactersetEncoderTestCase {
 
     @Before
     public void setUp() {
-        singlebyteEncoder = CharactersetEncoder.newInstance("cp500", CharacterSetType.SINGLE_BYTE);
-        doublebyteEncoder = CharactersetEncoder.newInstance("cp937",
-                CharacterSetType.DOUBLE_BYTE_LINE_DATA);
+        singlebyteEncoder = CharacterSetType.SINGLE_BYTE.getEncoder("cp500");
+        doublebyteEncoder = CharacterSetType.DOUBLE_BYTE_LINE_DATA.getEncoder("cp937");
     }
 
     // This is just an arbitrary CJK string
index 7a427c548eeaaae5d12acd471d149668512494e0..35748743f42d0accda84fef8154af88769da95df 100644 (file)
@@ -24,8 +24,8 @@ import java.io.File;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 
 import static org.junit.Assert.assertEquals;
 
@@ -34,8 +34,8 @@ import static org.junit.Assert.assertEquals;
  */
 public class DejaVuLGCSerifTestCase {
 
-    private InternalResourceResolver resolver = new InternalResourceResolver(new File(".").toURI(),
-            ResourceResolverFactory.createDefaultResourceResolver());
+    private InternalResourceResolver resolver =
+            ResourceResolverFactory.createDefaultInternalResourceResolver(new File(".").toURI());
     private CustomFont font;
 
     /**
index f80ce7521dac45a58d9bdd2292824cb281a466ac..b1dc571f966f8adf9eae20514a5130da280c4bed 100644 (file)
@@ -25,8 +25,8 @@ import java.net.URI;
 
 import org.junit.Test;
 
-import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.EncodingMode;
 
 import static org.junit.Assert.assertFalse;
@@ -42,18 +42,19 @@ public class TTFFontLoaderTestCase {
         boolean useComplexScriptFeatures = false;
         File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
         URI absoluteFilePath = file.toURI();
-        InternalResourceResolver resolver = ResourceResolverFactory.createDefaultWrapper();
+        InternalResourceResolver resourceResolver = ResourceResolverFactory.createDefaultInternalResourceResolver(
+                                                                           new File(".").toURI());
         String fontName = "Deja Vu";
         boolean embedded = false;
         boolean useKerning = true;
 
         TTFFontLoader fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded,
-                EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resolver);
+                EncodingMode.AUTO, useKerning, useComplexScriptFeatures, resourceResolver);
         assertTrue(fontLoader.getFont().hasKerningInfo());
         useKerning = false;
 
         fontLoader = new TTFFontLoader(absoluteFilePath, fontName, embedded, EncodingMode.AUTO,
-                useKerning, useComplexScriptFeatures, resolver);
+                useKerning, useComplexScriptFeatures, resourceResolver);
         assertFalse(fontLoader.getFont().hasKerningInfo());
     }
 }
index a781c3c8a54f110c0a6f104984f6381da454a208..ac9df4046544f688320f2d4b0d1b8756251d5a5b 100644 (file)
 
 package org.apache.fop.pdf;
 
+import java.io.File;
+import java.net.URI;
+
 import org.junit.Test;
 
-import org.apache.fop.apps.io.ResourceResolverFactory;
 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.CIDSubset;
 import org.apache.fop.fonts.MultiByteFont;
 
@@ -56,7 +60,11 @@ public class PDFFactoryTestCase {
         }
         PDFDocument doc = new PDFDocument("Test");
         PDFFactory pdfFactory = new PDFFactory(doc);
-        MockedFont font = new MockedFont(ResourceResolverFactory.createDefaultWrapper());
+        URI thisURI = new File(".").toURI();
+        ResourceResolver resolver = ResourceResolverFactory.createDefaultResourceResolver();
+        InternalResourceResolver resourceResolver = ResourceResolverFactory.createInternalResourceResolver(
+                thisURI, resolver);
+        MockedFont font = new MockedFont(resourceResolver);
 
         PDFFont pdfDejaVu = pdfFactory.makeFont("DejaVu", "DejaVu", "TTF", font, font);
         assertEquals("/EAAAAA+DejaVu", pdfDejaVu.getBaseFont().toString());
index a48d7546236a7ecd51536a39f99209da97e67646..93a48a62bb2ff9e14da178aeb238069d919759ef 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.fop.render.pdf;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
@@ -221,9 +222,9 @@ public class PDFRendererConfiguratorTestCase extends
 
     @Test
     public void testSetProfile() throws Exception {
-        String testString = "this string is purely for testing and has no contextual meaning";
+        String testString = "this.uri.is.purely.for.testing.and.has.no.contextual.meaning";
         parseConfigMockUtil(createBuilder().setOutputProfile(testString));
-        verify(pdfUtil).setOutputProfileURI(testString);
+        verify(pdfUtil).setOutputProfileURI(URI.create(testString));
     }
 
     @Test