diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java index 8e274dd08..06057f9f1 100644 --- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java +++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java @@ -40,7 +40,7 @@ public class StaticContentTest { public void testInvalidRersources2() throws Exception { try (final WebClient webClient = new WebClient()) { try { - webClient.getPage(ParameterUtils.getBaseUrl() + "/struts/..%252f"); + webClient.getPage(ParameterUtils.getBaseUrl() + "/static/..%252f"); Assert.fail("Previous request should have failed"); } catch (FailingHttpStatusCodeException e) { } @@ -49,7 +49,7 @@ public class StaticContentTest { /*public void testInvalidRersources3() throws IOException { try { - beginAt("/struts/..%252f..%252f..%252fWEB-INF/classes/org/apache/struts2/showcase/action/EmployeeAction.class/"); + beginAt("/static/..%252f..%252f..%252fWEB-INF/classes/org/apache/struts2/showcase/action/EmployeeAction.class/"); fail("Previous request should have failed"); } catch (TestingEngineResponseException ex) { // ok diff --git a/bundles/admin/src/main/resources/osgi/admin/shell.ftl b/bundles/admin/src/main/resources/osgi/admin/shell.ftl index aa7d8a9f2..62d0cce6c 100644 --- a/bundles/admin/src/main/resources/osgi/admin/shell.ftl +++ b/bundles/admin/src/main/resources/osgi/admin/shell.ftl @@ -22,13 +22,13 @@
@@ -43,8 +48,8 @@ import java.util.*; * *
* This class is used to serve common static content needed when using various parts of Struts, such as JavaScript - * files, CSS files, etc. It works by looking for requests to /struts/* (or /static/*), and then mapping the value after "/struts/" - * to common packages in Struts and, optionally, in your class path. By default, the following packages are + * files, CSS files, etc. It works by looking for requests to {@link #staticContentPath}/* and then mapping the value + * after to common packages in Struts and, optionally, in your class path. By default, the following packages are * automatically searched: *
* @@ -55,7 +60,7 @@ import java.util.*; * * *
- * This means that you can simply request /struts/xhtml/styles.css and the XHTML UI theme's default stylesheet
+ * This means that you can simply request {@link #staticContentPath}/xhtml/styles.css and the XHTML UI theme's default stylesheet
* will be returned. Likewise, many of the AJAX UI components require various JavaScript files, which are found in the
* org.apache.struts2.static package. If you wish to add additional packages to be searched, you can add a comma
* separated (space, tab and new line will do as well) list in the filter init parameter named "packages". Be
@@ -68,7 +73,7 @@ public class DefaultStaticContentLoader implements StaticContentLoader {
/**
* Provide a logging instance.
*/
- private Logger LOG = LogManager.getLogger(DefaultStaticContentLoader.class);
+ private final Logger LOG = LogManager.getLogger(DefaultStaticContentLoader.class);
/**
* Store set of path prefixes to use with static resources.
@@ -80,6 +85,11 @@ public class DefaultStaticContentLoader implements StaticContentLoader {
*/
protected boolean serveStatic;
+ /**
+ * Store state of StrutsConstants.STRUTS_STATIC_CONTENT_PATH setting.
+ */
+ protected String staticContentPath;
+
/**
* Store state of StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE setting.
*/
@@ -100,20 +110,23 @@ public class DefaultStaticContentLoader implements StaticContentLoader {
/**
* Modify state of StrutsConstants.STRUTS_SERVE_STATIC_CONTENT setting.
*
- * @param serveStaticContent
- * New setting
+ * @param serveStaticContent New setting
*/
@Inject(StrutsConstants.STRUTS_SERVE_STATIC_CONTENT)
public void setServeStaticContent(String serveStaticContent) {
this.serveStatic = BooleanUtils.toBoolean(serveStaticContent);
}
+ @Inject(StrutsConstants.STRUTS_UI_STATIC_CONTENT_PATH)
+ public void setStaticContentPath(String staticContentPath) {
+ this.staticContentPath = staticContentPath;
+ }
+
/**
* Modify state of StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE
* setting.
*
- * @param serveStaticBrowserCache
- * New setting
+ * @param serveStaticBrowserCache New setting
*/
@Inject(StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE)
public void setServeStaticBrowserCache(String serveStaticBrowserCache) {
@@ -122,6 +135,7 @@ public class DefaultStaticContentLoader implements StaticContentLoader {
/**
* Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting.
+ *
* @param encoding New setting
*/
@Inject(StrutsConstants.STRUTS_I18N_ENCODING)
@@ -164,8 +178,7 @@ public class DefaultStaticContentLoader implements StaticContentLoader {
/**
* Create a string array from a comma-delimited list of packages.
*
- * @param packages
- * A comma-delimited String listing packages
+ * @param packages A comma-delimited String listing packages
* @return A string array of packages
*/
protected List
diff --git a/core/src/main/resources/template/simple/optiontransferselect.ftl b/core/src/main/resources/template/simple/optiontransferselect.ftl
index 910dc6a95..e0d00eef0 100644
--- a/core/src/main/resources/template/simple/optiontransferselect.ftl
+++ b/core/src/main/resources/template/simple/optiontransferselect.ftl
@@ -19,7 +19,7 @@
*/
-->
<#if !stack.findValue("#optiontransferselect_js_included")??><#t/>
- " <#include "/${parameters.templateDir}/simple/nonce.ftl" /> >
+ " <#include "/${parameters.templateDir}/simple/nonce.ftl" /> >
<#assign temporaryVariable = stack.setValue("#optiontransferselect_js_included", "true") /><#t/>
#if><#t/>
diff --git a/core/src/main/resources/template/simple/updownselect.ftl b/core/src/main/resources/template/simple/updownselect.ftl
index 4f57b849a..f1185d3a5 100644
--- a/core/src/main/resources/template/simple/updownselect.ftl
+++ b/core/src/main/resources/template/simple/updownselect.ftl
@@ -19,7 +19,7 @@
*/
-->
<#if !stack.findValue("#optiontransferselect_js_included")??><#t/>
- " <#include "/${parameters.templateDir}/simple/nonce.ftl" /> >
+ " <#include "/${parameters.templateDir}/simple/nonce.ftl" /> >
<#assign temporaryVariable = stack.setValue("#optiontransferselect_js_included", "true") /><#t/>
#if><#t/>
diff --git a/core/src/main/resources/template/xhtml/form-validate.ftl b/core/src/main/resources/template/xhtml/form-validate.ftl
index 3a67f445a..33e8b5507 100644
--- a/core/src/main/resources/template/xhtml/form-validate.ftl
+++ b/core/src/main/resources/template/xhtml/form-validate.ftl
@@ -19,7 +19,7 @@
*/
-->
<#if parameters.validate!false == true>
- >
+ >
<#if parameters.onsubmit??>
${tag.addParameter('onsubmit', "${parameters.onsubmit}; return validateForm_${parameters.id?replace('[^a-zA-Z0-9_]', '_', 'r')}();")}
<#else>
diff --git a/core/src/main/resources/template/xhtml/head.ftl b/core/src/main/resources/template/xhtml/head.ftl
index 48678f269..7b5bfe08d 100644
--- a/core/src/main/resources/template/xhtml/head.ftl
+++ b/core/src/main/resources/template/xhtml/head.ftl
@@ -18,5 +18,5 @@
* under the License.
*/
-->
- />
+ />
<#include "/${parameters.templateDir}/simple/head.ftl" />
diff --git a/core/src/main/resources/template/xhtml/tooltip.ftl b/core/src/main/resources/template/xhtml/tooltip.ftl
index d0b35e726..faa69f69b 100644
--- a/core/src/main/resources/template/xhtml/tooltip.ftl
+++ b/core/src/main/resources/template/xhtml/tooltip.ftl
@@ -23,7 +23,7 @@
<#if parameters.tooltipIconPath??><#t/>
src='<@s.url value="${parameters.tooltipIconPath}" includeParams="none" encode="false" />'
<#else><#t/>
- src='<@s.url value="/struts/tooltip.gif" includeParams="none" encode="false" />'
+ src='<@s.url value="${parameters.staticContentPath}/tooltip.gif" includeParams="none" encode="false" />'
#if><#t/>
<#if (parameters.jsTooltipEnabled!'false') == 'true'>
onmouseover="domTT_activate(this, event, 'content', '<#outputformat 'JavaScript'>${parameters.tooltip}#outputformat>'<#t/>
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java b/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
index 8f8eda1eb..d0e93da98 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/DefaultStaticContentLoaderTest.java
@@ -103,13 +103,14 @@ public class DefaultStaticContentLoaderTest extends StrutsInternalTestCase {
}
protected void setUp() {
- requestMock = (HttpServletRequest) createMock(HttpServletRequest.class);
- responseMock = (HttpServletResponse) createMock(HttpServletResponse.class);
- hostConfigMock = (HostConfig) createMock(HostConfig.class);
+ requestMock = createMock(HttpServletRequest.class);
+ responseMock = createMock(HttpServletResponse.class);
+ hostConfigMock = createMock(HostConfig.class);
expect(hostConfigMock.getInitParameter("packages")).andStubReturn(null);
expect(hostConfigMock.getInitParameter("loggerFactory")).andStubReturn(null);
defaultStaticContentLoader = new DefaultStaticContentLoader();
defaultStaticContentLoader.setHostConfig(hostConfigMock);
defaultStaticContentLoader.setEncoding("UTF-8");
+ defaultStaticContentLoader.setStaticContentPath("/static");
}
}
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java b/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
index c99127519..fbcf4e62b 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
@@ -39,7 +39,7 @@ public class StaticContentLoaderTest extends TestCase {
private MockHttpServletResponse res;
public void testCantHandleWithoutServingStatic() {
- StaticContentLoader contentLoader = new DefaultStaticContentLoader();
+ DefaultStaticContentLoader contentLoader = new DefaultStaticContentLoader();
assertFalse(contentLoader.canHandle("/static/test1.css"));
assertFalse(contentLoader.canHandle("/struts/test1.css"));
@@ -49,14 +49,15 @@ public class StaticContentLoaderTest extends TestCase {
public void testCanHandle() {
DefaultStaticContentLoader contentLoader = new DefaultStaticContentLoader();
contentLoader.setServeStaticContent("true");
+ contentLoader.setStaticContentPath("/static");
assertTrue(contentLoader.canHandle("/static/test1.css"));
- assertTrue(contentLoader.canHandle("/struts/test1.css"));
+ assertFalse(contentLoader.canHandle("/struts/test1.css"));
assertFalse(contentLoader.canHandle("test1.css"));
}
- public void testValidRersources() throws IOException {
- contentLoader.findStaticResource("/struts/resource.css", req, res);
+ public void testValidResources() throws IOException {
+ contentLoader.findStaticResource("/static/resource.css", req, res);
assertTrue(res.getContentAsString().contains("color: red;"));
}
@@ -67,25 +68,25 @@ public class StaticContentLoaderTest extends TestCase {
}
public void testInvalidRersources2() throws IOException {
- contentLoader.findStaticResource("/struts/..", req, res);
+ contentLoader.findStaticResource("/static/..", req, res);
assertEquals(HttpServletResponse.SC_NOT_FOUND, res.getStatus());
assertEquals(0, res.getContentLength());
}
public void testInvalidRersources3() throws IOException {
- contentLoader.findStaticResource("/struts/../othertest.properties", req, res);
+ contentLoader.findStaticResource("/static/../othertest.properties", req, res);
assertEquals(HttpServletResponse.SC_NOT_FOUND, res.getStatus());
assertEquals(0, res.getContentLength());
}
public void testInvalidRersources4() throws IOException {
- contentLoader.findStaticResource("/struts/..%252f", req, res);
+ contentLoader.findStaticResource("/static/..%252f", req, res);
assertEquals(HttpServletResponse.SC_NOT_FOUND, res.getStatus());
assertEquals(0, res.getContentLength());
}
public void testInvalidRersources5() throws IOException {
- contentLoader.findStaticResource("/struts/..%252fothertest.properties", req, res);
+ contentLoader.findStaticResource("/static/..%252fothertest.properties", req, res);
assertEquals(HttpServletResponse.SC_NOT_FOUND, res.getStatus());
assertEquals(0, res.getContentLength());
}
@@ -95,6 +96,7 @@ public class StaticContentLoaderTest extends TestCase {
super.setUp();
this.contentLoader = new DefaultStaticContentLoader();
+ this.contentLoader.setStaticContentPath("/static");
MockServletContext servletContext = new MockServletContext();
req = new MockHttpServletRequest(servletContext);
res = new MockHttpServletResponse();
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/StrutsPrepareAndExecuteFilterIntegrationTest.java b/core/src/test/java/org/apache/struts2/dispatcher/StrutsPrepareAndExecuteFilterIntegrationTest.java
index 7bc46ed74..a5419cd8b 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/StrutsPrepareAndExecuteFilterIntegrationTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/StrutsPrepareAndExecuteFilterIntegrationTest.java
@@ -179,7 +179,7 @@ public class StrutsPrepareAndExecuteFilterIntegrationTest extends TestCase {
}
};
- request.setRequestURI("/struts/utils.js");
+ request.setRequestURI("/static/utils.js");
StrutsPrepareAndExecuteFilter filter = new StrutsPrepareAndExecuteFilter();
filter.init(filterConfig);
filter.doFilter(request, response, filterChain);
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/TwoFilterIntegrationTest.java b/core/src/test/java/org/apache/struts2/dispatcher/TwoFilterIntegrationTest.java
index b432a8d28..edc88ba17 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/TwoFilterIntegrationTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/TwoFilterIntegrationTest.java
@@ -79,7 +79,7 @@ public class TwoFilterIntegrationTest extends TestCase {
}
public void testStaticExecute() throws ServletException, IOException {
- MockHttpServletResponse response = run("/struts/utils.js", filterPrepare, filterExecute, failFilter);
+ MockHttpServletResponse response = run("/static/utils.js", filterPrepare, filterExecute, failFilter);
assertEquals(200, response.getStatus());
assertTrue(response.getContentAsString().contains("StrutsUtils"));
}
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
index 50d2bc5f5..8c8d8e1c8 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/TooltipTest.java
@@ -52,7 +52,7 @@ public class TooltipTest extends AbstractUITagTest {
tag.setTooltip("myTooltip");
tag.setTooltipConfig(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip.gif', " +
"'tooltipDelay':'500', " +
"'jsTooltipEnabled':'true' "+
"}"
@@ -86,7 +86,7 @@ public class TooltipTest extends AbstractUITagTest {
tag.setTooltip("myTooltip");
tag.setTooltipConfig(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip.gif', " +
"'tooltipDelay':'500', " +
"'jsTooltipEnabled':'false' "+
"}"
@@ -119,7 +119,7 @@ public class TooltipTest extends AbstractUITagTest {
//same parameters as the OGNL map configuration, output must be the same
tag.setTooltip("myTooltip");
- tag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
+ tag.setTooltipIconPath("/static/tooltip/myTooltip.gif");
tag.setTooltipDelay("500");
tag.setJavascriptTooltip("true");
@@ -142,7 +142,7 @@ public class TooltipTest extends AbstractUITagTest {
formTag.setTooltipConfig(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip.gif', " +
"'tooltipDelay':'500', " +
"'jsTooltipEnabled':'true' "+
"}"
@@ -174,7 +174,7 @@ public class TooltipTest extends AbstractUITagTest {
// same parameters as the OGNL map configuration, output must be the same
formTag.setTooltip("myTooltip");
- formTag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
+ formTag.setTooltipIconPath("/static/tooltip/myTooltip.gif");
formTag.setTooltipDelay("500");
formTag.setJavascriptTooltip("true");
@@ -204,7 +204,7 @@ public class TooltipTest extends AbstractUITagTest {
formTag.setTooltipConfig(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip.gif', " +
"'tooltipDelay':'500', " +
"'jsTooltipEnabled':'true' "+
"}"
@@ -219,7 +219,7 @@ public class TooltipTest extends AbstractUITagTest {
tag.setTooltip("myTooltip");
tag.setTooltipConfig(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip2.gif', " +
"'tooltipDelay':'5000' " +
"}"
);
@@ -242,7 +242,7 @@ public class TooltipTest extends AbstractUITagTest {
// same parameters as the OGNL map configuration, output must be the same
formTag.setTooltip("myTooltip");
- formTag.setTooltipIconPath("/struts/tooltip/myTooltip.gif");
+ formTag.setTooltipIconPath("/static/tooltip/myTooltip.gif");
formTag.setTooltipDelay("500");
formTag.setJavascriptTooltip("true");
@@ -255,7 +255,7 @@ public class TooltipTest extends AbstractUITagTest {
//same parameters as the OGNL map configuration, output must be the same
tag.setTooltip("myTooltip");
- tag.setTooltipIconPath("/struts/tooltip/myTooltip2.gif");
+ tag.setTooltipIconPath("/static/tooltip/myTooltip2.gif");
tag.setTooltipDelay("5000");
tag.setJavascriptTooltip("true");
@@ -280,7 +280,7 @@ public class TooltipTest extends AbstractUITagTest {
formParamTag.setName("tooltipConfig");
formParamTag.setValue(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip.gif', " +
"'tooltipDelay':'500', " +
"'jsTooltipEnabled':'true' "+
"}"
@@ -298,7 +298,7 @@ public class TooltipTest extends AbstractUITagTest {
textFieldParamTag.setName("tooltipConfig");
textFieldParamTag.setValue(
"#{" +
- "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " +
+ "'tooltipIcon':'/static/tooltip/myTooltip2.gif', " +
"'tooltipDelay':'5000' "+
"}"
);
@@ -330,7 +330,7 @@ public class TooltipTest extends AbstractUITagTest {
formParamTag.setName("tooltipConfig");
StrutsMockBodyContent bodyContent = new StrutsMockBodyContent(new MockJspWriter());
bodyContent.setString(
- "tooltipIcon=/struts/tooltip/myTooltip.gif| " +
+ "tooltipIcon=/static/tooltip/myTooltip.gif| " +
"tooltipDelay=500| " +
"jsTooltipEnabled=true "
);
@@ -348,7 +348,7 @@ public class TooltipTest extends AbstractUITagTest {
textFieldParamTag.setName("tooltipConfig");
StrutsMockBodyContent bodyContent2 = new StrutsMockBodyContent(new MockJspWriter());
bodyContent2.setString(
- "tooltipIcon=/struts/tooltip/myTooltip2.gif| " +
+ "tooltipIcon=/static/tooltip/myTooltip2.gif| " +
"tooltipDelay=5000 "
);
textFieldParamTag.setBodyContent(bodyContent2);
diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
index ca4358a65..7a4889cab 100644
--- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
+++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-11.txt
@@ -1,8 +1,8 @@
-
+