You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2011/01/21 02:15:00 UTC

svn commit: r1061592 - in /sling/trunk/bundles/scripting/core/src: main/java/org/apache/sling/scripting/core/impl/ main/java/org/apache/sling/scripting/core/impl/helper/ test/java/org/apache/sling/scripting/core/impl/helper/

Author: justin
Date: Fri Jan 21 01:15:00 2011
New Revision: 1061592

URL: http://svn.apache.org/viewvc?rev=1061592&view=rev
Log:
fixing SLING-1941 - DefaultSlingScript now has a static list of protected keys

Modified:
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java
    sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindingsTest.java

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java?rev=1061592&r1=1061591&r2=1061592&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java (original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java Fri Jan 21 01:15:00 2011
@@ -25,6 +25,7 @@ import static org.apache.sling.api.scrip
 import static org.apache.sling.api.scripting.SlingBindings.RESOURCE;
 import static org.apache.sling.api.scripting.SlingBindings.RESPONSE;
 import static org.apache.sling.api.scripting.SlingBindings.SLING;
+import static org.apache.sling.api.scripting.SlingBindings.FLUSH;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -38,9 +39,11 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.script.Bindings;
 import javax.script.Invocable;
@@ -81,6 +84,10 @@ class DefaultSlingScript implements Slin
     /** Thread local containing the resource resolver. */
     private static ThreadLocal<ResourceResolver> requestResourceResolver = new ThreadLocal<ResourceResolver>();
 
+    /** The set of protected keys. */
+    private static final Set<String> PROTECTED_KEYS = 
+        new HashSet<String>(Arrays.asList(REQUEST, RESPONSE, READER, SLING, RESOURCE, OUT, FLUSH, LOG));
+    
     /** The resource pointing to the script. */
     private final Resource scriptResource;
 
@@ -359,7 +366,7 @@ class DefaultSlingScript implements Slin
                 }
             }
             // optionall flush the output channel
-            Object flushObject = bindings.get(SlingBindings.FLUSH);
+            Object flushObject = bindings.get(FLUSH);
             if (flushObject instanceof Boolean && (Boolean) flushObject) {
                 ctx.getWriter().flush();
             }
@@ -673,7 +680,10 @@ class DefaultSlingScript implements Slin
         }
 
         if (!bindingsValuesProviders.isEmpty()) {
-            ProtectedBindings protectedBindings = new ProtectedBindings(bindings);
+            Set<String> protectedKeys = new HashSet<String>();
+            protectedKeys.addAll(PROTECTED_KEYS);
+            
+            ProtectedBindings protectedBindings = new ProtectedBindings(bindings, protectedKeys);
             for (BindingsValuesProvider provider : bindingsValuesProviders) {
                 provider.addBindings(protectedBindings);
             }

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java?rev=1061592&r1=1061591&r2=1061592&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java (original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java Fri Jan 21 01:15:00 2011
@@ -2,7 +2,6 @@ package org.apache.sling.scripting.core.
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -13,9 +12,9 @@ public class ProtectedBindings implement
     private final Bindings wrapped;
     private final Set<String> protectedKeys;
 
-    public ProtectedBindings(Bindings wrapped) {
+    public ProtectedBindings(Bindings wrapped, Set<String> protectedKeys) {
         this.wrapped = wrapped;
-        this.protectedKeys = new HashSet<String>(wrapped.keySet());
+        this.protectedKeys = protectedKeys;
     }
 
     /**

Modified: sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindingsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindingsTest.java?rev=1061592&r1=1061591&r2=1061592&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindingsTest.java (original)
+++ sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindingsTest.java Fri Jan 21 01:15:00 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.scripting.core.impl.helper;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -38,7 +39,7 @@ public class ProtectedBindingsTest {
     public void setup() {
         SimpleBindings inner = new SimpleBindings();
         inner.put("test1", "value1");
-        this.bindings = new ProtectedBindings(inner);
+        this.bindings = new ProtectedBindings(inner, Collections.singleton("test1"));
     }
 
     @Test(expected=IllegalArgumentException.class)