Search in sources :

Example 16 with TagLibTagAttr

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

the class GetTagData method cfmlBasedTag.

private static Struct cfmlBasedTag(PageContext pc, TagLib tld, TagLibTag tag) throws PageException {
    // Map attrs = tag.getAttributes();
    TagLibTagAttr attrFilename = tag.getAttribute("__filename");
    // TagLibTagAttr attrName = tag.getAttribute("__name");
    TagLibTagAttr attrIsWeb = tag.getAttribute("__isweb");
    String filename = Caster.toString(attrFilename.getDefaultValue());
    String name = Caster.toString(attrFilename.getDefaultValue());
    boolean isWeb = Caster.toBooleanValue(attrIsWeb.getDefaultValue());
    InitFile source = CFTagCore.createInitFile(pc, isWeb, filename);
    String callPath = ResourceUtil.removeExtension(source.getFilename(), source.getFilename());
    Component cfc = ComponentLoader.loadComponent(pc, source.getPageSource(), callPath, false, true);
    ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
    Struct metadata = Caster.toStruct(cw.get("metadata", null), null, false);
    Struct sct = new StructImpl();
    sct.set("nameSpaceSeperator", tld.getNameSpaceSeparator());
    sct.set("nameSpace", tld.getNameSpace());
    sct.set(KeyConstants._name, name.substring(0, name.lastIndexOf('.')));
    sct.set("hasNameAppendix", Boolean.FALSE);
    sct.set(KeyConstants._status, "implemeted");
    sct.set(KeyConstants._type, "cfml");
    sct.set("bodyType", getBodyType(tag));
    sct.set("attrMin", Caster.toDouble(0));
    sct.set("attrMax", Caster.toDouble(0));
    sct.set("attributeCollection", getSupportAttributeCollection(tag));
    // TODO add support for script for cfml tags
    Struct scp = new StructImpl();
    sct.set(KeyConstants._script, scp);
    scp.set("rtexpr", Boolean.FALSE);
    scp.set(KeyConstants._type, "none");
    if (metadata != null) {
        sct.set(KeyConstants._description, metadata.get("hint", ""));
        sct.set("attributeType", metadata.get("attributeType", ""));
        sct.set("parseBody", Caster.toBoolean(metadata.get("parseBody", Boolean.FALSE), Boolean.FALSE));
        Struct _attrs = new StructImpl();
        sct.set(KeyConstants._attributes, _attrs);
        Struct srcAttrs = Caster.toStruct(metadata.get(KeyConstants._attributes, null), null, false);
        Struct src;
        if (srcAttrs != null) {
            // Key[] keys = srcAttrs.keys();
            Iterator<Entry<Key, Object>> it = srcAttrs.entryIterator();
            Entry<Key, Object> e;
            while (it.hasNext()) {
                e = it.next();
                src = Caster.toStruct(e.getValue(), null, false);
                if (Caster.toBooleanValue(src.get(KeyConstants._hidden, null), false))
                    continue;
                Struct _attr = new StructImpl();
                _attr.set(KeyConstants._status, "implemeted");
                _attr.set(KeyConstants._description, src.get(KeyConstants._hint, ""));
                _attr.set(KeyConstants._type, src.get(KeyConstants._type, "any"));
                _attr.set(KeyConstants._required, Caster.toBoolean(src.get(KeyConstants._required, ""), null));
                _attr.set("scriptSupport", "none");
                _attrs.setEL(e.getKey().getLowerString(), _attr);
            }
        }
    }
    return sct;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) InitFile(lucee.runtime.customtag.InitFile) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) Key(lucee.runtime.type.Collection.Key)

Example 17 with TagLibTagAttr

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

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