incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r591268 - in /incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling: resource/ scripting/ scripting/engines/freemarker/ scripting/engines/rhino/ scripting/engines/velocity/
Date Fri, 02 Nov 2007 08:55:04 GMT
Author: fmeschbe
Date: Fri Nov  2 01:55:03 2007
New Revision: 591268

URL: http://svn.apache.org/viewvc?rev=591268&view=rev
Log:
Adapt to the new Script interface having the script resource and not the script path
and make JcrNodeResource public to be used by the ScriptResolver (SLING-88)

Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptServlet.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/rhino/RhinoJavasSriptEngine.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/velocity/VelocityTemplatesScriptEngine.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java?rev=591268&r1=591267&r2=591268&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
Fri Nov  2 01:55:03 2007
@@ -24,7 +24,7 @@
 import org.apache.sling.api.resource.ResourceMetadata;
 
 /** A Resource that wraps a JCR Node */
-class JcrNodeResource implements Resource {
+public class JcrNodeResource implements Resource {
     private final Node node;
     private final String path;
     private final String resourceType;
@@ -45,7 +45,7 @@
         resourceType = getResourceTypeForNode(node);
     }
 
-    JcrNodeResource(Node node) throws RepositoryException {
+    public JcrNodeResource(Node node) throws RepositoryException {
         this.node = node;
         this.path = node.getPath();
         metadata = new ResourceMetadata();

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java?rev=591268&r1=591267&r2=591268&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptResolver.java
Fri Nov  2 01:55:03 2007
@@ -40,6 +40,7 @@
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptEngine;
 import org.apache.sling.api.scripting.SlingScriptResolver;
+import org.apache.sling.microsling.resource.JcrNodeResource;
 import org.apache.sling.microsling.scripting.engines.freemarker.FreemarkerScriptEngine;
 import org.apache.sling.microsling.scripting.engines.rhino.RhinoJavasSriptEngine;
 import org.apache.sling.microsling.scripting.engines.velocity.VelocityTemplatesScriptEngine;
@@ -104,10 +105,9 @@
             props.put(SlingScriptEngine.SLING, helper);
             props.put(SlingScriptEngine.RESOURCE, helper.getRequest().getResource());
             props.put(SlingScriptEngine.REQUEST, helper.getRequest());
-            props.put(SlingScriptEngine.RESOURCE, helper.getRequest().getResource());
             props.put(SlingScriptEngine.RESPONSE, helper.getResponse());
             props.put(SlingScriptEngine.OUT, helper.getResponse().getWriter());
-            props.put(SlingScriptEngine.LOG, LoggerFactory.getLogger(script.getScriptPath()));
+            props.put(SlingScriptEngine.LOG, LoggerFactory.getLogger(script.getScriptResource().getURI()));
 
             resp.setContentType(req.getResponseContentType()
                 + "; charset=UTF-8");
@@ -206,8 +206,7 @@
 
                         if (scriptEngine != null) {
                             MicroslingScript script = new MicroslingScript();
-                            script.setNode(scriptNode);
-                            script.setScriptPath(scriptNode.getPath());
+                            script.setScriptResource(new JcrNodeResource(scriptNode));
                             script.setScriptEngine(scriptEngine);
                             result = script;
                             break;
@@ -218,11 +217,12 @@
         }
 
         if (result != null) {
-            log.info("Found nt:file script node " + result.getScriptPath()
-                + " for Resource=" + r);
+            log.info("Found nt:file script node {} for Resource={}",
+                result.getScriptResource().getURI(), r);
         } else {
-            log.debug("nt:file script node not found at path=" + scriptPath
-                + " for Resource=" + r);
+            log.debug(
+                "nt:file script node not found at path={} for Resource={}",
+                scriptPath, r);
         }
 
         return result;
@@ -250,67 +250,44 @@
     }
 
     private static class MicroslingScript implements SlingScript {
-        private Node node;
 
-        private String scriptPath;
+        private Resource scriptResource;
 
         private SlingScriptEngine scriptEngine;
 
-        /**
-         * @return the node
-         */
-        Node getNode() {
-            return node;
-        }
-
-        /**
-         * @param node the node to set
-         */
-        void setNode(Node node) {
-            this.node = node;
-        }
-
-        /**
-         * @return the scriptPath
-         */
-        public String getScriptPath() {
-            return scriptPath;
+        public Resource getScriptResource() {
+            return scriptResource;
         }
 
-        /**
-         * @param scriptPath the scriptPath to set
-         */
-        void setScriptPath(String scriptPath) {
-            this.scriptPath = scriptPath;
+        void setScriptResource(Resource scriptResource) {
+            this.scriptResource = scriptResource;
         }
 
-        /**
-         * @return the scriptEngine
-         */
         public SlingScriptEngine getScriptEngine() {
             return scriptEngine;
         }
 
-        /**
-         * @param scriptEngine the scriptEngine to set
-         */
         void setScriptEngine(SlingScriptEngine scriptEngine) {
             this.scriptEngine = scriptEngine;
         }
 
-        /**
-         * @return The script stored in the node as a Reader
-         */
         public Reader getScriptReader() throws IOException {
 
             Property property;
             Value value;
 
             try {
-                // SLING-72: Cannot use primary items due to WebDAV creating
-                // nt:unstructured as jcr:content node. So we just assume
-                // nt:file and try to use the well-known data path
-                property = getNode().getProperty("jcr:content/jcr:data");
+
+                if (getScriptResource().getRawData() instanceof Node) {
+                    // SLING-72: Cannot use primary items due to WebDAV creating
+                    // nt:unstructured as jcr:content node. So we just assume
+                    // nt:file and try to use the well-known data path
+                    Node node = (Node) getScriptResource().getRawData();
+                    property = node.getProperty("jcr:content/jcr:data");
+                } else {
+                    throw new IOException("Scriptresource " + getScriptResource() + " must
is not JCR Node based");
+                }
+
                 value = null;
                 if (property.getDefinition().isMultiple()) {
                     // for a multi-valued property, we take the first non-null
@@ -328,7 +305,7 @@
                     // incase we could not find a non-null value, we bail out
                     if (value == null) {
                         throw new IOException("Cannot access "
-                            + getScriptPath());
+                            + getScriptResource().getURI());
                     }
                 } else {
                     // for single-valued properties, we just take this value
@@ -336,7 +313,7 @@
                 }
             } catch (RepositoryException re) {
                 throw (IOException) new IOException("Cannot get script "
-                    + getScriptPath()).initCause(re);
+                    + getScriptResource().getURI()).initCause(re);
             }
 
             // Now know how to get the input stream, we still have to decide
@@ -364,7 +341,7 @@
                     new InputStreamReader(input, encoding));
             } catch (RepositoryException re) {
                 throw (IOException) new IOException("Cannot get script "
-                    + getScriptPath()).initCause(re);
+                    + getScriptResource().getURI()).initCause(re);
             }
         }
     }

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptServlet.java?rev=591268&r1=591267&r2=591268&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/MicroslingScriptServlet.java
Fri Nov  2 01:55:03 2007
@@ -49,7 +49,7 @@
     }
 
     public String getServletInfo() {
-        return "Servlet for script " + script.getScriptPath();
+        return "Servlet for script " + script.getScriptResource().getURI();
     }
 
     public void init(ServletConfig config) {

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java?rev=591268&r1=591267&r2=591268&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/freemarker/FreemarkerScriptEngine.java
Fri Nov  2 01:55:03 2007
@@ -60,7 +60,6 @@
     public void eval(SlingScript script, Map<String, Object> props)
             throws SlingException, IOException {
 
-        String scriptName = script.getScriptPath();
         // ensure get method
         HttpServletRequest request = (HttpServletRequest) props.get(REQUEST);
         if (!"GET".equals(request.getMethod())) {
@@ -69,6 +68,7 @@
                 "FreeMarker templates only support GET requests");
         }
 
+        String scriptName = script.getScriptResource().getURI();
         Template tmpl = new Template(scriptName, script.getScriptReader(),
             configuration);
 

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/rhino/RhinoJavasSriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/rhino/RhinoJavasSriptEngine.java?rev=591268&r1=591267&r2=591268&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/rhino/RhinoJavasSriptEngine.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/rhino/RhinoJavasSriptEngine.java
Fri Nov  2 01:55:03 2007
@@ -62,9 +62,11 @@
     public void eval(SlingScript script, Map<String, Object> props)
             throws SlingException, IOException {
 
+        String scriptName = script.getScriptResource().getURI();
+
         // wrap the reader in an EspReader for ESP scripts
         Reader scriptReader = script.getScriptReader();
-        if (script.getScriptPath().endsWith(ESP_SCRIPT_EXTENSION)) {
+        if (scriptName.endsWith(ESP_SCRIPT_EXTENSION)) {
             scriptReader = new EspReader(scriptReader);
         }
 
@@ -82,14 +84,13 @@
             final int lineNumber = 1;
             final Object securityDomain = null;
 
-            rhinoContext.evaluateReader(scope, scriptReader,
-                script.getScriptPath(), lineNumber, securityDomain);
+            rhinoContext.evaluateReader(scope, scriptReader, scriptName,
+                lineNumber, securityDomain);
 
         } catch (IOException ioe) {
             throw ioe;
         } catch (Throwable t) {
-            throw new SlingException("Failure running script "
-                + script.getScriptPath(), t);
+            throw new SlingException("Failure running script " + scriptName, t);
         } finally {
             Context.exit();
         }

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/velocity/VelocityTemplatesScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/velocity/VelocityTemplatesScriptEngine.java?rev=591268&r1=591267&r2=591268&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/velocity/VelocityTemplatesScriptEngine.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/engines/velocity/VelocityTemplatesScriptEngine.java
Fri Nov  2 01:55:03 2007
@@ -88,7 +88,7 @@
             throw ioe;
         } catch (Throwable t) {
             throw new SlingException("Failure running script "
-                + script.getScriptPath(), t);
+                + script.getScriptResource().getURI(), t);
         }
     }
 }



Mime
View raw message