Search in sources :

Example 6 with ComponentSpecificAccess

use of lucee.runtime.ComponentSpecificAccess in project Lucee by lucee.

the class JSONConverter method _serializeComponent.

/**
 * serialize a Component
 * @param component Component to serialize
 * @param sb
 * @param serializeQueryByColumns
 * @param done
 * @throws ConverterException
 */
private void _serializeComponent(PageContext pc, Set test, Component component, StringBuilder sb, boolean serializeQueryByColumns, Set<Object> done) throws ConverterException {
    ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, component);
    _serializeStruct(pc, test, cw, sb, serializeQueryByColumns, false, done);
}
Also used : ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess)

Example 7 with ComponentSpecificAccess

use of lucee.runtime.ComponentSpecificAccess in project Lucee by lucee.

the class EvaluateComponent method setInternalState.

public static void setInternalState(Component comp, Struct sctThis, Struct sctVariables) throws PageException {
    // this
    // delete this scope data members
    ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, comp);
    Collection.Key[] cwKeys = CollectionUtil.keys(cw);
    Object member;
    for (int i = 0; i < cwKeys.length; i++) {
        member = cw.get(cwKeys[i]);
        if (member instanceof UDF)
            continue;
        cw.removeEL(cwKeys[i]);
    }
    // set this scope data members
    Iterator<Entry<Key, Object>> it = sctThis.entryIterator();
    Entry<Key, Object> e;
    // keys = sctThis.keys();
    while (it.hasNext()) {
        e = it.next();
        comp.set(e.getKey(), e.getValue());
    }
    // Variables
    ComponentScope scope = comp.getComponentScope();
    // delete variables scope data members
    Key[] sKeys = CollectionUtil.keys(scope);
    for (int i = 0; i < sKeys.length; i++) {
        if (KeyConstants._this.equals(sKeys[i]))
            continue;
        if (scope.get(sKeys[i]) instanceof UDF)
            continue;
        scope.removeEL(sKeys[i]);
    }
    // set variables scope data members
    it = sctVariables.entryIterator();
    // keys = sctVariables.keys();
    while (it.hasNext()) {
        e = it.next();
        scope.set(e.getKey(), e.getValue());
    }
}
Also used : Entry(java.util.Map.Entry) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Key(lucee.runtime.type.Collection.Key)

Example 8 with ComponentSpecificAccess

use of lucee.runtime.ComponentSpecificAccess 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)

Aggregations

ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)8 Key (lucee.runtime.type.Collection.Key)6 Struct (lucee.runtime.type.Struct)6 UDF (lucee.runtime.type.UDF)5 Entry (java.util.Map.Entry)4 Component (lucee.runtime.Component)4 ComponentScope (lucee.runtime.ComponentScope)4 PageException (lucee.runtime.exp.PageException)4 IOException (java.io.IOException)3 Property (lucee.runtime.component.Property)3 Collection (lucee.runtime.type.Collection)3 StructImpl (lucee.runtime.type.StructImpl)2 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 Resource (lucee.commons.io.res.Resource)1 ComponentImpl (lucee.runtime.ComponentImpl)1 PageContextImpl (lucee.runtime.PageContextImpl)1 PageSource (lucee.runtime.PageSource)1 CacheConnection (lucee.runtime.cache.CacheConnection)1