You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2013/10/30 16:42:33 UTC

svn commit: r1537136 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/resource/ jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ resour...

Author: dklco
Date: Wed Oct 30 15:42:32 2013
New Revision: 1537136

URL: http://svn.apache.org/r1537136
Log:
Finishing SLING-3213 : Adding support for the method 'hasChildren' on Resource and ResourceResolvers

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java
    sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/AbstractResource.java Wed Oct 30 15:42:32 2013
@@ -104,6 +104,14 @@ public abstract class AbstractResource
             }
         };
     }
+    
+    /**
+     * Checks to see if there are direct children of this resource by invoking
+     * {@link ResourceResolver#hasChildren(Resource)}.
+     */
+    public boolean hasChildren() {
+        return getResourceResolver().hasChildren(this);
+    }
 
     /**
      * Returns <code>true</code> if this resource is of the given resource type

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/Resource.java Wed Oct 30 15:42:32 2013
@@ -130,6 +130,14 @@ public interface Resource extends Adapta
     String getResourceSuperType();
 
     /**
+     * Checks if the resource has any child resources.
+     * 
+     * @return <code>true</code> if the resource has any child resources
+     * @since 2.4.4
+     */
+    boolean hasChildren();
+
+    /**
      * Returns <code>true</code> if the resource type or any of the resource's
      * super type(s) equals the given resource type.
      *

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java Wed Oct 30 15:42:32 2013
@@ -448,6 +448,16 @@ public interface ResourceResolver extend
     Iterator<Map<String, Object>> queryResources(String query, String language);
 
     /**
+     * Checks if the specified resource has any direct child resources.
+     * 
+     * @param resource
+     *            the resource to check for direct children
+     * @return <code>true</code> if the resource has any child resources
+     * @since 2.4.4
+     */
+    boolean hasChildren(Resource resource);
+    
+    /**
      * Returns a new <code>ResourceResolver</code> instance based on the given
      * <code>authenticationInfo</code> map and the original authentication info
      * used to create this instance.

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java Wed Oct 30 15:42:32 2013
@@ -136,6 +136,16 @@ public class ResourceWrapper implements 
     }
 
     /**
+     * Returns the value of calling <code>hasChildren</code> on the
+     * {@link #getResource() wrapped resource}.
+     * 
+     * @since 2.4.4
+     */
+	public boolean hasChildren() {
+		return getResource().hasChildren();
+	}
+    
+    /**
      * Returns the value of calling <code>isResourceType</code> on the
      * {@link #getResource() wrapped resource}.
      *
@@ -170,4 +180,5 @@ public class ResourceWrapper implements 
         return className + ", type=" + getResourceType()
             + ", path=" + getPath() + ", resource=[" + getResource() + "]";
     }
+	
 }

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=1537136&r1=1537135&r2=1537136&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 Wed Oct 30 15:42:32 2013
@@ -235,4 +235,9 @@ public class JcrPropertyResource extends
     Iterator<Resource> listJcrChildren() {
         return null;
     }
+
+    @Override
+	public boolean hasChildren() {
+		return false;
+	}
 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java (original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java Wed Oct 30 15:42:32 2013
@@ -1094,6 +1094,13 @@ public class ResourceResolverImpl extend
     public boolean hasChanges() {
         return this.context.hasChanges(this);
     }
+    
+    /**
+     * @see org.apache.sling.api.resource.ResourceResolver#hasChildren()
+     */
+	public boolean hasChildren(Resource resource) {
+		return listChildren(resource).hasNext();
+	}
 
     /**
      * @see org.apache.sling.api.resource.ResourceResolver#getParentResourceType(org.apache.sling.api.resource.Resource)

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java (original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java Wed Oct 30 15:42:32 2013
@@ -274,5 +274,9 @@ public class ResourceProviderEntryTest {
         public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
             return null;
         }
+
+		public boolean hasChildren() {
+			return false;
+		}
     }
 }

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/SlingFunctions.java Wed Oct 30 15:42:32 2013
@@ -183,6 +183,18 @@ public class SlingFunctions {
 	}
 
 	/**
+	 * Method for checking whether or not a resource has child resources.
+	 * 
+	 * @param resource
+	 *            the resource to check for child resources
+	 * @return true if the resource has child resources, false otherwise
+	 * @since 2.2.2
+	 */
+	public static final boolean hasChildren(Resource resource) {
+		return resource != null ? resource.listChildren().hasNext() : false;
+	}
+
+	/**
 	 * Method for allowing the invocation of the Sling Resource listChildren
 	 * method.
 	 * 

Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld?rev=1537136&r1=1537135&r2=1537136&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/resources/META-INF/sling.tld Wed Oct 30 15:42:32 2013
@@ -48,6 +48,11 @@
         <function-signature>java.lang.Object getValue(org.apache.sling.api.resource.ValueMap,java.lang.String,java.lang.Object)</function-signature>
     </function>
 	
+    <function>
+        <name>hasChildren</name>
+        <function-class>org.apache.sling.scripting.jsp.taglib.SlingFunctions</function-class>
+        <function-signature>java.lang.Boolean hasChildren(org.apache.sling.api.resource.Resource)</function-signature>
+    </function>
 
 	<function>
 		<name>listChildren</name>