sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From npelt...@apache.org
Subject svn commit: r1800871 - in /sling/trunk/contrib/extensions/sling-pipes/src: main/java/org/apache/sling/pipes/PipeBindings.java test/java/org/apache/sling/pipes/PipeBindingsTest.java
Date Wed, 05 Jul 2017 12:56:24 GMT
Author: npeltier
Date: Wed Jul  5 12:56:24 2017
New Revision: 1800871

URL: http://svn.apache.org/viewvc?rev=1800871&view=rev
Log:
SLING-6770 add resource names as bindings

- 'name' is a map referring resource names just as 'path'
- add some more comments,
- add a unit test based on a container pipe

Modified:
    sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBindings.java
    sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java

Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBindings.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBindings.java?rev=1800871&r1=1800870&r2=1800871&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBindings.java
(original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBindings.java
Wed Jul  5 12:56:24 2017
@@ -55,10 +55,18 @@ public class PipeBindings {
 
     ScriptContext scriptContext = new SimpleScriptContext();
 
+    /**
+     * add ${path.pipeName} binding allowing to retrieve pipeName's current resource path
+     */
     public static final String PATH_BINDING = "path";
-
     Map<String, String> pathBindings = new HashMap<>();
 
+    /**
+     * add ${name.pipeName} binding allowing to retrieve pipeName's current resource name
+     */
+    public static final String NAME_BINDING = "name";
+    Map<String, String> nameBindings = new HashMap<>();
+
     Map<String, Resource> outputResources = new HashMap<>();
 
     private static final Pattern INJECTED_SCRIPT = Pattern.compile("\\$\\{(([^\\{^\\}]*(\\{[0-9,]+\\})?)*)\\}");
@@ -72,6 +80,9 @@ public class PipeBindings {
         //add path bindings where path.MyPipe will give MyPipe current resource path
         getBindings().put(PATH_BINDING, pathBindings);
 
+        //add name bindings where name.MyPipe will give MyPipe current resource name
+        getBindings().put(NAME_BINDING, nameBindings);
+
         //additional bindings (global variables to use in child pipes expressions)
         Resource additionalBindings = resource.getChild(NN_ADDITIONALBINDINGS);
         if (additionalBindings != null) {
@@ -152,6 +163,7 @@ public class PipeBindings {
         outputResources.put(pipe.getName(), resource);
         if (resource != null) {
             pathBindings.put(pipe.getName(), resource.getPath());
+            nameBindings.put(pipe.getName(), resource.getName());
         }
         addBinding(pipe.getName(), pipe.getOutputBinding());
     }

Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java?rev=1800871&r1=1800870&r2=1800871&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
(original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
Wed Jul  5 12:56:24 2017
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNul
 
 import java.util.Calendar;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 
 import javax.script.ScriptException;
@@ -123,4 +124,15 @@ public class PipeBindingsTest extends Ab
         Number expression = (Number)bindings.instantiateObject("${testSumFunction(1,2)}");
         assertEquals("computed expression have testSum script's functionavailable", 3, expression.intValue());
     }
+
+    @Test
+    public void testNameBinding() throws Exception {
+        Pipe pipe = getPipe(PATH_PIPE + "/" + ContainerPipeTest.NN_ONEPIPE);
+        Iterator<Resource> output = pipe.getOutput();
+        output.next();
+        PipeBindings bindings = pipe.getBindings();
+        assertEquals("first name binding should be apple", bindings.instantiateExpression("${name.dummyParent}"),
"apple");
+        output.next();
+        assertEquals("second name binding should be banana", bindings.instantiateExpression("${name.dummyParent}"),
"banana");
+    }
 }
\ No newline at end of file



Mime
View raw message