This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch feature/WW-5256-compress in repository https://gitbox.apache.org/repos/asf/struts.git
commit 328e4d2dba281fb0afd3bb58ca832e9139b72dcb Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Sun Jul 14 16:13:04 2024 +0200 WW-5256 Improves html rendering by using compress directive --- .../components/template/FreemarkerTemplateEngine.java | 7 +++++++ core/src/main/resources/template/css_xhtml/checkbox.ftl | 2 ++ .../main/resources/template/css_xhtml/controlfooter.ftl | 15 +++++++-------- .../resources/template/css_xhtml/controlheader-core.ftl | 2 ++ .../main/resources/template/css_xhtml/controlheader.ftl | 2 ++ .../main/resources/template/css_xhtml/form-validate.ftl | 12 +++++++----- core/src/main/resources/template/css_xhtml/head.ftl | 6 ++++-- core/src/main/resources/template/css_xhtml/label.ftl | 3 ++- core/src/main/resources/template/css_xhtml/reset.ftl | 3 ++- .../main/resources/template/css_xhtml/submit-close.ftl | 2 ++ core/src/main/resources/template/css_xhtml/submit.ftl | 2 ++ core/src/main/resources/template/simple/actionerror.ftl | 14 +++++++------- .../resources/template/simple/form-close-tooltips.ftl | 3 ++- core/src/main/resources/template/simple/form-close.ftl | 4 ++-- core/src/main/resources/template/simple/form.ftl | 4 +++- core/src/main/resources/template/xhtml/controlfooter.ftl | 2 +- .../main/resources/template/xhtml/form-close-validate.ftl | 2 ++ core/src/main/resources/template/xhtml/form-validate.ftl | 14 ++++++++------ 18 files changed, 64 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java b/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java index 99c1d4797..e5cb0a11d 100644 --- a/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java +++ b/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java @@ -34,6 +34,7 @@ import org.apache.logging.log4j.Logger; import org.apache.struts2.views.freemarker.FreemarkerManager; import java.io.IOException; +import java.io.StringWriter; import java.io.Writer; import java.util.List; @@ -125,6 +126,12 @@ public class FreemarkerTemplateEngine extends BaseTemplateEngine { } SimpleHash model = freemarkerManager.buildTemplateModel(stack, action, servletContext, req, res, config.getObjectWrapper()); + if (LOG.isTraceEnabled()){ + StringWriter writer = new StringWriter(); + template.dump(writer); + LOG.trace("Template dumped:\n{}", writer); + } + model.put("tag", templateContext.getTag()); model.put("themeProperties", getThemeProps(templateContext.getTemplate())); diff --git a/core/src/main/resources/template/css_xhtml/checkbox.ftl b/core/src/main/resources/template/css_xhtml/checkbox.ftl index ba5784e75..24d580222 100644 --- a/core/src/main/resources/template/css_xhtml/checkbox.ftl +++ b/core/src/main/resources/template/css_xhtml/checkbox.ftl @@ -23,6 +23,7 @@ NOTE: The 'header' stuff that follows is in this one file for checkbox due to th that for checkboxes we do not want the label field to show up as checkboxes handle their own lables --> +<@compress single_line=true> <#assign hasFieldErrors = fieldErrors?? && fieldErrors.get(attributes.name)??/> <div <#rt/><#if attributes.id??>id="wwgrp_${attributes.id}"<#rt/></#if> class="wwgrp"> @@ -105,3 +106,4 @@ lables </#if> </#if> </div> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/controlfooter.ftl b/core/src/main/resources/template/css_xhtml/controlfooter.ftl index d25b5790c..5ad26904a 100644 --- a/core/src/main/resources/template/css_xhtml/controlfooter.ftl +++ b/core/src/main/resources/template/css_xhtml/controlfooter.ftl @@ -18,8 +18,8 @@ * under the License. */ --> +<@compress single_line=true> ${attributes.after!}<#t/> - <#lt/> <#if !attributes.labelPosition?? && (attributes.form.labelPosition)??> <#assign labelPos = attributes.form.labelPosition/> <#elseif attributes.labelPosition??> @@ -35,15 +35,14 @@ ${attributes.after!}<#t/> <#if hasFieldErrors> <div <#rt/><#if attributes.id??>id="wwerr_${attributes.id}"<#rt/></#if> class="wwerr"> <#list fieldErrors.get(attributes.name) as error> - <div<#rt/> - <#if attributes.id??> - errorFor="${attributes.id}"<#rt/> - </#if> - class="errorMessage"> - ${error} - </div><#t/> +<div<#rt/> + <#if attributes.id??> + errorFor="${attributes.id}"<#rt/> + </#if> + class="errorMessage">${error}</div><#t/> </#list> </div><#t/> </#if> </#if> </div> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/controlheader-core.ftl b/core/src/main/resources/template/css_xhtml/controlheader-core.ftl index 206b638e8..42c920225 100644 --- a/core/src/main/resources/template/css_xhtml/controlheader-core.ftl +++ b/core/src/main/resources/template/css_xhtml/controlheader-core.ftl @@ -22,6 +22,7 @@ Only show message if errors are available. This will be done if ActionSupport is used. --> +<@compress single_line=true> <#assign hasFieldErrors = attributes.name?? && fieldErrors?? && fieldErrors.get(attributes.name)??/> <div <#rt/><#if attributes.id??>id="wwgrp_${attributes.id}"<#rt/></#if> class="wwgrp"> @@ -75,3 +76,4 @@ </span> <#rt/> </#if> </#if> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/controlheader.ftl b/core/src/main/resources/template/css_xhtml/controlheader.ftl index f76a9459b..cc253bffd 100644 --- a/core/src/main/resources/template/css_xhtml/controlheader.ftl +++ b/core/src/main/resources/template/css_xhtml/controlheader.ftl @@ -18,6 +18,7 @@ * under the License. */ --> +<@compress single_line=true> <#include "/${attributes.templateDir}/${attributes.expandTheme}/controlheader-core.ftl"> <#if !attributes.labelPosition?? && (attributes.form.labelPosition)??> <#assign labelPos = attributes.form.labelPosition/> @@ -30,3 +31,4 @@ <span <#rt/> </#if> <#if attributes.id??>id="wwctrl_${attributes.id}"<#rt/></#if> class="wwctrl"> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/form-validate.ftl b/core/src/main/resources/template/css_xhtml/form-validate.ftl index 7beb7fab5..22fe80f20 100644 --- a/core/src/main/resources/template/css_xhtml/form-validate.ftl +++ b/core/src/main/resources/template/css_xhtml/form-validate.ftl @@ -18,11 +18,13 @@ * under the License. */ --> +<@compress single_line=true> <#if attributes.validate!false == true> <@s.script src="${base}${attributes.staticContentPath}/css_xhtml/validation.js"/> - <#if attributes.onsubmit??> - ${tag.addParameter('onsubmit', "${attributes.onsubmit}; return validateForm_${attributes.escapedId}();")} - <#else> - ${tag.addParameter('onsubmit', "return validateForm_${attributes.escapedId}();")} - </#if> +<#if attributes.onsubmit??> + ${tag.addParameter('onsubmit', "${attributes.onsubmit}; return validateForm_${attributes.escapedId}();")} +<#else> + ${tag.addParameter('onsubmit', "return validateForm_${attributes.escapedId}();")} </#if> +</#if> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/head.ftl b/core/src/main/resources/template/css_xhtml/head.ftl index 0614441f6..db6527550 100644 --- a/core/src/main/resources/template/css_xhtml/head.ftl +++ b/core/src/main/resources/template/css_xhtml/head.ftl @@ -18,5 +18,7 @@ * under the License. */ --> -<@s.link rel="stylesheet" href="${base}${attributes.staticContentPath}/css_xhtml/styles.css" type="text/css" /> -<#include "/${attributes.templateDir}/simple/head.ftl" /> +<@compress single_line=true> +<@s.link rel="stylesheet" href="${base}${parameters.staticContentPath}/css_xhtml/styles.css" type="text/css" /> +<#include "/${parameters.templateDir}/simple/head.ftl" /> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/label.ftl b/core/src/main/resources/template/css_xhtml/label.ftl index 23701e715..d12b0a487 100644 --- a/core/src/main/resources/template/css_xhtml/label.ftl +++ b/core/src/main/resources/template/css_xhtml/label.ftl @@ -18,7 +18,7 @@ * under the License. */ --> -<#--include "/${attributes.templateDir}/css_xhtml/controlheader.ftl" /--> +<@compress single_line=true> <#include "/${attributes.templateDir}/${attributes.expandTheme}/controlheader.ftl" /> <label<#rt/> <#if attributes.id??> @@ -43,3 +43,4 @@ </label> <#include "/${attributes.templateDir}/${attributes.expandTheme}/controlfooter.ftl" /> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/reset.ftl b/core/src/main/resources/template/css_xhtml/reset.ftl index 17e242002..9c69b378b 100644 --- a/core/src/main/resources/template/css_xhtml/reset.ftl +++ b/core/src/main/resources/template/css_xhtml/reset.ftl @@ -18,6 +18,7 @@ * under the License. */ --> +<@compress single_line=true> <#if !attributes.labelPosition?? && (attributes.form.labelPosition)??> <#assign labelPos = attributes.form.labelPosition/> <#elseif attributes.labelPosition??> @@ -39,4 +40,4 @@ <#else> </span> <#t/> </#if> - +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/submit-close.ftl b/core/src/main/resources/template/css_xhtml/submit-close.ftl index 4fefff643..6cf559aa6 100644 --- a/core/src/main/resources/template/css_xhtml/submit-close.ftl +++ b/core/src/main/resources/template/css_xhtml/submit-close.ftl @@ -18,6 +18,7 @@ * under the License. */ --> +<@compress single_line=true> <#include "/${attributes.templateDir}/simple/submit-close.ftl" /> <#if !attributes.labelPosition?? && (attributes.form.labelPosition)??> <#assign labelPos = attributes.form.labelPosition/> @@ -29,3 +30,4 @@ <#else> </span> <#t/> </#if> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/css_xhtml/submit.ftl b/core/src/main/resources/template/css_xhtml/submit.ftl index 0ed1e9391..4f7e7bbf1 100644 --- a/core/src/main/resources/template/css_xhtml/submit.ftl +++ b/core/src/main/resources/template/css_xhtml/submit.ftl @@ -18,6 +18,7 @@ * under the License. */ --> +<@compress single_line=true> <#if !attributes.labelPosition?? && (attributes.form.labelPosition)??> <#assign labelPos = attributes.form.labelPosition/> <#elseif attributes.labelPosition??> @@ -34,3 +35,4 @@ </#if> ><#t/> <#include "/${attributes.templateDir}/simple/submit.ftl" /> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/simple/actionerror.ftl b/core/src/main/resources/template/simple/actionerror.ftl index 3073836fb..a7e2c7baf 100644 --- a/core/src/main/resources/template/simple/actionerror.ftl +++ b/core/src/main/resources/template/simple/actionerror.ftl @@ -20,7 +20,7 @@ --> <@compress single_line=true> <#if (actionErrors?? && actionErrors?size > 0)> - <ul<#rt/> +<ul<#rt/> <#if attributes.id??> id="${attributes.id}"<#rt/> </#if> @@ -33,11 +33,11 @@ style="${attributes.cssStyle}"<#rt/> </#if> > - <#list actionErrors as error> - <#if error??> - <li><span><#if attributes.escape>${error!}<#else>${error!?no_esc}</#if></span><#rt/></li><#rt/> - </#if> - </#list> - </ul> +<#list actionErrors as error> +<#if error??> + <li><span><#if attributes.escape>${error!}<#else>${error!?no_esc}</#if></span><#rt/></li><#rt/> +</#if> +</#list> +</ul> </#if> </@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/simple/form-close-tooltips.ftl b/core/src/main/resources/template/simple/form-close-tooltips.ftl index 1bf45e909..b0968f12c 100644 --- a/core/src/main/resources/template/simple/form-close-tooltips.ftl +++ b/core/src/main/resources/template/simple/form-close-tooltips.ftl @@ -18,7 +18,7 @@ * under the License. */ --> - +<@compress single_line=true> <#-- Code that will add javascript needed for tooltips --><#t/> @@ -27,3 +27,4 @@ <#lt/><@s.script src="${base}${attributes.staticContentPath}/domTT.js" /> <#lt/><@s.link rel="stylesheet" type="text/css" href="${base}${attributes.staticContentPath}/domTT.css" /> </#if><#t/> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/simple/form-close.ftl b/core/src/main/resources/template/simple/form-close.ftl index 59d4f0dbc..ff3a44b68 100644 --- a/core/src/main/resources/template/simple/form-close.ftl +++ b/core/src/main/resources/template/simple/form-close.ftl @@ -19,7 +19,7 @@ */ --> </form> - +<@compress single_line=true> <#if (attributes.customOnsubmitEnabled??)> <@s.script> <#-- @@ -98,5 +98,5 @@ </#if> </@s.script> </#if> - <#include "/${attributes.templateDir}/${attributes.expandTheme}/form-close-tooltips.ftl" /> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/simple/form.ftl b/core/src/main/resources/template/simple/form.ftl index 829b2d677..a6394a72d 100644 --- a/core/src/main/resources/template/simple/form.ftl +++ b/core/src/main/resources/template/simple/form.ftl @@ -18,8 +18,10 @@ * under the License. */ --> +<@compress single_line=true> <#include "/${attributes.templateDir}/${attributes.expandTheme}/form-common.ftl" /> <#if attributes.onreset?has_content> onreset="${attributes.onreset}"<#rt/> </#if> -> \ No newline at end of file +> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/xhtml/controlfooter.ftl b/core/src/main/resources/template/xhtml/controlfooter.ftl index c729f5114..90a3011a3 100644 --- a/core/src/main/resources/template/xhtml/controlfooter.ftl +++ b/core/src/main/resources/template/xhtml/controlfooter.ftl @@ -19,7 +19,7 @@ */ --> ${attributes.after!}<#t/> - </td><#lt/> + </td><#lt/> </tr> <@compress single_line=true> <#if (attributes.errorposition!"top") == 'bottom'> diff --git a/core/src/main/resources/template/xhtml/form-close-validate.ftl b/core/src/main/resources/template/xhtml/form-close-validate.ftl index 8e8661568..aff3a3c66 100644 --- a/core/src/main/resources/template/xhtml/form-close-validate.ftl +++ b/core/src/main/resources/template/xhtml/form-close-validate.ftl @@ -31,6 +31,7 @@ Only the following validators are supported: * double validator END SNIPPET: supported-validators --> +<@compress single_line=true> <#if ((attributes.validate!false == true) && (attributes.performValidation!false == true))> <@s.script> function validateForm_${attributes.escapedId}() { @@ -154,3 +155,4 @@ END SNIPPET: supported-validators } </@s.script> </#if> +</@compress> \ No newline at end of file diff --git a/core/src/main/resources/template/xhtml/form-validate.ftl b/core/src/main/resources/template/xhtml/form-validate.ftl index a074bef2f..dfd40cf35 100644 --- a/core/src/main/resources/template/xhtml/form-validate.ftl +++ b/core/src/main/resources/template/xhtml/form-validate.ftl @@ -18,11 +18,13 @@ * under the License. */ --> +<@compress single_line=true> <#if attributes.validate!false == true> - <@s.script src="${base}${attributes.staticContentPath}/xhtml/validation.js" /> - <#if attributes.onsubmit??> - ${tag.addParameter('onsubmit', "${attributes.onsubmit}; return validateForm_${attributes.escapedId}();")} - <#else> - ${tag.addParameter('onsubmit', "return validateForm_${attributes.escapedId}();")} - </#if> +<@s.script src="${base}${attributes.staticContentPath}/xhtml/validation.js" /> +<#if attributes.onsubmit??> + ${tag.addParameter('onsubmit', "${attributes.onsubmit}; return validateForm_${attributes.escapedId}();")} +<#else> + ${tag.addParameter('onsubmit', "return validateForm_${attributes.escapedId}();")} </#if> +</#if> +</@compress>