sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r788719 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/resource/ api/src/test/java/org/apache/sling/api/resource/ engine/src/main/java/org/apache/sling/engine/impl/request/ jcr/resource/src/main/java/org/apache/sling/jcr/...
Date Fri, 26 Jun 2009 14:43:54 GMT
Author: cziegeler
Date: Fri Jun 26 14:43:53 2009
New Revision: 788719

URL: http://svn.apache.org/viewvc?rev=788719&view=rev
Log:
SLING-1024 : Correct resource super type handling. JCR node resource only returns a resource
type if the property is set on the node. Bundle resources now have a default fixed resource
super type. Cleaned up resource super type handling.

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
    sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
    sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Fri Jun 26 14:43:53 2009
@@ -349,29 +349,8 @@
         final Resource rtResource = resourceResolver.getResource(rtPath);
         // check for endless recursion
         if ( rtResource != null ) {
-            if ( !resourceType.equals(rtResource.getResourceType()) ) {
-                return rtResource.getResourceSuperType();
-            }
+            return rtResource.getResourceSuperType();
         }
         return null;
     }
-
-    /**
-     * Returns the resource super type of the resource type of the given resource.
-     * This method simply calls {@link #getResourceSuperType(ResourceResolver, String)}
-     * with the resource type of the <code>resource</code>
-     *
-     * @param resource The <code>Resource</code> whose resource super type is
-     *            requested.
-     * @return The resource super type or <code>null</code> if the algorithm
-     *         described above does not yield a resource super type.
-     * @since 2.0.6
-     */
-    public static String getResourceSuperType(final Resource resource) {
-        if ( resource == null ) {
-            return null;
-        }
-        return getResourceSuperType(resource.getResourceResolver(),
-                resource.getResourceType());
-    }
 }

Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
(original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Fri Jun 26 14:43:53 2009
@@ -272,8 +272,7 @@
             allowing(resolver).getResource("a/c");
             will(returnValue(null));
         }});
-        assertEquals("t:c", ResourceUtil.getResourceSuperType(r));
-        assertNull(ResourceUtil.getResourceSuperType(null));
-        assertNull(ResourceUtil.getResourceSuperType(r2));
+        assertEquals("t:c", ResourceUtil.getResourceSuperType(r.getResourceResolver(), r.getResourceType()));
+        assertNull(ResourceUtil.getResourceSuperType(r2.getResourceResolver(), r2.getResourceType()));
     }
 }

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java
Fri Jun 26 14:43:53 2009
@@ -203,7 +203,8 @@
         @Override
         public String getResourceSuperType() {
             if (resourceSuperType == UNSET_RESOURCE_SUPER_TYPE) {
-                resourceSuperType = ResourceUtil.getResourceSuperType(this);
+                resourceSuperType = ResourceUtil.getResourceSuperType(this.getResourceResolver(),
+                        this.resourceType);
             }
             return resourceSuperType;
         }

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
Fri Jun 26 14:43:53 2009
@@ -219,24 +219,17 @@
      * @return The resource super type or <code>null</code> if the algorithm
      *         described above does not yield a resource super type.
      * @deprecated Call {@link Resource#getResourceSuperType()} and if
-     * that returns <code>null</code> {@link ResourceUtil#getResourceSuperType(Resource)}
+     * that returns <code>null</code> {@link ResourceUtil#getResourceSuperType(ResourceResolver,
String)}
      */
     @Deprecated
     public static String getResourceSuperType(Resource resource) {
-        ResourceResolver resolver = resource.getResourceResolver();
+        String resourceSuperType = resource.getResourceSuperType();
+        if ( resourceSuperType == null ) {
+            final ResourceResolver resolver = resource.getResourceResolver();
 
-        // try local resourceSuperType "property"
-        String resourceSuperType = null;
-        Resource typeResource = resolver.getResource(resource,
-            JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY);
-        if (typeResource != null) {
-            resourceSuperType = typeResource.adaptTo(String.class);
-        }
-
-        // try explicit resourceSuperType resource
-        if (resourceSuperType == null) {
-            String resourceType = resource.getResourceType();
-            resourceSuperType = getResourceSuperType(resolver, resourceType);
+            // try explicit resourceSuperType resource
+            final String resourceType = resource.getResourceType();
+            resourceSuperType = ResourceUtil.getResourceSuperType(resolver, resourceType);
         }
 
         return resourceSuperType;

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrItemResource.java
Fri Jun 26 14:43:53 2009
@@ -27,23 +27,17 @@
 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.ResourceUtil;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.jcr.resource.JcrResourceTypeProvider;
 
 abstract class JcrItemResource extends SlingAdaptable implements Resource {
 
-    /** marker value for the resourceSupertType before trying to evaluate */
-    protected static final String UNSET_RESOURCE_SUPER_TYPE = "<unset>";
-
     private final ResourceResolver resourceResolver;
 
     private final String path;
 
     private final ResourceMetadata metadata;
 
-    protected String resourceSuperType;
-
     protected final JcrResourceTypeProvider[] resourceTypeProviders;
 
     protected JcrItemResource(ResourceResolver resourceResolver,
@@ -56,8 +50,6 @@
 
         metadata = new ResourceMetadata();
         metadata.setResolutionPath(path);
-
-        resourceSuperType = UNSET_RESOURCE_SUPER_TYPE;
     }
 
     public ResourceResolver getResourceResolver() {
@@ -68,13 +60,6 @@
         return path;
     }
 
-    public String getResourceSuperType() {
-        if (resourceSuperType == UNSET_RESOURCE_SUPER_TYPE) {
-            resourceSuperType = ResourceUtil.getResourceSuperType(this);
-        }
-        return resourceSuperType;
-    }
-
     public ResourceMetadata getResourceMetadata() {
         return metadata;
     }

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
Fri Jun 26 14:43:53 2009
@@ -53,6 +53,9 @@
 /** A Resource that wraps a JCR Node */
 public class JcrNodeResource extends JcrItemResource {
 
+    /** marker value for the resourceSupertType before trying to evaluate */
+    private static final String UNSET_RESOURCE_SUPER_TYPE = "<unset>";
+
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -60,12 +63,15 @@
 
     private final String resourceType;
 
+    protected String resourceSuperType;
+
     public JcrNodeResource(ResourceResolver resourceResolver, Node node,
             JcrResourceTypeProvider[] resourceTypeProviders)
             throws RepositoryException {
         super(resourceResolver, node.getPath(), resourceTypeProviders);
         this.node = node;
         resourceType = getResourceTypeForNode(node);
+        resourceSuperType = UNSET_RESOURCE_SUPER_TYPE;
 
         // check for nt:file metadata
         setMetaData(node, getResourceMetadata());
@@ -85,7 +91,7 @@
                 // we ignore this
             }
             if ( resourceSuperType == UNSET_RESOURCE_SUPER_TYPE ) {
-                return super.getResourceSuperType();
+                resourceSuperType = null;
             }
         }
         return resourceSuperType;

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
Fri Jun 26 14:43:53 2009
@@ -60,6 +60,10 @@
         return resourceType;
     }
 
+    public String getResourceSuperType() {
+        return null;
+    }
+
     @SuppressWarnings("unchecked")
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
 

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
Fri Jun 26 14:43:53 2009
@@ -102,12 +102,13 @@
     }
 
     /**
-     * Calls {@link ResourceUtil#getResourceSuperType(Resource)} method
+     * Calls {@link ResourceUtil#getResourceSuperType(ResourceResolver, String)} method
      * to dynamically resolve the resource super type of this star resource.
      */
     public String getResourceSuperType() {
         if (resourceSuperType == UNSET_RESOURCE_SUPER_TYPE) {
-            resourceSuperType = ResourceUtil.getResourceSuperType(this);
+            resourceSuperType = ResourceUtil.getResourceSuperType(this.getResourceResolver(),
+                    this.getResourceType());
         }
         return resourceSuperType;
     }

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
Fri Jun 26 14:43:53 2009
@@ -31,6 +31,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.jcr.resource.JcrResourceUtil;
 
 public class JcrNodeResourceTest extends JcrItemResourceTestBase {
 
@@ -129,8 +130,8 @@
         Resource jnr = new JcrNodeResource(resourceResolver, node, null);
         assertEquals(typeName, jnr.getResourceType());
 
-        // default super type is super type of node type
-        assertEquals(null, jnr.getResourceSuperType());
+        // default super type is null
+        assertNull(jnr.getResourceSuperType());
 
         String superTypeName = "supertype";
         Node typeNode = rootNode.addNode(typeNodeName, JcrConstants.NT_UNSTRUCTURED);
@@ -139,7 +140,7 @@
 
         jnr = new JcrNodeResource(resourceResolver, node, null);
         assertEquals(typeName, jnr.getResourceType());
-        assertEquals(superTypeName, jnr.getResourceSuperType());
+        assertEquals(superTypeName, JcrResourceUtil.getResourceSuperType(jnr));
 
         // overwrite super type with direct property
         String otherSuperTypeName = "othersupertype";
@@ -170,21 +171,21 @@
         JcrNodeResource jnr = new JcrNodeResource(null, res, null);
 
         final Map<?, ?> props = jnr.adaptTo(Map.class);
-        
+
         // assert we have properties at all, only fails if property
         // retrieval fails for any reason
         assertNotNull(props);
         assertFalse(props.isEmpty());
-        
+
         // assert all properties set up
         assertEquals(TEST_MODIFIED, props.get(JcrConstants.JCR_LASTMODIFIED));
         assertEquals(TEST_TYPE, props.get(JcrConstants.JCR_MIMETYPE));
         assertEquals(TEST_ENCODING, props.get(JcrConstants.JCR_ENCODING));
         assertEquals(TEST_DATA, (InputStream) props.get(JcrConstants.JCR_DATA));
-        
+
         // assert JCR managed properties
         assertEquals(JcrConstants.NT_UNSTRUCTURED, props.get(JcrConstants.JCR_PRIMARYTYPE));
-        
+
         // assert we have nothing else left
         final Set<String> existingKeys = new HashSet<String>();
         existingKeys.add(JcrConstants.JCR_LASTMODIFIED);
@@ -198,21 +199,21 @@
 
         // call a second time, ensure the map contains the same data again
         final Map<?, ?> propsSecond = jnr.adaptTo(Map.class);
-        
+
         // assert we have properties at all, only fails if property
         // retrieval fails for any reason
         assertNotNull(propsSecond);
         assertFalse(propsSecond.isEmpty());
-        
+
         // assert all properties set up
         assertEquals(TEST_MODIFIED, propsSecond.get(JcrConstants.JCR_LASTMODIFIED));
         assertEquals(TEST_TYPE, propsSecond.get(JcrConstants.JCR_MIMETYPE));
         assertEquals(TEST_ENCODING, propsSecond.get(JcrConstants.JCR_ENCODING));
         assertEquals(TEST_DATA, (InputStream) propsSecond.get(JcrConstants.JCR_DATA));
-        
+
         // assert JCR managed properties
         assertEquals(JcrConstants.NT_UNSTRUCTURED, propsSecond.get(JcrConstants.JCR_PRIMARYTYPE));
-        
+
         // assert we have nothing else left
         final Set<Object> crossCheck2 = new HashSet<Object>(propsSecond.keySet());
         crossCheck2.removeAll(existingKeys);
@@ -238,7 +239,7 @@
     private void assertProperty(Object expected, Object actual) {
         if (expected != null) {
             assertNotNull(actual);
-            
+
             assertEquals(expected, actual);
         } else {
             assertNull(actual);

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java
Fri Jun 26 14:43:53 2009
@@ -440,7 +440,6 @@
     		}
     	}
 
-    	boolean hasOptingServlet = false;
         for (Resource candidateResource : candidates) {
         	if(log.isDebugEnabled()) {
         		log.debug("Checking if candidate resource {} adapts to servlet and accepts request",
@@ -454,9 +453,6 @@
                 if (servletAcceptsRequest) {
                     return candidate;
                 }
-                if ( isOptingServlet ) {
-                    hasOptingServlet = true;
-                }
             	if(log.isDebugEnabled()) {
             		log.debug("Candidate {} does not accept request, ignored", candidateResource.getPath());
             	}

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationIterator.java
Fri Jun 26 14:43:53 2009
@@ -188,7 +188,8 @@
 
         // get the super type of the current resource type
         String superType;
-        if (resourceType.equals(this.firstResourceType)) {
+        if (resourceType.equals(this.firstResourceType)
+                && this.firstResourceSuperType != null ) {
             superType = this.firstResourceSuperType;
         } else {
             superType = ResourceUtil.getResourceSuperType(resolver,

Modified: sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java?rev=788719&r1=788718&r2=788719&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
(original)
+++ sling/trunk/bundles/servlets/resolver/src/main/java/org/apache/sling/servlets/resolver/internal/resource/ServletResource.java
Fri Jun 26 14:43:53 2009
@@ -60,9 +60,10 @@
         return resourceType;
     }
 
-    /** Servlet Resources have no super type */
+    /** Servlet Resources always returns "sling/bundle/resource" as
+     * the super type. */
     public String getResourceSuperType() {
-        return null;
+        return "sling/bundle/resource";
     }
 
     public String getPath() {



Mime
View raw message