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;
}
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('}');
}
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;
}
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());
}
}
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;
}
Aggregations