Search in sources :

Example 6 with ComponentScope

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

the class Property method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (pageContext.variablesScope() instanceof ComponentScope) {
        Component comp = ((ComponentScope) pageContext.variablesScope()).getComponent();
        comp.setProperty(property);
        property.setOwnerName(comp.getAbsName());
    }
    return SKIP_BODY;
}
Also used : ComponentScope(lucee.runtime.ComponentScope) Component(lucee.runtime.Component)

Example 7 with ComponentScope

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

the class JSONConverter method _serializeStruct.

/**
 * serialize a Struct
 * @param struct Struct to serialize
 * @param sb
 * @param serializeQueryByColumns
 * @param addUDFs
 * @param done
 * @throws ConverterException
 */
public void _serializeStruct(PageContext pc, Set test, Struct struct, StringBuilder sb, boolean serializeQueryByColumns, boolean addUDFs, Set<Object> done) throws ConverterException {
    // Component
    if (struct instanceof Component) {
        String res = castToJson(pc, (Component) struct, NULL_STRING);
        if (res != NULL_STRING) {
            sb.append(res);
            return;
        }
    }
    sb.append(goIn());
    sb.append("{");
    // Key[] keys = struct.keys();
    // Key key;
    Iterator<Entry<Key, Object>> it = struct.entryIterator();
    Entry<Key, Object> e;
    Object value;
    boolean doIt = false;
    while (it.hasNext()) {
        e = it.next();
        // key=keys[i];
        value = e.getValue();
        if (!addUDFs && (value instanceof UDF || value == null))
            continue;
        if (doIt)
            sb.append(',');
        doIt = true;
        sb.append(StringUtil.escapeJS(e.getKey().getString(), '"', charsetEncoder));
        sb.append(':');
        _serialize(pc, test, value, sb, serializeQueryByColumns, done);
    }
    if (struct instanceof Component) {
        Boolean remotingFetch;
        Component comp = (Component) struct;
        boolean isPeristent = false;
        isPeristent = comp.isPersistent();
        Property[] props = comp.getProperties(false);
        ComponentScope scope = comp.getComponentScope();
        for (int i = 0; i < props.length; i++) {
            if (!ignoreRemotingFetch) {
                remotingFetch = Caster.toBoolean(props[i].getDynamicAttributes().get(REMOTING_FETCH, null), null);
                if (remotingFetch == null) {
                    if (isPeristent && ORMUtil.isRelated(props[i]))
                        continue;
                } else if (!remotingFetch.booleanValue())
                    continue;
            }
            Key key = KeyImpl.getInstance(props[i].getName());
            value = scope.get(key, null);
            if (!addUDFs && (value instanceof UDF || value == null))
                continue;
            if (doIt)
                sb.append(',');
            doIt = true;
            sb.append(StringUtil.escapeJS(key.getString(), '"', charsetEncoder));
            sb.append(':');
            _serialize(pc, test, value, sb, serializeQueryByColumns, done);
        }
    }
    sb.append('}');
}
Also used : Entry(java.util.Map.Entry) ComponentScope(lucee.runtime.ComponentScope) UDF(lucee.runtime.type.UDF) JavaObject(lucee.runtime.java.JavaObject) Component(lucee.runtime.Component) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Example 8 with ComponentScope

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

the class XMLConverter method _deserializeComponent.

/**
 * Desirialize a Component Object
 * @param elComp Component Object as XML Element
 * @return Component Object
 * @throws ConverterException
 * @throws ConverterException
 */
private Object _deserializeComponent(Element elComp) throws ConverterException {
    // String type=elStruct.getAttribute("type");
    String name = elComp.getAttribute("name");
    String md5 = elComp.getAttribute("md5");
    // TLPC
    PageContext pc = ThreadLocalPageContext.get();
    // Load comp
    Component comp = null;
    try {
        comp = pc.loadComponent(name);
        if (!ComponentUtil.md5(comp).equals(md5)) {
            throw new ConverterException("component [" + name + "] in this enviroment has not the same interface as the component to load, it is possible that one off the components has Functions added dynamicly.");
        }
    } catch (ConverterException e) {
        throw e;
    } catch (Exception e) {
        throw new ConverterException(e.getMessage());
    }
    NodeList list = elComp.getChildNodes();
    ComponentScope scope = comp.getComponentScope();
    int len = list.getLength();
    String scopeName;
    Element var, value;
    Collection.Key key;
    for (int i = 0; i < len; i++) {
        Node node = list.item(i);
        if (node instanceof Element) {
            var = (Element) node;
            value = getChildElement((Element) node);
            scopeName = var.getAttribute("scope");
            if (value != null) {
                key = Caster.toKey(var.getAttribute("name"), null);
                if (key == null)
                    continue;
                if ("variables".equalsIgnoreCase(scopeName))
                    scope.setEL(key, _deserialize(value));
                else
                    comp.setEL(key, _deserialize(value));
            }
        }
    }
    return comp;
}
Also used : Key(lucee.runtime.type.Collection.Key) ComponentScope(lucee.runtime.ComponentScope) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Collection(lucee.runtime.type.Collection) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) Component(lucee.runtime.Component) PageException(lucee.runtime.exp.PageException) IOException(java.io.IOException)

Example 9 with ComponentScope

use of lucee.runtime.ComponentScope 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 10 with ComponentScope

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

the class AxisCaster method toComponent.

public static Component toComponent(PageContext pc, Pojo pojo, String compPath, Component defaultValue) {
    try {
        Component cfc = pc.loadComponent(compPath);
        Property[] props = cfc.getProperties(false, true, false, false);
        PojoIterator it = new PojoIterator(pojo);
        // only when the same amount of properties
        if (props.length == it.size()) {
            Map<Collection.Key, Property> propMap = toMap(props);
            Property p;
            Pair<Collection.Key, Object> pair;
            ComponentScope scope = cfc.getComponentScope();
            while (it.hasNext()) {
                pair = it.next();
                p = propMap.get(pair.getName());
                if (p == null)
                    return defaultValue;
                Object val = null;
                try {
                    val = Caster.castTo(pc, p.getType(), pair.getValue(), false);
                } catch (PageException e) {
                }
                // store in variables and this scope
                scope.setEL(pair.getName(), val);
                cfc.setEL(pair.getName(), val);
            }
            return cfc;
        }
    } catch (PageException e) {
    }
    return defaultValue;
}
Also used : PageException(lucee.runtime.exp.PageException) ComponentScope(lucee.runtime.ComponentScope) Component(lucee.runtime.Component) Property(lucee.runtime.component.Property) Key(lucee.runtime.type.Collection.Key)

Aggregations

ComponentScope (lucee.runtime.ComponentScope)10 Key (lucee.runtime.type.Collection.Key)8 Component (lucee.runtime.Component)7 Property (lucee.runtime.component.Property)6 PageException (lucee.runtime.exp.PageException)6 IOException (java.io.IOException)5 UDF (lucee.runtime.type.UDF)5 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)4 Collection (lucee.runtime.type.Collection)4 Entry (java.util.Map.Entry)3 Struct (lucee.runtime.type.Struct)3 PageContext (lucee.runtime.PageContext)2 CoderException (lucee.runtime.coder.CoderException)2 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 ClassException (lucee.commons.lang.ClassException)1