xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject svn commit: r1344594 [3/15] - in /xmlgraphics/fop/branches/Temp_URI_Unification: ./ examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/events/ examples/embedding/java/embedding/intermediate/ sr...
Date Thu, 31 May 2012 08:33:50 GMT
Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryBuilder.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryBuilder.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryBuilder.java Thu May 31 08:33:36 2012
@@ -0,0 +1,744 @@
+/*
+ * 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;
+
+import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.transform.URIResolver;
+
+import org.apache.avalon.framework.configuration.Configuration;
+
+import org.apache.xmlgraphics.image.loader.ImageContext;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+
+import org.apache.fop.apps.io.DefaultResourceResolver;
+import org.apache.fop.apps.io.FOURIResolver;
+import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.fonts.FontManager;
+import org.apache.fop.hyphenation.HyphenationTreeResolver;
+import org.apache.fop.layoutmgr.LayoutManagerMaker;
+
+/**
+ * This is the builder class for {@link FopFactory}. Setters can be chained to
+ * make building a {@link FopFactory} object more concise and intuitive e.g.
+ *
+ * <pre>
+ * {@code
+ * FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(<URI>)
+ *                                                  .setURIResolver(<URIResolver>)
+ *                                                  .setPageHeight(<String>)
+ *                                                  .setPageWidth(<String>)
+ *                                                  .setStrictUserConfigValidation(<boolean>)
+ *                                                    ... etc ...
+ * FopFactory fopFactory = fopFactoryBuilder.build();
+ * }
+ * </pre>
+ */
+public final class FopFactoryBuilder {
+
+    private final FopFactoryConfig config;
+
+    private FopFactoryConfigBuilder fopFactoryConfigBuilder;
+
+    /**
+     * A builder class for {@link FopFactory} which can be used for setting configuration. This is
+     * a helper constructor that uses the default URI resolver implementation that FOP packages
+     * provide ({@link DefaultResourceResolver}).
+     *
+     * @param defaultBaseURI the default base URI for resolving URIs against
+     */
+    public FopFactoryBuilder(URI defaultBaseURI) {
+        this(defaultBaseURI, new DefaultResourceResolver());
+    }
+
+    /**
+     * A builder class for {@link FopFactory} which can be used for setting configuration.
+     *
+     * @param defaultBaseURI the default base URI for resolving URIs against
+     * @param uriResolver the URI resolver
+     */
+    public FopFactoryBuilder(URI defaultBaseURI, ResourceResolver uriResolver) {
+        this(EnvironmentalProfileFactory.createDefault(defaultBaseURI, uriResolver));
+    }
+
+    /**
+     * A builder class for {@link FopFactory} which can be used for setting configuration.
+     *
+     * @param enviro the profile of the FOP deployment environment
+     */
+    public FopFactoryBuilder(EnvironmentProfile enviro) {
+        config = new FopFactoryConfigImpl(enviro);
+        fopFactoryConfigBuilder = new ActiveFopFactoryConfigBuilder((FopFactoryConfigImpl) config);
+    }
+
+    /**
+     * Returns the {@link FopFactoryConfig} which is needed to get an instance of
+     * {@link FopFactory}.
+     *
+     * @return build the {@link FopFactoryConfig}
+     * @deprecated Exposing the {@link FopFactoryConfig} is only to maintain backwards compatibility
+     */
+    public FopFactoryConfig buildConfig() {
+        fopFactoryConfigBuilder = CompletedFopFactoryConfigBuilder.INSTANCE;
+        return config;
+    }
+
+    /**
+     * Builds an instance of the the {@link FopFactory}.
+     *
+     * @return the FopFactory instance
+     */
+    public FopFactory build() {
+        return FopFactory.newInstance(buildConfig());
+    }
+
+    /**
+     * Gets the base URI used to resolve all URIs within FOP.
+     *
+     * @return the base URI
+     */
+    URI getBaseUri() {
+        return config.getBaseURI();
+    }
+
+    /**
+     * Returns the {@link FontManager} used for managing the fonts within FOP.
+     *
+     * @return the font managing object
+     */
+    public FontManager getFontManager() {
+        return config.getFontManager();
+    }
+
+    /**
+     * Return the {@link ImageManager} used for handling images through out FOP.
+     *
+     * @return the image manager
+     */
+    public ImageManager getImageManager() {
+        return config.getImageManager();
+    }
+
+    /**
+     * Sets whether to include accessibility features in document creation.
+     *
+     * @param enableAccessibility true to set accessibility on
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setAccessibility(boolean enableAccessibility) {
+        fopFactoryConfigBuilder.setAccessibility(enableAccessibility);
+        return this;
+    }
+
+    /**
+     * Sets the {@link LayoutManagerMaker} so that users can configure how FOP creates
+     * {@link LayoutManager}s.
+     *
+     * @param lmMaker he layout manager maker
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setLayoutManagerMakerOverride(
+            LayoutManagerMaker lmMaker) {
+        fopFactoryConfigBuilder.setLayoutManagerMakerOverride(lmMaker);
+        return this;
+    }
+
+    /**
+     * Sets the URI resolver to be used for controlling FOP's file access.
+     *
+     * @param resolver the URI resolver
+     * @return <code>this</code>
+     * @deprecated this URIResolver will be phased out in favour of a unified URI resolution
+     * mechanism
+     */
+    public FopFactoryBuilder setURIResolver(URIResolver resolver) {
+        fopFactoryConfigBuilder.setURIResolver(resolver);
+        return this;
+    }
+
+    /**
+     * Sets the base URI, this will be used for resolving all URIs given to FOP.
+     *
+     * @param baseURI the base URI
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setBaseURI(URI baseURI) {
+        fopFactoryConfigBuilder.setBaseURI(baseURI);
+        return this;
+    }
+
+    /**
+     * Sets the base URI for hyphenation data.
+     *
+     * @param hyphenationBase the hyphenation-base-URI
+     * @return <code>this</code>
+     * @deprecated this will be phased out in favour of a unified URI resolution mechanism
+     */
+    public FopFactoryBuilder setHyphenationBaseURI(URI hyphenationBase) {
+        fopFactoryConfigBuilder.setHyphenationBaseURI(hyphenationBase);
+        return this;
+    }
+
+    /**
+     * Sets the URI resolver specific to Hyphenation data.
+     *
+     * @param hyphResolver the hyphenation-URI-resolver
+     * @return <code>this</code>
+     * @deprecated this will be phased out in favour of a unified URI resolution mechanism
+     */
+    public FopFactoryBuilder setHyphenationTreeResolver(
+            HyphenationTreeResolver hyphResolver) {
+        fopFactoryConfigBuilder.setHyphenationTreeResolver(hyphResolver);
+        return this;
+
+    }
+
+    /**
+     * Sets whether to perform strict validation on the FO used.
+     *
+     * @param validateStrictly true if the FO is to be strictly validated
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setStrictFOValidation(boolean validateStrictly) {
+        fopFactoryConfigBuilder.setStrictFOValidation(validateStrictly);
+        return this;
+    }
+
+    /**
+     * Sets whether to perform strict alidation on the user-configuration.
+     *
+     * @param validateStrictly true if the fop conf is to be strictly validated
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setStrictUserConfigValidation(
+            boolean validateStrictly) {
+        fopFactoryConfigBuilder.setStrictUserConfigValidation(validateStrictly);
+        return this;
+    }
+
+    /**
+     * Sets whether the indent inheritance should be broken when crossing reference area boundaries.
+     *
+     * @param value true to break inheritance when crossing reference area boundaries
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setBreakIndentInheritanceOnReferenceAreaBoundary(
+            boolean value) {
+        fopFactoryConfigBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary(value);
+        return this;
+    }
+
+    /**
+     * Sets the resolution of resolution-dependent input.
+     *
+     * @param dpi the source resolution
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setSourceResolution(float dpi) {
+        fopFactoryConfigBuilder.setSourceResolution(dpi);
+        return this;
+    }
+
+    /**
+     * Sets the resolution of resolution-dependent output.
+     *
+     * @param dpi the target resolution
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setTargetResolution(float dpi) {
+        fopFactoryConfigBuilder.setTargetResolution(dpi);
+        return this;
+    }
+
+    /**
+     * Sets the page height of the paginated output.
+     *
+     * @param pageHeight the page height
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setPageHeight(String pageHeight) {
+        fopFactoryConfigBuilder.setPageHeight(pageHeight);
+        return this;
+    }
+
+    /**
+     * Sets the page width of the paginated output.
+     *
+     * @param pageWidth the page width
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setPageWidth(String pageWidth) {
+        fopFactoryConfigBuilder.setPageWidth(pageWidth);
+        return this;
+    }
+
+    /**
+     * FOP will ignore the specified XML element namespace.
+     *
+     * @param namespaceURI the namespace URI to ignore
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder ignoreNamespace(String namespaceURI) {
+        fopFactoryConfigBuilder.ignoreNamespace(namespaceURI);
+        return this;
+    }
+
+    /**
+     * FOP will ignore the colletion of XML element namespaces.
+     *
+     * @param namespaceURIs a collection of namespace URIs to ignore
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder ignoreNamespaces(Collection<String> namespaceURIs) {
+        fopFactoryConfigBuilder.ignoreNamespaces(namespaceURIs);
+        return this;
+    }
+
+    /**
+     * Sets the Avalon configuration if a FOP conf is used.
+     *
+     * @param cfg the fop conf configuration
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setConfiguration(Configuration cfg) {
+        fopFactoryConfigBuilder.setConfiguration(cfg);
+        return this;
+    }
+
+    /**
+     * Sets whether to chose a {@link Renderer} in preference to an
+     * {@link org.apache.fop.render.intermediate.IFDocumentHandler}.
+     *
+     * @see {@link RendererFactory}
+     * @param preferRenderer true to prefer {@link Renderer}
+     * @return <code>this</code>
+     */
+    public FopFactoryBuilder setPreferRenderer(boolean preferRenderer) {
+        fopFactoryConfigBuilder.setPreferRenderer(preferRenderer);
+        return this;
+    }
+
+    public FopFactoryBuilder setComplexScriptFeatures(boolean csf) {
+        fopFactoryConfigBuilder.setComplexScriptFeaturesEnabled(csf);
+        return this;
+    }
+
+    public FopFactoryBuilder setHyphPatNames(Map<String, String> hyphPatNames) {
+        fopFactoryConfigBuilder.setHyphPatNames(hyphPatNames);
+        return this;
+    }
+
+    public static class FopFactoryConfigImpl implements FopFactoryConfig {
+
+        private final EnvironmentProfile enviro;
+
+        private final ImageManager imageManager;
+
+        private boolean accessibility;
+
+        private LayoutManagerMaker layoutManagerMaker;
+
+        private URI baseURI;
+
+        private URI hyphenationBaseURI;
+
+        private HyphenationTreeResolver hyphenationTreeResolver;
+
+        private boolean hasStrictFOValidation = true;
+
+        private boolean hasStrictUserValidation = FopFactoryConfig.DEFAULT_STRICT_USERCONFIG_VALIDATION;
+
+        private boolean breakIndentInheritanceOnReferenceBoundary
+        = FopFactoryConfig.DEFAULT_BREAK_INDENT_INHERITANCE;
+
+        private float sourceResolution = FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION;
+
+        private float targetResolution = FopFactoryConfig.DEFAULT_TARGET_RESOLUTION;
+
+        private String pageHeight = FopFactoryConfig.DEFAULT_PAGE_HEIGHT;
+
+        private String pageWidth = FopFactoryConfig.DEFAULT_PAGE_WIDTH;
+
+        private Set<String> ignoredNamespaces = new HashSet<String>();
+
+        private URIResolver resolver;
+
+        private Configuration cfg;
+
+        private boolean preferRenderer;
+
+        private boolean isComplexScript = true;
+
+        private Map<String, String> hyphPatNames;
+
+        private static final class ImageContextImpl implements ImageContext {
+
+            private final FopFactoryConfig config;
+
+            ImageContextImpl(FopFactoryConfig config) {
+                this.config = config;
+            }
+
+            public float getSourceResolution() {
+                return config.getSourceResolution();
+            }
+        }
+
+        FopFactoryConfigImpl(EnvironmentProfile enviro) {
+            this.enviro = enviro;
+            this.baseURI = enviro.getDefaultBaseURI();
+            this.imageManager = new ImageManager(new ImageContextImpl(this));
+            this.resolver = new FOURIResolver();
+        }
+
+        /** {@inheritDoc} */
+        public boolean isAccessibilityEnabled() {
+            return accessibility;
+        }
+
+        /** {@inheritDoc} */
+        public LayoutManagerMaker getLayoutManagerMakerOverride() {
+            return layoutManagerMaker;
+        }
+
+        /** {@inheritDoc} */
+        public ResourceResolver getNewURIResolver() {
+            return enviro.getResourceResolver();
+        }
+
+        /** {@inheritDoc} */
+        public URIResolver getURIResolver() {
+            return resolver;
+        }
+
+        /** {@inheritDoc} */
+        public URI getBaseURI() {
+            return baseURI;
+        }
+
+        /** {@inheritDoc} */
+        public URI getHyphenationBaseURI() {
+            return hyphenationBaseURI;
+        }
+
+        /** {@inheritDoc} */
+        public HyphenationTreeResolver getHyphenationTreeResolver() {
+            return hyphenationTreeResolver;
+        }
+
+        /** {@inheritDoc} */
+        public boolean validateStrictly() {
+            return hasStrictFOValidation;
+        }
+
+        /** {@inheritDoc} */
+        public boolean validateUserConfigStrictly() {
+            return hasStrictUserValidation;
+        }
+
+        /** {@inheritDoc} */
+        public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
+            return breakIndentInheritanceOnReferenceBoundary;
+        }
+
+        /** {@inheritDoc} */
+        public float getSourceResolution() {
+            return sourceResolution;
+        }
+
+        /** {@inheritDoc} */
+        public float getTargetResolution() {
+            return targetResolution;
+        }
+
+        /** {@inheritDoc} */
+        public String getPageHeight() {
+            return pageHeight;
+        }
+
+        /** {@inheritDoc} */
+        public String getPageWidth() {
+            return pageWidth;
+        }
+
+        /** {@inheritDoc} */
+        public Set<String> getIgnoredNamespaces() {
+            return Collections.unmodifiableSet(ignoredNamespaces);
+        }
+
+        /** {@inheritDoc} */
+        public boolean isNamespaceIgnored(String namespace) {
+            return ignoredNamespaces.contains(namespace);
+        }
+
+        /** {@inheritDoc} */
+        public Configuration getUserConfig() {
+            return cfg;
+        }
+
+        /** {@inheritDoc} */
+        public boolean preferRenderer() {
+            return preferRenderer;
+        }
+
+        /** {@inheritDoc} */
+        public FontManager getFontManager() {
+            return enviro.getFontManager();
+        }
+
+        /** {@inheritDoc} */
+        public ImageManager getImageManager() {
+            return imageManager;
+        }
+
+        public boolean isComplexScriptFeaturesEnabled() {
+            return isComplexScript;
+        }
+
+        public Map<String, String> getHyphPatNames() {
+            return hyphPatNames;
+        }
+    }
+
+    private interface FopFactoryConfigBuilder {
+
+        void setAccessibility(boolean enableAccessibility);
+
+        void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker);
+
+        void setURIResolver(URIResolver resolver);
+
+        void setBaseURI(URI baseURI);
+
+        void setHyphenationBaseURI(URI hyphenationBase);
+
+        void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver);
+
+        void setStrictFOValidation(boolean validateStrictly);
+
+        void setStrictUserConfigValidation(boolean validateStrictly);
+
+        void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value);
+
+        void setSourceResolution(float dpi);
+
+        void setTargetResolution(float dpi);
+
+        void setPageHeight(String pageHeight);
+
+        void setPageWidth(String pageWidth);
+
+        void ignoreNamespace(String namespaceURI);
+
+        void ignoreNamespaces(Collection<String> namespaceURIs);
+
+        void setConfiguration(Configuration cfg);
+
+        void setPreferRenderer(boolean preferRenderer);
+
+        void setComplexScriptFeaturesEnabled(boolean csf);
+
+        void setHyphPatNames(Map<String, String> hyphPatNames);
+    }
+
+    private static final class CompletedFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
+
+        private static final CompletedFopFactoryConfigBuilder INSTANCE
+        = new CompletedFopFactoryConfigBuilder();
+
+        private void throwIllegalStateException() {
+            throw new IllegalStateException("The final FOP Factory configuration has already been built");
+        }
+
+        public void setAccessibility(boolean enableAccessibility) {
+            throwIllegalStateException();
+        }
+
+        public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
+            throwIllegalStateException();
+
+        }
+
+        public void setURIResolver(URIResolver resolver) {
+            throwIllegalStateException();
+        }
+
+        public void setBaseURI(URI baseURI) {
+            throwIllegalStateException();
+        }
+
+        public void setHyphenationBaseURI(URI hyphenationBase) {
+            throwIllegalStateException();
+        }
+
+        public void setHyphenationTreeResolver(
+                HyphenationTreeResolver hyphResolver) {
+            throwIllegalStateException();
+        }
+
+        public void setStrictFOValidation(boolean validateStrictly) {
+            throwIllegalStateException();
+        }
+
+        public void setStrictUserConfigValidation(boolean validateStrictly) {
+            throwIllegalStateException();
+        }
+
+        public void setBreakIndentInheritanceOnReferenceAreaBoundary(
+                boolean value) {
+            throwIllegalStateException();
+        }
+
+        public void setSourceResolution(float dpi) {
+            throwIllegalStateException();
+        }
+
+        public void setTargetResolution(float dpi) {
+            throwIllegalStateException();
+        }
+
+        public void setPageHeight(String pageHeight) {
+            throwIllegalStateException();
+        }
+
+        public void setPageWidth(String pageWidth) {
+            throwIllegalStateException();
+        }
+
+        public void ignoreNamespace(String namespaceURI) {
+            throwIllegalStateException();
+        }
+
+        public void ignoreNamespaces(Collection<String> namespaceURIs) {
+            throwIllegalStateException();
+        }
+
+        public void setConfiguration(Configuration cfg) {
+            throwIllegalStateException();
+        }
+
+        public void setPreferRenderer(boolean preferRenderer) {
+            throwIllegalStateException();
+        }
+
+        public void setComplexScriptFeaturesEnabled(boolean csf) {
+            throwIllegalStateException();
+        }
+
+        public void setHyphPatNames(Map<String, String> hyphPatNames) {
+            throwIllegalStateException();
+        }
+
+    }
+
+    private static final class ActiveFopFactoryConfigBuilder implements FopFactoryConfigBuilder {
+
+        private final FopFactoryConfigImpl config;
+
+        private ActiveFopFactoryConfigBuilder(FopFactoryConfigImpl config) {
+            this.config = config;
+        }
+
+        public void setAccessibility(boolean enableAccessibility) {
+            config.accessibility = enableAccessibility;
+        }
+
+        public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
+            config.layoutManagerMaker = lmMaker;
+        }
+
+        public void setURIResolver(URIResolver resolver) {
+            config.resolver = resolver;
+        }
+
+        public void setBaseURI(URI baseURI) {
+            config.baseURI = baseURI;
+        }
+
+        public void setHyphenationBaseURI(URI hyphenationBase) {
+            config.hyphenationBaseURI = hyphenationBase;
+        }
+
+        public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) {
+            config.hyphenationTreeResolver = hyphResolver;
+        }
+
+        public void setStrictFOValidation(boolean validateStrictly) {
+            config.hasStrictFOValidation = validateStrictly;
+        }
+
+        public void setStrictUserConfigValidation(
+                boolean validateStrictly) {
+            config.hasStrictUserValidation = validateStrictly;
+        }
+
+        public void setBreakIndentInheritanceOnReferenceAreaBoundary(
+                boolean value) {
+            config.breakIndentInheritanceOnReferenceBoundary = value;
+        }
+
+        public void setSourceResolution(float dpi) {
+            config.sourceResolution = dpi;
+        }
+
+        public void setTargetResolution(float dpi) {
+            config.targetResolution = dpi;
+        }
+
+        public void setPageHeight(String pageHeight) {
+            config.pageHeight = pageHeight;
+        }
+
+        public void setPageWidth(String pageWidth) {
+            config.pageWidth = pageWidth;
+        }
+
+        public void ignoreNamespace(String namespaceURI) {
+            config.ignoredNamespaces.add(namespaceURI);
+        }
+
+        public void ignoreNamespaces(
+                Collection<String> namespaceURIs) {
+            config.ignoredNamespaces.addAll(namespaceURIs);
+        }
+
+        public void setConfiguration(Configuration cfg) {
+            config.cfg = cfg;
+        }
+
+        public void setPreferRenderer(boolean preferRenderer) {
+            config.preferRenderer = preferRenderer;
+        }
+
+        public void setComplexScriptFeaturesEnabled(boolean csf) {
+            config.isComplexScript = csf;
+        }
+
+        public void setHyphPatNames(Map<String, String> hyphPatNames) {
+            config.hyphPatNames = hyphPatNames;
+        }
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryConfig.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryConfig.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryConfig.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryConfig.java Thu May 31 08:33:36 2012
@@ -0,0 +1,159 @@
+/*
+ * 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;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.transform.URIResolver;
+
+import org.apache.avalon.framework.configuration.Configuration;
+
+import org.apache.xmlgraphics.image.loader.ImageManager;
+
+import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.fonts.FontManager;
+import org.apache.fop.hyphenation.HyphenationTreeResolver;
+import org.apache.fop.layoutmgr.LayoutManagerMaker;
+
+/**
+ * The configuration data for a {@link FopFactory} instance.
+ */
+public interface FopFactoryConfig {
+
+    /** Defines if FOP should use an alternative rule to determine text indents */
+    boolean DEFAULT_BREAK_INDENT_INHERITANCE = false;
+
+    /** Defines if FOP should validate the user config strictly */
+    boolean DEFAULT_STRICT_USERCONFIG_VALIDATION = true;
+
+    /** Defines if FOP should use strict validation for FO and user config */
+    boolean DEFAULT_STRICT_FO_VALIDATION = true;
+
+    /** Defines the default page-width */
+    String DEFAULT_PAGE_WIDTH = "8.26in";
+
+    /** Defines the default page-height */
+    String DEFAULT_PAGE_HEIGHT = "11in";
+
+    /** Defines the default source resolution (72dpi) for FOP */
+    float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi
+
+    /** Defines the default target resolution (72dpi) for FOP */
+    float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi
+
+    /**
+     * Whether accessibility features are switched on.
+     *
+     * @return true if accessibility features have been requested
+     */
+    boolean isAccessibilityEnabled();
+
+    /** @see {@link FopFactory#getLayoutManagerMakerOverride()} */
+    LayoutManagerMaker getLayoutManagerMakerOverride();
+
+    /**
+     * The URI resolver used through-out FOP for controlling all file access.
+     *
+     * @return the URI resolver
+     */
+    ResourceResolver getNewURIResolver();
+
+    /**
+     * The URI resolver for controlling file access.
+     *
+     * @return the URI resolver
+     * @deprecated please use the {@link #getNewURIResolver()} method.
+     */
+    URIResolver getURIResolver();
+
+    /**
+     * The base URI from which URIs are resolved against.
+     *
+     * @return the base URI
+     */
+    URI getBaseURI();
+
+    /**
+     * The base URI of hyphenation data.
+     *
+     * @return the hyphenation-base-URI
+     * @deprecated this intelligence can be configured in the URI resolver set in
+     * {@link #getNewURIResolver()}
+     */
+    URI getHyphenationBaseURI();
+
+    /**
+     * The URI resolver for resolving hyphenation data.
+     *
+     * @return the hyphenation-URI-resolver
+     * @deprecated this intelligence can be configured in the URI resolver set in
+     * {@link #getNewURIResolver()}
+     */
+    HyphenationTreeResolver getHyphenationTreeResolver();
+
+    /** @see {@link FopFactory#validateStrictly()} */
+    boolean validateStrictly();
+
+    /** @see {@link FopFactory#validateUserConfigStrictly()} */
+    boolean validateUserConfigStrictly();
+
+    /** @see {@link FopFactory#isBreakIndentInheritanceOnReferenceAreaBoundary()} */
+    boolean isBreakIndentInheritanceOnReferenceAreaBoundary();
+
+    /** @see {@link FopFactory#getSourceResolution()} */
+    float getSourceResolution();
+
+    /** @see {@link FopFactory#getTargetResolution()} */
+    float getTargetResolution();
+
+    /** @see {@link FopFactory#getPageHeight()} */
+    String getPageHeight();
+
+    /** @see {@link FopFactory#getPageWidth()} */
+    String getPageWidth();
+
+    /** @see {@link FopFactory#getIgnoredNamespace()} */
+    Set<String> getIgnoredNamespaces();
+
+    /** @see {@link FopFactory#isNamespaceIgnored(String)} */
+    boolean isNamespaceIgnored(String namespace);
+
+    /**
+     * Returns the Avalon {@link Configuration} object.
+     *
+     * @return the Avalon config object
+     */
+    Configuration getUserConfig();
+
+    /** @see {@link org.apache.fop.render.RendererFactory#isRendererPreferred()} */
+    boolean preferRenderer();
+
+    /** @see {@link FopFactory#getFontManager()} */
+    FontManager getFontManager();
+
+    /** @see {@link FopFactory#getImageManager()} */
+    ImageManager getImageManager();
+
+    boolean isComplexScriptFeaturesEnabled();
+
+    Map<String, String> getHyphPatNames();
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactoryConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/DefaultResourceResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/DefaultResourceResolver.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/DefaultResourceResolver.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/DefaultResourceResolver.java Thu May 31 08:33:36 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+
+
+public class DefaultResourceResolver implements ResourceResolver {
+
+    public Resource getResource(URI uri) throws IOException {
+        try {
+            return new Resource(uri.toURL().openStream());
+        } catch (MalformedURLException mue) {
+            throw new RuntimeException(mue);
+        }
+    }
+
+    public OutputStream getOutputStream(URI uri) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    public static URIResolverWrapper 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 URIResolverWrapper(thisUri, new DefaultResourceResolver());
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/DefaultResourceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/FOURIResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/FOURIResolver.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/FOURIResolver.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/FOURIResolver.java Thu May 31 08:33:36 2012
@@ -0,0 +1,377 @@
+/*
+ * 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.ByteArrayOutputStream;
+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;
+
+import javax.xml.transform.Source;
+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.fop.apps.FOUserAgent;
+
+import org.apache.xmlgraphics.util.io.Base64EncodeStream;
+import org.apache.xmlgraphics.util.uri.CommonURIResolver;
+
+/**
+ * Provides FOP specific URI resolution. This is the default URIResolver
+ * {@link FOUserAgent} will use unless overridden.
+ *
+ * @see javax.xml.transform.URIResolver
+ */
+public class FOURIResolver implements javax.xml.transform.URIResolver {
+
+    // log
+    private Log log = LogFactory.getLog("FOP");
+
+    /** Common URIResolver */
+    private CommonURIResolver commonURIResolver = new CommonURIResolver();
+
+    /** A user settable URI Resolver */
+    private URIResolver uriResolver = null;
+
+    /** true if exceptions are to be thrown if the URIs cannot be resolved. */
+    private boolean throwExceptions = false;
+
+    /**
+     * Checks if the given base URL is acceptable. It also normalizes the URL.
+     * @param base the base URL to check
+     * @return the normalized URL
+     * @throws MalformedURLException if there's a problem with a file URL
+     */
+    public String checkBaseURL(String base) throws MalformedURLException {
+        // replace back slash with forward slash to ensure windows file:/// URLS are supported
+        base = base.replace('\\', '/');
+        if (!base.endsWith("/")) {
+            // The behavior described by RFC 3986 regarding resolution of relative
+            // references may be misleading for normal users:
+            // file://path/to/resources + myResource.res -> file://path/to/myResource.res
+            // file://path/to/resources/ + myResource.res -> file://path/to/resources/myResource.res
+            // We assume that even when the ending slash is missing, users have the second
+            // example in mind
+            base += "/";
+        }
+        File dir = new File(base);
+        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());
+            }
+        }
+    }
+
+    /**
+     * Default constructor
+     */
+    public FOURIResolver() {
+        this(false);
+    }
+
+    /**
+     * Additional constructor
+     *
+     * @param throwExceptions
+     *            true if exceptions are to be thrown if the URIs cannot be
+     *            resolved.
+     */
+    public FOURIResolver(boolean throwExceptions) {
+        this.throwExceptions = throwExceptions;
+    }
+
+    /**
+     * Handles resolve exceptions appropriately.
+     *
+     * @param e
+     *            the exception
+     * @param errorStr
+     *            error string
+     * @param strict
+     *            strict user config
+     */
+    private void handleException(Exception e, String errorStr, boolean strict)
+            throws TransformerException {
+        if (strict) {
+            throw new TransformerException(errorStr, e);
+        }
+        log.error(e.getMessage());
+    }
+
+    /**
+     * Called by the processor through {@link FOUserAgent} when it encounters an
+     * uri in an external-graphic element. (see also
+     * {@link javax.xml.transform.URIResolver#resolve(String, String)} This
+     * resolver will allow URLs without a scheme, i.e. it assumes 'file:' as the
+     * default scheme. It also allows relative URLs with scheme, e.g.
+     * file:../../abc.jpg which is not strictly RFC compliant as long as the
+     * scheme is the same as the scheme of the base URL. If the base URL is null
+     * a 'file:' URL referencing the current directory is used as the base URL.
+     * If the method is successful it will return a Source of type
+     * {@link javax.xml.transform.stream.StreamSource} with its SystemID set to
+     * the resolved URL used to open the underlying InputStream.
+     *
+     * @param href
+     *            An href attribute, which may be relative or absolute.
+     * @param base
+     *            The base URI against which the first argument will be made
+     *            absolute if the absolute URI is required.
+     * @return A {@link javax.xml.transform.Source} object, or null if the href
+     *         cannot be resolved.
+     * @throws javax.xml.transform.TransformerException
+     *             Never thrown by this implementation.
+     * @see javax.xml.transform.URIResolver#resolve(String, String)
+     */
+    public Source resolve(String href, String base) throws TransformerException {
+        Source source = null;
+
+        // data URLs can be quite long so evaluate early and don't try to build a File
+        // (can lead to problems)
+        source = commonURIResolver.resolve(href, base);
+
+        // Custom uri resolution
+        if (source == null && uriResolver != null) {
+            source = uriResolver.resolve(href, base);
+        }
+
+        // Fallback to default resolution mechanism
+        if (source == null) {
+            URL absoluteURL = null;
+            int hashPos = href.indexOf('#');
+            String fileURL;
+            String fragment;
+            if (hashPos >= 0) {
+                fileURL = href.substring(0, hashPos);
+                fragment = href.substring(hashPos);
+            } else {
+                fileURL = href;
+                fragment = null;
+            }
+            File file = new File(fileURL);
+            if (file.canRead() && file.isFile()) {
+                try {
+                    if (fragment != null) {
+                        absoluteURL = new URL(file.toURI().toURL().toExternalForm() + fragment);
+                    } else {
+                        absoluteURL = file.toURI().toURL();
+                    }
+                } catch (MalformedURLException mfue) {
+                    handleException(mfue, "Could not convert filename '" + href
+                            + "' to URL", throwExceptions);
+                }
+            } else {
+                // no base provided
+                if (base == null) {
+                    // We don't have a valid file protocol based URL
+                    try {
+                        absoluteURL = new URL(href);
+                    } catch (MalformedURLException mue) {
+                        try {
+                            // the above failed, we give it another go in case
+                            // the href contains only a path then file: is
+                            // assumed
+                            absoluteURL = new URL("file:" + href);
+                        } catch (MalformedURLException mfue) {
+                            handleException(mfue, "Error with URL '" + href
+                                    + "'", throwExceptions);
+                        }
+                    }
+
+                    // try and resolve from context of base
+                } else {
+                    URL baseURL = null;
+                    try {
+                        baseURL = new URL(base);
+                    } catch (MalformedURLException mfue) {
+                        handleException(mfue, "Error with base URL '" + base
+                                + "'", throwExceptions);
+                    }
+
+                    /*
+                     * This piece of code is based on the following statement in
+                     * RFC2396 section 5.2:
+                     *
+                     * 3) If the scheme component is defined, indicating that
+                     * the reference starts with a scheme name, then the
+                     * reference is interpreted as an absolute URI and we are
+                     * done. Otherwise, the reference URI's scheme is inherited
+                     * from the base URI's scheme component.
+                     *
+                     * Due to a loophole in prior specifications [RFC1630], some
+                     * parsers allow the scheme name to be present in a relative
+                     * URI if it is the same as the base URI scheme.
+                     * Unfortunately, this can conflict with the correct parsing
+                     * of non-hierarchical URI. For backwards compatibility, an
+                     * implementation may work around such references by
+                     * removing the scheme if it matches that of the base URI
+                     * and the scheme is known to always use the <hier_part>
+                     * syntax.
+                     *
+                     * The URL class does not implement this work around, so we
+                     * do.
+                     */
+                    assert (baseURL != null);
+                    String scheme = baseURL.getProtocol() + ":";
+                    if (href.startsWith(scheme) && "file:".equals(scheme)) {
+                        href = href.substring(scheme.length());
+                        int colonPos = href.indexOf(':');
+                        int slashPos = href.indexOf('/');
+                        if (slashPos >= 0 && colonPos >= 0
+                                && colonPos < slashPos) {
+                            href = "/" + href; // Absolute file URL doesn't
+                            // have a leading slash
+                        }
+                    }
+                    try {
+                        absoluteURL = new URL(baseURL, href);
+                    } catch (MalformedURLException mfue) {
+                        handleException(mfue, "Error with URL; base '" + base
+                                + "' " + "href '" + href + "'", throwExceptions);
+                    }
+                }
+            }
+
+            if (absoluteURL != null) {
+                String effURL = absoluteURL.toExternalForm();
+                try {
+                    URLConnection connection = absoluteURL.openConnection();
+                    connection.setAllowUserInteraction(false);
+                    connection.setDoInput(true);
+                    updateURLConnection(connection, href);
+                    connection.connect();
+                    return new StreamSource(connection.getInputStream(), effURL);
+                } catch (FileNotFoundException fnfe) {
+                    // Note: This is on "debug" level since the caller is
+                    // supposed to handle this
+                    log.debug("File not found: " + effURL);
+                } catch (java.io.IOException ioe) {
+                    log.error("Error with opening URL '" + effURL + "': "
+                            + ioe.getMessage());
+                }
+            }
+        }
+        return source;
+    }
+
+    /**
+     * This method allows you to set special values on a URLConnection just
+     * before the connect() method is called. Subclass FOURIResolver and
+     * override this method to do things like adding the user name and password
+     * for HTTP basic authentication.
+     *
+     * @param connection
+     *            the URLConnection instance
+     * @param href
+     *            the original URI
+     */
+    protected void updateURLConnection(URLConnection connection, String href) {
+        // nop
+    }
+
+    /**
+     * This is a convenience method for users who want to override
+     * updateURLConnection for HTTP basic authentication. Simply call it using
+     * the right username and password.
+     *
+     * @param connection
+     *            the URLConnection to set up for HTTP basic authentication
+     * @param username
+     *            the username
+     * @param password
+     *            the password
+     */
+    protected void applyHttpBasicAuthentication(URLConnection connection,
+            String username, String password) {
+        String combined = username + ":" + password;
+        try {
+            ByteArrayOutputStream baout = new ByteArrayOutputStream(combined
+                    .length() * 2);
+            Base64EncodeStream base64 = new Base64EncodeStream(baout);
+            // TODO Not sure what charset/encoding can be used with basic
+            // authentication
+            base64.write(combined.getBytes("UTF-8"));
+            base64.close();
+            connection.setRequestProperty("Authorization", "Basic "
+                    + new String(baout.toByteArray(), "UTF-8"));
+        } catch (IOException e) {
+            // won't happen. We're operating in-memory.
+            throw new RuntimeException(
+                    "Error during base64 encodation of username/password");
+        }
+    }
+
+    /**
+     * Sets the custom URI Resolver. It is used for resolving factory-level URIs like
+     * hyphenation patterns and as backup for URI resolution performed during a
+     * rendering run.
+     *
+     * @param resolver
+     *            the new URI resolver
+     */
+    public void setCustomURIResolver(URIResolver resolver) {
+        this.uriResolver = resolver;
+    }
+
+    /**
+     * Returns the custom URI Resolver.
+     *
+     * @return the URI Resolver or null, if none is set
+     */
+    public URIResolver getCustomURIResolver() {
+        return this.uriResolver;
+    }
+
+    /**
+     * @param throwExceptions
+     *            Whether or not to throw exceptions on resolution error
+     */
+    public void setThrowExceptions(boolean throwExceptions) {
+        this.throwExceptions = throwExceptions;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/FOURIResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/Resource.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/Resource.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/Resource.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/Resource.java Thu May 31 08:33:36 2012
@@ -0,0 +1,59 @@
+/*
+ * 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;
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/Resource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/ResourceResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/ResourceResolver.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/ResourceResolver.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/ResourceResolver.java Thu May 31 08:33:36 2012
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+public interface ResourceResolver {
+
+    Resource getResource(URI uri) throws IOException;
+
+    OutputStream getOutputStream(URI uri) throws IOException;
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/ResourceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/URIResolverWrapper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/URIResolverWrapper.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/URIResolverWrapper.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/URIResolverWrapper.java Thu May 31 08:33:36 2012
@@ -0,0 +1,74 @@
+/*
+ * 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.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+
+public class URIResolverWrapper {
+    private final URI baseUri;
+    private final ResourceResolver uriResolver;
+
+    public URIResolverWrapper(URI baseUri, ResourceResolver uriResolver) {
+        this.baseUri = baseUri;
+        this.uriResolver = uriResolver;
+    }
+
+    public URI getBaseURI() {
+        return baseUri;
+    }
+
+    public InputStream resolveIn(String stringUri) throws IOException, URISyntaxException {
+        return resolveIn(cleanURI(stringUri));
+    }
+
+    public InputStream resolveIn(URI uri) throws IOException {
+        return uriResolver.getResource(resolveFromBase(uri));
+    }
+
+    public OutputStream resolveOut(URI uri) throws IOException {
+        return uriResolver.getOutputStream(resolveFromBase(uri));
+    }
+
+    private URI resolveFromBase(URI uri) {
+        return baseUri.resolve(uri);
+    }
+
+    public static URI cleanURI(String base) throws URISyntaxException {
+        // replace back slash with forward slash to ensure windows file:/// URLS are supported
+        if (base == null) {
+            return null;
+        }
+        String fixedUri = base.replace('\\', '/');
+        fixedUri = fixedUri.replace(" ", "%20");
+        URI baseURI = new URI(fixedUri);
+        return baseURI;
+    }
+
+    public static URI getBaseURI(String base) throws URISyntaxException {
+        String path = base + (base.endsWith("/") ? "" : "/");
+        return cleanURI(path);
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/URIResolverWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/package.html
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/package.html?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/package.html (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/package.html Thu May 31 08:33:36 2012
@@ -0,0 +1,6 @@
+<HTML>
+<TITLE>org.apache.fop.io Package</TITLE>
+<BODY>
+<P>Classes that control all IO in FOP.</P>
+</BODY>
+</HTML>
\ No newline at end of file

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/io/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeHandler.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeHandler.java Thu May 31 08:33:36 2012
@@ -104,7 +104,7 @@ public class AreaTreeHandler extends FOE
 
         setupModel(userAgent, outputFormat, stream);
 
-        this.lmMaker = userAgent.getFactory().getLayoutManagerMakerOverride();
+        this.lmMaker = userAgent.getLayoutManagerMakerOverride();
         if (lmMaker == null) {
             lmMaker = new LayoutManagerMapping();
         }

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeParser.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeParser.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/area/AreaTreeParser.java Thu May 31 08:33:36 2012
@@ -132,7 +132,7 @@ public class AreaTreeParser {
      */
     public ContentHandler getContentHandler(AreaTreeModel treeModel, FOUserAgent userAgent) {
         ElementMappingRegistry elementMappingRegistry
-            = userAgent.getFactory().getElementMappingRegistry();
+            = userAgent.getElementMappingRegistry();
         return new Handler(treeModel, userAgent, elementMappingRegistry);
     }
 
@@ -292,7 +292,7 @@ public class AreaTreeParser {
                     }
                 } else {
                     ContentHandlerFactoryRegistry registry
-                            = userAgent.getFactory().getContentHandlerFactoryRegistry();
+                            = userAgent.getContentHandlerFactoryRegistry();
                     ContentHandlerFactory factory = registry.getFactory(uri);
                     if (factory != null) {
                         delegate = factory.createContentHandler();
@@ -1102,7 +1102,7 @@ public class AreaTreeParser {
                             bkg.setURL(uri);
 
                             try {
-                                ImageManager manager = userAgent.getFactory().getImageManager();
+                                ImageManager manager = userAgent.getImageManager();
                                 ImageSessionContext sessionContext
                                     = userAgent.getImageSessionContext();
                                 ImageInfo info = manager.getImageInfo(uri, sessionContext);

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/CommandLineOptions.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/CommandLineOptions.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/CommandLineOptions.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/CommandLineOptions.java Thu May 31 08:33:36 2012
@@ -39,9 +39,10 @@ import org.apache.fop.Version;
 import org.apache.fop.accessibility.Accessibility;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopConfParser;
 import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FopFactoryBuilder;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fonts.FontManager;
 import org.apache.fop.pdf.PDFAMode;
 import org.apache.fop.pdf.PDFEncryptionManager;
 import org.apache.fop.pdf.PDFEncryptionParams;
@@ -51,12 +52,13 @@ import org.apache.fop.render.awt.AWTRend
 import org.apache.fop.render.intermediate.IFContext;
 import org.apache.fop.render.intermediate.IFDocumentHandler;
 import org.apache.fop.render.intermediate.IFSerializer;
-import org.apache.fop.render.pdf.PDFConfigurationConstants;
 import org.apache.fop.render.print.PagesMode;
 import org.apache.fop.render.print.PrintRenderer;
 import org.apache.fop.render.xml.XMLRenderer;
 import org.apache.fop.util.CommandLineLogger;
 
+import static org.apache.fop.render.pdf.PDFRendererConfigOptions.ENCRYPTION_PARAMS;
+
 /**
  * Options parses the commandline arguments
  */
@@ -116,12 +118,14 @@ public class CommandLineOptions {
     private Map renderingOptions = new java.util.HashMap();
     /* target resolution (for the user agent) */
     private int targetResolution = 0;
+
+    private boolean strictValidation = true;
     /* control memory-conservation policy */
     private boolean conserveMemoryPolicy = false;
     /* true if a complex script features are enabled */
     private boolean useComplexScriptFeatures = true;
 
-    private FopFactory factory = FopFactory.newInstance();
+    private FopFactory factory;
     private FOUserAgent foUserAgent;
 
     private InputHandler inputHandler;
@@ -183,9 +187,10 @@ public class CommandLineOptions {
                 addXSLTParameter("fop-output-format", getOutputFormat());
                 addXSLTParameter("fop-version", Version.getVersion());
                 foUserAgent.setConserveMemoryPolicy(conserveMemoryPolicy);
-                if (!useComplexScriptFeatures) {
-                    foUserAgent.setComplexScriptFeaturesEnabled(false);
-                }
+                // TODO: Handle this!!
+                //if (!useComplexScriptFeatures) {
+                //    foUserAgent.setComplexScriptFeaturesEnabled(false);
+                //}
             } else {
                 return false;
             }
@@ -225,9 +230,7 @@ public class CommandLineOptions {
         } else if (MimeConstants.MIME_FOP_IF.equals(outputmode)
                 && mimicRenderer != null) {
             // render from FO to Intermediate Format
-            IFSerializer serializer = new IFSerializer();
-            serializer.setContext(new IFContext(foUserAgent));
-
+            IFSerializer serializer = new IFSerializer(new IFContext(foUserAgent));
             IFDocumentHandler targetHandler
                 = foUserAgent.getRendererFactory().createDocumentHandler(
                         foUserAgent, mimicRenderer);
@@ -288,7 +291,7 @@ public class CommandLineOptions {
             } else if (args[i].equals("-d")) {
                 setLogOption("debug", "debug");
             } else if (args[i].equals("-r")) {
-                factory.setStrictValidation(false);
+                strictValidation = false;
             } else if (args[i].equals("-conserve")) {
                 conserveMemoryPolicy = true;
             } else if (args[i].equals("-flush")) {
@@ -819,15 +822,14 @@ public class CommandLineOptions {
     }
 
     private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
-        PDFEncryptionParams params = (PDFEncryptionParams)renderingOptions.get(
-                        PDFConfigurationConstants.ENCRYPTION_PARAMS);
+        PDFEncryptionParams params = (PDFEncryptionParams) renderingOptions.get(ENCRYPTION_PARAMS);
         if (params == null) {
             if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
                 throw new FOPException("PDF encryption requested but it is not available."
                         + " Please make sure MD5 and RC4 algorithms are available.");
             }
             params = new PDFEncryptionParams();
-            renderingOptions.put(PDFConfigurationConstants.ENCRYPTION_PARAMS, params);
+            renderingOptions.put(ENCRYPTION_PARAMS, params);
         }
         return params;
     }
@@ -860,7 +862,7 @@ public class CommandLineOptions {
             throw new FOPException("You must specify a PDF profile");
         } else {
             String profile = args[i + 1];
-            PDFAMode pdfAMode = PDFAMode.valueOf(profile);
+            PDFAMode pdfAMode = PDFAMode.getValueOf(profile);
             if (pdfAMode != null && pdfAMode != PDFAMode.DISABLED) {
                 if (renderingOptions.get("pdf-a-mode") != null) {
                     throw new FOPException("PDF/A mode already set");
@@ -868,7 +870,7 @@ public class CommandLineOptions {
                 renderingOptions.put("pdf-a-mode", pdfAMode.getName());
                 return 1;
             } else {
-                PDFXMode pdfXMode = PDFXMode.valueOf(profile);
+                PDFXMode pdfXMode = PDFXMode.getValueOf(profile);
                 if (pdfXMode != null && pdfXMode != PDFXMode.DISABLED) {
                     if (renderingOptions.get("pdf-x-mode") != null) {
                         throw new FOPException("PDF/X mode already set");
@@ -1027,14 +1029,18 @@ public class CommandLineOptions {
      * @throws IOException
      */
     private void setUserConfig() throws FOPException, IOException {
+        FopFactoryBuilder fopFactoryBuilder;
         if (userConfigFile == null) {
-            return;
-        }
-        try {
-            factory.setUserConfig(userConfigFile);
-        } catch (SAXException e) {
-            throw new FOPException(e);
+            fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI());
+        } else {
+            try {
+                fopFactoryBuilder = new FopConfParser(userConfigFile).getFopFactoryBuilder();
+            } catch (SAXException e) {
+                throw new FOPException(e);
+            }
+            fopFactoryBuilder.setStrictFOValidation(strictValidation);
         }
+        factory = fopFactoryBuilder.build();
      }
 
     /**
@@ -1390,13 +1396,7 @@ public class CommandLineOptions {
     }
 
     private void flushCache() throws FOPException {
-        FontManager fontManager = factory.getFontManager();
-        File cacheFile = fontManager.getCacheFile();
-        if (!fontManager.deleteCache()) {
-            System.err.println("Failed to flush the font cache file '"
-                    + cacheFile + "'.");
-            System.exit(1);
-        }
+        factory.getFontManager().deleteCache();
     }
 }
 

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/IFInputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/IFInputHandler.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/IFInputHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/IFInputHandler.java Thu May 31 08:33:36 2012
@@ -62,7 +62,7 @@ public class IFInputHandler extends Inpu
     public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
                 throws FOPException {
         IFDocumentHandler documentHandler
-            = userAgent.getFactory().getRendererFactory().createDocumentHandler(
+            = userAgent.getRendererFactory().createDocumentHandler(
                     userAgent, outputFormat);
         try {
             documentHandler.setResult(new StreamResult(out));

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/InputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/InputHandler.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/InputHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/cli/InputHandler.java Thu May 31 08:33:36 2012
@@ -51,7 +51,6 @@ import org.apache.fop.ResourceEventProdu
 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.render.awt.viewer.Renderable;
 
 /**
@@ -103,25 +102,11 @@ public class InputHandler implements Err
     public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
                 throws FOPException {
 
-        FopFactory factory = userAgent.getFactory();
         Fop fop;
         if (out != null) {
-            fop = factory.newFop(outputFormat, userAgent, out);
+            fop = userAgent.newFop(outputFormat, out);
         } else {
-            fop = factory.newFop(outputFormat, userAgent);
-        }
-
-        // if base URL was not explicitly set in FOUserAgent, obtain here
-        if (fop.getUserAgent().getBaseURL() == null && sourcefile != null) {
-            String baseURL = null;
-
-            try {
-                baseURL = new File(sourcefile.getAbsolutePath())
-                        .getParentFile().toURI().toURL().toExternalForm();
-            } catch (Exception e) {
-                baseURL = "";
-            }
-            fop.getUserAgent().setBaseURL(baseURL);
+            fop = userAgent.newFop(outputFormat);
         }
 
         // Resulting SAX events (the generated FO) must be piped through to FOP

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/FOTreeBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/FOTreeBuilder.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/FOTreeBuilder.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/FOTreeBuilder.java Thu May 31 08:33:36 2012
@@ -99,7 +99,7 @@ public class FOTreeBuilder extends Defau
             throws FOPException {
 
         this.userAgent = foUserAgent;
-        this.elementMappingRegistry = userAgent.getFactory().getElementMappingRegistry();
+        this.elementMappingRegistry = userAgent.getElementMappingRegistry();
         //This creates either an AreaTreeHandler and ultimately a Renderer, or
         //one of the RTF-, MIF- etc. Handlers.
         foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler(

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/PropertyList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/PropertyList.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/PropertyList.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/PropertyList.java Thu May 31 08:33:36 2012
@@ -27,7 +27,7 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.xmlgraphics.util.QName;
 
-import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.expr.PropertyException;
 import org.apache.fop.fo.properties.CommonAbsolutePosition;
 import org.apache.fop.fo.properties.CommonAural;
@@ -308,7 +308,7 @@ public abstract class PropertyList {
         String attributeNS;
         String attributeName;
         String attributeValue;
-        FopFactory factory = getFObj().getUserAgent().getFactory();
+        FOUserAgent userAgent = getFObj().getUserAgent();
         for (int i = 0; i < attributes.getLength(); i++) {
             /* convert all attributes with the same namespace as the fo element
              * the "xml:lang" and "xml:base" properties are special cases */
@@ -319,8 +319,8 @@ public abstract class PropertyList {
                     || "xml:lang".equals(attributeName)
                     || "xml:base".equals(attributeName)) {
                 convertAttributeToProperty(attributes, attributeName, attributeValue);
-            } else if (!factory.isNamespaceIgnored(attributeNS)) {
-                ElementMapping mapping = factory.getElementMappingRegistry().getElementMapping(
+            } else if (!userAgent.isNamespaceIgnored(attributeNS)) {
+                ElementMapping mapping = userAgent.getElementMappingRegistry().getElementMapping(
                         attributeNS);
                 QName attr = new QName(attributeNS, attributeName);
                 if (mapping != null) {

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java Thu May 31 08:33:36 2012
@@ -23,7 +23,8 @@ package org.apache.fop.fo.extensions.svg
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
-import java.net.URL;
+import java.io.File;
+import java.net.URI;
 
 import org.w3c.dom.Element;
 
@@ -71,12 +72,11 @@ public class SVGElement extends SVGObj {
         /* if width and height are zero, get the bounds of the content. */
 
         try {
-            URL baseURL = new URL(getUserAgent().getBaseURL() == null
-                            ? new java.io.File("").toURI().toURL().toExternalForm()
-                            : getUserAgent().getBaseURL());
-            if (baseURL != null) {
+            URI baseUri = getUserAgent().getNewURIResolver().getBaseURI();
+            baseUri = baseUri == null ? new File("").toURI() : baseUri;
+            if (baseUri != null) {
                 SVGOMDocument svgdoc = (SVGOMDocument)doc;
-                svgdoc.setURLObject(baseURL);
+                svgdoc.setURLObject(baseUri.toURL());
                 //The following line should not be called to leave FOP compatible to Batik 1.6.
                 //svgdoc.setDocumentURI(baseURL.toString());
             }

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/flow/ExternalGraphic.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/flow/ExternalGraphic.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/flow/ExternalGraphic.java Thu May 31 08:33:36 2012
@@ -75,7 +75,7 @@ public class ExternalGraphic extends Abs
         //Additional processing: obtain the image's intrinsic size and baseline information
         url = URISpecification.getURL(src);
         FOUserAgent userAgent = getUserAgent();
-        ImageManager manager = userAgent.getFactory().getImageManager();
+        ImageManager manager = userAgent.getImageManager();
         ImageInfo info = null;
         try {
             info = manager.getImageInfo(url, userAgent.getImageSessionContext());

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java Thu May 31 08:33:36 2012
@@ -374,7 +374,7 @@ public class CommonBorderPaddingBackgrou
                 String uri = URISpecification.getURL(newInstance.backgroundImage);
                 FObj fobj = pList.getFObj();
                 FOUserAgent userAgent = pList.getFObj().getUserAgent();
-                ImageManager manager = userAgent.getFactory().getImageManager();
+                ImageManager manager = userAgent.getImageManager();
                 ImageSessionContext sessionContext = userAgent.getImageSessionContext();
                 ImageInfo info;
                 try {

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CIDFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CIDFont.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CIDFont.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CIDFont.java Thu May 31 08:33:36 2012
@@ -19,6 +19,8 @@
 
 package org.apache.fop.fonts;
 
+import org.apache.fop.apps.io.URIResolverWrapper;
+
 //Java
 
 /**
@@ -29,6 +31,13 @@ public abstract class CIDFont extends Cu
     /** Contains the character widths for all characters in the font */
     protected int[] width = null;
 
+    /**
+     * @param resolver the URI resolver for controlling file access
+     */
+    public CIDFont(URIResolverWrapper resolver) {
+        super(resolver);
+    }
+
     // ---- Required ----
     /**
      * Returns the type of the CID font.

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFont.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFont.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFont.java Thu May 31 08:33:36 2012
@@ -20,13 +20,15 @@
 package org.apache.fop.fonts;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import javax.xml.transform.Source;
+import org.apache.fop.apps.io.URIResolverWrapper;
 
 
 /**
@@ -35,26 +37,26 @@ import javax.xml.transform.Source;
 public abstract class CustomFont extends Typeface
             implements FontDescriptor, MutableFont {
 
-    private String fontName = null;
-    private String fullName = null;
-    private Set<String> familyNames = null;
-    private String fontSubName = null;
-    private String embedFileName = null;
-    private String embedResourceName = null;
-    private FontResolver resolver = null;
-
-    private int capHeight = 0;
-    private int xHeight = 0;
-    private int ascender = 0;
-    private int descender = 0;
+    private String fontName;
+    private String fullName;
+    private Set<String> familyNames;
+    private String fontSubName;
+    private URI embedFileURI;
+    private String embedResourceName;
+    private final URIResolverWrapper resolver;
+
+    private int capHeight;
+    private int xHeight;
+    private int ascender;
+    private int descender;
     private int[] fontBBox = {0, 0, 0, 0};
     private int flags = 4;
-    private int weight = 0; //0 means unknown weight
-    private int stemV = 0;
-    private int italicAngle = 0;
-    private int missingWidth = 0;
+    private int weight; //0 means unknown weight
+    private int stemV;
+    private int italicAngle;
+    private int missingWidth;
     private FontType fontType = FontType.TYPE1;
-    private int firstChar = 0;
+    private int firstChar;
     private int lastChar = 255;
 
     private Map<Integer, Map<Integer, Integer>> kerning;
@@ -62,6 +64,13 @@ public abstract class CustomFont extends
     private boolean useKerning = true;
     private boolean useAdvanced = true;
 
+    /**
+     * @param resolver the URI resolver for controlling file access
+     */
+    public CustomFont(URIResolverWrapper resolver) {
+        this.resolver = resolver;
+    }
+
     /** {@inheritDoc} */
     public String getFontName() {
         return fontName;
@@ -103,29 +112,22 @@ public abstract class CustomFont extends
     }
 
     /**
-     * Returns an URI representing an embeddable font file. The URI will often
-     * be a filename or an URL.
+     * Returns an URI representing an embeddable font file.
+     *
      * @return URI to an embeddable font file or null if not available.
      */
-    public String getEmbedFileName() {
-        return embedFileName;
+    public URI getEmbedFileURI() {
+        return embedFileURI;
     }
 
     /**
-     * Returns a Source representing an embeddable font file.
-     * @return Source for an embeddable font file
+     * Returns an {@link InputStream} representing an embeddable font file.
+     *
+     * @return {@link InputStream} for an embeddable font file
      * @throws IOException if embedFileName is not null but Source is not found
      */
-    public Source getEmbedFileSource() throws IOException {
-        Source result = null;
-        if (resolver != null && embedFileName != null) {
-            result = resolver.resolve(embedFileName);
-            if (result == null) {
-                throw new IOException("Unable to resolve Source '"
-                        + embedFileName + "' for embedded font");
-            }
-        }
-        return result;
+    public InputStream getInputStream() throws IOException {
+        return resolver.resolveIn(embedFileURI);
     }
 
     /**
@@ -323,8 +325,8 @@ public abstract class CustomFont extends
     /**
      * {@inheritDoc}
      */
-    public void setEmbedFileName(String path) {
-        this.embedFileName = path;
+    public void setEmbedURI(URI path) {
+        this.embedFileURI = path;
     }
 
     /**
@@ -444,14 +446,6 @@ public abstract class CustomFont extends
         this.useAdvanced = enabled;
     }
 
-    /**
-     * Sets the font resolver. Needed for URI resolution.
-     * @param resolver the font resolver
-     */
-    public void setResolver(FontResolver resolver) {
-        this.resolver = resolver;
-    }
-
     /** {@inheritDoc} */
     public void putKerningEntry(Integer key, Map<Integer, Integer> value) {
         if (kerning == null) {

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFontCollection.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFontCollection.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/CustomFontCollection.java Thu May 31 08:33:36 2012
@@ -21,13 +21,16 @@ package org.apache.fop.fonts;
 
 import java.util.List;
 
+import org.apache.fop.apps.io.URIResolverWrapper;
+
 /**
  * Sets up a set of custom (embedded) fonts
  */
 public class CustomFontCollection implements FontCollection {
 
-    private FontResolver fontResolver;
     private final List<EmbedFontInfo> embedFontInfoList;
+    private final URIResolverWrapper uriResolver;
+    private final boolean useComplexScripts;
 
     /**
      * Main constructor.
@@ -35,14 +38,11 @@ public class CustomFontCollection implem
      * @param customFonts the list of custom fonts
      * @param useComplexScriptFeatures true if complex script features enabled
      */
-    public CustomFontCollection(FontResolver fontResolver,
-           List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) {
-        this.fontResolver = fontResolver;
-        if (this.fontResolver == null) {
-            //Ensure that we have minimal font resolution capabilities
-            this.fontResolver = FontManager.createMinimalFontResolver(useComplexScriptFeatures);
-        }
+    public CustomFontCollection(URIResolverWrapper fontResolver,
+            List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) {
+        this.uriResolver = fontResolver;
         this.embedFontInfoList = customFonts;
+        this.useComplexScripts = useComplexScriptFeatures;
     }
 
     /** {@inheritDoc} */
@@ -52,27 +52,19 @@ public class CustomFontCollection implem
         }
 
         String internalName = null;
-        //FontReader reader = null;
 
         for (int i = 0; i < embedFontInfoList.size(); i++) {
             EmbedFontInfo embedFontInfo = embedFontInfoList.get(i);
 
-            //String metricsFile = configFontInfo.getMetricsFile();
             internalName = "F" + num;
             num++;
-            /*
-            reader = new FontReader(metricsFile);
-            reader.useKerning(configFontInfo.getKerning());
-            reader.setFontEmbedPath(configFontInfo.getEmbedFile());
-            fontInfo.addMetrics(internalName, reader.getFont());
-            */
 
-            LazyFont font = new LazyFont(embedFontInfo, this.fontResolver);
+            LazyFont font = new LazyFont(embedFontInfo, this.uriResolver, useComplexScripts);
             fontInfo.addMetrics(internalName, font);
 
             List<FontTriplet> triplets = embedFontInfo.getFontTriplets();
             for (int tripletIndex = 0; tripletIndex < triplets.size(); tripletIndex++) {
-                FontTriplet triplet = (FontTriplet) triplets.get(tripletIndex);
+                FontTriplet triplet = triplets.get(tripletIndex);
                 fontInfo.addFontProperties(internalName, triplet);
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message