You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by gm...@apache.org on 2004/06/26 01:35:00 UTC

cvs commit: xml-fop/test/java/org/apache/fop BasicDriverTestCase.java GenericFOPTestCase.java

gmazza      2004/06/25 16:35:00

  Modified:    src/java/org/apache/fop/apps CommandLineOptions.java
                        Driver.java FOUserAgent.java Fop.java
                        XSLTInputHandler.java
               src/java/org/apache/fop/fo/pagination Region.java
                        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
                        GenericFOPTestCase.java
  Log:
  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.
  
  Revision  Changes    Path
  1.22      +17 -10    xml-fop/src/java/org/apache/fop/apps/CommandLineOptions.java
  
  Index: CommandLineOptions.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/CommandLineOptions.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- CommandLineOptions.java	23 Jun 2004 00:25:27 -0000	1.21
  +++ CommandLineOptions.java	25 Jun 2004 23:35:00 -0000	1.22
  @@ -114,6 +114,8 @@
               printUsage();
               throw e;
           }
  +        
  +        foUserAgent.setInputHandler(createInputHandler());
       }
   
       /**
  @@ -386,6 +388,11 @@
               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 @@
       }
   
       /**
  -     * 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.");
           }
       }
   
  
  
  
  1.75      +2 -9      xml-fop/src/java/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- Driver.java	23 Jun 2004 00:25:27 -0000	1.74
  +++ Driver.java	25 Jun 2004 23:35:00 -0000	1.75
  @@ -310,7 +310,8 @@
               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;
  @@ -353,14 +354,6 @@
           renderer.setUserAgent(getUserAgent());
           userAgent.setProducer("FOP Version" + Fop.getVersion());
           this.renderer = renderer;
  -    }
  -
  -    /**
  -     * Returns the currently active renderer.
  -     * @return the renderer
  -     */
  -    public Renderer getRenderer() {
  -        return renderer;
       }
   
       /**
  
  
  
  1.10      +21 -2     xml-fop/src/java/org/apache/fop/apps/FOUserAgent.java
  
  Index: FOUserAgent.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOUserAgent.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FOUserAgent.java	23 Jun 2004 00:25:27 -0000	1.9
  +++ FOUserAgent.java	25 Jun 2004 23:35:00 -0000	1.10
  @@ -58,7 +58,9 @@
       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 @@
        */
       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
  
  
  
  1.14      +14 -20    xml-fop/src/java/org/apache/fop/apps/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Fop.java	23 Jun 2004 00:25:27 -0000	1.13
  +++ Fop.java	25 Jun 2004 23:35:00 -0000	1.14
  @@ -37,35 +37,29 @@
        */
       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
  
  
  
  1.14      +4 -8      xml-fop/src/java/org/apache/fop/apps/XSLTInputHandler.java
  
  Index: XSLTInputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/XSLTInputHandler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XSLTInputHandler.java	16 Mar 2004 05:25:16 -0000	1.13
  +++ XSLTInputHandler.java	25 Jun 2004 23:35:00 -0000	1.14
  @@ -54,7 +54,7 @@
        *      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 @@
        * @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 @@
        * @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 @@
        * @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(),
  
  
  
  1.20      +12 -1     xml-fop/src/java/org/apache/fop/fo/pagination/Region.java
  
  Index: Region.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/Region.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Region.java	22 May 2004 03:59:53 -0000	1.19
  +++ Region.java	25 Jun 2004 23:35:00 -0000	1.20
  @@ -20,12 +20,15 @@
   
   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
  @@ -59,6 +62,14 @@
       protected Region(FONode parent, int id) {
           super(parent);
           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);
       }
   
       /**
  
  
  
  1.23      +0 -9      xml-fop/src/java/org/apache/fop/fo/pagination/RegionBody.java
  
  Index: RegionBody.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/RegionBody.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- RegionBody.java	23 Jun 2004 00:25:27 -0000	1.22
  +++ RegionBody.java	25 Jun 2004 23:35:00 -0000	1.23
  @@ -23,7 +23,6 @@
   
   // XML
   import org.xml.sax.Attributes;
  -import org.xml.sax.Locator;
   
   // FOP
   import org.apache.fop.datatypes.ColorType;
  @@ -48,14 +47,6 @@
        */
       public RegionBody(FONode parent) {
           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);
       }
   
       /**
  
  
  
  1.26      +5 -12     xml-fop/src/java/org/apache/fop/render/awt/AWTRenderer.java
  
  Index: AWTRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/awt/AWTRenderer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- AWTRenderer.java	19 Jun 2004 13:35:33 -0000	1.25
  +++ AWTRenderer.java	25 Jun 2004 23:35:00 -0000	1.26
  @@ -47,6 +47,7 @@
   
   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 @@
       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 @@
        */
       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());
       }
   
       /**
  
  
  
  1.13      +2 -7      xml-fop/src/java/org/apache/fop/servlet/FopPrintServlet.java
  
  Index: FopPrintServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/servlet/FopPrintServlet.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FopPrintServlet.java	20 Jun 2004 12:35:17 -0000	1.12
  +++ FopPrintServlet.java	25 Jun 2004 23:35:00 -0000	1.13
  @@ -32,7 +32,6 @@
   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 @@
                            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 @@
                             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);
  
  
  
  1.6       +1 -12     xml-fop/test/java/org/apache/fop/BasicDriverTestCase.java
  
  Index: BasicDriverTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/test/java/org/apache/fop/BasicDriverTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BasicDriverTestCase.java	2 Apr 2004 01:31:59 -0000	1.5
  +++ BasicDriverTestCase.java	25 Jun 2004 23:35:00 -0000	1.6
  @@ -33,7 +33,6 @@
   
   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 @@
    */
   public class BasicDriverTestCase extends AbstractFOPTestCase {
   
  -    private NoOpLog logger = new NoOpLog();
  -
       /**
        * @see junit.framework.TestCase#TestCase(String)
        */
  @@ -67,7 +64,6 @@
               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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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);
           
  
  
  
  1.3       +5 -2      xml-fop/test/java/org/apache/fop/GenericFOPTestCase.java
  
  Index: GenericFOPTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/test/java/org/apache/fop/GenericFOPTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GenericFOPTestCase.java	27 Feb 2004 17:58:44 -0000	1.2
  +++ GenericFOPTestCase.java	25 Jun 2004 23:35:00 -0000	1.3
  @@ -31,6 +31,7 @@
   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 @@
       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 =
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org