Search in sources :

Example 1 with TagLibTagScript

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

the class AbstrCFMLScriptTransformer method __multiAttrStatement.

private final Tag __multiAttrStatement(Body parent, ExprData data, TagLibTag tlt) throws TemplateException {
    if (data.ep == null)
        return null;
    String type = tlt.getName();
    if (data.srcCode.forwardIfCurrent(type) || // lucee dialect support component as alias for class
    (data.srcCode.getDialect() == CFMLEngine.DIALECT_LUCEE && type.equalsIgnoreCase(Constants.LUCEE_COMPONENT_TAG_NAME) && data.srcCode.forwardIfCurrent(Constants.CFML_COMPONENT_TAG_NAME))) {
        boolean isValid = (data.srcCode.isCurrent(' ') || (tlt.getHasBody() && data.srcCode.isCurrent('{')));
        if (!isValid) {
            data.srcCode.setPos(data.srcCode.getPos() - type.length());
            return null;
        }
    } else
        return null;
    Position line = data.srcCode.getPosition();
    TagLibTagScript script = tlt.getScript();
    // TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,type);
    if (script.getContext() == CTX_CFC)
        data.isCFC = true;
    else if (script.getContext() == CTX_INTERFACE)
        data.isInterface = true;
    // Tag tag=new TagComponent(line);
    Tag tag = getTag(data, parent, tlt, line, null);
    tag.setTagLibTag(tlt);
    tag.setScriptBase(true);
    // add component meta data
    if (data.isCFC) {
        addMetaData(data, tag, IGNORE_LIST_COMPONENT);
    }
    if (data.isInterface) {
        addMetaData(data, tag, IGNORE_LIST_INTERFACE);
    }
    // EvaluatorPool.getPool();
    comments(data);
    // attributes
    // attributes(func,data);
    Attribute[] attrs = attributes(tag, tlt, data, SEMI_BLOCK, data.factory.EMPTY(), script.getRtexpr() ? Boolean.TRUE : Boolean.FALSE, null, false, ',', false);
    for (int i = 0; i < attrs.length; i++) {
        tag.addAttribute(attrs[i]);
    }
    comments(data);
    // body
    if (tlt.getHasBody()) {
        Body body = new BodyBase(data.factory);
        boolean wasSemiColon = statement(data, body, script.getContext());
        if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
            tag.setBody(body);
    } else
        checkSemiColonLineFeed(data, true, true, true);
    tag.setEnd(data.srcCode.getPosition());
    eval(tlt, data, tag);
    return tag;
}
Also used : TagLibTagScript(lucee.transformer.library.tag.TagLibTagScript) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 2 with TagLibTagScript

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

the class AbstrCFMLScriptTransformer method cftagStatement.

private Statement cftagStatement(ExprData data, Body parent) throws TemplateException {
    // that is because cfloop-contition evaluator does not pass this
    if (data.ep == null)
        return null;
    final int start = data.srcCode.getPos();
    // namespace and separator
    final TagLib tagLib = CFMLTransformer.nameSpace(data);
    if (tagLib == null || !tagLib.isCore())
        return null;
    // print.e("namespace:"+tagLib.getNameSpaceAndSeparator());
    // get the name of the tag
    String id = CFMLTransformer.identifier(data.srcCode, false, true);
    if (id == null) {
        data.srcCode.setPos(start);
        return null;
    }
    id = id.toLowerCase();
    String appendix = null;
    TagLibTag tlt = tagLib.getTag(id);
    // get taglib
    if (tlt == null) {
        tlt = tagLib.getAppendixTag(id);
        if (tlt == null) {
            // if(tagLib.getIgnoreUnknowTags()){ if we do this a expression like the following no longer work cfwhatever=1;
            data.srcCode.setPos(start);
            return null;
        // }
        // throw new TemplateException(data.srcCode,"undefined tag ["+tagLib.getNameSpaceAndSeparator()+id+"]");
        }
        appendix = StringUtil.removeStartingIgnoreCase(id, tlt.getName());
    }
    if (tlt.getScript() == null) {
        data.srcCode.setPos(start);
        return null;
    }
    // check for opening bracked or closing semicolon
    comments(data);
    boolean noAttrs = false;
    if (!data.srcCode.forwardIfCurrent('(')) {
        if (checkSemiColonLineFeed(data, false, false, false)) {
            noAttrs = true;
        } else {
            data.srcCode.setPos(start);
            return null;
        }
    }
    Position line = data.srcCode.getPosition();
    // script specific behavior
    short context = CTX_OTHER;
    Boolean allowExpression = Boolean.TRUE;
    {
        TagLibTagScript script = tlt.getScript();
        if (script != null) {
            context = script.getContext();
            // always true for this tags allowExpression=script.getRtexpr()?Boolean.TRUE:Boolean.FALSE;
            if (context == CTX_CFC)
                data.isCFC = true;
            else if (context == CTX_INTERFACE)
                data.isInterface = true;
        }
    }
    Tag tag = getTag(data, parent, tlt, line, null);
    if (appendix != null) {
        tag.setAppendix(appendix);
        tag.setFullname(tlt.getFullName().concat(appendix));
    } else {
        tag.setFullname(tlt.getFullName());
    }
    tag.setTagLibTag(tlt);
    tag.setScriptBase(true);
    // add component meta data
    if (data.isCFC) {
        addMetaData(data, tag, IGNORE_LIST_COMPONENT);
    }
    if (data.isInterface) {
        addMetaData(data, tag, IGNORE_LIST_INTERFACE);
    }
    comments(data);
    // attributes
    Attribute[] attrs = noAttrs ? new Attribute[0] : attributes(tag, tlt, data, BRACKED, data.factory.EMPTY(), allowExpression, null, false, ',', true);
    data.srcCode.forwardIfCurrent(')');
    for (int i = 0; i < attrs.length; i++) {
        tag.addAttribute(attrs[i]);
    }
    comments(data);
    // body
    if (tlt.getHasBody()) {
        Body body = new BodyBase(data.factory);
        boolean wasSemiColon = statement(data, body, context);
        if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
            tag.setBody(body);
    } else
        checkSemiColonLineFeed(data, true, true, true);
    tag.setEnd(data.srcCode.getPosition());
    eval(tlt, data, tag);
    return tag;
}
Also used : TagLibTagScript(lucee.transformer.library.tag.TagLibTagScript) TagLibTag(lucee.transformer.library.tag.TagLibTag) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TagLib(lucee.transformer.library.tag.TagLib) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) RefBoolean(lucee.commons.lang.types.RefBoolean) ExprBoolean(lucee.transformer.expression.ExprBoolean) CastBoolean(lucee.transformer.bytecode.cast.CastBoolean) LitBoolean(lucee.transformer.expression.literal.LitBoolean) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 3 with TagLibTagScript

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

the class GetTagData method javaBasedTag.

private static Struct javaBasedTag(TagLib tld, TagLibTag tag) throws PageException {
    Struct sct = new StructImpl();
    sct.set("nameSpaceSeperator", tld.getNameSpaceSeparator());
    sct.set("nameSpace", tld.getNameSpace());
    sct.set(KeyConstants._name, tag.getName());
    sct.set(KeyConstants._description, tag.getDescription());
    sct.set(KeyConstants._status, TagLibFactory.toStatus(tag.getStatus()));
    sct.set("attributeType", getAttributeType(tag));
    sct.set("parseBody", Caster.toBoolean(tag.getParseBody()));
    sct.set("bodyType", getBodyType(tag));
    sct.set("attrMin", Caster.toDouble(tag.getMin()));
    sct.set("attrMax", Caster.toDouble(tag.getMax()));
    sct.set("hasNameAppendix", Caster.toBoolean(tag.hasAppendix()));
    sct.set("attributeCollection", getSupportAttributeCollection(tag));
    if (tag.getIntroduced() != null)
        sct.set(GetFunctionData.INTRODUCED, tag.getIntroduced().toString());
    // script
    TagLibTagScript script = tag.getScript();
    if (script != null) {
        Struct scp = new StructImpl();
        sct.set(KeyConstants._script, scp);
        scp.set("rtexpr", Caster.toBoolean(script.getRtexpr()));
        scp.set(KeyConstants._type, script.getTypeAsString());
        if (script.getType() == TagLibTagScript.TYPE_SINGLE) {
            TagLibTagAttr attr = script.getSingleAttr();
            if (attr != null)
                scp.set("singletype", attr.getScriptSupportAsString());
            else
                scp.set("singletype", "none");
        }
    }
    sct.set(KeyConstants._type, "java");
    Struct _args = new StructImpl();
    sct.set(KeyConstants._attributes, _args);
    // Map<String,TagLibTagAttr> atts = tag.getAttributes();
    Iterator<Entry<String, TagLibTagAttr>> it = tag.getAttributes().entrySet().iterator();
    Entry<String, TagLibTagAttr> e;
    while (it.hasNext()) {
        e = it.next();
        TagLibTagAttr attr = e.getValue();
        if (attr.getHidden())
            continue;
        // for(int i=0;i<args.size();i++) {
        Struct _arg = new StructImpl();
        _arg.set(KeyConstants._status, TagLibFactory.toStatus(attr.getStatus()));
        _arg.set(KeyConstants._description, attr.getDescription());
        _arg.set(KeyConstants._type, attr.getType());
        if (attr.getAlias() != null)
            _arg.set(KeyConstants._alias, ListUtil.arrayToList(attr.getAlias(), ","));
        if (attr.getValues() != null)
            _arg.set(KeyConstants._values, Caster.toArray(attr.getValues()));
        if (attr.getDefaultValue() != null)
            _arg.set("defaultValue", attr.getDefaultValue());
        _arg.set(KeyConstants._required, attr.isRequired() ? Boolean.TRUE : Boolean.FALSE);
        _arg.set("scriptSupport", attr.getScriptSupportAsString());
        if (attr.getIntroduced() != null)
            _arg.set(GetFunctionData.INTRODUCED, attr.getIntroduced().toString());
        _args.setEL(attr.getName(), _arg);
    }
    return sct;
}
Also used : TagLibTagScript(lucee.transformer.library.tag.TagLibTagScript) TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) Struct(lucee.runtime.type.Struct)

Aggregations

TagLibTagScript (lucee.transformer.library.tag.TagLibTagScript)3 Position (lucee.transformer.Position)2 Body (lucee.transformer.bytecode.Body)2 BodyBase (lucee.transformer.bytecode.BodyBase)2 FunctionBody (lucee.transformer.bytecode.FunctionBody)2 ScriptBody (lucee.transformer.bytecode.ScriptBody)2 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)2 Tag (lucee.transformer.bytecode.statement.tag.Tag)2 TagLibTag (lucee.transformer.library.tag.TagLibTag)2 Entry (java.util.Map.Entry)1 RefBoolean (lucee.commons.lang.types.RefBoolean)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 CastBoolean (lucee.transformer.bytecode.cast.CastBoolean)1 ExprBoolean (lucee.transformer.expression.ExprBoolean)1 LitBoolean (lucee.transformer.expression.literal.LitBoolean)1 TagLib (lucee.transformer.library.tag.TagLib)1 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)1