Making retrieval of theme and templateDir more safe

WW-2366


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@615195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2008-01-25 12:05:37 +00:00
parent 2e3bedad4c
commit d741210f20
2 changed files with 39 additions and 2 deletions
@@ -552,7 +552,7 @@ public abstract class UIBean extends Component {
// If templateDir is not explicitly given,
// try to find attribute which states the dir set to use
if ((templateDir == null) || (templateDir.equals(""))) {
templateDir = (String) stack.findValue("#attr.templateDir");
templateDir = stack.findString("#attr.templateDir");
}
// Default template set
@@ -585,7 +585,7 @@ public abstract class UIBean extends Component {
// If theme set is not explicitly given,
// try to find attribute which states the theme set to use
if ((theme == null) || (theme.equals(""))) {
theme = (String) stack.findValue("#attr.theme");
theme = stack.findString("#attr.theme");
}
// Default theme set
@@ -28,6 +28,9 @@ import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import java.util.Map;
import java.util.Collections;
/**
*
* @version $Date$ $Id$
@@ -81,4 +84,38 @@ public class UIBeanTest extends StrutsTestCase {
assertEquals("formId_txtFldName", txtFld.getParameters().get("id"));
}
public void testGetThemeFromForm() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
Form form = new Form(stack, req, res);
form.setTheme("foo");
TextField txtFld = new TextField(stack, req, res);
assertEquals("foo", txtFld.getTheme());
}
public void testGetThemeFromContext() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
Map context = Collections.singletonMap("theme", "bar");
ActionContext.getContext().put("attr", context);
TextField txtFld = new TextField(stack, req, res);
assertEquals("bar", txtFld.getTheme());
}
public void testGetThemeFromContextNonString() throws Exception {
ValueStack stack = ActionContext.getContext().getValueStack();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
Map context = Collections.singletonMap("theme", new Integer(12));
ActionContext.getContext().put("attr", context);
TextField txtFld = new TextField(stack, req, res);
assertEquals("12", txtFld.getTheme());
}
}