Author: justin Date: Mon Jan 25 20:34:23 2010 New Revision: 902967 URL: http://svn.apache.org/viewvc?rev=902967&view=rev Log: SLING-1304 - moving currentNode script binding to jcr.resource bundle
Added: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java Modified: sling/trunk/bundles/jcr/resource/pom.xml sling/trunk/bundles/scripting/core/pom.xml sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java Modified: sling/trunk/bundles/jcr/resource/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/pom.xml?rev=902967&r1=902966&r2=902967&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/pom.xml (original) +++ sling/trunk/bundles/jcr/resource/pom.xml Mon Jan 25 20:34:23 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 @@ -59,6 +59,9 @@ <extensions>true</extensions> <configuration> <instructions> + <Import-Package> + org.apache.sling.scripting.api.*;resolution:=optional,* + </Import-Package> <Export-Package> org.apache.sling.jcr.resource;version=${pom.version} </Export-Package> @@ -115,6 +118,12 @@ <version>2.0.8</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.scripting.api</artifactId> + <version>2.0.3-SNAPSHOT</version> + <scope>provided</scope> + </dependency> <dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> @@ -173,7 +182,7 @@ <version>1.6.0</version> <scope>provided</scope> </dependency> - + <!-- Testing --> <dependency> <groupId>org.apache.sling</groupId> Added: 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/CurrentNodeBindingsValuesProvider.java?rev=902967&view=auto ============================================================================== --- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java (added) +++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/scripting/CurrentNodeBindingsValuesProvider.java Mon Jan 25 20:34:23 2010 @@ -0,0 +1,48 @@ +/* + * 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.jcr.resource.internal.scripting; + +import javax.jcr.Node; +import javax.script.Bindings; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.scripting.api.BindingsValuesProvider; + +/** + * BindingsValuesProvider for currentNode object. + * + * @scr.component immediate="true" metatype="no" + * @scr.service + * + * @scr.property name="service.description" value="CurrentNode BindingsValuesProvider" + * @scr.property name="service.vendor" value="The Apache Software Foundation" + */ +public class CurrentNodeBindingsValuesProvider implements BindingsValuesProvider { + + /** + * {...@inheritdoc} + */ + public void addBindings(Bindings bindings) { + Resource resource = (Resource) bindings.get("resource"); + Node node = resource.adaptTo(Node.class); + if (node != null) { + bindings.put("currentNode", node); + } + + } + +} Modified: sling/trunk/bundles/scripting/core/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/pom.xml?rev=902967&r1=902966&r2=902967&view=diff ============================================================================== --- sling/trunk/bundles/scripting/core/pom.xml (original) +++ sling/trunk/bundles/scripting/core/pom.xml Mon Jan 25 20:34:23 2010 @@ -53,9 +53,6 @@ <extensions>true</extensions> <configuration> <instructions> - <Import-Package> - javax.jcr;resolution:=optional,* - </Import-Package> <Export-Package> org.apache.sling.scripting.core;version=2.0.8 </Export-Package> 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=902967&r1=902966&r2=902967&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 20:34:23 2010 @@ -79,20 +79,6 @@ /** The logger. */ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSlingScript.class); - // name of the global variable containing the node to which the - // resource adapts (null if the resource does not adapt to a node - private static final String NODE = "currentNode"; - - /** Contains the javax.jcr.Node class if it is available. */ - private static Class<?> JCR_NODE_CLASS; - static { - try { - JCR_NODE_CLASS = DefaultSlingScript.class.getClassLoader().loadClass("javax.jcr.Node"); - } catch (Exception ignore) { - LOGGER.info("Binding {} is not active as the javax.jcr.Node class is not available.", NODE); - } - } - /** Thread local containing the resource resolver. */ private static ThreadLocal<ResourceResolver> requestResourceResolver = new ThreadLocal<ResourceResolver>(); @@ -536,14 +522,6 @@ bindings.put(RESPONSE, sling.getResponse()); bindings.put(RESOURCE, sling.getRequest().getResource()); bindings.put(OUT, sling.getResponse().getWriter()); - - // set the current node if the resource is node based - if ( JCR_NODE_CLASS != null ) { - final Object node = sling.getRequest().getResource().adaptTo(JCR_NODE_CLASS); - if (node != null) { - bindings.put(NODE, node); - } - } } Object logObject = slingBindings.get(LOG);