Search in sources :

Example 6 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class ProcessingDirective method execute.

@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
    // dot notation
    Boolean dotNotationUpperCase = null;
    if (tag.containsAttribute("preservecase")) {
        Boolean preservecase = ASMUtil.getAttributeBoolean(tag, "preservecase", null);
        if (preservecase == null)
            throw new TemplateException(data.srcCode, "attribute [preserveCase] of the tag [processingdirective] must be a constant boolean value");
        dotNotationUpperCase = preservecase.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
        if (dotNotationUpperCase == data.settings.dotNotationUpper)
            dotNotationUpperCase = null;
    }
    // page encoding
    Charset cs = null;
    if (tag.containsAttribute("pageencoding")) {
        String str = ASMUtil.getAttributeString(tag, "pageencoding", null);
        if (str == null)
            throw new TemplateException(data.srcCode, "attribute [pageencoding] of the tag [processingdirective] must be a constant value");
        cs = CharsetUtil.toCharset(str);
        PageSourceCode psc = data.srcCode instanceof PageSourceCode ? (PageSourceCode) data.srcCode : null;
        if (psc == null || cs.equals(psc.getCharset())) {
            cs = null;
        }
    }
    // execution log
    Boolean exeLog = null;
    if (tag.containsAttribute("executionlog")) {
        String strExeLog = ASMUtil.getAttributeString(tag, "executionlog", null);
        exeLog = Caster.toBoolean(strExeLog, null);
        if (exeLog == null)
            throw new TemplateException(data.srcCode, "attribute [executionlog] of the tag [processingdirective] must be a constant boolean value");
        if (exeLog.booleanValue() == data.srcCode.getWriteLog())
            exeLog = null;
    }
    if (cs != null || exeLog != null || dotNotationUpperCase != null) {
        if (cs == null) {
            if (data.srcCode instanceof PageSourceCode)
                cs = ((PageSourceCode) data.srcCode).getCharset();
            else
                cs = CharsetUtil.UTF8;
        }
        if (exeLog == null)
            exeLog = data.srcCode.getWriteLog() ? Boolean.TRUE : Boolean.FALSE;
        if (dotNotationUpperCase == null)
            dotNotationUpperCase = data.settings.dotNotationUpper;
        throw new ProcessingDirectiveException(data.srcCode, cs, dotNotationUpperCase, exeLog);
    }
    return null;
}
Also used : PageSourceCode(lucee.transformer.util.PageSourceCode) TemplateException(lucee.runtime.exp.TemplateException) Charset(java.nio.charset.Charset)

Example 7 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method assignOp.

/**
 * Transfomiert Zuweisungs Operation.
 * <br />
 * EBNF:<br />
 * <code>eqvOp ["=" spaces assignOp];</code>
 * @return CFXD Element
 * @throws TemplateException
 */
protected Expression assignOp(ExprData data) throws TemplateException {
    Expression expr = conditionalOp(data);
    if (data.srcCode.forwardIfCurrent('=')) {
        comments(data);
        if (data.mode == STATIC)
            expr = new DynAssign(expr, assignOp(data));
        else {
            if (expr instanceof Variable) {
                Expression value = assignOp(data);
                expr = new Assign((Variable) expr, value, data.srcCode.getPosition());
            } else if (expr instanceof Null) {
                Variable var = ((Null) expr).toVariable();
                Expression value = assignOp(data);
                expr = new Assign(var, value, data.srcCode.getPosition());
            } else
                throw new TemplateException(data.srcCode, "invalid assignment left-hand side (" + expr.getClass().getName() + ")");
        }
    }
    // patch for test()();  only works at the end of an expression!
    comments(data);
    while (data.srcCode.isCurrent('(')) {
        comments(data);
        Call call = new Call(expr);
        getFunctionMemberAttrs(data, null, false, call, null);
        call.setEnd(data.srcCode.getPosition());
        comments(data);
        expr = call;
    }
    return expr;
}
Also used : Call(lucee.transformer.bytecode.expression.var.Call) Null(lucee.transformer.bytecode.literal.Null) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TemplateException(lucee.runtime.exp.TemplateException) DynAssign(lucee.transformer.bytecode.expression.var.DynAssign) Assign(lucee.transformer.bytecode.expression.var.Assign) DynAssign(lucee.transformer.bytecode.expression.var.DynAssign)

Example 8 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method dynamic.

/**
 * Liest den folgenden idetifier ein und prueft ob dieser ein boolscher Wert ist.
 * Im Gegensatz zu CFMX wird auch "yes" und "no" als bolscher <wert akzeptiert,
 * was bei CFMX nur beim Umwandeln einer Zeichenkette zu einem boolschen Wert der Fall ist.<br />
 * Wenn es sich um keinen bolschen Wert handelt wird der folgende Wert eingelesen mit seiner ganzen Hirarchie.
 * <br />
 * EBNF:<br />
 * <code>"true" | "false" | "yes" | "no" | startElement {("." identifier | "[" structElement "]" )[function] };</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression dynamic(ExprData data) throws TemplateException {
    // Die Implementation weicht ein wenig von der Grammatik ab,
    // aber nicht in der Logik sondern rein wie es umgesetzt wurde.
    // get First Element of the Variable
    Position line = data.srcCode.getPosition();
    Identifier id = identifier(data, false, true);
    if (id == null) {
        if (!data.srcCode.forwardIfCurrent('('))
            return null;
        comments(data);
        Expression expr = assignOp(data);
        if (!data.srcCode.forwardIfCurrent(')'))
            throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] not found");
        comments(data);
        // subDynamic(expr);
        return expr;
    }
    Variable var;
    comments(data);
    // Boolean constant
    if (id.getString().equalsIgnoreCase("TRUE")) {
        // || name.equals("YES"))	{
        comments(data);
        return id.getFactory().createLitBoolean(true, line, data.srcCode.getPosition());
    } else if (id.getString().equalsIgnoreCase("FALSE")) {
        // || name.equals("NO"))	{
        comments(data);
        return id.getFactory().createLitBoolean(false, line, data.srcCode.getPosition());
    } else if ((data.srcCode.getDialect() != CFMLEngine.DIALECT_CFML || data.config.getFullNullSupport()) && id.getString().equalsIgnoreCase("NULL")) {
        comments(data);
        return id.getFactory().createNull(line, data.srcCode.getPosition());
    }
    // Extract Scope from the Variable
    var = startElement(data, id, line);
    var.setStart(line);
    var.setEnd(data.srcCode.getPosition());
    return var;
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TemplateException(lucee.runtime.exp.TemplateException)

Example 9 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class Function method addAttribute.

public final void addAttribute(Attribute attr) throws TemplateException {
    String name = attr.getName().toLowerCase();
    // name
    if ("name".equals(name)) {
        throw new TransformerException("name cannot be defined twice", getStart());
    } else if ("returntype".equals(name)) {
        this.returnType = toLitString(name, attr.getValue());
    } else if ("access".equals(name)) {
        LitString ls = toLitString(name, attr.getValue());
        String strAccess = ls.getString();
        int acc = ComponentUtil.toIntAccess(strAccess, -1);
        if (acc == -1)
            throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
        access = acc;
    } else if ("output".equals(name))
        this.output = toLitBoolean(name, attr.getValue());
    else if ("bufferoutput".equals(name))
        this.bufferOutput = toLitBoolean(name, attr.getValue());
    else if ("displayname".equals(name))
        this.displayName = toLitString(name, attr.getValue());
    else if ("hint".equals(name))
        this.hint = toLitString(name, attr.getValue());
    else if ("description".equals(name))
        this.description = toLitString(name, attr.getValue());
    else if ("returnformat".equals(name))
        this.returnFormat = toLitString(name, attr.getValue());
    else if ("securejson".equals(name))
        this.secureJson = toLitBoolean(name, attr.getValue());
    else if ("verifyclient".equals(name))
        this.verifyClient = toLitBoolean(name, attr.getValue());
    else if ("localmode".equals(name)) {
        Expression v = attr.getValue();
        if (v != null) {
            String str = ASMUtil.toString(v, null);
            if (!StringUtil.isEmpty(str)) {
                int mode = AppListenerUtil.toLocalMode(str, -1);
                if (mode != -1)
                    this.localMode = v.getFactory().createLitInteger(mode);
                else
                    throw new TransformerException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)", getStart());
            }
        }
    } else if ("cachedwithin".equals(name)) {
        try {
            // ASMUtil.timeSpanToLong(attr.getValue());
            this.cachedWithin = ASMUtil.cachedWithinValue(attr.getValue());
        } catch (EvaluatorException e) {
            throw new TemplateException(e.getMessage());
        }
    } else if ("modifier".equals(name)) {
        Expression val = attr.getValue();
        if (val instanceof Literal) {
            Literal l = (Literal) val;
            String str = StringUtil.emptyIfNull(l.getString()).trim();
            if ("abstract".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_ABSTRACT;
            else if ("final".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_FINAL;
        }
    } else {
        // needed for testing
        toLitString(name, attr.getValue());
        if (metadata == null)
            metadata = new HashMap<String, Attribute>();
        metadata.put(attr.getName(), attr);
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Expression(lucee.transformer.expression.Expression) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TemplateException(lucee.runtime.exp.TemplateException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Literal(lucee.transformer.expression.literal.Literal) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) TransformerException(lucee.transformer.TransformerException)

Example 10 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class CFMLTransformer method createTemplateException.

public static TemplateException createTemplateException(SourceCode cfml, String msg, TagLibTag tag) {
    TemplateException te = new TemplateException(cfml, msg);
    setAddional(te, tag);
    return te;
}
Also used : ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException)

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)55 Position (lucee.transformer.Position)21 Expression (lucee.transformer.expression.Expression)18 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)15 LitString (lucee.transformer.expression.literal.LitString)14 ScriptBody (lucee.transformer.bytecode.ScriptBody)9 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 Body (lucee.transformer.bytecode.Body)8 BodyBase (lucee.transformer.bytecode.BodyBase)8 FunctionBody (lucee.transformer.bytecode.FunctionBody)8 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)8 Variable (lucee.transformer.expression.var.Variable)8 ExprString (lucee.transformer.expression.ExprString)7 TagLibTag (lucee.transformer.library.tag.TagLibTag)6 PageSourceCode (lucee.transformer.util.PageSourceCode)6 ArrayList (java.util.ArrayList)5 OpVariable (lucee.transformer.bytecode.op.OpVariable)5 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)5 Resource (lucee.commons.io.res.Resource)4 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)4