You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/03/23 07:49:52 UTC
svn commit: r521601 - in /ofbiz/trunk:
applications/content/src/org/ofbiz/content/print/PrintServices.java
framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java
Author: jacopoc
Date: Thu Mar 22 23:49:50 2007
New Revision: 521601
URL: http://svn.apache.org/viewvc?view=rev&rev=521601
Log:
This new version of the sendPrintFromScreen service is now working.
A lot of improvements can be done (in the way a printer is selected, in the printer options etc) but this is a good start.
Modified:
ofbiz/trunk/applications/content/src/org/ofbiz/content/print/PrintServices.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java
Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/print/PrintServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/print/PrintServices.java?view=diff&rev=521601&r1=521600&r2=521601
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/print/PrintServices.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/print/PrintServices.java Thu Mar 22 23:49:50 2007
@@ -32,6 +32,7 @@
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ServiceUtil;
import org.ofbiz.webapp.view.ApacheFopFactory;
+import org.ofbiz.widget.fo.FoFormRenderer;
import org.ofbiz.widget.html.HtmlScreenRenderer;
import org.ofbiz.widget.screen.ScreenRenderer;
import org.xml.sax.SAXException;
@@ -60,10 +61,12 @@
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.PrintRequestAttributeSet;
-import javax.print.attribute.HashPrintRequestAttributeSet;
+import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.HashPrintServiceAttributeSet;
import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.PrinterName;
import javax.print.attribute.standard.PrinterURI;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
@@ -86,7 +89,7 @@
public final static String module = PrintServices.class.getName();
protected static final HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer();
-
+ protected static final FoFormRenderer foFormRenderer = new FoFormRenderer();
public static Map sendPrintFromScreen(DispatchContext dctx, Map serviceContext) {
LocalDispatcher dispatcher = dctx.getDispatcher();
@@ -101,7 +104,7 @@
}
screenContext.put("locale", locale);
if (UtilValidate.isEmpty(contentType)) {
- contentType = "application/pdf";
+ contentType = "application/postscript";
}
try {
@@ -109,13 +112,12 @@
MapStack screenContextTmp = MapStack.create();
screenContextTmp.put("locale", locale);
-
Writer writer = new StringWriter();
// substitute the freemarker variables...
ScreenRenderer screensAtt = new ScreenRenderer(writer, screenContextTmp, htmlScreenRenderer);
screensAtt.populateContextForService(dctx, screenContext);
screenContextTmp.putAll(screenContext);
- //screensAtt.getContext().put("formStringRenderer", new org.ofbiz.widget.fo.FoFormRenderer());
+ screensAtt.getContext().put("formStringRenderer", foFormRenderer);
screensAtt.render(screenLocation);
// create the in/output stream for the generation
@@ -148,14 +150,31 @@
URI printerUri = new URI(printerName);
PrinterURI printerUriObj = new PrinterURI(printerUri);
psaset.add(printerUriObj);
- PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, psaset);
+ //PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, psaset); // TODO: selecting the printer by URI seems to not work
+ PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, null);
+ PrintService printer = null;
if (services.length > 0) {
+ String sPrinterName = null;
+ for (int i = 0; i < services.length; i++) {
+ PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
+ sPrinterName = ((PrinterName)attr).getValue();
+ if (sPrinterName.toLowerCase().indexOf(printerName.toLowerCase()) >= 0) {
+ printer = services[i];
+ Debug.logInfo("Printer with name [" + sPrinterName +"] selected", module);
+ break;
+ }
+ }
+ if (UtilValidate.isEmpty(printer)) {
+ printer = services[0];
+ }
+ }
+ if (UtilValidate.isNotEmpty(printer)) {
PrintRequestAttributeSet praset = new HashPrintRequestAttributeSet();
praset.add(new Copies(1));
- DocPrintJob job = services[0].createPrintJob();
+ DocPrintJob job = printer.createPrintJob();
job.print(myDoc, praset);
} else {
- String errMsg = "No printer found";
+ String errMsg = "No printer found with name: " + printerName;
Debug.logError(errMsg, module);
return ServiceUtil.returnError(errMsg);
}
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java?view=diff&rev=521601&r1=521600&r2=521601
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java Thu Mar 22 23:49:50 2007
@@ -62,7 +62,7 @@
HttpServletRequest request;
HttpServletResponse response;
- protected FoFormRenderer() {}
+ public FoFormRenderer() {}
public FoFormRenderer(HttpServletRequest request, HttpServletResponse response) {
this.request = request;