org.beetl.core.Function Java Examples
The following examples show how to use
org.beetl.core.Function.
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: SimpleVATest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testFunctionAttribute() throws Exception { gt.registerFunction("userArray", new Function() { @Override public Object call(Object[] paras, Context ctx) { // TODO Auto-generated method stub return new Object[] { User.getTestUser(), "a" }; } }); Template t = gt.getTemplate("/va/va_fun_template.html"); String str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/va/va_fun_expected.html"), str); t = gt.getTemplate("/va/va_fun_template.html"); str = t.render(); AssertJUnit.assertEquals(this.getFileContent("/va/va_fun_expected.html"), str); }
Example #2
Source File: BeetlConfiguration.java From MeetingFilm with Apache License 2.0 | 5 votes |
@Override public void initOther() { groupTemplate.registerFunctionPackage("shiro", new ShiroExt()); groupTemplate.registerFunctionPackage("tool", new ToolUtil()); groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil()); groupTemplate.registerTagFactory("dictSelector", new TagFactory() { @Override public Tag createTag() { return dictSelectorTag; } }); groupTemplate.registerFunction("env", new Function() { @Override public String call(Object[] paras, Context ctx) { String key = (String)paras[0]; String value = env.getProperty(key); if(value!=null) { return getStr(value); } if(paras.length==2) { return (String)paras[1]; } return null; } protected String getStr(String str) { try { return new String(str.getBytes("iso8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } }); }
Example #3
Source File: BeetlConfiguration.java From WebStack-Guns with MIT License | 5 votes |
@Override public void initOther() { groupTemplate.registerFunctionPackage("shiro", new ShiroExt()); groupTemplate.registerFunctionPackage("tool", new ToolUtil()); groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil()); groupTemplate.registerTagFactory("dictSelector", () -> dictSelectorTag); groupTemplate.registerFunction("env", new Function() { @Override public String call(Object[] paras, Context ctx) { String key = (String) paras[0]; String value = env.getProperty(key); if (value != null) { return getStr(value); } if (paras.length == 2) { return (String) paras[1]; } return null; } String getStr(String str) { try { return new String(str.getBytes("iso8859-1"), StandardCharsets.UTF_8); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } }); }
Example #4
Source File: AbstractGroupTemplateConfig.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * 自定义函数 * * @param functions */ public void setFunctions(Map<String, Function> functions) { this.functions = functions; }