use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class Template method renderTo.
public void renderTo(ByteWriter byteWriter) {
try {
ctx.byteWriter = byteWriter;
ctx.byteOutputMode = cf.directByteOutput;
ctx.gt = this.gt;
ctx.template = this;
if (gt.sharedVars != null) {
for (Entry<String, Object> entry : gt.sharedVars.entrySet()) {
ctx.set(entry.getKey(), entry.getValue());
}
}
program.metaData.initContext(ctx);
if (ajaxId != null) {
AjaxStatement ajax = program.metaData.getAjax(ajaxId);
if (ajax == null) {
BeetlException be = new BeetlException(BeetlException.AJAX_NOT_FOUND);
be.pushToken(new GrammarToken(ajaxId, 0, 0));
throw be;
}
ajax.execute(ctx);
} else {
program.execute(ctx);
}
if (isRoot) {
byteWriter.flush();
}
} catch (BeetlException e) {
if (!(program instanceof ErrorGrammarProgram)) {
e.pushResource(this.program.res);
}
// 是否打印异常,只有根模板才能打印异常
if (!isRoot)
throw e;
if (e.detailCode == BeetlException.CLIENT_IO_ERROR_ERROR && ctx.gt.conf.isIgnoreClientIOError) {
return;
}
Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter);
e.gt = this.program.gt;
e.cr = this.program.metaData.lineSeparator;
ErrorHandler errorHandler = this.gt.getErrorHandler();
if (errorHandler == null) {
throw e;
}
errorHandler.processExcption(e, w);
try {
ctx.byteWriter.flush();
} catch (IOException e1) {
// 输出到客户端
}
} catch (IOException e) {
if (!ctx.gt.conf.isIgnoreClientIOError) {
BeetlException be = new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, e.getMessage(), e);
be.pushResource(this.program.res);
be.pushToken(new GrammarToken(this.program.res.id, 0, 0));
ErrorHandler errorHandler = this.gt.getErrorHandler();
if (errorHandler == null) {
throw be;
}
Writer w = BeetlUtil.getWriterByByteWriter(ctx.byteWriter);
errorHandler.processExcption(be, w);
try {
ctx.byteWriter.flush();
} catch (IOException e1) {
// 输出到客户端
}
} else {
// do nothing ,just ignore
}
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class Template method validate.
/**
* 语法校验,如果返回BeetlException,则表示语法有错,返回null,语法无错误
* @return
*/
public BeetlException validate() {
if (!(program instanceof ErrorGrammarProgram)) {
return null;
}
ErrorGrammarProgram error = (ErrorGrammarProgram) program;
BeetlException exception = error.getException();
return exception;
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class ALU method valueIsNullException.
private static RuntimeException valueIsNullException(final Object o1, ASTNode node1) {
BeetlException ex = new BeetlException(BeetlException.NULL);
ex.pushToken(node1.token);
throw ex;
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class ALU method numberExpectedException.
private static RuntimeException numberExpectedException(final Object o1, ASTNode node1) {
BeetlException ex = new BeetlException(BeetlException.NUMBER_EXPECTED_ERROR);
ex.pushToken(node1.token);
throw ex;
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class GroupTemplate method loadScript.
private Program loadScript(Resource res) {
try {
Reader scriptReader = res.openReader();
Program program = engine.createProgram(res, scriptReader, Collections.EMPTY_MAP, System.getProperty("line.separator"), this);
return program;
} catch (BeetlException ex) {
ErrorGrammarProgram ep = new ErrorGrammarProgram(res, this, System.getProperty("line.separator"));
ex.pushResource(res);
ep.setException(ex);
return ep;
}
}
Aggregations