Commits

Anonymous committed 9fffdfe

initial support for new tag syntax (off by default)

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

Comments (0)

Files changed (22)

src/java/com/opensymphony/webwork/default.properties

 # extension for actions
 webwork.action.extension=action
 
+# use beta alternative syntax that requires %{} in most places
+# to evaluate expressions for String attributes for tags
+webwork.tag.altSyntax=false
+
 ### Standard UI theme
 # Change this to reflect which path should be used for JSP control tag templates by default
 webwork.ui.theme=xhtml

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

         }
 
         //make the comparision
-        Object o = findValue(test);
+        answer = (Boolean) findValue(test, Boolean.class);
 
-        if ((o != null) && o instanceof Boolean) {
-            answer = (Boolean) o;
-
-            if (answer.booleanValue()) {
-                return EVAL_BODY_INCLUDE;
-            }
+        if (answer != null && answer.booleanValue()) {
+            return EVAL_BODY_INCLUDE;
         }
 
         return SKIP_BODY;

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

     }
 
     public int doStartTag() throws JspException {
-        Object o = findValue(test);
+        answer = (Boolean) findValue(test, Boolean.class);
 
-        if ((o != null) && o instanceof Boolean) {
-            answer = (Boolean) o;
-
-            if (answer.booleanValue()) {
-                return EVAL_BODY_INCLUDE;
-            }
+        if (answer != null && answer.booleanValue()) {
+            return EVAL_BODY_INCLUDE;
         }
 
         return SKIP_BODY;

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

                 if (parametricTag instanceof UnnamedParametric) {
                     ((UnnamedParametric) parametricTag).addParameter(findValue(valueAttr));
                 } else {
-                    Object name = findValue(nameAttr);
+                    String name = findString(nameAttr);
 
                     if (name == null) {
                         throw new JspException("No name found for following expression: " + nameAttr);
                     }
 
                     Object value = findValue(valueAttr);
-                    parametricTag.addParameter(name.toString(), value);
+                    parametricTag.addParameter(name, value);
                 }
             } else {
                 String content = null;

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

                 value = "top";
             }
 
-            actualValue = findValue(value, String.class);
+            // exception: don't call findString(), since we don't want the
+            //            expression parsed in this one case. it really
+            //            doesn't make sense, in fact.
+            actualValue = getStack().findValue(value, String.class);
 
             if (actualValue != null) {
                 pageContext.getOut().print(prepare(actualValue));

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

     }
 
     protected Object findValue(String expr, Class toType) {
-        expr = CompatUtil.compat(expr);
+        if (WebWorkTagSupport.ALT_SYNTAX && toType == String.class) {
+            return WebWorkTagSupport.translateVariables(expr, getStack());
+        } else {
+            expr = CompatUtil.compat(expr);
 
-        return getStack().findValue(expr, toType);
+            return getStack().findValue(expr, toType);
+        }
     }
 
     protected String toString(Throwable t) {

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

 package com.opensymphony.webwork.views.jsp;
 
 import com.opensymphony.webwork.util.FastByteArrayOutputStream;
+import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.xwork.util.OgnlValueStack;
 
 import javax.servlet.jsp.tagext.TagSupport;
  * WebWork base class for defining new tag handlers.
  */
 public abstract class WebWorkTagSupport extends TagSupport {
-    //~ Methods ////////////////////////////////////////////////////////////////
+    public static final boolean ALT_SYNTAX = "true".equals(Configuration.getString("webwork.tag.altSyntax"));
+
+    public static String translateVariables(String expression, OgnlValueStack stack) {
+        while (true) {
+            int x = expression.indexOf("%{");
+            int y = expression.indexOf("}", x);
+
+            if ((x != -1) && (y != -1)) {
+                String var = expression.substring(x + 2, y);
+
+                Object o = stack.findValue(var, String.class);
+
+                if (o != null) {
+                    expression = expression.substring(0, x) + o + expression.substring(y + 1);
+                } else {
+                    // the variable doesn't exist, so don't display anything
+                    expression = expression.substring(0, x) + expression.substring(y + 1);
+                }
+            } else {
+                break;
+            }
+        }
+
+        return expression;
+    }
 
     protected OgnlValueStack getStack() {
         return TagUtils.getStack(pageContext);
     }
 
     protected Object findValue(String expr, Class toType) {
-        expr = CompatUtil.compat(expr);
+        if (ALT_SYNTAX && toType == String.class) {
+            return translateVariables(expr, getStack());
+        } else {
+            expr = CompatUtil.compat(expr);
 
-        return getStack().findValue(expr, toType);
+            return getStack().findValue(expr, toType);
+        }
     }
 
     protected String toString(Throwable t) {

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractDoubleListTag.java

         Object doubleName = null;
 
         if (doubleNameAttr != null) {
-            doubleName = findValue(doubleNameAttr, String.class);
+            doubleName = findString(doubleNameAttr);
             addParameter("doubleName", doubleName);
         }
 

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractUITag.java

  * @author Matt Ho <a href="mailto:matt@enginegreen.com">&lt;matt@enginegreen.com&gt;</a>
  */
 public abstract class AbstractUITag extends ParameterizedTagSupport {
-    //~ Static fields/initializers /////////////////////////////////////////////
 
     private static final Log LOG = LogFactory.getLog(AbstractUITag.class);
 
-    //~ Instance fields ////////////////////////////////////////////////////////
-
     protected String cssClassAttr;
     protected String cssStyleAttr;
     protected String disabledAttr;
         Object name = null;
 
         if (nameAttr != null) {
-            name = findValue(nameAttr, String.class);
+            name = findString(nameAttr);
             addParameter("name", name);
         }
 
         if (labelAttr != null) {
-            addParameter("label", findValue(labelAttr, String.class));
+            addParameter("label", findString(labelAttr));
         }
 
         if (labelPositionAttr != null) {
-            addParameter("labelposition", findValue(labelPositionAttr, String.class));
+            addParameter("labelposition", findString(labelPositionAttr));
         }
 
         if (requiredAttr != null) {
         }
 
         if (tabindexAttr != null) {
-            addParameter("tabindex", findValue(tabindexAttr, String.class));
+            addParameter("tabindex", findString(tabindexAttr));
         }
 
         if (onchangeAttr != null) {
-            addParameter("onchange", findValue(onchangeAttr, String.class));
+            addParameter("onchange", findString(onchangeAttr));
         }
 
         if (cssClassAttr != null) {
-            addParameter("cssClass", findValue(cssClassAttr, String.class));
+            addParameter("cssClass", findString(cssClassAttr));
         }
 
         if (cssStyleAttr != null) {
-            addParameter("cssStyle", findValue(cssStyleAttr, String.class));
+            addParameter("cssStyle", findString(cssStyleAttr));
         }
 
         if (evaluateNameValue()) {
                 if (valueAttr != null) {
                     addParameter("nameValue", findValue(valueAttr, valueClazz));
                 } else if (name != null) {
-                    addParameter("nameValue", findValue(name.toString(), valueClazz));
+                    String expr = name.toString();
+                    if (ALT_SYNTAX) {
+                        expr = "%{" + expr + "}";
+                    }
+
+                    addParameter("nameValue", findValue(expr, valueClazz));
                 }
             } else {
                 if (valueAttr != null) {

src/java/com/opensymphony/webwork/views/jsp/ui/CheckboxTag.java

 
     protected void evaluateExtraParams(OgnlValueStack stack) {
         if (fieldValueAttr != null) {
-            addParameter("fieldValue", findValue(fieldValueAttr, String.class));
+            addParameter("fieldValue", findString(fieldValueAttr));
         }
     }
 }

src/java/com/opensymphony/webwork/views/jsp/ui/ComboBoxTag.java

         }
 
         if (sizeAttr != null) {
-            addParameter("size", findValue(sizeAttr));
+            addParameter("size", findValue(sizeAttr, Integer.class));
         }
 
         if (maxlengthAttr != null) {
-            addParameter("maxlength", findValue(maxlengthAttr));
+            addParameter("maxlength", findValue(maxlengthAttr, Integer.class));
         }
 
         if (onkeyupAttr != null) {
-            addParameter("onkeyup", findValue(onkeyupAttr));
+            addParameter("onkeyup", findString(onkeyupAttr));
         }
     }
 }

src/java/com/opensymphony/webwork/views/jsp/ui/DoubleSelectTag.java

         }
 
         if (sizeAttr != null) {
-            addParameter("size", findValue(sizeAttr, String.class));
+            addParameter("size", findString(sizeAttr));
         }
 
         if ((headerKeyAttr != null) && (headerValueAttr != null)) {
-            addParameter("headerKey", findValue(headerKeyAttr, String.class));
-            addParameter("headerValue", findValue(headerValueAttr, String.class));
+            addParameter("headerKey", findString(headerKeyAttr));
+            addParameter("headerValue", findString(headerValueAttr));
         }
     }
 

src/java/com/opensymphony/webwork/views/jsp/ui/FileTag.java

         super.evaluateParams(stack);
 
         if (acceptAttr != null) {
-            addParameter("accept", findValue(acceptAttr, String.class));
+            addParameter("accept", findString(acceptAttr));
         }
 
         if (sizeAttr != null) {
-            addParameter("size", findValue(sizeAttr, String.class));
+            addParameter("size", findString(sizeAttr));
         }
     }
 }

src/java/com/opensymphony/webwork/views/jsp/ui/FormTag.java

                 response = ServletActionContext.getResponse();
             }
 
-            String action = (String) findValue(actionAttr, String.class);
+            String action = (String) findString(actionAttr);
             String namespace;
 
             if (namespaceAttr == null) {
         }
 
         if (enctypeAttr != null) {
-            addParameter("enctype", findValue(enctypeAttr, String.class));
+            addParameter("enctype", findString(enctypeAttr));
         }
 
         if (methodAttr != null) {
-            addParameter("method", findValue(methodAttr, String.class));
+            addParameter("method", findString(methodAttr));
         }
 
         if (validateAttr != null) {

src/java/com/opensymphony/webwork/views/jsp/ui/LabelTag.java

 
         // try value first, then name (this overrides the default behavior in the superclass)
         if (valueAttr != null) {
-            addParameter("nameValue", findValue(valueAttr, String.class));
+            addParameter("nameValue", findString(valueAttr));
         } else if (nameAttr != null) {
-            addParameter("nameValue", findValue(nameAttr, String.class));
+            String expr = nameAttr;
+            if (ALT_SYNTAX) {
+                expr = "%{" + expr + "}";
+            }
+
+            addParameter("nameValue", findString(expr));
         }
     }
 }

src/java/com/opensymphony/webwork/views/jsp/ui/SelectTag.java

         }
 
         if (sizeAttr != null) {
-            addParameter("size", findValue(sizeAttr, String.class));
+            addParameter("size", findString(sizeAttr));
         }
 
         if ((headerKeyAttr != null) && (headerValueAttr != null)) {
-            addParameter("headerKey", findValue(headerKeyAttr, String.class));
-            addParameter("headerValue", findValue(headerValueAttr, String.class));
+            addParameter("headerKey", findString(headerKeyAttr));
+            addParameter("headerValue", findString(headerValueAttr));
         }
     }
 

src/java/com/opensymphony/webwork/views/jsp/ui/SubmitTag.java

 
         super.evaluateParams(stack);
 
-        addParameter("align", findValue(alignAttr, String.class));
+        addParameter("align", findString(alignAttr));
     }
 }

src/java/com/opensymphony/webwork/views/jsp/ui/TabbedPaneTag.java

 
     protected String strVal(String objName) {
         try {
-            return String.valueOf(findValue(objName));
+            return findString(objName);
         } catch (Exception e) {
             return objName;
         }

src/java/com/opensymphony/webwork/views/jsp/ui/TextFieldTag.java

         super.evaluateExtraParams(stack);
 
         if (sizeAttr != null) {
-            addParameter("size", findValue(sizeAttr, String.class));
+            addParameter("size", findString(sizeAttr));
         }
 
         if (maxLengthAttr != null) {
-            addParameter("maxlength", findValue(maxLengthAttr, String.class));
+            addParameter("maxlength", findString(maxLengthAttr));
         }
 
         if (readonlyAttr != null) {
         }
 
         if (onkeyupAttr != null) {
-            addParameter("onkeyup", findValue(onkeyupAttr, String.class));
+            addParameter("onkeyup", findString(onkeyupAttr));
         }
     }
 

src/java/com/opensymphony/webwork/views/jsp/ui/TextTag.java

 import com.opensymphony.webwork.views.jsp.ParamTag;
 import com.opensymphony.webwork.views.jsp.WebWorkBodyTagSupport;
 import com.opensymphony.xwork.TextProvider;
-import com.opensymphony.xwork.util.OgnlValueStack;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
         values.add(value);
     }
 
-    // BodyTag implementation ----------------------------------------
     public int doEndTag() throws JspException {
-        OgnlValueStack stack = getStack();
-
-        actualName = (String) findValue(nameAttr, String.class);
+        actualName = (String) findString(nameAttr);
 
         // Add tag attribute values
         // These can be used to parameterize the i18n-ized message

src/java/com/opensymphony/webwork/views/jsp/ui/TextareaTag.java

         }
 
         if (onkeyupAttr != null) {
-            addParameter("onkeyup", findValue(onkeyupAttr, String.class));
+            addParameter("onkeyup", findString(onkeyupAttr));
         }
 
         if (colsAttr != null) {
-            addParameter("cols", findValue(colsAttr, String.class));
+            addParameter("cols", findString(colsAttr));
         }
 
         if (rowsAttr != null) {
-            addParameter("rows", findValue(rowsAttr, String.class));
+            addParameter("rows", findString(rowsAttr));
         }
     }
 

src/java/com/opensymphony/webwork/views/jsp/ui/TokenTag.java

             if (nameAttr == null) {
                 tokenName = TokenHelper.DEFAULT_TOKEN_NAME;
             } else {
-                tokenName = (String) findValue(nameAttr, String.class);
+                tokenName = (String) findString(nameAttr);
 
                 if (tokenName == null) {
                     tokenName = nameAttr;