svn commit: r481558 - in /incubator/ofbiz/trunk: ./ applications/content/servicedef/ applications/content/src/org/ofbiz/content/content/ applications/content/src/org/ofbiz/content/email/ framework/base/lib/ framework/base/lib/commons/ framework/example...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r481558 - in /incubator/ofbiz/trunk: ./ applications/content/servicedef/ applications/content/src/org/ofbiz/content/content/ applications/content/src/org/ofbiz/content/email/ framework/base/lib/ framework/base/lib/commons/ framework/example...

jacopoc
Author: jacopoc
Date: Sat Dec  2 05:37:24 2006
New Revision: 481558

URL: http://svn.apache.org/viewvc?view=rev&rev=481558
Log:
Major refactoring of the Apache  FOP rendering engine: upgrade from .20.5 to .92
Special thanks to John Martin and Christian Geisert for this work: OFBIZ-311

Added:
    incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.2.0.jar
      - copied, changed from r481543, incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.1.5.jar
    incubator/ofbiz/trunk/framework/base/lib/commons/commons-io-1.1.jar   (with props)
    incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.92.jar
      - copied, changed from r481543, incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.20.5-complete.jar
    incubator/ofbiz/trunk/framework/webapp/lib/batik-all-1.6.jar
      - copied, changed from r481543, incubator/ofbiz/trunk/framework/webapp/lib/batik.jar
    incubator/ofbiz/trunk/framework/webapp/lib/fop-0.92.jar
      - copied, changed from r481543, incubator/ofbiz/trunk/framework/webapp/lib/fop.jar
    incubator/ofbiz/trunk/framework/webapp/lib/xmlgraphics-commons-1.0.jar   (with props)
    incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java   (with props)
Removed:
    incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.1.5.jar
    incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.20.5-complete.jar
    incubator/ofbiz/trunk/framework/webapp/lib/batik.jar
    incubator/ofbiz/trunk/framework/webapp/lib/fop.jar
Modified:
    incubator/ofbiz/trunk/.classpath
    incubator/ofbiz/trunk/LICENSE
    incubator/ofbiz/trunk/applications/content/servicedef/services.xml
    incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java
    incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java
    incubator/ofbiz/trunk/framework/example/build.xml
    incubator/ofbiz/trunk/framework/example/src/org/ofbiz/example/ExamplePrintServices.java
    incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/FopRenderer.java
    incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java

Modified: incubator/ofbiz/trunk/.classpath
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/.classpath?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/.classpath (original)
+++ incubator/ofbiz/trunk/.classpath Sat Dec  2 05:37:24 2006
@@ -37,10 +37,12 @@
  <classpathentry kind="lib" path="framework/webapp/lib/velocity-1.3.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/MinML2.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/JPublish.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/fop.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/EdenLib.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/DataVision.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/batik.jar"/>
+ <classpathentry kind="lib" path="framework/webapp/lib/barcode4j-fop-ext-0.92.jar"/>
+ <classpathentry kind="lib" path="framework/webapp/lib/batik-all-1.6.jar"/>
+ <classpathentry kind="lib" path="framework/webapp/lib/fop-0.92.jar"/>
+ <classpathentry kind="lib" path="framework/webapp/lib/xmlgraphics-commons-1.0.jar"/>
  <classpathentry kind="lib" path="framework/service/lib/wsdl4j.jar"/>
  <classpathentry kind="lib" path="framework/service/lib/axis-ant.jar"/>
  <classpathentry kind="lib" path="framework/service/lib/axis.jar"/>
@@ -59,7 +61,6 @@
  <classpathentry kind="lib" path="framework/catalina/lib/catalina.jar"/>
  <classpathentry kind="lib" path="framework/catalina/lib/jmx.jar"/>
  <classpathentry kind="lib" path="framework/catalina/lib/catalina-cluster.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/barcode4j-fop-ext-0.20.5-complete.jar"/>
  <classpathentry kind="lib" path="framework/webapp/lib/itext-1.3.6.jar"/>
  <classpathentry kind="lib" path="framework/geronimo/lib/geronimo-transaction-1.0.jar"/>
  <classpathentry kind="lib" path="framework/geronimo/lib/jencks-1.1.3.jar"/>
@@ -77,9 +78,9 @@
  <classpathentry kind="lib" path="framework/base/lib/jakarta-regexp.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/icu4j_3_4.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/httpunit.jar"/>
- <classpathentry kind="lib" path="framework/base/lib/freemarker.jar"/>
+ <classpathentry kind="lib" path="framework/base/lib/freemarker-2.3.8.jar"/>
+ <classpathentry kind="lib" path="framework/base/lib/avalon-framework-4.2.0.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/avalon-util-exception-1.0.0.jar"/>
- <classpathentry kind="lib" path="framework/base/lib/avalon-framework-4.1.5.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/ant-launcher.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/ant.jar"/>
  <classpathentry kind="lib" path="framework/base/lib/commons/commons-vfs-providers.jar"/>

Modified: incubator/ofbiz/trunk/LICENSE
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/LICENSE?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/LICENSE (original)
+++ incubator/ofbiz/trunk/LICENSE Sat Dec  2 05:37:24 2006
@@ -13,7 +13,7 @@
 The following libraries are licensed under the Apache License Version 2.0:
 ofbiz/trunk/framework/base/lib/ant-launcher.jar
 ofbiz/trunk/framework/base/lib/ant.jar
-ofbiz/trunk/framework/base/lib/avalon-framework-4.1.5.jar
+ofbiz/trunk/framework/base/lib/avalon-framework-4.2.0.jar
 ofbiz/trunk/framework/base/lib/avalon-util-exception-1.0.0.jar
 ofbiz/trunk/framework/base/lib/jakarta-regexp.jar
 ofbiz/trunk/framework/base/lib/log4j.jar
@@ -32,6 +32,7 @@
 ofbiz/trunk/framework/base/lib/commons/commons-discovery.jar
 ofbiz/trunk/framework/base/lib/commons/commons-el.jar
 ofbiz/trunk/framework/base/lib/commons/commons-fileupload.jar
+ofbiz/trunk/framework/base/lib/commons/commons-io-1.1.jar
 ofbiz/trunk/framework/base/lib/commons/commons-lang-2.1.jar
 ofbiz/trunk/framework/base/lib/commons/commons-logging.jar
 ofbiz/trunk/framework/base/lib/commons/commons-modeler.jar
@@ -85,11 +86,12 @@
 ofbiz/trunk/framework/jetty/lib/org.mortbay.jmx.jar
 ofbiz/trunk/framework/service/lib/axis-ant.jar
 ofbiz/trunk/framework/service/lib/axis.jar
-ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.20.5-complete.jar
-ofbiz/trunk/framework/webapp/lib/batik.jar
-ofbiz/trunk/framework/webapp/lib/fop.jar
+ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.92.jar
+ofbiz/trunk/framework/webapp/lib/batik-all-1.6.jar
+ofbiz/trunk/framework/webapp/lib/fop-0.92.jar
 ofbiz/trunk/framework/webapp/lib/velocity-1.3.jar
 ofbiz/trunk/framework/webapp/lib/velocity-dep-1.3.jar
+ofbiz/trunk/framework/webapp/lib/xmlgraphics-commons-1.0.jar
 ofbiz/trunk/framework/geronimo/lib/geronimo-transaction-1.0.jar
 ofbiz/trunk/framework/geronimo/lib/jencks-1.1.3.jar
 ofbiz/trunk/applications/content/lib/lucene.jar

Modified: incubator/ofbiz/trunk/applications/content/servicedef/services.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/content/servicedef/services.xml?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/applications/content/servicedef/services.xml (original)
+++ incubator/ofbiz/trunk/applications/content/servicedef/services.xml Sat Dec  2 05:37:24 2006
@@ -1187,19 +1187,6 @@
         <attribute name="mapIn" type="java.util.Map" mode="IN" optional="false"/>
         <attribute mode="OUT" name="outputString" optional="true" type="String"/>
     </service>
-    <service name="foToPdf" auth="true" engine="java" transaction-timeout="72000"
-        location="org.ofbiz.content.content.ContentServices" invoke="foToPdf">
-        <attribute name="foFileIn" mode="IN" type="String" optional="false"/>
-        <attribute name="pdfFileOut" mode="IN" type="String" optional="true"/>
-        <attribute name="inputDataResourceTypeId" mode="IN" type="String" optional="true"/>
-        <attribute name="outputDataResourceTypeId" mode="IN" type="String" optional="true"/>
-        <attribute name="outputContentId" mode="INOUT" type="String" optional="true"/>
-        <attribute name="foContentId" mode="INOUT" type="String" optional="true"/>
-        <attribute name="templateDataResourceId" mode="IN" type="String" optional="true"/>
-        <attribute name="fmContext" type="java.util.Map" mode="IN" optional="true"/>
-        <attribute name="fmPrefixMap" type="java.util.Map" mode="IN" optional="true" string-map-prefix="CTX_"/>
-        <attribute name="pdfByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="true"/>
-    </service>
 
     <!-- Content Revision services -->
     <service name="createContentRevision" engine="simple"

Modified: incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java (original)
+++ incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java Sat Dec  2 05:37:24 2006
@@ -15,28 +15,6 @@
  */
 package org.ofbiz.content.content;
 
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.avalon.framework.logger.Log4JLogger;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.image.FopImageFactory;
-import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.tools.DocumentInputSource;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.StringUtil;
@@ -45,14 +23,12 @@
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.ByteWrapper;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.security.Security;
 import org.ofbiz.service.DispatchContext;
@@ -60,9 +36,18 @@
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
 import org.ofbiz.service.ServiceUtil;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * ContentServices Class
@@ -1130,209 +1115,4 @@
         return result;
     }
     
-    /**
-     * foFileIn - path to FO template, can be null if template is in the CMS
-     *            Normally, this parameter will only be used once to get the template
-     *            into the CMS, as this option will create a new entry in CMS each time.
-     * inputDataResourceTypeId - can be LOCAL_FILE or OFBIZ_FILE. Used if foFileIn is not null.
-     * pdfFileOut - path to where output PDF will be stored.Can be null if either PDF will be
-     *              stored as ELECTRONIC_TEXT or not stored at all, but returned as pdfByteWrapper
-     * outputDataResourceTypeId - can be LOCAL_FILE, OFBIZ_FILE or ELECTRONIC_TEXT.
-     * outputContentId - The CMS id of PDF output Content entity. Type is INOUT, but can be null,
-     *                  in which case it will be generated.
-     * foContentId - The CMS id of FO template Content entity. Type is INOUT, but can be null,
-     *                  in which case it will be generated.
-     *                  If not null, then foFileIn will be ignored.
-     *                  There is no current way to specify what you want the generated FO template ID to be.
-     *                  This is the preferred way to use the template - it should be in the CMS,
-     *                   else it will be created each time.
-     * fmContext - the Map that will be used in processing the FO template.
-     * fmPrefixMap - If fmContext is null, this Map will be used. It is generated by using the
-     *              prefix, "CTX_" on form parameters. Allows this service to be used as
-     *              in request event handler.
-     * @param dctx
-     * @param context
-     * @return
-     * @throws GenericServiceException
-     */
-    public static Map foToPdf(DispatchContext dctx, Map context) throws GenericServiceException{
-            
-        LocalDispatcher dispatcher = dctx.getDispatcher();
-        GenericValue userLogin = (GenericValue)context.get("userLogin");
-        Map result = new HashMap();
-        String foFileIn = (String)context.get("foFileIn");
-        String pdfFileOut = (String)context.get("pdfFileOut");
-        String outputDataResourceTypeId = (String)context.get("outputDataResourceTypeId");
-        String inputDataResourceTypeId = (String)context.get("inputDataResourceTypeId");
-        if (UtilValidate.isEmpty(inputDataResourceTypeId)) {
-            inputDataResourceTypeId = "LOCAL_FILE";
-        }
-        String outputContentId = (String)context.get("outputContentId");
-        String foContentId = (String)context.get("foContentId");
-        String templateDataResourceId = (String)context.get("templateDataResourceId");
-        Map fmContext = (Map)context.get("fmContext");
-        Map fmPrefixMap = (Map)context.get("fmPrefixMap");
-        // configure logging for the FOP
-        Logger logger = new Log4JLogger(Debug.getLogger(module));
-        MessageHandler.setScreenLogger(logger);        
-                          
-        // Get input FO. Process thru template, if required.
-        String processedFo = null;
-        // If the FO template is not already in the CMS, put it there,
-        // else, if the FTL template id is not there in the exisiting content, add it.
-        if (UtilValidate.isEmpty(foContentId)) {
-            if (UtilValidate.isEmpty(foFileIn)) {
-                return ServiceUtil.returnError("No FO file or contentId available.");
-            }
-            Map mapIn = new HashMap();
-            mapIn.put("drObjectInfo", foFileIn);
-            mapIn.put("drDataResourceTypeId", inputDataResourceTypeId);
-            mapIn.put("contentTypeId", "DOCUMENT");
-            //mapIn.put("contentPurposeString", "SOURCE");
-            mapIn.put("templateDataResourceId", templateDataResourceId);
-            mapIn.put("drDataTemplateTypeId", "FTL");
-            mapIn.put("userLogin", userLogin);
-            try {
-                Map thisResult = dispatcher.runSync("persistContentAndAssoc", mapIn);
-                foContentId = (String)thisResult.get("contentId");
-                if (UtilValidate.isEmpty(foContentId)) {
-                 Debug.logError("Could not add FO content - foContentId is null.", "ContentServices");
-                    return ServiceUtil.returnError("Could not add FO conten - foContentId is null.");
-                }
-                result.put("foContentId", foContentId);
-            } catch (GenericServiceException e) {
-                Debug.logError(e, "Problem adding FO content.", "ContentServices");
-                return ServiceUtil.returnError("Problem adding FO content.");
-            }
-            
-        } else {
-            if (UtilValidate.isNotEmpty(templateDataResourceId)) {
-                try {
-                    GenericDelegator delegator = dctx.getDelegator();
-                    GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", foContentId));
-                    String thisTemplateDataResourceId = content.getString("templateDataResourceId");
-                    if (thisTemplateDataResourceId == null || !thisTemplateDataResourceId.equals(templateDataResourceId)) {
-                         content.put("templateDataResourceId", templateDataResourceId);
-                         content.store();
-                    }
-                } catch(GenericEntityException e) {
-                    Debug.logError(e,  "ContentServices");
-                    return ServiceUtil.returnError(e.getMessage());
-                }
-            }
-        }
-        
-        // Now that the FO file is in the CMS and the FTL template Id is in place
-        // Get the processed FO file by running "renderContentAsText" file
-        Map mapIn = new HashMap();
-        mapIn.put("contentId", foContentId);
-        if (fmContext != null) {
-         mapIn.put("templateContext", fmContext);
-        } else {
-         mapIn.put("templateContext", fmPrefixMap);
-        }
-        StringWriter sw = new StringWriter();
-        mapIn.put("outWriter", sw);
-        try {
-            Map thisResult = dispatcher.runSync("renderContentAsText", mapIn);
-            processedFo = (String)thisResult.get("textData");
-            if (UtilValidate.isEmpty(processedFo)) {
-             Debug.logError("Could not get FO text", "ContentServices");
-                return ServiceUtil.returnError("Could not get FO text");
-            }
-        } catch (GenericServiceException e) {
-            Debug.logError(e, "Problem getting FO text", "ContentServices");
-            return ServiceUtil.returnError("Problem getting FO text");
-        }
-        
-        // load the FOP driver
-        Driver driver = new Driver();
-        driver.setRenderer(Driver.RENDER_PDF);
-        driver.setLogger(logger);
-                                        
-        // get the XSL-FO XML in Document format
-        Document xslfo = null;
-        try {
-            xslfo = UtilXml.readXmlDocument(processedFo);
-        } catch (FileNotFoundException e) {
-            return ServiceUtil.returnError("Error getting FO file: " + e.toString());
-        } catch (IOException e2) {
-            return ServiceUtil.returnError("Error getting FO file: " + e2.toString());
-        } catch (ParserConfigurationException e3) {
-            return ServiceUtil.returnError("Error getting FO file: " + e3.toString());
-        } catch (SAXException e4) {
-            return ServiceUtil.returnError("Error getting FO file: " + e4.toString());
-        }
-        
-        // create the output stream for the PDF
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        driver.setOutputStream(out);    
-                
-        // set the input source (XSL-FO) and generate the PDF        
-        InputSource is = new DocumentInputSource(xslfo);              
-        driver.setInputSource(is);        
-        try {
-            driver.run();
-            FopImageFactory.resetCache();
-        } catch (Throwable t) {
-            Debug.logError("Error processing PDF." + t.getMessage(), "ContentServices");
-            return ServiceUtil.returnError("Error processing PDF." + t.getMessage());
-        }
-        ByteWrapper pdfByteWrapper = new ByteWrapper(out.toByteArray());
-        result.put("pdfByteWrapper", pdfByteWrapper );
-                  
-        // Put output into CMS if dataResourceTypeId is present
-        // else, just write it to a file
-        if (UtilValidate.isNotEmpty(outputDataResourceTypeId)) {
-            if (pdfByteWrapper != null) {
-                Map mapIn2 = new HashMap();
-                mapIn2.put("contentId", outputContentId);
-                mapIn2.put("drDataResourceTypeId", outputDataResourceTypeId);
-                mapIn2.put("contentTypeId", "DOCUMENT");
-                mapIn2.put("imageData", pdfByteWrapper);
-                mapIn2.put("_imageData_contentType", "application/pdf");
-                mapIn2.put("_imageData_fileName", pdfFileOut);
-                mapIn2.put("drObjectInfo", pdfFileOut);
-                mapIn2.put("userLogin", userLogin);
-                try {
-                    Map thisResult = dispatcher.runSync("persistContentAndAssoc", mapIn2);
-                    outputContentId = (String)thisResult.get("contentId");
-                    if (UtilValidate.isEmpty(foContentId)) {
-                     Debug.logError("Could not add PDF content - contentId is null.", "ContentServices");
-                        return ServiceUtil.returnError("Could not add PDF conten - contentId is null.");
-                    }
-                    result.put("outputContentId", outputContentId);
-                } catch (GenericServiceException e) {
-                    Debug.logError(e, "Problem adding FO content.", module);
-                    return ServiceUtil.returnError("Problem adding FO content.");
-                }
-                result.put("outputContentId", outputContentId);
-            }
-        } else {
-            if (UtilValidate.isEmpty(pdfFileOut)) {
-                String outputPath = null;
-                String thisDataResourceTypeId = null;
-                String ofbizHome = System.getProperty("ofbiz.home");
-                int pos = pdfFileOut.indexOf("${OFBIZ_HOME}");
-                if (pos > 0 ) {
-                    outputPath =  pdfFileOut.substring(pos + 13);
-                    thisDataResourceTypeId = "OFBIZ_FILE";
-                } else {
-                    outputPath = pdfFileOut;  
-                    thisDataResourceTypeId = "LOCAL_FILE";
-                }
-                Map mapIn3 = new HashMap();
-                mapIn3.put("objectInfo", outputPath);
-                mapIn3.put("drDataResourceTypeId", thisDataResourceTypeId);
-                mapIn3.put("binData", pdfByteWrapper);
-                try {
-                    Map thisResult = dispatcher.runSync("createFile", mapIn3);
-                } catch (GenericServiceException e) {
-                    Debug.logError(e, "Problem writing FO content.", module);
-                    return ServiceUtil.returnError("Problem adding FO content.");
-                }
-            }
-        }
-        return result;
-    }
 }

Modified: incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java (original)
+++ incubator/ofbiz/trunk/applications/content/src/org/ofbiz/content/email/EmailServices.java Sat Dec  2 05:37:24 2006
@@ -15,28 +15,60 @@
  */
 package org.ofbiz.content.email;
 
+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.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.HttpClient;
+import org.ofbiz.base.util.HttpClientException;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.collections.MapStack;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.mail.MimeMessageWrapper;
+import org.ofbiz.webapp.view.ApacheFopFactory;
+import org.ofbiz.widget.html.HtmlScreenRenderer;
+import org.ofbiz.widget.screen.ScreenRenderer;
+import org.xml.sax.SAXException;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.ArrayList;
 import java.util.Locale;
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Properties;
-import java.sql.Timestamp;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
-import javax.mail.Message;
 import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Part;
 import javax.mail.Session;
 import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
@@ -44,44 +76,18 @@
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Part;
-import java.util.Date;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
 
-import org.apache.avalon.framework.logger.Log4JLogger;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.image.FopImageFactory;
-import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.tools.DocumentInputSource;
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.HttpClient;
-import org.ofbiz.base.util.HttpClientException;
-import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilProperties;
-import org.ofbiz.base.util.UtilValidate;
-import org.ofbiz.base.util.UtilXml;
-import org.ofbiz.base.util.UtilDateTime;
-import org.ofbiz.base.util.collections.MapStack;
-import org.ofbiz.base.util.string.FlexibleStringExpander;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.service.DispatchContext;
-import org.ofbiz.service.GenericServiceException;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.service.ServiceUtil;
-import org.ofbiz.service.mail.MimeMessageWrapper;
-import org.ofbiz.widget.html.HtmlScreenRenderer;
-import org.ofbiz.widget.screen.ScreenRenderer;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
 /**
  * Email Services
  */
@@ -359,39 +365,27 @@
                     Debug.logError(e, "Couldn't save xsl-fo xml debug file: " + e.toString(), module);
                 }
                 */
-                
-                // configure logging for the FOP
-                Logger logger = new Log4JLogger(Debug.getLogger(module));
-                MessageHandler.setScreenLogger(logger);        
-                
-                // load the FOP driver
-                Driver driver = new Driver();
-                driver.setRenderer(Driver.RENDER_PDF);
-                driver.setLogger(logger);
-                
-                // read the XSL-FO XML into the W3 Document
-                Document xslfo = UtilXml.readXmlDocument(writer.toString());
 
                 // create the in/output stream for the generation
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                driver.setOutputStream(baos);    
-                driver.setInputSource(new DocumentInputSource(xslfo));        
                 
+                FopFactory fopFactory = ApacheFopFactory.instance();
+                Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, baos);
+                TransformerFactory transFactory = TransformerFactory.newInstance();
+                Transformer transformer = transFactory.newTransformer();
+
+                Reader reader = new StringReader(writer.toString());
+                Source src = new StreamSource(reader);
+                Result res = new SAXResult(fop.getDefaultHandler());
+                
+                // Start XSLT transformation and FOP processing
+                transformer.transform(src, res);
                 // and generate the PDF
-                driver.run();
-                FopImageFactory.resetCache();
                 baos.flush();
                 baos.close();
 
-                /*
-                try {    // save generated pdf file for debugging
-                    FileOutputStream fos = new FileOutputStream(new java.io.File("/tmp/file2.pdf"));
-                    baos.writeTo(fos);
-                    fos.close();
-                } catch (IOException e) {
-                    Debug.logError(e, "Couldn't save xsl-fo pdf debug file: " + e.toString(), module);
-                }
-                */
+                // We don't want to cache the images that get loaded by the FOP engine
+                fopFactory.getImageFactory().clearCaches();
 
                 // store in the list of maps for sendmail....
                 List bodyParts = FastList.newInstance();
@@ -414,6 +408,12 @@
             } catch (FOPException fe) {
                 String errMsg = "Error rendering PDF attachment for email: " + fe.toString();
                 Debug.logError(fe, errMsg, module);
+                return ServiceUtil.returnError(errMsg);
+            } catch (TransformerConfigurationException tce) {
+                String errMsg = "FOP TransformerConfiguration Exception: " + tce.toString();
+                return ServiceUtil.returnError(errMsg);
+            } catch (TransformerException te) {
+                String errMsg = "FOP transform failed: " + te.toString();
                 return ServiceUtil.returnError(errMsg);
             } catch (SAXException se) {
                 String errMsg = "Error rendering PDF attachment for email: " + se.toString();

Copied: incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.2.0.jar (from r481543, incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.1.5.jar)
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.2.0.jar?view=diff&rev=481558&p1=incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.1.5.jar&r1=481543&p2=incubator/ofbiz/trunk/framework/base/lib/avalon-framework-4.2.0.jar&r2=481558
==============================================================================
Binary files - no diff available.

Added: incubator/ofbiz/trunk/framework/base/lib/commons/commons-io-1.1.jar
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/base/lib/commons/commons-io-1.1.jar?view=auto&rev=481558
==============================================================================
Binary file - no diff available.

Propchange: incubator/ofbiz/trunk/framework/base/lib/commons/commons-io-1.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/ofbiz/trunk/framework/example/build.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/example/build.xml?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/framework/example/build.xml (original)
+++ incubator/ofbiz/trunk/framework/example/build.xml Sat Dec  2 05:37:24 2006
@@ -45,6 +45,7 @@
             <fileset dir="../../framework/minilang/build/lib" includes="*.jar"/>
             <fileset dir="../../framework/widget/build/lib" includes="*.jar"/>
             <fileset dir="../../framework/webapp/lib" includes="*.jar"/>
+            <fileset dir="../../framework/webapp/build/lib" includes="*.jar"/>
         </path>
     </target>
 

Modified: incubator/ofbiz/trunk/framework/example/src/org/ofbiz/example/ExamplePrintServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/example/src/org/ofbiz/example/ExamplePrintServices.java?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/framework/example/src/org/ofbiz/example/ExamplePrintServices.java (original)
+++ incubator/ofbiz/trunk/framework/example/src/org/ofbiz/example/ExamplePrintServices.java Sat Dec  2 05:37:24 2006
@@ -15,8 +15,23 @@
  */
 package org.ofbiz.example;
 
+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.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.webapp.view.ApacheFopFactory;
+import org.ofbiz.widget.html.HtmlScreenRenderer;
+import org.ofbiz.widget.screen.ScreenRenderer;
+import org.xml.sax.SAXException;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Map;
@@ -33,23 +48,15 @@
 import javax.print.attribute.standard.Copies;
 import javax.print.attribute.standard.Sides;
 import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.avalon.framework.logger.Log4JLogger;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.image.FopImageFactory;
-import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.tools.DocumentInputSource;
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.UtilXml;
-import org.ofbiz.service.DispatchContext;
-import org.ofbiz.service.ServiceUtil;
-import org.ofbiz.widget.html.HtmlScreenRenderer;
-import org.ofbiz.widget.screen.ScreenRenderer;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
 
 public class ExamplePrintServices {
     public static final String module = ExamplePrintServices.class.getName();
@@ -90,40 +97,48 @@
 
         String reportXmlDocument = reportWriter.toString();
 
-        // configure logging for the FOP
-        Logger logger = new Log4JLogger(Debug.getLogger(module));
-        MessageHandler.setScreenLogger(logger);        
-                          
-        // load the FOP driver
-        Driver driver = new Driver();
-        driver.setRenderer(Driver.RENDER_PDF);
-        driver.setLogger(logger);
-                                        
-        // read the XSL-FO XML Document
-        Document xslfo = null;
-        try {
-            xslfo = UtilXml.readXmlDocument(reportXmlDocument);
-        } catch (Throwable t) {
-            String errMsg = "Problems reading the parsed content to XML Document: " + t.toString();
-            Debug.logError(t, errMsg, module);
-            return ServiceUtil.returnError(errMsg);
-        }
-        
-        // create the output stream for the PDF
+        // create the in/output stream for the generation
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        driver.setOutputStream(out);    
-                
-        // set the input source (XSL-FO) and generate the PDF        
-        InputSource is = new DocumentInputSource(xslfo);              
-        driver.setInputSource(is);        
+        
+        
+        FopFactory fopFactory;
         try {
-            driver.run();
-            FopImageFactory.resetCache();
-        } catch (Throwable t) {
-            String errMsg = "Unable to generate PDF from XSL-FO: " + t.toString();
-            Debug.logError(t, errMsg, module);
-            return ServiceUtil.returnError(errMsg);
+            fopFactory = ApacheFopFactory.instance();
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
+            TransformerFactory transFactory = TransformerFactory.newInstance();
+            Transformer transformer = transFactory.newTransformer();
+
+            // set the input source (XSL-FO) and generate the PDF
+            Reader reader = new StringReader(reportXmlDocument);
+            Source src = new StreamSource(reader);
+            
+            // load the FOP driver
+
+            // Get handler that is used in the generation process
+            Result res = new SAXResult(fop.getDefaultHandler());
+            
+            // read the XSL-FO XML into the W3 Document
+            
+            // Start XSLT transformation and FOP processing
+            transformer.transform(src, res);
+            // and generate the PDF
+            // We don't want to cache the images that get loaded by the FOP engine
+            fopFactory.getImageFactory().clearCaches();
+            
+        } catch (FOPException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (TransformerConfigurationException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (TransformerFactoryConfigurationError e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (TransformerException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
         }
+      
         
         /*
         // set the content type and length                    

Copied: incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.92.jar (from r481543, incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.20.5-complete.jar)
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.92.jar?view=diff&rev=481558&p1=incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.20.5-complete.jar&r1=481543&p2=incubator/ofbiz/trunk/framework/webapp/lib/barcode4j-fop-ext-0.92.jar&r2=481558
==============================================================================
Binary files - no diff available.

Copied: incubator/ofbiz/trunk/framework/webapp/lib/batik-all-1.6.jar (from r481543, incubator/ofbiz/trunk/framework/webapp/lib/batik.jar)
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/lib/batik-all-1.6.jar?view=diff&rev=481558&p1=incubator/ofbiz/trunk/framework/webapp/lib/batik.jar&r1=481543&p2=incubator/ofbiz/trunk/framework/webapp/lib/batik-all-1.6.jar&r2=481558
==============================================================================
Binary files - no diff available.

Copied: incubator/ofbiz/trunk/framework/webapp/lib/fop-0.92.jar (from r481543, incubator/ofbiz/trunk/framework/webapp/lib/fop.jar)
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/lib/fop-0.92.jar?view=diff&rev=481558&p1=incubator/ofbiz/trunk/framework/webapp/lib/fop.jar&r1=481543&p2=incubator/ofbiz/trunk/framework/webapp/lib/fop-0.92.jar&r2=481558
==============================================================================
Binary files - no diff available.

Added: incubator/ofbiz/trunk/framework/webapp/lib/xmlgraphics-commons-1.0.jar
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/lib/xmlgraphics-commons-1.0.jar?view=auto&rev=481558
==============================================================================
Binary file - no diff available.

Propchange: incubator/ofbiz/trunk/framework/webapp/lib/xmlgraphics-commons-1.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java?view=auto&rev=481558
==============================================================================
--- incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java (added)
+++ incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java Sat Dec  2 05:37:24 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 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. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.webapp.view;
+
+import org.apache.fop.apps.FopFactory;
+
+/**
+ * Apache FOP Factory used to provide a singleton instance of the FopFactory.  Best pratices recommended
+ * the reuse of the factory because of the startup time.
+ *
+ */
+
+public class ApacheFopFactory {
+
+    private static final FopFactory fopFactory;
+
+    static {
+        // Create the factory
+        fopFactory = FopFactory.newInstance();
+
+        // Limit the validation for backwards compatibility
+        fopFactory.setStrictValidation(false);
+    }
+
+    public static FopFactory instance() {
+        return fopFactory;
+    }
+
+}

Propchange: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/FopRenderer.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/FopRenderer.java?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/FopRenderer.java (original)
+++ incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/FopRenderer.java Sat Dec  2 05:37:24 2006
@@ -15,22 +15,21 @@
  */
 package org.ofbiz.webapp.view;
 
-import java.io.ByteArrayOutputStream;
-import java.io.Writer;
+import java.io.*;
 
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.logger.Log4JLogger;
-import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.tools.DocumentInputSource;
-import org.apache.fop.image.FopImageFactory;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FOPException;
 
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.GeneralException;
 
+import javax.xml.transform.*;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.Result;
+
 /**
  * FopRenderer
  */
@@ -38,50 +37,51 @@
 
     public static final String module = FopRenderer.class.getName();
 
+    /**
+     * Renders a PDF document from a FO script that is passed in and returns the content as a ByteArrayOutputStream
+     * @param writer    a Writer stream that supplies the FO text to be rendered
+     * @return  ByteArrayOutputStream containing the binary representation of a PDF document
+     * @throws GeneralException
+     */
     public static ByteArrayOutputStream render(Writer writer) throws GeneralException {
-        // configure logging for the FOP
-        Logger logger = new Log4JLogger(Debug.getLogger(module));
-        MessageHandler.setScreenLogger(logger);
-
-        // load the FOP driver
-        Driver driver = new Driver();
-        driver.setRenderer(Driver.RENDER_PDF);
-        driver.setLogger(logger);
 
-        /*
-        try {
-            String buf = writer.toString();
-            java.io.FileWriter fw = new java.io.FileWriter(new java.io.File("/tmp/xslfo.out"));
-            fw.write(buf.toString());
-            fw.close();
-        } catch (IOException e) {
-            throw new GeneralException("Unable write to browser OutputStream", e);
-        }
-        */
-
-        // read the XSL-FO XML Document
-        Document xslfo = null;
-        try {
-            xslfo = UtilXml.readXmlDocument(writer.toString());
-        } catch (Throwable t) {
-            throw new GeneralException("Problems reading the parsed content to XML Document", t);
-        }
+        FopFactory fopFactory = ApacheFopFactory.instance();
 
-        // create the output stream for the PDF
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        driver.setOutputStream(out);
 
-        // set the input source (XSL-FO) and generate the PDF
-        InputSource is = new DocumentInputSource(xslfo);
-        driver.setInputSource(is);
+        TransformerFactory transFactory = TransformerFactory.newInstance();
+
         try {
-            driver.run();
-            FopImageFactory.resetCache();
-        } catch (Throwable t) {
-            throw new GeneralException("Unable to generate PDF from XSL-FO", t);
-        }
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
+            Transformer transformer = transFactory.newTransformer();
 
-        return out;
+            // set the input source (XSL-FO) and generate the PDF
+            Reader reader = new StringReader(writer.toString());
+            Source src = new StreamSource(reader);
+
+            // Get handler that is used in the generation process
+            Result res = new SAXResult(fop.getDefaultHandler());
+
+            try {
+                // Transform the FOP XML source into a PDF, hopefully...
+                transformer.transform(src, res);
+
+                // We don't want to cache the images that get loaded by the FOP engine
+                fopFactory.getImageFactory().clearCaches();
+
+                return out;
+
+            } catch (TransformerException e) {
+                Debug.logError("FOP transform failed:" + e, module );
+                throw new GeneralException("Unable to transform FO to PDF", e);
+            }
+
+        } catch (TransformerConfigurationException e) {
+            Debug.logError("FOP TransformerConfiguration Exception " + e, module);
+            throw new GeneralException("Transformer Configuration Error", e);
+        } catch (FOPException e) {
+            Debug.logError("FOP Exception " + e, module);
+            throw new GeneralException("FOP Error", e);
+        }
     }
-
 }

Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java?view=diff&rev=481558&r1=481557&r2=481558
==============================================================================
--- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java (original)
+++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFopPdfViewHandler.java Sat Dec  2 05:37:24 2006
@@ -15,105 +15,114 @@
  */
 package org.ofbiz.widget.screen;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
+import java.io.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.*;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.FOPException;
 
-import org.apache.avalon.framework.logger.Log4JLogger;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.image.FopImageFactory;
-import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.tools.DocumentInputSource;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.webapp.view.ViewHandlerException;
+import org.ofbiz.webapp.view.ApacheFopFactory;
 import org.ofbiz.widget.fo.FoFormRenderer;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
 
 /**
  * Uses XSL-FO formatted templates to generate PDF views
  * This handler will use JPublish to generate the XSL-FO
  */
 public class ScreenFopPdfViewHandler extends ScreenWidgetViewHandler {
-    
     public static final String module = ScreenFopPdfViewHandler.class.getName();
-    
+
     /**
      * @see org.ofbiz.content.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
     public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {
-        // render and obtain the XSL-FO
+
+        // render and obtain the XSL-FO
         Writer writer = new StringWriter();
+
+        FopFactory fopFactory = ApacheFopFactory.instance();
+
         try {
             ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer);
             screens.populateContextForRequest(request, response, servletContext);
+
             // this is the object used to render forms from their definitions
             screens.getContext().put("formStringRenderer", new FoFormRenderer(request, response));
             screens.render(page);
         } catch (Throwable t) {
             throw new ViewHandlerException("Problems with the response writer/output stream", t);
         }
-        if (Debug.verboseOn()) {
-           // Debug.logVerbose("XSL-FO : " + writer.toString(), module);
-        }
-        
-        // configure logging for the FOP
-        Logger logger = new Log4JLogger(Debug.getLogger(module));
-        MessageHandler.setScreenLogger(logger);        
-                          
-        // load the FOP driver
-        Driver driver = new Driver();
-        driver.setRenderer(Driver.RENDER_PDF);
-        driver.setLogger(logger);
-                                        
-        /*
-        try {
-            String buf = writer.toString();
-            java.io.FileWriter fw = new java.io.FileWriter(new java.io.File("/tmp/xslfo.out"));
-            fw.write(buf.toString());
-            fw.close();
-        } catch (IOException e) {
-            throw new ViewHandlerException("Unable write to browser OutputStream", e);            
-        }                            
-        */
-        // read the XSL-FO XML Document
-        Document xslfo = null;
-        try {
-            xslfo = UtilXml.readXmlDocument(writer.toString());
-        } catch (Throwable t) {
-            throw new ViewHandlerException("Problems reading the parsed content to XML Document", t);
-        }
-        
-        // create the output stream for the PDF
+
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        driver.setOutputStream(out);    
-                
-        // set the input source (XSL-FO) and generate the PDF        
-        InputSource is = new DocumentInputSource(xslfo);              
-        driver.setInputSource(is);        
+
+        TransformerFactory transFactory = TransformerFactory.newInstance();
+
         try {
-            driver.run();
-            FopImageFactory.resetCache();
-        } catch (Throwable t) {
-            throw new ViewHandlerException("Unable to generate PDF from XSL-FO", t);
+            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
+            Transformer transformer = transFactory.newTransformer();
+
+            // set the input source (XSL-FO) and generate the PDF
+            Reader reader = new StringReader(writer.toString());
+            Source src = new StreamSource(reader);
+
+            /*
+            try {
+                String buf = writer.toString();
+                java.io.FileWriter fw = new java.io.FileWriter(new java.io.File("/tmp/xslfo.out"));
+                fw.write(buf.toString());
+                fw.close();
+            } catch (IOException e) {
+                throw new ViewHandlerException("Unable write to browser OutputStream", e);            
+            }                            
+            */
+            
+            // Get handler that is used in the generation process
+            Result res = new SAXResult(fop.getDefaultHandler());
+
+            try {
+                // Transform the FOP XML source into a PDF, hopefully...
+                transformer.transform(src, res);
+
+                // We don't want to cache the images that get loaded by the FOP engine
+                fopFactory.getImageFactory().clearCaches();
+
+                // set the content type and length
+                response.setContentType(MimeConstants.MIME_PDF);
+                response.setContentLength(out.size());
+
+                // write to the browser
+                try {
+                    out.writeTo(response.getOutputStream());
+                    response.getOutputStream().flush();
+                } catch (IOException e) {
+                    throw new ViewHandlerException("Unable write to browser OutputStream", e);
+                }
+
+            } catch (TransformerException e) {
+                Debug.logError("FOP transform failed:" + e, module );
+                throw new ViewHandlerException("Unable to transform FO to PDF", e);
+            }
+
+        } catch (TransformerConfigurationException e) {
+            Debug.logError("FOP TransformerConfiguration Exception " + e, module);
+            throw new ViewHandlerException("Transformer Configuration Error", e);
+        } catch (FOPException e) {
+            Debug.logError("FOP Exception " + e, module);
+            throw new ViewHandlerException("FOP Error", e);
+        } finally {
+            try {
+                out.close();
+            } catch (IOException e) {
+                Debug.logError("Unable to close output stream " + e, module);
+            }
         }
-                  
-        // set the content type and length                    
-        response.setContentType("application/pdf");        
-        response.setContentLength(out.size());
-        
-        // write to the browser
-        try {
-            out.writeTo(response.getOutputStream());
-            response.getOutputStream().flush();
-        } catch (IOException e) {
-            throw new ViewHandlerException("Unable write to browser OutputStream", e);            
-        }                            
     }
 }