This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.fsresource-2.1.2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 77f4ea67951c9c2c10e66531bb6d015cf5b74c9b Author: Stefan Seifert <[email protected]> AuthorDate: Tue May 23 23:27:05 2017 +0000 SLING-6877 FSResource: Allow to adapt to Node from FileResource git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource@1795980 13f79535-47bb-0310-9956-ffa450edef68 --- .../fsprovider/internal/mapper/FileResource.java | 21 +++++++++++++++------ .../sling/fsprovider/internal/JsonContentTest.java | 5 +++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java index 3d65264..873aba8 100644 --- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java +++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java @@ -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.ResourceResolver; 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 AbstractResource { 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 AbstractResource { 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 AbstractResource { 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; diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java index 1046350..4fb6a32 100644 --- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java +++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java @@ -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()); } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
