use of org.beetl.core.statement.GrammarToken in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseOneIncDecContext.
protected IncDecExpression parseOneIncDecContext(OneIncDecContext ctx) {
IncDecExpression exp = null;
boolean isInc = ctx.INCREASE() != null;
GrammarToken t = this.getBTToken(ctx.Identifier().getSymbol());
exp = new IncDecExpression(isInc, true, t);
this.pbCtx.setVarPosition(t.text, exp);
return exp;
}
use of org.beetl.core.statement.GrammarToken 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.statement.GrammarToken in project beetl2.0 by javamonkey.
the class LineStatus method transform.
public Reader transform(Reader orginal) throws IOException, HTMLTagParserException {
StringBuilder temp = new StringBuilder();
int bufSzie = 1024;
cs = new char[bufSzie];
int len = -1;
while ((len = orginal.read(cs)) != -1) {
temp.append(cs, 0, len);
}
cs = temp.toString().toCharArray();
// 找到回车换行符号
findCR();
checkAppendCR();
parser();
if (this.isSupportHtmlTag && this.htmlTagStack.size() != 0) {
String tagName = (String) htmlTagStack.peek();
GrammarToken token = GrammarToken.createToken(tagName, this.totalLineCount + 1);
HTMLTagParserException ex = new HTMLTagParserException("解析html tag 标签出错,未找到匹配结束标签 " + tagName);
ex.pushToken(token);
ex.line = totalLineCount + 1;
this.clear();
throw ex;
}
orginal.close();
return new StringReader(sb.toString());
}
Aggregations