use of org.beetl.core.ResourceLoader in project beetl2.0 by javamonkey.
the class CompositeResourceLoader method init.
@Override
public void init(GroupTemplate gt) {
// 逐个初始化
for (ResourceLoader rl : this.matcherResourceLoaderMap.values()) {
rl.init(gt);
}
Map<String, String> resourceMap = gt.getConf().getResourceMap();
this.autoCheck = Boolean.parseBoolean(resourceMap.get("autoCheck"));
}
use of org.beetl.core.ResourceLoader in project beetl2.0 by javamonkey.
the class IncludeJSPTag method getPrefix.
protected String getPrefix() {
ResourceLoader rs = ctx.gt.getResourceLoader();
String loaderRoot = null;
if (rs instanceof FileResourceLoader) {
loaderRoot = ((FileResourceLoader) rs).getRoot();
} else {
return "";
}
File loaderFileRoot = new File(loaderRoot);
if (loaderFileRoot.equals(root)) {
return "";
} else {
int len = root.getAbsolutePath().length();
return loaderFileRoot.getAbsolutePath().substring(len);
}
}
use of org.beetl.core.ResourceLoader in project beetl2.0 by javamonkey.
the class WebErrorHandler method processExcption.
@Override
public void processExcption(BeetlException e, Writer writer) {
// 判断是不是开发者模式,如果不是调用父类方法(默认输出控制台)
if (!Boolean.valueOf(e.gt.getConf().getProperty("RESOURCE.autoCheck"))) {
super.processExcption(e, writer);
}
ErrorInfo error = new ErrorInfo(e);
StringBuilder title = new StringBuilder();
StringBuilder msg = new StringBuilder();
if (error.getErrorCode().equals(BeetlException.CLIENT_IO_ERROR_ERROR)) {
// 不输出详细提示信息
title = new StringBuilder(">>").append("客户端IO异常:").append(e.resource.getId());
if (e.getCause() != null) {
msg.append(e.getCause());
}
render(writer, title.toString(), msg.toString());
return;
}
int line = error.getErrorTokenLine();
title = new StringBuilder(">>").append(error.getType()).append(":").append(error.getErrorTokenText()).append(" 位于").append(line).append("行").append(" 资源:").append(e.resource.getId());
if (error.getErrorCode().equals(BeetlException.TEMPLATE_LOAD_ERROR)) {
if (error.getMsg() != null)
msg.append(error.getMsg());
render(writer, title.toString(), msg.toString());
return;
}
if (e.getMessage() != null) {
msg.append(e.getMessage()).append("\n");
}
ResourceLoader resLoader = e.gt.getResourceLoader();
// 潜在问题,此时可能得到是一个新的模板,不过可能性很小,忽略!
String content = null;
Resource res = resLoader.getResource(e.resource.getId());
// 显示前后三行的内容
int[] range = this.getRange(line);
try {
content = res.getContent(range[0], range[1]);
} catch (IOException e1) {
}
if (content != null) {
String[] strs = content.split(e.cr);
int lineNumber = range[0];
for (int i = 0; i < strs.length; i++) {
msg.append("" + lineNumber).append("|").append(strs[i].trim()).append("\n");
lineNumber++;
}
}
if (error.hasCallStack()) {
msg.append(" ========================").append("\n");
msg.append(" 调用栈:").append("\n");
for (int i = 0; i < error.getResourceCallStack().size(); i++) {
msg.append(" " + error.getResourceCallStack().get(i) + " 行:").append(error.getTokenCallStack().get(i).line).append("\n");
}
Throwable t = error.getCause();
if (t != null) {
msg.append(t.toString()).append("\n");
}
}
render(writer, title.toString(), msg.toString());
try {
writer.flush();
} catch (IOException e1) {
}
}
use of org.beetl.core.ResourceLoader in project beetl2.0 by javamonkey.
the class CompositeResourceLoader method close.
@Override
public void close() {
Iterator<ResourceLoader> it = matcherResourceLoaderMap.values().iterator();
ResourceLoader rl = null;
while (it.hasNext()) {
rl = it.next();
rl.close();
}
}
Aggregations