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 2010/01/25 20:31:57 UTC

svn commit: r902942 - in /sling/trunk: bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/ bundles/scripting/core/ bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ bundles/scripting/core/src/main/java/org/apach...

Author: justin
Date: Mon Jan 25 19:31:55 2010
New Revision: 902942

URL: http://svn.apache.org/viewvc?rev=902942&view=rev
Log:
initial impl of SLING-1303

Added:
    sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/BindingsValuesProvider.java
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/GroovyBindingsValuesProvider.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StringBindingsValuesProvider.java
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
    sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.esp
    sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.groovy
Modified:
    sling/trunk/bundles/scripting/core/pom.xml
    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/SlingScriptAdapterFactory.java
    sling/trunk/launchpad/test-services/pom.xml

Added: sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/BindingsValuesProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/BindingsValuesProvider.java?rev=902942&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/BindingsValuesProvider.java (added)
+++ sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/BindingsValuesProvider.java Mon Jan 25 19:31:55 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.scripting.api;
+
+import javax.script.Bindings;
+
+/**
+ * Service interface which allows for the Bindings object
+ */
+public interface BindingsValuesProvider {
+
+    /**
+     * Add objects to the Bindings object. The Bindings
+     * object passed to this method does not support replacing
+     * or removing entries provided by Sling core scripting supports
+     * (request, response, resource, etc.). Entries created by
+     * <i>other</i> implementations of SlingScriptBindingsValuesProvider
+     * is permitted.
+     *
+     * @param bindings the Bindings object
+     */
+    void addBindings(Bindings bindings);
+
+}

Modified: sling/trunk/bundles/scripting/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/pom.xml?rev=902942&r1=902941&r2=902942&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/pom.xml (original)
+++ sling/trunk/bundles/scripting/core/pom.xml Mon Jan 25 19:31:55 2010
@@ -7,9 +7,9 @@
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
-    
+
     http://www.apache.org/licenses/LICENSE-2.0
-    
+
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -138,7 +138,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.api</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.0.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
 

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=902942&r1=902941&r2=902942&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 Mon Jan 25 19:31:55 2010
@@ -35,6 +35,7 @@
 import java.io.StringReader;
 import java.io.Writer;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -66,7 +67,9 @@
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptConstants;
 import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.scripting.api.BindingsValuesProvider;
 import org.apache.sling.scripting.core.ScriptHelper;
+import org.apache.sling.scripting.core.impl.helper.ProtectedBindings;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -114,16 +117,21 @@
     /** The current bundle context. */
     private final BundleContext bundleContext;
 
+    /** The ScriptBindingsValuesProviders. */
+    private final Collection<BindingsValuesProvider> bindingsValuesProviders;
+
     /**
      * Constructor
      * @param bundleContext The bundle context
      * @param scriptResource The script resource
      * @param scriptEngine The script engine
      */
-    DefaultSlingScript(BundleContext bundleContext, Resource scriptResource, ScriptEngine scriptEngine) {
+    DefaultSlingScript(BundleContext bundleContext, Resource scriptResource, ScriptEngine scriptEngine,
+            Collection<BindingsValuesProvider> bindingsValuesProviders) {
         this.scriptResource = scriptResource;
         this.scriptEngine = scriptEngine;
         this.bundleContext = bundleContext;
+        this.bindingsValuesProviders = bindingsValuesProviders;
         this.scriptName = this.scriptResource.getPath();
         // Now know how to get the input stream, we still have to decide
         // on the encoding of the stream's data. Primarily we assume it is
@@ -553,6 +561,13 @@
             }
         }
 
+        if (!bindingsValuesProviders.isEmpty()) {
+            ProtectedBindings protectedBindings = new ProtectedBindings(bindings);
+            for (BindingsValuesProvider provider : bindingsValuesProviders) {
+                provider.addBindings(protectedBindings);
+            }
+        }
+
         return bindings;
     }
 

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java?rev=902942&r1=902941&r2=902942&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java (original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java Mon Jan 25 19:31:55 2010
@@ -22,10 +22,15 @@
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -37,11 +42,13 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.scripting.SlingScriptConstants;
 import org.apache.sling.commons.mime.MimeTypeProvider;
+import org.apache.sling.scripting.api.BindingsValuesProvider;
 import org.apache.sling.scripting.core.impl.helper.SlingScriptEngineManager;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
@@ -66,6 +73,9 @@
  * @scr.reference name="ScriptEngineFactory"
  *                interface="javax.script.ScriptEngineFactory"
  *                cardinality="0..n" policy="dynamic"
+ * @scr.reference name="BindingsValuesProvider"
+ *                interface="org.apache.sling.scripting.api.BindingsValuesProvider"
+ *                cardinality="0..n" policy="dynamic"
  */
 public class SlingScriptAdapterFactory implements AdapterFactory,
         MimeTypeProvider, BundleListener {
@@ -87,6 +97,11 @@
      */
     private ServiceTracker eventAdminTracker;
 
+    private Collection<BindingsValuesProvider> genericBindingsValuesProviders;
+
+    private Map<String, Collection<BindingsValuesProvider>> langBindingsValuesProviders;
+
+
     // ---------- AdapterFactory -----------------------------------------------
 
     @SuppressWarnings("unchecked")
@@ -99,9 +114,11 @@
 
         ScriptEngine engine = getScriptEngineManager().getEngineByExtension(ext);
         if (engine != null) {
+            Collection<BindingsValuesProvider> bindingsValuesProviders =
+                getBindingsValuesProviders(engine);
             // unchecked cast
             return (AdapterType) new DefaultSlingScript(this.bundleContext,
-                resource, engine);
+                resource, engine, bindingsValuesProviders);
         }
 
         return null;
@@ -268,6 +285,9 @@
                 EventAdmin.class.getName(), null);
         this.eventAdminTracker.open();
 
+        genericBindingsValuesProviders = new HashSet<BindingsValuesProvider>();
+        langBindingsValuesProviders = new HashMap<String, Collection<BindingsValuesProvider>>();
+
         this.bundleContext = context.getBundleContext();
         this.bundleContext.addBundleListener(this);
 
@@ -334,6 +354,17 @@
         }
     }
 
+    private Collection<BindingsValuesProvider> getBindingsValuesProviders(ScriptEngine engine) {
+        String name = (String) engine.get(ScriptEngine.NAME);
+        Set<BindingsValuesProvider> results = new HashSet<BindingsValuesProvider>();
+        results.addAll(genericBindingsValuesProviders);
+        Collection<BindingsValuesProvider> langProviders = langBindingsValuesProviders.get(name);
+        if (langProviders != null) {
+            results.addAll(langProviders);
+        }
+        return langProviders;
+    }
+
     protected void bindScriptEngineFactory(
             ScriptEngineFactory scriptEngineFactory) {
         engineSpiServices.add(scriptEngineFactory);
@@ -350,4 +381,33 @@
         postEvent(SlingScriptConstants.TOPIC_SCRIPT_ENGINE_FACTORY_REMOVED, scriptEngineFactory);
     }
 
+    protected void bindBindingsValuesProvider(ServiceReference ref) {
+        String engineName = (String) ref.getProperty(ScriptEngine.NAME);
+        BindingsValuesProvider service = (BindingsValuesProvider)bundleContext.getService(ref);
+        if (engineName == null) {
+            genericBindingsValuesProviders.add(service);
+        } else {
+            Collection<BindingsValuesProvider> langProviders = langBindingsValuesProviders.get(engineName);
+            if (langProviders == null) {
+                langProviders = new HashSet<BindingsValuesProvider>();
+                langBindingsValuesProviders.put(engineName, langProviders);
+            }
+
+            langProviders.add(service);
+        }
+    }
+
+    protected void unbindBindingsValuesProvider(ServiceReference ref) {
+        String engineName = (String) ref.getProperty(ScriptEngine.NAME);
+        BindingsValuesProvider service = (BindingsValuesProvider)bundleContext.getService(ref);
+        if (engineName == null) {
+            genericBindingsValuesProviders.remove(service);
+        } else {
+            Collection<BindingsValuesProvider> langProviders = langBindingsValuesProviders.get(engineName);
+            if (langProviders != null) {
+                langProviders.remove(service);
+            }
+        }
+    }
+
 }

Added: 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=902942&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java (added)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/helper/ProtectedBindings.java Mon Jan 25 19:31:55 2010
@@ -0,0 +1,129 @@
+package org.apache.sling.scripting.core.impl.helper;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.script.Bindings;
+
+@SuppressWarnings("restriction")
+public class ProtectedBindings implements Bindings {
+
+    private final Bindings wrapped;
+    private final Set<String> protectedKeys;
+
+    public ProtectedBindings(Bindings wrapped) {
+        this.wrapped = wrapped;
+        this.protectedKeys = Collections.unmodifiableSet(wrapped.keySet());
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @throws an IllegalArgumentException if the key is protected
+     */
+    public Object put(String key, Object value) {
+        if (protectedKeys.contains(key)) {
+            throw new IllegalArgumentException(String.format("Key %s is protected.", key));
+        }
+        return wrapped.put(key, value);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void putAll(Map<? extends String, ? extends Object> toMerge) {
+        for (String key : toMerge.keySet()) {
+            if (!protectedKeys.contains(key)) {
+                wrapped.put(key, toMerge.get(key));
+            }
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @throws an IllegalArgumentException if the key is protected
+     */
+    public Object remove(Object key) {
+        if (protectedKeys.contains(key)) {
+            throw new IllegalArgumentException(String.format("Key %s is protected.", key));
+        }
+        return wrapped.remove(key);
+    }
+
+    /**
+     * The clear operation is not supported.
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("ProtectedBindings does not support clear()");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean containsValue(Object value) {
+        return wrapped.containsValue(value);
+    }
+
+    /**
+     * Returns a Set view of the mappings contains in this map. The Set is
+     * unmodifiable.
+     *
+     * @return an unmodifiable Set view of the map
+     */
+    public Set<java.util.Map.Entry<String, Object>> entrySet() {
+        return Collections.unmodifiableSet(wrapped.entrySet());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEmpty() {
+        return wrapped.isEmpty();
+    }
+
+    /**
+     * Returns a Set view of the keys contained in this map. The Set is
+     * unmodifiable.
+     *
+     * @return an unmodifiable Set view of the map's keys
+     */
+    public Set<String> keySet() {
+        return Collections.unmodifiableSet(wrapped.keySet());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int size() {
+        return wrapped.size();
+    }
+
+    /**
+     * Returns a Collection view of the values contained in this map. The
+     * Collection is unmodifiable.
+     *
+     * @return an unmodifiable Collection view of the map's values
+     */
+    public Collection<Object> values() {
+        return Collections.unmodifiableCollection(wrapped.values());
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean containsKey(Object key) {
+        return wrapped.containsKey(key);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object get(Object key) {
+        return wrapped.get(key);
+    }
+
+}

Modified: sling/trunk/launchpad/test-services/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/pom.xml?rev=902942&r1=902941&r2=902942&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/pom.xml (original)
+++ sling/trunk/launchpad/test-services/pom.xml Mon Jan 25 19:31:55 2010
@@ -7,9 +7,9 @@
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
-    
+
     http://www.apache.org/licenses/LICENSE-2.0
-    
+
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -73,6 +73,11 @@
             <version>2.0.8</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.api</artifactId>
+            <version>2.0.3-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/GroovyBindingsValuesProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/GroovyBindingsValuesProvider.java?rev=902942&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/GroovyBindingsValuesProvider.java (added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/GroovyBindingsValuesProvider.java Mon Jan 25 19:31:55 2010
@@ -0,0 +1,39 @@
+package org.apache.sling.launchpad.testservices.scripting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import javax.script.Bindings;
+
+import org.apache.sling.scripting.api.BindingsValuesProvider;
+/** Example/test BindingsValuesProvider targeting groovy scripts.
+*
+* @scr.component immediate="true" metatype="no"
+* @scr.service
+*
+* @scr.property name="service.description" value="Groovy BindingsValuesProvider"
+* @scr.property name="service.vendor" value="The Apache Software Foundation"
+*
+* @scr.property name="javax.script.name" value="groovy"
+*/
+public class GroovyBindingsValuesProvider implements BindingsValuesProvider {
+
+    public void addBindings(Bindings bindings) {
+       bindings.put("groovyHelloWorld", "Hello World from Groovy!");
+    }
+
+}

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StringBindingsValuesProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StringBindingsValuesProvider.java?rev=902942&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StringBindingsValuesProvider.java (added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StringBindingsValuesProvider.java Mon Jan 25 19:31:55 2010
@@ -0,0 +1,37 @@
+package org.apache.sling.launchpad.testservices.scripting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import javax.script.Bindings;
+
+import org.apache.sling.scripting.api.BindingsValuesProvider;
+/** Example/test BindingsValuesProvider targetting all scripts.
+*
+* @scr.component immediate="true" metatype="no"
+* @scr.service
+*
+* @scr.property name="service.description" value="String BindingsValuesProvider"
+* @scr.property name="service.vendor" value="The Apache Software Foundation"
+*/
+public class StringBindingsValuesProvider implements BindingsValuesProvider {
+
+    public void addBindings(Bindings bindings) {
+        bindings.put("helloWorld", "Hello World!");
+    }
+
+}

Added: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java?rev=902942&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java (added)
+++ sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ScriptBindingsValuesProviderTest.java Mon Jan 25 19:31:55 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.servlets.post.SlingPostConstants;
+
+public class ScriptBindingsValuesProviderTest extends RenderingTestBase {
+
+    private String slingResourceType;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // set test values
+        slingResourceType = "integration-test/srt." + System.currentTimeMillis();
+        testText = "This is a test " + System.currentTimeMillis();
+
+        // create the test node, under a path that's specific to this class to allow collisions
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("sling:resourceType", slingResourceType);
+        props.put("text", testText);
+        displayUrl = testClient.createNode(url, props);
+
+        // the rendering script goes under /apps in the repository
+        scriptPath = "/apps/" + slingResourceType;
+        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+    }
+
+    public void testGenericProvider() throws IOException {
+        final String toDelete = uploadTestScript("bindingsprovided.esp","html.esp");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes ESP marker (" + content + ")",content.contains("ESP template"));
+            assertTrue("Content includes test text (" + content + ")", content.contains("Hello World!"));
+            assertFalse("Content doesn't include Groovy-specific test text (" + content + ")", content.contains("Hello World from Groovy!"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+
+    public void testGroovyProvider() throws IOException {
+        final String toDelete = uploadTestScript("bindingsprovided.groovy","html.groovy");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes ESP marker (" + content + ")",content.contains("ESP template"));
+            assertTrue("Content includes test text (" + content + ")", content.contains("Hello World!"));
+            assertTrue("Content includes Groovy-specific test text (" + content + ")", content.contains("Hello World from Groovy!"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+
+}

Added: sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.esp
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.esp?rev=902942&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.esp (added)
+++ sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.esp Mon Jan 25 19:31:55 2010
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+<%-- used by ScriptBindingsValuesProviderTest --%>
+<html>
+	<body>
+		<h1>ESP template</h1>
+		<p>helloWorld:<%= helloWorld %></p>
+		<p>groovyHelloWorld:<%= groovyHelloWorld %></p>
+	</body>
+</html>

Added: sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.groovy
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.groovy?rev=902942&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.groovy (added)
+++ sling/trunk/launchpad/testing/src/test/resources/integration-test/bindingsprovided.groovy Mon Jan 25 19:31:55 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+out.write """<html>
+    <body>
+        <h1>ESP template</h1>
+        <p>helloWorld:${helloWorld}</p>
+        <p>groovyHelloWorld:${groovyHelloWorld}</p>
+    </body>
+</html>"""
\ No newline at end of file