You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/03/28 10:12:11 UTC

svn commit: r642156 - in /incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource: JcrResourceUtil.java internal/helper/starresource/StarResource.java

Author: fmeschbe
Date: Fri Mar 28 02:12:08 2008
New Revision: 642156

URL: http://svn.apache.org/viewvc?rev=642156&view=rev
Log:
SLING-344 Add helper methods to identify non-existing and star resources.

Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java?rev=642156&r1=642155&r2=642156&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java Fri Mar 28 02:12:08 2008
@@ -26,9 +26,11 @@
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
+import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.jcr.resource.internal.helper.LazyInputStream;
+import org.apache.sling.jcr.resource.internal.helper.starresource.StarResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -260,5 +262,45 @@
 
         // get the resource super type from the resource
         return (rtResource != null) ? rtResource.getResourceSuperType() : null;
+    }
+
+    /**
+     * Returns <code>true</code> if the resource <code>res</code> is a "star
+     * resource". A <i>star resource</i> is a resource returned from the
+     * <code>ResourceResolver.resolve(HttpServletRequest)</code> whose path
+     * terminates in a <code>/*</code>. Generally such resource result from
+     * requests to something like <code>/some/path/*</code> or
+     * <code>/some/path/*.html</code> which may be used web applications to
+     * uniformly handle resources to be created.
+     * <p>
+     * This method checks whether the resource path ends with a <code>/*</code>
+     * indicating such a star resource.
+     * 
+     * @param res The <code>Resource</code> to check whether it is a star
+     *            resource.
+     * @return <code>true</code> if <code>res</code> is to be considered a
+     *         star resource.
+     * @throws NullPointerException if <code>res</code> is <code>null</code>.
+     */
+    public static boolean isStarResource(Resource res) {
+        return StarResource.isStarResource(res);
+    }
+
+    /**
+     * Returns <code>true</code> if the resource <code>res</code> is a
+     * non-existing resource.
+     * <p>
+     * This method checks the resource type of the resource to match the
+     * well-known resource type <code>sling:nonexisting</code> of the
+     * <code>NonExistingResource</code> class defined in the Sling API.
+     * 
+     * @param res The <code>Resource</code> to check whether it is a
+     *            non-existing resource.
+     * @return <code>true</code> if <code>res</code> is to be considered a
+     *         non-existing resource.
+     * @throws NullPointerException if <code>res</code> is <code>null</code>.
+     */
+    public static boolean isNonExistingResource(Resource res) {
+        return NonExistingResource.RESOURCE_TYPE_NON_EXISTING.equals(res.getResourceType());
     }
 }

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=642156&r1=642155&r2=642156&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 Fri Mar 28 02:12:08 2008
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.api.SlingException;
+import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.SyntheticResource;
 import org.apache.sling.jcr.resource.JcrDefaultResourceTypeProvider;
@@ -43,6 +44,21 @@
         }
     }
     
+    /** True if a StarResource should be used for the given request, if
+     *  a real Resource was not found */
+    public static boolean appliesTo(HttpServletRequest request) {
+        return "GET".equals(request.getMethod()) && request.getPathInfo().contains(PATH_PATTERN);
+    }
+
+    /**
+     * Returns true if the path of the resource ends with the
+     * {@link #PATH_CLEAN_SUFFIX} and therefore should be considered a star
+     * resource.
+     */
+    public static boolean isStarResource(Resource res) {
+        return res.getPath().endsWith(PATH_CLEAN_SUFFIX);
+    }
+    
     public StarResource(ResourceResolver resourceResolver, String path, JcrDefaultResourceTypeProvider drtp) throws SlingException {
         super(resourceResolver, convertPath(path), null);
         
@@ -73,12 +89,6 @@
         return null;
     }
     
-    /** True if a StarResource should be used for the given request, if
-     *  a real Resource was not found */
-    public static boolean appliesTo(HttpServletRequest request) {
-        return "GET".equals(request.getMethod()) && request.getPathInfo().contains(PATH_PATTERN);
-    }
-
     /** Cleanup our path, for example /foo/*.html becomes /foo/* */
     protected static String convertPath(String path) {
         final int index = path.indexOf(PATH_PATTERN);