本文整理了Java中org.nutz.lang.Lang.context()
方法的一些代码示例,展示了Lang.context()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lang.context()
方法的具体详情如下:
包路径:org.nutz.lang.Lang
类名称:Lang
方法名:context
[英]创建一个新的上下文对象
[中]创建一个新的上下文对象
代码示例来源:origin: nutzam/nutz
public ObjConvertImpl(Type type) {
this.type = type;
if (NutConf.USE_EL_IN_OBJECT_CONVERT)
context = Lang.context();
}
代码示例来源:origin: nutzam/nutz
public Context reqCtx() {
Context ctx = reqThreadLocal.get();
if (ctx == null) {
ctx = Lang.context();
reqThreadLocal.set(ctx);
}
return ctx;
}
代码示例来源:origin: nutzam/nutz
/**
* 根据一段 JSON 字符串,生产一个新的上下文对象
*
* @return 一个新创建的上下文对象
*/
public static Context context(String str) {
return context(map(str));
}
代码示例来源:origin: nutzam/nutz
public int evalInt(String el) {
Object obj = El.eval(Lang.context(this), el);
if (obj == null)
return 0;
if (obj instanceof Number)
return ((Number) obj).intValue();
return Integer.parseInt(obj.toString());
}
代码示例来源:origin: nutzam/nutz
/**
* 根据一段 JSON 字符串,生产一个新的上下文对象
*
* @param fmt
* JSON 字符串模板
* @param args
* 模板参数
*
* @return 一个新创建的上下文对象
*/
public static Context contextf(String fmt, Object... args) {
return context(Lang.mapf(fmt, args));
}
代码示例来源:origin: nutzam/nutz
public Object eval(String el) {
return El.eval(Lang.context(this), el);
}
代码示例来源:origin: nutzam/nutz
/**
* @see #replace(Segment, Context)
*/
public static String replace(String pattern, Map<String, Object> context) {
return replace(pattern, Lang.context(new NutMap(context)));
}
代码示例来源:origin: nutzam/nutz
protected String evalPath(HttpServletRequest req, Object obj) {
if (null == dest)
return null;
Context context = Lang.context();
// 解析每个表达式
if (exps.size() != 0) {
Context expContext = createContext(req, obj);
for (Entry<String, El> en : exps.entrySet())
context.set(en.getKey(), en.getValue().eval(expContext));
}
// 生成解析后的路径
return Strings.trim(this.dest.render(context).toString());
}
代码示例来源:origin: nutzam/nutz
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();
}
}
代码示例来源:origin: nutzam/nutz
public void parse(Reader reader) {
nodes = new LinkedList<SegmentNode>();
context = Lang.context();
keys = new NutMap();
StringBuilder org = new StringBuilder();
代码示例来源:origin: nutzam/nutz
protected void createContext(NutConfig config) {
// 构建一个上下文对象,方便子类获取更多的环境信息
// 同时,所有 Filter 和 Adaptor 都可以用 ${app.root} 来填充自己
Context context = Lang.context();
String appRoot = config.getAppRoot();
context.set("app.root", appRoot);
if (log.isDebugEnabled()) {
log.debugf(">> app.root = %s", appRoot);
}
// 载入环境变量
for (Entry<String, String> entry : System.getenv().entrySet())
context.set("env." + entry.getKey(), entry.getValue());
// 载入系统变量
for (Entry<Object, Object> entry : System.getProperties().entrySet())
context.set("sys." + entry.getKey(), entry.getValue());
if (log.isTraceEnabled()) {
log.tracef(">>\nCONTEXT %s", Json.toJson(context, JsonFormat.nice()));
}
config.getServletContext().setAttribute(Loading.CONTEXT_NAME, context);
}
代码示例来源:origin: nutzam/nutz
public static String render(CharSegment seg, Context ctx) {
Context main = Lang.context();
for (String key : seg.keys()) {
main.putAll(key, new El(key).eval(ctx));
}
return seg.render(main).toString();
}
代码示例来源:origin: nutzam/nutz
Context context = Lang.context();
代码示例来源:origin: nutzam/nutz
/**
* 根据当前线程的参考对象,渲染一个动态表名
*
* @param tableName
* 动态表名
* @return 渲染后的表名
*/
public static String render(Segment tableName) {
Object obj = get();
if (null == obj || !tableName.hasKey())
return tableName.toString();
Context context = Lang.context();
if (isPrimitive(obj)) {
for (String key : tableName.keys())
context.set(key, obj);
} else if (obj instanceof Context) {
for (String key : tableName.keys())
context.set(key, ((Context) obj).get(key));
} else if (obj instanceof Map<?, ?>) {
for (String key : tableName.keys())
context.set(key, ((Map<?, ?>) obj).get(key));
} else {
Mirror<?> mirror = Mirror.me(obj);
for (String key : tableName.keys())
context.set(key, mirror.getValue(obj, key));
}
return tableName.render(context).toString();
}
代码示例来源:origin: nutzam/nutz
log.infof("Local socket is up at :%d with %d action ready", port, actions.size());
final Context context = Lang.context();
context.set("stop", false);
代码示例来源:origin: org.nutz/nutz
public ObjConvertImpl(Type type) {
this.type = type;
if (NutConf.USE_EL_IN_OBJECT_CONVERT)
context = Lang.context();
}
代码示例来源:origin: org.nutz/nutz
public int evalInt(String el) {
Object obj = El.eval(Lang.context(this), el);
if (obj == null)
return 0;
if (obj instanceof Number)
return ((Number) obj).intValue();
return Integer.parseInt(obj.toString());
}
代码示例来源:origin: org.nutz/nutz
/**
* @see #replace(Segment, Context)
*/
public static String replace(String pattern, Map<String, Object> context) {
return replace(pattern, Lang.context(new NutMap(context)));
}
代码示例来源:origin: org.nutz/nutz
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();
}
}
代码示例来源:origin: org.nutz/nutz
public static String render(CharSegment seg, Context ctx) {
Context main = Lang.context();
for (String key : seg.keys()) {
main.putAll(key, new El(key).eval(ctx));
}
return seg.render(main).toString();
}
内容来源于网络,如有侵权,请联系作者删除!