sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-fsresource] 10/22: SLING-1081 : fsresource: allow to adapt to ValueMap
Date Tue, 07 Nov 2017 09:36:13 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git

commit 8318373ac31a331af7ef9878e1792e4f4ad5a42b
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Wed Jan 4 08:43:03 2012 +0000

    SLING-1081 : fsresource: allow to adapt to ValueMap
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@1227076
13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/fsprovider/internal/FsResource.java       | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
index 8ddb7cc..a0f68f7 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
@@ -24,6 +24,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.sling.adapter.annotations.Adaptable;
 import org.apache.sling.adapter.annotations.Adapter;
@@ -31,6 +34,8 @@ import org.apache.sling.api.resource.AbstractResource;
 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.ValueMap;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -178,8 +183,22 @@ public class FsResource extends AbstractResource implements Resource
{
                         + " to an URL", mue);
             }
 
+        } else if (type == ValueMap.class) {
+            
+            // this resource simulates nt:file/nt:folder behavior by returning it as resource
type
+            // we should simulate the corresponding JCR properties in a value map as well
+            if (file.exists() && file.canRead()) {
+                Map<String,Object> props = new HashMap<String, Object>();
+                props.put("jcr:primaryType", getResourceType());
+                props.put("jcr:createdBy", "system");
+                Calendar lastModifed = Calendar.getInstance();
+                lastModifed.setTimeInMillis(file.lastModified());
+                props.put("jcr:created", lastModifed);
+                return (AdapterType) new ValueMapDecorator(props);
+            }
+            
         }
-
+        
         return super.adaptTo(type);
     }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message