incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r631960 - 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
Date Thu, 28 Feb 2008 13:20:42 GMT
Author: bdelacretaz
Date: Thu Feb 28 05:20:37 2008
New Revision: 631960

URL: http://svn.apache.org/viewvc?rev=631960&view=rev
Log:
SLING-282 - ScriptableNode.getNodes(namePattern) added

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=631960&r1=631959&r2=631960&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
Thu Feb 28 05:20:37 2008
@@ -100,11 +100,26 @@
         }
     }
 
+    public ScriptableItemMap jsFunction_getNodes(String namePattern) {
+        try {
+            NodeIterator iter = null;
+            if(namePattern == null || "undefined".equals(namePattern)) {
+                iter = node.getNodes();
+            } else {
+                iter = node.getNodes(namePattern);
+            }
+            return new ScriptableItemMap(iter);
+        } catch (RepositoryException re) {
+            log.warn("Cannot get children of " + jsFunction_getPath() + " with pattern "
+ namePattern, re);
+            return new ScriptableItemMap();
+        }
+    }
+    
     public ScriptableItemMap jsFunction_getProperties() {
         try {
             return new ScriptableItemMap(node.getProperties());
         } catch (RepositoryException re) {
-            log.warn("Cannot get children of " + jsFunction_getPath(), re);
+            log.warn("Cannot get properties of " + jsFunction_getPath(), re);
             return new ScriptableItemMap();
         }
     }

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=631960&r1=631959&r2=631960&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
Thu Feb 28 05:20:37 2008
@@ -143,4 +143,27 @@
         final String code = "out.print(node.getProperty('text'));";
         assertEquals(testText, script.evalToString(code, data));
     }
+    
+    public void testGetNodesNoPattern() throws Exception {
+        final String path = "subgnnp_" + System.currentTimeMillis();
+        final String code =
+            "node.addNode('" + path + "_A');\n"
+            + "node.addNode('" + path + "_B');\n"
+            + "var nodes = node.getNodes();\n"
+            + "for (i in nodes) { out.print(nodes[i].getName() + ' '); }\n"
+        ;
+        assertEquals(path + "_A " + path + "_B ", script.evalToString(code, data));
+    }
+    
+    public void testGetNodesWithPattern() throws Exception {
+        final String path = "subgnnp_" + System.currentTimeMillis();
+        final String code =
+            "node.addNode('1_" + path + "_A');\n"
+            + "node.addNode('1_" + path + "_B');\n"
+            + "node.addNode('2_" + path + "_C');\n"
+            + "var nodes = node.getNodes('1_*');\n"
+            + "for (i in nodes) { out.print(nodes[i].getName() + ' '); }\n"
+        ;
+        assertEquals("1_" + path + "_A 1_" + path + "_B ", script.evalToString(code, data));
+    }
 }



Mime
View raw message