IDEMPIERE-5225 - HTML Report minification (#1237)

* IDEMPIERE-5225 - HTML Report minification

* IDEMPIERE-5225 - SysConfig added

* IDEMPIERE-5225 - minification default set to true
This commit is contained in:
PeterTakacs300 2022-03-17 15:36:02 +01:00 committed by GitHub
parent 38fd810122
commit ccda5e4495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 28 deletions

View File

@ -0,0 +1,10 @@
-- IDEMPIERE-5225
SELECT register_migration_script('202203161513_IDEMPIERE-5225.sql') FROM dual;
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Mar 16, 2022, 3:13:31 PM CET
INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200197,0,0,TO_TIMESTAMP('2022-03-16 15:13:30','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2022-03-16 15:13:30','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','HTML_REPORT_MINIFY','Y','Enable/disable minification on HTML Reports','D','C','9f3e162c-653e-4f45-9b1c-8151caf0945e')
;

View File

@ -0,0 +1,7 @@
-- IDEMPIERE-5225
SELECT register_migration_script('202203161513_IDEMPIERE-5225.sql') FROM dual;
-- Mar 16, 2022, 3:13:31 PM CET
INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200197,0,0,TO_TIMESTAMP('2022-03-16 15:13:30','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2022-03-16 15:13:30','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','HTML_REPORT_MINIFY','Y','Enable/disable minification on HTML Reports','D','C','9f3e162c-653e-4f45-9b1c-8151caf0945e')
;

View File

@ -7,7 +7,9 @@ Bundle-ClassPath: .,
lib/bsh.jar, lib/bsh.jar,
lib/commons-validator.jar, lib/commons-validator.jar,
lib/cron4j.jar, lib/cron4j.jar,
lib/avalon-framework-api.jar lib/avalon-framework-api.jar,
lib/htmlcompressor.jar,
lib/yuicompressor.jar
Export-Package: bsh, Export-Package: bsh,
bsh.classpath, bsh.classpath,
bsh.collection, bsh.collection,

View File

@ -6,7 +6,9 @@ bin.includes = plugin.xml,\
lib/avalon-framework-api.jar,\ lib/avalon-framework-api.jar,\
lib/bsh.jar,\ lib/bsh.jar,\
lib/commons-validator.jar,\ lib/commons-validator.jar,\
lib/cron4j.jar lib/cron4j.jar,\
lib/htmlcompressor.jar,\
lib/yuicompressor.jar
src.includes = schema/ src.includes = schema/
source.. = src/ source.. = src/
output.. = target/classes/ output.. = target/classes/

View File

@ -43,6 +43,16 @@
<artifactId>avalon-framework-api</artifactId> <artifactId>avalon-framework-api</artifactId>
<version>4.3.1</version> <version>4.3.1</version>
</artifactItem> </artifactItem>
<artifactItem>
<groupId>com.googlecode.htmlcompressor</groupId>
<artifactId>htmlcompressor</artifactId>
<version>1.5.2</version>
</artifactItem>
<artifactItem>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.8</version>
</artifactItem>
</artifactItems> </artifactItems>
<outputDirectory>lib</outputDirectory> <outputDirectory>lib</outputDirectory>
<stripVersion>true</stripVersion> <stripVersion>true</stripVersion>

View File

@ -101,6 +101,7 @@ public class MSysConfig extends X_AD_SysConfig
public static final String FEEDBACK_EMAIL_CC = "FEEDBACK_EMAIL_CC"; public static final String FEEDBACK_EMAIL_CC = "FEEDBACK_EMAIL_CC";
public static final String FEEDBACK_EMAIL_TO = "FEEDBACK_EMAIL_TO"; public static final String FEEDBACK_EMAIL_TO = "FEEDBACK_EMAIL_TO";
public static final String GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS = "GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS"; public static final String GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS = "GRIDTABLE_LOAD_TIMEOUT_IN_SECONDS";
public static final String HTML_REPORT_MINIFY = "HTML_REPORT_MINIFY";
public static final String HTML_REPORT_THEME = "HTML_REPORT_THEME"; public static final String HTML_REPORT_THEME = "HTML_REPORT_THEME";
public static final String IBAN_VALIDATION = "IBAN_VALIDATION"; public static final String IBAN_VALIDATION = "IBAN_VALIDATION";
public static final String IDENTIFIER_SEPARATOR = "IDENTIFIER_SEPARATOR"; public static final String IDENTIFIER_SEPARATOR = "IDENTIFIER_SEPARATOR";

View File

@ -113,6 +113,8 @@ import org.compiere.util.Util;
import org.eevolution.model.MDDOrder; import org.eevolution.model.MDDOrder;
import org.eevolution.model.X_PP_Order; import org.eevolution.model.X_PP_Order;
import com.googlecode.htmlcompressor.compressor.HtmlCompressor;
/** /**
* Report Engine. * Report Engine.
* For a given PrintFormat, * For a given PrintFormat,
@ -695,9 +697,10 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
table.setNeedClosingTag(false); table.setNeedClosingTag(false);
PrintWriter w = new PrintWriter(writer); PrintWriter w = new PrintWriter(writer);
XhtmlDocument doc = null; XhtmlDocument doc = null;
boolean minify = MSysConfig.getBooleanValue(MSysConfig.HTML_REPORT_MINIFY, true, Env.getAD_Client_ID(getCtx()));
if (onlyTable) if (onlyTable)
table.output(w); w.print(compress(table.toString(), minify));
else else
{ {
doc = new XhtmlDocument(); doc = new XhtmlDocument();
@ -785,14 +788,14 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
styleBuild = new StringBuilder(styleBuild.toString().replaceAll(";", "!important;")); styleBuild = new StringBuilder(styleBuild.toString().replaceAll(";", "!important;"));
appendInlineCss (doc, styleBuild); appendInlineCss (doc, styleBuild);
doc.output(w); w.print(compress(doc.toString(), minify));
w.println("<div class='"+cssPrefix+"-flex-container'>"); w.print("<div class='"+cssPrefix+"-flex-container'>");
String paraWrapId = null; String paraWrapId = null;
if (parameterTable != null) { if (parameterTable != null) {
paraWrapId = cssPrefix + "-para-table-wrap"; paraWrapId = cssPrefix + "-para-table-wrap";
w.println("<div id='" + paraWrapId + "'>"); w.print("<div id='" + paraWrapId + "'>");
parameterTable.output(w); w.print(compress(parameterTable.toString(), minify));
tr tr = new tr(); tr tr = new tr();
tr.setClass("tr-parameter"); tr.setClass("tr-parameter");
@ -825,12 +828,11 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
tr.addElement(td); tr.addElement(td);
td.addElement(query.getInfoDisplayAll(r)); td.addElement(query.getInfoDisplayAll(r));
tr.output(w); w.print(compress(tr.toString(), minify));
} }
w.println(); w.print("</table>");
w.println("</table>"); w.print("</div>");
w.println("</div>");
} }
StringBuilder tableWrapDiv = new StringBuilder(); StringBuilder tableWrapDiv = new StringBuilder();
@ -842,8 +844,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
} }
tableWrapDiv.append(" >"); tableWrapDiv.append(" >");
w.println(tableWrapDiv.toString()); w.print(compress(tableWrapDiv.toString(), minify));
table.output(w); w.print(compress(table.toString(), minify));
} }
thead thead = new thead(); thead thead = new thead();
@ -1089,19 +1091,18 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
/* output table header */ /* output table header */
if (row == -1){ if (row == -1){
thead.output(w); w.print(compress(thead.toString(), minify));
// output open of tbody // output open of tbody
tbody.output(w); w.print(compress(tbody.toString(), minify));
}else{ }else{
// output row by row // output row by row
tr.output(w); w.print(compress(tr.toString(), minify));
} }
} // for all rows } // for all rows
w.println(); w.print("</tbody>");
w.println("</tbody>"); w.print("</table>");
w.println("</table>");
if (suppressMap.size() > 0) if (suppressMap.size() > 0)
{ {
StringBuilder st = new StringBuilder(); StringBuilder st = new StringBuilder();
@ -1114,15 +1115,14 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
st.append(" {\n\t\tdisplay:none;\n\t}"); st.append(" {\n\t\tdisplay:none;\n\t}");
style styleTag = new style(); style styleTag = new style();
styleTag.addElement(st.toString()); styleTag.addElement(st.toString());
styleTag.output(w); w.print(compress(styleTag.toString(), minify));
w.println();
} }
if (!onlyTable) if (!onlyTable)
{ {
w.println("</div>"); w.print("</div>");
w.println("</div>"); w.print("</div>");
w.println("</body>"); w.print("</body>");
w.println("</html>"); w.print("</html>");
} }
w.flush(); w.flush();
w.close(); w.close();
@ -2577,4 +2577,34 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
return Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), item.getDisplayLogic()); return Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), item.getDisplayLogic());
} }
public String compress(String src, boolean minify) {
if(minify) {
HtmlCompressor compressor = new HtmlCompressor();
compressor.setEnabled(true);
compressor.setCompressCss(true);
compressor.setCompressJavaScript(true);
compressor.setRemoveComments(true);
compressor.setRemoveMultiSpaces(true);
compressor.setRemoveIntertagSpaces(true);
// compressor.setGenerateStatistics(false);
// compressor.setRemoveQuotes(false);
// compressor.setSimpleDoctype(false);
// compressor.setRemoveScriptAttributes(false);
// compressor.setRemoveStyleAttributes(false);
// compressor.setRemoveLinkAttributes(false);
// compressor.setRemoveFormAttributes(false);
// compressor.setRemoveInputAttributes(false);
// compressor.setSimpleBooleanAttributes(false);
// compressor.setRemoveJavaScriptProtocol(false);
// compressor.setRemoveHttpProtocol(false);
// compressor.setRemoveHttpsProtocol(false);
// compressor.setPreserveLineBreaks(false);
return compressor.compress(src);
}
else {
return src;
}
}
} // ReportEngine } // ReportEngine