incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r923271 - in /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting: CurrentNodeBindingsValuesProvider.java JcrObjectsBindingsValuesProvider.java
Date Mon, 15 Mar 2010 14:48:20 GMT
Author: cziegeler
Date: Mon Mar 15 14:48:20 2010
New Revision: 923271

URL: http://svn.apache.org/viewvc?rev=923271&view=rev
Log:
SLING-514 : Expose current session through currentSession binding

Added:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/JcrObjectsBindingsValuesProvider.java
      - copied, changed from r923117, sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java
Removed:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java

Copied: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/JcrObjectsBindingsValuesProvider.java
(from r923117, sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/JcrObjectsBindingsValuesProvider.java?p2=sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/JcrObjectsBindingsValuesProvider.java&p1=sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java&r1=923117&r2=923271&rev=923271&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/JcrObjectsBindingsValuesProvider.java
Mon Mar 15 14:48:20 2010
@@ -17,13 +17,14 @@
 package org.apache.sling.jcr.resource.internal.scripting;
 
 import javax.jcr.Node;
+import javax.jcr.Session;
 import javax.script.Bindings;
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.scripting.api.BindingsValuesProvider;
 
 /**
- * BindingsValuesProvider for currentNode object.
+ * BindingsValuesProvider for currentNode and currentSession object.
  *
  * @scr.component metatype="no"
  * @scr.service
@@ -31,17 +32,27 @@ import org.apache.sling.scripting.api.Bi
  * @scr.property name="service.description" value="Apache Sling CurrentNode BindingsValuesProvider"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
  */
-public class CurrentNodeBindingsValuesProvider implements BindingsValuesProvider {
+public class JcrObjectsBindingsValuesProvider implements BindingsValuesProvider {
+
+
+    private static final String PROP_CURRENT_NODE = "currentNode";
+    private static final String PROP_CURRENT_SESSION = "currentSession";
 
     /**
      * {@inheritDoc}
      */
     public void addBindings(Bindings bindings) {
         Resource resource = (Resource) bindings.get("resource");
-        if(resource != null) {
+        if (resource != null) {
             Node node = resource.adaptTo(Node.class);
             if (node != null) {
-                bindings.put("currentNode", node);
+                bindings.put(PROP_CURRENT_NODE, node);
+            }
+            if ( bindings.get(PROP_CURRENT_SESSION) == null ) {
+                final Session session = resource.getResourceResolver().adaptTo(Session.class);
+                if ( session != null ) {
+                    bindings.put(PROP_CURRENT_SESSION, session);
+                }
             }
         }
     }



Mime
View raw message