You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/08/27 12:44:30 UTC

svn commit: r689439 - in /incubator/sling/trunk: api/src/main/java/org/apache/sling/api/resource/ engine/src/test/java/org/apache/sling/engine/impl/request/ jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/ jcr/reso...

Author: bdelacretaz
Date: Wed Aug 27 03:44:29 2008
New Revision: 689439

URL: http://svn.apache.org/viewvc?rev=689439&view=rev
Log:
SLING-630 - StarResource did not initialize ResourceMetadata correctly

Added:
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java   (with props)
Modified:
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
    incubator/sling/trunk/engine/src/test/java/org/apache/sling/engine/impl/request/SlingRequestPathInfoTest.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
    incubator/sling/trunk/launchpad/jcrapp/pom.xml

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java?rev=689439&r1=689438&r2=689439&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java (original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java Wed Aug 27 03:44:29 2008
@@ -49,6 +49,18 @@
         this.resourceMetadata = new ResourceMetadata();
         this.resourceMetadata.setResolutionPath(path);
     }
+    
+    /**
+     * Creates a synthetic resource with the given <code>ResourceMetadata</code>
+     * and <code>resourceType</code>.
+     */
+    public SyntheticResource(ResourceResolver resourceResolver, ResourceMetadata rm, 
+    		String resourceType) {
+        this.resourceResolver = resourceResolver;
+        this.path = rm.getResolutionPath();
+        this.resourceType = resourceType;
+        this.resourceMetadata = rm;
+    }
 
     public String getPath() {
         return path;

Modified: incubator/sling/trunk/engine/src/test/java/org/apache/sling/engine/impl/request/SlingRequestPathInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/test/java/org/apache/sling/engine/impl/request/SlingRequestPathInfoTest.java?rev=689439&r1=689438&r2=689439&view=diff
==============================================================================
--- incubator/sling/trunk/engine/src/test/java/org/apache/sling/engine/impl/request/SlingRequestPathInfoTest.java (original)
+++ incubator/sling/trunk/engine/src/test/java/org/apache/sling/engine/impl/request/SlingRequestPathInfoTest.java Wed Aug 27 03:44:29 2008
@@ -40,19 +40,19 @@
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path", "."));
         assertEquals("/some/path", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Extension is null",p.getExtension());
+        assertNull("Suffix is null", p.getSuffix());
     }
 
     public void testTrailingDotWithSuffix() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path", "./suffix"));
         assertEquals("/some/path", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
+        assertNull("Extension is null",p.getExtension());
         assertEquals("/suffix", p.getSuffix());
     }
 
@@ -60,19 +60,19 @@
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path", ".."));
         assertEquals("/some/path", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Extension is null",p.getExtension());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testTrailingDotDotWithSuffix() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path", "../suffix"));
         assertEquals("/some/path", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
+        assertNull("Extension is null",p.getExtension());
         assertEquals("/suffix", p.getSuffix());
     }
 
@@ -80,19 +80,19 @@
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path", "..."));
         assertEquals("/some/path", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Extension is null",p.getExtension());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testTrailingDotDotDotWithSuffix() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path", ".../suffix"));
         assertEquals("/some/path", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
+        assertNull("Extension is null",p.getExtension());
         assertEquals("/suffix", p.getSuffix());
     }
 
@@ -112,40 +112,40 @@
         RequestPathInfo p = new SlingRequestPathInfo(
             new MockResource("/", null));
         assertEquals("/", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Extension is null",p.getExtension());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testPathOnly() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path/here", ""));
         assertEquals("/some/path/here", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Extension is null",p.getExtension());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testPathWithExtensionOnly() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path/here.html", ""));
         assertEquals("/some/path/here.html", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
-        assertNull(p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Extension is null",p.getExtension());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testPathAndExtensionOnly() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path/here", ".html"));
         assertEquals("/some/path/here", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
         assertEquals("html", p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testPathAndOneSelectorOnly() {
@@ -156,14 +156,14 @@
         assertEquals(1, p.getSelectors().length);
         assertEquals("print", p.getSelectors()[0]);
         assertEquals("html", p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Suffix is null",p.getSuffix());
     }
 
     public void testPathExtAndSuffix() {
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path/here", ".html/something"));
         assertEquals("/some/path/here", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
         assertEquals("html", p.getExtension());
         assertEquals("/something", p.getSuffix());
@@ -207,7 +207,7 @@
         RequestPathInfo p = new SlingRequestPathInfo(new MockResource(
             "/some/path.print.a4", ".html/some/suffix"));
         assertEquals("/some/path.print.a4", p.getResourcePath());
-        assertNull(p.getSelectorString());
+        assertNull("Selectors are null",p.getSelectorString());
         assertEquals(0, p.getSelectors().length);
         assertEquals("html", p.getExtension());
         assertEquals("/some/suffix", p.getSuffix());
@@ -226,7 +226,7 @@
             ".1.json"));
         assertEquals("/", p.getResourcePath());
         assertEquals("json", p.getExtension());
-        assertNull(p.getSuffix());
+        assertNull("Suffix is null",p.getSuffix());
         assertEquals("Selector string must not be null", "1",
             p.getSelectorString());
     }
@@ -246,8 +246,8 @@
             ".json"));
         assertEquals("/", p.getResourcePath());
         assertEquals("json", p.getExtension());
-        assertNull(p.getSuffix());
-        assertNull(p.getSelectorString());
+        assertNull("Suffix is null",p.getSuffix());
+        assertNull("Selectors are null",p.getSelectorString());
     }
 
     static class MockResource implements Resource {

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java?rev=689439&r1=689438&r2=689439&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java Wed Aug 27 03:44:29 2008
@@ -24,6 +24,7 @@
 
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.SyntheticResource;
 import org.apache.sling.jcr.resource.JcrResourceTypeProvider;
@@ -33,8 +34,7 @@
  */
 public class StarResource extends SyntheticResource {
 
-    public final static String PATH_PATTERN = "/*.";
-    public final static String PATH_CLEAN_SUFFIX = "/*";
+    final static String SLASH_STAR = "/*";
     public final static String DEFAULT_RESOURCE_TYPE = "sling:syntheticStarResource";
 
     @SuppressWarnings("serial")
@@ -48,7 +48,7 @@
      *  a real Resource was not found */
     public static boolean appliesTo(HttpServletRequest request) {
         String path = request.getPathInfo();
-        return path.contains(PATH_PATTERN) || path.endsWith(PATH_CLEAN_SUFFIX);
+        return path.contains(SLASH_STAR) || path.endsWith(SLASH_STAR);
     }
 
     /**
@@ -57,11 +57,11 @@
      * resource.
      */
     public static boolean isStarResource(Resource res) {
-        return res.getPath().endsWith(PATH_CLEAN_SUFFIX);
+        return res.getPath().endsWith(SLASH_STAR);
     }
 
     public StarResource(ResourceResolver resourceResolver, String path, JcrResourceTypeProvider[] jcrProviders) throws SlingException {
-        super(resourceResolver, convertPath(path), null);
+        super(resourceResolver, getResourceMetadata(path), null);
 
         // The only way we can set a meaningful resource type is via the drtp
         final Node n = new FakeNode(getPath());
@@ -90,17 +90,24 @@
     public <Type> Type adaptTo(Class<Type> type) {
         if(type == Node.class) {
             return (Type) new FakeNode(getPath());
+        } else if(type == String.class) {
+        	return (Type)"";
         }
         return null;
     }
-
-    /** Cleanup our path, for example /foo/*.html becomes /foo/* */
-    protected static String convertPath(String path) {
-        final int index = path.indexOf(PATH_PATTERN);
+    
+    /** Get our ResourceMetadata for given path */
+    static ResourceMetadata getResourceMetadata(String path) {
+    	ResourceMetadata result = new ResourceMetadata();
+    	
+    	// The path is up to /*, what follows is pathInfo
+        final int index = path.indexOf(SLASH_STAR);
         if(index >= 0) {
-            return path.substring(0, index) + PATH_CLEAN_SUFFIX;
+            result.setResolutionPath(path.substring(0, index) + SLASH_STAR);
+            result.setResolutionPathInfo(path.substring(index + SLASH_STAR.length()));
+        } else {
+            result.setResolutionPath(path);
         }
-        return path;
+        return result;
     }
-
-}
+}
\ No newline at end of file

Added: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java?rev=689439&view=auto
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java (added)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java Wed Aug 27 03:44:29 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.resource.internal.helper.starresource;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.api.resource.ResourceMetadata;
+
+/** Test the StarResource */
+public class StarResourceTest extends TestCase {
+	private void assertSplit(String requestPath, String path, String pathInfo) {
+		final ResourceMetadata rm = StarResource.getResourceMetadata(requestPath);
+		assertEquals("For requestPath=" + requestPath + ", path matches", path, rm.getResolutionPath());
+		assertEquals("For requestPath=" + requestPath + ", pathInfo matches", pathInfo, rm.getResolutionPathInfo());
+	}
+	
+	public void testSimplePath() {
+		assertSplit("/foo/*.html", "/foo/*", ".html");
+	}
+	
+	public void testNoExtension() {
+		assertSplit("/foo/*", "/foo/*", "");
+	}
+	
+	public void testNoStar() {
+		assertSplit("/foo/bar.html", "/foo/bar.html", null);
+	}
+	
+	public void testTwoStars() {
+		assertSplit("/foo/*.html/*.txt", "/foo/*", ".html/*.txt");
+	}
+}

Propchange: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/launchpad/jcrapp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/jcrapp/pom.xml?rev=689439&r1=689438&r2=689439&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/jcrapp/pom.xml (original)
+++ incubator/sling/trunk/launchpad/jcrapp/pom.xml Wed Aug 27 03:44:29 2008
@@ -178,7 +178,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.0.3-incubator-SNAPSHOT</version>
             <optional>true</optional>
         </dependency>