diff options
author | Simon Pepping <spepping@apache.org> | 2004-07-09 17:27:12 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2004-07-09 17:27:12 +0000 |
commit | d04908a05ef64a2850289f6817125bd8a02c9088 (patch) | |
tree | d061c12afadde065aacd2f067490e7af033b6bc9 /src/java/org/apache/fop | |
parent | f7ebe087cfc59cf9ff28e7f458e2e4f21f9770e9 (diff) | |
download | xmlgraphics-fop-d04908a05ef64a2850289f6817125bd8a02c9088.tar.gz xmlgraphics-fop-d04908a05ef64a2850289f6817125bd8a02c9088.zip |
Implementing user configuration file.
Adding debug logging for user configuration, user PDF filters and user
fonts.
Adding reporting of mime type to renderers.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197774 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r-- | src/java/org/apache/fop/apps/CommandLineOptions.java | 37 | ||||
-rw-r--r-- | src/java/org/apache/fop/apps/FOUserAgent.java | 55 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/RenderPagesModel.java | 29 | ||||
-rw-r--r-- | src/java/org/apache/fop/fonts/FontSetup.java | 24 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFFilterList.java | 26 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/AbstractRenderer.java | 11 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/pdf/PDFRenderer.java | 5 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/ps/PSRenderer.java | 5 |
8 files changed, 183 insertions, 9 deletions
diff --git a/src/java/org/apache/fop/apps/CommandLineOptions.java b/src/java/org/apache/fop/apps/CommandLineOptions.java index 0689702b3..74b84f38a 100644 --- a/src/java/org/apache/fop/apps/CommandLineOptions.java +++ b/src/java/org/apache/fop/apps/CommandLineOptions.java @@ -20,15 +20,26 @@ package org.apache.fop.apps; // java import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Locale; import java.util.Vector; import org.apache.fop.fo.Constants; +// commons logging import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.impl.SimpleLog; +// SAX +import org.xml.sax.XMLReader; +import org.xml.sax.SAXException; + +// avalon configuration +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; + /** * Options parses the commandline arguments */ @@ -66,7 +77,7 @@ public class CommandLineOptions implements Constants { * @throws FileNotFoundException if an input file wasn't found. */ public CommandLineOptions(String[] args) - throws FOPException, FileNotFoundException { + throws FOPException, FileNotFoundException, IOException { log = LogFactory.getLog("FOP"); @@ -81,6 +92,7 @@ public class CommandLineOptions implements Constants { dumpConfiguration(); } checkSettings(); + createUserConfig(); } } catch (FOPException e) { printUsage(); @@ -414,6 +426,29 @@ public class CommandLineOptions implements Constants { } // end checkSettings /** + * Create the user configuration. + * @throws FOPException if creating the user configuration fails + * @throws IOException + */ + private void createUserConfig() throws FOPException, IOException { + if (userConfigFile == null) { + return; + } + XMLReader parser = FOFileHandler.createParser(); + DefaultConfigurationBuilder configBuilder + = new DefaultConfigurationBuilder(parser); + Configuration userConfig = null; + try { + userConfig = configBuilder.buildFromFile(userConfigFile); + } catch (SAXException e) { + throw new FOPException(e); + } catch (ConfigurationException e) { + throw new FOPException(e); + } + foUserAgent.setUserConfig(userConfig); + } + + /** * @return the type chosen renderer * @throws FOPException for invalid output modes */ diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index f135c5219..3de6959f1 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -25,6 +25,14 @@ import java.util.Map; import java.io.IOException; import java.io.InputStream; +// avalon configuration +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; + +// commons logging +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + // FOP import org.apache.fop.pdf.PDFEncryptionParams; import org.apache.fop.render.Renderer; @@ -61,7 +69,10 @@ public class FOUserAgent { private HashMap rendererOptions = new java.util.HashMap(); private InputHandler inputHandler = null; private Renderer rendererOverride = null; - + /* user configuration */ + private Configuration userConfig = null; + private Log log = LogFactory.getLog("FOP"); + /** Producer: Metadata element for the system/software that produces * the document. (Some renderers can store this in the document.) */ @@ -167,6 +178,48 @@ public class FOUserAgent { } /** + * Set the user configuration. + * @return the user configuration + */ + public void setUserConfig(Configuration userConfig) { + this.userConfig = userConfig; + } + + /** + * Get the user configuration. + * @return the user configuration + */ + public Configuration getUserConfig() { + return userConfig; + } + + public Configuration getUserRendererConfig (String mimeType) { + + if (userConfig == null || mimeType == null) { + return null; + } + + Configuration userRendererConfig = null; + + Configuration[] cfgs + = userConfig.getChild("renderers").getChildren("renderer"); + for (int i = 0; i < cfgs.length; ++i) { + Configuration cfg = cfgs[i]; + try { + if (cfg.getAttribute("mime").equals(mimeType)) { + userRendererConfig = cfg; + break; + } + } catch (ConfigurationException e) { + // silently pass over configurations without mime type + } + } + log.debug((userRendererConfig==null ? "No u" : "U") + + "ser configuration found for MIME type " + mimeType); + return userRendererConfig; + } + + /** * Sets the base URL. * @param baseURL base URL */ diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java index 96fcb8a7e..fd62a88d9 100644 --- a/src/java/org/apache/fop/area/RenderPagesModel.java +++ b/src/java/org/apache/fop/area/RenderPagesModel.java @@ -27,12 +27,17 @@ import java.util.Iterator; // XML import org.xml.sax.SAXException; +// avalon configuration +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; + // FOP import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.Constants; import org.apache.fop.fonts.FontInfo; import org.apache.fop.render.Renderer; +import org.apache.fop.render.AbstractRenderer; /** * This uses the store pages model to store the pages @@ -69,8 +74,22 @@ public class RenderPagesModel extends StorePagesModel { if (userAgent.getRendererOverride() != null) { renderer = userAgent.getRendererOverride(); } else { - renderer = createRenderer(renderType); - renderer.setUserAgent(userAgent); + AbstractRenderer rend = createRenderer(renderType); + rend.setUserAgent(userAgent); + String mimeType = rend.getMimeType(); + Configuration userRendererConfig = null; + if (mimeType != null) { + userRendererConfig + = userAgent.getUserRendererConfig(mimeType); + } + if (userRendererConfig != null) { + try { + rend.configure(userRendererConfig); + } catch (ConfigurationException e) { + throw new FOPException(e); + } + } + renderer = rend; } try { @@ -87,12 +106,12 @@ public class RenderPagesModel extends StorePagesModel { } /** - * Creates a Renderer object based on render-type desired + * Creates an AbstractRenderer object based on render-type desired * @param renderType the type of renderer to use - * @return Renderer the new Renderer instance + * @return AbstractRenderer the new Renderer instance * @throws IllegalArgumentException if an unsupported renderer type was requested */ - private Renderer createRenderer(int renderType) throws IllegalArgumentException { + private AbstractRenderer createRenderer(int renderType) throws IllegalArgumentException { switch (renderType) { case Constants.RENDER_PDF: diff --git a/src/java/org/apache/fop/fonts/FontSetup.java b/src/java/org/apache/fop/fonts/FontSetup.java index 87d325d18..93942f63f 100644 --- a/src/java/org/apache/fop/fonts/FontSetup.java +++ b/src/java/org/apache/fop/fonts/FontSetup.java @@ -34,6 +34,11 @@ import org.apache.fop.fonts.base14.CourierBoldOblique; import org.apache.fop.fonts.base14.Symbol; import org.apache.fop.fonts.base14.ZapfDingbats; +// commons logging +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +// Avalon import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -50,6 +55,11 @@ import java.util.List; public class FontSetup { /** + * logging instance + */ + protected static Log log = LogFactory.getLog("org.apache.fop.fonts"); + + /** * Sets up the font info object. * * Adds metrics for basic fonts and useful family-style-weight @@ -210,7 +220,7 @@ public class FontSetup { public static List buildFontListFromConfiguration(Configuration cfg) throws ConfigurationException { List fontList = new java.util.ArrayList(); - Configuration[] font = cfg.getChildren("font"); + Configuration[] font = cfg.getChild("fonts").getChildren("font"); for (int i = 0; i < font.length; i++) { Configuration[] triple = font[i].getChildren("font-triplet"); List tripleList = new java.util.ArrayList(); @@ -225,6 +235,18 @@ public class FontSetup { font[i].getAttributeAsBoolean("kerning", false), tripleList, font[i].getAttribute("embed-url", null)); + if (log.isDebugEnabled()) { + log.debug("Adding font " + efi.getEmbedFile() + + ", metric file " + efi.getMetricsFile()); + for (int j = 0; j < tripleList.size(); ++j) { + FontTriplet triplet = (FontTriplet) tripleList.get(j); + log.debug("Font triplet " + + triplet.getName() + ", " + + triplet.getWeight() + ", " + + triplet.getStyle()); + } + } + fontList.add(efi); } return fontList; diff --git a/src/java/org/apache/fop/pdf/PDFFilterList.java b/src/java/org/apache/fop/pdf/PDFFilterList.java index 946e10dc7..499bafc06 100644 --- a/src/java/org/apache/fop/pdf/PDFFilterList.java +++ b/src/java/org/apache/fop/pdf/PDFFilterList.java @@ -23,6 +23,11 @@ import java.io.OutputStream; import java.util.List; import java.util.Map; +// commons logging +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +// Avalon import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -48,6 +53,11 @@ public class PDFFilterList { private boolean ignoreASCIIFilters = false; /** + * logging instance + */ + protected static Log logger = LogFactory.getLog("org.apache.fop.render"); + + /** * Default constructor. * <p> * The flag for ignoring ASCII filters defaults to false. @@ -276,6 +286,22 @@ public class PDFFilterList { if (type == null) { type = PDFFilterList.DEFAULT_FILTER; } + + if (!filterList.isEmpty() && logger.isDebugEnabled()) { + StringBuffer debug = new StringBuffer("Adding PDF filter"); + if (filterList.size() != 1) { + debug.append("s"); + } + debug.append(" for type ").append(type).append(": "); + for (int j = 0; j < filterList.size(); j++) { + if (j != 0) { + debug.append(", "); + } + debug.append(filterList.get(j)); + } + logger.debug(debug.toString()); + } + if (filterMap.get(type) != null) { throw new ConfigurationException("A filterList of type '" + type + "' has already been defined"); diff --git a/src/java/org/apache/fop/render/AbstractRenderer.java b/src/java/org/apache/fop/render/AbstractRenderer.java index 813cbf90c..7f47a6d14 100644 --- a/src/java/org/apache/fop/render/AbstractRenderer.java +++ b/src/java/org/apache/fop/render/AbstractRenderer.java @@ -87,7 +87,7 @@ public abstract class AbstractRenderer /** * logging instance */ - protected static Log logger = LogFactory.getLog("FOP"); + protected static Log logger = LogFactory.getLog("org.apache.fop.render"); /** * block progression position @@ -724,5 +724,14 @@ public abstract class AbstractRenderer + "No handler defined for XML: " + namespace); } } + + /** + * Get the MIME type of the renderer. + * + * @return The MIME type of the renderer + */ + public String getMimeType() { + return null; + } } diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index a9cd5608a..73cfe9685 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -1343,5 +1343,10 @@ public class PDFRenderer extends PrintRenderer { beginTextObject(); super.renderLeader(area); } + + /** @see org.apache.fop.render.AbstractRenderer */ + public String getMimeType() { + return MIME_TYPE; + } } diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java index a3d4aabe4..904a1183c 100644 --- a/src/java/org/apache/fop/render/ps/PSRenderer.java +++ b/src/java/org/apache/fop/render/ps/PSRenderer.java @@ -838,4 +838,9 @@ public class PSRenderer extends AbstractRenderer { renderXML(userAgent, context, doc, ns); } + /** @see org.apache.fop.render.AbstractRenderer */ + public String getMimeType() { + return MIME_TYPE; + } + } |