1 16 17 package org.apache.taglibs.standard.lang.jstl.test; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.taglibs.standard.lang.jstl.Evaluator; 23 24 30 31 public class StaticFunctionTests { 32 33 public static void main(String args[]) throws Exception { 34 Map m = getSampleMethodMap(); 35 Evaluator e = new Evaluator(); 36 Object o; 37 o = e.evaluate("", "4", Integer .class, null, null, m, "foo"); 38 System.out.println(o); 39 o = e.evaluate("", "${4}", Integer .class, null, null, m, "foo"); 40 System.out.println(o); 41 o = e.evaluate("", "${2+2}", Integer .class, null, null, m, "foo"); 42 System.out.println(o); 43 o = e.evaluate("", "${foo:add(2, 3)}", Integer .class, null, null, m, "foo"); 44 System.out.println(o); 45 o = e.evaluate("", "${foo:multiply(2, 3)}", Integer .class, null, null, m, "foo"); 46 System.out.println(o); 47 o = e.evaluate("", "${add(2, 3)}", Integer .class, null, null, m, "foo"); 48 System.out.println(o); 49 o = e.evaluate("", "${multiply(2, 3)}", Integer .class, null, null, m, "foo"); 50 System.out.println(o); 51 o = e.evaluate("", "${add(2, 3) + 5}", Integer .class, null, null, m, "foo"); 52 System.out.println(o); 53 54 System.out.println("---"); 55 o = e.evaluate("", "${getInt(getInteger(getInt(5)))}", Integer .class, null, null, m, "foo"); 56 System.out.println(o); 57 o = e.evaluate("", "${getInteger(getInt(getInteger(5)))}", Integer .class, null, null, m, "foo"); 58 System.out.println(o); 59 o = e.evaluate("", "${getInt(getInt(getInt(5)))}", Integer .class, null, null, m, "foo"); 60 System.out.println(o); 61 o = e.evaluate("", "${getInteger(getInteger(getInteger(5)))}", Integer .class, null, null, m, "foo"); 62 System.out.println(o); 63 64 } 65 66 public static int add(int a, int b) { 67 return a + b; 68 } 69 70 public static int multiply(int a, int b) { 71 return a * b; 72 } 73 74 public static int getInt(Integer i) { 75 return i.intValue(); 76 } 77 78 public static Integer getInteger(int i) { 79 return new Integer (i); 80 } 81 82 public static Map getSampleMethodMap() throws Exception { 83 Map m = new HashMap (); 84 Class c = StaticFunctionTests.class; 85 m.put("foo:add", 86 c.getMethod("add", new Class [] { Integer.TYPE, Integer.TYPE })); 87 m.put("foo:multiply", 88 c.getMethod("multiply", new Class [] { Integer.TYPE, Integer.TYPE })); 89 m.put("foo:getInt", 90 c.getMethod("getInt", new Class [] { Integer .class })); 91 m.put("foo:getInteger", 92 c.getMethod("getInteger", new Class [] { Integer.TYPE })); 93 return m; 94 } 95 96 } 97 | Popular Tags |