use of com.enonic.xp.script.ScriptValue in project xp by enonic.
the class ScriptValueTest method testObject.
@Test
public void testObject() throws Exception {
final ScriptValue obj = evalValue("testObject");
assertEquals(false, obj.isArray());
assertEquals(false, obj.isFunction());
assertEquals(true, obj.isObject());
assertEquals(false, obj.isValue());
assertEquals(null, obj.getValue());
assertEquals(2, obj.getKeys().size());
assertEquals(true, obj.hasMember("a"));
assertEquals(1, obj.getMember("a").getValue());
assertEquals(0, obj.getArray().size());
assertEquals(null, obj.call("a"));
assertEquals(null, obj.getValue(String.class));
assertEquals(0, obj.getArray(String.class).size());
assertEquals("a=1,b=2", obj.getMap().entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(",")));
}
use of com.enonic.xp.script.ScriptValue in project xp by enonic.
the class ScriptValueTest method testValue.
@Test
public void testValue() throws Exception {
final ScriptValue obj = evalValue("testValue");
assertEquals(false, obj.isArray());
assertEquals(false, obj.isFunction());
assertEquals(false, obj.isObject());
assertEquals(true, obj.isValue());
assertEquals(1, obj.getValue());
assertEquals(0, obj.getKeys().size());
assertEquals(false, obj.hasMember("a"));
assertEquals(null, obj.getMember("a"));
assertEquals(0, obj.getArray().size());
assertEquals(null, obj.call("a"));
assertEquals("1", obj.getValue(String.class));
assertEquals(0, obj.getArray(String.class).size());
assertEquals(0, obj.getMap().size());
}
use of com.enonic.xp.script.ScriptValue in project xp by enonic.
the class ModifyProfileHandler method newProfileEditor.
private void newProfileEditor(final EditableUser edit) {
final PropertyTree profile = edit.source.getProfile();
final PropertyTreeMapper mapper = createPropertyTreeMapper(profile, true);
final ScriptValue scriptValue = this.editor.call(mapper);
updateUser(edit, scriptValue);
}
use of com.enonic.xp.script.ScriptValue in project xp by enonic.
the class ModifyNodeHandler method execute.
@Override
public Object execute() {
final Node node = getExistingNode();
final ScriptValue updatedNodeScriptValue = applyEditor(node);
final BinaryAttachments binaryAttachments = getBinaryAttachments(updatedNodeScriptValue);
final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(node.id()).editor(createEditor(updatedNodeScriptValue)).setBinaryAttachments(binaryAttachments).build();
final Node updatedNode = this.nodeService.update(updateNodeParams);
return new NodeMapper(updatedNode, false);
}
use of com.enonic.xp.script.ScriptValue in project xp by enonic.
the class UrlServiceScriptTest method execute.
private boolean execute(final String method) {
final ScriptExports exports = runScript("/test/url-test.js");
final ScriptValue value = exports.executeMethod(method);
return value != null ? value.getValue(Boolean.class) : false;
}
Aggregations