[OFBiz] SVN: r6550 - in trunk/framework/webtools: . src/org/ofbiz/webtools/print/applet src/org/ofbiz/webtools/print/rmi webapp/webtools/print

jaz@svn.ofbiz.org jaz at svn.ofbiz.org
Mon Jan 23 01:37:46 CST 2006


Author: jaz
Date: 2006-01-23 01:37:42 -0600 (Mon, 23 Jan 2006)
New Revision: 6550

Modified:
   trunk/framework/webtools/build.xml
   trunk/framework/webtools/src/org/ofbiz/webtools/print/applet/PdfPrintApplet.java
   trunk/framework/webtools/src/org/ofbiz/webtools/print/rmi/FopPrintRemoteImpl.java
   trunk/framework/webtools/webapp/webtools/print/printStart.ftl
Log:
fixed multiple screen printing problems; changed to not use FOPRender due to problems (will trace down later)


Modified: trunk/framework/webtools/build.xml
===================================================================
--- trunk/framework/webtools/build.xml	2006-01-23 07:37:03 UTC (rev 6549)
+++ trunk/framework/webtools/build.xml	2006-01-23 07:37:42 UTC (rev 6550)
@@ -52,6 +52,7 @@
             <fileset dir="../service/lib" includes="*.jar"/>
             <fileset dir="../service/build/lib" includes="*.jar"/>
             <fileset dir="../minilang/build/lib" includes="*.jar"/>
+            <fileset dir="../webapp/lib" includes="*.jar"/>
             <fileset dir="../webapp/build/lib" includes="*.jar"/>
             <fileset dir="../widget/build/lib" includes="*.jar"/>
         </path>

Modified: trunk/framework/webtools/src/org/ofbiz/webtools/print/applet/PdfPrintApplet.java
===================================================================
--- trunk/framework/webtools/src/org/ofbiz/webtools/print/applet/PdfPrintApplet.java	2006-01-23 07:37:03 UTC (rev 6549)
+++ trunk/framework/webtools/src/org/ofbiz/webtools/print/applet/PdfPrintApplet.java	2006-01-23 07:37:42 UTC (rev 6550)
@@ -250,10 +250,12 @@
             buf.append(count);
             buf.append("=");
             buf.append(URLEncoder.encode(printer, "UTF-8"));
+            count++;
         }
 
         String path = "/webtools/control/printComplete?" + buf.toString();
         URL url = new URL(serverUrl + path);
+        System.out.println("Returning complete: " + url.toExternalForm());
         this.getAppletContext().showDocument(url);
     }
 

Modified: trunk/framework/webtools/src/org/ofbiz/webtools/print/rmi/FopPrintRemoteImpl.java
===================================================================
--- trunk/framework/webtools/src/org/ofbiz/webtools/print/rmi/FopPrintRemoteImpl.java	2006-01-23 07:37:03 UTC (rev 6549)
+++ trunk/framework/webtools/src/org/ofbiz/webtools/print/rmi/FopPrintRemoteImpl.java	2006-01-23 07:37:42 UTC (rev 6550)
@@ -32,13 +32,21 @@
 import java.rmi.server.RMIClientSocketFactory;
 import java.rmi.server.RMIServerSocketFactory;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.Locale;
 import java.util.Map;
-import java.util.Locale;
 
-import org.ofbiz.base.util.GeneralException;
+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.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.service.DispatchContext;
-import org.ofbiz.webapp.view.FopRenderer;
 import org.ofbiz.widget.html.HtmlScreenRenderer;
 import org.ofbiz.widget.screen.ScreenRenderer;
 
@@ -72,25 +80,52 @@
         }
 
         Debug.log("Attempt to render screen [" + screenUri + "] using parameters: " + parameters, module);
+        return render(screenUri, parameters);
 
+    }
+
+    public byte[] render(String screen, Map parameters) throws RemoteException {
         // render and obtain the XSL-FO
         Writer writer = new StringWriter();
         try {
             ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer);
             screens.populateContextForService(dctx, parameters);
-            screens.render(screenUri);
+            screens.render(screen);
         } catch (Throwable t) {
             throw new RemoteException("Problems with the response writer/output stream", t);
         }
 
-        // render the byte array
-        ByteArrayOutputStream out = null;
+        // 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 {
-            out = FopRenderer.render(writer);
-        } catch (GeneralException e) {
-            throw new RemoteException(e.getMessage(), e.getNested());
+            xslfo = UtilXml.readXmlDocument(writer.toString());
+        } catch (Throwable t) {
+            throw new RemoteException("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);
+        try {
+            driver.run();
+            FopImageFactory.resetCache();
+        } catch (Throwable t) {
+            throw new RemoteException("Unable to generate PDF from XSL-FO", t);
+        }
+
         byte[] bytes = out.toByteArray();
         try {
             out.close();

Modified: trunk/framework/webtools/webapp/webtools/print/printStart.ftl
===================================================================
--- trunk/framework/webtools/webapp/webtools/print/printStart.ftl	2006-01-23 07:37:03 UTC (rev 6549)
+++ trunk/framework/webtools/webapp/webtools/print/printStart.ftl	2006-01-23 07:37:42 UTC (rev 6550)
@@ -30,7 +30,6 @@
 <#assign screenMap = (requestAttributes.screenPrinterMap)?if_exists>
 <#assign screens = (screenMap.keySet())?if_exists>
 <#assign auto = "true">
-<#assign count = 1>
 <html>
     <body>
       <center>
@@ -38,6 +37,7 @@
         <object align="center" height="200" width="600" classid="java:org.ofbiz.webtools.print.applet.PdfPrintApplet"
                 type="application/x-java-applet" mayscript="true" archive="/webtools/applet/ofbiz-webtools-print.jar, /webtools/applet/14_os_jpedal.jar"
                 codebase="/webtools/applet" server-url= "${serverRoot}" rmi-name="RMIFopPrintServer" rmi-host="${serverHost}" rmi-port="1099"
+                <#assign count = 1>
                 <#list screens as screen>
                   <#assign printer = screenMap.get(screen)?if_exists>
                   <#if printer?has_content>
@@ -46,6 +46,7 @@
                     <#assign auto = "false">
                   </#if>
                   screen.${count}="${screen}"
+                  <#assign count = count + 1>
                 </#list>>
 
             <object align="center" height="200" width="600" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93">
@@ -57,6 +58,7 @@
                 <param name="rmi-name" value="RMIFopPrintServer">
                 <param name="rmi-host" value="${serverHost}">
                 <param name="rmi-port" value="1099">
+                <#assign count = 1>
                 <#list screens as screen>
                   <#assign printer = screenMap.get(screen)?if_exists>
                   <#if printer?has_content>
@@ -65,7 +67,7 @@
                     <#assign auto = "false">
                   </#if>
                   <param name="screen.${count}" value="${screen}">
-
+                  <#assign count = count + 1>
                 </#list>
             </object>
         </object>



More information about the Svn mailing list