use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class HelloBeetl method main.
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);
}
use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class SharedVars method main.
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);
}
use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class RegisterFunctionByFile method main.
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);
}
use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class RegisterFunctionPackage method main.
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);
}
use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class BeetlGroupUtilConfiguration method initGroupTemplate.
private void initGroupTemplate() throws IOException {
// 配置数据加载
Configuration configuration = null;
// 如果都未设置,取默认的配置
if ((configProperties == null) && (configFileResource == null)) {
configuration = Configuration.defaultConfiguration();
} else {
Properties properties = new Properties();
if (configFileResource != null) {
InputStream in = null;
try {
// 如果指定了配置文件,先加载配置文件
in = configFileResource.getInputStream();
properties.load(in);
} catch (IOException ex) {
throw ex;
} finally {
if (in != null) {
in.close();
in = null;
}
}
}
if (configProperties != null) {
for (Entry<Object, Object> entry : configProperties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
properties.setProperty(key, value);
}
}
// 使用配置项配置properties
configuration = new Configuration(properties);
}
// 如果未指定,返回
if (resourceLoader != null) {
groupTemplate = new GroupTemplate(resourceLoader, configuration);
} else {
WebAppResourceLoader defaultLoader = new WebAppResourceLoader(root);
groupTemplate = new GroupTemplate(defaultLoader, configuration);
}
if (errorHandler != null) {
groupTemplate.setErrorHandler(errorHandler);
}
// 设置共享变量
if (sharedVars != null) {
groupTemplate.setSharedVars(sharedVars);
}
}
Aggregations