Search in sources :

Example 36 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class El2Test method test_el2.

@Test
public void test_el2() throws Exception {
    El el = new El("sayhi(name)");
    Context ctx = Lang.context();
    ctx.set("name", "wendal");
    ctx.set("sayhi", getClass().getMethod("sayhi", String.class));
    assertEquals("hi,wendal", el.eval(ctx));
}
Also used : Context(org.nutz.lang.util.Context) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 37 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class ElFieldMacro method onAfter.

public void onAfter(Connection conn, ResultSet rs, Statement stmt) throws SQLException {
    Context context = entityField.getEntity().wrapAsContext(getOperatingObject());
    context.set("field", entityField.getColumnName());
    context.set("view", entityField.getEntity());
    Object value = bin.eval(context);
    entityField.setValue(getOperatingObject(), value);
}
Also used : Context(org.nutz.lang.util.Context)

Example 38 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class AccessOpt method calculate.

public Object calculate() {
    //如果直接调用计算方法,那基本上就是直接调用属性了吧...我也不知道^^
    Object obj = fetchVar();
    if (obj == null) {
        throw new ElException("obj is NULL, can't call obj." + right);
    }
    if (obj instanceof Map) {
        Map<?, ?> om = (Map<?, ?>) obj;
        if (om.containsKey(right.toString())) {
            return om.get(right.toString());
        }
    }
    if (obj instanceof Context) {
        Context sc = (Context) obj;
        if (sc.has(right.toString())) {
            return sc.get(right.toString());
        }
    }
    Mirror<?> me = Mirror.me(obj);
    return me.getValue(obj, right.toString());
}
Also used : Context(org.nutz.lang.util.Context) ElException(org.nutz.el.ElException) Map(java.util.Map)

Example 39 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class El method render.

public static String render(CharSegment seg, Map<String, El> els, Context ctx) {
    Context main = Lang.context();
    for (String key : seg.keys()) {
        El el = els.get(key);
        if (el == null)
            el = new El(key);
        main.putAll(key, el.eval(ctx));
    }
    return seg.render(main).toString();
}
Also used : Context(org.nutz.lang.util.Context)

Example 40 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class SegmentsTest method test_issue_722.

@Test
public void test_issue_722() {
    Context ctx = Lang.context();
    assertEquals("^.+abc.+$", Segments.replace("^.+abc.+$", ctx));
//        assertEquals("^.+abc.+${", Segments.replace("^.+abc.+${", ctx));
}
Also used : Context(org.nutz.lang.util.Context) Test(org.junit.Test)

Aggregations

Context (org.nutz.lang.util.Context)40 Test (org.junit.Test)29 SimpleSpeedTest (org.nutz.el.speed.SimpleSpeedTest)24 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 ServletContext (javax.servlet.ServletContext)3 El (org.nutz.el.El)3 Map (java.util.Map)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigDecimal (java.math.BigDecimal)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 Ignore (org.junit.Ignore)1 ElException (org.nutz.el.ElException)1 Issue293 (org.nutz.el.issue.Issue293)1 Issue303 (org.nutz.el.issue.Issue303)1