use of org.beetl.core.resource.WebAppResourceLoader 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);
}
}
use of org.beetl.core.resource.WebAppResourceLoader in project beetl2.0 by javamonkey.
the class JFinal3BeetlRenderFactory method config.
public void config(String root) {
WebAppResourceLoader resourceLoader = new WebAppResourceLoader(root);
config(resourceLoader);
}
use of org.beetl.core.resource.WebAppResourceLoader 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.resource.WebAppResourceLoader in project beetl2.0 by javamonkey.
the class JFinal3BeetlRenderFactory method config.
public void config() {
String root = PathKit.getWebRootPath();
WebAppResourceLoader resourceLoader = new WebAppResourceLoader(root);
config(resourceLoader);
}
Aggregations