Search in sources :

Example 36 with BeetlException

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
        }
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) IOException(java.io.IOException) ErrorGrammarProgram(org.beetl.core.statement.ErrorGrammarProgram) AjaxStatement(org.beetl.core.statement.AjaxStatement) GrammarToken(org.beetl.core.statement.GrammarToken) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 37 with BeetlException

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;
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) ErrorGrammarProgram(org.beetl.core.statement.ErrorGrammarProgram)

Example 38 with BeetlException

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;
}
Also used : BeetlException(org.beetl.core.exception.BeetlException)

Example 39 with BeetlException

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;
}
Also used : BeetlException(org.beetl.core.exception.BeetlException)

Example 40 with BeetlException

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;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) Program(org.beetl.core.statement.Program) ErrorGrammarProgram(org.beetl.core.statement.ErrorGrammarProgram) Reader(java.io.Reader) ErrorGrammarProgram(org.beetl.core.statement.ErrorGrammarProgram)

Aggregations

BeetlException (org.beetl.core.exception.BeetlException)60 GrammarToken (org.beetl.core.statement.GrammarToken)10 IOException (java.io.IOException)7 BeetlParserException (org.beetl.core.exception.BeetlParserException)6 Expression (org.beetl.core.statement.Expression)6 AndExpression (org.beetl.core.statement.AndExpression)5 ArthExpression (org.beetl.core.statement.ArthExpression)5 CompareExpression (org.beetl.core.statement.CompareExpression)5 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)5 FormatExpression (org.beetl.core.statement.FormatExpression)5 FunctionExpression (org.beetl.core.statement.FunctionExpression)5 IncDecExpression (org.beetl.core.statement.IncDecExpression)5 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)5 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)5 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)5 NegExpression (org.beetl.core.statement.NegExpression)5 NotBooleanExpression (org.beetl.core.statement.NotBooleanExpression)5 OrExpression (org.beetl.core.statement.OrExpression)5 StatementExpression (org.beetl.core.statement.StatementExpression)5 TernaryExpression (org.beetl.core.statement.TernaryExpression)5