]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Implementing user configuration file.
authorSimon Pepping <spepping@apache.org>
Fri, 9 Jul 2004 17:27:12 +0000 (17:27 +0000)
committerSimon Pepping <spepping@apache.org>
Fri, 9 Jul 2004 17:27:12 +0000 (17:27 +0000)
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

src/java/org/apache/fop/apps/CommandLineOptions.java
src/java/org/apache/fop/apps/FOUserAgent.java
src/java/org/apache/fop/area/RenderPagesModel.java
src/java/org/apache/fop/fonts/FontSetup.java
src/java/org/apache/fop/pdf/PDFFilterList.java
src/java/org/apache/fop/render/AbstractRenderer.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java
src/java/org/apache/fop/render/ps/PSRenderer.java

index 0689702b3cd4639b2073e6e161ba0c02ed7f3639..74b84f38a2b425e0ecd3c06b841c18a6d781a694 100644 (file)
@@ -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();
@@ -413,6 +425,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
index f135c5219ac99c9548ab6073c37c0716ed167886..3de6959f10a76d334248fe2d3a1a225df10fdafd 100644 (file)
@@ -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.)
      */
@@ -166,6 +177,48 @@ public class FOUserAgent {
         return rendererOptions;
     }
 
+    /**
+     * 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
index 96fcb8a7e4d2f2d3f602d4e62bea589672daa63f..fd62a88d937f34e9af97d07b1c4612caffa93ef8 100644 (file)
@@ -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:
index 87d325d188c15c0394a9985c847aa835ab78106f..93942f63f2dc4a963e1ff2e92f4a241a20c5fef6 100644 (file)
@@ -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;
 
@@ -49,6 +54,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.
      *
@@ -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;
index 946e10dc7bcfda2172849c18ce7b1ef9b42cf855..499bafc06c8922efe8ddf116824080a1df2fb4cc 100644 (file)
@@ -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;
 
@@ -47,6 +52,11 @@ public class PDFFilterList {
 
     private boolean ignoreASCIIFilters = false;
     
+    /**
+     * logging instance
+     */
+    protected static Log logger = LogFactory.getLog("org.apache.fop.render");
+    
     /**
      * Default constructor.
      * <p>
@@ -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");
index 813cbf90c1bd02d69a669a02737e8a0da33e1c9a..7f47a6d14c21fed6f4661756922d2b0207fe4c3a 100644 (file)
@@ -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;
+    }
 }
 
index a9cd5608a8d4f53c653acaa42ab42ede63f6d4dd..73cfe96850dd747e56c543670ec1a9247ac4a2c0 100644 (file)
@@ -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;
+    }
 }
 
index a3d4aabe4b29709a2e4e6bde55b8e31d451ec37a..904a1183c567a9406ad89e088d4cf24f83aaa787 100644 (file)
@@ -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;
+    }
+
 }