sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1795980 - in /sling/trunk/bundles/extensions/fsresource/src: main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
Date Tue, 23 May 2017 23:27:05 GMT
Author: sseifert
Date: Tue May 23 23:27:05 2017
New Revision: 1795980

URL: http://svn.apache.org/viewvc?rev=1795980&view=rev
Log:
SLING-6877 FSResource: Allow to adapt to Node from FileResource

Modified:
    sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
    sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java

Modified: sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java?rev=1795980&r1=1795979&r2=1795980&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
(original)
+++ sling/trunk/bundles/extensions/fsresource/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
Tue May 23 23:27:05 2017
@@ -28,6 +28,8 @@ import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.jcr.Node;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
@@ -40,8 +42,8 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.fsprovider.internal.ContentFileExtensions;
 import org.apache.sling.fsprovider.internal.FsResourceProvider;
+import org.apache.sling.fsprovider.internal.mapper.jcr.FsNode;
 import org.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapDecorator;
-import org.apache.sling.fsprovider.internal.parser.ContentElement;
 import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
 import org.apache.sling.jcr.contentparser.ParserOptions;
 import org.slf4j.Logger;
@@ -200,6 +202,13 @@ public final class FileResource extends
         else if (type == ValueMap.class) {
             return (AdapterType) getValueMap();
         }
+        else if (type == Node.class) {
+            ContentFile contentFile = getNodeDescriptorContentFile();
+            if (contentFile != null) {
+                // support a subset of JCR API for content file resources
+                return (AdapterType)new FsNode(contentFile, getResourceResolver());
+            }
+        }
         return super.adaptTo(type);
     }
 
@@ -227,9 +236,9 @@ public final class FileResource extends
                 props.put("jcr:created", lastModifed);
                 
                 // overlay properties with those from node descriptor content file, if it
exists
-                ContentElement content = getNodeDescriptorContent();
-                if (content != null) {
-                    for (Map.Entry<String, Object> entry : content.getProperties().entrySet())
{
+                ContentFile contentFile = getNodeDescriptorContentFile();
+                if (contentFile != null) {
+                    for (Map.Entry<String, Object> entry : contentFile.getValueMap().entrySet())
{
                         // skip primary type if it is the default type assigned by contentparser
when none is defined
                         if (StringUtils.equals(entry.getKey(), "jcr:primaryType")
                                 && StringUtils.equals((String)entry.getValue(), ParserOptions.DEFAULT_PRIMARY_TYPE))
{
@@ -245,14 +254,14 @@ public final class FileResource extends
         return valueMap;
     }
     
-    private ContentElement getNodeDescriptorContent() {
+    private ContentFile getNodeDescriptorContentFile() {
         if (contentFileExtensions == null || contentFileCache == null) {
             return null;
         }
         for (String fileNameSuffix : contentFileExtensions.getSuffixes()) {
             File fileWithSuffix = new File(file.getPath() + fileNameSuffix);
             if (fileWithSuffix.exists() && fileWithSuffix.canRead()) {
-                return contentFileCache.get(resourcePath, fileWithSuffix);
+                return new ContentFile(fileWithSuffix, resourcePath, null, contentFileCache);
             }
         }
         return null;

Modified: sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java?rev=1795980&r1=1795979&r2=1795980&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
(original)
+++ sling/trunk/bundles/extensions/fsresource/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
Tue May 23 23:27:05 2017
@@ -275,6 +275,11 @@ public class JsonContentTest {
         assertArrayEquals(new String[] { "mix:language" }, props.get("jcr:mixinTypes", String[].class));
 
         assertNull(fsroot.getChild("folder2/folder21/file21a.txt.xml"));
+        
+        Node node = file21a.adaptTo(Node.class);
+        assertNotNull(node);
+        assertEquals("/my/super/type", node.getProperty("sling:resourceSuperType").getString());
+        assertEquals("en", node.getProperty("jcr:language").getString());
     }
 
 }



Mime
View raw message