You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/01/04 09:43:03 UTC
svn commit: r1227076 -
/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
Author: cziegeler
Date: Wed Jan 4 08:43:03 2012
New Revision: 1227076
URL: http://svn.apache.org/viewvc?rev=1227076&view=rev
Log:
SLING-1081 : fsresource: allow to adapt to ValueMap
Modified:
sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java?rev=1227076&r1=1227075&r2=1227076&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java (original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java Wed Jan 4 08:43:03 2012
@@ -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.Abs
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 Abstract
+ " 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);
}