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/05 21:47:02 UTC

svn commit: r383398 - in /xmlgraphics/fop/branches/Temp_API_Finalization: examples/embedding/java/embedding/MultipleFO2PDF.java src/java/org/apache/fop/apps/Fop.java src/java/org/apache/fop/apps/FopFactory.java

Author: spepping
Date: Sun Mar  5 12:47:00 2006
New Revision: 383398

URL: http://svn.apache.org/viewcvs?rev=383398&view=rev
Log:
Add Fop constructor and corresponding FopFactory methods with an
output stream. Adapt MultipleFO2PDF example.

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

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=383398&r1=383397&r2=383398&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 Sun Mar  5 12:47:00 2006
@@ -43,6 +43,7 @@
 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.
@@ -73,14 +74,22 @@
         try {
             FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
             // configure foUserAgent as desired
-            // Construct fop with desired output format
-            fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent);
     
             // Setup output stream.  Note: Using BufferedOutputStream
             // for performance reasons (helpful with FileOutputStreams).
             out = new FileOutputStream(pdf);
             out = new BufferedOutputStream(out);
-            fop.setOutputStream(out);
+
+            // 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();
@@ -90,7 +99,7 @@
             Source src = new StreamSource(fo);
 
             // Resulting SAX events (the generated FO) must be piped through to FOP
-            Result res = new SAXResult(fop.getDefaultHandler());
+            Result res = new SAXResult(handler);
             
             // 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=383398&r1=383397&r2=383398&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 Sun Mar  5 12:47:00 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -25,7 +25,6 @@
 import org.xml.sax.helpers.DefaultHandler;
 
 // FOP
-import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FOTreeBuilder;
 
 /**
@@ -58,6 +57,24 @@
 
     // FOTreeBuilder object to maintain reference for access to results
     private FOTreeBuilder foTreeBuilder = null;
+
+    /**
+     * Constructor for use with already-created FOUserAgents. 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").
+     * @param ua FOUserAgent object
+     * @param stream the output stream
+     */
+    public Fop(String outputFormat, FOUserAgent ua, OutputStream stream) {
+        this.outputFormat = outputFormat;
+
+        foUserAgent = ua;
+        if (foUserAgent == null) {
+            foUserAgent = new FOUserAgent();
+        }
+        
+        this.stream = stream;
+    }
 
     /**
      * Constructor for use with already-created FOUserAgents. It uses MIME types to select the 

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=383398&r1=383397&r2=383398&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 Sun Mar  5 12:47:00 2006
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
@@ -154,6 +155,41 @@
             throw new NullPointerException("The userAgent parameter must not be null!");
         }
         return new Fop(outputFormat, userAgent);
+    }
+    
+    /**
+     * Returns a new {@link Fop} instance. FOP will be configured with a default user agent 
+     * instance. Use this factory method if your output type requires an output stream.
+     * <p>
+     * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
+     * use the constants defined in {@link MimeConstants}.
+     * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). 
+     * @param stream the output stream
+     * @return the new Fop instance
+     */
+    public Fop newFop(String outputFormat, OutputStream stream) {
+        return new Fop(outputFormat, newFOUserAgent(), stream);
+    }
+
+    /**
+     * Returns a new {@link Fop} instance. Use this factory method if your output type
+     * requires an output stream and you want to configure this very rendering run,
+     * i.e. if you want to set some metadata like the title and author of the document
+     * you want to render. In that case, create a new {@link FOUserAgent} instance
+     * using {@link #newFOUserAgent()}.
+     * <p>
+     * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can
+     * use the constants defined in {@link MimeConstants}.
+     * @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     
+     * @param stream the output stream
+     * @return the new Fop instance
+     */
+    public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream) {
+        if (userAgent == null) {
+            throw new NullPointerException("The userAgent parameter must not be null!");
+        }
+        return new Fop(outputFormat, userAgent, stream);
     }
     
     /**



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


Re: Test errors in API finalization branch [Re: svn commit: r383398 - in /xmlgraphics/fop/branches/Temp_API_Finalization: examples/embedding/java/embedding/MultipleFO2PDF.java src/java/org/apache/fop/apps/Fop.java src/java/org/apache/fop/apps/FopFactory.java]

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Hmm, I don't have them here.

On 05.03.2006 21:52:45 Simon Pepping wrote:
> I am getting two test errors in the FOTreeTestSuite in the API
> finalization branch, on page-dimension_auto_fallback.fo and
> page-dimension_both_indefinite.fo. Because I also get them without my
> changes, I committed anyway.
> 
> Regards, Simon
> 
> On Sun, Mar 05, 2006 at 08:47:02PM -0000, spepping@apache.org wrote:
> > Author: spepping
> > Date: Sun Mar  5 12:47:00 2006
> > New Revision: 383398
> > 
> > URL: http://svn.apache.org/viewcvs?rev=383398&view=rev
> > Log:
> > Add Fop constructor and corresponding FopFactory methods with an
> > output stream. Adapt MultipleFO2PDF example.
> > 
> > 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
> 
> -- 
> Simon Pepping
> home page: http://www.leverkruid.nl



Jeremias Maerki


Test errors in API finalization branch [Re: svn commit: r383398 - in /xmlgraphics/fop/branches/Temp_API_Finalization: examples/embedding/java/embedding/MultipleFO2PDF.java src/java/org/apache/fop/apps/Fop.java src/java/org/apache/fop/apps/FopFactory.java]

Posted by Simon Pepping <sp...@leverkruid.nl>.
I am getting two test errors in the FOTreeTestSuite in the API
finalization branch, on page-dimension_auto_fallback.fo and
page-dimension_both_indefinite.fo. Because I also get them without my
changes, I committed anyway.

Regards, Simon

On Sun, Mar 05, 2006 at 08:47:02PM -0000, spepping@apache.org wrote:
> Author: spepping
> Date: Sun Mar  5 12:47:00 2006
> New Revision: 383398
> 
> URL: http://svn.apache.org/viewcvs?rev=383398&view=rev
> Log:
> Add Fop constructor and corresponding FopFactory methods with an
> output stream. Adapt MultipleFO2PDF example.
> 
> 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

-- 
Simon Pepping
home page: http://www.leverkruid.nl