This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.pipes-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git

commit e16c19e60567345c2bbdaa0f21aa525c05f21074
Author: Nicolas Peltier <[email protected]>
AuthorDate: Wed Jul 5 12:56:24 2017 +0000

    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
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/sling-pipes@1800871
 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/pipes/PipeBindings.java     | 14 +++++++++++++-
 src/test/java/org/apache/sling/pipes/PipeBindingsTest.java | 12 ++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/pipes/PipeBindings.java 
b/src/main/java/org/apache/sling/pipes/PipeBindings.java
index a1b677b..a1b52ab 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBindings.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBindings.java
@@ -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());
     }
diff --git a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java 
b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
index 4aa7254..6922f8f 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNull;
 
 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 AbstractPipeTest {
         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

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to