Author: mrdon
Date: Fri Jan 25 04:05:37 2008
New Revision: 615195

URL: http://svn.apache.org/viewvc?rev=615195&view=rev
Log:
Making retrieval of theme and templateDir more safe
WW-2366

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java?rev=615195&r1=615194&r2=615195&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
 Fri Jan 25 04:05:37 2008
@@ -552,7 +552,7 @@
         // 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 @@
         // 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

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java?rev=615195&r1=615194&r2=615195&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/components/UIBeanTest.java
 Fri Jan 25 04:05:37 2008
@@ -28,6 +28,9 @@
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.util.ValueStackFactory;
 
+import java.util.Map;
+import java.util.Collections;
+
 /**
  *
  * @version $Date$ $Id$
@@ -80,5 +83,39 @@
         txtFld.populateComponentHtmlId(form);
 
         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());
     }
 }


Reply via email to