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 sp...@apache.org on 2006/03/07 20:33:33 UTC

svn commit: r383973 - in /xmlgraphics/fop/branches/Temp_API_Finalization: examples/embedding/java/embedding/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/cli/ src/java/org/apache/fop/render/

Author: spepping
Date: Tue Mar  7 11:33:32 2006
New Revision: 383973

URL: http://svn.apache.org/viewcvs?rev=383973&view=rev
Log:
Ensure the consistency of the created Fop object

Modified:
    xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java
    xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/Fop.java
    xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java
    xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/cli/InputHandler.java
    xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/render/RendererFactory.java

Modified: xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java?rev=383973&r1=383972&r2=383973&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java (original)
+++ xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java Tue Mar  7 11:33:32 2006
@@ -43,7 +43,6 @@
 import org.apache.fop.apps.FormattingResults;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.apps.PageSequenceResults;
-import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * This class demonstrates the conversion of multiple FO files to PDF using FOP.
@@ -83,14 +82,6 @@
             // Construct fop with desired output format and output stream
             fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
 
-            // This will also check the consistency of your setup
-            DefaultHandler handler;
-            try {
-                handler = fop.getDefaultHandler();
-            } catch (IllegalStateException e) {
-                throw new FOPException(e);
-            }
-
             // Setup JAXP using identity transformer
             TransformerFactory factory = TransformerFactory.newInstance();
             Transformer transformer = factory.newTransformer(); // identity transformer
@@ -99,7 +90,7 @@
             Source src = new StreamSource(fo);
 
             // Resulting SAX events (the generated FO) must be piped through to FOP
-            Result res = new SAXResult(handler);
+            Result res = new SAXResult(fop.getDefaultHandler());
             
             // Start XSLT transformation and FOP processing
             transformer.transform(src, res);

Modified: xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/Fop.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/Fop.java?rev=383973&r1=383972&r2=383973&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/Fop.java (original)
+++ xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/Fop.java Tue Mar  7 11:33:32 2006
@@ -64,8 +64,9 @@
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
      * @param ua FOUserAgent object
      * @param stream the output stream
+     * @throws FOPException if setting up the DefaultHandler fails
      */
-    public Fop(String outputFormat, FOUserAgent ua, OutputStream stream) {
+    public Fop(String outputFormat, FOUserAgent ua, OutputStream stream) throws FOPException {
         this.outputFormat = outputFormat;
 
         foUserAgent = ua;
@@ -74,6 +75,8 @@
         }
         
         this.stream = stream;
+        
+        createDefaultHandler();
     }
 
     /**
@@ -81,23 +84,28 @@
      * output format (ex. "application/pdf" for PDF).
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
      * @param ua FOUserAgent object
+     * @throws FOPException if setting up the DefaultHandler fails
      */
-    public Fop(String outputFormat, FOUserAgent ua) {
+    public Fop(String outputFormat, FOUserAgent ua) throws FOPException {
         this.outputFormat = outputFormat;
 
         foUserAgent = ua;
         if (foUserAgent == null) {
             foUserAgent = new FOUserAgent();
         }
+        
+        createDefaultHandler();
     }
 
     /**
      * Constructor for FOP with a default FOUserAgent. It uses MIME types to select the 
      * output format (ex. "application/pdf" for PDF).
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
+     * @deprecated Use a constructor with an FOUserAgent instead!
      */
     public Fop(String outputFormat) {
-        this(outputFormat, null);
+        this.outputFormat = outputFormat;
+        foUserAgent = new FOUserAgent();
     }
 
     /**
@@ -118,19 +126,28 @@
     }
 
     /**
-     * Returns a DefaultHandler object used to generate the document.
+     * Creates a DefaultHandler object used to generate the document.
      * Note this object implements the ContentHandler interface.
      * For processing with a Transformer object, this DefaultHandler object
      * can be used in the SAXResult constructor.
      * Alternatively, for processing with a SAXParser, this object can be
      * used as the DefaultHandler argument to its parse() methods.
      *
-     * @return a SAX DefaultHandler for handling the SAX events.
+     * @throws FOPException if setting up the DefaultHandler fails
+     */
+    private void createDefaultHandler() throws FOPException {
+        this.foTreeBuilder = new FOTreeBuilder(outputFormat, foUserAgent, stream);
+    }
+
+    /**
+     * Returns the DefaultHandler object used to generate the document.
+     * Checking for null and the exception is only for the deprecated constructor.
+     * @return the SAX DefaultHandler for handling the SAX events.
      * @throws FOPException if setting up the DefaultHandler fails
      */
     public DefaultHandler getDefaultHandler() throws FOPException {
         if (foTreeBuilder == null) {
-            this.foTreeBuilder = new FOTreeBuilder(outputFormat, foUserAgent, stream);
+            createDefaultHandler();
         }
         return this.foTreeBuilder;
     }

Modified: xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java?rev=383973&r1=383972&r2=383973&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java Tue Mar  7 11:33:32 2006
@@ -133,8 +133,9 @@
      * use the constants defined in {@link MimeConstants}.
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").     
      * @return the new Fop instance
+     * @throws FOPException when the constructor fails
      */
-    public Fop newFop(String outputFormat) {
+    public Fop newFop(String outputFormat) throws FOPException {
         return new Fop(outputFormat, newFOUserAgent());
     }
 
@@ -149,8 +150,9 @@
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf").
      * @param userAgent the user agent that will be used to control the rendering run     
      * @return the new Fop instance
+     * @throws FOPException  when the constructor fails
      */
-    public Fop newFop(String outputFormat, FOUserAgent userAgent) {
+    public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException {
         if (userAgent == null) {
             throw new NullPointerException("The userAgent parameter must not be null!");
         }
@@ -166,8 +168,9 @@
      * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). 
      * @param stream the output stream
      * @return the new Fop instance
+     * @throws FOPException when the constructor fails
      */
-    public Fop newFop(String outputFormat, OutputStream stream) {
+    public Fop newFop(String outputFormat, OutputStream stream) throws FOPException {
         return new Fop(outputFormat, newFOUserAgent(), stream);
     }
 
@@ -184,8 +187,9 @@
      * @param userAgent the user agent that will be used to control the rendering run     
      * @param stream the output stream
      * @return the new Fop instance
+     * @throws FOPException when the constructor fails
      */
-    public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream) {
+    public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream) throws FOPException {
         if (userAgent == null) {
             throw new NullPointerException("The userAgent parameter must not be null!");
         }
@@ -199,8 +203,9 @@
      * instance instead of the default ones created internally by FOP.
      * @param userAgent the user agent that will be used to control the rendering run     
      * @return the new Fop instance
+     * @throws FOPException when the constructor fails
      */
-    public Fop newFop(FOUserAgent userAgent) {
+    public Fop newFop(FOUserAgent userAgent) throws FOPException {
         if (userAgent.getRendererOverride() == null 
                 && userAgent.getFOEventHandlerOverride() == null) {
             throw new IllegalStateException("Either the overriding renderer or the overriding"

Modified: xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/cli/InputHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/cli/InputHandler.java?rev=383973&r1=383972&r2=383973&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/cli/InputHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/cli/InputHandler.java Tue Mar  7 11:33:32 2006
@@ -85,10 +85,12 @@
      */
     public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) 
                 throws FOPException {
-        
-        Fop fop = new Fop(outputFormat, userAgent);
+
+        Fop fop;
         if (out != null) {
-            fop.setOutputStream(out);
+            fop = new Fop(outputFormat, userAgent, out);
+        } else {
+            fop = new Fop(outputFormat, userAgent);
         }
 
         // if base URL was not explicitly set in FOUserAgent, obtain here

Modified: xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/render/RendererFactory.java?rev=383973&r1=383972&r2=383973&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/render/RendererFactory.java Tue Mar  7 11:33:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -248,7 +248,7 @@
                     if (out == null 
                             && userAgent.getRendererOverride() == null 
                             && rendMaker.needsOutputStream()) {
-                        throw new IllegalStateException(
+                        throw new FOPException(
                             "OutputStream has not been set");
                     }
                     //Found a Renderer so we need to construct an AreaTreeHandler.



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