Search in sources :

Example 11 with TagLibTagAttr

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

the class ConfigImpl method createTag.

public void createTag(TagLib tl, String filename) {
    // Jira 1298
    // filename.substring(0,filename.length()-(getCFCExtension().length()+1));
    String name = toName(filename);
    TagLibTag tlt = new TagLibTag(tl);
    tlt.setName(name);
    tlt.setTagClassDefinition("lucee.runtime.tag.CFTagCore", getIdentification(), null);
    tlt.setHandleExceptions(true);
    tlt.setBodyContent("free");
    tlt.setParseBody(false);
    tlt.setDescription("");
    tlt.setAttributeType(TagLibTag.ATTRIBUTE_TYPE_MIXED);
    TagLibTagAttr tlta = new TagLibTagAttr(tlt);
    tlta.setName("__filename");
    tlta.setRequired(true);
    tlta.setRtexpr(true);
    tlta.setType("string");
    tlta.setHidden(true);
    tlta.setDefaultValue(filename);
    tlt.setAttribute(tlta);
    tlta = new TagLibTagAttr(tlt);
    tlta.setName("__name");
    tlta.setRequired(true);
    tlta.setRtexpr(true);
    tlta.setHidden(true);
    tlta.setType("string");
    tlta.setDefaultValue(name);
    tlt.setAttribute(tlta);
    tlta = new TagLibTagAttr(tlt);
    tlta.setName("__isweb");
    tlta.setRequired(true);
    tlta.setRtexpr(true);
    tlta.setHidden(true);
    tlta.setType("boolean");
    tlta.setDefaultValue(this instanceof ConfigWeb ? "true" : "false");
    tlt.setAttribute(tlta);
    tl.setTag(tlt);
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TagLibTag(lucee.transformer.library.tag.TagLibTag)

Example 12 with TagLibTagAttr

use of lucee.transformer.library.tag.TagLibTagAttr 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 13 with TagLibTagAttr

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

the class AbstrCFMLScriptTransformer method __singleAttrStatement.

private final Statement __singleAttrStatement(Body parent, ExprData data, TagLibTag tlt, boolean allowTwiceAttr) throws TemplateException {
    String tagName = tlt.getName();
    if (data.srcCode.forwardIfCurrent(tagName)) {
        if (!data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent(';')) {
            data.srcCode.setPos(data.srcCode.getPos() - tagName.length());
            return null;
        }
    } else
        return null;
    int pos = data.srcCode.getPos() - tagName.length();
    Position line = data.srcCode.getPosition();
    // TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,tagName.equals("pageencoding")?"processingdirective":tagName);
    Tag tag = getTag(data, parent, tlt, line, null);
    tag.setScriptBase(true);
    tag.setTagLibTag(tlt);
    comments(data);
    // attribute
    TagLibTagAttr attr = tlt.getScript().getSingleAttr();
    String attrName = null;
    Expression attrValue = null;
    short attrType = ATTR_TYPE_NONE;
    if (attr != null) {
        attrType = attr.getScriptSupport();
        char c = data.srcCode.getCurrent();
        if (ATTR_TYPE_REQUIRED == attrType || (!data.srcCode.isCurrent(';') && ATTR_TYPE_OPTIONAL == attrType)) {
            if (data.srcCode.isCurrent('{')) {
                // this can be only a json string
                int p = data.srcCode.getPos();
                try {
                    attrValue = isSimpleValue(attr.getType()) ? null : json(data, JSON_STRUCT, '{', '}');
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                    data.srcCode.setPos(p);
                }
            } else
                attrValue = attributeValue(data, tlt.getScript().getRtexpr());
            if (attrValue != null && isOperator(c)) {
                data.srcCode.setPos(pos);
                return null;
            }
        }
    }
    if (attrValue != null) {
        attrName = attr.getName();
        TagLibTagAttr tlta = tlt.getAttribute(attr.getName(), true);
        tag.addAttribute(new Attribute(false, attrName, CastOther.toExpression(attrValue, tlta.getType()), tlta.getType()));
    } else if (ATTR_TYPE_REQUIRED == attrType) {
        data.srcCode.setPos(pos);
        return null;
    }
    // body
    if (tlt.getHasBody()) {
        Body body = new BodyBase(data.factory);
        boolean wasSemiColon = statement(data, body, tlt.getScript().getContext());
        if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
            tag.setBody(body);
    } else
        checkSemiColonLineFeed(data, true, true, true);
    if (tlt.hasTTE())
        data.ep.add(tlt, tag, data.flibs, data.srcCode);
    if (!StringUtil.isEmpty(attrName))
        validateAttributeName(attrName, data.srcCode, new ArrayList<String>(), tlt, new RefBooleanImpl(false), new StringBuffer(), allowTwiceAttr);
    tag.setEnd(data.srcCode.getPosition());
    eval(tlt, data, tag);
    return tag;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ArrayList(java.util.ArrayList) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 14 with TagLibTagAttr

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

the class AbstrCFMLScriptTransformer method validateAttributeName.

private final String validateAttributeName(String idOC, SourceCode cfml, ArrayList<String> args, TagLibTag tag, RefBoolean dynamic, StringBuffer sbType, boolean allowTwiceAttr) throws TemplateException {
    String idLC = idOC.toLowerCase();
    if (args.contains(idLC) && !allowTwiceAttr)
        throw new TemplateException(cfml, "you can't use the same attribute [" + idOC + "] twice");
    args.add(idLC);
    if (tag == null)
        return idOC;
    int typeDef = tag.getAttributeType();
    if ("attributecollection".equals(idLC)) {
        dynamic.setValue(tag.getAttribute(idLC, true) == null);
        sbType.append("struct");
    } else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED || typeDef == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
        TagLibTagAttr attr = tag.getAttribute(idLC, true);
        if (attr == null) {
            if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED) {
                String names = tag.getAttributeNames();
                if (StringUtil.isEmpty(names))
                    throw new TemplateException(cfml, "Attribute " + idOC + " is not allowed for tag " + tag.getFullName());
                throw new TemplateException(cfml, "Attribute " + idOC + " is not allowed for statement " + tag.getName(), "valid attribute names are [" + names + "]");
            }
            dynamic.setValue(true);
        } else {
            idOC = attr.getName();
            idLC = idOC.toLowerCase();
            sbType.append(attr.getType());
        // parseExpression[0]=attr.getRtexpr();
        }
    } else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_DYNAMIC) {
        dynamic.setValue(true);
    }
    return idOC;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TemplateException(lucee.runtime.exp.TemplateException)

Example 15 with TagLibTagAttr

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

the class ApplicationContextSupport method _initTagDefaultAttributeValues.

private static void _initTagDefaultAttributeValues(Config config, TagLib lib, Map<Collection.Key, Map<Collection.Key, Object>> tagDefaultAttributeValues, Struct sct, boolean checkNameSpace) {
    if (sct == null)
        return;
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    // loop tags
    Struct attrs;
    TagLibTag tag;
    Iterator<Entry<Key, Object>> iit;
    Entry<Key, Object> e;
    Map<Collection.Key, Object> map;
    TagLibTagAttr attr;
    String name;
    while (it.hasNext()) {
        e = it.next();
        attrs = Caster.toStruct(e.getValue(), null);
        if (attrs != null) {
            tag = null;
            if (checkNameSpace) {
                name = e.getKey().getLowerString();
                if (StringUtil.startsWithIgnoreCase(name, lib.getNameSpaceAndSeparator())) {
                    name = name.substring(lib.getNameSpaceAndSeparator().length());
                    tag = lib.getTag(name);
                }
            } else
                tag = lib.getTag(e.getKey().getLowerString());
            if (tag != null) {
                sct.removeEL(e.getKey());
                map = new HashMap<Collection.Key, Object>();
                iit = attrs.entryIterator();
                while (iit.hasNext()) {
                    e = iit.next();
                    map.put(KeyImpl.init(e.getKey().getLowerString()), e.getValue());
                }
                tagDefaultAttributeValues.put(KeyImpl.init(tag.getFullName()), map);
            }
        }
    }
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TagLibTag(lucee.transformer.library.tag.TagLibTag) Entry(java.util.Map.Entry) Key(lucee.runtime.type.Collection.Key) Struct(lucee.runtime.type.Struct)

Aggregations

TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)17 Entry (java.util.Map.Entry)8 TagLibTag (lucee.transformer.library.tag.TagLibTag)8 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)6 TemplateException (lucee.runtime.exp.TemplateException)5 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)4 Key (lucee.runtime.type.Collection.Key)4 Struct (lucee.runtime.type.Struct)4 Expression (lucee.transformer.expression.Expression)4 LitString (lucee.transformer.expression.literal.LitString)4 ArrayList (java.util.ArrayList)3 RefBoolean (lucee.commons.lang.types.RefBoolean)3 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)3 StructImpl (lucee.runtime.type.StructImpl)2 Position (lucee.transformer.Position)2 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)2 ClassException (lucee.commons.lang.ClassException)1 Component (lucee.runtime.Component)1 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)1 Member (lucee.runtime.component.Member)1