From c47d87d3890cd6d6aab3d4ab4d09316f180b2ebe Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sun, 6 Dec 2015 17:22:56 -0500 Subject: [PATCH] IDEMPIERE-2640 Performance: Html/Tabular reports size could be reduced / IDEMPIERE-2355 Allow to style the summary rows of HTML report --- .../src/org/compiere/print/ReportEngine.java | 9 ++-- .../webui/desktop/DashboardController.java | 3 +- .../adempiere/webui/report/HTMLExtension.java | 48 ++++++++++++++++--- .../webui/window/ZkReportViewer.java | 7 +-- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 26a50e3c85..70c5e58287 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -16,9 +16,9 @@ *****************************************************************************/ package org.compiere.print; -import static org.compiere.model.SystemIDs.TABLE_AD_TABLE; import static org.compiere.model.SystemIDs.PROCESS_RPT_M_INVENTORY; import static org.compiere.model.SystemIDs.PROCESS_RPT_M_MOVEMENT; +import static org.compiere.model.SystemIDs.TABLE_AD_TABLE; import java.awt.Color; import java.awt.Font; @@ -807,14 +807,14 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) if (extension != null && extension.getStyleURL() != null) { // maybe cache style content with key is path - String pathStyleFile = extension.getFullPathStyle(); + String pathStyleFile = extension.getFullPathStyle(); // creates a temp file - delete below Path path = Paths.get(pathStyleFile); List styleLines = Files.readAllLines(path, Ini.getCharset()); + Files.delete(path); // delete temp file StringBuilder styleBuild = new StringBuilder(); for (String styleLine : styleLines){ - styleBuild.append(styleLine); + styleBuild.append(styleLine); //.append("\n"); } - appendInlineCss (doc, styleBuild); } if (extension != null && extension.getScriptURL() != null && !isExport) @@ -2092,4 +2092,5 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) return String.format(CSS_SELECTOR_TEMPLATE, index + 1); } } + } // ReportEngine diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index 832e6b3941..37175c593c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -798,8 +798,7 @@ public class DashboardController implements EventListener { Iframe iframe = new Iframe(); iframe.setSclass("dashboard-report-iframe"); File file = File.createTempFile(re.getName(), ".html"); - re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getDesktop().getWebApp().getRealPath("/"), - Executions.getCurrent().getContextPath(), "rp", + re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getContextPath(), "rp", SessionManager.getAppDesktop().getComponent().getUuid())); AMedia media = new AMedia(re.getName(), "html", "text/html", file, false); iframe.setContent(media); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/report/HTMLExtension.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/report/HTMLExtension.java index 52b16af718..3a1d3335ce 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/report/HTMLExtension.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/report/HTMLExtension.java @@ -13,6 +13,13 @@ *****************************************************************************/ package org.adempiere.webui.report; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.adempiere.exceptions.AdempiereException; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.theme.ThemeManager; import org.apache.ecs.ConcreteElement; @@ -36,9 +43,8 @@ public class HTMLExtension implements IHTMLExtension { private String componentId; private String scriptURL; private String styleURL; - private String contextFullPath; - public HTMLExtension(String contextFullPath, String contextPath, String classPrefix, String componentId) { + public HTMLExtension(String contextPath, String classPrefix, String componentId) { String theme = MSysConfig.getValue(MSysConfig.HTML_REPORT_THEME, "/", Env.getAD_Client_ID(Env.getCtx())); @@ -51,7 +57,6 @@ public class HTMLExtension implements IHTMLExtension { this.componentId = componentId; this.scriptURL = contextPath + theme + "js/report.js"; this.styleURL = contextPath + theme + "css/report.css"; - this.contextFullPath = contextFullPath; } public void extendIDColumn(int row, ConcreteElement columnElement, a href, @@ -94,15 +99,44 @@ public class HTMLExtension implements IHTMLExtension { } - public String getFullPathStyle (){ + public String getFullPathStyle() { String theme = MSysConfig.getValue(MSysConfig.HTML_REPORT_THEME, "/", Env.getAD_Client_ID(Env.getCtx())); - if (! theme.startsWith("/")) theme = "/" + theme; if (! theme.endsWith("/")) theme = theme + "/"; - - return contextFullPath + theme + "css/report.css"; + String resFile = theme + "css/report.css"; + URL urlFile = this.getClass().getResource(resFile); + if (urlFile == null) { + resFile = "/css/report.css"; // default + urlFile = this.getClass().getResource(resFile); + } + if (urlFile != null) { + FileOutputStream cssStream = null; + File cssFile = null; + try { + // copy the resource to a temporary file to process it with 2pack + InputStream stream = urlFile.openStream(); + cssFile = File.createTempFile("report", ".css"); + cssStream = new FileOutputStream(cssFile); + byte[] buffer = new byte[1024]; + int read; + while((read = stream.read(buffer)) != -1){ + cssStream.write(buffer, 0, read); + } + } catch (IOException e) { + throw new AdempiereException(e); + } finally{ + if (cssStream != null) { + try { + cssStream.close(); + } catch (Exception e2) {} + } + } + return cssFile.getAbsolutePath(); + } else { + return null; + } } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java index d097d5d39a..340a2587e8 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java @@ -1043,8 +1043,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab { StringWriter sw = new StringWriter(); String contextPath = Executions.getCurrent().getContextPath(); - String contextFullPath = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/"); - m_reportEngine.createHTML(sw, false, m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextFullPath, contextPath, "rp", this.getUuid()), true); + m_reportEngine.createHTML(sw, false, m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextPath, "rp", this.getUuid()), true); data = sw.getBuffer().toString().getBytes(); } else if (ext.equals("xls")) @@ -1424,13 +1423,11 @@ public class ZkReportViewer extends Window implements EventListener, ITab private ZkReportViewer viewer; private String contextPath; - private String contextFullPath; public HTMLRendererRunnable(ZkReportViewer viewer) { super(); this.viewer = viewer; contextPath = Executions.getCurrent().getContextPath(); - contextFullPath = Executions.getCurrent().getDesktop().getWebApp().getRealPath("/"); } @Override @@ -1445,7 +1442,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab log.log(Level.FINE, "Path="+path + " Prefix="+prefix); } File file = File.createTempFile(prefix, ".html", new File(path)); - viewer.m_reportEngine.createHTML(file, false, viewer.m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextFullPath, contextPath, "rp", viewer.getUuid())); + viewer.m_reportEngine.createHTML(file, false, viewer.m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextPath, "rp", viewer.getUuid())); viewer.media = new AMedia(file.getName(), "html", "text/html", file, false); } catch (Exception e) { if (e instanceof RuntimeException)