incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r629835 - in /incubator/sling/trunk/sling/core/src: main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
Date Thu, 21 Feb 2008 15:46:25 GMT
Author: bdelacretaz
Date: Thu Feb 21 07:46:24 2008
New Revision: 629835

URL: http://svn.apache.org/viewvc?rev=629835&view=rev
Log:
SLING-250 - fix SlingRequestPathInfo to handle paths starting with /. - contributed by Lars
Trieloff, thanks\!

Modified:
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
    incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java?rev=629835&r1=629834&r2=629835&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
Thu Feb 21 07:46:24 2008
@@ -64,7 +64,33 @@
             pathToParse = pathToParse.substring(resourcePath.length());
         }
 
-        if (pathToParse.startsWith("/")) {
+        if (pathToParse.startsWith("/.")) {
+            final int lastDot = pathToParse.lastIndexOf('.');
+            
+            if (1==lastDot) {
+            	selectorString = null;
+                selectors = NO_SELECTORS;
+            } else {
+            	String tmpSel = pathToParse.substring(2, lastDot);
+                selectors = tmpSel.split("\\.");
+                selectorString = (selectors.length > 0) ? tmpSel : null;
+            	
+            	//selectorString = pathToParse.substring(firstDot, lastDot - firstDot);
+            	
+            }
+            
+            final int lastSlash = pathToParse.lastIndexOf('/');
+            if (lastSlash == 0) {
+            	suffix = "";
+            	extension = pathToParse.substring(lastDot + 1);
+            } else {
+            	final int secondSlash = pathToParse.indexOf("/", 1);
+            	suffix = pathToParse.substring(secondSlash);
+            	String prefix = pathToParse.substring(0, secondSlash);
+            	final int extensionDot = prefix.lastIndexOf(".");
+            	extension = prefix.substring(extensionDot + 1);
+            }
+        } else if (pathToParse.startsWith("/")) {
             // resolution path is up in the hierarchy
             // from request path: split the remainder
             // in suffix and extension only

Modified: incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java?rev=629835&r1=629834&r2=629835&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
(original)
+++ incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
Thu Feb 21 07:46:24 2008
@@ -266,6 +266,53 @@
         assertEquals("12005879509741.json",p.getSuffix());
     }
 
+    public void testJIRA_250_a() {
+    	RequestPathInfo p = 
+            new SlingRequestPathInfo(
+                    new MockResource("/bunkai"), 
+                    "/bunkai.1.json"
+            );
+        assertEquals("/bunkai", p.getResourcePath());
+        assertEquals("json", p.getExtension());
+        assertEquals("1", p.getSelectorString());
+    }
+    
+    public void testJIRA_250_b() {
+    	RequestPathInfo p = 
+            new SlingRequestPathInfo(
+                    new MockResource("/"), 
+                    "/.1.json"
+            );
+        assertEquals("/", p.getResourcePath());
+        assertEquals("json", p.getExtension());
+        assertEquals("", p.getSuffix());
+        assertEquals("Selector string must not be null", "1", p.getSelectorString());
+    }
+    
+    public void testJIRA_250_c() {
+    	RequestPathInfo p = 
+            new SlingRequestPathInfo(
+                    new MockResource("/"), 
+                    "/.1.json/my/suffix"
+            );
+        assertEquals("/", p.getResourcePath());
+        assertEquals("json", p.getExtension());
+        assertEquals("/my/suffix",p.getSuffix());
+        assertEquals("Selector string must not be null", "1", p.getSelectorString());
+    }
+    
+    public void testJIRA_250_d() {
+    	RequestPathInfo p = 
+            new SlingRequestPathInfo(
+                    new MockResource("/"), 
+                    "/.json"
+            );
+        assertEquals("/", p.getResourcePath());
+        assertEquals("json", p.getExtension());
+        assertEquals("", p.getSuffix());
+        assertNull(p.getSelectorString());
+    }
+    
     static class MockResource implements Resource {
 
         private final ResourceMetadata metadata;



Mime
View raw message