incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r586538 - /incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
Date Fri, 19 Oct 2007 16:58:50 GMT
Author: fmeschbe
Date: Fri Oct 19 09:58:49 2007
New Revision: 586538

URL: http://svn.apache.org/viewvc?rev=586538&view=rev
Log:
SLING-72 Fix three issues with the ScriptResolver: nt:file node handling if jcr:content is
nt:unstructured; wrong test for node item; wrong behaviour for requests with selectors.

Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?rev=586538&r1=586537&r2=586538&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java
Fri Oct 19 09:58:49 2007
@@ -104,6 +104,10 @@
             // evaluate the script now using the ScriptEngine
             script.getScriptEngine().eval(script.getScriptSource(), props);
 
+            resp.getWriter().println("<!-- This is the end -->");
+            resp.getWriter().flush();
+
+
             return true;
 
         } catch (IOException ioe) {
@@ -129,46 +133,55 @@
             return null;
         }
 
-        final String scriptFilename = scriptFilenameBuilder.buildScriptFilename(
+        String scriptFilename = scriptFilenameBuilder.buildScriptFilename(
             method,
             ctx.getRequestPathInfo().getSelectorString(),
             ctx.getResponseContentType(),
             "*"
         );
-
-        // this is the location of the trailing asterisk
-        final int scriptExtensionOffset = scriptFilename.length() - 1;
-
-        final String scriptPath =
+        String scriptPath =
             SCRIPT_BASE_PATH
             + "/"
             + r.getResourceType()
             ;
 
+        // SLING-72: if the scriptfilename contains a relative path, move that
+        // to the scriptPath and make the scriptFilename a direct child pattern
+        int lastSlash = scriptFilename.lastIndexOf('/');
+        if (lastSlash >= 0) {
+            scriptPath += "/" + scriptFilename.substring(0, lastSlash);
+            scriptFilename = scriptFilename.substring(lastSlash + 1);
+        }
+
+        // this is the location of the trailing asterisk
+        final int scriptExtensionOffset = scriptFilename.length() - 1;
+
         if(s.itemExists(scriptPath)) {
 
             // get the item and ensure it is a node
             final Item i = s.getItem(scriptPath);
             if (i.isNode()) {
-                return null;
-            }
-
-            Node parent = (Node) i;
-            NodeIterator scriptNodeIterator = parent.getNodes(scriptFilename);
-            while (scriptNodeIterator.hasNext()) {
-                Node scriptNode = scriptNodeIterator.nextNode();
-
-                String scriptName = scriptNode.getName();
-                String scriptExt = scriptName.substring(scriptExtensionOffset);
-                ScriptEngine scriptEngine = scriptEngines.get(scriptExt);
-
-                if (scriptEngine != null) {
-                    Script script = new Script();
-                    script.setNode(scriptNode);
-                    script.setScriptPath(scriptNode.getPath());
-                    script.setScriptEngine(scriptEngine);
-                    result = script;
-                    break;
+                Node parent = (Node) i;
+                NodeIterator scriptNodeIterator = parent.getNodes(scriptFilename);
+                while (scriptNodeIterator.hasNext()) {
+                    Node scriptNode = scriptNodeIterator.nextNode();
+
+                    // SLING-72: Require the node to be an nt:file
+                    if (scriptNode.isNodeType("nt:file")) {
+
+                        String scriptName = scriptNode.getName();
+                        String scriptExt = scriptName.substring(scriptExtensionOffset);
+                        ScriptEngine scriptEngine = scriptEngines.get(scriptExt);
+
+                        if (scriptEngine != null) {
+                            Script script = new Script();
+                            script.setNode(scriptNode);
+                            script.setScriptPath(scriptNode.getPath());
+                            script.setScriptEngine(scriptEngine);
+                            result = script;
+                            break;
+                        }
+                    }
                 }
             }
         }
@@ -250,20 +263,10 @@
          */
         Reader getScriptSource() throws RepositoryException, IOException {
 
-            // resolve the script node to a property or fail if not possible
-            // in case of a nt:file/nt:resource node tuple, the nt:file node
-            // will first resolve to the jcr:content child node of type
-            // nt:resource which in turn will resolve to the jcr:data node.
-            // Other node types may be defined similarly. Using the primary item
-            // prevents restricting this code to nt:file/nt:resource nodes
-            Item item = getNode();
-            while (item.isNode()) {
-                item = ((Node) item).getPrimaryItem();
-            }
-
-            // if we end the loop without being thrown, the item is now a
-            // Property, which we have to check whether it is multivalued
-            Property property = (Property) item;
+            // 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 property = getNode().getProperty("jcr:content/jcr:data");
             Value value = null;
             if (property.getDefinition().isMultiple()) {
                 // for a multi-valued property, we take the first non-null



Mime
View raw message