Search in sources :

Example 1 with Evaluator

use of org.apache.taglibs.standard.lang.jstl.Evaluator in project opennms by OpenNMS.

the class StaticFunctionTests method main.

public static void main(String[] args) throws Exception {
    Map m = getSampleMethodMap();
    Evaluator e = new Evaluator();
    Object o;
    o = e.evaluate("", "4", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${4}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${2+2}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${foo:add(2, 3)}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${foo:multiply(2, 3)}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${add(2, 3)}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${multiply(2, 3)}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${add(2, 3) + 5}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    System.out.println("---");
    o = e.evaluate("", "${getInt(getInteger(getInt(5)))}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${getInteger(getInt(getInteger(5)))}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${getInt(getInt(getInt(5)))}", Integer.class, null, null, m, "foo");
    System.out.println(o);
    o = e.evaluate("", "${getInteger(getInteger(getInteger(5)))}", Integer.class, null, null, m, "foo");
    System.out.println(o);
}
Also used : Evaluator(org.apache.taglibs.standard.lang.jstl.Evaluator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Evaluator

use of org.apache.taglibs.standard.lang.jstl.Evaluator in project opennms by OpenNMS.

the class EvaluationTest method runTests.

// -------------------------------------
/**
 * Runs the tests, reading expressions from pIn and writing the
 * results to pOut.
 */
public static void runTests(DataInput pIn, PrintStream pOut) throws IOException {
    PageContext context = createTestContext();
    while (true) {
        String str = pIn.readLine();
        if (str == null)
            break;
        if (str.startsWith("#") || "".equals(str.trim())) {
            pOut.println(str);
        } else {
            String typeStr = pIn.readLine();
            pOut.println("Expression: " + str);
            try {
                Class cl = parseClassName(typeStr);
                pOut.println("ExpectedType: " + cl);
                Evaluator e = new Evaluator();
                Object val = e.evaluate("test", str, cl, null, context);
                pOut.println("Evaluates to: " + val);
                if (val != null) {
                    pOut.println("With type: " + val.getClass().getName());
                }
                pOut.println();
            } catch (JspException exc) {
                pOut.println("Causes an error: " + exc);
            } catch (ClassNotFoundException exc) {
                pOut.println("Causes an error: " + exc);
            }
        }
    }
}
Also used : JspException(javax.servlet.jsp.JspException) PageContext(javax.servlet.jsp.PageContext) Evaluator(org.apache.taglibs.standard.lang.jstl.Evaluator)

Aggregations

Evaluator (org.apache.taglibs.standard.lang.jstl.Evaluator)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JspException (javax.servlet.jsp.JspException)1 PageContext (javax.servlet.jsp.PageContext)1