incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r896867 - in /sling/trunk/bundles/scripting/core: pom.xml src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java
Date Thu, 07 Jan 2010 12:54:10 GMT
Author: cziegeler
Date: Thu Jan  7 12:53:08 2010
New Revision: 896867

URL: http://svn.apache.org/viewvc?rev=896867&view=rev
Log:
SLING-1269 : Make dependency to jcr optional

Modified:
    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/scripting/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/pom.xml?rev=896867&r1=896866&r2=896867&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/pom.xml (original)
+++ sling/trunk/bundles/scripting/core/pom.xml Thu Jan  7 12:53:08 2010
@@ -53,6 +53,9 @@
                 <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>
@@ -128,24 +131,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.commons.osgi</artifactId>
-            <version>2.0.2-incubator</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.mime</artifactId>
             <version>2.0.2-incubator</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.api</artifactId>
-            <version>2.0.2-incubator</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.api</artifactId>
             <version>2.0.2-incubator</version>
             <scope>provided</scope>

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=896867&r1=896866&r2=896867&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
Thu Jan  7 12:53:08 2010
@@ -41,7 +41,6 @@
 import java.util.Hashtable;
 import java.util.Map;
 
-import javax.jcr.Node;
 import javax.script.Bindings;
 import javax.script.Invocable;
 import javax.script.ScriptContext;
@@ -74,12 +73,22 @@
 
 class DefaultSlingScript implements SlingScript, Servlet, ServletConfig {
 
-	// name of the global variable containing the node to which the
+    /** 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";
 
-    /** The logger. */
-    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSlingScript.class);
+    /** 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>();
@@ -521,9 +530,11 @@
             bindings.put(OUT, sling.getResponse().getWriter());
 
             // set the current node if the resource is node based
-            Node node = sling.getRequest().getResource().adaptTo(Node.class);
-            if (node != null) {
-                bindings.put(NODE, node);
+            if ( JCR_NODE_CLASS != null ) {
+                final Object node = sling.getRequest().getResource().adaptTo(JCR_NODE_CLASS);
+                if (node != null) {
+                    bindings.put(NODE, node);
+                }
             }
         }
 



Mime
View raw message