IDEMPIERE-2640:Performance: Html/Tabular reports size could be reduced

step3: include css content into report
This commit is contained in:
hieplq 2015-07-03 00:08:34 +07:00
parent e8fadaefbc
commit 03f649f75e
5 changed files with 40 additions and 5 deletions

View File

@ -35,4 +35,6 @@ public interface IHTMLExtension {
public void extendIDColumn(int row, ConcreteElement columnElement, a href, PrintDataElement dataElement);
public void setWebAttribute (body reportBody);
public String getFullPathStyle ();
}

View File

@ -23,12 +23,16 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -764,8 +768,16 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
doc.appendBody(table);
if (extension != null && extension.getStyleURL() != null)
{
link l = new link(extension.getStyleURL(), "stylesheet", "text/css");
doc.appendHead(l);
// maybe cache style content with key is path
String pathStyleFile = extension.getFullPathStyle();
Path path = Paths.get(pathStyleFile);
List<String> styleLines = Files.readAllLines(path, Ini.getCharset());
StringBuilder styleBuild = new StringBuilder();
for (String styleLine : styleLines){
styleBuild.append(styleLine);
}
appendInlineCss (doc, styleBuild);
}
if (extension != null && extension.getScriptURL() != null)
{
@ -1816,6 +1828,10 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
buildCssInline.append("\n");
}
appendInlineCss (doc, buildCssInline);
}
public void appendInlineCss (XhtmlDocument doc, StringBuilder buildCssInline){
if (buildCssInline.length() > 0){
buildCssInline.insert(0, "<style>");
buildCssInline.append("</style>");

View File

@ -798,7 +798,8 @@ public class DashboardController implements EventListener<Event> {
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().getContextPath(), "rp",
re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getDesktop().getWebApp().getRealPath("/"),
Executions.getCurrent().getContextPath(), "rp",
SessionManager.getAppDesktop().getComponent().getUuid()));
AMedia media = new AMedia(re.getName(), "html", "text/html", file, false);
iframe.setContent(media);

View File

@ -36,8 +36,9 @@ public class HTMLExtension implements IHTMLExtension {
private String componentId;
private String scriptURL;
private String styleURL;
private String contextFullPath;
public HTMLExtension(String contextPath, String classPrefix, String componentId) {
public HTMLExtension(String contextFullPath, String contextPath, String classPrefix, String componentId) {
String theme = MSysConfig.getValue(MSysConfig.HTML_REPORT_THEME, "/", Env.getAD_Client_ID(Env.getCtx()));
@ -50,6 +51,7 @@ 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,
@ -91,4 +93,16 @@ public class HTMLExtension implements IHTMLExtension {
reportBody.addAttribute ("windowLabel", Msg.getMsg(AEnv.getLanguage(Env.getCtx()), "Window"));
}
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";
}
}

View File

@ -1422,11 +1422,13 @@ public class ZkReportViewer extends Window implements EventListener<Event>, 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
@ -1441,7 +1443,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, 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(contextPath, "rp", viewer.getUuid()));
viewer.m_reportEngine.createHTML(file, false, viewer.m_reportEngine.getPrintFormat().getLanguage(), new HTMLExtension(contextFullPath, contextPath, "rp", viewer.getUuid()));
viewer.media = new AMedia(file.getName(), "html", "text/html", file, false);
} catch (Exception e) {
if (e instanceof RuntimeException)