You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/02/18 13:51:45 UTC
svn commit: r628709 - in /incubator/sling/trunk/scripting/javascript/src:
main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
test/java/org/apache/sling/scripting/wrapper/ScriptableNodeTest.java
Author: bdelacretaz
Date: Mon Feb 18 04:51:42 2008
New Revision: 628709
URL: http://svn.apache.org/viewvc?rev=628709&view=rev
Log:
SLING-154 - Node.addNode(...) and Node.getNode(...) methods added to ScriptableNode, with tests
Modified:
incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableNodeTest.java
Modified: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java?rev=628709&r1=628708&r2=628709&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java Mon Feb 18 04:51:42 2008
@@ -74,6 +74,22 @@
public Class<?> [] getWrappedClasses() {
return WRAPPED_CLASSES;
}
+
+ public Object jsFunction_addNode(String path, String primaryType) throws RepositoryException {
+ Node n = null;
+ if(primaryType == null || "undefined".equals(primaryType)) {
+ n = node.addNode(path);
+ } else {
+ n = node.addNode(path, primaryType);
+ }
+
+ final Object result = ScriptRuntime.toObject(this, n);
+ return result;
+ }
+
+ public Object jsFunction_getNode(String path) throws RepositoryException {
+ return ScriptRuntime.toObject(this, node.getNode(path));
+ }
public ScriptableItemMap jsFunction_getChildren() {
try {
Modified: incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableNodeTest.java?rev=628709&r1=628708&r2=628709&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableNodeTest.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableNodeTest.java Mon Feb 18 04:51:42 2008
@@ -110,4 +110,32 @@
assertTrue("result (" + result + ") contains '" + name + "'", result.contains(name));
}
}
+
+ public void testAddNodeDefaultType() throws Exception {
+ final String path = "subdt_" + System.currentTimeMillis();
+ final String code =
+ "var n = node.addNode('" + path + "');\n"
+ + "out.print(n['jcr:primaryType']);\n"
+ ;
+ assertEquals("nt:unstructured", script.evalToString(code, data));
+ }
+
+ public void testAddNodeSpecificType() throws Exception {
+ final String path = "subst_" + System.currentTimeMillis();
+ final String code =
+ "var n = node.addNode('" + path + "', 'nt:folder');\n"
+ + "out.print(n['jcr:primaryType']);\n"
+ ;
+ assertEquals("nt:folder", script.evalToString(code, data));
+ }
+
+ public void testGetNode() throws Exception {
+ final String path = "subgn_" + System.currentTimeMillis();
+ final String code =
+ "node.addNode('" + path + "', 'nt:resource');\n"
+ + "var n=node.getNode('" + path + "');\n"
+ + "out.print(n['jcr:primaryType']);\n"
+ ;
+ assertEquals("nt:resource", script.evalToString(code, data));
+ }
}