incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r704328 - /incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Date Tue, 14 Oct 2008 06:59:16 GMT
Author: cziegeler
Date: Mon Oct 13 23:59:16 2008
New Revision: 704328

URL: http://svn.apache.org/viewvc?rev=704328&view=rev
Log:
Add utility method to always get a value map for a resource.

Modified:
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=704328&r1=704327&r2=704328&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Mon Oct 13 23:59:16 2008
@@ -267,4 +267,22 @@
     public static Iterator<Resource> listChildren(Resource parent) {
         return parent.getResourceResolver().listChildren(parent);
     }
+
+    /**
+     * Returns an <code>ValueMap</code> object for the given
+     * <code>Resource</code>.
+     * This method calls {@link Resource#adaptTo(Class)} with the
+     * {@link ValueMap} class as an argument. If the <code>adaptTo</code>
+     * method returns a map, this map is returned. If the resource is not
+     * adaptable to a value map, an empty value map is returned.
+     * @param res The <code>Resource</code> to adapt to the value map.
+     * @return A value map.
+     */
+    public static ValueMap getValueMap(final Resource res) {
+        ValueMap map = res.adaptTo(ValueMap.class);
+        if ( map == null ) {
+            map = ValueMap.EMPTY;
+        }
+        return map;
+    }
 }



Mime
View raw message