From 3825229f44450bd34a8e2e22ac80291515170847 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Fri, 10 Jun 2022 16:06:10 +0200 Subject: [PATCH 1/4] WW-5185 Reintroduces proper implementation of Tiles resource to support wildcard matching of Tiles definitions It was broken after refactoring related to WW-5011 --- .../tiles/StrutsApplicationResource.java | 82 +++++++++++++++++++ ...rutsWildcardServletApplicationContext.java | 5 +- 2 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java new file mode 100644 index 000000000..1ad6ab95e --- /dev/null +++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsApplicationResource.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.tiles; + +import org.apache.tiles.request.locale.PostfixedApplicationResource; +import org.apache.tiles.request.locale.URLApplicationResource; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +public class StrutsApplicationResource extends PostfixedApplicationResource { + + private final URL url; + private final File file; + + /** + * fixes WW-5011 + * @return file path for "file" protocol elsewhere url path as before to keep backward-compatibility + * @see URLApplicationResource#getFile(URL) + */ + private static String getFilePath(URL url) { + String path = url.getPath(); + if (!"file".equals(url.getProtocol())) { + return path; + } + try { + // fixes WW-5011 because includes ref in path - like URLApplicationResource#getFile(URL) + path = (new URI(url.toExternalForm())).getSchemeSpecificPart(); + } catch (Exception e) { + // fallback solution + if (url.getRef() != null && !new File(path).exists()) { + // it's like WW-5011 + path += "#" + url.getRef(); + } + } + + return path; + } + + public StrutsApplicationResource(URL url) { + super(getFilePath(url)); + this.url = url; + this.file = new File(getFilePath(url)); + } + + @Override + public InputStream getInputStream() throws IOException { + return url.openStream(); + } + + @Override + public long getLastModified() throws IOException { + if (file.exists()) { + return file.lastModified(); + } + return 0; + } + + @Override + public String toString() { + return "Resource " + getLocalePath() + " at " + url.toString(); + } +} diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java index 5b1181fd3..6a890d4a9 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsWildcardServletApplicationContext.java @@ -102,7 +102,7 @@ public class StrutsWildcardServletApplicationContext extends ServletApplicationC File localFile = new File(localePath); if (localFile.exists()) { try { - return new URLApplicationResource(localePath, localFile.toURI().toURL()); + return new StrutsApplicationResource(localFile.toURI().toURL()); } catch (MalformedURLException e) { LOG.warn("Cannot access [{}]", localePath, e); return null; @@ -121,8 +121,7 @@ public class StrutsWildcardServletApplicationContext extends ServletApplicationC for (Map.Entry entry : matches.entrySet()) { if (pattern.matcher(entry.getKey()).matches()) { - URL url = entry.getValue(); - resources.add(new URLApplicationResource(url.toExternalForm(), url)); + resources.add(new StrutsApplicationResource(entry.getValue())); } } From 9a2996f9b794f546461a43d4e927ba387f197209 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Fri, 10 Jun 2022 16:06:27 +0200 Subject: [PATCH 2/4] Uses proper Servlet API 3.1 headers --- .../src/main/webapp/WEB-INF/web.xml | 7 +-- apps/showcase/src/main/webapp/WEB-INF/web.xml | 46 +++++++++---------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml b/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml index 4367ef3af..10e50dd16 100644 --- a/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml +++ b/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml @@ -19,13 +19,14 @@ * under the License. */ --> - + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee + http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" + version="3.1"> Struts 2 Rest Example - diff --git a/apps/showcase/src/main/webapp/WEB-INF/web.xml b/apps/showcase/src/main/webapp/WEB-INF/web.xml index d76908275..58a831b6c 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/web.xml +++ b/apps/showcase/src/main/webapp/WEB-INF/web.xml @@ -1,5 +1,6 @@ - + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee + http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" + version="3.1"> Struts Showcase Application - - org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG - - /WEB-INF/tiles.xml - - - async org.apache.struts2.showcase.async.AsyncFilter @@ -46,11 +43,10 @@ org.apache.struts2.dispatcher.filter.StrutsExecuteFilter - - - sitemesh - com.opensymphony.sitemesh.webapp.SiteMeshFilter - + + sitemesh + com.opensymphony.sitemesh.webapp.SiteMeshFilter + async @@ -81,18 +77,18 @@ org.apache.struts2.tiles.StrutsTilesListener - + - - org.apache.struts2.showcase.chat.ChatSessionListener - + + org.apache.struts2.showcase.chat.ChatSessionListener + org.apache.struts2.dispatcher.listener.StrutsListener - + @@ -103,13 +99,13 @@ true - - JspSupportServlet - org.apache.struts2.views.JspSupportServlet - 1 - + + JspSupportServlet + org.apache.struts2.views.JspSupportServlet + 1 + - + sitemesh-freemarker org.apache.struts2.sitemesh.FreemarkerDecoratorServlet From fc2aebd10afcf6201572b209fe94a16fadbecac8 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 14 Jun 2022 13:17:19 +0200 Subject: [PATCH 3/4] WW-5187 Comments out Velocity based PageFilter --- .../java/org/apache/struts2/sitemesh/VelocityPageFilter.java | 2 +- plugins/sitemesh/src/main/resources/struts-plugin.xml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java index a57c8ed47..22de2c60a 100644 --- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java +++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java @@ -50,7 +50,7 @@ public class VelocityPageFilter extends SiteMeshFilter { // TODO: Remove heavy coupling on horrible SM2 Factory Factory factory = Factory.getInstance(new Config(filterConfig)); factory.refresh(); - return new FreemarkerMapper2DecoratorSelector(factory.getDecoratorMapper()); + return new VelocityMapper2DecoratorSelector(factory.getDecoratorMapper()); } } diff --git a/plugins/sitemesh/src/main/resources/struts-plugin.xml b/plugins/sitemesh/src/main/resources/struts-plugin.xml index c5fcd5d88..406a73a0f 100644 --- a/plugins/sitemesh/src/main/resources/struts-plugin.xml +++ b/plugins/sitemesh/src/main/resources/struts-plugin.xml @@ -22,8 +22,9 @@ - + - + + From 0e4d5962e1d774d6791b2f713263d9e9fcd41aab Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 15 Jun 2022 14:49:02 +0200 Subject: [PATCH 4/4] WW-5191 Fixes placement of maxLength and minLength attributes in tag --- .../apache/struts2/views/jsp/ui/TextareaTag.java | 4 +++- .../main/resources/template/simple/textarea.ftl | 14 +++++++------- .../apache/struts2/views/jsp/ui/TextareaTest.java | 4 ++++ .../org/apache/struts2/views/jsp/ui/Textarea-1.txt | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/TextareaTag.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/TextareaTag.java index 0da6fe8bf..b814eb115 100644 --- a/core/src/main/java/org/apache/struts2/views/jsp/ui/TextareaTag.java +++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/TextareaTag.java @@ -73,7 +73,7 @@ public class TextareaTag extends AbstractUITag { public void setWrap(String wrap) { this.wrap = wrap; } - + public void setMaxlength(String maxlength) { this.maxlength = maxlength; } @@ -100,6 +100,8 @@ public class TextareaTag extends AbstractUITag { this.readonly = null; this.rows = null; this.wrap = null; + this.maxlength = null; + this.minlength = null; } } diff --git a/core/src/main/resources/template/simple/textarea.ftl b/core/src/main/resources/template/simple/textarea.ftl index f08826f1e..b3f653ced 100644 --- a/core/src/main/resources/template/simple/textarea.ftl +++ b/core/src/main/resources/template/simple/textarea.ftl @@ -45,6 +45,12 @@ <#if parameters.title?has_content> title="${parameters.title}"<#rt/> +<#if parameters.maxlength?has_content> + maxlength="${parameters.maxlength}"<#rt/> + +<#if parameters.minlength?has_content> + minlength="${parameters.minlength}"<#rt/> + <#include "/${parameters.templateDir}/${parameters.expandTheme}/scripting-events.ftl" /> <#include "/${parameters.templateDir}/${parameters.expandTheme}/common-attributes.ftl" /> <#include "/${parameters.templateDir}/${parameters.expandTheme}/dynamic-attributes.ftl" /> @@ -52,10 +58,4 @@ <#if parameters.nameValue??> <@s.property value="parameters.nameValue"/><#t/> -<#if parameters.maxlength?has_content> - maxlength="${parameters.maxlength}"<#rt/> - -<#if parameters.minlength?has_content> - minlength="${parameters.minlength}"<#rt/> - - \ No newline at end of file + diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/TextareaTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/TextareaTest.java index d94bbd2c5..c83086255 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/TextareaTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/TextareaTest.java @@ -47,6 +47,8 @@ public class TextareaTest extends AbstractUITagTest { tag.setId("the_id"); tag.setOnkeyup("alert('hello');"); tag.setReadonly("true"); + tag.setMaxlength("100"); + tag.setMinlength("10"); tag.doStartTag(); tag.doEndTag(); @@ -81,6 +83,8 @@ public class TextareaTest extends AbstractUITagTest { tag.setId("the_id"); tag.setOnkeyup("alert('hello');"); tag.setReadonly("true"); + tag.setMaxlength("100"); + tag.setMinlength("10"); tag.doStartTag(); setComponentTagClearTagState(tag, true); // Ensure component tag state clearing is set true (to match tag). diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textarea-1.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textarea-1.txt index 3b6fe998c..c40a1160d 100644 --- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textarea-1.txt +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Textarea-1.txt @@ -1,4 +1,4 @@ - +