use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class JFinal3BeetlRenderFactory method config.
public void config(ResourceLoader rs) {
if (groupTemplate != null) {
groupTemplate.close();
}
try {
Configuration cfg = Configuration.defaultConfiguration();
groupTemplate = new GroupTemplate(rs, cfg);
} catch (IOException e) {
throw new RuntimeException("加载GroupTemplate失败", e);
}
}
use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.
the class BeetlViewMaker method init.
public void init() throws IOException {
log.debug("beetl init ....");
Configuration cfg = Configuration.defaultConfiguration();
Properties prop = new Properties();
InputStream ins = Configuration.class.getResourceAsStream("/beetl.properties");
if (ins != null) {
log.debug("found beetl.properties, loading ...");
try {
prop.load(ins);
} finally {
Streams.safeClose(ins);
}
}
if (!prop.containsKey(Configuration.RESOURCE_LOADER)) {
// 默认选用WebAppResourceLoader,除非用户自定义了RESOURCE_LOADER
log.debug("no custom RESOURCE_LOADER found , select WebAppResourceLoader");
cfg.setResourceLoader(WebAppResourceLoader.class.getName());
}
if (!prop.containsKey(Configuration.DIRECT_BYTE_OUTPUT)) {
// 默认启用DIRECT_BYTE_OUTPUT,除非用户自定义, 一般不会.
log.debug("no custom DIRECT_BYTE_OUTPUT found , set to true");
// 当DIRECT_BYTE_OUTPUT为真时, beetl渲染会通过getOutputStream获取输出流
// 而BeetlView会使用LazyResponseWrapper代理getOutputStream方法
// 从而实现在模板输出之前,避免真正调用getOutputStream
// 这样@Fail视图就能正常工作了
cfg.setDirectByteOutput(true);
}
if (!prop.containsKey(Configuration.ERROR_HANDLER)) {
// 没有自定义ERROR_HANDLER,用定制的
cfg.setErrorHandlerClass(LogErrorHandler.class.getName());
}
groupTemplate = new GroupTemplate(cfg);
render = new WebRender(groupTemplate);
log.debug("beetl init complete");
}
use of org.beetl.core.GroupTemplate in project swift by luastar.
the class BeetlUtils method init.
private void init() {
try {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
Configuration cfg = Configuration.defaultConfiguration();
groupTemplate = new GroupTemplate(resourceLoader, cfg);
} catch (Exception e) {
logger.error("转换为文件时异常", e);
}
}
use of org.beetl.core.GroupTemplate in project hello-world by haoziapple.
the class BasicUse 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 nutzboot by nutzam.
the class BeetlGroupTemplateStarter method getGroupTemplate.
@IocBean(depose = "close")
public GroupTemplate getGroupTemplate() throws IOException {
Properties prop = new Properties();
for (String key : conf.keySet()) {
if (key.startsWith("beetl.")) {
prop.put(key.substring("beetl.".length()), conf.get(key));
}
}
System.out.println(prop);
if (!prop.containsKey(Configuration.RESOURCE_LOADER)) {
prop.put(Configuration.RESOURCE_LOADER, ClasspathResourceLoader.class.getName());
}
if (!prop.containsKey("RESOURCE.autoCheck")) {
prop.put("RESOURCE.autoCheck", "true");
}
if (!prop.containsKey("RESOURCE.root")) {
prop.put("RESOURCE.root", prop.getProperty("root", "template/"));
}
if (!prop.containsKey(Configuration.DIRECT_BYTE_OUTPUT)) {
// 默认启用DIRECT_BYTE_OUTPUT,除非用户自定义, 一般不会.
log.debug("no custom DIRECT_BYTE_OUTPUT found , set to true");
// 当DIRECT_BYTE_OUTPUT为真时, beetl渲染会通过getOutputStream获取输出流
// 而BeetlView会使用LazyResponseWrapper代理getOutputStream方法
// 从而实现在模板输出之前,避免真正调用getOutputStream
// 这样@Fail视图就能正常工作了
prop.put(Configuration.DIRECT_BYTE_OUTPUT, "true");
}
if (!prop.containsKey(Configuration.ERROR_HANDLER)) {
// 没有自定义ERROR_HANDLER,用定制的
prop.put(Configuration.ERROR_HANDLER, LogErrorHandler.class.getName());
}
Configuration cfg = new Configuration(prop);
String local = conf.get(PROP_TEMPLATE_ROOT_LOCAL);
GroupTemplate gt = new GroupTemplate(cfg);
if (!Strings.isBlank(local)) {
try {
if (new File(local).exists()) {
local = new File(local).getAbsolutePath();
FileResourceLoader resourceLoader = new FileResourceLoader(local);
resourceLoader.setAutoCheck(true);
gt.setResourceLoader(resourceLoader);
log.debugf("Template Local path=%s is ok, use it", local);
}
} catch (Throwable e) {
log.infof("Template Local path=%s is not vaild, fallback to beetl.RESOURCE.root", local, e);
}
}
return gt;
}
Aggregations