Search in sources :

Example 1 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Component method evaluate.

@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
    tagLibTag.setParseBody(false);
    Attribute attr = tag.getAttribute("output");
    if (attr != null) {
        Expression expr = attr.getValue();
        if (!(expr instanceof LitBoolean))
            throw new AttributeEvaluatorException("Attribute output of the Tag Component, must be a static boolean value (true or false)");
        if (((LitBoolean) expr).getBooleanValue())
            tagLibTag.setParseBody(true);
    }
    return tagLibTag;
}
Also used : AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean)

Example 2 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Function method evaluate.

@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
    tagLibTag.setParseBody(false);
    Attribute attrOutput = tag.getAttribute("output");
    if (attrOutput == null)
        return tagLibTag;
    Expression expr = CastBoolean.toExprBoolean(attrOutput.getValue());
    if (!(expr instanceof LitBoolean))
        throw new AttributeEvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false)");
    boolean output = ((LitBoolean) expr).getBooleanValue();
    if (output)
        tagLibTag.setParseBody(true);
    return tagLibTag;
}
Also used : AttributeEvaluatorException(lucee.transformer.cfml.attributes.AttributeEvaluatorException) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean)

Example 3 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Transaction method evaluate.

@Override
public TagLibTag evaluate(TagLibTag tagLibTag, Tag tag) throws AttributeEvaluatorException {
    Attribute action = tag.getAttribute("action");
    if (action != null) {
        Tag parent = ASMUtil.getAncestorTag(tag, tag.getFullname());
        if (parent != null) {
            tagLibTag = tagLibTag.duplicate(false);
            tagLibTag.setBodyContent("empty");
        }
    }
    return tagLibTag;
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Tag(lucee.transformer.bytecode.statement.tag.Tag) TagLibTag(lucee.transformer.library.tag.TagLibTag)

Example 4 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Argument method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    String ns = libTag.getTagLib().getNameSpaceAndSeparator();
    String functionName = ns + "function";
    ASMUtil.isLiteralAttribute(tag, "type", ASMUtil.TYPE_STRING, false, true);
    ASMUtil.isLiteralAttribute(tag, "name", ASMUtil.TYPE_STRING, false, true);
    // ASMUtil.isLiteralAttribute(tag,"hint",ASMUtil.TYPE_STRING,false,true);
    // ASMUtil.isLiteralAttribute(tag,"displayname",ASMUtil.TYPE_STRING,false,true);
    // check if default can be converted to a literal value that match the type declration.
    checkDefaultValue(tag);
    // check attribute passby
    Attribute attrPassBy = tag.getAttribute("passby");
    if (attrPassBy != null) {
        ExprString expr = tag.getFactory().toExprString(attrPassBy.getValue());
        if (!(expr instanceof LitString))
            throw new EvaluatorException("Attribute passby of the Tag Argument, must be a literal string");
        LitString lit = (LitString) expr;
        String passBy = lit.getString().toLowerCase().trim();
        if (!"value".equals(passBy) && !"ref".equals(passBy) && !"reference".equals(passBy))
            throw new EvaluatorException("Attribute passby of the Tag Argument has an invalid value [" + passBy + "], valid values are [reference,value]");
    }
    // check if tag is direct inside function
    if (!ASMUtil.isParentTag(tag, functionName)) {
        Tag parent = ASMUtil.getParentTag(tag);
        String addText = (parent != null) ? "but tag " + libTag.getFullName() + " is inside tag " + parent.getFullname() + "" : "but tag " + libTag.getFullName() + " has no parent";
        throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be direct inside a " + functionName + " tag, " + addText);
    }
// TODO check if there is a tag other than argument and text before
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) Tag(lucee.transformer.bytecode.statement.tag.Tag) TagLibTag(lucee.transformer.library.tag.TagLibTag)

Example 5 with Attribute

use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.

the class Argument method checkDefaultValue.

public static void checkDefaultValue(Tag tag) {
    Attribute _type = tag.getAttribute("type");
    if (_type != null) {
        ExprString typeValue = tag.getFactory().toExprString(_type.getValue());
        if (typeValue instanceof LitString) {
            String strType = ((LitString) typeValue).getString();
            Attribute _default = tag.getAttribute("default");
            if (_default != null) {
                Expression defaultValue = _default.getValue();
                if (defaultValue instanceof LitString) {
                    String strDefault = ((LitString) defaultValue).getString();
                    // check for boolean
                    if ("boolean".equalsIgnoreCase(strType)) {
                        if ("true".equalsIgnoreCase(strDefault) || "yes".equalsIgnoreCase(strDefault))
                            tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().TRUE(), _default.getType()));
                        if ("false".equalsIgnoreCase(strDefault) || "no".equalsIgnoreCase(strDefault))
                            tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().FALSE(), _default.getType()));
                    }
                    // check for numbers
                    if ("number".equalsIgnoreCase(strType) || "numeric".equalsIgnoreCase(strType)) {
                        Double dbl = Caster.toDouble(strDefault, null);
                        if (dbl != null) {
                            tag.addAttribute(new Attribute(_default.isDynamicType(), _default.getName(), tag.getFactory().createLitDouble(dbl.doubleValue()), _default.getType()));
                        }
                    }
                }
            }
        }
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Aggregations

Attribute (lucee.transformer.bytecode.statement.tag.Attribute)35 Expression (lucee.transformer.expression.Expression)16 LitString (lucee.transformer.expression.literal.LitString)13 TagLibTag (lucee.transformer.library.tag.TagLibTag)11 TemplateException (lucee.runtime.exp.TemplateException)10 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)9 Tag (lucee.transformer.bytecode.statement.tag.Tag)8 LitBoolean (lucee.transformer.expression.literal.LitBoolean)8 Body (lucee.transformer.bytecode.Body)7 Literal (lucee.transformer.expression.literal.Literal)6 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)6 Position (lucee.transformer.Position)5 ExprString (lucee.transformer.expression.ExprString)5 ArrayList (java.util.ArrayList)4 RefBoolean (lucee.commons.lang.types.RefBoolean)4 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)4 BodyBase (lucee.transformer.bytecode.BodyBase)4 FunctionBody (lucee.transformer.bytecode.FunctionBody)4 Page (lucee.transformer.bytecode.Page)4 ScriptBody (lucee.transformer.bytecode.ScriptBody)4