Browse Source

Made FOUserAgent.configure() protected again (not to tempt any users to play with it). Instead improved CommandLineOptions to properly build and adjust the FOUserAgent. Manuel's fix was ok, but I wasn't too comfortable with the public configure() method.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@420761 13f79535-47bb-0310-9956-ffa450edef68
pull/25/head
Jeremias Maerki 18 years ago
parent
commit
fb3a04efdc

+ 1
- 1
src/java/org/apache/fop/apps/FOUserAgent.java View File

* Configures the FOUserAgent through the factory's configuration. * Configures the FOUserAgent through the factory's configuration.
* @see org.apache.avalon.framework.configuration.Configurable * @see org.apache.avalon.framework.configuration.Configurable
*/ */
public void configure(Configuration cfg) {
protected void configure(Configuration cfg) {
setBaseURL(FopFactory.getBaseURLfromConfig(cfg, "base")); setBaseURL(FopFactory.getBaseURLfromConfig(cfg, "base"));
if (cfg.getChild("target-resolution", false) != null) { if (cfg.getChild("target-resolution", false) != null) {
this.targetResolution this.targetResolution

+ 18
- 11
src/java/org/apache/fop/cli/CommandLineOptions.java View File

import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Vector; import java.util.Vector;


import javax.swing.UIManager; import javax.swing.UIManager;
private int inputmode = NOT_SET; private int inputmode = NOT_SET;
/* output mode */ /* output mode */
private String outputmode = null; private String outputmode = null;

/* rendering options (for the user agent) */
private Map renderingOptions = new java.util.HashMap();
/* target resolution (for the user agent) */
private int targetResolution = 0;
private FopFactory factory = FopFactory.newInstance(); private FopFactory factory = FopFactory.newInstance();
private FOUserAgent foUserAgent; private FOUserAgent foUserAgent;


throws FOPException, IOException { throws FOPException, IOException {
boolean optionsParsed = true; boolean optionsParsed = true;


foUserAgent = factory.newFOUserAgent();

try { try {
optionsParsed = parseOptions(args); optionsParsed = parseOptions(args);
if (optionsParsed) { if (optionsParsed) {
} }
checkSettings(); checkSettings();
createUserConfig(); createUserConfig();
if (factory.getUserConfig() != null) {
foUserAgent.configure(factory.getUserConfig());
//Factory config is set up, now we can create the user agent
foUserAgent = factory.newFOUserAgent();
foUserAgent.getRendererOptions().putAll(renderingOptions);
if (targetResolution != 0) {
foUserAgent.setTargetResolution(targetResolution);
} }
addXSLTParameter("fop-output-format", getOutputFormat()); addXSLTParameter("fop-output-format", getOutputFormat());
addXSLTParameter("fop-version", Version.getVersion()); addXSLTParameter("fop-version", Version.getVersion());
throw new FOPException( throw new FOPException(
"if you use '-dpi', you must specify a resolution (dots per inch)"); "if you use '-dpi', you must specify a resolution (dots per inch)");
} else { } else {
foUserAgent.setTargetResolution(Integer.parseInt(args[i + 1]));
this.targetResolution = Integer.parseInt(args[i + 1]);
return 1; return 1;
} }
} }
} else { } else {
outfile = new File(args[i + 1]); outfile = new File(args[i + 1]);
if (pdfAMode != null) { if (pdfAMode != null) {
foUserAgent.getRendererOptions().put("pdf-a-mode", pdfAMode);
renderingOptions.put("pdf-a-mode", pdfAMode);
} }
return 1; return 1;
} }
|| (args[i + 1].charAt(0) != '-')) { || (args[i + 1].charAt(0) != '-')) {
mime = args[i + 1]; mime = args[i + 1];
if ("list".equals(mime)) { if ("list".equals(mime)) {
String[] mimes = foUserAgent.getRendererFactory().listSupportedMimeTypes();
String[] mimes = factory.getRendererFactory().listSupportedMimeTypes();
System.out.println("Supported MIME types:"); System.out.println("Supported MIME types:");
for (int j = 0; j < mimes.length; j++) { for (int j = 0; j < mimes.length; j++) {
System.out.println(" " + mimes[j]); System.out.println(" " + mimes[j]);
} }


private PDFEncryptionParams getPDFEncryptionParams() throws FOPException { private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
PDFEncryptionParams params = (PDFEncryptionParams)foUserAgent.getRendererOptions().get(
PDFEncryptionParams params = (PDFEncryptionParams)renderingOptions.get(
PDFRenderer.ENCRYPTION_PARAMS); PDFRenderer.ENCRYPTION_PARAMS);
if (params == null) { if (params == null) {
if (!PDFEncryptionManager.checkAvailableAlgorithms()) { if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
+ " Please make sure MD5 and RC4 algorithms are available."); + " Please make sure MD5 and RC4 algorithms are available.");
} }
params = new PDFEncryptionParams(); params = new PDFEncryptionParams();
foUserAgent.getRendererOptions().put(PDFRenderer.ENCRYPTION_PARAMS, params);
renderingOptions.put(PDFRenderer.ENCRYPTION_PARAMS, params);
} }
return params; return params;
} }
throw new FOPException("Renderer has not been set!"); throw new FOPException("Renderer has not been set!");
} }
if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
foUserAgent.getRendererOptions().put("fineDetail", isCoarseAreaXml());
renderingOptions.put("fineDetail", isCoarseAreaXml());
} }
return outputmode; return outputmode;
} }

Loading…
Cancel
Save