in src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java [304:359]
public Object get(String name, Scriptable start) {
// builtin javascript properties (jsFunction_ etc.) have priority
final Object fromSuperclass = super.get(name, start);
if (fromSuperclass != Scriptable.NOT_FOUND) {
return fromSuperclass;
}
if (node == null) {
return Undefined.instance;
}
final List<Scriptable> items = new ArrayList<Scriptable>();
// Add all matching nodes to result
try {
NodeIterator it = node.getNodes(name);
while (it.hasNext()) {
items.add(ScriptRuntime.toObject(this, it.nextNode()));
}
} catch (RepositoryException e) {
log.debug("RepositoryException while collecting Node children", e);
}
// Add all matching properties to result
boolean isMulti = false;
try {
PropertyIterator it = node.getProperties(name);
while (it.hasNext()) {
Property prop = it.nextProperty();
if (prop.getDefinition().isMultiple()) {
isMulti = true;
Value[] values = prop.getValues();
for (int i = 0; i < values.length; i++) {
items.add(wrap(values[i]));
}
} else {
items.add(wrap(prop.getValue()));
}
}
} catch (RepositoryException e) {
log.debug("RepositoryException while collecting Node properties", e);
}
if (items.size() == 0) {
return getNative(name, start);
} else if (items.size() == 1 && !isMulti) {
return items.iterator().next();
} else {
NativeArray result = new NativeArray(items.toArray());
ScriptRuntime.setObjectProtoAndParent(result, this);
return result;
}
}