[prev in list] [next in list] [prev in thread] [next in thread]
List: fop-cvs
Subject: svn commit: r1344594 [2/15] - in /xmlgraphics/fop/branches/Temp_URI_Unification: ./
From: mehdi () apache ! org
Date: 2012-05-31 8:33:50
Message-ID: 20120531083417.63AE22388A02 () eris ! apache ! org
[Download RAW message or body]
Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java \
(added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java \
Thu May 31 08:33:36 2012 @@ -0,0 +1,111 @@
+/*
+ * 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 org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.apps.io.URIResolverWrapper;
+import org.apache.fop.fonts.FontCacheManager;
+import org.apache.fop.fonts.FontCacheManagerFactory;
+import org.apache.fop.fonts.FontDetector;
+import org.apache.fop.fonts.FontDetectorFactory;
+import org.apache.fop.fonts.FontManager;
+
+/**
+ * Creates an {@link EnvironmentProfile} that sets the environment in which a FOP \
instance is run. + */
+public final class EnvironmentalProfileFactory {
+
+ private EnvironmentalProfileFactory() {
+ };
+
+ /**
+ * Creates the default environment that FOP is invoked in. This default profile \
has no + * operational restrictions for FOP.
+ *
+ * @param defaultBaseUri the default base URI for resolving resource URIs
+ * @param resourceResolver the resource resolver
+ * @return the environment profile
+ */
+ public static EnvironmentProfile createDefault(URI defaultBaseUri,
+ ResourceResolver resourceResolver) {
+ return new Profile(defaultBaseUri, resourceResolver,
+ createFontManager(defaultBaseUri, resourceResolver,
+ FontDetectorFactory.createDefault(),
+ FontCacheManagerFactory.createDefault()));
+ }
+
+ /**
+ * Creates an IO-restricted environment for FOP by disabling some of the \
environment-specific + * functionality within FOP.
+ *
+ * @param defaultBaseUri the default base URI for resolving resource URIs
+ * @param resourceResolver the resource resolver
+ * @return the environment profile
+ */
+ public static EnvironmentProfile createRestrictedIO(URI defaultBaseUri,
+ ResourceResolver resourceResolver) {
+ return new Profile(defaultBaseUri, resourceResolver,
+ createFontManager(defaultBaseUri, resourceResolver,
+ FontDetectorFactory.createDisabled(),
+ FontCacheManagerFactory.createDisabled()));
+ }
+
+ private static final class Profile implements EnvironmentProfile {
+
+ private final ResourceResolver resourceResolver;
+
+ private final FontManager fontManager;
+
+ private final URI defaultBaseURI;
+
+ private Profile(URI defaultBaseURI, ResourceResolver resourceResolver,
+ FontManager fontManager) {
+ if (defaultBaseURI == null) {
+ throw new IllegalArgumentException("Default base URI must not be \
null"); + }
+ if (resourceResolver == null) {
+ throw new IllegalArgumentException("URI Resolver must not be null");
+ }
+ this.defaultBaseURI = defaultBaseURI;
+ this.resourceResolver = resourceResolver;
+ this.fontManager = fontManager;
+ }
+
+ public ResourceResolver getResourceResolver() {
+ return resourceResolver;
+ }
+
+ public FontManager getFontManager() {
+ return fontManager;
+ }
+
+ public URI getDefaultBaseURI() {
+ return defaultBaseURI;
+ }
+ }
+
+ private static FontManager createFontManager(URI defaultBaseUri, \
ResourceResolver resourceResolver, + FontDetector fontDetector, \
FontCacheManager fontCacheManager) { + return new FontManager(new \
URIResolverWrapper(defaultBaseUri, resourceResolver), fontDetector, + \
fontCacheManager); + }
+}
Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/EnvironmentalProfileFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/ja \
va/org/apache/fop/apps/FOUserAgent.java?rev=1344594&r1=1344593&r2=1344594&view=diff \
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FOUserAgent.java \
(original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FOUserAgent.java \
Thu May 31 08:33:36 2012 @@ -21,37 +21,54 @@ package org.apache.fop.apps;
// Java
import java.io.File;
-import java.net.MalformedURLException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Date;
import java.util.Map;
import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.image.loader.ImageContext;
+import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext;
import org.apache.xmlgraphics.util.UnitConv;
+import org.apache.xmlgraphics.util.uri.CommonURIResolver;
import org.apache.fop.Version;
import org.apache.fop.accessibility.Accessibility;
import org.apache.fop.accessibility.DummyStructureTreeEventHandler;
import org.apache.fop.accessibility.StructureTreeEventHandler;
+import org.apache.fop.apps.io.URIResolverWrapper;
import org.apache.fop.events.DefaultEventBroadcaster;
import org.apache.fop.events.Event;
import org.apache.fop.events.EventBroadcaster;
import org.apache.fop.events.EventListener;
import org.apache.fop.events.FOPEventListenerProxy;
import org.apache.fop.events.LoggingEventListener;
+import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.FOEventHandler;
+import org.apache.fop.fonts.FontManager;
+import org.apache.fop.hyphenation.HyphenationTreeResolver;
+import org.apache.fop.layoutmgr.LayoutManagerMaker;
+import org.apache.fop.render.ImageHandlerRegistry;
import org.apache.fop.render.Renderer;
+import org.apache.fop.render.RendererConfig;
+import org.apache.fop.render.RendererConfig.RendererConfigParser;
+import org.apache.fop.render.RendererConfigOptions;
import org.apache.fop.render.RendererFactory;
import org.apache.fop.render.XMLHandlerRegistry;
import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.util.ColorSpaceCache;
+import org.apache.fop.util.ContentHandlerFactoryRegistry;
/**
* This is the user agent for FOP.
@@ -75,24 +92,13 @@ import org.apache.fop.render.intermediat
*/
public class FOUserAgent {
- /** Defines the default target resolution (72dpi) for FOP */
- public static final float DEFAULT_TARGET_RESOLUTION
- = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
-
private static Log log = LogFactory.getLog("FOP");
- private FopFactory factory;
-
- /**
- * The base URL for all URL resolutions, especially for
- * external-graphics.
- */
- private String base = null;
+ private final FopFactory factory;
- /** A user settable URI Resolver */
- private URIResolver uriResolver = null;
+ private final URIResolverWrapper newUriResolver;
- private float targetResolution = \
FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; + private float targetResolution \
= FopFactoryConfig.DEFAULT_TARGET_RESOLUTION; private Map rendererOptions = new \
java.util.HashMap(); private File outputFile = null;
private IFDocumentHandler documentHandlerOverride = null;
@@ -131,7 +137,7 @@ public class FOUserAgent {
private ImageSessionContext imageSessionContext = new \
AbstractImageSessionContext() {
public ImageContext getParentContext() {
- return getFactory();
+ return factory;
}
public float getTargetResolution() {
@@ -150,19 +156,56 @@ public class FOUserAgent {
* @param factory the factory that provides environment-level information
* @see org.apache.fop.apps.FopFactory
*/
- public FOUserAgent(FopFactory factory) {
- if (factory == null) {
- throw new NullPointerException("The factory parameter must not be \
null");
- }
+ FOUserAgent(FopFactory factory, URIResolverWrapper uriResolver) {
this.factory = factory;
- setBaseURL(factory.getBaseURL());
+ this.newUriResolver = uriResolver;
setTargetResolution(factory.getTargetResolution());
setAccessibility(factory.isAccessibilityEnabled());
}
- /** @return the associated FopFactory instance */
- public FopFactory getFactory() {
- return this.factory;
+ /**
+ * Returns a new {@link Fop} instance. Use this factory method if your output \
type + * requires an output stream and you want to configure this very rendering \
run, + * i.e. if you want to set some metadata like the title and author of the \
document + * you want to render. In that case, create a new {@link FOUserAgent} \
instance + * using {@link #newFOUserAgent()}.
+ * <p>
+ * MIME types are used to select the output format (ex. "application/pdf" for \
PDF). You can + * use the constants defined in {@link MimeConstants}.
+ * @param outputFormat the MIME type of the output format to use (ex. \
"application/pdf"). + * @param stream the output stream
+ * @return the new Fop instance
+ * @throws FOPException when the constructor fails
+ */
+ public Fop newFop(String outputFormat, OutputStream stream) throws FOPException \
{ + return new Fop(outputFormat, this, stream);
+ }
+
+
+ /**
+ * Returns a new {@link Fop} instance. Use this factory method if you want to \
configure this + * very rendering run, i.e. if you want to set some metadata like \
the title and author of the + * document you want to render. In that case, create \
a new {@link FOUserAgent} + * instance using {@link #newFOUserAgent()}.
+ * <p>
+ * MIME types are used to select the output format (ex. "application/pdf" for \
PDF). You can + * use the constants defined in {@link MimeConstants}.
+ * @param outputFormat the MIME type of the output format to use (ex. \
"application/pdf"). + * @return the new Fop instance
+ * @throws FOPException when the constructor fails
+ */
+ public Fop newFop(String outputFormat) throws FOPException {
+ return newFop(outputFormat, null);
+ }
+
+
+ /**
+ * Returns the URI Resolver.
+ *
+ * @return the URI resolver
+ */
+ public URIResolverWrapper getNewURIResolver() {
+ return newUriResolver;
}
// ---------------------------------------------- rendering-run dependent stuff
@@ -345,48 +388,13 @@ public class FOUserAgent {
}
/**
- * Sets the base URL.
- * @param baseUrl base URL
- */
- public void setBaseURL(String baseUrl) {
- this.base = baseUrl;
- }
-
- /**
- * Sets font base URL.
- * @param fontBaseUrl font base URL
- * @deprecated Use {@link FontManager#setFontBaseURL(String)} instead.
- */
- public void setFontBaseURL(String fontBaseUrl) {
- try {
- getFactory().getFontManager().setFontBaseURL(fontBaseUrl);
- } catch (MalformedURLException e) {
- throw new IllegalArgumentException(e.getMessage());
- }
- }
-
- /**
- * Returns the base URL.
- * @return the base URL
- */
- public String getBaseURL() {
- return this.base;
- }
-
- /**
- * Sets the URI Resolver.
- * @param resolver the new URI resolver
- */
- public void setURIResolver(URIResolver resolver) {
- this.uriResolver = resolver;
- }
-
- /**
- * Returns the URI Resolver.
- * @return the URI Resolver
- */
- public URIResolver getURIResolver() {
- return this.uriResolver;
+ * Gets the renderer options given an interface representing renderer \
configuration options. + *
+ * @param option the renderer option
+ * @return the value
+ */
+ public Object getRendererOption(RendererConfigOptions option) {
+ return rendererOptions.get(option.getName());
}
/**
@@ -396,39 +404,27 @@ public class FOUserAgent {
* @param uri URI to access
* @return A {@link javax.xml.transform.Source} object, or null if the URI
* cannot be resolved.
- * @see org.apache.fop.apps.FOURIResolver
+ * @see org.apache.fop.apps.io.FOURIResolver
*/
public Source resolveURI(String uri) {
- return resolveURI(uri, getBaseURL());
- }
-
- /**
- * Attempts to resolve the given URI.
- * Will use the configured resolver and if not successful fall back
- * to the default resolver.
- * @param href URI to access
- * @param base the base URI to resolve against
- * @return A {@link javax.xml.transform.Source} object, or null if the URI
- * cannot be resolved.
- * @see org.apache.fop.apps.FOURIResolver
- */
- public Source resolveURI(String href, String base) {
- Source source = null;
- //RFC 2397 data URLs don't need to be resolved, just decode them through \
FOP's default
- //URIResolver.
- boolean bypassURIResolution = href.startsWith("data:");
- if (!bypassURIResolution && uriResolver != null) {
- try {
- source = uriResolver.resolve(href, base);
- } catch (TransformerException te) {
- log.error("Attempt to resolve URI '" + href + "' failed: ", te);
+ // TODO: What do we want to do when resources aren't found???
+ try {
+ Source src;
+ // Have to do this so we can resolve data URIs
+ if (uri.startsWith("data:")) {
+ CommonURIResolver uriResolver = new CommonURIResolver();
+ src = uriResolver.resolve(uri, "");
+ } else {
+ URI actualUri = URIResolverWrapper.cleanURI(uri);
+ src = new StreamSource(newUriResolver.resolveIn(actualUri));
+ src.setSystemId(uri);
}
+ return src;
+ } catch (URISyntaxException use) {
+ return null;
+ } catch (IOException ioe) {
+ return null;
}
- if (source == null) {
- // URI Resolver not configured or returned null, use default resolver \
from the factory
- source = getFactory().resolveURI(href, base);
- }
- return source;
}
/**
@@ -498,28 +494,18 @@ public class FOUserAgent {
// (convenience access to \
FopFactory methods)
/**
- * Returns the font base URL.
- * @return the font base URL
- * @deprecated Use {@link FontManager#getFontBaseURL()} instead. This method is \
not used by FOP.
- */
- public String getFontBaseURL() {
- String fontBase = getFactory().getFontManager().getFontBaseURL();
- return fontBase != null ? fontBase : getBaseURL();
- }
-
- /**
* Returns the conversion factor from pixel units to millimeters. This
* depends on the desired source resolution.
* @return float conversion factor
* @see #getSourceResolution()
*/
public float getSourcePixelUnitToMillimeter() {
- return getFactory().getSourcePixelUnitToMillimeter();
+ return factory.getSourcePixelUnitToMillimeter();
}
/** @return the resolution for resolution-dependant input */
public float getSourceResolution() {
- return getFactory().getSourceResolution();
+ return factory.getSourceResolution();
}
/**
@@ -530,7 +516,7 @@ public class FOUserAgent {
* @see FopFactory#getPageHeight()
*/
public String getPageHeight() {
- return getFactory().getPageHeight();
+ return factory.getPageHeight();
}
/**
@@ -541,7 +527,7 @@ public class FOUserAgent {
* @see FopFactory#getPageWidth()
*/
public String getPageWidth() {
- return getFactory().getPageWidth();
+ return factory.getPageWidth();
}
/**
@@ -550,7 +536,7 @@ public class FOUserAgent {
* @see FopFactory#validateStrictly()
*/
public boolean validateStrictly() {
- return getFactory().validateStrictly();
+ return factory.validateStrictly();
}
/**
@@ -559,21 +545,21 @@ public class FOUserAgent {
* @see FopFactory#isBreakIndentInheritanceOnReferenceAreaBoundary()
*/
public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
- return getFactory().isBreakIndentInheritanceOnReferenceAreaBoundary();
+ return factory.isBreakIndentInheritanceOnReferenceAreaBoundary();
}
/**
* @return the RendererFactory
*/
public RendererFactory getRendererFactory() {
- return getFactory().getRendererFactory();
+ return factory.getRendererFactory();
}
/**
* @return the XML handler registry
*/
public XMLHandlerRegistry getXMLHandlerRegistry() {
- return getFactory().getXMLHandlerRegistry();
+ return factory.getXMLHandlerRegistry();
}
/**
@@ -662,12 +648,53 @@ public class FOUserAgent {
}
/**
- * Control whether complex script features should be enabled
+ * Returns the renderer configuration object for a particular MIME type.
+ *
+ * @param mimeType the config MIME type
+ * @param configCreator the parser for creating the config for the first run of \
parsing. + * @return the renderer configuration object
+ * @throws FOPException if an error occurs when creating the config object
+ */
+ public RendererConfig getRendererConfig(String mimeType, RendererConfigParser \
configCreator) + throws FOPException {
+ return factory.getRendererConfig(this, getRendererConfiguration(mimeType), \
configCreator); + }
+
+ /**
+ * Returns a {@link Configuration} object for which contains renderer \
configuration for a given + * MIME type.
*
- * @param useComplexScriptFeatures true if FOP is to use complex script features
+ * @param mimeType the renderer configuration MIME type
+ * @return the configuration object
*/
- public void setComplexScriptFeaturesEnabled(boolean useComplexScriptFeatures) {
- factory.setComplexScriptFeaturesEnabled ( useComplexScriptFeatures );
+ public Configuration getRendererConfiguration(String mimeType) {
+ Configuration cfg = getUserConfig();
+ String type = "renderer";
+ String mime = "mime";
+ if (cfg == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("userconfig is null");
+ }
+ return null;
+ }
+
+ Configuration userConfig = null;
+
+ Configuration[] cfgs = cfg.getChild(type + "s").getChildren(type);
+ for (int i = 0; i < cfgs.length; ++i) {
+ Configuration child = cfgs[i];
+ try {
+ if (child.getAttribute(mime).equals(mimeType)) {
+ userConfig = child;
+ break;
+ }
+ } catch (ConfigurationException e) {
+ // silently pass over configurations without mime type
+ }
+ }
+ log.debug((userConfig == null ? "No u" : "U")
+ + "ser configuration found for MIME type " + mimeType);
+ return userConfig;
}
/**
@@ -713,5 +740,74 @@ public class FOUserAgent {
public StructureTreeEventHandler getStructureTreeEventHandler() {
return this.structureTreeEventHandler;
}
+
+ /** @see FopFactory#getLayoutManagerMakerOverride() */
+ public LayoutManagerMaker getLayoutManagerMakerOverride() {
+ return factory.getLayoutManagerMakerOverride();
+ }
+
+ /** @see FopFactory#getContentHandlerFactoryRegistry() */
+ public ContentHandlerFactoryRegistry getContentHandlerFactoryRegistry() {
+ return factory.getContentHandlerFactoryRegistry();
+ }
+
+ /** @see FopFactory#getImageManager() */
+ public ImageManager getImageManager() {
+ return factory.getImageManager();
+ }
+
+ /** @see FopFactory#getElementMappingRegistry() */
+ public ElementMappingRegistry getElementMappingRegistry() {
+ return factory.getElementMappingRegistry();
+ }
+
+ /** @see FopFactory#getFontManager() */
+ public FontManager getFontManager() {
+ return factory.getFontManager();
+ }
+
+ /**
+ * Indicates whether a namespace URI is on the ignored list.
+ * @param namespaceURI the namespace URI
+ * @return true if the namespace is ignored by FOP
+ */
+ public boolean isNamespaceIgnored(String namespaceURI) {
+ return factory.isNamespaceIgnored(namespaceURI);
+ }
+
+ /**
+ * Is the user configuration to be validated?
+ * @return if the user configuration should be validated
+ */
+ public boolean validateUserConfigStrictly() {
+ return factory.validateUserConfigStrictly();
+ }
+
+ /**
+ * Get the user configuration.
+ * @return the user configuration
+ */
+ public Configuration getUserConfig() {
+ return factory.getUserConfig();
+ }
+
+ /** @return the image handler registry */
+ public ImageHandlerRegistry getImageHandlerRegistry() {
+ return factory.getImageHandlerRegistry();
+ }
+
+ /** TODO: javadoc*/
+ public ColorSpaceCache getColorSpaceCache() {
+ return factory.getColorSpaceCache();
+ }
+
+ /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation \
patterns. */ + public HyphenationTreeResolver getHyphenationTreeResolver() {
+ return factory.getHyphenationTreeResolver();
+ }
+
+ public Map<String, String> getHyphPatNames() {
+ return factory.getHyphPatNames();
+ }
}
Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/Fop.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/Fop.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/Fop.java \
(original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/Fop.java \
Thu May 31 08:33:36 2012 @@ -66,12 +66,12 @@ public class Fop {
* @throws FOPException if setting up the DefaultHandler fails
*/
Fop(String outputFormat, FOUserAgent ua, OutputStream stream) throws \
FOPException { + if (ua == null) {
+ throw new FOPException("Cannot create a new Fop instance without a User \
Agent."); + }
this.outputFormat = outputFormat;
foUserAgent = ua;
- if (foUserAgent == null) {
- foUserAgent = FopFactory.newInstance().newFOUserAgent();
- }
this.stream = stream;
Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopConfParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopConfParser.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopConfParser.java \
(added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopConfParser.java \
Thu May 31 08:33:36 2012 @@ -0,0 +1,359 @@
+/*
+ * 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.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.xml.sax.SAXException;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry;
+import org.apache.xmlgraphics.image.loader.util.Penalty;
+
+import org.apache.fop.apps.io.DefaultResourceResolver;
+import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.apps.io.URIResolverWrapper;
+import org.apache.fop.fonts.FontManagerConfigurator;
+import org.apache.fop.hyphenation.HyphenationTreeCache;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * Parses the FOP configuration file and returns a {@link FopFactoryBuilder} which \
builds a + * {@link FopFactory}.
+ */
+public class FopConfParser {
+
+ private static final String PREFER_RENDERER = "prefer-renderer";
+
+ private final Log log = LogFactory.getLog(FopConfParser.class);
+
+ private final FopFactoryBuilder fopFactoryBuilder;
+
+ /**
+ * Constructor that takes the FOP conf in the form of an {@link InputStream}. A \
default base URI + * must be given as a fall-back mechanism for URI resolution.
+ *
+ * @param fopConfStream the fop conf input stream
+ * @param enviro the profile of the FOP deployment environment
+ * @throws SAXException if a SAX error was thrown parsing the FOP conf
+ * @throws IOException if an I/O error is thrown while parsing the FOP conf
+ */
+ public FopConfParser(InputStream fopConfStream, EnvironmentProfile enviro)
+ throws SAXException, IOException {
+ DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+ Configuration cfg;
+ try {
+ cfg = cfgBuilder.build(fopConfStream);
+ } catch (ConfigurationException e) {
+ throw new FOPException(e);
+ }
+ // The default base URI is taken from the directory in which the fopConf \
resides + fopFactoryBuilder = new \
FopFactoryBuilder(enviro).setConfiguration(cfg); + \
configure(enviro.getDefaultBaseURI(), enviro.getResourceResolver(), cfg); + }
+
+ /**
+ * Constructor that takes the FOP conf in the form of an {@link InputStream}. A \
default base URI + * must be given as a fall-back mechanism for URI resolution.
+ *
+ * @param fopConfStream the fop conf input stream
+ * @param defaultBaseURI the default base URI
+ * @param resolver the URI resolver
+ * @throws SAXException if a SAX error was thrown parsing the FOP conf
+ * @throws IOException if an I/O error is thrown while parsing the FOP conf
+ */
+ public FopConfParser(InputStream fopConfStream, URI defaultBaseURI,
+ ResourceResolver resolver) throws SAXException, IOException {
+ this(fopConfStream, \
EnvironmentalProfileFactory.createDefault(defaultBaseURI, resolver)); + }
+
+ /**
+ * Constructor that takes the FOP conf in the form of an {@link InputStream}. A \
default base URI + * must be given as a fall-back mechanism for URI resolution. \
The default URI resolvers is used. + *
+ * @param fopConfStream the fop conf input stream
+ * @param defaultBaseURI the default base URI
+ * @throws SAXException if a SAX error was thrown parsing the FOP conf
+ * @throws IOException if an I/O error is thrown while parsing the FOP conf
+ */
+ public FopConfParser(InputStream fopConfStream, URI defaultBaseURI) throws \
SAXException, + IOException {
+ this(fopConfStream, defaultBaseURI, new DefaultResourceResolver());
+ }
+
+ /**
+ * Constructor that takes the FOP conf and uses the default URI resolver.
+ *
+ * @param fopConfFile the FOP conf file
+ * @throws SAXException if a SAX error was thrown parsing the FOP conf
+ * @throws IOException if an I/O error is thrown while parsing the FOP conf
+ */
+ public FopConfParser(File fopConfFile) throws SAXException, IOException {
+ this(fopConfFile, new DefaultResourceResolver());
+ }
+
+ /**
+ * Constructor that parses the FOP conf and uses the URI resolver given.
+ *
+ * @param fopConfFile the FOP conf file
+ * @param resolver the URI resolver
+ * @throws SAXException if a SAX error was thrown parsing the FOP conf
+ * @throws IOException if an I/O error is thrown while parsing the FOP conf
+ */
+ public FopConfParser(File fopConfFile, ResourceResolver resolver)
+ throws SAXException, IOException {
+ this(new FileInputStream(fopConfFile),
+ fopConfFile.getAbsoluteFile().getParentFile().toURI(), resolver);
+ }
+
+ private void configure(final URI defaultBaseURI, final ResourceResolver \
resolver, + Configuration cfg) throws FOPException {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing FopFactory Configuration");
+ }
+
+ // TODO: This makes this variable both strict FO and user-config validation, \
is that right? + boolean strict = false;
+ // strict fo validation
+ if (cfg.getChild("strict-validation", false) != null) {
+ try {
+ strict = cfg.getChild("strict-validation").getValueAsBoolean();
+ fopFactoryBuilder.setStrictUserConfigValidation(strict);
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, false);
+ }
+ }
+
+ if (cfg.getChild("accessibility", false) != null) {
+ try {
+ fopFactoryBuilder.setAccessibility(cfg.getChild("accessibility").getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, false);
+ }
+ }
+
+ // base definitions for relative path resolution
+ if (cfg.getChild("base", false) != null) {
+ try {
+ URI confUri = \
URIResolverWrapper.getBaseURI(cfg.getChild("base").getValue(null)); + \
fopFactoryBuilder.setBaseURI(defaultBaseURI.resolve(confUri)); + } catch \
(URISyntaxException use) { + LogUtil.handleException(log, use, \
strict); + }
+ }
+
+ if (cfg.getChild("hyphenation-base", false) != null) {
+ String path = cfg.getChild("hyphenation-base").getValue(null);
+ if (defaultBaseURI != null) {
+ try {
+ URI hyphBaseUri = URIResolverWrapper.getBaseURI(path);
+ \
fopFactoryBuilder.setHyphenationBaseURI(defaultBaseURI.resolve(hyphBaseUri)); + \
} catch (URISyntaxException use) { + LogUtil.handleException(log, \
use, strict); + }
+ }
+ }
+
+ // renderer options
+ if (cfg.getChild("source-resolution", false) != null) {
+ float srcRes = cfg.getChild("source-resolution").getValueAsFloat(
+ FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION);
+ fopFactoryBuilder.setSourceResolution(srcRes);
+ if (log.isDebugEnabled()) {
+ log.debug("source-resolution set to: " + srcRes + "dpi");
+ }
+ }
+ if (cfg.getChild("target-resolution", false) != null) {
+ float targetRes = cfg.getChild("target-resolution").getValueAsFloat(
+ FopFactoryConfig.DEFAULT_TARGET_RESOLUTION);
+ fopFactoryBuilder.setTargetResolution(targetRes);
+ if (log.isDebugEnabled()) {
+ log.debug("target-resolution set to: " + targetRes + "dpi");
+ }
+ }
+ if (cfg.getChild("break-indent-inheritance", false) != null) {
+ try {
+ fopFactoryBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary(
+ \
cfg.getChild("break-indent-inheritance").getValueAsBoolean()); + } catch \
(ConfigurationException e) { + LogUtil.handleException(log, e, \
strict); + }
+ }
+ Configuration pageConfig = cfg.getChild("default-page-settings");
+ if (pageConfig.getAttribute("height", null) != null) {
+ String pageHeight = pageConfig.getAttribute("height",
+ FopFactoryConfig.DEFAULT_PAGE_HEIGHT);
+ fopFactoryBuilder.setPageHeight(pageHeight);
+ if (log.isInfoEnabled()) {
+ log.info("Default page-height set to: " + pageHeight);
+ }
+ }
+ if (pageConfig.getAttribute("width", null) != null) {
+ String pageWidth = pageConfig.getAttribute("width",
+ FopFactoryConfig.DEFAULT_PAGE_WIDTH);
+ fopFactoryBuilder.setPageWidth(pageWidth);
+ if (log.isInfoEnabled()) {
+ log.info("Default page-width set to: " + pageWidth);
+ }
+ }
+
+ if (cfg.getChild("complex-scripts") != null) {
+ Configuration csConfig = cfg.getChild("complex-scripts");
+ fopFactoryBuilder.setComplexScriptFeatures(!csConfig.getAttributeAsBoolean("disabled",
+ false));
+ }
+
+ setHyphPatNames(cfg, fopFactoryBuilder, strict);
+
+ // prefer Renderer over IFDocumentHandler
+ if (cfg.getChild(PREFER_RENDERER, false) != null) {
+ try {
+ fopFactoryBuilder.setPreferRenderer(
+ cfg.getChild(PREFER_RENDERER).getValueAsBoolean());
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+
+ // configure font manager
+ new FontManagerConfigurator(cfg, fopFactoryBuilder.getBaseUri(), \
resolver).configure( + fopFactoryBuilder.getFontManager(), strict);
+
+ // configure image loader framework
+ configureImageLoading(cfg.getChild("image-loading", false), strict);
+ }
+
+ private void setHyphPatNames(Configuration cfg, FopFactoryBuilder builder, \
boolean strict) + throws FOPException {
+ Configuration[] hyphPatConfig = cfg.getChildren("hyphenation-pattern");
+ if (hyphPatConfig.length != 0) {
+ Map<String, String> hyphPatNames = new HashMap<String, String>();
+ for (int i = 0; i < hyphPatConfig.length; ++i) {
+ String lang;
+ String country;
+ String filename;
+ StringBuffer error = new StringBuffer();
+ String location = hyphPatConfig[i].getLocation();
+
+ lang = hyphPatConfig[i].getAttribute("lang", null);
+ if (lang == null) {
+ addError("The lang attribute of a hyphenation-pattern \
configuration" + + " element must exist (" + location + \
")", error); + } else if (!lang.matches("[a-zA-Z]{2}")) {
+ addError("The lang attribute of a hyphenation-pattern \
configuration" + + " element must consist of exactly two \
letters (" + + location + ")", error);
+ }
+ lang = lang.toLowerCase();
+
+ country = hyphPatConfig[i].getAttribute("country", null);
+ if ("".equals(country)) {
+ country = null;
+ }
+ if (country != null) {
+ if (!country.matches("[a-zA-Z]{2}")) {
+ addError("The country attribute of a hyphenation-pattern \
configuration" + + " element must consist of exactly \
two letters (" + + location + ")", error);
+ }
+ country = country.toUpperCase();
+ }
+
+ filename = hyphPatConfig[i].getValue(null);
+ if (filename == null) {
+ addError("The value of a hyphenation-pattern configuration"
+ + " element may not be empty (" + location + ")", \
error); + }
+
+ if (error.length() != 0) {
+ LogUtil.handleError(log, error.toString(), strict);
+ continue;
+ }
+
+ String llccKey = HyphenationTreeCache.constructLlccKey(lang, \
country); + hyphPatNames.put(llccKey, filename);
+ if (log.isDebugEnabled()) {
+ log.debug("Using hyphenation pattern filename " + filename
+ + " for lang=\"" + lang + "\""
+ + (country != null ? ", country=\"" + country + "\"" : \
"")); + }
+ }
+ builder.setHyphPatNames(hyphPatNames);
+ }
+ }
+
+ private static void addError(String message, StringBuffer error) {
+ if (error.length() != 0) {
+ error.append(". ");
+ }
+ error.append(message);
+ }
+
+ private void configureImageLoading(Configuration parent, boolean strict) throws \
FOPException { + if (parent == null) {
+ return;
+ }
+ ImageImplRegistry registry = \
fopFactoryBuilder.getImageManager().getRegistry(); + Configuration[] penalties \
= parent.getChildren("penalty"); + try {
+ for (int i = 0, c = penalties.length; i < c; i++) {
+ Configuration penaltyCfg = penalties[i];
+ String className = penaltyCfg.getAttribute("class");
+ String value = penaltyCfg.getAttribute("value");
+ Penalty p = null;
+ if (value.toUpperCase().startsWith("INF")) {
+ p = Penalty.INFINITE_PENALTY;
+ } else {
+ try {
+ p = Penalty.toPenalty(Integer.parseInt(value));
+ } catch (NumberFormatException nfe) {
+ LogUtil.handleException(log, nfe, strict);
+ }
+ }
+ if (p != null) {
+ registry.setAdditionalPenalty(className, p);
+ }
+ }
+ } catch (ConfigurationException e) {
+ LogUtil.handleException(log, e, strict);
+ }
+ }
+
+ /**
+ * Returns the {@link FopFactoryBuilder}.
+ *
+ * @return the object for configuring the {@link FopFactory}
+ */
+ public FopFactoryBuilder getFopFactoryBuilder() {
+ return fopFactoryBuilder;
+ }
+}
Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopConfParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/ja \
va/org/apache/fop/apps/FopFactory.java?rev=1344594&r1=1344593&r2=1344594&view=diff \
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactory.java \
(original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/apps/FopFactory.java \
Thu May 31 08:33:36 2012 @@ -21,18 +21,15 @@ package org.apache.fop.apps;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
import org.xml.sax.SAXException;
@@ -44,13 +41,15 @@ import org.apache.xmlgraphics.image.load
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.util.UnitConv;
+import org.apache.fop.apps.io.URIResolverWrapper;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
-import org.apache.fop.fonts.FontCache;
import org.apache.fop.fonts.FontManager;
import org.apache.fop.hyphenation.HyphenationTreeResolver;
import org.apache.fop.layoutmgr.LayoutManagerMaker;
import org.apache.fop.render.ImageHandlerRegistry;
+import org.apache.fop.render.RendererConfig;
+import org.apache.fop.render.RendererConfig.RendererConfigParser;
import org.apache.fop.render.RendererFactory;
import org.apache.fop.render.XMLHandlerRegistry;
import org.apache.fop.util.ColorSpaceCache;
@@ -59,57 +58,48 @@ import org.apache.fop.util.ContentHandle
/**
* Factory class which instantiates new Fop and FOUserAgent instances. This
* class also holds environmental information and configuration used by FOP.
- * Information that may potentially be different for each rendering run can be
+ * Information that may potentially be different for each renderingq run can be
* found and managed in the FOUserAgent.
*/
-public class FopFactory implements ImageContext {
+public final class FopFactory implements ImageContext {
/** logger instance */
private static Log log = LogFactory.getLog(FopFactory.class);
/** Factory for Renderers and FOEventHandlers */
- private RendererFactory rendererFactory;
+ private final RendererFactory rendererFactory;
/** Registry for XML handlers */
- private XMLHandlerRegistry xmlHandlers;
+ private final XMLHandlerRegistry xmlHandlers;
/** Registry for image handlers */
- private ImageHandlerRegistry imageHandlers;
+ private final ImageHandlerRegistry imageHandlers;
/** The registry for ElementMapping instances */
- private ElementMappingRegistry elementMappingRegistry;
+ private final ElementMappingRegistry elementMappingRegistry;
/** The registry for ContentHandlerFactory instance */
- private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry
- = new ContentHandlerFactoryRegistry();
+ private final ContentHandlerFactoryRegistry contentHandlerFactoryRegistry
+ = new ContentHandlerFactoryRegistry();
- /** The resolver for user-supplied hyphenation patterns */
- private HyphenationTreeResolver hyphResolver = null;
+ private final ColorSpaceCache colorSpaceCache;
- private ColorSpaceCache colorSpaceCache = null;
+ private final FopFactoryConfig config;
- /** Image manager for loading and caching image objects */
- private ImageManager imageManager;
+ private final URIResolverWrapper uriResolverWrapper;
- /** Font manager for font substitution, autodetection and caching **/
- private FontManager fontManager;
+ private final Map<String, RendererConfig> rendererConfig;
- /** Configuration layer used to configure fop */
- private FopFactoryConfigurator config = null;
-
- /**
- * The base URL for all URL resolutions, especially for
- * external-graphics.
- */
- private String base = null;
-
- /**
- * Controls if accessibility is turned on or off
- */
- private boolean accessibility = false;
-
- /** The base URL for all hyphen URL resolutions. */
- private String hyphenBase = null;
+ private FopFactory(FopFactoryConfig config) {
+ this.config = config;
+ this.uriResolverWrapper = new URIResolverWrapper(config.getBaseURI(), \
config.getNewURIResolver()); + this.elementMappingRegistry = new \
ElementMappingRegistry(this); + this.colorSpaceCache = new \
ColorSpaceCache(config.getURIResolver()); + this.rendererFactory = new \
RendererFactory(config.preferRenderer()); + this.xmlHandlers = new \
XMLHandlerRegistry(); + this.imageHandlers = new ImageHandlerRegistry();
+ rendererConfig = new HashMap<String, RendererConfig>();
+ }
/**
* Map of configured names of hyphenation pattern file names: ll_CC => name
@@ -121,73 +111,52 @@ public class FopFactory implements Image
* input XSL violates that FO's content model. This is the default
* behavior for FOP. However, this flag, if set, provides the user the
* ability for FOP to halt on all content model violations if desired.
+ * Returns a new FopFactory instance that is configured using the {@link \
FopFactoryConfig} object. + *
+ * @param config the fop configuration
+ * @return the requested FopFactory instance.
*/
- private boolean strictFOValidation = \
FopFactoryConfigurator.DEFAULT_STRICT_FO_VALIDATION; + public static FopFactory \
newInstance(FopFactoryConfig config) { + return new FopFactory(config);
+ }
/**
- * FOP will validate the contents of the user configuration strictly
- * (e.g. base-urls and font urls/paths).
+ * Returns a new FopFactory instance that is configured using the {@link \
FopFactoryConfig} object that + * is created when the fopConf is parsed.
+ *
+ * @param fopConf the fop conf configuration file to parse
+ * @return the requested FopFactory instance.
+ * @throws IOException
+ * @throws SAXException
*/
- private boolean strictUserConfigValidation
- = FopFactoryConfigurator.DEFAULT_STRICT_USERCONFIG_VALIDATION;
-
- /** Source resolution in dpi */
- private float sourceResolution = \
FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION;
-
- /** Target resolution in dpi */
- private float targetResolution = \
FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
-
- /** Page height */
- private String pageHeight = FopFactoryConfigurator.DEFAULT_PAGE_HEIGHT;
-
- /** Page width */
- private String pageWidth = FopFactoryConfigurator.DEFAULT_PAGE_WIDTH;
-
- /** Complex scripts support enabled */
- private boolean useComplexScriptFeatures
- = FopFactoryConfigurator.DEFAULT_COMPLEX_SCRIPT_FEATURES;
-
- /** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
- private boolean breakIndentInheritanceOnReferenceAreaBoundary
- = FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE;
-
- /** Optional overriding LayoutManagerMaker */
- private LayoutManagerMaker lmMakerOverride = null;
-
- private Set<String> ignoredNamespaces;
-
- private FOURIResolver foURIResolver;
+ public static FopFactory newInstance(File fopConf) throws SAXException, \
IOException { + return new \
FopConfParser(fopConf).getFopFactoryBuilder().build(); + }
/**
- * Main constructor.
+ * Returns a new FopFactory instance that is configured only by the default \
configuration + * parameters.
+ *
+ * @param baseURI the base URI to resolve resource URIs against
+ * @return the requested FopFactory instance.
*/
- protected FopFactory() {
- this.config = new FopFactoryConfigurator(this);
- this.elementMappingRegistry = new ElementMappingRegistry(this);
- this.foURIResolver = new FOURIResolver(validateUserConfigStrictly());
- this.fontManager = new FontManager() {
-
- /** {@inheritDoc} */
- @Override
- public void setFontBaseURL(String fontBase) throws MalformedURLException \
{
- super.setFontBaseURL(getFOURIResolver().checkBaseURL(fontBase));
- }
-
- };
- this.colorSpaceCache = new ColorSpaceCache(foURIResolver);
- this.imageManager = new ImageManager(this);
- this.rendererFactory = new RendererFactory();
- this.xmlHandlers = new XMLHandlerRegistry();
- this.imageHandlers = new ImageHandlerRegistry();
- this.ignoredNamespaces = new java.util.HashSet<String>();
+ public static FopFactory newInstance(URI baseURI) {
+ return new FopFactoryBuilder(baseURI).build();
}
/**
- * Returns a new FopFactory instance.
+ * Returns a new FopFactory instance that is configured using the {@link \
FopFactoryConfig} object that + * is created when the fopConf is parsed.
+ *
+ * @param baseURI the base URI to resolve resource URIs against
+ * @param confStream the fop conf configuration stream to parse
* @return the requested FopFactory instance.
+ * @throws SAXException
+ * @throws IOException
*/
- public static FopFactory newInstance() {
- return new FopFactory();
+ public static FopFactory newInstance(URI baseURI, InputStream confStream) throws \
SAXException, + IOException {
+ return new FopConfParser(confStream, \
baseURI).getFopFactoryBuilder().build(); }
/**
@@ -198,34 +167,12 @@ public class FopFactory implements Image
* @throws FOPException
*/
public FOUserAgent newFOUserAgent() {
- FOUserAgent userAgent = new FOUserAgent(this);
+ FOUserAgent userAgent = new FOUserAgent(this, uriResolverWrapper);
return userAgent;
}
- /**
- * Sets accessibility support.
- *
- * @param value <code>true</code> to enable accessibility, <code>false</code> \
otherwise
- */
- void setAccessibility(boolean value) {
- this.accessibility = value;
- }
-
- boolean isAccessibilityEnabled() {
- return accessibility;
- }
-
- /**
- * Sets complex script support.
- * @param value <code>true</code> to enable complex script features,
- * <code>false</code> otherwise
- */
- void setComplexScriptFeaturesEnabled(boolean value) {
- this.useComplexScriptFeatures = value;
- }
-
boolean isComplexScriptFeaturesEnabled() {
- return useComplexScriptFeatures;
+ return config.isComplexScriptFeaturesEnabled();
}
/**
@@ -239,7 +186,7 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat) throws FOPException {
- return newFop(outputFormat, newFOUserAgent());
+ return newFOUserAgent().newFop(outputFormat);
}
/**
@@ -256,7 +203,7 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat, FOUserAgent userAgent) throws \
FOPException {
- return newFop(outputFormat, userAgent, null);
+ return userAgent.newFop(outputFormat, null);
}
/**
@@ -271,7 +218,7 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat, OutputStream stream) throws FOPException \
{
- return newFop(outputFormat, newFOUserAgent(), stream);
+ return newFOUserAgent().newFop(outputFormat, stream);
}
/**
@@ -290,11 +237,8 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream \
stream)
- throws FOPException {
- if (userAgent == null) {
- throw new NullPointerException("The userAgent parameter must not be \
null!");
- }
- return new Fop(outputFormat, userAgent, stream);
+ throws FOPException {
+ return userAgent.newFop(outputFormat, stream);
}
/**
@@ -343,11 +287,28 @@ public class FopFactory implements Image
}
/**
- * Returns the image manager.
- * @return the image manager
- */
- public ImageManager getImageManager() {
- return this.imageManager;
+ * Returns the renderer configuration object for a specific renderer given the \
parser and + * configuration to read. The renderer config is cached such that the \
{@link Configuration} is + * only parsed once per renderer, per FopFactory \
instance. + *
+ * @param userAgent the user agent
+ * @param cfg the configuration to be parsed
+ * @param configCreator the parser that creates the config object
+ * @return the config object
+ * @throws FOPException when an error occurs while creating the configuration \
object + */
+ public RendererConfig getRendererConfig(FOUserAgent userAgent, Configuration \
cfg, + RendererConfigParser configCreator) throws FOPException {
+ RendererConfig config = rendererConfig.get(configCreator.getMimeType());
+ if (config == null) {
+ try {
+ config = configCreator.build(userAgent, cfg);
+ rendererConfig.put(configCreator.getMimeType(), config);
+ } catch (Exception e) {
+ throw new FOPException(e);
+ }
+ }
+ return config;
}
/**
@@ -359,143 +320,41 @@ public class FopFactory implements Image
}
/**
- * Sets an explicit LayoutManagerMaker instance which overrides the one
- * defined by the AreaTreeHandler.
- * @param lmMaker the LayoutManagerMaker instance
- */
- public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
- this.lmMakerOverride = lmMaker;
- }
-
- /**
- * Returns the overriding LayoutManagerMaker instance, if any.
- * @return the overriding LayoutManagerMaker or null
- */
- public LayoutManagerMaker getLayoutManagerMakerOverride() {
- return this.lmMakerOverride;
- }
-
- /**
- * Sets the base URL.
- * @param base the base URL
- * @throws MalformedURLException if there's a problem with a file URL
- */
- public void setBaseURL(String base) throws MalformedURLException {
- this.base = foURIResolver.checkBaseURL(base);
- }
-
- /**
- * Returns the base URL.
- * @return the base URL
+ * Returns whether accessibility is enabled.
+ * @return true if accessibility is enabled
*/
- public String getBaseURL() {
- return this.base;
- }
-
- /**
- * Sets the font base URL.
- * @param fontBase font base URL
- * @throws MalformedURLException if there's a problem with a file URL
- * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
- */
- @Deprecated
- public void setFontBaseURL(String fontBase) throws MalformedURLException {
- getFontManager().setFontBaseURL(fontBase);
- }
-
- /**
- * @return the font base URL
- * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
- */
- @Deprecated
- public String getFontBaseURL() {
- return getFontManager().getFontBaseURL();
- }
-
- /** @return the hyphen base URL */
- public String getHyphenBaseURL() {
- return this.hyphenBase;
- }
-
- /**
- * Sets the hyphen base URL.
- * @param hyphenBase hythen base URL
- * @throws MalformedURLException if there's a problem with a file URL
- * */
- public void setHyphenBaseURL(final String hyphenBase) throws \
MalformedURLException {
- if (hyphenBase != null) {
- setHyphenationTreeResolver(
- new HyphenationTreeResolver() {
- public Source resolve(String href) {
- return resolveURI(href, hyphenBase);
- }
- });
- }
- this.hyphenBase = foURIResolver.checkBaseURL(hyphenBase);
- }
-
- /**
- * @return the hyphPatNames
- */
- public Map getHyphPatNames() {
- return hyphPatNames;
- }
-
- /**
- * @param hyphPatNames the hyphPatNames to set
- */
- public void setHyphPatNames(Map hyphPatNames) {
- if (hyphPatNames == null) {
- hyphPatNames = new HashMap();
- }
- this.hyphPatNames = hyphPatNames;
+ boolean isAccessibilityEnabled() {
+ return config.isAccessibilityEnabled();
}
/**
- * Sets the 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 uriResolver the new URI resolver
+ * Returns the image manager.
+ * @return the image manager
*/
- public void setURIResolver(URIResolver uriResolver) {
- foURIResolver.setCustomURIResolver(uriResolver);
+ public ImageManager getImageManager() {
+ return config.getImageManager();
}
/**
- * Returns the URI Resolver.
- * @return the URI Resolver
+ * Returns the overriding LayoutManagerMaker instance, if any.
+ * @return the overriding LayoutManagerMaker or null
*/
- public URIResolver getURIResolver() {
- return foURIResolver;
+ public LayoutManagerMaker getLayoutManagerMakerOverride() {
+ return config.getLayoutManagerMakerOverride();
}
- /**
- * Returns the FO URI Resolver.
- * @return the FO URI Resolver
- */
- public FOURIResolver getFOURIResolver() {
- return foURIResolver;
+ /** @return the hyphen base URI */
+ public String getHyphenBaseURI() {
+ return config.getHyphenationBaseURI().toASCIIString();
}
/** @return the HyphenationTreeResolver for resolving user-supplied hyphenation \
patterns. */ public HyphenationTreeResolver getHyphenationTreeResolver() {
- return this.hyphResolver;
- }
-
- /**
- * Sets the HyphenationTreeResolver to be used for resolving user-supplied \
hyphenation files.
- * @param hyphResolver the HyphenationTreeResolver instance
- */
- public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) {
- this.hyphResolver = hyphResolver;
+ return config.getHyphenationTreeResolver();
}
- /**
- * Activates strict XSL content model validation for FOP
- * Default is false (FOP will continue processing where it can)
- * @param validateStrictly true to turn on strict validation
- */
- public void setStrictValidation(boolean validateStrictly) {
- this.strictFOValidation = validateStrictly;
+ public Map<String, String> getHyphPatNames() {
+ return config.getHyphPatNames();
}
/**
@@ -503,7 +362,7 @@ public class FopFactory implements Image
* @return true of strict validation turned on, false otherwise
*/
public boolean validateStrictly() {
- return strictFOValidation;
+ return config.validateStrictly();
}
/**
@@ -511,48 +370,12 @@ public class FopFactory implements Image
* boundaries (for more info, see the javadoc for the relative member \
variable)
*/
public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
- return breakIndentInheritanceOnReferenceAreaBoundary;
- }
-
- /**
- * Controls whether to enable a feature that breaks indent inheritance when \
crossing
- * reference area boundaries.
- * <p>
- * This flag controls whether FOP will enable special code that breaks property
- * inheritance for start-indent and end-indent when the evaluation of the \
inherited
- * value would cross a reference area. This is described under
- * http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
- * improve interoperability with commercial FO implementations and to produce
- * results that are more in line with the expectation of unexperienced FO users.
- * Note: Enabling this features violates the XSL specification!
- * @param value true to enable the feature
- */
- public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
- this.breakIndentInheritanceOnReferenceAreaBoundary = value;
- }
-
- /**
- * @return true if kerning on base 14 fonts is enabled
- * @deprecated use getFontManager().isBase14KerningEnabled() instead
- */
- @Deprecated
- public boolean isBase14KerningEnabled() {
- return getFontManager().isBase14KerningEnabled();
+ return config.isBreakIndentInheritanceOnReferenceAreaBoundary();
}
- /**
- * Controls whether kerning is activated on base 14 fonts.
- * @param value true if kerning should be activated
- * @deprecated use getFontManager().setBase14KerningEnabled(boolean) instead
- */
- @Deprecated
- public void setBase14KerningEnabled(boolean value) {
- getFontManager().setBase14KerningEnabled(value);
- }
-
- /** @return the resolution for resolution-dependant input */
+ /** @return the resolution for resolution-dependent input */
public float getSourceResolution() {
- return this.sourceResolution;
+ return config.getSourceResolution();
}
/**
@@ -565,22 +388,9 @@ public class FopFactory implements Image
return UnitConv.IN2MM / getSourceResolution();
}
- /**
- * Sets the source resolution in dpi. This value is used to interpret the pixel \
size
- * of source documents like SVG images and bitmap images without resolution \
information.
- * @param dpi resolution in dpi
- */
- public void setSourceResolution(float dpi) {
- this.sourceResolution = dpi;
- if (log.isDebugEnabled()) {
- log.debug("source-resolution set to: " + sourceResolution
- + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
- }
- }
-
/** @return the resolution for resolution-dependant output */
public float getTargetResolution() {
- return this.targetResolution;
+ return config.getTargetResolution();
}
/**
@@ -590,25 +400,7 @@ public class FopFactory implements Image
* @see #getTargetResolution()
*/
public float getTargetPixelUnitToMillimeter() {
- return UnitConv.IN2MM / this.targetResolution;
- }
-
- /**
- * Sets the source resolution in dpi. This value is used to interpret the pixel \
size
- * of source documents like SVG images and bitmap images without resolution \
information.
- * @param dpi resolution in dpi
- */
- public void setTargetResolution(float dpi) {
- this.targetResolution = dpi;
- }
-
- /**
- * Sets the source resolution in dpi. This value is used to interpret the pixel \
size
- * of source documents like SVG images and bitmap images without resolution \
information.
- * @param dpi resolution in dpi
- */
- public void setSourceResolution(int dpi) {
- setSourceResolution((float)dpi);
+ return 25.4f / getTargetResolution();
}
/**
@@ -618,20 +410,7 @@ public class FopFactory implements Image
* @return the page-height, as a String
*/
public String getPageHeight() {
- return this.pageHeight;
- }
-
- /**
- * Sets the page-height to use as fallback, in case
- * page-height="auto"
- *
- * @param pageHeight page-height as a String
- */
- public void setPageHeight(String pageHeight) {
- this.pageHeight = pageHeight;
- if (log.isDebugEnabled()) {
- log.debug("Default page-height set to: " + pageHeight);
- }
+ return config.getPageHeight();
}
/**
@@ -641,40 +420,7 @@ public class FopFactory implements Image
* @return the page-width, as a String
*/
public String getPageWidth() {
- return this.pageWidth;
- }
-
- /**
- * Sets the page-width to use as fallback, in case
- * page-width="auto"
- *
- * @param pageWidth page-width as a String
- */
- public void setPageWidth(String pageWidth) {
- this.pageWidth = pageWidth;
- if (log.isDebugEnabled()) {
- log.debug("Default page-width set to: " + pageWidth);
- }
- }
-
- /**
- * Adds a namespace to the set of ignored namespaces.
- * If FOP encounters a namespace which it cannot handle, it issues a warning \
except if this
- * namespace is in the ignored set.
- * @param namespaceURI the namespace URI
- */
- public void ignoreNamespace(String namespaceURI) {
- this.ignoredNamespaces.add(namespaceURI);
- }
-
- /**
- * Adds a collection of namespaces to the set of ignored namespaces.
- * If FOP encounters a namespace which it cannot handle, it issues a warning \
except if this
- * namespace is in the ignored set.
- * @param namespaceURIs the namespace URIs
- */
- public void ignoreNamespaces(Collection<String> namespaceURIs) {
- this.ignoredNamespaces.addAll(namespaceURIs);
+ return config.getPageWidth();
}
/**
@@ -683,55 +429,17 @@ public class FopFactory implements Image
* @return true if the namespace is ignored by FOP
*/
public boolean isNamespaceIgnored(String namespaceURI) {
- return this.ignoredNamespaces.contains(namespaceURI);
+ return config.isNamespaceIgnored(namespaceURI);
}
/** @return the set of namespaces that are ignored by FOP */
public Set<String> getIgnoredNamespace() {
- return Collections.unmodifiableSet(this.ignoredNamespaces);
+ return config.getIgnoredNamespaces();
}
//------------------------------------------- Configuration stuff
/**
- * Set the user configuration.
- * @param userConfigFile the configuration file
- * @throws IOException if an I/O error occurs
- * @throws SAXException if a parsing error occurs
- */
- public void setUserConfig(File userConfigFile) throws SAXException, IOException \
{
- config.setUserConfig(userConfigFile);
- }
-
- /**
- * Set the user configuration from an URI.
- * @param uri the URI to the configuration file
- * @throws IOException if an I/O error occurs
- * @throws SAXException if a parsing error occurs
- */
- public void setUserConfig(String uri) throws SAXException, IOException {
- config.setUserConfig(uri);
- }
-
- /**
- * Set the user configuration.
- * @param userConfig configuration
- * @throws FOPException if a configuration problem occurs
- */
- public void setUserConfig(Configuration userConfig) throws FOPException {
- config.setUserConfig(userConfig);
- }
-
- /**
- * Set the base URI for the user configuration
- * Useful for programmatic configurations
- * @param baseURI the base URI
- */
- public void setUserConfigBaseURI(URI baseURI) {
- config.setBaseURI(baseURI);
- }
-
- /**
* Get the user configuration.
* @return the user configuration
*/
@@ -741,59 +449,20 @@ public class FopFactory implements Image
/**
* Is the user configuration to be validated?
- * @param strictUserConfigValidation strict user config validation
- */
- public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
- this.strictUserConfigValidation = strictUserConfigValidation;
- this.foURIResolver.setThrowExceptions(strictUserConfigValidation);
- }
-
- /**
- * Is the user configuration to be validated?
* @return if the user configuration should be validated
*/
public boolean validateUserConfigStrictly() {
- return this.strictUserConfigValidation;
+ return config.validateUserConfigStrictly();
}
//------------------------------------------- Font related stuff
/**
- * Whether or not to cache results of font triplet detection/auto-config
- * @param useCache use cache or not
- * @deprecated use getFontManager().setUseCache(boolean) instead
- */
- @Deprecated
- public void setUseCache(boolean useCache) {
- getFontManager().setUseCache(useCache);
- }
-
- /**
- * Cache results of font triplet detection/auto-config?
- * @return whether this factory is uses the cache
- * @deprecated use getFontManager().useCache() instead
- */
- @Deprecated
- public boolean useCache() {
- return getFontManager().useCache();
- }
-
- /**
- * Returns the font cache instance used by this factory.
- * @return the font cache
- * @deprecated use getFontManager().getFontCache() instead
- */
- @Deprecated
- public FontCache getFontCache() {
- return getFontManager().getFontCache();
- }
-
- /**
* Returns the font manager.
* @return the font manager
*/
public FontManager getFontManager() {
- return this.fontManager;
+ return config.getFontManager();
}
/**
@@ -804,12 +473,12 @@ public class FopFactory implements Image
* @param baseUri the base URI to resolve against
* @return A {@link javax.xml.transform.Source} object, or null if the URI
* cannot be resolved.
- * @see org.apache.fop.apps.FOURIResolver
+ * @see org.apache.fop.apps.io.FOURIResolver
*/
public Source resolveURI(String href, String baseUri) {
Source source = null;
try {
- source = foURIResolver.resolve(href, baseUri);
+ source = config.getURIResolver().resolve(href, baseUri);
} catch (TransformerException e) {
log.error("Attempt to resolve URI '" + href + "' failed: ", e);
}
@@ -825,5 +494,4 @@ public class FopFactory implements Image
public ColorSpaceCache getColorSpaceCache() {
return this.colorSpaceCache;
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic