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 je...@apache.org on 2006/03/27 11:51:21 UTC

svn commit: r389086 [1/2] - in /xmlgraphics/fop/trunk: ./ examples/embedding/java/embedding/ examples/embedding/java/embedding/intermediate/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/area/ src/java/org/apache/fop/cli/ src/java/org/apache/fo...

Author: jeremias
Date: Mon Mar 27 01:51:14 2006
New Revision: 389086

URL: http://svn.apache.org/viewcvs?rev=389086&view=rev
Log:
Merged Temp_API_Finalization branch back into FOP Trunk:
Finalized API according to the plan in the Wiki: http://wiki.apache.org/xmlgraphics-fop/ApiDesign

In addition to that:
Deprecated the rest of the Fop constructors.
Refactored the FopServlet a bit to make it more versatile and still easy to understand. The FopPrintServlet is now a subclass of FopServlet.
Some further cleanup on the way.

Added:
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/MultipleFO2PDF.java
      - copied, changed from r388782, xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java
      - copied, changed from r388782, xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java
Modified:
    xmlgraphics/fop/trunk/build.xml
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleAWTViewer.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleDOM2PDF.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2RTF.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2PDF.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleConcat.java
    xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleStamp.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/Fop.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/AreaTreeInputHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/ElementMappingRegistry.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageFactory.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageLoader.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopPrintServlet.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopServlet.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/TestConverter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/anttasks/Fop.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/BasicDriverTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/GenericFOPTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/URIResolutionTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/threading/FOProcessorImpl.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BitmapProducerJava2D.java

Modified: xmlgraphics/fop/trunk/build.xml
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/build.xml?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/build.xml (original)
+++ xmlgraphics/fop/trunk/build.xml Mon Mar 27 01:51:14 2006
@@ -142,7 +142,7 @@
   <property name="Name" value="Apache FOP"/>
   <property name="name" value="fop"/>
   <property name="NAME" value="FOP"/>
-  <property name="version" value="0.91svn"/>
+  <property name="version" value="svn-trunk"/>
   <property name="year" value="1999-2006"/>
 
   <property name="javac.debug" value="on"/>

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleAWTViewer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleAWTViewer.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleAWTViewer.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleAWTViewer.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2003,2005 The Apache Software Foundation.
+ * Copyright 1999-2003,2005-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.
@@ -37,19 +37,29 @@
 //FOP
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fo.Constants;
 
 /**
  * This class demonstrates the use of the AWT Viewer.
  */
 public class ExampleAWTViewer {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+
+    /**
+     * Display an FO file in the AWT Preview.
+     * @param fo the FO file
+     * @throws IOException In case of an I/O problem
+     * @throws FOPException In case of a problem during layout
+     * @throws TransformerException In case of a problem during XML processing
+     */
     public void viewFO(File fo)
                 throws IOException, FOPException, TransformerException {
 
         //Setup FOP
-        Fop fop = new Fop(MimeConstants.MIME_FOP_AWT_PREVIEW);
+        Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW);
 
         try {
 
@@ -68,6 +78,10 @@
         }
     }
 
+    /**
+     * Main method.
+     * @param args the command-line arguments
+     */
     public static void main(String[] args) {
         try {
             System.out.println("FOP ExampleAWTViewer\n");

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleDOM2PDF.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleDOM2PDF.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleDOM2PDF.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleDOM2PDF.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -20,10 +20,10 @@
 
 // Java
 import java.io.File;
-import java.io.IOException;
 import java.io.OutputStream;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
 
 //JAXP
 import javax.xml.transform.Transformer;
@@ -40,7 +40,9 @@
 import org.w3c.dom.Text;
 
 // FOP
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 
 
@@ -50,6 +52,9 @@
  */
 public class ExampleDOM2PDF {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+    
     /** xsl-fo namespace URI */
     protected static String foNS = "http://www.w3.org/1999/XSL/Format";
 
@@ -57,20 +62,19 @@
      * Converts a DOM Document to a PDF file using FOP.
      * @param xslfoDoc the DOM Document
      * @param pdf the target PDF file
-     * @throws IOException In case of an I/O problem
-     * @throws FOPException In case of a FOP problem
      */
     public void convertDOM2PDF(Document xslfoDoc, File pdf) {
         try {
-            // Construct fop with desired output format
-            Fop fop = new Fop(MimeConstants.MIME_PDF);
-            
+            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+            // configure foUserAgent as desired
+    
             // Setup output
             OutputStream out = new java.io.FileOutputStream(pdf);
             out = new java.io.BufferedOutputStream(out);
     
             try {
-                fop.setOutputStream(out);
+                // Construct fop with desired output format and output stream
+                Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
                 
                 // Setup Identity Transformer
                 TransformerFactory factory = TransformerFactory.newInstance();
@@ -113,38 +117,7 @@
             System.out.println("PDF Output File: " + pdffile);
             System.out.println();
             
-            // Create a sample XSL-FO DOM document
-            Document foDoc = null;
-            Element root = null, ele1 = null, ele2 = null, ele3 = null;
-            
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware(true);
-            DocumentBuilder db = dbf.newDocumentBuilder();
-            foDoc = db.newDocument();
-            
-            root = foDoc.createElementNS(foNS, "fo:root");
-            foDoc.appendChild(root);
-            
-            ele1 = foDoc.createElementNS(foNS, "fo:layout-master-set");
-            root.appendChild(ele1);
-            ele2 = foDoc.createElementNS(foNS, "fo:simple-page-master");
-            ele1.appendChild(ele2);
-            ele2.setAttributeNS(null, "master-name", "letter");
-            ele2.setAttributeNS(null, "page-height", "11in");
-            ele2.setAttributeNS(null, "page-width", "8.5in");
-            ele2.setAttributeNS(null, "margin-top", "1in");
-            ele2.setAttributeNS(null, "margin-bottom", "1in");
-            ele2.setAttributeNS(null, "margin-left", "1in");
-            ele2.setAttributeNS(null, "margin-right", "1in");
-            ele3 = foDoc.createElementNS(foNS, "fo:region-body");
-            ele2.appendChild(ele3);
-            ele1 = foDoc.createElementNS(foNS, "fo:page-sequence");
-            root.appendChild(ele1);
-            ele1.setAttributeNS(null, "master-reference", "letter");
-            ele2 = foDoc.createElementNS(foNS, "fo:flow");
-            ele1.appendChild(ele2);
-            ele2.setAttributeNS(null, "flow-name", "xsl-region-body");
-            addElement(ele2, "fo:block", "Hello World!");
+            Document foDoc = buildDOMDocument();
             
             ExampleDOM2PDF app = new ExampleDOM2PDF();
             app.convertDOM2PDF(foDoc, pdffile);
@@ -155,6 +128,47 @@
             e.printStackTrace(System.err);
             System.exit(-1);
         }
+    }
+
+    /**
+     * Builds the example FO document as a DOM in memory.
+     * @return the FO document
+     * @throws ParserConfigurationException In case there is a problem creating a DOM document
+     */
+    private static Document buildDOMDocument() throws ParserConfigurationException {
+        // Create a sample XSL-FO DOM document
+        Document foDoc = null;
+        Element root = null, ele1 = null, ele2 = null, ele3 = null;
+        
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        foDoc = db.newDocument();
+        
+        root = foDoc.createElementNS(foNS, "fo:root");
+        foDoc.appendChild(root);
+        
+        ele1 = foDoc.createElementNS(foNS, "fo:layout-master-set");
+        root.appendChild(ele1);
+        ele2 = foDoc.createElementNS(foNS, "fo:simple-page-master");
+        ele1.appendChild(ele2);
+        ele2.setAttributeNS(null, "master-name", "letter");
+        ele2.setAttributeNS(null, "page-height", "11in");
+        ele2.setAttributeNS(null, "page-width", "8.5in");
+        ele2.setAttributeNS(null, "margin-top", "1in");
+        ele2.setAttributeNS(null, "margin-bottom", "1in");
+        ele2.setAttributeNS(null, "margin-left", "1in");
+        ele2.setAttributeNS(null, "margin-right", "1in");
+        ele3 = foDoc.createElementNS(foNS, "fo:region-body");
+        ele2.appendChild(ele3);
+        ele1 = foDoc.createElementNS(foNS, "fo:page-sequence");
+        root.appendChild(ele1);
+        ele1.setAttributeNS(null, "master-reference", "letter");
+        ele2 = foDoc.createElementNS(foNS, "fo:flow");
+        ele1.appendChild(ele2);
+        ele2.setAttributeNS(null, "flow-name", "xsl-region-body");
+        addElement(ele2, "fo:block", "Hello World!");
+        return foDoc;
     }
 
     /**

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2OldStylePrint.java Mon Mar 27 01:51:14 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.
@@ -36,7 +36,7 @@
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.render.print.PrintRenderer;
 
 /**
@@ -44,6 +44,9 @@
  */
 public class ExampleFO2OldStylePrint {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+    
     /**
      * Prints an FO file using an old-style PrinterJob.
      * @param fo the FO file
@@ -60,13 +63,11 @@
         
         try {
             //Set up a custom user agent so we can supply our own renderer instance
-            FOUserAgent userAgent = new FOUserAgent();
+            FOUserAgent userAgent = fopFactory.newFOUserAgent();
             userAgent.setRendererOverride(renderer);
             
-            // Construct fop with desired output format
-            Fop fop = new Fop(MimeConstants.MIME_FOP_PRINT, userAgent);
-            //Note: the first parameter here has no effect if we use 
-            //FOUserAgent.setRendererOverride()
+            // Construct fop with desired output format (here, it is set through the user agent)
+            Fop fop = fopFactory.newFop(userAgent);
 
             // Setup JAXP using identity transformer
             TransformerFactory factory = TransformerFactory.newInstance();

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java Mon Mar 27 01:51:14 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.
@@ -35,8 +35,10 @@
 
 
 // FOP
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.FormattingResults;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.apps.PageSequenceResults;
@@ -46,6 +48,9 @@
  */
 public class ExampleFO2PDF {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+
     /**
      * Converts an FO file to a PDF file using FOP
      * @param fo the FO file
@@ -58,14 +63,16 @@
         OutputStream out = null;
         
         try {
-            // Construct fop with desired output format
-            Fop fop = new Fop(MimeConstants.MIME_PDF);
+            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+            // configure foUserAgent as desired
     
             // 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
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
 
             // Setup JAXP using identity transformer
             TransformerFactory factory = TransformerFactory.newInstance();

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -36,8 +36,9 @@
 import org.xml.sax.SAXException;
 
 // FOP
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 
 /**
@@ -46,32 +47,36 @@
  */
 public class ExampleFO2PDFUsingSAXParser {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+
     /**
      * Converts an FO file to a PDF file using FOP
      * @param fo the FO file
      * @param pdf the target PDF file
-     * @throws FactoryConfigurationError
-     * @throws ParserConfigurationException
-     * @throws SAXException
+     * @throws FactoryConfigurationError In case of a problem with the JAXP factory configuration
+     * @throws ParserConfigurationException In case of a problem with the parser configuration
+     * @throws SAXException In case of a problem during XML processing
      * @throws IOException In case of an I/O problem
-     * @throws FOPException In case of a FOP problem
      */
     public void convertFO2PDF(File fo, File pdf)
         throws FactoryConfigurationError,
                ParserConfigurationException,
-               FOPException, SAXException, IOException {
+               SAXException, IOException {
+
+        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+        // configure foUserAgent as desired
 
         OutputStream out = null;
         
         try {
-            // Construct fop and setup output format
-            Fop fop = new Fop(MimeConstants.MIME_PDF);
-    
             // 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 and setup output format
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
 
             // Setup SAX parser
             // throws FactoryConfigurationError

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2RTF.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2RTF.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2RTF.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2RTF.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-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.
@@ -34,18 +34,23 @@
 import javax.xml.transform.sax.SAXResult;
 
 // FOP
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 
 /**
  * This class demonstrates the conversion of an FO file to RTF using FOP.
  * <p>
  * Please note that this is practically the same as the ExampleFO2PDF example. Only
- * one parameter to the Fop contructor is different!
+ * the MIME parameter to the newFop() method is different!
  */
 public class ExampleFO2RTF {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+
     /**
      * Converts an FO file to a RTF file using FOP
      * @param fo the FO file
@@ -55,18 +60,20 @@
      */
     public void convertFO2RTF(File fo, File rtf) throws IOException, FOPException {
         
+        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+        // configure foUserAgent as desired
+
         OutputStream out = null;
         
         try {
-            // Construct fop with desired output format
-            Fop fop = new Fop(MimeConstants.MIME_RTF);
-    
             // Setup output stream.  Note: Using BufferedOutputStream
             // for performance reasons (helpful with FileOutputStreams).
             out = new FileOutputStream(rtf);
             out = new BufferedOutputStream(out);
-            fop.setOutputStream(out);
 
+            // Construct fop with desired output format
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, out);
+    
             // Setup JAXP using identity transformer
             TransformerFactory factory = TransformerFactory.newInstance();
             Transformer transformer = factory.newTransformer(); // identity transformer

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2PDF.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2PDF.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2PDF.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2PDF.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-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.
@@ -33,8 +33,10 @@
 import javax.xml.transform.sax.SAXResult;
 
 // FOP
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 
 import embedding.model.ProjectTeam;
@@ -45,6 +47,9 @@
  */
 public class ExampleObj2PDF {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+
     /**
      * Converts a ProjectTeam object to a PDF file.
      * @param team the ProjectTeam object
@@ -57,14 +62,15 @@
     public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf) 
                 throws IOException, FOPException, TransformerException {
                     
-        // Construct fop with desired output format
-        Fop fop = new Fop(MimeConstants.MIME_PDF);
+        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+        // configure foUserAgent as desired
 
         // Setup output
         OutputStream out = new java.io.FileOutputStream(pdf);
         out = new java.io.BufferedOutputStream(out);
         try {
-            fop.setOutputStream(out);
+            // Construct fop with desired output format
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
 
             // Setup XSLT
             TransformerFactory factory = TransformerFactory.newInstance();

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java Mon Mar 27 01:51:14 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.
@@ -31,7 +31,9 @@
 import javax.xml.transform.sax.SAXResult;
 
 //FOP
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 
 /**
@@ -65,15 +67,19 @@
             System.out.println();
             System.out.println("Transforming...");
             
-            // Construct fop with desired output format
-            Fop fop = new Fop(MimeConstants.MIME_PDF);
-            
+            // configure fopFactory as desired
+            FopFactory fopFactory = FopFactory.newInstance();
+
+            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+            // configure foUserAgent as desired
+
             // Setup output
             OutputStream out = new java.io.FileOutputStream(pdffile);
             out = new java.io.BufferedOutputStream(out);
             
             try {
-                fop.setOutputStream(out);
+                // Construct fop with desired output format
+                Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
     
                 // Setup XSLT
                 TransformerFactory factory = TransformerFactory.newInstance();

Copied: xmlgraphics/fop/trunk/examples/embedding/java/embedding/MultipleFO2PDF.java (from r388782, xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java)
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/MultipleFO2PDF.java?p2=xmlgraphics/fop/trunk/examples/embedding/java/embedding/MultipleFO2PDF.java&p1=xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java&r1=388782&r2=389086&rev=389086&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/examples/embedding/java/embedding/MultipleFO2PDF.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/MultipleFO2PDF.java Mon Mar 27 01:51:14 2006
@@ -54,6 +54,9 @@
 
     // configure fopFactory as desired
     private FopFactory fopFactory = FopFactory.newInstance();
+
+    // JAXP TransformerFactory can be reused, too
+    private TransformerFactory factory = TransformerFactory.newInstance();
     
     /**
      * Converts an FO file to a PDF file using FOP
@@ -83,7 +86,6 @@
             fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
 
             // Setup JAXP using identity transformer
-            TransformerFactory factory = TransformerFactory.newInstance();
             Transformer transformer = factory.newTransformer(); // identity transformer
             
             // Setup input stream

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleConcat.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleConcat.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleConcat.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleConcat.java Mon Mar 27 01:51:14 2006
@@ -33,6 +33,7 @@
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.AreaTreeModel;
 import org.apache.fop.area.AreaTreeParser;
@@ -53,6 +54,9 @@
  */
 public class ExampleConcat {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+
     /**
      * Creates a sample ProjectTeam instance for this demo.
      * @return ProjectTeam the newly created ProjectTeam instance
@@ -80,7 +84,7 @@
                 throws IOException, FOPException, TransformerException {
         
         //Create a user agent
-        FOUserAgent userAgent = new FOUserAgent();
+        FOUserAgent userAgent = fopFactory.newFOUserAgent();
         
         //Create an instance of the target renderer so the XMLRenderer can use its font setup
         Renderer targetRenderer = userAgent.getRendererFactory().createRenderer(
@@ -96,14 +100,12 @@
         //Make sure the prepared XMLRenderer is used
         userAgent.setRendererOverride(xmlRenderer);
         
-        // Construct fop (the MIME type here is unimportant due to the override on the user agent)
-        Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, userAgent);
-
         // Setup output
         OutputStream out = new java.io.FileOutputStream(intermediate);
         out = new java.io.BufferedOutputStream(out);
         try {
-            fop.setOutputStream(out);
+            // Construct fop (the MIME type here is unimportant due to the override on the user agent)
+            Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, userAgent, out);
 
             // Setup XSLT
             TransformerFactory factory = TransformerFactory.newInstance();
@@ -140,7 +142,7 @@
         try {
             //Setup fonts and user agent
             FontInfo fontInfo = new FontInfo();
-            FOUserAgent userAgent = new FOUserAgent();
+            FOUserAgent userAgent = fopFactory.newFOUserAgent();
 
             //Construct the AreaTreeModel that will received the individual pages
             AreaTreeModel treeModel = new RenderPagesModel(userAgent, 

Modified: xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleStamp.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleStamp.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleStamp.java (original)
+++ xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ExampleStamp.java Mon Mar 27 01:51:14 2006
@@ -30,6 +30,7 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.area.AreaTreeModel;
 import org.apache.fop.area.AreaTreeParser;
@@ -46,6 +47,9 @@
  */
 public class ExampleStamp {
 
+    // configure fopFactory as desired
+    private FopFactory fopFactory = FopFactory.newInstance();
+    
     /**
      * Stamps an intermediate file and renders it to a PDF file.
      * @param atfile the intermediate file (area tree XML)
@@ -63,7 +67,7 @@
         try {
             //Setup fonts and user agent
             FontInfo fontInfo = new FontInfo();
-            FOUserAgent userAgent = new FOUserAgent();
+            FOUserAgent userAgent = fopFactory.newFOUserAgent();
 
             //Construct the AreaTreeModel that will received the individual pages
             AreaTreeModel treeModel = new RenderPagesModel(userAgent, 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java Mon Mar 27 01:51:14 2006
@@ -20,10 +20,7 @@
 
 // Java
 import java.io.File;
-import java.net.URL;
-import java.net.MalformedURLException;
 import java.util.Date;
-import java.util.List;
 import java.util.Map;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
@@ -39,19 +36,17 @@
 
 // FOP
 import org.apache.fop.Version;
-import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.FOEventHandler;
-import org.apache.fop.hyphenation.HyphenationTreeResolver;
-import org.apache.fop.layoutmgr.LayoutManagerMaker;
 import org.apache.fop.pdf.PDFEncryptionParams;
 import org.apache.fop.render.Renderer;
 import org.apache.fop.render.RendererFactory;
 import org.apache.fop.render.XMLHandlerRegistry;
+import org.apache.fop.render.pdf.PDFRenderer;
 
 /**
- * The User Agent for fo.
- * This user agent is used by the processing to obtain user configurable
- * options.
+ * This is the user agent for FOP.
+ * It is the entity through which you can interact with the XSL-FO processing and is
+ * used by the processing to obtain user configurable options.
  * <p>
  * Renderer specific extensions (that do not produce normal areas on
  * the output) will be done like so:
@@ -70,65 +65,25 @@
  */
 public class FOUserAgent {
 
-    /** Defines the default source resolution (72dpi) for FOP */
-    public static final float DEFAULT_SOURCE_RESOLUTION = 72.0f; //dpi
     /** Defines the default target resolution (72dpi) for FOP */
     public static final float DEFAULT_TARGET_RESOLUTION = 72.0f; //dpi
-    /** Defines the default page-height */
-    public static final String DEFAULT_PAGE_HEIGHT = "11in";
-    /** Defines the default page-width */
-    public static final String DEFAULT_PAGE_WIDTH = "8.26in";
-    
-    /** Factory for Renderers and FOEventHandlers */
-    private RendererFactory rendererFactory = new RendererFactory();
-    
-    /** Registry for XML handlers */
-    private XMLHandlerRegistry xmlHandlers = new XMLHandlerRegistry();
-    
-    /** The resolver for user-supplied hyphenation patterns */
-    private HyphenationTreeResolver hyphResolver;
+
+    private static Log log = LogFactory.getLog("FOP");
+
+    private FopFactory factory;
     
     /** The base URL for all URL resolutions, especially for external-graphics */
     private String baseURL;
     
-    /** The base URL for all font URL resolutions */
-    private String fontBaseURL;
-    
     /** A user settable URI Resolver */
     private URIResolver uriResolver = null;
-    /** Our default resolver if none is set */
-    private URIResolver foURIResolver = new FOURIResolver();
     
-    private PDFEncryptionParams pdfEncryptionParams;
-    private float sourceResolution = DEFAULT_SOURCE_RESOLUTION;
     private float targetResolution = DEFAULT_TARGET_RESOLUTION;
-    private String pageHeight = DEFAULT_PAGE_HEIGHT;
-    private String pageWidth = DEFAULT_PAGE_WIDTH;
     private Map rendererOptions = new java.util.HashMap();
     private File outputFile = null;
     private Renderer rendererOverride = null;
     private FOEventHandler foEventHandlerOverride = null;
-    private LayoutManagerMaker lmMakerOverride = null;
-    /* user configuration */
-    private Configuration userConfig = null;
-    private Log log = LogFactory.getLog("FOP");
-    
-    /* FOP has the ability, for some FO's, to continue processing even if the
-     * input XSL violates that FO's content model.  This is the default  
-     * behavior for FOP.  However, this flag, if set, provides the user the
-     * ability for FOP to halt on all content model violations if desired.   
-     */ 
-    private boolean strictValidation = true;
-    
-    /** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
-    private boolean breakIndentInheritanceOnReferenceAreaBoundary = false;
-
-    /** Allows enabling kerning on the base 14 fonts, default is false */
-    private boolean enableBase14Kerning = false;
     
-    /* Additional fo.ElementMapping subclasses set by user */
-    private List additionalElementMappings = null;
-
     /** Producer:  Metadata element for the system/software that produces
      * the document. (Some renderers can store this in the document.)
      */
@@ -152,24 +107,43 @@
     protected String keywords = null;
     
     /**
-     * Add the element mapping with the given class name.
-     * @param elementMapping the class name representing the element mapping.
+     * Default constructor
+     * @see org.apache.fop.apps.FopFactory
+     * @deprecated Provided for compatibility only. Please use the methods from 
+     *             FopFactory to construct FOUserAgent instances!
      */
-    public void addElementMapping(ElementMapping elementMapping) {
-        if (additionalElementMappings == null) {
-            additionalElementMappings = new java.util.ArrayList();
-        }
-        additionalElementMappings.add(elementMapping);
+    public FOUserAgent() {
+        this(FopFactory.newInstance());
     }
-
+    
     /**
-     * Returns the List of user-added ElementMapping class names
-     * @return List of Strings holding ElementMapping names.
+     * Main constructor. <b>This constructor should not be called directly. Please use the 
+     * methods from FopFactory to construct FOUserAgent instances!</b>
+     * @param factory the factory that provides environment-level information
+     * @see org.apache.fop.apps.FopFactory
      */
-    public List getAdditionalElementMappings() {
-        return additionalElementMappings;
+    public FOUserAgent(FopFactory factory) {
+        if (factory == null) {
+            throw new NullPointerException("The factory parameter must not be null");
+        }
+        this.factory = factory;
+        try {
+            if (factory.getUserConfig() != null) {
+                configure(factory.getUserConfig());
+            }
+        } catch (ConfigurationException cfge) {
+            log.error("Error while initializing the user asgent: "
+                    + cfge.getMessage());
+        }
     }
-
+    
+    /** @return the associated FopFactory instance */
+    public FopFactory getFactory() {
+        return this.factory;
+    }
+    
+    // ---------------------------------------------- rendering-run dependent stuff
+    
     /**
      * Sets an explicit renderer to use which overrides the one defined by the 
      * render type setting.  
@@ -205,78 +179,6 @@
     }
 
     /**
-     * Activates strict XSL content model validation for FOP
-     * Default is false (FOP will continue processing where it can)
-     * @param validateStrictly true to turn on strict validation
-     */
-    public void setStrictValidation(boolean validateStrictly) {
-        this.strictValidation = validateStrictly;
-    }
-
-    /**
-     * Returns whether FOP is strictly validating input XSL
-     * @return true of strict validation turned on, false otherwise
-     */
-    public boolean validateStrictly() {
-        return strictValidation;
-    }
-
-    /**
-     * @return true if the indent inheritance should be broken when crossing reference area 
-     *         boundaries (for more info, see the javadoc for the relative member variable)
-     */
-    public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
-        return breakIndentInheritanceOnReferenceAreaBoundary;
-    }
-
-    /**
-     * Controls whether to enable a feature that breaks indent inheritance when crossing
-     * reference area boundaries.
-     * <p>
-     * This flag controls whether FOP will enable special code that breaks property
-     * inheritance for start-indent and end-indent when the evaluation of the inherited
-     * value would cross a reference area. This is described under
-     * http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
-     * improve interoperability with commercial FO implementations and to produce
-     * results that are more in line with the expectation of unexperienced FO users.
-     * Note: Enabling this features violates the XSL specification!
-     * @param value true to enable the feature
-     */
-    public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
-        this.breakIndentInheritanceOnReferenceAreaBoundary = value;
-    }
-    
-    /** @return true if kerning on base 14 fonts is enabled */
-    public boolean isBase14KerningEnabled() {
-        return this.enableBase14Kerning;
-    }
-    
-    /**
-     * Controls whether kerning is activated on base 14 fonts.
-     * @param value true if kerning should be activated
-     */
-    public void setBase14KerningEnabled(boolean value) {
-        this.enableBase14Kerning = value;
-    }
-    
-    /**
-     * Sets an explicit LayoutManagerMaker instance which overrides the one
-     * defined by the AreaTreeHandler.
-     * @param lmMaker the LayoutManagerMaker instance
-     */
-    public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
-        this.lmMakerOverride = lmMaker;
-    }
-
-    /**
-     * Returns the overriding LayoutManagerMaker instance, if any.
-     * @return the overriding LayoutManagerMaker or null
-     */
-    public LayoutManagerMaker getLayoutManagerMakerOverride() {
-        return this.lmMakerOverride;
-    }
-
-    /**
      * Sets the producer of the document.  
      * @param producer source of document
      */
@@ -382,95 +284,18 @@
     }
 
     /**
-     * Set the user configuration.
-     * @param userConfig configuration
-     */
-    public void setUserConfig(Configuration userConfig) {
-        this.userConfig = userConfig;
-        try {
-            initUserConfig();
-        } catch (ConfigurationException cfge) {
-            log.error("Error initializing User Agent configuration: "
-                    + cfge.getMessage());
-        }
-    }
-
-    /**
-     * Get the user configuration.
-     * @return the user configuration
+     * Configures the FOUserAgent through the factory's configuration. 
+     * @see org.apache.avalon.framework.configuration.Configurable
      */
-    public Configuration getUserConfig() {
-        return userConfig;
-    }
-    
-    /**
-     * Initializes user agent settings from the user configuration
-     * file, if present: baseURL, resolution, default page size,...
-     * 
-     * @throws ConfigurationException when there is an entry that 
-     *          misses the required attribute
-     */
-    public void initUserConfig() throws ConfigurationException {
-        log.debug("Initializing User Agent Configuration");
-        setBaseURL(getBaseURLfromConfig("base"));
-        setFontBaseURL(getBaseURLfromConfig("font-base"));
-        final String hyphBase = getBaseURLfromConfig("hyphenation-base");
-        if (hyphBase != null) {
-            this.hyphResolver = new HyphenationTreeResolver() {
-                public Source resolve(String href) {
-                    return resolveURI(href, hyphBase);
-                }
-            };
-        }
-        if (userConfig.getChild("source-resolution", false) != null) {
-            this.sourceResolution 
-                = userConfig.getChild("source-resolution").getValueAsFloat(
-                        DEFAULT_SOURCE_RESOLUTION);
-            log.info("Source resolution set to: " + sourceResolution 
-                    + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
-        }
-        if (userConfig.getChild("target-resolution", false) != null) {
+    protected void configure(Configuration cfg) throws ConfigurationException {
+        setBaseURL(FopFactory.getBaseURLfromConfig(cfg, "base"));
+        if (cfg.getChild("target-resolution", false) != null) {
             this.targetResolution 
-                = userConfig.getChild("target-resolution").getValueAsFloat(
+                = cfg.getChild("target-resolution").getValueAsFloat(
                         DEFAULT_TARGET_RESOLUTION);
             log.info("Target resolution set to: " + targetResolution 
                     + "dpi (px2mm=" + getTargetPixelUnitToMillimeter() + ")");
         }
-        if (userConfig.getChild("strict-validation", false) != null) {
-            this.strictValidation = userConfig.getChild("strict-validation").getValueAsBoolean();
-        }
-        if (userConfig.getChild("break-indent-inheritance", false) != null) {
-            this.breakIndentInheritanceOnReferenceAreaBoundary 
-                = userConfig.getChild("break-indent-inheritance").getValueAsBoolean();
-        }
-        Configuration pageConfig = userConfig.getChild("default-page-settings");
-        if (pageConfig.getAttribute("height", null) != null) {
-            setPageHeight(pageConfig.getAttribute("height"));
-            log.info("Default page-height set to: " + pageHeight);
-        }
-        if (pageConfig.getAttribute("width", null) != null) {
-            setPageWidth(pageConfig.getAttribute("width"));
-            log.info("Default page-width set to: " + pageWidth);
-        }
-    }
-
-    private String getBaseURLfromConfig(String name) {
-        if (userConfig.getChild(name, false) != null) {
-            try {
-                String cfgBaseDir = userConfig.getChild(name).getValue(null);
-                if (cfgBaseDir != null) {
-                    File dir = new File(cfgBaseDir);
-                    if (dir.isDirectory()) {
-                        cfgBaseDir = dir.toURL().toExternalForm(); 
-                    }
-                }
-                log.info(name + " set to: " + cfgBaseDir);
-                return cfgBaseDir;
-            } catch (MalformedURLException mue) {
-                log.error("Base URL in user config is malformed!");
-            }
-        }
-        return null;
     }
     
     /**
@@ -478,21 +303,22 @@
      * @param mimeType MIME type of the renderer
      * @return the requested configuration subtree, null if there's no configuration
      */
-    public Configuration getUserRendererConfig (String mimeType) {
+    public Configuration getUserRendererConfig(String mimeType) {
 
-        if (userConfig == null || mimeType == null) {
+        Configuration cfg = getFactory().getUserConfig();
+        if (cfg == null || mimeType == null) {
             return null;
         }
 
         Configuration userRendererConfig = null;
 
         Configuration[] cfgs
-            = userConfig.getChild("renderers").getChildren("renderer");
+            = cfg.getChild("renderers").getChildren("renderer");
         for (int i = 0; i < cfgs.length; ++i) {
-            Configuration cfg = cfgs[i];
+            Configuration child = cfgs[i];
             try {
-                if (cfg.getAttribute("mime").equals(mimeType)) {
-                    userRendererConfig = cfg;
+                if (child.getAttribute("mime").equals(mimeType)) {
+                    userRendererConfig = child;
                     break;
                 }
             } catch (ConfigurationException e) {
@@ -521,27 +347,11 @@
     }
 
     /**
-     * Sets the font base URL.
-     * @param fontBaseURL font base URL
-     */
-    public void setFontBaseURL(String fontBaseURL) {
-        this.fontBaseURL = fontBaseURL;
-    }
-
-    /**
-     * Returns the font base URL.
-     * @return the font base URL
-     */
-    public String getFontBaseURL() {
-        return this.fontBaseURL != null ? this.fontBaseURL : this.baseURL;
-    }
-
-    /**
      * Sets the URI Resolver.
-     * @param uriResolver the new URI resolver
+     * @param resolver the new URI resolver
      */
-    public void setURIResolver(URIResolver uriResolver) {
-        this.uriResolver = uriResolver;
+    public void setURIResolver(URIResolver resolver) {
+        this.uriResolver = resolver;
     }
 
     /**
@@ -555,18 +365,23 @@
     /**
      * Returns the parameters for PDF encryption.
      * @return the PDF encryption parameters, null if not applicable
+     * @deprecated Use (PDFEncryptionParams)getRendererOptions().get("encryption-params") 
+     *             instead.
      */
     public PDFEncryptionParams getPDFEncryptionParams() {
-        return pdfEncryptionParams;
+        return (PDFEncryptionParams)getRendererOptions().get(PDFRenderer.ENCRYPTION_PARAMS);
     }
 
     /**
      * Sets the parameters for PDF encryption.
      * @param pdfEncryptionParams the PDF encryption parameters, null to
      * disable PDF encryption
+     * @deprecated Use getRendererOptions().put("encryption-params", 
+     *             new PDFEncryptionParams(..)) instead or set every parameter separately: 
+     *             getRendererOptions().put("noprint", Boolean.TRUE).
      */
     public void setPDFEncryptionParams(PDFEncryptionParams pdfEncryptionParams) {
-        this.pdfEncryptionParams = pdfEncryptionParams;
+        getRendererOptions().put(PDFRenderer.ENCRYPTION_PARAMS, pdfEncryptionParams);
     }
 
 
@@ -588,27 +403,23 @@
      * Will use the configured resolver and if not successful fall back
      * to the default resolver.
      * @param uri URI to access
-     * @param baseURL the base url to resolve against
+     * @param base the base URI to resolve against
      * @return A {@link javax.xml.transform.Source} object, or null if the URI
      * cannot be resolved. 
      * @see org.apache.fop.apps.FOURIResolver
      */
-    public Source resolveURI(String uri, String baseURL) {
+    public Source resolveURI(String uri, String base) {
         Source source = null;
         if (uriResolver != null) {
             try {
-                source = uriResolver.resolve(uri, baseURL);
+                source = uriResolver.resolve(uri, base);
             } catch (TransformerException te) {
                 log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
             }
         }
         if (source == null) {
-            // URI Resolver not configured or returned null, use default resolver
-            try {
-                source = foURIResolver.resolve(uri, baseURL);
-            } catch (TransformerException te) {
-                log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
-            }
+            // URI Resolver not configured or returned null, use default resolver from the factory
+            source = getFactory().resolveURI(uri, base);
         }
         return source;
     }
@@ -631,44 +442,20 @@
 
     /**
      * Returns the conversion factor from pixel units to millimeters. This
-     * depends on the desired source resolution.
-     * @return float conversion factor
-     * @see getSourceResolution()
-     */
-    public float getSourcePixelUnitToMillimeter() {
-        return 25.4f / this.sourceResolution; 
-    }
-    
-    /**
-     * Returns the conversion factor from pixel units to millimeters. This
      * depends on the desired target resolution.
      * @return float conversion factor
-     * @see getTargetResolution()
+     * @see #getTargetResolution()
      */
     public float getTargetPixelUnitToMillimeter() {
         return 25.4f / this.targetResolution; 
     }
     
-    /** @return the resolution for resolution-dependant input */
-    public float getSourceResolution() {
-        return this.sourceResolution;
-    }
-
     /** @return the resolution for resolution-dependant output */
     public float getTargetResolution() {
         return this.targetResolution;
     }
 
     /**
-     * Sets the source resolution in dpi. This value is used to interpret the pixel size
-     * of source documents like SVG images and bitmap images without resolution information.
-     * @param dpi resolution in dpi
-     */
-    public void setSourceResolution(int dpi) {
-        this.sourceResolution = dpi;
-    }
-    
-    /**
      * Sets the target resolution in dpi. This value defines the target resolution of
      * bitmap images generated by the bitmap renderers (such as the TIFF renderer) and of
      * bitmap images generated by filter effects in Apache Batik.
@@ -678,24 +465,39 @@
         this.targetResolution = dpi;
     }
     
+    // ---------------------------------------------- environment-level stuff
+    //                                                (convenience access to FopFactory methods)
+
+    /** @return the font base URL */
+    public String getFontBaseURL() {
+        String fontBaseURL = getFactory().getFontBaseURL(); 
+        return fontBaseURL != null ? fontBaseURL : this.baseURL;
+    }
+
     /**
-     * Gets the default page-height to use as fallback,
-     * in case page-height="auto"
-     * 
-     * @return the page-height, as a String
+     * Returns the conversion factor from pixel units to millimeters. This
+     * depends on the desired source resolution.
+     * @return float conversion factor
+     * @see #getSourceResolution()
      */
-    public String getPageHeight() {
-        return this.pageHeight;
+    public float getSourcePixelUnitToMillimeter() {
+        return getFactory().getSourcePixelUnitToMillimeter(); 
     }
     
+    /** @return the resolution for resolution-dependant input */
+    public float getSourceResolution() {
+        return getFactory().getSourceResolution();
+    }
+
     /**
-     * Sets the page-height to use as fallback, in case
-     * page-height="auto"
+     * Gets the default page-height to use as fallback,
+     * in case page-height="auto"
      * 
-     * @param pageHeight    page-height as a String
+     * @return the page-height, as a String
+     * @see FopFactory#getPageHeight()
      */
-    public void setPageHeight(String pageHeight) {
-        this.pageHeight = pageHeight;
+    public String getPageHeight() {
+        return getFactory().getPageHeight();
     }
     
     /**
@@ -703,48 +505,43 @@
      * in case page-width="auto"
      * 
      * @return the page-width, as a String
+     * @see FopFactory#getPageWidth()
      */
     public String getPageWidth() {
-        return this.pageWidth;
+        return getFactory().getPageWidth();
     }
     
     /**
-     * Sets the page-width to use as fallback, in case
-     * page-width="auto"
-     * 
-     * @param pageWidth    page-width as a String
+     * Returns whether FOP is strictly validating input XSL
+     * @return true of strict validation turned on, false otherwise
+     * @see FopFactory#validateStrictly()
      */
-    public void setPageWidth(String pageWidth) {
-        this.pageWidth = pageWidth;
+    public boolean validateStrictly() {
+        return getFactory().validateStrictly();
     }
-    
+
     /**
-     * If to create hot links to footnotes and before floats.
-     * @return True if hot links should be created
+     * @return true if the indent inheritance should be broken when crossing reference area 
+     *         boundaries (for more info, see the javadoc for the relative member variable)
+     * @see FopFactory#isBreakIndentInheritanceOnReferenceAreaBoundary()
      */
-    /* TODO This method is never referenced!
-    public boolean linkToFootnotes() {
-        return true;
-    }*/
+    public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
+        return getFactory().isBreakIndentInheritanceOnReferenceAreaBoundary();
+    }
 
     /**
      * @return the RendererFactory
      */
     public RendererFactory getRendererFactory() {
-        return this.rendererFactory;
+        return getFactory().getRendererFactory();
     }
 
     /**
      * @return the XML handler registry
      */
     public XMLHandlerRegistry getXMLHandlerRegistry() {
-        return this.xmlHandlers;
+        return getFactory().getXMLHandlerRegistry();
     }
 
-    /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation patterns. */
-    public HyphenationTreeResolver getHyphenationTreeResolver() {
-        return this.hyphResolver;
-    }
-    
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/Fop.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/Fop.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/Fop.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/Fop.java Mon Mar 27 01:51:14 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;
 
 /**
@@ -45,7 +44,7 @@
  * At the moment, it is recommended not to reuse an instance of this
  * class for more than one rendering run.
  */
-public class Fop implements Constants {
+public class Fop {
 
     // desired output format: MIME type such as "application/pdf", "application/postscript" etc.
     private String outputFormat = null;
@@ -64,23 +63,54 @@
      * 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
+     * @throws FOPException if setting up the DefaultHandler fails
+     * @deprecated End-users should use {@link FopFactory#newFop(String, FOUserAgent, OutputStream)} 
+     *             instead! This constructor will become invisible with FOP 1.0.
+     */
+    public Fop(String outputFormat, FOUserAgent ua, OutputStream stream) throws FOPException {
+        this.outputFormat = outputFormat;
+
+        foUserAgent = ua;
+        if (foUserAgent == null) {
+            foUserAgent = FopFactory.newInstance().newFOUserAgent();
+        }
+        
+        this.stream = stream;
+        
+        createDefaultHandler();
+    }
+
+    /**
+     * 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
+     * @throws FOPException if setting up the DefaultHandler fails
+     * @deprecated End-users should use {@link FopFactory#newFop(String, FOUserAgent)} instead!
+     *             This constructor will become invisible with FOP 1.0.
      */
-    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();
+            foUserAgent = FopFactory.newInstance().newFOUserAgent();
         }
+        
+        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 End-users should use {@link FopFactory#newFop(String)} instead!
+     *             This constructor will become invisible with FOP 1.0.
      */
     public Fop(String outputFormat) {
-        this(outputFormat, null);
+        this.outputFormat = outputFormat;
+        foUserAgent = FopFactory.newInstance().newFOUserAgent();
     }
 
     /**
@@ -95,25 +125,36 @@
      * Set the OutputStream to use to output the result of the Render
      * (if applicable)
      * @param stream the stream to output the result of rendering to
+     * @deprecated Use one of the factory methods on {@link FopFactory} with an OutputStream
+     *             parameter instead. This method will be removed with FOP 1.0.
      */
     public void setOutputStream(OutputStream stream) {
         this.stream = stream;
     }
 
     /**
-     * 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;
     }
@@ -140,6 +181,7 @@
      * Get the version of FOP
      * @return the version string
      * @deprecated Use {@link org.apache.fop.Version#getVersion()} instead!
+     *             This method will be removed with FOP 1.0.
      */
     public static String getVersion() {
         return org.apache.fop.Version.getVersion();

Copied: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java (from r388782, xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java)
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java?p2=xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java&p1=xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java&r1=388782&r2=389086&rev=389086&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_API_Finalization/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java Mon Mar 27 01:51:14 2006
@@ -22,9 +22,12 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.List;
 
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
@@ -32,6 +35,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.ElementMappingRegistry;
+import org.apache.fop.hyphenation.HyphenationTreeResolver;
 import org.apache.fop.image.ImageFactory;
 import org.apache.fop.layoutmgr.LayoutManagerMaker;
 import org.apache.fop.render.RendererFactory;
@@ -69,6 +73,14 @@
     private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry 
                 = new ContentHandlerFactoryRegistry();
     
+    /** Our default resolver if none is set */
+    private URIResolver foURIResolver = new FOURIResolver();
+    /** A user settable URI Resolver */
+    private URIResolver uriResolver = null;
+
+    /** The resolver for user-supplied hyphenation patterns */
+    private HyphenationTreeResolver hyphResolver;
+    
     private ImageFactory imageFactory = new ImageFactory();
 
     /** user configuration */
@@ -85,6 +97,9 @@
      */ 
     private boolean strictValidation = true;
 
+    /** Allows enabling kerning on the base 14 fonts, default is false */
+    private boolean enableBase14Kerning = false;
+    
     /** Source resolution in dpi */
     private float sourceResolution = DEFAULT_SOURCE_RESOLUTION;
     private String pageHeight = DEFAULT_PAGE_HEIGHT;
@@ -290,6 +305,28 @@
     }
 
     /**
+     * Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
+     * patterns and as backup for URI resolution performed during a rendering run. 
+     * @param resolver the new URI resolver
+     */
+    public void setURIResolver(URIResolver resolver) {
+        this.uriResolver = resolver;
+    }
+
+    /**
+     * Returns the URI Resolver.
+     * @return the URI Resolver
+     */
+    public URIResolver getURIResolver() {
+        return this.uriResolver;
+    }
+
+    /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation patterns. */
+    public HyphenationTreeResolver getHyphenationTreeResolver() {
+        return this.hyphResolver;
+    }
+    
+    /**
      * Activates strict XSL content model validation for FOP
      * Default is false (FOP will continue processing where it can)
      * @param validateStrictly true to turn on strict validation
@@ -331,6 +368,19 @@
         this.breakIndentInheritanceOnReferenceAreaBoundary = value;
     }
     
+    /** @return true if kerning on base 14 fonts is enabled */
+    public boolean isBase14KerningEnabled() {
+        return this.enableBase14Kerning;
+    }
+    
+    /**
+     * Controls whether kerning is activated on base 14 fonts.
+     * @param value true if kerning should be activated
+     */
+    public void setBase14KerningEnabled(boolean value) {
+        this.enableBase14Kerning = value;
+    }
+    
     /** @return the resolution for resolution-dependant input */
     public float getSourceResolution() {
         return this.sourceResolution;
@@ -463,6 +513,14 @@
     public void initUserConfig() throws ConfigurationException {
         log.debug("Initializing User Agent Configuration");
         setFontBaseURL(getBaseURLfromConfig(userConfig, "font-base"));
+        final String hyphBase = getBaseURLfromConfig(userConfig, "hyphenation-base");
+        if (hyphBase != null) {
+            this.hyphResolver = new HyphenationTreeResolver() {
+                public Source resolve(String href) {
+                    return resolveURI(href, hyphBase);
+                }
+            };
+        }
         if (userConfig.getChild("source-resolution", false) != null) {
             this.sourceResolution 
                 = userConfig.getChild("source-resolution").getValueAsFloat(
@@ -502,9 +560,6 @@
                     File dir = new File(cfgBaseDir);
                     if (dir.isDirectory()) {
                         cfgBaseDir = dir.toURL().toExternalForm(); 
-                    } else {
-                        //The next statement is for validation only
-                        new URL(cfgBaseDir);
                     }
                 }
                 log.info(name + " set to: " + cfgBaseDir);
@@ -514,6 +569,38 @@
             }
         }
         return null;
+    }
+
+    //------------------------------------------- URI resolution
+
+    /**
+     * Attempts to resolve the given URI.
+     * Will use the configured resolver and if not successful fall back
+     * to the default resolver.
+     * @param uri URI to access
+     * @param base the base URI to resolve against
+     * @return A {@link javax.xml.transform.Source} object, or null if the URI
+     * cannot be resolved. 
+     * @see org.apache.fop.apps.FOURIResolver
+     */
+    public Source resolveURI(String uri, String base) {
+        Source source = null;
+        if (uriResolver != null) {
+            try {
+                source = uriResolver.resolve(uri, base);
+            } catch (TransformerException te) {
+                log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
+            }
+        }
+        if (source == null) {
+            // URI Resolver not configured or returned null, use default resolver
+            try {
+                source = foURIResolver.resolve(uri, base);
+            } catch (TransformerException te) {
+                log.error("Attempt to resolve URI '" + uri + "' failed: ", te);
+            }
+        }
+        return source;
     }
 
     

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java Mon Mar 27 01:51:14 2006
@@ -116,7 +116,7 @@
 
         setupModel(userAgent, outputFormat, stream);
             
-        lmMaker = userAgent.getLayoutManagerMakerOverride();
+        lmMaker = userAgent.getFactory().getLayoutManagerMakerOverride();
         if (lmMaker == null) {
             lmMaker = new LayoutManagerMapping();
         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java Mon Mar 27 01:51:14 2006
@@ -108,8 +108,8 @@
      * @return the ContentHandler instance to receive the SAX stream from the area tree XML
      */
     public ContentHandler getContentHandler(AreaTreeModel treeModel, FOUserAgent userAgent) {
-        //TODO Retrieve this instance from the environment class once it has been created.
-        ElementMappingRegistry elementMappingRegistry = new ElementMappingRegistry(userAgent);
+        ElementMappingRegistry elementMappingRegistry 
+            = userAgent.getFactory().getElementMappingRegistry();
         return new Handler(treeModel, userAgent, elementMappingRegistry);
     }
     
@@ -252,8 +252,9 @@
                         handled = false;
                     }
                 } else {
-                    ContentHandlerFactory factory 
-                            = ContentHandlerFactoryRegistry.getInstance().getFactory(uri);
+                    ContentHandlerFactoryRegistry registry
+                            = userAgent.getFactory().getContentHandlerFactoryRegistry();
+                    ContentHandlerFactory factory = registry.getFactory(uri);
                     if (factory != null) {
                         delegate = factory.createContentHandler();
                         delegateStack.push(qName);
@@ -936,7 +937,7 @@
                             if (url != null) {
                                 bkg.setURL(url);
                                 
-                                ImageFactory fact = ImageFactory.getInstance();
+                                ImageFactory fact = userAgent.getFactory().getImageFactory();
                                 FopImage img = fact.getImage(url, userAgent);
                                 if (img == null) {
                                     log.error("Background image not available: " + url);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/AreaTreeInputHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/AreaTreeInputHandler.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/AreaTreeInputHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/AreaTreeInputHandler.java Mon Mar 27 01:51:14 2006
@@ -61,10 +61,6 @@
     public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) 
                 throws FOPException {
         FontInfo fontInfo = new FontInfo();
-        FOUserAgent effUserAgent = userAgent;
-        if (effUserAgent == null) {
-            effUserAgent = new FOUserAgent();
-        }
         AreaTreeModel treeModel = new RenderPagesModel(userAgent, 
                 outputFormat, fontInfo, out);
         

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java Mon Mar 27 01:51:14 2006
@@ -28,11 +28,13 @@
 import org.apache.fop.Version;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
 import org.apache.fop.pdf.PDFEncryptionManager;
 import org.apache.fop.pdf.PDFEncryptionParams;
 import org.apache.fop.render.awt.AWTRenderer;
 import org.apache.fop.render.Renderer;
+import org.apache.fop.render.pdf.PDFRenderer;
 import org.apache.fop.render.xml.XMLRenderer;
 import org.apache.fop.util.CommandLineLogger;
 
@@ -41,14 +43,7 @@
 import org.apache.commons.logging.LogFactory;
 
 // SAX
-import org.xml.sax.XMLReader;
 import org.xml.sax.SAXException;
-import javax.xml.parsers.SAXParserFactory;
-
-// avalon configuration
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
 
 /**
  * Options parses the commandline arguments
@@ -92,6 +87,7 @@
     /* output mode */
     private String outputmode = null;
 
+    private FopFactory factory = FopFactory.newInstance();
     private FOUserAgent foUserAgent;
 
     private InputHandler inputHandler;
@@ -130,7 +126,7 @@
             throws FOPException, IOException {
         boolean optionsParsed = true;
 
-        foUserAgent = new FOUserAgent();
+        foUserAgent = factory.newFOUserAgent();
 
         try {
             optionsParsed = parseOptions(args);
@@ -217,7 +213,7 @@
             } else if (args[i].equals("-d")) {
                 setLogOption("debug", "debug");
             } else if (args[i].equals("-r")) {
-                foUserAgent.setStrictValidation(false);
+                factory.setStrictValidation(false);
             } else if (args[i].equals("-dpi")) {
                 i = i + parseResolution(args, i);
             } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
@@ -571,14 +567,17 @@
     }
 
     private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
-        if (foUserAgent.getPDFEncryptionParams() == null) {
+        PDFEncryptionParams params = (PDFEncryptionParams)foUserAgent.getRendererOptions().get(
+                        PDFRenderer.ENCRYPTION_PARAMS); 
+        if (params == null) {
             if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
                 throw new FOPException("PDF encryption requested but it is not available."
                         + " Please make sure MD5 and RC4 algorithms are available.");
             }
-            foUserAgent.setPDFEncryptionParams(new PDFEncryptionParams());
+            params = new PDFEncryptionParams();
+            foUserAgent.getRendererOptions().put(PDFRenderer.ENCRYPTION_PARAMS, params);
         }
-        return foUserAgent.getPDFEncryptionParams();
+        return params;
     }
 
     private int parsePDFOwnerPassword(String[] args, int i) throws FOPException {
@@ -726,18 +725,11 @@
         if (userConfigFile == null) {
             return;
         }
-        XMLReader parser = createParser();
-        DefaultConfigurationBuilder configBuilder
-            = new DefaultConfigurationBuilder(parser);
-        Configuration userConfig = null;
         try {
-            userConfig = configBuilder.buildFromFile(userConfigFile);
+            factory.setUserConfig(userConfigFile);
         } catch (SAXException e) {
             throw new FOPException(e);
-        } catch (ConfigurationException e) {
-            throw new FOPException(e);
         }
-        foUserAgent.setUserConfig(userConfig);
      }
 
     /**
@@ -978,20 +970,5 @@
         }
     }
 
-    /**
-     * Creates <code>XMLReader</code> object using default
-     * <code>SAXParserFactory</code>
-     * @return the created <code>XMLReader</code>
-     * @throws FOPException if the parser couldn't be created or configured for proper operation.
-     */
-    private XMLReader createParser() throws FOPException {
-        try {
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setNamespaceAware(true);
-            return factory.newSAXParser().getXMLReader();
-        } catch (Exception e) {
-            throw new FOPException("Couldn't create XMLReader", e);
-        }
-    }
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java Mon Mar 27 01:51:14 2006
@@ -39,6 +39,7 @@
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.render.awt.viewer.Renderable;
 
 /**
@@ -85,10 +86,13 @@
      */
     public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) 
                 throws FOPException {
-        
-        Fop fop = new Fop(outputFormat, userAgent);
+
+        FopFactory factory = userAgent.getFactory();
+        Fop fop;
         if (out != null) {
-            fop.setOutputStream(out);
+            fop = factory.newFop(outputFormat, userAgent, out);
+        } else {
+            fop = factory.newFop(outputFormat, userAgent);
         }
 
         // if base URL was not explicitly set in FOUserAgent, obtain here

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/ElementMappingRegistry.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/ElementMappingRegistry.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/ElementMappingRegistry.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/ElementMappingRegistry.java Mon Mar 27 01:51:14 2006
@@ -25,7 +25,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
 import org.apache.fop.fo.ElementMapping.Maker;
 import org.apache.fop.util.Service;
 import org.w3c.dom.DOMImplementation;
@@ -54,14 +54,14 @@
     /**
      * Main constructor. Adds all default element mapping as well as detects ElementMapping
      * through the Service discovery.
-     * @param userAgent the user agent
+     * @param factory the Fop Factory
      */
-    public ElementMappingRegistry(FOUserAgent userAgent) {
+    public ElementMappingRegistry(FopFactory factory) {
         // Add standard element mappings
         setupDefaultMappings();
 
         // add additional ElementMappings defined within FOUserAgent
-        List addlEMs = userAgent.getAdditionalElementMappings();
+        List addlEMs = factory.getAdditionalElementMappings();
 
         if (addlEMs != null) {
             for (int i = 0; i < addlEMs.size(); i++) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java Mon Mar 27 01:51:14 2006
@@ -52,9 +52,7 @@
 
     /** The registry for ElementMapping instances */
     protected ElementMappingRegistry elementMappingRegistry;
-    //TODO Remove the ElementMappingRegistry from here and move it to a new environmental class
-    //FOTreeBuilder should be a "one-use" component.
-    
+
     /**
      * The root of the formatting object tree
      */
@@ -93,7 +91,7 @@
         OutputStream stream) throws FOPException {
 
         this.userAgent = foUserAgent;
-        
+        this.elementMappingRegistry = userAgent.getFactory().getElementMappingRegistry();        
         //This creates either an AreaTreeHandler and ultimately a Renderer, or
         //one of the RTF-, MIF- etc. Handlers.
         foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler(
@@ -103,8 +101,6 @@
                 return new StaticPropertyList(fobj, parentPropertyList);
             }
         });
-
-        this.elementMappingRegistry = new ElementMappingRegistry(foUserAgent);
     }
 
     /**
@@ -174,7 +170,8 @@
         foEventHandler.endDocument();
         
         //Notify the image factory that this user agent has expired.
-        ImageFactory.getInstance().removeContext(this.userAgent);
+        ImageFactory imageFactory = userAgent.getFactory().getImageFactory();
+        imageFactory.removeContext(this.userAgent);
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java Mon Mar 27 01:51:14 2006
@@ -19,6 +19,7 @@
 package org.apache.fop.fo.flow;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
@@ -60,8 +61,9 @@
         
         //Additional processing: preload image
         url = ImageFactory.getURL(getSrc());
-        ImageFactory fact = ImageFactory.getInstance();
-        fopimage = fact.getImage(url, getUserAgent());
+        FOUserAgent userAgent = getUserAgent();
+        ImageFactory fact = userAgent.getFactory().getImageFactory();
+        fopimage = fact.getImage(url, userAgent);
         if (fopimage == null) {
             getLogger().error("Image not available: " + getSrc());
         } else {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java Mon Mar 27 01:51:14 2006
@@ -18,6 +18,7 @@
 
 package org.apache.fop.fo.properties;
 
+import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.datatypes.Length;
 import org.apache.fop.datatypes.PercentBaseContext;
@@ -158,8 +159,9 @@
             
             //Additional processing: preload image
             String url = ImageFactory.getURL(backgroundImage);
-            ImageFactory fact = ImageFactory.getInstance();
-            fopimage = fact.getImage(url, fobj.getUserAgent());
+            FOUserAgent userAgent = fobj.getUserAgent();
+            ImageFactory fact = userAgent.getFactory().getImageFactory();
+            fopimage = fact.getImage(url, userAgent);
             if (fopimage == null) {
                 fobj.getLogger().error("Background image not available: " + backgroundImage);
             } else {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageFactory.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageFactory.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageFactory.java Mon Mar 27 01:51:14 2006
@@ -50,13 +50,14 @@
      */
     protected static Log log = LogFactory.getLog(FopImage.class);
     
-    private static ImageFactory factory = new ImageFactory();
-
     private HashMap imageMimeTypes = new HashMap();
     
     private ImageCache cache = new ContextImageCache(true);
 
-    private ImageFactory() {
+    /**
+     * Main constructor for the ImageFactory.
+     */
+    public ImageFactory() {
         /* @todo The mappings set up below of image mime types to implementing
          * classes should be made externally configurable
          */
@@ -121,15 +122,6 @@
         imt = new ImageMimeType("image/emf");
         imageMimeTypes.put(imt.getMimeType(), imt);
         imt.addProvider(emfImage);
-    }
-
-    /**
-     * Get static image factory instance.
-     *
-     * @return the image factory instance
-     */
-    public static ImageFactory getInstance() {
-        return factory;
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageLoader.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageLoader.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageLoader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/image/ImageLoader.java Mon Mar 27 01:51:14 2006
@@ -51,7 +51,8 @@
         if (!valid || image != null) {
             return image;
         }
-        image = ImageFactory.getInstance().loadImage(url, userAgent);
+        ImageFactory imageFactory = userAgent.getFactory().getImageFactory();
+        image = imageFactory.loadImage(url, userAgent);
         if (image == null) {
             cache.invalidateImage(url, userAgent);
             valid = false;



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