struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject struts git commit: Reduces expression evaluation if there is no expression
Date Sun, 06 Mar 2016 09:08:24 GMT
Repository: struts
Updated Branches:
  refs/heads/master f7364a50d -> 15857a69e


Reduces expression evaluation if there is no expression


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/15857a69
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/15857a69
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/15857a69

Branch: refs/heads/master
Commit: 15857a69e7baf3675804495a5954cd0756ac8364
Parents: f7364a5
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Sun Mar 6 10:07:06 2016 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Sun Mar 6 10:08:15 2016 +0100

----------------------------------------------------------------------
 .../apache/struts2/components/Component.java    |  6 ++-
 .../org/apache/struts2/util/ComponentUtils.java |  9 ++--
 .../struts2/views/jsp/ui/AbstractUITag.java     |  2 +-
 .../apache/struts2/util/ComponentUtilsTest.java | 44 ++++++++++++++++++++
 4 files changed, 56 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/15857a69/core/src/main/java/org/apache/struts2/components/Component.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/components/Component.java b/core/src/main/java/org/apache/struts2/components/Component.java
index f6ab54c..2505fd2 100644
--- a/core/src/main/java/org/apache/struts2/components/Component.java
+++ b/core/src/main/java/org/apache/struts2/components/Component.java
@@ -373,7 +373,11 @@ public class Component {
      */
     protected Object findValue(String expr, Class toType) {
         if (altSyntax() && toType == String.class) {
-        	return TextParseUtil.translateVariables('%', expr, stack);
+            if (ComponentUtils.containsExpression(expr)) {
+                return TextParseUtil.translateVariables('%', expr, stack);
+            } else {
+                return expr;
+            }
         } else {
             expr = stripExpressionIfAltSyntax(expr);
 

http://git-wip-us.apache.org/repos/asf/struts/blob/15857a69/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/util/ComponentUtils.java b/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
index 89a238f..01fbcd9 100644
--- a/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
+++ b/core/src/main/java/org/apache/struts2/util/ComponentUtils.java
@@ -40,12 +40,15 @@ public class ComponentUtils {
     /**
      * Check if object is expression base on altSyntax
      *
-     * @param value to treat as an expression
+     * @param expr to treat as an expression
      * @return true if it is an expression
      */
-    public static boolean isExpression(Object value) {
-        String expr = value.toString();
+    public static boolean isExpression(String expr) {
         return expr.startsWith("%{") && expr.endsWith("}");
     }
 
+    public static boolean containsExpression(String expr) {
+        return expr.contains("%{") && expr.contains("}");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/15857a69/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
index 4b65e11..73cddc9 100644
--- a/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
+++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITag.java
@@ -306,7 +306,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements
Dynam
     }
 
     public void setDynamicAttribute(String uri, String localName, Object value) throws JspException
{
-        if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(value))
{
+        if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(value.toString()))
{
             dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
value)));
         } else {
             dynamicAttributes.put(localName, value);

http://git-wip-us.apache.org/repos/asf/struts/blob/15857a69/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java b/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
index 6689352..095176a 100644
--- a/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
+++ b/core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
@@ -71,6 +71,17 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
         assertTrue(actual);
     }
 
+    public void testIsExpressionIsFalseWhenCombined() throws Exception {
+        // given
+        String anExpression = "bar%{foo}";
+
+        // when
+        boolean actual = ComponentUtils.isExpression(anExpression);
+
+        // then
+        assertFalse(actual);
+    }
+
     public void testIsExpressionIsFalse() throws Exception {
         // given
         String anExpression = "foo";
@@ -81,6 +92,39 @@ public class ComponentUtilsTest extends StrutsInternalTestCase {
         // then
         assertFalse(actual);
     }
+
+    public void testContainsExpressionIsTrue() throws Exception {
+        // given
+        String anExpression = "%{foo}";
+
+        // when
+        boolean actual = ComponentUtils.containsExpression(anExpression);
+
+        // then
+        assertTrue(actual);
+    }
+
+    public void testIsContainsIsTrueWhenCombined() throws Exception {
+        // given
+        String anExpression = "bar%{foo}";
+
+        // when
+        boolean actual = ComponentUtils.containsExpression(anExpression);
+
+        // then
+        assertTrue(actual);
+    }
+
+    public void testContainsExpressionIsFalse() throws Exception {
+        // given
+        String anExpression = "foo";
+
+        // when
+        boolean actual = ComponentUtils.containsExpression(anExpression);
+
+        // then
+        assertFalse(actual);
+    }
 }
 
 class MockConfigurationProvider implements ConfigurationProvider {


Mime
View raw message