Java Code Examples for org.beetl.core.Context#getGlobal()
The following examples show how to use
org.beetl.core.Context#getGlobal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CookieFunction.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Object call(Object[] paras, Context ctx) { HttpServletRequest request = (HttpServletRequest)ctx.getGlobal(WebVariable.REQUEST); Cookie[] cookies = request.getCookies(); if(paras.length==0){ return cookies; }else{ String name = (String)paras[0]; for(Cookie cookie:cookies){ if(cookie.getName().equals(name)){ return cookie; } } return null; } }
Example 2
Source File: I18nFunction.java From java-platform with Apache License 2.0 | 5 votes |
@Override public Object call(Object[] paras, Context ctx) { RequestContext requestContext = (RequestContext) ctx .getGlobal(AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE); Assert.notNull(requestContext); Assert.notNull(paras); Assert.isTrue(paras.length > 0); String code = (String) paras[0]; Object[] args = paras.length > 1 ? Arrays.copyOfRange(paras, 1, paras.length) : null; return requestContext.getMessage(code, args); }
Example 3
Source File: HasWebSession.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Boolean call(Object[] paras, Context ctx) { HttpServletRequest requet = (HttpServletRequest) ctx.getGlobal("request"); return requet.getSession(false) != null; }
Example 4
Source File: EmptyFunction.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Boolean call(Object[] paras, Context ctx) { String key = null; for (Object o : paras) { key = (String) o; if (ctx.globalVar.containsKey(key)) { Object result = ctx.getGlobal(key); if (result != null) { if (result instanceof String) { if (((String) result).length() != 0) { return false; } } else if (result instanceof Collection) { if (((Collection) result).size() != 0) { return false; } } else if (result instanceof Map) { if (((Map) result).size() != 0) { return false; } } else if (result.getClass().isArray()) { Class ct = result.getClass().getComponentType(); if (ct.isPrimitive()) { return PrimitiveArrayUtil.getSize(result)==0; } else { return ((Object[]) result).length==0; } } else { return false; } } else { continue; } } } return true; }