]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1.) Moved the CommandLineOptions' InputHandler object into FOUserAgent, allowing
authorGlen Mazza <gmazza@apache.org>
Fri, 25 Jun 2004 23:35:00 +0000 (23:35 +0000)
committerGlen Mazza <gmazza@apache.org>
Fri, 25 Jun 2004 23:35:00 +0000 (23:35 +0000)
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

src/java/org/apache/fop/apps/CommandLineOptions.java
src/java/org/apache/fop/apps/Driver.java
src/java/org/apache/fop/apps/FOUserAgent.java
src/java/org/apache/fop/apps/Fop.java
src/java/org/apache/fop/apps/XSLTInputHandler.java
src/java/org/apache/fop/fo/pagination/Region.java
src/java/org/apache/fop/fo/pagination/RegionBody.java
src/java/org/apache/fop/render/awt/AWTRenderer.java
src/java/org/apache/fop/servlet/FopPrintServlet.java
test/java/org/apache/fop/BasicDriverTestCase.java
test/java/org/apache/fop/GenericFOPTestCase.java

index 6a3adbfc263609e726ed85b16ee8df097a5d8998..2497131cb7608c17dafc3d0bcacf310321500e53 100644 (file)
@@ -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.");
         }
     }
 
index 0dd53cff86f26dbe213efe338662598c4e38e018..2a96d80398eeea3efe1ccda14f2a560e61ca6b09 100644 (file)
@@ -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;
@@ -355,14 +356,6 @@ public class Driver {
         this.renderer = renderer;
     }
 
-    /**
-     * 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.
index 15bc9962859b4710f07695ce62c67e09a34a35d0..b84d17bbc29278f4af45bf1452557bb82637c506 100644 (file)
@@ -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.)
      */
@@ -74,6 +76,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
index a7b8eb06e80275ecd03efcf8de487394c5297142..7376c9bbe65e38409892975f755df08f5a03157d 100644 (file)
@@ -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
index 88771f6b3d8bdafa2cc17da3e1140d6a22e20cdd..47c7aa6d93ae064e26b85d0740d021f4901ee61d 100644 (file)
@@ -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(),
index 1540682a5f07daf4467d2732aae3dbe8e67ca833..31ac2eb13281fc22d495fc03f64548dfae568224 100644 (file)
@@ -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
@@ -61,6 +64,14 @@ public abstract class Region extends FObj {
         regionId = id;
     }
 
+    /**
+     * @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
      */
index 15ed0cc39c08f0ddf2344788b4b36b2b6e39348e..c0855abaaa2ec1ec7bb28db8e93f4c1b45159337 100644 (file)
@@ -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;
@@ -50,14 +49,6 @@ public class RegionBody extends Region {
         super(parent, Region.BODY_CODE);
     }
 
-    /**
-     * @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)
      */
index f4f934528a2963886a00b5dba19cc34aa99d0931..5b174646c30e305276f9438febd5018d1419b0fe 100644 (file)
@@ -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;
@@ -80,12 +81,6 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
     /** Font configuration */
     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.
      */
@@ -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());
     }
 
     /**
index f873812aa3e34fdaf24268e1306a7f2ca6d4e7ed..687019042ebe7deb54c8fa267a166c7ec0ccf7c1 100644 (file)
@@ -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);
index ab158a396c6dc726642615d9408c9747157889a9..c512a50ec317dec8328f7967e89a2c2f049b15a6 100644 (file)
@@ -33,7 +33,6 @@ import javax.xml.transform.stream.StreamSource;
 
 import org.xml.sax.InputSource;
 
-import org.apache.commons.logging.impl.NoOpLog;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.fop.apps.Driver;
 import org.apache.fop.apps.InputHandler;
@@ -47,8 +46,6 @@ import org.w3c.dom.Document;
  */
 public class BasicDriverTestCase extends AbstractFOPTestCase {
 
-    private NoOpLog logger = new NoOpLog();
-
     /**
      * @see junit.framework.TestCase#TestCase(String)
      */
@@ -67,7 +64,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
             new InputSource(foFile.toURL().toExternalForm()),
             baout);
 
-        driver.setLogger(this.logger);
         driver.setRenderer(Driver.RENDER_PDF);
         driver.run();
         assertTrue("Generated PDF has zero length", baout.size() > 0);
@@ -82,7 +78,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
 
-        driver.setLogger(this.logger);
         driver.setInputSource(new InputSource(foFile.toURL().toExternalForm()));
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_PDF);
@@ -109,7 +104,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
 
-        driver.setLogger(this.logger);
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_PDF);
         driver.render(loadDocument(foFile));
@@ -125,7 +119,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
 
-        driver.setLogger(this.logger);
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_PDF);
         SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -145,7 +138,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
-        driver.setLogger(this.logger);
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_PDF);
         
@@ -166,7 +158,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
-        driver.setLogger(this.logger);
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_PS);
         
@@ -187,7 +178,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
-        driver.setLogger(this.logger);
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_RTF);
         
@@ -209,7 +199,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase {
         File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl");
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         Driver driver = new Driver();
-        driver.setLogger(this.logger);
         driver.setOutputStream(baout);
         driver.setRenderer(Driver.RENDER_PDF);
         
index 5688558494b211a3eaa5252cc790e1095c6ec4a3..370b012a9053846b4c37cf47a3e710063c597c1f 100644 (file)
@@ -31,6 +31,7 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import org.apache.fop.apps.Driver;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.render.pdf.PDFRenderer;
 import org.apache.fop.util.DigestFilter;
 import org.xml.sax.InputSource;
@@ -112,7 +113,9 @@ public final class GenericFOPTestCase extends TestCase {
     private void renderPDF(String fo, String digestIn, String digestOut)
         throws Exception {
         PDFRenderer renderer = new PDFRenderer();
-        renderer.setCreationDate(new Date(10000));
+        FOUserAgent foUserAgent = new FOUserAgent();
+        foUserAgent.setCreationDate(new Date(10000));
+        renderer.setUserAgent(foUserAgent);
         MessageDigest outDigest = MessageDigest.getInstance("MD5");
         ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
         DigestOutputStream out =