aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2004-06-25 23:35:00 +0000
committerGlen Mazza <gmazza@apache.org>2004-06-25 23:35:00 +0000
commit8a045dbc8d61f3ae7750715cd61c626fb48f775b (patch)
tree19184827a664695aca312b9f5e8f5f371cb8de0d /src/java/org/apache
parentf575d5d538b1e9d2ff86a44f81247466d78ee77c (diff)
downloadxmlgraphics-fop-8a045dbc8d61f3ae7750715cd61c626fb48f775b.tar.gz
xmlgraphics-fop-8a045dbc8d61f3ae7750715cd61c626fb48f775b.zip
1.) Moved the CommandLineOptions' InputHandler object into FOUserAgent, allowing
for a no-parameter constructor for AWTRenderer (like the other renderers). (Code is not yet ideal in AWTRenderer, but will do the task.) 2.) AWT renderer handling now more similar to the other renderers (simplifications in Driver, Fop). 3.) Driver.getRenderer() removed from API. (Renderer configuration now mostly done through FOUserAgent, and setup of renderer prior to calling setRenderer().) 4.) Validity checking added to region-after, -start, -end, and -before. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197744 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/apps/CommandLineOptions.java27
-rw-r--r--src/java/org/apache/fop/apps/Driver.java11
-rw-r--r--src/java/org/apache/fop/apps/FOUserAgent.java21
-rw-r--r--src/java/org/apache/fop/apps/Fop.java34
-rw-r--r--src/java/org/apache/fop/apps/XSLTInputHandler.java12
-rw-r--r--src/java/org/apache/fop/fo/pagination/Region.java13
-rw-r--r--src/java/org/apache/fop/fo/pagination/RegionBody.java9
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRenderer.java17
-rw-r--r--src/java/org/apache/fop/servlet/FopPrintServlet.java9
9 files changed, 76 insertions, 77 deletions
diff --git a/src/java/org/apache/fop/apps/CommandLineOptions.java b/src/java/org/apache/fop/apps/CommandLineOptions.java
index 6a3adbfc2..2497131cb 100644
--- a/src/java/org/apache/fop/apps/CommandLineOptions.java
+++ b/src/java/org/apache/fop/apps/CommandLineOptions.java
@@ -114,6 +114,8 @@ public class CommandLineOptions {
printUsage();
throw e;
}
+
+ foUserAgent.setInputHandler(createInputHandler());
}
/**
@@ -386,6 +388,11 @@ public class CommandLineOptions {
throw new FOPException("No output file specified");
}
+ if ((outputmode == AWT_OUTPUT || outputmode == PRINT_OUTPUT) && outfile != null) {
+ throw new FOPException("Output file may not be specified " +
+ "for AWT or PRINT output");
+ }
+
if (inputmode == XSLT_INPUT) {
// check whether xml *and* xslt file have been set
if (xmlfile == null) {
@@ -466,18 +473,18 @@ public class CommandLineOptions {
}
/**
- * Get the input handler.
- * @return the input handler
- * @throws FOPException if creating the InputHandler fails
+ * Create an InputHandler object based on command-line parameters
+ * @return a new InputHandler instance
+ * @throws IllegalStateException if invalid/missing parameters
*/
- public InputHandler getInputHandler() throws FOPException {
+ private InputHandler createInputHandler() throws IllegalArgumentException {
switch (inputmode) {
- case FO_INPUT:
- return new FOFileHandler(fofile);
- case XSLT_INPUT:
- return new XSLTInputHandler(xmlfile, xsltfile, xsltParams);
- default:
- throw new FOPException("Invalid inputmode setting!");
+ case FO_INPUT:
+ return new FOFileHandler(fofile);
+ case XSLT_INPUT:
+ return new XSLTInputHandler(xmlfile, xsltfile, xsltParams);
+ default:
+ throw new IllegalArgumentException("Error creating InputHandler object.");
}
}
diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java
index 0dd53cff8..2a96d8039 100644
--- a/src/java/org/apache/fop/apps/Driver.java
+++ b/src/java/org/apache/fop/apps/Driver.java
@@ -310,7 +310,8 @@ public class Driver {
setRenderer("org.apache.fop.render.pdf.PDFRenderer");
break;
case RENDER_AWT:
- throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT");
+ setRenderer("org.apache.fop.render.awt.AWTRenderer");
+ break;
case RENDER_PRINT:
setRenderer("org.apache.fop.render.awt.AWTPrintRenderer");
break;
@@ -356,14 +357,6 @@ public class Driver {
}
/**
- * Returns the currently active renderer.
- * @return the renderer
- */
- public Renderer getRenderer() {
- return renderer;
- }
-
- /**
* Set the class name of the Renderer to use as well as the
* producer string for those renderers that can make use of it.
* @param rendererClassName classname of the renderer to use such as
diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java
index 15bc99628..b84d17bbc 100644
--- a/src/java/org/apache/fop/apps/FOUserAgent.java
+++ b/src/java/org/apache/fop/apps/FOUserAgent.java
@@ -58,7 +58,9 @@ public class FOUserAgent {
private PDFEncryptionParams pdfEncryptionParams;
private float px2mm = 0.35277777777777777778f; //72dpi (=25.4/dpi)
private HashMap rendererOptions = new java.util.HashMap();
-
+ private InputHandler inputHandler = null;
+
+
/** Producer: Metadata element for the system/software that produces
* the document. (Some renderers can store this in the document.)
*/
@@ -75,6 +77,23 @@ public class FOUserAgent {
protected Date creationDate = null;
/**
+ * Sets the InputHandler object for this process
+ * @param inputHandler holding input file name information
+ */
+ public void setInputHandler(InputHandler inputHandler) {
+ this.inputHandler = inputHandler;
+ }
+
+ /**
+ * Returns the apps.InputHandler object created during command-line
+ * processing
+ * @return InputHandler object
+ */
+ public InputHandler getInputHandler() {
+ return inputHandler;
+ }
+
+ /**
* Sets the producer of the document.
* @param producer source of document
*/
diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java
index a7b8eb06e..7376c9bbe 100644
--- a/src/java/org/apache/fop/apps/Fop.java
+++ b/src/java/org/apache/fop/apps/Fop.java
@@ -37,35 +37,29 @@ public class Fop {
*/
public static void main(String[] args) {
CommandLineOptions options = null;
- InputHandler inputHandler = null;
+ FOUserAgent foUserAgent = null;
BufferedOutputStream bos = null;
try {
Driver driver = new Driver();
options = new CommandLineOptions(args);
- driver.setUserAgent(options.getFOUserAgent());
- inputHandler = options.getInputHandler();
+ foUserAgent = options.getFOUserAgent();
+ driver.setUserAgent(foUserAgent);
+ driver.setRenderer(options.getRenderer());
try {
- if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) {
- driver.setRenderer(new AWTRenderer(inputHandler));
- } else {
- driver.setRenderer(options.getRenderer());
-
- if (options.getOutputFile() != null) {
- bos = new BufferedOutputStream(new FileOutputStream(
- options.getOutputFile()));
- driver.setOutputStream(bos);
- }
- }
-
- driver.render(inputHandler);
- } finally {
- if (bos != null) {
- bos.close();
+ if (options.getOutputFile() != null) {
+ bos = new BufferedOutputStream(new FileOutputStream(
+ options.getOutputFile()));
+ driver.setOutputStream(bos);
}
- }
+ driver.render(foUserAgent.getInputHandler());
+ } finally {
+ if (bos != null) {
+ bos.close();
+ }
+ }
// System.exit(0) called to close AWT/SVG-created threads, if any.
// AWTRenderer closes with window shutdown, so exit() should not
diff --git a/src/java/org/apache/fop/apps/XSLTInputHandler.java b/src/java/org/apache/fop/apps/XSLTInputHandler.java
index 88771f6b3..47c7aa6d9 100644
--- a/src/java/org/apache/fop/apps/XSLTInputHandler.java
+++ b/src/java/org/apache/fop/apps/XSLTInputHandler.java
@@ -54,7 +54,7 @@ public class XSLTInputHandler extends InputHandler {
* name, value, ...) for XSL stylesheet
* @throws FOPException if initializing the Transformer fails
*/
- public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) throws FOPException {
+ public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) {
this.xmlSource = new StreamSource(xmlfile);
this.xsltSource = new StreamSource(xsltfile);
try {
@@ -71,9 +71,8 @@ public class XSLTInputHandler extends InputHandler {
* @param xmlfile XML file
* @param xsltfile XSLT file
* @throws FOPException if initializing the Transformer fails
- * @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(File xmlfile, File xsltfile) throws FOPException {
+ public XSLTInputHandler(File xmlfile, File xsltfile) {
this.xmlSource = new StreamSource(xmlfile);
this.xsltSource = new StreamSource(xsltfile);
try {
@@ -89,9 +88,8 @@ public class XSLTInputHandler extends InputHandler {
* @param xmlURL XML URL
* @param xsltURL XSLT URL
* @throws FOPException if initializing the Transformer fails
- * @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(String xmlURL, String xsltURL) throws FOPException {
+ public XSLTInputHandler(String xmlURL, String xsltURL) {
this.xmlSource = new StreamSource(xmlURL);
this.xsltSource = new StreamSource(xsltURL);
}
@@ -101,10 +99,8 @@ public class XSLTInputHandler extends InputHandler {
* @param xmlSource XML InputSource
* @param xsltSource XSLT InputSource
* @throws FOPException if initializing the Transformer fails
- * @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource)
- throws FOPException {
+ public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource) {
this.xmlSource = new StreamSource(xmlSource.getByteStream(),
xmlSource.getSystemId());
this.xsltSource = new StreamSource(xsltSource.getByteStream(),
diff --git a/src/java/org/apache/fop/fo/pagination/Region.java b/src/java/org/apache/fop/fo/pagination/Region.java
index 1540682a5..31ac2eb13 100644
--- a/src/java/org/apache/fop/fo/pagination/Region.java
+++ b/src/java/org/apache/fop/fo/pagination/Region.java
@@ -20,12 +20,15 @@ package org.apache.fop.fo.pagination;
import java.awt.Rectangle;
+// XML
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FOTreeVisitor;
import org.apache.fop.fo.FObj;
-import org.xml.sax.Attributes;
/**
* This is an abstract base class for pagination regions
@@ -62,6 +65,14 @@ public abstract class Region extends FObj {
}
/**
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ * XSL/FOP Content Model: empty
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
+ invalidChildError(loc, nsURI, localName);
+ }
+
+ /**
* @see org.apache.fop.fo.FObj#addProperties
*/
protected void addProperties(Attributes attlist) throws FOPException {
diff --git a/src/java/org/apache/fop/fo/pagination/RegionBody.java b/src/java/org/apache/fop/fo/pagination/RegionBody.java
index 15ed0cc39..c0855abaa 100644
--- a/src/java/org/apache/fop/fo/pagination/RegionBody.java
+++ b/src/java/org/apache/fop/fo/pagination/RegionBody.java
@@ -23,7 +23,6 @@ import java.awt.Rectangle;
// XML
import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
// FOP
import org.apache.fop.datatypes.ColorType;
@@ -51,14 +50,6 @@ public class RegionBody extends Region {
}
/**
- * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
- * XSL/FOP Content Model: empty
- */
- protected void validateChildNode(Locator loc, String nsURI, String localName) {
- invalidChildError(loc, nsURI, localName);
- }
-
- /**
* @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension)
*/
public Rectangle getViewportRectangle (FODimension reldims) {
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java
index f4f934528..5b174646c 100644
--- a/src/java/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java
@@ -47,6 +47,7 @@ import java.util.Vector;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.InputHandler;
import org.apache.fop.area.Area;
import org.apache.fop.area.Page;
@@ -81,12 +82,6 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
protected FontInfo fontInfo;
/**
- The InputHandler associated with this Renderer.
- Sent to the PreviewDialog for document reloading.
- */
- private InputHandler inputHandler;
-
- /**
* The resource bundle used for AWT messages.
*/
protected Translator translator = null;
@@ -102,15 +97,13 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
*/
protected PreviewDialog frame;
- public AWTRenderer(InputHandler handler) {
- inputHandler = handler;
+ public AWTRenderer() {
translator = new Translator();
- createPreviewDialog(inputHandler);
}
- public AWTRenderer() {
- translator = new Translator();
- createPreviewDialog(null);
+ public void setUserAgent(FOUserAgent foUserAgent) {
+ super.setUserAgent(foUserAgent);
+ createPreviewDialog(foUserAgent.getInputHandler());
}
/**
diff --git a/src/java/org/apache/fop/servlet/FopPrintServlet.java b/src/java/org/apache/fop/servlet/FopPrintServlet.java
index f873812aa..687019042 100644
--- a/src/java/org/apache/fop/servlet/FopPrintServlet.java
+++ b/src/java/org/apache/fop/servlet/FopPrintServlet.java
@@ -32,7 +32,6 @@ import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.logging.Log;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.XSLTInputHandler;
-import org.apache.fop.render.awt.AWTPrintRenderer;
import org.xml.sax.InputSource;
/**
@@ -132,9 +131,7 @@ public class FopPrintServlet extends HttpServlet {
HttpServletResponse response) throws ServletException {
try {
Driver driver = new Driver(foFile, null);
- AWTPrintRenderer renderer = new AWTPrintRenderer();
-
- driver.setRenderer(renderer);
+ driver.setRenderer(Driver.RENDER_PRINT);
driver.run();
reportOK (response);
@@ -153,9 +150,7 @@ public class FopPrintServlet extends HttpServlet {
HttpServletResponse response) throws ServletException {
try {
Driver driver = new Driver();
- AWTPrintRenderer renderer = new AWTPrintRenderer();
-
- driver.setRenderer(renderer);
+ driver.setRenderer(Driver.RENDER_PRINT);
driver.render(input.getParser(), input.getInputSource());
reportOK (response);