tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r896620 - /tomcat/trunk/test/org/apache/el/TestELEvaluation.java
Date Wed, 06 Jan 2010 18:51:24 GMT
Author: markt
Date: Wed Jan  6 18:51:24 2010
New Revision: 896620

URL: http://svn.apache.org/viewvc?rev=896620&view=rev
Log:
Add a test case for bug 48112 (note this passes - need to check when used in a JSP)

Modified:
    tomcat/trunk/test/org/apache/el/TestELEvaluation.java

Modified: tomcat/trunk/test/org/apache/el/TestELEvaluation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/TestELEvaluation.java?rev=896620&r1=896619&r2=896620&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/TestELEvaluation.java (original)
+++ tomcat/trunk/test/org/apache/el/TestELEvaluation.java Wed Jan  6 18:51:24 2010
@@ -18,9 +18,11 @@
 package org.apache.el;
 
 import java.io.File;
+import java.lang.reflect.Method;
 import java.util.Date;
 
 import javax.el.ValueExpression;
+import javax.el.FunctionMapper;
 
 import org.apache.el.ExpressionFactoryImpl;
 import org.apache.el.lang.ELSupport;
@@ -90,6 +92,11 @@
         assertEquals("\"\\", evaluateExpression("${\"\\\"\\\\\"}"));
     }
 
+    public void testParserFunction() {
+        // bug 48112
+        assertEquals("{world}", evaluateExpression("${fn:trim('{world}')}"));
+    }
+
     private void compareBoth(String msg, int expected, Object o1, Object o2){
         int i1 = ELSupport.compare(o1, o2);
         int i2 = ELSupport.compare(o2, o1);
@@ -116,9 +123,33 @@
 
     private String evaluateExpression(String expression) {
         ELContextImpl ctx = new ELContextImpl();
+        ctx.setFunctionMapper(new FMapper());
         ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
         ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
                 String.class);
         return (String) ve.getValue(ctx);
     }
+    
+    public static class FMapper extends FunctionMapper {
+
+        @Override
+        public Method resolveFunction(String prefix, String localName) {
+            if ("trim".equals(localName)) {
+                Method m;
+                try {
+                    m = this.getClass().getMethod("trim", String.class);
+                    return m;
+                } catch (SecurityException e) {
+                    // Ignore
+                } catch (NoSuchMethodException e) {
+                    // Ignore
+                } 
+            }
+            return null;
+        }
+        
+        public static String trim(String input) {
+            return input.trim();
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message