Commits

Anonymous committed 0b34480

resolves WW-229 and also removes references to peek() on the valuestack and replaced it instead with a direct call to "that" (type conversion works this way)

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@102573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (4)

src/etc/taglib.tld

             <required>false</required>
             <rtexprvalue>true</rtexprvalue>
         </attribute>
+        <attribute>
+            <name>escape</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+        </attribute>
     </tag>
 
     <tag>

src/java/com/opensymphony/webwork/views/jsp/ParamTag.java

                 Object o = null;
 
                 if (value == null) {
-                    o = vs.getRoot().peek();
-                } else {
-                    o = vs.findValue(value);
+                    value = "that";
                 }
 
+                o = vs.findValue(value);
+
                 parent.addParam(name, o);
 
                 /**

src/java/com/opensymphony/webwork/views/jsp/PropertyTag.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.util.OgnlValueStack;
+import com.opensymphony.util.TextUtils;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
     private static final Log log = LogFactory.getLog(PropertyTag.class);
 
+
     //~ Instance fields ////////////////////////////////////////////////////////
 
     private String defaultValue;
     private String value;
+    private boolean escape = false;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         this.value = value;
     }
 
+    public void setEscape(boolean escape) {
+        this.escape = escape;
+    }
+
     public int doStartTag() throws JspException {
         OgnlValueStack stack = ActionContext.getContext().getValueStack();
 
                 Object actualValue = null;
 
                 if (value == null) {
-                    actualValue = stack.getRoot().peek();
-                } else {
-                    actualValue = stack.findValue(value, String.class);
+                    value = "that";
                 }
 
+                actualValue = stack.findValue(value, String.class);
+
                 if (actualValue != null) {
-                    pageContext.getOut().print(actualValue);
+                    pageContext.getOut().print(prepare(actualValue));
                 } else if (defaultValue != null) {
-                    pageContext.getOut().print(defaultValue);
+                    pageContext.getOut().print(prepare(defaultValue));
                 }
             } else if (defaultValue != null) {
-                pageContext.getOut().print(defaultValue);
+                pageContext.getOut().print(prepare(defaultValue));
             }
         } catch (IOException e) {
             log.info("Could not print out value '" + value + "': " + e.getMessage());
         return SKIP_BODY;
     }
 
+    private Object prepare(Object value) {
+        if (escape) {
+            return TextUtils.htmlEncode(value.toString());
+        } else {
+            return value;
+        }
+    }
+
     /**
      * Clears all the instance variables to allow this instance to be reused.
      */
         super.release();
         this.value = null;
         this.defaultValue = null;
+        this.escape = false;
     }
 }

src/webapp/success.jsp

 <%@ page import="java.util.Map,
-
                  com.opensymphony.xwork.util.OgnlValueStack"%>
-
 <%@ taglib uri="webwork" prefix="ww" %>
-
 <%@ taglib uri="c" prefix="c" %>
 
-
+Escaped:     <ww:property value="'this &amp; that'" escape="true" /><br/>
+Not escaped: <ww:property value="'this &amp; that'" escape="false" /><br/>
 
 Success!
-
 <hr>
 
-
-
 <ww:property value="counter.count"/>
 
-
-
 <%--
-
 this sets the variable "counter" in the webwork context
-
 to hold the object returned by the VS find query of "conter"
-
 --%>
-
 <ww:set name="counterBLAH" value="counter" scope="webwork" />
 
-
-
 <%--
-
 We can then reference the above object using # (like @ in the
-
 old EL). This time the scope is page and the variable is
-
 "counter", so now we can use JSTL. The last two ww:set
-
 calls could have, of course, been a simple call ;)
-
 --%>
-
 <ww:set name="counter" value="#counterBLAH" scope="page" />
-
 (JSTL also says: <c:out value="${counter.count}"/>)
 
-
-
 <%--
-
 aka:
-
-
-
 <ww:push value="counter">
-
     <ww:property value="count"/>
-
 </ww:push>
 
-
-
 aka:
-
-
-
 <ww:push value="counter">
-
     <ww:property value="counter.count"/>
-
 </ww:push>
 
-
-
 aka:
-
-
-
 <ww:push value="counter">
-
     <ww:property value="[1].counter.count"/>
-
 </ww:push>
 
-
-
 aka:
-
-
-
 <ww:push value="counter">
-
     <ww:push value="count">
-
         <ww:property value="peek()"/>
-
     </ww:push>
-
 </ww:push>
 
-
-
 aka:
-
-
-
 <ww:push value="counter">
-
     <ww:property value="getCount()"/>
-
 </ww:push>
 
-
-
 <%
-
     long x = System.currentTimeMillis();
-
 %>
 
-
-
 <ww:textfield label="This is a test" name="counter.count"/>
-
-
-
 <%
-
     long y = System.currentTimeMillis();
-
     System.out.println(y - x);
-
 %>
-
 --%>
 
-
-
 <hr>
-
-
-
 Here is an action inside an action. This should make the counter increase twice as fast:<br/>
-
-<pre>
-
 <ww:action name="VelocityCounter" id="vc">
-
  <ww:param name="foo" value="'BAR'"/>
-
 </ww:action>
 
 <ww:push value="#vc">
+<pre>
  counter.count (old) == <ww:property value="[1].counter.count" />
-
  counter.count (new) == <ww:property value="counter.count" />
-
  foo is also: <ww:property value="foo"/>
-</ww:push>
-
 </pre>
-
-
-
+</ww:push>