Skip to content

Commit 9e1e13a

Browse files
committed
Refactor(theme): Update for Struts 7 compatibility
- Rename FreeMarker template variable `parameters` to `attributes`. - Add `@StrutsParameter` annotations to action parameter getter. - Implement OGNL allowlist for stricter security compliance. - Update `web.xml` to schema version 6.0. - Change JSP file encoding to UTF-8.
1 parent a26684c commit 9e1e13a

8 files changed

Lines changed: 38 additions & 32 deletions

File tree

themes/src/main/java/org/apache/struts/edit/action/EditAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.struts.edit.service.EditService;
1010
import org.apache.struts.edit.service.EditServiceInMemory;
1111
import org.apache.struts2.ActionSupport;
12+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
1213

1314
/**
1415
* Acts as a controller to handle actions
@@ -48,6 +49,7 @@ public String input() throws Exception {
4849
return INPUT;
4950
}
5051

52+
@StrutsParameter(depth = 1)
5153
public Person getPersonBean() {
5254

5355

themes/src/main/resources/struts.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
<struts>
77

88
<constant name="struts.devMode" value="true" />
9-
<constant name="struts.ui.theme" value="KUTheme"/>
9+
<constant name="struts.ui.theme" value="KUTheme"/>
10+
<constant name="struts.allowlist.packageNames" value="org.apache.struts.edit.model" />
1011

1112
<package name="basicstruts2" extends="struts-default">
12-
13+
<default-action-ref name="index"/>
1314
<!-- If no class attribute is specified the framework will assume success and
1415
render the result index.jsp -->
1516
<!-- If no name value for the result node is specified the success value is the default -->
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<#include "/${parameters.templateDir}/${parameters.expandTheme}/controlheader.ftl" />
2-
<#include "/${parameters.templateDir}/KUTheme_simple/checkboxlist.ftl" />
3-
<#include "/${parameters.templateDir}/${parameters.expandTheme}/controlfooter.ftl" /><#nt/>
1+
<#include "/${attributes.templateDir}/${attributes.expandTheme}/controlheader.ftl" />
2+
<#include "/${attributes.templateDir}/KUTheme_simple/checkboxlist.ftl" />
3+
<#include "/${attributes.templateDir}/${attributes.expandTheme}/controlfooter.ftl" /><#nt/>
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
<#assign itemCount = 0/>
2-
<#if parameters.list??>
3-
<@s.iterator value="parameters.list">
2+
<#if attributes.list??>
3+
<@s.iterator value="attributes.list">
44
<#assign itemCount = itemCount + 1/>
5-
<#if parameters.listKey??>
6-
<#assign itemKey = stack.findValue(parameters.listKey)/>
5+
<#if attributes.listKey??>
6+
<#assign itemKey = stack.findValue(attributes.listKey)/>
77
<#else>
88
<#assign itemKey = stack.findValue('top')/>
99
</#if>
10-
<#if parameters.listValue??>
11-
<#assign itemValue = stack.findString(parameters.listValue)?default("")/>
10+
<#if attributes.listValue??>
11+
<#assign itemValue = stack.findString(attributes.listValue)?default("")/>
1212
<#else>
1313
<#assign itemValue = stack.findString('top')/>
1414
</#if>
1515
<#assign itemKeyStr=itemKey.toString() />
16-
<input type="checkbox" name="${parameters.name?esc}" value="${itemKeyStr?esc}" id="${parameters.name?esc}-${itemCount}"<#rt/>
17-
<#if tag.contains(parameters.nameValue, itemKey)>
16+
<input type="checkbox" name="${attributes.name?esc}" value="${itemKeyStr?esc}" id="${attributes.name?esc}-${itemCount}"<#rt/>
17+
<#if tag.contains(attributes.nameValue, itemKey)>
1818
checked="checked"<#rt/>
1919
</#if>
20-
<#if parameters.disabled?default(false)>
20+
<#if attributes.disabled?default(false)>
2121
disabled="disabled"<#rt/>
2222
</#if>
23-
<#if parameters.title??>
24-
title="${parameters.title?esc}"<#rt/>
23+
<#if attributes.title??>
24+
title="${attributes.title?esc}"<#rt/>
2525
</#if>
26-
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
27-
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
26+
<#include "/${attributes.templateDir}/simple/scripting-events.ftl" />
27+
<#include "/${attributes.templateDir}/simple/common-attributes.ftl" />
2828
/>
29-
<label for="${parameters.name?esc}-${itemCount}" style="color:red;font-weight:bold">${itemValue?esc}</label> <br />
29+
<label for="${attributes.name?esc}-${itemCount}" style="color:red;font-weight:bold">${itemValue?esc}</label> <br />
3030
</@s.iterator>
3131
<#else>
3232
&nbsp;
3333
</#if>
34-
<input type="hidden" id="__multiselect_${parameters.id?esc}" name="__multiselect_${parameters.name?esc}" value=""<#rt/>
35-
<#if parameters.disabled?default(false)>
34+
<input type="hidden" id="__multiselect_${attributes.id?esc}" name="__multiselect_${attributes.name?esc}" value=""<#rt/>
35+
<#if attributes.disabled?default(false)>
3636
disabled="disabled"<#rt/>
3737
</#if>
3838
/>

themes/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
2+
<web-app id="WebApp_ID" version="6.0"
3+
xmlns="https://jakarta.ee/xml/ns/jakartaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
36
<display-name>Themes Struts 2</display-name>
47
<welcome-file-list>
58
<welcome-file>index.jsp</welcome-file>

themes/src/main/webapp/edit.jsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
33
<%@ taglib prefix="s" uri="/struts-tags" %>
44
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
55
<html>
66
<head>
77
<s:head />
8-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
8+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
99
<title>Struts 2 Form Tags - Edit Person</title>
1010

1111
</head>

themes/src/main/webapp/index.jsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
33
<%@ taglib prefix="s" uri="/struts-tags" %>
44
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
55
<html>
66
<head>
7-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88
<title>Struts 2 Form Tags - Welcome</title>
99
</head>
1010
<body>

themes/src/main/webapp/thankyou.jsp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0" encoding="ISO-8859-1" ?>
2-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3-
pageEncoding="ISO-8859-1"%>
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<%@ page language="java" contentType="text/html; charset=UTF-8"
3+
pageEncoding="UTF-8"%>
44
<%@ taglib prefix="s" uri="/struts-tags" %>
55
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
66
<html xmlns="http://www.w3.org/1999/xhtml">
77
<head>
8-
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
8+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
99
<title>Update Successful</title>
1010
</head>
1111
<body>

0 commit comments

Comments
 (0)