本文整理汇总了Java中org.beetl.core.GroupTemplate.getTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java GroupTemplate.getTemplate方法的具体用法?Java GroupTemplate.getTemplate怎么用?Java GroupTemplate.getTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.beetl.core.GroupTemplate
的用法示例。
在下文中一共展示了GroupTemplate.getTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
@Override
public String render(String templatePath, Map<String, Object> data) throws Exception {
GroupTemplate gt = getGroupTemplate();
// set template global shared vars
Map<String, Object> sharedVars = new HashMap<>();
sharedVars.put("REQUEST", HttpContext.request());
Session session = HttpContext.request().session();
sharedVars.put("SESSION", session != null ? session.attributes() : new HashMap<String, Object>());
gt.setSharedVars(sharedVars);
Template template = gt.getTemplate(templatePath);
template.binding(data);
return template.render();
}
示例2: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String home = System.getProperty("user.dir") + File.separator
+ "template" + File.separator;
Configuration cf = Configuration.defaultConfiguration();
cf.setStatementStart("<!--:");
cf.setStatementEnd("-->");
FileResourceLoader rs = new FileResourceLoader(home, cf.getCharset());
GroupTemplate gt = new GroupTemplate(rs, cf);
List<StockModel> list = StockModel.dummyItems();
Template t = gt.getTemplate("/helloworld.html");
t.binding("items", list);
StringWriter sw = new StringWriter();
t.renderTo(sw);
System.out.println(sw.toString());
// 第二次
t = gt.getTemplate("/helloworld.html");
t.binding("items", list);
sw = new StringWriter();
t.renderTo(sw);
System.out.println(sw.toString());
}
示例3: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Map<String,Object> shared = new HashMap<String,Object>();
shared.put("name", "beetl");
gt.setSharedVars(shared);
Template t = gt.getTemplate("/org/beetl/sample/s0208/t1.txt");
String str = t.render();
System.out.println(str);
t = gt.getTemplate("/org/beetl/sample/s0208/t2.txt");
str = t.render();
System.out.println(str);
}
示例4: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String home = System.getProperty("user.dir") + File.separator
+ "template" + File.separator;
Configuration cf = Configuration.defaultConfiguration();
FileResourceLoader rs = new FileResourceLoader(home, cf.getCharset());
GroupTemplate gt = new GroupTemplate(rs, cf);
Template t = gt.getTemplate("/helloworld.html");
Program p = gt.getProgram("/helloworld.html");
ProgramMetaData old = p.metaData;
ProgramMetaData copy = old.copy();
System.out.println("ok");
}
示例5: testSimple
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
@Test
public void testSimple() throws Exception
{
Configuration conf = Configuration.defaultConfiguration();
CompositeResourceLoader loader = new CompositeResourceLoader();
String home = System.getProperty("user.dir");
String path1 = home + "/src/test/resources/template/resourceloader/var1";
String path2 = home + "/src/test/resources/template/resourceloader/var2";
FileResourceLoader fileLoader1 = new FileResourceLoader(path1);
FileResourceLoader fileLoader2 = new FileResourceLoader(path2);
Map data = getData();
// 根据id加载
MapResourceLoader mapLoader = new MapResourceLoader(data);
loader.addResourceLoader(new StartsWithMatcher("http:").withoutPrefix(), fileLoader2);
loader.addResourceLoader(new StartsWithMatcher("db:").withoutPrefix(), mapLoader);
loader.addResourceLoader(new AllowAllMatcher(), fileLoader1);
GroupTemplate gt = new GroupTemplate(loader, conf);
Template t = gt.getTemplate("/xxx.html");
t.binding("a", "hello");
String result = t.render();
;
AssertJUnit.assertEquals("hellohello--file2:hello--db=hello", result);
}
示例6: testSecurity
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
@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);
}
示例7: testSimple
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
@Test
public void testSimple() throws Exception
{
GroupTemplate newGt = getGt();
Template t = newGt.getTemplate("/text/single_template.html");
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/text/single_expected.html"), str);
}
示例8: testSimple
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
@Test
public void testSimple() throws Exception
{
GroupTemplate newGt = getGt();
Template t = newGt.getTemplate("/text/simple_pair_template.html");
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/text/simple_pair_expected.html"), str);
}
示例9: testPair
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
@Test
public void testPair() throws Exception
{
GroupTemplate newGt = getGt();
Template t = newGt.getTemplate("/text/pair_template.html");
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/text/pair_expected.html"), str);
}
示例10: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String root = System.getProperty("user.dir")+File.separator+"template";
FileResourceLoader resourceLoader = new FileResourceLoader(root,"utf-8");
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
gt.registerFunctionPackage("t", new FunctionPackage());
Template t = gt.getTemplate("/s32/functionPackage.html");
String str = t.render();
System.out.println(str);
}
示例11: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String root = System.getProperty("user.dir")+File.separator+"template";
FileResourceLoader resourceLoader = new FileResourceLoader(root,"utf-8");
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/s32/pagefunction.html");
String str = t.render();
System.out.println(str);
}
示例12: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
URL url = resourceLoader.getClass().getResource("/org/beetl/sample/s01/hello.txt");
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/org/beetl/sample/s01/hello.txt");
String str = t.render();
System.out.println(str);
}
示例13: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
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);
}
示例14: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String root = System.getProperty("user.dir")+File.separator+"template";
FileResourceLoader resourceLoader = new FileResourceLoader(root,"utf-8");
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/s01/hello.txt");
String str = t.render();
System.out.println(str);
}
示例15: main
import org.beetl.core.GroupTemplate; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/org/beetl/sample/s0125/error1.txt");
String str = t.render();
t = gt.getTemplate("/org/beetl/sample/s0125/error2.txt");
str = t.render();
System.out.println(str);
}