Search in sources :

Example 1 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.

the class CFTag method validateAttributes.

private static void validateAttributes(Component cfc, StructImpl attributesScope, String tagName) throws ApplicationException, ExpressionException {
    TagLibTag tag = getAttributeRequirments(cfc, false);
    if (tag == null)
        return;
    if (tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_FIXED || tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
        Iterator<Entry<String, TagLibTagAttr>> it = tag.getAttributes().entrySet().iterator();
        int count = 0;
        Collection.Key key;
        TagLibTagAttr attr;
        Object value;
        Entry<String, TagLibTagAttr> entry;
        // check existing attributes
        while (it.hasNext()) {
            entry = it.next();
            count++;
            key = KeyImpl.toKey(entry.getKey(), null);
            attr = entry.getValue();
            value = attributesScope.get(key, null);
            // check alias
            if (value == null) {
                String[] alias = attr.getAlias();
                if (!ArrayUtil.isEmpty(alias))
                    for (int i = 0; i < alias.length; i++) {
                        value = attributesScope.get(KeyImpl.toKey(alias[i], null), null);
                        if (value != null)
                            break;
                    }
            }
            if (value == null) {
                if (attr.getDefaultValue() != null) {
                    value = attr.getDefaultValue();
                    attributesScope.setEL(key, value);
                } else if (attr.isRequired())
                    throw new ApplicationException("attribute [" + key.getString() + "] is required for tag [" + tagName + "]");
            }
            if (value != null) {
                if (!Decision.isCastableTo(attr.getType(), value, true, true, -1))
                    throw new CasterException(createMessage(attr.getType(), value));
            }
        }
        // check if there are attributes not supported
        if (tag.getAttributeType() == TagLibTag.ATTRIBUTE_TYPE_FIXED && count < attributesScope.size()) {
            Collection.Key[] keys = attributesScope.keys();
            for (int i = 0; i < keys.length; i++) {
                if (tag.getAttribute(keys[i].getLowerString(), true) == null)
                    throw new ApplicationException("attribute [" + keys[i].getString() + "] is not supported for tag [" + tagName + "]");
            }
        // Attribute susi is not allowed for tag cfmail
        }
    }
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TagLibTag(lucee.transformer.library.tag.TagLibTag) CasterException(lucee.runtime.exp.CasterException) Key(lucee.runtime.type.Collection.Key) Entry(java.util.Map.Entry) ApplicationException(lucee.runtime.exp.ApplicationException) Collection(lucee.runtime.type.Collection) Key(lucee.runtime.type.Collection.Key)

Example 2 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.

the class ConfigImpl method addTag.

protected void addTag(String nameSpace, String nameSpaceSeperator, String name, int dialect, ClassDefinition cd) {
    if (dialect == CFMLEngine.DIALECT_BOTH) {
        addTag(nameSpace, nameSpaceSeperator, name, CFMLEngine.DIALECT_CFML, cd);
        addTag(nameSpace, nameSpaceSeperator, name, CFMLEngine.DIALECT_LUCEE, cd);
        return;
    }
    TagLib[] tlds = dialect == CFMLEngine.DIALECT_CFML ? cfmlTlds : luceeTlds;
    for (int i = 0; i < tlds.length; i++) {
        if (tlds[i].getNameSpaceAndSeparator().equalsIgnoreCase(nameSpace + nameSpaceSeperator)) {
            TagLibTag tlt = new TagLibTag(tlds[i]);
            tlt.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_DYNAMIC);
            tlt.setBodyContent("free");
            tlt.setTagClassDefinition(cd);
            tlt.setName(name);
            tlds[i].setTag(tlt);
        }
    }
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) TagLib(lucee.transformer.library.tag.TagLib)

Example 3 with TagLibTag

use of lucee.transformer.library.tag.TagLibTag 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 TagLibTag

use of lucee.transformer.library.tag.TagLibTag 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 TagLibTag

use of lucee.transformer.library.tag.TagLibTag in project Lucee by lucee.

the class Interface method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
    super.evaluate(tag, libTag);
    Body body = tag.getBody();
    List<Statement> statments = body.getStatements();
    Statement stat;
    Iterator<Statement> it = statments.iterator();
    Tag t;
    while (it.hasNext()) {
        stat = it.next();
        if (stat instanceof PrintOut) {
        // body.remove(stat);
        } else if (stat instanceof Tag) {
            t = (Tag) stat;
            if (stat instanceof TagImport) {
            // ignore
            } else if (stat instanceof TagFunction) {
                Function.throwIfNotEmpty(t);
                Attribute attr = t.getAttribute("access");
                if (attr != null) {
                    ExprString expr = t.getFactory().toExprString(attr.getValue());
                    if (!(expr instanceof LitString))
                        throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
                    String access = ((LitString) expr).getString().trim();
                    if (!"public".equalsIgnoreCase(access))
                        throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
                } else
                    t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
            } else
                throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
        }
    }
}
Also used : TagFunction(lucee.transformer.bytecode.statement.tag.TagFunction) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ExprString(lucee.transformer.expression.ExprString) Statement(lucee.transformer.bytecode.Statement) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) TagImport(lucee.transformer.bytecode.statement.tag.TagImport) LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body)

Aggregations

TagLibTag (lucee.transformer.library.tag.TagLibTag)28 Tag (lucee.transformer.bytecode.statement.tag.Tag)12 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)11 TagLib (lucee.transformer.library.tag.TagLib)9 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)8 Body (lucee.transformer.bytecode.Body)7 TemplateException (lucee.runtime.exp.TemplateException)6 Position (lucee.transformer.Position)6 BodyBase (lucee.transformer.bytecode.BodyBase)6 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)6 LitString (lucee.transformer.expression.literal.LitString)6 Statement (lucee.transformer.bytecode.Statement)5 Entry (java.util.Map.Entry)3 Key (lucee.runtime.type.Collection.Key)3 Struct (lucee.runtime.type.Struct)3 FunctionBody (lucee.transformer.bytecode.FunctionBody)3 Page (lucee.transformer.bytecode.Page)3 ScriptBody (lucee.transformer.bytecode.ScriptBody)3 Expression (lucee.transformer.expression.Expression)3 ArrayList (java.util.ArrayList)2