ItEr42S15SoporteImpresionMultiplesPaxinasItEr41S18: Generalized parameters configuration in print view and updated CutyCapt path to packaged destination

This commit is contained in:
Lorenzo Tilve 2010-01-08 14:34:41 +01:00 committed by Javier Moran Rua
parent 5ae1ea2622
commit 8e741cabe4
3 changed files with 104 additions and 76 deletions

View file

@ -96,7 +96,7 @@ tool and a lightweight X server must be installed.
The capturing tool is CutyCapt [1], which has to be either compiled or installed from
an external package. Once compiled from the tarball the binary CutyCapt must be located
under /usr/local/bin/ to be available to the application.
under /usr/bin/ to be available to the application.
X virtual framebuffer xvfb[2] package needs to be installed for the application running on
a non-desktop server is capable of launching an X instance to create the print capture of

View file

@ -22,18 +22,11 @@ package org.zkoss.ganttz;
import static org.zkoss.ganttz.i18n.I18nHelper._;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.zkoss.ganttz.adapters.IDisabilityConfiguration;
import org.zkoss.ganttz.adapters.PlannerConfiguration;
import org.zkoss.ganttz.data.Dependency;
@ -44,8 +37,7 @@ import org.zkoss.ganttz.data.GanttDiagramGraph.IGraphChangeListener;
import org.zkoss.ganttz.extensions.ICommand;
import org.zkoss.ganttz.extensions.ICommandOnTask;
import org.zkoss.ganttz.extensions.IContext;
import org.zkoss.ganttz.servlets.CallbackServlet;
import org.zkoss.ganttz.servlets.CallbackServlet.IServletRequestHandler;
import org.zkoss.ganttz.print.CutyPrint;
import org.zkoss.ganttz.timetracker.TimeTracker;
import org.zkoss.ganttz.timetracker.TimeTrackerComponent;
import org.zkoss.ganttz.timetracker.TimeTrackerComponentWithoutColumns;
@ -66,12 +58,6 @@ import org.zkoss.zul.api.Button;
public class Planner extends HtmlMacroComponent {
// Read path and Xvfb port from properties file
private static final String CUTYCAPT_COMMAND = "/usr/local/bin/CutyCapt ";
// Calculate dynamically width and delay parameters
private static final String CUTYCAPT_PARAMETERS = " --min-width=2500 --delay=1000 ";
public static void registerNeededScripts() {
IScriptsRegister register = getScriptsRegister();
register.register(ScriptsRequiredByPlanner.class);
@ -407,66 +393,7 @@ public class Planner extends HtmlMacroComponent {
public void print() {
// Pending to raise print configuration popup
HttpServletRequest request = (HttpServletRequest) Executions
.getCurrent().getNativeRequest();
String url = CallbackServlet.registerAndCreateURLFor(request,
new IServletRequestHandler() {
@Override
public void handle(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String forwardURL = "/planner/index.zul";
String orderId = request.getParameter("order");
if ((orderId != null) && !(orderId.equals(""))) {
forwardURL += ";order=" + orderId;
}
// Pending to forward and process additional parameters
// as show labels or resources
request.getRequestDispatcher(forwardURL).forward(
request, response);
}
});
String CUTYCAPT_URL = "--url=http://localhost:8080" + url;
String captureString = CUTYCAPT_COMMAND + CUTYCAPT_URL;
captureString += CUTYCAPT_PARAMETERS;
String absolutePath = request.getSession().getServletContext()
.getRealPath("/");
String filename = "/print/"
+ new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
+ ".pdf";
captureString += "--out=" + absolutePath + filename;
try {
// CutyCapt command execution
// If there is a not real X server environment, use framebuffer
String[] serverEnvironment = { "PATH=$PATH" };
Process server = Runtime.getRuntime().exec("env - Xvfb :99",
serverEnvironment);
String[] environment = { "DISPLAY=:99.0" };
Process p = Runtime.getRuntime().exec(captureString, environment);
System.out.println(captureString);
try {
p.waitFor();
p.destroy();
server.destroy();
Executions.getCurrent().sendRedirect(filename, "_blank");
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
CutyPrint.print();
}
}

View file

@ -0,0 +1,101 @@
package org.zkoss.ganttz.print;
import static org.zkoss.ganttz.i18n.I18nHelper._;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.zkoss.ganttz.servlets.CallbackServlet;
import org.zkoss.ganttz.servlets.CallbackServlet.IServletRequestHandler;
import org.zkoss.zk.ui.Executions;
public class CutyPrint {
private static final Log LOG = LogFactory.getLog(CutyPrint.class);
private static final String CUTYCAPT_COMMAND = "/usr/bin/CutyCapt ";
// Calculate dynamically width and delay parameters
private static final String CUTYCAPT_PARAMETERS = " --min-width=2500 --delay=1000 ";
public static void print() {
HttpServletRequest request = (HttpServletRequest) Executions
.getCurrent().getNativeRequest();
String url = CallbackServlet.registerAndCreateURLFor(request,
new IServletRequestHandler() {
@Override
public void handle(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String forwardURL = "/planner/index.zul";
String orderId = request.getParameter("order");
if ((orderId != null) && !(orderId.equals(""))) {
forwardURL += ";order=" + orderId;
}
// Pending to forward and process additional parameters
// as show labels or resources
request.getRequestDispatcher(forwardURL).forward(
request, response);
}
});
String CUTYCAPT_URL = "--url=http://" + request.getLocalName() + ":"
+ request.getLocalPort() + url;
String captureString = CUTYCAPT_COMMAND + CUTYCAPT_URL;
captureString += CUTYCAPT_PARAMETERS;
String absolutePath = request.getSession().getServletContext()
.getRealPath("/");
String filename = "/print/"
+ new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
+ ".pdf";
captureString += "--out=" + absolutePath + filename;
try {
// CutyCapt command execution
// If there is a not real X server environment, use framebuffer
LOG.debug(captureString);
Process print;
Process server = null;
if ((System.getenv("DISPLAY") == null)
|| (System.getenv("DISPLAY").equals(""))) {
String[] serverEnvironment = { "PATH=$PATH" };
server = Runtime.getRuntime().exec("env - Xvfb :99",
serverEnvironment);
String[] environment = { "DISPLAY=:99.0" };
print = Runtime.getRuntime().exec(captureString, environment);
} else {
print = Runtime.getRuntime().exec(captureString);
}
try {
print.waitFor();
print.destroy();
if ((System.getenv("DISPLAY") == null)
|| (System.getenv("DISPLAY").equals(""))) {
server.destroy();
}
Executions.getCurrent().sendRedirect(filename, "_blank");
} catch (InterruptedException e) {
LOG.error(_("Could open generated PDF"), e);
}
} catch (IOException e) {
LOG.error(_("Could not execute print command"), e);
}
}
}