incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r755984 - /incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Date Thu, 19 Mar 2009 13:16:53 GMT
Author: cziegeler
Date: Thu Mar 19 13:16:52 2009
New Revision: 755984

URL: http://svn.apache.org/viewvc?rev=755984&view=rev
Log:
Try to adapt resource to a map to get a value map.

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

Modified: incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=755984&r1=755983&r2=755984&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++ incubator/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Thu Mar 19 13:16:52 2009
@@ -19,6 +19,9 @@
 package org.apache.sling.api.resource;
 
 import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.sling.api.wrappers.ValueMapDecorator;
 
 
 /**
@@ -274,7 +277,9 @@
      * 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.
+     * adaptable to a value map, next an adaption to {@link Map} is tried
+     * and if this is successful the map is wrapped as a value map.
+     * If the adaptions are not successful an empty value map is returned.
      * If <code>null</code> is provided as the resource an empty map is
      * returned as well.
      * @param res The <code>Resource</code> to adapt to the value map.
@@ -283,7 +288,12 @@
     public static ValueMap getValueMap(final Resource res) {
         ValueMap map = (res == null ? null : res.adaptTo(ValueMap.class));
         if ( map == null ) {
-            map = ValueMap.EMPTY;
+            Map m = res.adaptTo(Map.class);
+            if ( m != null ) {
+                map = new ValueMapDecorator(m);
+            } else {
+                map = ValueMap.EMPTY;
+            }
         }
         return map;
     }



Mime
View raw message