org.beetl.core.resource.StringTemplateResourceLoader Java Examples
The following examples show how to use
org.beetl.core.resource.StringTemplateResourceLoader.
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: BeetlTest.java From seed with Apache License 2.0 | 6 votes |
@Test public void buildFromString() throws IOException { GroupTemplate groupTemplate = new GroupTemplate(new StringTemplateResourceLoader(), Configuration.defaultConfiguration()); //设置模板字符串 Template template = groupTemplate.getTemplate("<!DOCTYPE HTML>\n" + "<html>\n" + "<head>\n" + " <meta charset=\"UTF-8\">\n" + " <title>beetl demo</title>\n" + "</head>\n" + "<body>\n" + " 长篇架空武侠小说:${book},真的忍心烂尾么??\n" + "</body>\n" + "</html>"); //设置模板所需的共享变量 Map<String, Object> sharedVars = new HashMap<>(); sharedVars.put("book", "英雄志"); template.binding(sharedVars); //template.binding("book", "野狗志"); //解析模板字符串 String data = template.render(); System.out.println(data); }
Example #2
Source File: AlbianBeetlTemplateService.java From Albianj2 with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void loading() throws AlbianParserException { try { FileResourceLoader resourceLoader = new FileResourceLoader(c.getRootPath(), c.getCharset()); Configuration cfg = Configuration.defaultConfiguration(); cfg.setHtmlTagSupport(true); gt = new GroupTemplate(resourceLoader, cfg); StringTemplateResourceLoader rl = new StringTemplateResourceLoader(); sgt = new GroupTemplate(rl, cfg); Map<String, CustomTagConfigurtion> ctcs = c.getCustomTags(); for (Map.Entry<String, CustomTagConfigurtion> entry : ctcs.entrySet()) { CustomTagConfigurtion ctc = entry.getValue(); Class<? extends Tag> cla = (Class<? extends Tag>) AlbianClassLoader.getInstance().loadClass(ctc.getFullClassname()); if (null != cla) { gt.registerTag(ctc.getName(), cla); sgt.registerTag(ctc.getName(), cla); } } } catch (Exception e) { throw new AlbianParserException(e); } }
Example #3
Source File: NativeTest.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testSecurity() throws Exception { StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader(); Configuration cfg = Configuration.defaultConfiguration(); GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); Template t = gt.getTemplate("hello,${@java.lang.System.currentTimeMillis()}"); String str = t.render(); AssertJUnit.assertEquals("hello,", str); }
Example #4
Source File: HelloBeetl.java From beetl2.0 with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader(); Configuration cfg = Configuration.defaultConfiguration(); GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); Template t = gt.getTemplate("hello,${name}"); t.binding("name", "beetl"); String str = t.render(); System.out.println(str); }