// 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
*/
* @throws FileNotFoundException if an input file wasn't found.
*/
public CommandLineOptions(String[] args)
- throws FOPException, FileNotFoundException {
+ throws FOPException, FileNotFoundException, IOException {
log = LogFactory.getLog("FOP");
dumpConfiguration();
}
checkSettings();
+ createUserConfig();
}
} catch (FOPException e) {
printUsage();
}
} // 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
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;
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.)
*/
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
// 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
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 {
}
/**
- * 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:
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;
*/
public class FontSetup {
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog("org.apache.fop.fonts");
+
/**
* Sets up the font info object.
*
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();
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;
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;
private boolean ignoreASCIIFilters = false;
+ /**
+ * logging instance
+ */
+ protected static Log logger = LogFactory.getLog("org.apache.fop.render");
+
/**
* Default constructor.
* <p>
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");
/**
* logging instance
*/
- protected static Log logger = LogFactory.getLog("FOP");
+ protected static Log logger = LogFactory.getLog("org.apache.fop.render");
/**
* block progression position
+ "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;
+ }
}
beginTextObject();
super.renderLeader(area);
}
+
+ /** @see org.apache.fop.render.AbstractRenderer */
+ public String getMimeType() {
+ return MIME_TYPE;
+ }
}
renderXML(userAgent, context, doc, ns);
}
+ /** @see org.apache.fop.render.AbstractRenderer */
+ public String getMimeType() {
+ return MIME_TYPE;
+ }
+
}