Search in sources :

Example 41 with TemplateException

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

the class CFMLTransformer method attribute.

/**
 * Liest ein einzelnes Atribut eines tag ein (nicht NONAME).
 * <br />
 * EBNF:<br />
 * <code>attribute-name  spaces "=" spaces attribute-value;</code>
 * @param tag Definition des Tag das dieses Attribut enthaelt.
 * @param args Container zum Speichern einzelner Attribute Namen zum nachtraeglichen Prufen gegen die Tag-Lib.
 * @return Element Attribute Element.
 * @throws TemplateException
 */
private static Attribute attribute(TagData data, TagLibTag tag, ArrayList<String> args, RefBoolean allowDefaultValue) throws TemplateException {
    Expression value = null;
    // Name
    StringBuffer sbType = new StringBuffer();
    RefBoolean dynamic = new RefBooleanImpl(false);
    boolean isDefaultValue = false;
    boolean[] parseExpression = new boolean[2];
    parseExpression[0] = true;
    parseExpression[1] = false;
    String name = attributeName(data.srcCode, dynamic, args, tag, sbType, parseExpression, allowDefaultValue.toBooleanValue());
    // mixed in a noname attribute
    if (StringUtil.isEmpty(name)) {
        allowDefaultValue.setValue(false);
        TagLibTagAttr attr = tag.getDefaultAttribute();
        if (attr == null)
            throw new TemplateException(data.srcCode, "Invalid Identifier.");
        name = attr.getName();
        sbType.append(attr.getType());
        isDefaultValue = true;
    }
    comment(data.srcCode, true);
    if (isDefaultValue || data.srcCode.forwardIfCurrent('=')) {
        comment(data.srcCode, true);
        // Value
        value = attributeValue(data, tag, sbType.toString(), parseExpression[0], false, data.factory.createLitString(""));
    } else // default value boolean true
    {
        TagLibTagAttr attr = tag.getAttribute(name);
        if (attr != null)
            value = attr.getUndefinedValue(data.factory);
        else
            value = tag.getAttributeUndefinedValue(data.factory);
        if (sbType.toString().length() > 0) {
            value = CastOther.toExpression(value, sbType.toString());
        }
    }
    comment(data.srcCode, true);
    return new Attribute(dynamic.toBooleanValue(), name, value, sbType.toString());
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) RefBoolean(lucee.commons.lang.types.RefBoolean) Expression(lucee.transformer.expression.Expression) ComponentTemplateException(lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException) TemplateException(lucee.runtime.exp.TemplateException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) LitString(lucee.transformer.expression.literal.LitString) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Example 42 with TemplateException

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

the class PageEncoding method execute.

@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
    // encoding
    String str = ASMUtil.getAttributeString(tag, "charset", null);
    if (str == null)
        throw new TemplateException(data.srcCode, "attribute [pageencoding] of the tag [processingdirective] must be a constant value");
    Charset cs = CharsetUtil.toCharset(str);
    PageSourceCode psc = data.srcCode instanceof PageSourceCode ? (PageSourceCode) data.srcCode : null;
    if (psc == null || cs.equals(psc.getCharset()) || CharsetUtil.UTF8.equals(psc.getCharset())) {
        cs = null;
    }
    if (cs != null) {
        throw new ProcessingDirectiveException(data.srcCode, cs, null, data.srcCode.getWriteLog());
    }
    return null;
}
Also used : PageSourceCode(lucee.transformer.util.PageSourceCode) TemplateException(lucee.runtime.exp.TemplateException) Charset(java.nio.charset.Charset)

Example 43 with TemplateException

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

the class AbstrCFMLExprTransformer method conditionalOp.

private Expression conditionalOp(ExprData data) throws TemplateException {
    Expression expr = impOp(data);
    if (data.srcCode.forwardIfCurrent('?')) {
        comments(data);
        // Elvis
        if (data.srcCode.forwardIfCurrent(':')) {
            comments(data);
            Expression right = assignOp(data);
            if (expr instanceof ExprBoolean)
                return expr;
            if (!(expr instanceof Variable))
                throw new TemplateException(data.srcCode, "left operand of the Elvis operator has to be a variable or a function call");
            Variable left = (Variable) expr;
            /*List<Member> members = left.getMembers();
				Member last=null;
				for(Member m:members) {
					last=m;
					m.setSafeNavigated(true);
				}
				if(last!=null) {
					last.setSafeNavigatedValue(right);
				}
				return left;*/
            return OpElvis.toExpr(left, right);
        }
        Expression left = assignOp(data);
        comments(data);
        if (!data.srcCode.forwardIfCurrent(':'))
            throw new TemplateException(data.srcCode, "invalid conditional operator");
        comments(data);
        Expression right = assignOp(data);
        expr = OpContional.toExpr(expr, left, right);
    }
    return expr;
}
Also used : 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) ExprBoolean(lucee.transformer.expression.ExprBoolean)

Example 44 with TemplateException

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

the class AbstrCFMLExprTransformer method checker.

/**
 * Hier werden die verschiedenen Moeglichen Werte erkannt
 * und jenachdem wird mit der passenden Methode weitergefahren
 * <br />
 * EBNF:<br />
 * <code>string | number | dynamic | sharp;</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression checker(ExprData data) throws TemplateException {
    Expression expr = null;
    // String
    if ((expr = string(data)) != null) {
        expr = subDynamic(data, expr, false, false);
        // (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
        data.mode = STATIC;
        return expr;
    }
    // Number
    if ((expr = number(data)) != null) {
        expr = subDynamic(data, expr, false, false);
        // (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
        data.mode = STATIC;
        return expr;
    }
    // closure
    if ((expr = closure(data)) != null) {
        data.mode = DYNAMIC;
        return expr;
    }
    // lambda
    if ((expr = lambda(data)) != null) {
        data.mode = DYNAMIC;
        return expr;
    }
    // Dynamic
    if ((expr = dynamic(data)) != null) {
        expr = newOp(data, expr);
        expr = subDynamic(data, expr, true, false);
        data.mode = DYNAMIC;
        return expr;
    }
    // Sharp
    if ((expr = sharp(data)) != null) {
        data.mode = DYNAMIC;
        return expr;
    }
    // JSON
    if ((expr = json(data, JSON_ARRAY, '[', ']')) != null) {
        expr = subDynamic(data, expr, false, false);
        data.mode = DYNAMIC;
        return expr;
    }
    if ((expr = json(data, JSON_STRUCT, '{', '}')) != null) {
        expr = subDynamic(data, expr, false, false);
        data.mode = DYNAMIC;
        return expr;
    }
    // else Error
    throw new TemplateException(data.srcCode, "Syntax Error, Invalid Construct");
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TemplateException(lucee.runtime.exp.TemplateException)

Example 45 with TemplateException

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

the class AbstrCFMLExprTransformer method subDynamic.

private Expression subDynamic(ExprData data, Expression expr, boolean tryStatic, boolean isStaticChild) throws TemplateException {
    String name = null;
    Invoker invoker = null;
    // Loop over nested Variables
    boolean safeNavigation;
    while (data.srcCode.isValidIndex()) {
        safeNavigation = false;
        ExprString nameProp = null, namePropUC = null;
        // []
        if (data.srcCode.forwardIfCurrent('[')) {
            isStaticChild = false;
            // get Next Var
            nameProp = structElement(data);
            namePropUC = nameProp;
            // Valid Syntax ???
            if (!data.srcCode.forwardIfCurrent(']'))
                throw new TemplateException(data.srcCode, "Invalid Syntax Closing []] not found");
        } else // .
        if (isStaticChild || data.srcCode.forwardIfCurrent('.') || (safeNavigation = data.srcCode.forwardIfCurrent('?', '.'))) {
            isStaticChild = false;
            // Extract next Var String
            comments(data);
            Position line = data.srcCode.getPosition();
            name = identifier(data, true);
            if (name == null)
                throw new TemplateException(data.srcCode, "Invalid identifier");
            comments(data);
            nameProp = Identifier.toIdentifier(data.factory, name, line, data.srcCode.getPosition());
            namePropUC = Identifier.toIdentifier(data.factory, name, data.settings.dotNotationUpper ? Identifier.CASE_UPPER : Identifier.CASE_ORIGNAL, line, data.srcCode.getPosition());
        } else // finish
        {
            break;
        }
        comments(data);
        if (expr instanceof Invoker) {
            invoker = (Invoker) expr;
        } else {
            invoker = new ExpressionInvoker(expr);
            expr = invoker;
        }
        // safe navigation
        Member member;
        if (safeNavigation) {
            List<Member> members = invoker.getMembers();
            if (members.size() > 0) {
                member = members.get(members.size() - 1);
                member.setSafeNavigated(true);
            }
        }
        // Method
        if (data.srcCode.isCurrent('(')) {
            // properly this is never used
            if (nameProp == null && name != null)
                nameProp = Identifier.toIdentifier(data.factory, name, Identifier.CASE_ORIGNAL, null, null);
            invoker.addMember(member = getFunctionMember(data, nameProp, false));
        } else
            // property
            invoker.addMember(member = data.factory.createDataMember(namePropUC));
        if (safeNavigation) {
            member.setSafeNavigated(true);
        }
    }
    // STATIC SCOPE CALL
    if (tryStatic) {
        comments(data);
        Expression staticCall = staticScope(data, expr);
        if (staticCall != null)
            return staticCall;
    }
    return expr;
}
Also used : ExpressionInvoker(lucee.transformer.bytecode.expression.ExpressionInvoker) Invoker(lucee.transformer.expression.Invoker) ExpressionInvoker(lucee.transformer.bytecode.expression.ExpressionInvoker) ExprString(lucee.transformer.expression.ExprString) TemplateException(lucee.runtime.exp.TemplateException) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

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