incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r600919 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/scripting/ main/java/org/apache/sling/microsling/scripting/helpers/ test/java/org/apache/sling/microsling/integration/ test/java/org/a...
Date Tue, 04 Dec 2007 12:57:41 GMT
Author: bdelacretaz
Date: Tue Dec  4 04:57:40 2007
New Revision: 600919

URL: http://svn.apache.org/viewvc?rev=600919&view=rev
Log:
SLING-117 : MicroslingScriptResolver did not go up the path for selectors, fixed

Added:
    incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-2.esp
    incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-3.esp
Modified:
    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/helpers/ScriptFilenameBuilder.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java

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=600919&r1=600918&r2=600919&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
Tue Dec  4 04:57:40 2007
@@ -22,6 +22,8 @@
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Item;
@@ -167,50 +169,65 @@
 
         String scriptFilename = scriptFilenameBuilder.buildScriptFilename(
             request.getMethod(),
-            request.getRequestPathInfo().getSelectorString(),
             request.getRequestPathInfo().getExtension(), 
             "*");
         String scriptPath = scriptFilenameBuilder.buildScriptPath(r);
-
-        // 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 (log.isDebugEnabled()) {
-            log.debug("Looking for script with filename=" + scriptFilename
-                + " under " + scriptPath);
+        // if there are selectors A and B, look for a script first at
+        // A/B/scriptFilename, then A/scriptFilename, then scriptFilename
+        final List<String> possiblePaths = new LinkedList<String> ();
+        final String [] selectors = request.getRequestPathInfo().getSelectors();
+        if(selectors!=null) {
+            final StringBuffer sb = new StringBuffer();
+            sb.append(scriptPath);
+            for(int i=selectors.length - 1; i >= 0; i--) {
+                for(int j=0; j <= i; j++) {
+                    sb.append("/");
+                    sb.append(selectors[j]);
+                }
+                possiblePaths.add(sb.toString());
+            }
         }
-
-        if (s.itemExists(scriptPath)) {
-
-            // get the item and ensure it is a node
-            final Item i = s.getItem(scriptPath);
-            if (i.isNode()) {
-                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);
-                        SlingScriptEngine scriptEngine = scriptEngines.get(scriptExt);
-
-                        if (scriptEngine != null) {
-                            MicroslingScript script = new MicroslingScript();
-                            script.setScriptResource(new JcrNodeResource(scriptNode));
-                            script.setScriptEngine(scriptEngine);
-                            result = script;
-                            break;
+        possiblePaths.add(scriptPath);
+        
+        for(String currentPath : possiblePaths) {
+            
+            if(result != null) {
+                break;
+            }
+            
+            if (log.isDebugEnabled()) {
+                log.debug("Looking for script with filename=" + scriptFilename
+                    + " under " + scriptPath);
+            }
+            
+            if (s.itemExists(currentPath)) {
+    
+                // get the item and ensure it is a node
+                final Item i = s.getItem(currentPath);
+                if (i.isNode()) {
+                    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);
+                            SlingScriptEngine scriptEngine = scriptEngines.get(scriptExt);
+    
+                            if (scriptEngine != null) {
+                                MicroslingScript script = new MicroslingScript();
+                                script.setScriptResource(new JcrNodeResource(scriptNode));
+                                script.setScriptEngine(scriptEngine);
+                                result = script;
+                                break;
+                            }
                         }
                     }
                 }

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java?rev=600919&r1=600918&r2=600919&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
Tue Dec  4 04:57:40 2007
@@ -41,16 +41,8 @@
     public static final String SCRIPT_BASE_PATH = "/sling/scripts";
 
     /** @return a name like "html.js" or "print/a4/html.vlt" or "POST.js" */
-    public String buildScriptFilename(String methodName,String selectors,String requestExtension,String
scriptExtension) {
+    public String buildScriptFilename(String methodName,String requestExtension,String scriptExtension)
{
         final StringBuffer sb = new StringBuffer();
-
-        // path before filename:
-        // add selectors in front of the filename if any, replacing dots in them by slashes
-        // so that print.a4 becomes print/a4/
-        if(selectors != null) {
-            sb.append(selectors.toLowerCase().replace('.','/'));
-            sb.append('/');
-        }
 
         // filename:
         if(methodName==null || methodName.length() == 0) {

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=600919&r1=600918&r2=600919&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
Tue Dec  4 04:57:40 2007
@@ -37,7 +37,7 @@
         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();
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "_" + System.currentTimeMillis()
+ "/*";
         final Map<String,String> props = new HashMap<String,String>();
         props.put("sling:resourceType", slingResourceType);
         props.put("text", testText);
@@ -66,6 +66,35 @@
             assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
         } finally {
             testClient.delete(toDelete);
+        }
+    }
+
+    public void testEspHtmlWithSelectors() throws IOException {
+        final String toDeleteA = uploadTestScript("rendering-test.esp","html.esp");
+        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath + "/a4/print");
+        final String toDeleteB = uploadTestScript(scriptPath + "/a4","rendering-test-2.esp","html.esp");
+        final String toDeleteC = uploadTestScript(scriptPath + "/a4/print","rendering-test-3.esp","html.esp");
+        
+        try {
+            String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Without selectors, content includes standard marker",content.contains("ESP
template"));
+            assertTrue("Without selectors, content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+            
+            content = getContent(displayUrl + ".a4.print.html", CONTENT_TYPE_HTML);
+            assertTrue("With a4.print selectors, content includes marker 3",content.contains("Template
#3 for ESP tests"));
+            assertTrue("With a4.print selectors, content contains italic text",content.contains("<em>"
+ testText + "</em>"));
+            
+            content = getContent(displayUrl + ".a4.html", CONTENT_TYPE_HTML);
+            assertTrue("With a4 selector, content includes marker 2",content.contains("Template
#2 for ESP tests"));
+            assertTrue("With a4 selector, content contains bold text",content.contains("<b>"
+ testText + "</b>"));
+            
+            content = getContent(displayUrl + ".different.html", CONTENT_TYPE_HTML);
+            assertTrue("With different selector only, content includes standard marker",content.contains("ESP
template"));
+            assertTrue("With different selector only, content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDeleteA);
+            testClient.delete(toDeleteB);
+            testClient.delete(toDeleteC);
         }
     }
 

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java?rev=600919&r1=600918&r2=600919&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
Tue Dec  4 04:57:40 2007
@@ -32,62 +32,50 @@
     }
 
     public void testNull() {
-        assertEquals("NO_METHOD.NO_EXT",builder.buildScriptFilename(null,null,null,null));
+        assertEquals("NO_METHOD.NO_EXT",builder.buildScriptFilename(null,null,null));
     }
     
     public void testSimpleGet() {
-        assertEquals("html.js",builder.buildScriptFilename("GET",null,"html","js"));
+        assertEquals("html.js",builder.buildScriptFilename("GET","html","js"));
     }
     
     public void testGetAndNulls() {
-        assertEquals("GET.NO_EXT",builder.buildScriptFilename("GET",null,null,null));
+        assertEquals("GET.NO_EXT",builder.buildScriptFilename("GET",null,null));
     }
     
     public void testSimpleHead() {
-        assertEquals("HEAD.js",builder.buildScriptFilename("HEAD",null,"text/html","js"));
-    }
-    
-    public void testGetOneSelector() {
-        assertEquals("print/html.js",builder.buildScriptFilename("GET","print","html","js"));
-    }
-    
-    public void testGetTwoSelectors() {
-        assertEquals("print/a4/xml.vlt",builder.buildScriptFilename("GET","print.a4","xml","vlt"));
+        assertEquals("HEAD.js",builder.buildScriptFilename("HEAD","text/html","js"));
     }
     
     public void testSimplePost() {
-        assertEquals("POST.js",builder.buildScriptFilename("POST",null,"html","js"));
+        assertEquals("POST.js",builder.buildScriptFilename("POST","html","js"));
     }
     
     public void testSimplePut() {
-        assertEquals("PUT.js",builder.buildScriptFilename("PUT",null,"html","js"));
+        assertEquals("PUT.js",builder.buildScriptFilename("PUT","html","js"));
     }
     
     public void testSimpleDelete() {
-        assertEquals("DELETE.js",builder.buildScriptFilename("DELETE",null,"html","js"));
+        assertEquals("DELETE.js",builder.buildScriptFilename("DELETE","html","js"));
     }
     
     public void testGetTextMimeType() {
-        assertEquals("txt.js",builder.buildScriptFilename("GET",null,"txt","js"));
+        assertEquals("txt.js",builder.buildScriptFilename("GET","txt","js"));
     }
     
     public void testGetWhateverMimeType() {
-        assertEquals("whatever.js",builder.buildScriptFilename("GET",null,"whatever","js"));
+        assertEquals("whatever.js",builder.buildScriptFilename("GET","whatever","js"));
     }
     
     public void testGetNoSlashMimeType() {
-        assertEquals("bar.js",builder.buildScriptFilename("GET",null,"bar","js"));
+        assertEquals("bar.js",builder.buildScriptFilename("GET","bar","js"));
     }
     
     public void testCaseCleanupOne() {
-        assertEquals("POST.js",builder.buildScriptFilename("posT",null,"html","jS"));
+        assertEquals("POST.js",builder.buildScriptFilename("posT","html","jS"));
     }
     
     public void testCaseCleanupTwo() {
-        assertEquals("html.js",builder.buildScriptFilename("get",null,"HTML","JS"));
-    }
-    
-    public void testCaseCleanupThree() {
-        assertEquals("print/a4/html.js",builder.buildScriptFilename("get","PRInT.A4","HTML","JS"));
+        assertEquals("html.js",builder.buildScriptFilename("get","HTML","JS"));
     }
 }

Added: incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-2.esp
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-2.esp?rev=600919&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-2.esp
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-2.esp
Tue Dec  4 04:57:40 2007
@@ -0,0 +1,7 @@
+<%-- used by ScriptedRenderingTest --%>
+<html>
+	<body>
+		Template #2 for ESP tests 
+		<p><b><%= resource.node.text %></b></p>
+	</body>
+</html>

Added: incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-3.esp
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-3.esp?rev=600919&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-3.esp
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/rendering-test-3.esp
Tue Dec  4 04:57:40 2007
@@ -0,0 +1,7 @@
+<%-- used by ScriptedRenderingTest --%>
+<html>
+	<body>
+		Template #3 for ESP tests 
+		<p><em><%= resource.node.text %></em></p>
+	</body>
+</html>



Mime
View raw message