You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:37:15 UTC
[sling-org-apache-sling-fsresource] annotated tag
org.apache.sling.fsresource-1.3.0 created (now de5250f)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git.
at de5250f (tag)
tagging fd787ad957a4646c30309f9ca30edc4a2ce17e76 (commit)
by Stefan Seifert
on Mon Mar 27 16:17:12 2017 +0000
- Log -----------------------------------------------------------------
org.apache.sling.fsresource-1.3.0
-----------------------------------------------------------------------
This annotated tag includes the following new commits:
new 0c33118 SLING-583 Initial implementation of a filesystem resource provider
new fd8bbdc Code formatting
new 6f617dc SLING-583 Fix FsResourceProvider.listChildren if the provider root is to be return as the single entry in the iterator
new fc83e32 SLING-583 Latest change introduces dependency on JCR API (because a directory is not returned any more as a resource if a repository item with the same name exists)
new 7ab3c81 SLING-583 Cleanup to consistently not return FsResource instances for directories "hiding" existing repository items.
new a46c284 Remove redundant null check
new c361d2a SLING-808 : Increase version to 5-incubator-SNAPSHOT
new a284078 SLING-829 Cosmetics to the bundle/project names
new 6ec1315 SLING-829 Ensure Apache Sling prefix on all configuration names
new 4d89314 SLING-865 - Correct location
new 48e6a1d SLING-865 - Correct pom and svn reference.
new 5150158 SLING-916 move non-exported packages to internal packages and remove javadoc configuration which will be inherited from parent pom
new 19d32c4 Fix fsresource provider and sling plugin after recent refactorings.
new 6799d74 Use release parent pom
new bee824c [maven-release-plugin] prepare release org.apache.sling.fsresource-0.9.0-incubator
new fe60fe1 [maven-release-plugin] prepare for next development iteration
new 8958da0 Use next dev version of parent pom
new 36ccd05 Add missing licence, notice etc.
new 6bcf253 Prepare new release.
new 16644cd [maven-release-plugin] prepare release org.apache.sling.fsresource-0.9.2-incubator
new 746e1d1 [maven-release-plugin] prepare for next development iteration
new 16ecaa5 Use next parent pom for development.
new f943311 Set parent pom to released version.
new ab2cf0f Move Sling to new TLP location
new 501bb88 SLING-1011 : Remove disclaimer file.
new b47fdc9 SLING-1011 : Adjust svn location
new 40f9091 SLING-1011 : Remove disclaimer from readme's, adjust links to webite, fix versions in poms.
new 164dbcf SLING-1033 Upgrade to Sling parent POM 6 (and ensure web app has the leglize stuff, too)
new 2f0cded Use official release instead of incubator release.
new 10c9088 Update to latest Sling releases.
new a8b5bdf Update to latest release.
new 2d2ef3d SLING-1186 Upgrade to Sling Parent POM 8-SNAPSHOT (to use SCR plugin 1.4.0), set DS specification version of components to 1.1, convert component into a regular (non-ComponentFactory) component and ensure meta type descriptor is generated with factoryPid set to the same value as the PID to have factory configuration support.
new 3111d96 SLING-1186 Parent POM 7 is good enough (no need for 8-SNAPSHOT)
new 2051b5f SLING-1187 Remove FsProviderConstants (moved constants to FsResource) and FsFolderServlet (duplicate code from default GET Servlet)
new 3a95821 SLING-1192 use nt:file and nt:folder for files and folders and drop the special resource super type
new a78ef39 SLING-1205 Upgrade all projects to parent POM 8 and use OSGi provided OSGi libraries
new 5137b7e Just code cleanup - no functional changes.
new 71d0b66 Check whether the abstract file is a directory before trying to open the FileInputStream on it (to prevent a nasty log message)
new 93cda71 SLING-1387 : File system provider should send resource events
new 38aa5a1 SLING-1387 : File system provider should send resource events
new 5d6630a [maven-release-plugin] prepare release org.apache.sling.fsresource-1.0.0
new c0d679e [maven-release-plugin] prepare for next development iteration
new feb2473 SLING-1516 Fixed by looking for a factory pid on activation.
new b109367 SLING-1516 A much better fix provided by Felix.
new 8df175a Use released parent pom.
new a30c588 SLING-1193 Fsresoruce and bundle resource implement the 2.0.8 API which means they cant be used with ResourceUtil, updated.
new c385893 SLING-1193 Have the bundle plugin set the correct import version range for the resource API implemented by the bundles
new 61509be SLING-1625 Check File.listFiles() result to prevent NullPointerException
new b5c493c Use latest Sling API release
new 8cd0450 Fix javadocs
new 26c5948 updating all modules to parent 10-SNAPSHOT in anticipation of emma additions to parent
new 9281408 fixing relativePaths
new a8d1b87 Update to recent snapshots
new 2979d42 Use latest releases.
new abcabe3 Remove obsolete licence and notice
new 4d518af [maven-release-plugin] prepare release org.apache.sling.fsresource-1.0.2
new 820f5c2 [maven-release-plugin] prepare for next development iteration
new 04c2091 SLING-2150 : Update plugins to use the latest available versions
new 15cc17a Update to recent snapshot
new 366633f Using latest released parent pom
new 630b18e SLING-2187 - adding new module to contain our custom notice file; adding remote-resources plugin configuration to parent pom and removing all existing appended-resources NOTICE files
new f4a2616 temporarily using snapshots during release vote
new 15c85c9 using latest releases
new 0aba830 SLING-2312 - adding adapter annotations for fsresource bundle
new 8309283 SLING-2314 - applying patch from Stefan Seifert to switch annotation style on FSResourceProvider. Thanks for the patch!
new 8318373 SLING-1081 : fsresource: allow to adapt to ValueMap
new cc90f52 using next snapshots during release process
new d3e5959 Use released adapter annotations.
new 7c14443 Use released maven sling plugin
new a30d734 SLING-2480 : Add config for maven-sling-plugin to m2e configuration
new 1c8b6ab SLING-2483 Use provide:=true instead of version macros to define the proper import version range. Also fix a small glitch in the parent pom relativePath of the framework-extension-ws bundle
new d61a155 Correctly increase resource package version and include latest resource providers.
new 9363ec0 Update to latest parent pom
new 28ecd71 Use released versions
new 195c76d SLING-2541 : General mechanism to chain resource providers
new e71601f Preparing release
new 5468aa2 [maven-release-plugin] prepare release org.apache.sling.fsresource-1.1.0
new 7b1b0a6 [maven-release-plugin] prepare for next development iteration
new f867347 Set dependencies to latest snapshots after release
new 747e4bb Update to released bundles
new d93f502 Use latest releases and update to new parent pom
new 94c55fa Update to latest parent pom and use latest releases in launchpad
new 2653bcb SLING-2739 : Add methods for handling the resource type hierarchy to the resource resolver
new 0e9dd0f Prepare for release
new a76cf10 [maven-release-plugin] prepare release org.apache.sling.fsresource-1.1.2
new 418479c [maven-release-plugin] prepare for next development iteration
new fb5221e Use latest snapshot
new 8cf1d4e Use released versions after release.
new b273649 Correct reactor pom and update to parent pom 16
new c9aca5b Update to latest parent pom
new 592bc1e SLING-2944 Revert Sling API dependency to 2.3.0 again
new d5588c1 Update to parent pom 18
new 0bb72cc SLING-3286 - Remove plugin version overrides from poms
new 2254ba3 Update to parent pom v19
new 9584f16 3804 : Fields for dynamic references must be volatile
new 07281a3 Updated to parent version 20
new 4392745 [maven-release-plugin] prepare release org.apache.sling.fsresource-1.1.4
new a4d1ae4 [maven-release-plugin] prepare for next development iteration
new 2b642b2 Update to Sling Parent POM 22 with baselining enabled
new 43259e6 SLING-4698 - Set parent.relativePath to empty for all modules
new be69e70 Update to Sling Parent 23
new b030d0c set parent version to 24 and add empty relativePath where missing
new 0320672 Update the main reactor to parent 25
new 9f877f5 SLING-5192 - FsResourceProvider should set webconsole.configurationFactory.nameHint
new a5f05c9 Switch to parent pom 26
new f4b94c0 branch fsresource version before switch to new Sling API
new 54e89e7 backport of changes from SLING-6440 and SLING-6537 to 1.1.x version of fsresource based on old resource provider SPI
new 88b3a59 SLING-6440 simplify FileMonitor
new 2ea8852 SLING-6440 switch to fscontentparser rename "Filesystem" to "File System" update to latest parent
new aa2eecc SLING-6440 update to latest API
new b342fb6 set version in branch to 1.3.0-SNAPSHOT (for old Resource Provider SPI)
new af87b04 SLING-6537 FileVault XML support
new 633173f rename branch folder to 1.x
new a30fb87 update scm urls for branch
new 62f16aa SLING-6537 FileVault XML support
new 4c1b15f SLING-6440 use ManifestHeader to parse directives
new 56b09e5 SLING-6537 FileVault XML support
new 98a2215 SLING-6537 BigDecimal support, use copy of enhanced ValueMap with proper type converstion from Sling API 2.17.0
new f21de7a SLING-6630 rename INITIAL_CONTENT_FILES_FOLDERS to FILES_FOLDERS
new 16babc3 SLING-6630 make FILES_FOLDERS default
new 81a06d6 cosmetic: use consistent wording, reorder config attributes
new a353cfb SLING-6440 switch to latest jcr/contentparser API
new 8c0e64a SLING-6440 switch to latest jcr/contentparser API
new aa6fca1 SLING-6440 switch to latest contentparser API
new ac983c8 update dependencies
new 2386504 fix javadoc errors
new 3f53032 [maven-release-plugin] prepare release org.apache.sling.fsresource-1.3.0
new fd787ad [maven-release-plugin] copy for tag org.apache.sling.fsresource-1.3.0
The 128 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].
[sling-org-apache-sling-fsresource] 20/23: update dependencies
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit ac983c88e6352f8c34518c9bc2ad9628c807e5f0
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Mar 23 15:13:04 2017 +0000
update dependencies
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1788265 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 892c3d9..206e27c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -148,7 +148,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.contentparser</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -165,7 +165,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
- <version>2.2.2</version>
+ <version>2.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 11/23: SLING-6440 use
ManifestHeader to parse directives
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 4c1b15f30adb817bbdb958bf33cdf1d76beac25e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Mar 8 16:40:12 2017 +0000
SLING-6440 use ManifestHeader to parse directives
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786018 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 6 ++++
.../internal/InitialContentImportOptions.java | 33 +++++++++-------------
.../internal/InitialContentImportOptionsTest.java | 4 +--
3 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4f0ba96..0245895 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,6 +141,12 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.osgi</artifactId>
+ <version>2.2.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.fscontentparser</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
index 5353d0f..52de538 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
@@ -19,13 +19,14 @@
package org.apache.sling.fsprovider.internal;
import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.commons.osgi.ManifestHeader.Entry;
class InitialContentImportOptions {
@@ -46,25 +47,19 @@ class InitialContentImportOptions {
private final Set<String> ignoreImportProviders;
public InitialContentImportOptions(String optionsString) {
- Map<String,String> options = parseOptions(optionsString);
- overwrite = BooleanUtils.toBoolean(options.get(OVERWRITE_DIRECTIVE));
- ignoreImportProviders = new HashSet<>(Arrays.asList(StringUtils.split(StringUtils.defaultString(options.get(IGNORE_CONTENT_READERS_DIRECTIVE)))));
- }
-
- private static Map<String,String> parseOptions(String optionsString) {
- Map<String,String> options = new HashMap<>();
- String[] optionsList = StringUtils.split(optionsString, ";");
- if (optionsList != null) {
- for (String keyValueString : optionsList) {
- String[] keyValue = StringUtils.splitByWholeSeparator(keyValueString, ":=");
- if (keyValue.length == 2) {
- options.put(StringUtils.trim(keyValue[0]), StringUtils.trim(keyValue[1]));
- }
- }
+ ManifestHeader header = ManifestHeader.parse("/dummy/path;" + optionsString);
+ Entry[] entries = header.getEntries();
+ if (entries.length > 0) {
+ overwrite = BooleanUtils.toBoolean(entries[0].getDirectiveValue(OVERWRITE_DIRECTIVE));
+ String ignoreImportProvidersString = StringUtils.defaultString(entries[0].getDirectiveValue(IGNORE_CONTENT_READERS_DIRECTIVE));
+ ignoreImportProviders = new HashSet<>(Arrays.asList(StringUtils.split(ignoreImportProvidersString, ",")));
+ }
+ else {
+ overwrite = false;
+ ignoreImportProviders = Collections.emptySet();
}
- return options;
}
-
+
public boolean isOverwrite() {
return overwrite;
}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
index 513c51f..3a0d166 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
@@ -44,9 +44,9 @@ public class InitialContentImportOptionsTest {
@Test
public void testOptions1() {
- InitialContentImportOptions underTest = new InitialContentImportOptions("overwrite:=true;ignoreImportProviders:=xml,json");
+ InitialContentImportOptions underTest = new InitialContentImportOptions("overwrite:=true;ignoreImportProviders:=\"xml,json\"");
assertTrue(underTest.isOverwrite());
- assertEquals(ImmutableSet.of("xml,json"), underTest.getIgnoreImportProviders());
+ assertEquals(ImmutableSet.of("xml","json"), underTest.getIgnoreImportProviders());
}
@Test
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 21/23: fix javadoc errors
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 23865041bd958b3336d3ba04613aa398d75636b6
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Mar 27 16:14:33 2017 +0000
fix javadoc errors
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1788968 13f79535-47bb-0310-9956-ffa450edef68
---
.../java/org/apache/sling/fsprovider/internal/FileMonitor.java | 3 +++
.../org/apache/sling/fsprovider/internal/FsResourceProvider.java | 7 +++----
.../org/apache/sling/fsprovider/internal/mapper/FileResource.java | 4 ++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index 876c167..88c9d6f 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -68,6 +68,9 @@ public final class FileMonitor extends TimerTask {
* Creates a new instance of this class.
* @param provider The resource provider.
* @param interval The interval between executions of the task, in milliseconds.
+ * @param fsMode FS mode
+ * @param contentFileExtensions Content file extensions
+ * @param contentFileCache Content file cache
*/
public FileMonitor(final FsResourceProvider provider, final long interval, FsMode fsMode,
final ContentFileExtensions contentFileExtensions, final ContentFileCache contentFileCache) {
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index b00825b..927b77a 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -77,7 +77,8 @@ import org.osgi.service.metatype.annotations.Option;
public final class FsResourceProvider implements ResourceProvider {
/**
- * Resource metadata property set by {@link FsResource} if the underlying file reference is a directory.
+ * Resource metadata property set by {@link org.apache.sling.fsprovider.internal.mapper.FileResource}
+ * if the underlying file reference is a directory.
*/
public static final String RESOURCE_METADATA_FILE_DIRECTORY = ":org.apache.sling.fsprovider.file.directory";
@@ -130,9 +131,7 @@ public final class FsResourceProvider implements ResourceProvider {
description = "Max. number of content files cached in memory.")
int provider_cache_size() default 10000;
- /**
- * Internal Name hint for web console.
- */
+ // Internal Name hint for web console.
String webconsole_configurationFactory_nameHint() default "{provider.fs.mode}: {" + ResourceProvider.ROOTS + "}";
}
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 f0adfb8..ff35181 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
@@ -53,13 +53,13 @@ public final class FileResource extends AbstractResource {
/**
* The resource type for file system files mapped into the resource tree by
- * the {@link FsResourceProvider} (value is "nt:file").
+ * the {@link org.apache.sling.fsprovider.internal.FsResourceProvider} (value is "nt:file").
*/
public static final String RESOURCE_TYPE_FILE = "nt:file";
/**
* The resource type for file system folders mapped into the resource tree
- * by the {@link FsResourceProvider} (value is "nt:folder").
+ * by the {@link org.apache.sling.fsprovider.internal.FsResourceProvider} (value is "nt:folder").
*/
public static final String RESOURCE_TYPE_FOLDER = "nt:folder";
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 14/23: SLING-6630 rename
INITIAL_CONTENT_FILES_FOLDERS to FILES_FOLDERS
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit f21de7adde7ef6493d54eb316e2511db8b58b69a
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Mar 10 15:42:23 2017 +0000
SLING-6630 rename INITIAL_CONTENT_FILES_FOLDERS to FILES_FOLDERS
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786368 13f79535-47bb-0310-9956-ffa450edef68
---
src/main/java/org/apache/sling/fsprovider/internal/FsMode.java | 8 ++++----
.../org/apache/sling/fsprovider/internal/FsResourceProvider.java | 6 +++---
src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
index 15af91f..66f1af7 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
@@ -19,19 +19,19 @@
package org.apache.sling.fsprovider.internal;
/**
- * Different modes for Filesystem provider support and filesystem layouts.
+ * Different modes for File system provider support and file system layouts.
*/
public enum FsMode {
/**
- * Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files.
+ * Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format.
*/
INITIAL_CONTENT,
/**
- * Sling-Initial-Content filesystem layout, support only files and folders (classic mode).
+ * Support only files and folders (classic mode).
*/
- INITIAL_CONTENT_FILES_FOLDERS,
+ FILES_FOLDERS,
/**
* FileVault XML format (expanded content package).
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index 5e42a90..eafbfda 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -117,9 +117,9 @@ public final class FsResourceProvider implements ResourceProvider {
description = "Filesystem layout mode for files, folders and content.",
options={
@Option(value="INITIAL_CONTENT", label="INITIAL_CONTENT - "
- + "Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files"),
- @Option(value="INITIAL_CONTENT_FILES_FOLDERS", label="INITIAL_CONTENT_FILES_FOLDERS - "
- + "Sling-Initial-Content filesystem layout, support only files and folders (classic mode)"),
+ + "Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format"),
+ @Option(value="FILES_FOLDERS", label="FILES_FOLDERS - "
+ + "Support only files and folders (classic mode)"),
@Option(value="FILEVAULT_XML", label="FILEVAULT_XML - "
+ "FileVault XML format (expanded content package)"),
})
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
index 0d12a06..d077b34 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
@@ -59,7 +59,7 @@ class TestUtils {
config.put("provider.file", "src/test/resources/fs-test");
config.put("provider.roots", "/fs-test");
config.put("provider.checkinterval", 0);
- config.put("provider.fs.mode", FsMode.INITIAL_CONTENT_FILES_FOLDERS.name());
+ config.put("provider.fs.mode", FsMode.FILES_FOLDERS.name());
config.putAll(props);
context.registerInjectActivateService(new FsResourceProvider(), config);
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 10/23: SLING-6537 FileVault XML
support
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 62f16aa1598a8c948f40f55fa678958370765cb9
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Mar 7 21:56:51 2017 +0000
SLING-6537 FileVault XML support
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1785894 13f79535-47bb-0310-9956-ffa450edef68
---
.../java/org/apache/sling/fsprovider/internal/FileMonitor.java | 4 ++--
.../org/apache/sling/fsprovider/internal/FsResourceProvider.java | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index 4ac056a..d77a2f6 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -172,7 +172,7 @@ public final class FileMonitor extends TimerTask {
// removed file and update status
sendEvents(monitorable, TOPIC_RESOURCE_REMOVED, reporter);
monitorable.status = NonExistingStatus.SINGLETON;
- contentFileCache.remove(monitorable.path);
+ contentFileCache.remove(transformPath(monitorable.path));
} else {
// check for changes
final FileStatus fs = (FileStatus)monitorable.status;
@@ -182,7 +182,7 @@ public final class FileMonitor extends TimerTask {
// changed
sendEvents(monitorable, TOPIC_RESOURCE_CHANGED, reporter);
changed = true;
- contentFileCache.remove(monitorable.path);
+ contentFileCache.remove(transformPath(monitorable.path));
}
if ( fs instanceof DirStatus ) {
// directory
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index 6a9d45f..4ec8a07 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -117,11 +117,11 @@ public final class FsResourceProvider implements ResourceProvider {
description = "Filesystem layout mode for files, folders and content.",
options={
@Option(value="INITIAL_CONTENT", label="INITIAL_CONTENT - "
- + "Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files."),
+ + "Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files"),
@Option(value="INITIAL_CONTENT_FILES_FOLDERS", label="INITIAL_CONTENT_FILES_FOLDERS - "
- + "Sling-Initial-Content filesystem layout, support only files and folders (classic mode)."),
+ + "Sling-Initial-Content filesystem layout, support only files and folders (classic mode)"),
@Option(value="FILEVAULT_XML", label="FILEVAULT_XML - "
- + "FileVault XML format (expanded content package)."),
+ + "FileVault XML format (expanded content package)"),
})
FsMode provider_fs_mode() default FsMode.INITIAL_CONTENT;
@@ -136,7 +136,7 @@ public final class FsResourceProvider implements ResourceProvider {
/**
* Internal Name hint for web console.
*/
- String webconsole_configurationFactory_nameHint() default "Root paths: {" + ResourceProvider.ROOTS + "}";
+ String webconsole_configurationFactory_nameHint() default "{provider.fs.mode}: {" + ResourceProvider.ROOTS + "}";
}
// The location in the resource tree where the resources are mapped
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 17/23: SLING-6440 switch to
latest jcr/contentparser API
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit a353cfba38bce86b689fd497493f45f0fb48593d
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Mar 14 10:44:18 2017 +0000
SLING-6440 switch to latest jcr/contentparser API
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786873 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 ++--
.../fsprovider/internal/parser/ContentFileParserUtil.java | 12 ++++++------
.../sling/fsprovider/internal/parser/ContentFileTypes.java | 6 +++---
.../apache/sling/fsprovider/internal/JsonContentTest.java | 2 +-
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/pom.xml b/pom.xml
index 0245895..892c3d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@
<Embed-Dependency>
johnzon-core;scope=compile;inline=false,
geronimo-json_1.0_spec;scope=compile;inline=false,
- org.apache.sling.commons.fscontentparser;scope=compile;inline=false
+ org.apache.sling.jcr.contentparser;scope=compile;inline=false
</Embed-Dependency>
</instructions>
</configuration>
@@ -147,7 +147,7 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.fscontentparser</artifactId>
+ <artifactId>org.apache.sling.jcr.contentparser</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
index 6ac72c5..ff83c00 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
@@ -26,9 +26,9 @@ import java.io.File;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
-import org.apache.sling.fscontentparser.ContentFileParser;
-import org.apache.sling.fscontentparser.ContentFileParserFactory;
-import org.apache.sling.fscontentparser.ContentFileType;
+import org.apache.sling.jcr.contentparser.ContentParser;
+import org.apache.sling.jcr.contentparser.ContentParserFactory;
+import org.apache.sling.jcr.contentparser.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,19 +39,19 @@ class ContentFileParserUtil {
private static final Logger log = LoggerFactory.getLogger(ContentFileParserUtil.class);
- private static final ContentFileParser JSON_PARSER;
+ private static final ContentParser JSON_PARSER;
static {
// workaround for JsonProvider classloader issue until https://issues.apache.org/jira/browse/GERONIMO-6560 is fixed
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ContentFileParserUtil.class.getClassLoader());
- JSON_PARSER = ContentFileParserFactory.create(ContentFileType.JSON);
+ JSON_PARSER = ContentParserFactory.create(ContentType.JSON);
}
finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
- private static final ContentFileParser JCR_XML_PARSER = ContentFileParserFactory.create(ContentFileType.JCR_XML);
+ private static final ContentParser JCR_XML_PARSER = ContentParserFactory.create(ContentType.JCR_XML);
private ContentFileParserUtil() {
// static methods only
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
index f3e2c22..8e6a9be 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
@@ -18,7 +18,7 @@
*/
package org.apache.sling.fsprovider.internal.parser;
-import org.apache.sling.fscontentparser.ContentFileType;
+import org.apache.sling.jcr.contentparser.ContentType;
/**
* Content file types.
@@ -28,12 +28,12 @@ public final class ContentFileTypes {
/**
* JSON content files.
*/
- public static final String JSON_SUFFIX = "." + ContentFileType.JSON.getExtension();
+ public static final String JSON_SUFFIX = "." + ContentType.JSON.getExtension();
/**
* JCR XML content files.
*/
- public static final String JCR_XML_SUFFIX = "." + ContentFileType.JCR_XML.getExtension();
+ public static final String JCR_XML_SUFFIX = "." + ContentType.JCR_XML.getExtension();
private ContentFileTypes() {
// static methods only
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 f38a75f..c4631b6 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -44,9 +44,9 @@ import javax.jcr.nodetype.NodeType;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.fscontentparser.ParserOptions;
import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.jcr.contentparser.ParserOptions;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 06/23: set version in branch to
1.3.0-SNAPSHOT (for old Resource Provider SPI)
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit b342fb66b7917729f0d61449b6adc3b8fbf182d9
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Mar 3 13:13:51 2017 +0000
set version in branch to 1.3.0-SNAPSHOT (for old Resource Provider SPI)
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1785292 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 0db714b..f7d4a3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
<artifactId>org.apache.sling.fsresource</artifactId>
<packaging>bundle</packaging>
- <version>1.1.5-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<name>Apache Sling File System Resource Provider</name>
<description>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 18/23: SLING-6440 switch to
latest jcr/contentparser API
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 8c0e64afc0f6ff9cd7db4d0bb1c4849f6d15c953
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Mar 14 10:59:07 2017 +0000
SLING-6440 switch to latest jcr/contentparser API
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786878 13f79535-47bb-0310-9956-ffa450edef68
---
.../fsprovider/internal/parser/ContentFileParserUtil.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
index ff83c00..cb7e222 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
@@ -22,7 +22,10 @@ import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JCR_XML_SUFFIX;
import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JSON_SUFFIX;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
@@ -68,10 +71,10 @@ class ContentFileParserUtil {
}
try {
if (StringUtils.endsWith(file.getName(), JSON_SUFFIX)) {
- return JSON_PARSER.parse(file);
+ return parse(JSON_PARSER, file);
}
else if (StringUtils.equals(file.getName(), DOT_CONTENT_XML) || StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
- return JCR_XML_PARSER.parse(file);
+ return parse(JCR_XML_PARSER, file);
}
}
catch (Throwable ex) {
@@ -80,4 +83,11 @@ class ContentFileParserUtil {
return null;
}
+ private static Map<String,Object> parse(ContentParser contentParser, File file) throws IOException {
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis)) {
+ return contentParser.parse(bis);
+ }
+ }
+
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 08/23: rename branch folder to
1.x
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 633173fa36e60e4f55ace4eeacf54a05b0a6aa37
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Mar 7 21:15:11 2017 +0000
rename branch folder to 1.x
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1785889 13f79535-47bb-0310-9956-ffa450edef68
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 23/23: [maven-release-plugin]
copy for tag org.apache.sling.fsresource-1.3.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit fd787ad957a4646c30309f9ca30edc4a2ce17e76
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Mar 27 16:17:12 2017 +0000
[maven-release-plugin] copy for tag org.apache.sling.fsresource-1.3.0
git-svn-id: https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.fsresource-1.3.0@1788975 13f79535-47bb-0310-9956-ffa450edef68
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 05/23: SLING-6440 update to
latest API
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit aa2eeccb57f237f25eb037dc0a852fa770cb3601
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Mar 2 22:00:47 2017 +0000
SLING-6440 update to latest API
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1785203 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 ++--
.../sling/fsprovider/internal/parser/ContentFileParserUtil.java | 6 +++---
.../apache/sling/fsprovider/internal/parser/ContentFileTypes.java | 6 +++---
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5db693f..0db714b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@
<Embed-Dependency>
johnzon-core;scope=compile;inline=false,
geronimo-json_1.0_spec;scope=compile;inline=false,
- org.apache.sling.fscontentparser;scope=compile;inline=false
+ org.apache.sling.commons.fscontentparser;scope=compile;inline=false
</Embed-Dependency>
</instructions>
</configuration>
@@ -141,7 +141,7 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.fscontentparser</artifactId>
+ <artifactId>org.apache.sling.commons.fscontentparser</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
index ec9af59..4b46157 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
@@ -25,9 +25,9 @@ import java.io.File;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
-import org.apache.sling.fscontentparser.ContentFileExtension;
import org.apache.sling.fscontentparser.ContentFileParser;
import org.apache.sling.fscontentparser.ContentFileParserFactory;
+import org.apache.sling.fscontentparser.ContentFileType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,13 +44,13 @@ class ContentFileParserUtil {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(ContentFileParserUtil.class.getClassLoader());
- JSON_PARSER = ContentFileParserFactory.create(ContentFileExtension.JSON);
+ JSON_PARSER = ContentFileParserFactory.create(ContentFileType.JSON);
}
finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
- private static final ContentFileParser JCR_XML_PARSER = ContentFileParserFactory.create(ContentFileExtension.JCR_XML);
+ private static final ContentFileParser JCR_XML_PARSER = ContentFileParserFactory.create(ContentFileType.JCR_XML);
private ContentFileParserUtil() {
// static methods only
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
index 689654d..f3e2c22 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
@@ -18,7 +18,7 @@
*/
package org.apache.sling.fsprovider.internal.parser;
-import org.apache.sling.fscontentparser.ContentFileExtension;
+import org.apache.sling.fscontentparser.ContentFileType;
/**
* Content file types.
@@ -28,12 +28,12 @@ public final class ContentFileTypes {
/**
* JSON content files.
*/
- public static final String JSON_SUFFIX = "." + ContentFileExtension.JSON;
+ public static final String JSON_SUFFIX = "." + ContentFileType.JSON.getExtension();
/**
* JCR XML content files.
*/
- public static final String JCR_XML_SUFFIX = "." + ContentFileExtension.JCR_XML;
+ public static final String JCR_XML_SUFFIX = "." + ContentFileType.JCR_XML.getExtension();
private ContentFileTypes() {
// static methods only
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 15/23: SLING-6630 make
FILES_FOLDERS default
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 16babc30085967a7eb5dbed84a9319b70735ace6
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Mar 10 15:50:59 2017 +0000
SLING-6630 make FILES_FOLDERS default
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786371 13f79535-47bb-0310-9956-ffa450edef68
---
src/main/java/org/apache/sling/fsprovider/internal/FsMode.java | 10 +++++-----
.../apache/sling/fsprovider/internal/FsResourceProvider.java | 6 +++---
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
index 66f1af7..50eeebd 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
@@ -24,16 +24,16 @@ package org.apache.sling.fsprovider.internal;
public enum FsMode {
/**
- * Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format.
- */
- INITIAL_CONTENT,
-
- /**
* Support only files and folders (classic mode).
*/
FILES_FOLDERS,
/**
+ * Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format.
+ */
+ INITIAL_CONTENT,
+
+ /**
* FileVault XML format (expanded content package).
*/
FILEVAULT_XML
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index eafbfda..3745107 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -116,14 +116,14 @@ public final class FsResourceProvider implements ResourceProvider {
@AttributeDefinition(name = "Filesystem layout",
description = "Filesystem layout mode for files, folders and content.",
options={
- @Option(value="INITIAL_CONTENT", label="INITIAL_CONTENT - "
- + "Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format"),
@Option(value="FILES_FOLDERS", label="FILES_FOLDERS - "
+ "Support only files and folders (classic mode)"),
+ @Option(value="INITIAL_CONTENT", label="INITIAL_CONTENT - "
+ + "Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format"),
@Option(value="FILEVAULT_XML", label="FILEVAULT_XML - "
+ "FileVault XML format (expanded content package)"),
})
- FsMode provider_fs_mode() default FsMode.INITIAL_CONTENT;
+ FsMode provider_fs_mode() default FsMode.FILES_FOLDERS;
@AttributeDefinition(name = "Init. Content Options",
description = "Import options for Sling-Initial-Content filesystem layout. Supported options: overwrite, ignoreImportProviders.")
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 22/23: [maven-release-plugin]
prepare release org.apache.sling.fsresource-1.3.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 3f53032364569cac58d9310aa326dfb0860e4c56
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Mar 27 16:16:59 2017 +0000
[maven-release-plugin] prepare release org.apache.sling.fsresource-1.3.0
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1788974 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 206e27c..b2df63c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
<artifactId>org.apache.sling.fsresource</artifactId>
<packaging>bundle</packaging>
- <version>1.3.0-SNAPSHOT</version>
+ <version>1.3.0</version>
<name>Apache Sling File System Resource Provider</name>
<description>
@@ -36,9 +36,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/branches/fsresource-1.x</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/branches/fsresource-1.x</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.fsresource-1.3.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.fsresource-1.3.0</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.fsresource-1.3.0</url>
</scm>
<build>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 19/23: SLING-6440 switch to
latest contentparser API
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit aa6fca15821be8bb1c73311302e96dcaff24ea9e
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Mar 17 21:56:21 2017 +0000
SLING-6440 switch to latest contentparser API
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1787508 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/fsprovider/internal/FileMonitor.java | 27 ++++-----
.../fsprovider/internal/mapper/ContentFile.java | 70 +++++-----------------
.../internal/mapper/ContentFileResource.java | 2 +-
.../internal/mapper/ContentFileResourceMapper.java | 7 ++-
.../internal/mapper/FileVaultResourceMapper.java | 5 +-
.../internal/mapper/jcr/FsNodeIterator.java | 18 ++----
.../internal/mapper/valuemap/ValueMapUtil.java | 8 +--
.../fsprovider/internal/parser/ContentElement.java | 52 ++++++++++++++++
.../internal/parser/ContentElementHandler.java | 69 +++++++++++++++++++++
.../internal/parser/ContentElementImpl.java | 68 +++++++++++++++++++++
.../internal/parser/ContentFileCache.java | 12 ++--
.../internal/parser/ContentFileParserUtil.java | 13 ++--
.../internal/mapper/ContentFileTest.java | 25 +++-----
.../internal/mapper/valuemap/ValueMapUtilTest.java | 4 --
.../internal/parser/ContentFileCacheTest.java | 5 +-
.../internal/parser/ContentFileParserUtilTest.java | 19 +++---
16 files changed, 264 insertions(+), 140 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index f4db089..876c167 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -38,6 +38,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.vault.util.PlatformNameFormat;
import org.apache.sling.fsprovider.internal.mapper.ContentFile;
import org.apache.sling.fsprovider.internal.mapper.FileResource;
+import org.apache.sling.fsprovider.internal.parser.ContentElement;
+import org.apache.sling.fsprovider.internal.parser.ContentElementImpl;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
@@ -261,47 +263,44 @@ public final class FileMonitor extends TimerTask {
}
}
- @SuppressWarnings("unchecked")
private List<ResourceChange> collectResourceChanges(final Monitorable monitorable, final String changeType) {
List<ResourceChange> changes = new ArrayList<>();
if (monitorable.status instanceof ContentFileStatus) {
ContentFile contentFile = ((ContentFileStatus)monitorable.status).contentFile;
if (StringUtils.equals(changeType, TOPIC_RESOURCE_CHANGED)) {
- Map<String,Object> content = (Map<String,Object>)contentFile.getContent();
+ ContentElement content = contentFile.getContent();
// we cannot easily report the diff of resource changes between two content files
// so we simulate a removal of the toplevel node and then add all nodes contained in the current content file again.
changes.add(buildContentResourceChange(TOPIC_RESOURCE_REMOVED, content, transformPath(monitorable.path)));
addContentResourceChanges(changes, TOPIC_RESOURCE_ADDED, content, transformPath(monitorable.path));
}
else {
- addContentResourceChanges(changes, changeType, (Map<String,Object>)contentFile.getContent(), transformPath(monitorable.path));
+ addContentResourceChanges(changes, changeType, contentFile.getContent(), transformPath(monitorable.path));
}
}
else {
- Map<String,Object> content = new HashMap<>();
- content.put("sling:resourceType", monitorable.status instanceof FileStatus ?
+ Map<String,Object> props = new HashMap<>();
+ props.put("sling:resourceType", monitorable.status instanceof FileStatus ?
FileResource.RESOURCE_TYPE_FILE : FileResource.RESOURCE_TYPE_FOLDER);
+ ContentElement content = new ContentElementImpl(null, props);
changes.add(buildContentResourceChange(changeType, content, transformPath(monitorable.path)));
}
return changes;
}
- @SuppressWarnings("unchecked")
private void addContentResourceChanges(final List<ResourceChange> changes, final String changeType,
- final Map<String,Object> content, final String path) {
+ final ContentElement content, final String path) {
changes.add(buildContentResourceChange(changeType, content, path));
if (content != null) {
- for (Map.Entry<String,Object> entry : content.entrySet()) {
- if (entry.getValue() instanceof Map) {
- String childPath = path + "/" + entry.getKey();
- addContentResourceChanges(changes, changeType, (Map<String,Object>)entry.getValue(), childPath);
- }
+ for (Map.Entry<String,ContentElement> entry : content.getChildren().entrySet()) {
+ String childPath = path + "/" + entry.getKey();
+ addContentResourceChanges(changes, changeType, entry.getValue(), childPath);
}
}
}
- private ResourceChange buildContentResourceChange(final String changeType, final Map<String,Object> content, final String path) {
+ private ResourceChange buildContentResourceChange(final String changeType, final ContentElement content, final String path) {
ResourceChange change = new ResourceChange();
change.path = path;
- change.resourceType = content != null ? (String)content.get("sling:resourceType") : null;
+ change.resourceType = content != null ? (String)content.getProperties().get("sling:resourceType") : null;
change.topic = changeType;
return change;
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
index 00c238a..dd31346 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
@@ -22,10 +22,9 @@ import java.io.File;
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.collections.IteratorUtils;
-import org.apache.commons.collections.Predicate;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapUtil;
+import org.apache.sling.fsprovider.internal.parser.ContentElement;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
/**
@@ -38,7 +37,7 @@ public final class ContentFile {
private final String subPath;
private final ContentFileCache contentFileCache;
private boolean contentInitialized;
- private Object content;
+ private ContentElement content;
private ValueMap valueMap;
/**
@@ -79,10 +78,15 @@ public final class ContentFile {
* Content object referenced by sub path.
* @return Map if resource, property value if property.
*/
- public Object getContent() {
+ public ContentElement getContent() {
if (!contentInitialized) {
- Map<String,Object> rootContent = contentFileCache.get(path, file);
- content = getDeepContent(rootContent, subPath);
+ ContentElement rootContent = contentFileCache.get(path, file);
+ if (subPath == null) {
+ content = rootContent;
+ }
+ else {
+ content = rootContent.getChild(subPath);
+ }
contentInitialized = true;
}
return content;
@@ -96,21 +100,13 @@ public final class ContentFile {
}
/**
- * @return true if content references resource map.
- */
- public boolean isResource() {
- return (getContent() instanceof Map);
- }
-
- /**
* @return ValueMap for resource. Never null.
*/
- @SuppressWarnings("unchecked")
public ValueMap getValueMap() {
if (valueMap == null) {
- Object currentContent = getContent();
- if (currentContent instanceof Map) {
- valueMap = ValueMapUtil.toValueMap((Map<String,Object>)currentContent);
+ ContentElement currentContent = getContent();
+ if (currentContent != null) {
+ valueMap = ValueMapUtil.toValueMap(currentContent.getProperties());
}
else {
valueMap = ValueMap.EMPTY;
@@ -122,18 +118,8 @@ public final class ContentFile {
/**
* @return Child maps.
*/
- @SuppressWarnings("unchecked")
- public Iterator<Map.Entry<String,Map<String,Object>>> getChildren() {
- if (!isResource()) {
- return IteratorUtils.emptyIterator();
- }
- return IteratorUtils.filteredIterator(((Map)getContent()).entrySet().iterator(), new Predicate() {
- @Override
- public boolean evaluate(Object object) {
- Map.Entry<String,Object> entry = (Map.Entry<String,Object>)object;
- return entry.getValue() instanceof Map;
- }
- });
+ public Iterator<Map.Entry<String,ContentElement>> getChildren() {
+ return getContent().getChildren().entrySet().iterator();
}
/**
@@ -161,30 +147,4 @@ public final class ContentFile {
return new ContentFile(file, path, absoluteSubPath, contentFileCache);
}
- @SuppressWarnings("unchecked")
- private static Object getDeepContent(Object object, String subPath) {
- if (object == null) {
- return null;
- }
- if (subPath == null) {
- return object;
- }
- if (!(object instanceof Map)) {
- return null;
- }
- String name;
- String remainingSubPath;
- int slashIndex = subPath.indexOf('/');
- if (slashIndex >= 0) {
- name = subPath.substring(0, slashIndex);
- remainingSubPath = subPath.substring(slashIndex + 1);
- }
- else {
- name = subPath;
- remainingSubPath = null;
- }
- Object subObject = ((Map<String,Object>)object).get(name);
- return getDeepContent(subObject, remainingSubPath);
- }
-
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java
index 622deba..f65422d 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java
@@ -107,7 +107,7 @@ public final class ContentFileResource extends AbstractResource {
else if (type == ValueMap.class) {
return (AdapterType)contentFile.getValueMap();
}
- else if (type == Node.class && contentFile.isResource()) {
+ else if (type == Node.class) {
// support a subset of JCR API for content file resources
return (AdapterType)new FsNode(contentFile, getResourceResolver());
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
index 09b6ffe..b44926a 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
@@ -32,6 +32,7 @@ import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.fsprovider.internal.ContentFileExtensions;
import org.apache.sling.fsprovider.internal.FsResourceMapper;
+import org.apache.sling.fsprovider.internal.parser.ContentElement;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
public final class ContentFileResourceMapper implements FsResourceMapper {
@@ -105,10 +106,10 @@ public final class ContentFileResourceMapper implements FsResourceMapper {
// get child resources from content fragments in content file
List<ContentFile> children = new ArrayList<>();
- if (parentContentFile.hasContent() && parentContentFile.isResource()) {
- Iterator<Map.Entry<String,Map<String,Object>>> childMaps = parentContentFile.getChildren();
+ if (parentContentFile.hasContent()) {
+ Iterator<Map.Entry<String,ContentElement>> childMaps = parentContentFile.getChildren();
while (childMaps.hasNext()) {
- Map.Entry<String,Map<String,Object>> entry = childMaps.next();
+ Map.Entry<String,ContentElement> entry = childMaps.next();
children.add(parentContentFile.navigateToRelative(entry.getKey()));
}
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
index 6585d1e..14f6146 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
@@ -38,6 +38,7 @@ import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.fsprovider.internal.FsResourceMapper;
+import org.apache.sling.fsprovider.internal.parser.ContentElement;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -94,9 +95,9 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
// get children from content resource of parent
ContentFile parentContentFile = getContentFile(parentPath, null);
if (parentContentFile != null) {
- Iterator<Map.Entry<String,Map<String,Object>>> childMaps = parentContentFile.getChildren();
+ Iterator<Map.Entry<String,ContentElement>> childMaps = parentContentFile.getChildren();
while (childMaps.hasNext()) {
- Map.Entry<String,Map<String,Object>> entry = childMaps.next();
+ Map.Entry<String,ContentElement> entry = childMaps.next();
String childPath = parentPath + "/" + entry.getKey();
if (pathMatches(childPath)) {
childPaths.add(childPath);
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
index 09db7d4..7565994 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
@@ -24,10 +24,9 @@ import java.util.Map;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
-import org.apache.commons.collections.IteratorUtils;
-import org.apache.commons.collections.Predicate;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+import org.apache.sling.fsprovider.internal.parser.ContentElement;
/**
* Simplified implementation of read-only content access via the JCR API.
@@ -36,20 +35,13 @@ class FsNodeIterator implements NodeIterator {
private final ContentFile contentFile;
private final ResourceResolver resolver;
- private final Iterator<Map.Entry<String,Map<String,Object>>> children;
+ private final Iterator<Map.Entry<String,ContentElement>> children;
- @SuppressWarnings("unchecked")
public FsNodeIterator(ContentFile contentFile, ResourceResolver resolver) {
this.contentFile = contentFile;
this.resolver = resolver;
- Map<String,Object> content = (Map<String,Object>)contentFile.getContent();
- this.children = IteratorUtils.filteredIterator(content.entrySet().iterator(), new Predicate() {
- @Override
- public boolean evaluate(Object object) {
- Map.Entry<String,Object> entry = (Map.Entry<String,Object>)object;
- return (entry.getValue() instanceof Map);
- }
- });
+ ContentElement content = contentFile.getContent();
+ this.children = content.getChildren().entrySet().iterator();
}
public boolean hasNext() {
@@ -62,7 +54,7 @@ class FsNodeIterator implements NodeIterator {
@Override
public Node nextNode() {
- Map.Entry<String,Map<String,Object>> nextEntry = children.next();
+ Map.Entry<String,ContentElement> nextEntry = children.next();
return new FsNode(contentFile.navigateToRelative(nextEntry.getKey()), resolver);
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java
index b0a079c..ce69941 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java
@@ -38,12 +38,8 @@ public final class ValueMapUtil {
public static ValueMap toValueMap(Map<String,Object> content) {
Map<String,Object> props = new HashMap<>();
- for (Map.Entry<String, Object> entry : ((Map<String,Object>)content).entrySet()) {
- if (entry.getValue() instanceof Map) {
- // skip child resources
- continue;
- }
- else if (entry.getValue() instanceof Collection) {
+ for (Map.Entry<String, Object> entry : content.entrySet()) {
+ if (entry.getValue() instanceof Collection) {
// convert lists to arrays
props.put(entry.getKey(), ((Collection)entry.getValue()).toArray());
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElement.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElement.java
new file mode 100644
index 0000000..85ead62
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElement.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.util.Map;
+
+/**
+ * Represents a resource or node in the content hierarchy.
+ */
+public interface ContentElement {
+
+ /**
+ * @return Resource name. The root resource has no name (null).
+ */
+ String getName();
+
+ /**
+ * Properties of this resource.
+ * @return Properties (keys, values)
+ */
+ Map<String, Object> getProperties();
+
+ /**
+ * Get children of current resource. The Map preserves the ordering of children.
+ * @return Children (child names, child objects)
+ */
+ Map<String, ContentElement> getChildren();
+
+ /**
+ * Get child or descendant
+ * @param path Relative path to address child or one of it's descendants (use "/" as hierarchy separator).
+ * @return Child or null if no child found with this path
+ */
+ ContentElement getChild(String path);
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementHandler.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementHandler.java
new file mode 100644
index 0000000..e128943
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementHandler.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.jcr.contentparser.ContentHandler;
+
+/**
+ * {@link ContentHandler} implementation that produces a tree of {@link ContentElement} items.
+ */
+final class ContentElementHandler implements ContentHandler {
+
+ private ContentElement root;
+ private Pattern PATH_PATTERN = Pattern.compile("^((/[^/]+)*)(/([^/]+))$");
+
+ @Override
+ public void resource(String path, Map<String, Object> properties) {
+ if (StringUtils.equals(path, "/")) {
+ root = new ContentElementImpl(null, properties);
+ }
+ else {
+ if (root == null) {
+ throw new RuntimeException("Root resource not set.");
+ }
+ Matcher matcher = PATH_PATTERN.matcher(path);
+ if (!matcher.matches()) {
+ throw new RuntimeException("Unexpected path:" + path);
+ }
+ String relativeParentPath = StringUtils.stripStart(matcher.group(1), "/");
+ String name = matcher.group(4);
+ ContentElement parent;
+ if (StringUtils.isEmpty(relativeParentPath)) {
+ parent = root;
+ }
+ else {
+ parent = root.getChild(relativeParentPath);
+ }
+ if (parent == null) {
+ throw new RuntimeException("Parent '" + relativeParentPath + "' does not exist.");
+ }
+ parent.getChildren().put(name, new ContentElementImpl(name, properties));
+ }
+ }
+
+ public ContentElement getRoot() {
+ return root;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementImpl.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementImpl.java
new file mode 100644
index 0000000..5205c6e
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementImpl.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+
+public final class ContentElementImpl implements ContentElement {
+
+ private final String name;
+ private final Map<String, Object> properties;
+ private final Map<String, ContentElement> children = new LinkedHashMap<>();
+
+ public ContentElementImpl(String name, Map<String, Object> properties) {
+ this.name = name;
+ this.properties = properties;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public Map<String, ContentElement> getChildren() {
+ return children;
+ }
+
+ @Override
+ public ContentElement getChild(String path) {
+ String name = StringUtils.substringBefore(path, "/");
+ ContentElement child = children.get(name);
+ if (child == null) {
+ return null;
+ }
+ String remainingPath = StringUtils.substringAfter(path, "/");
+ if (StringUtils.isEmpty(remainingPath)) {
+ return child;
+ }
+ else {
+ return child.getChild(remainingPath);
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
index 745ae60..4222e98 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
@@ -29,8 +29,8 @@ import org.apache.commons.collections.map.LRUMap;
*/
public final class ContentFileCache {
- private final Map<String,Map<String,Object>> contentCache;
- private final Map<String,Object> NULL_MAP = Collections.emptyMap();
+ private final Map<String,ContentElement> contentCache;
+ private final ContentElement NULL_ELEMENT = new ContentElementImpl(null, Collections.<String,Object>emptyMap());
/**
* @param maxSize Cache size. 0 = caching disabled.
@@ -51,21 +51,21 @@ public final class ContentFileCache {
* @param file File
* @return Content or null
*/
- public Map<String,Object> get(String path, File file) {
- Map<String,Object> content = null;
+ public ContentElement get(String path, File file) {
+ ContentElement content = null;
if (contentCache != null) {
content = contentCache.get(path);
}
if (content == null) {
content = ContentFileParserUtil.parse(file);
if (content == null) {
- content = NULL_MAP;
+ content = NULL_ELEMENT;
}
if (contentCache != null) {
contentCache.put(path, content);
}
}
- if (content == NULL_MAP) {
+ if (content == NULL_ELEMENT) {
return null;
}
else {
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
index cb7e222..dbb638a 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
@@ -26,7 +26,6 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.jcr.contentparser.ContentParser;
@@ -65,7 +64,7 @@ class ContentFileParserUtil {
* @param file File. Type is detected automatically.
* @return Content or null if content could not be parsed.
*/
- public static Map<String,Object> parse(File file) {
+ public static ContentElement parse(File file) {
if (!file.exists()) {
return null;
}
@@ -82,12 +81,14 @@ class ContentFileParserUtil {
}
return null;
}
-
- private static Map<String,Object> parse(ContentParser contentParser, File file) throws IOException {
+
+ private static ContentElement parse(ContentParser contentParser, File file) throws IOException {
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis)) {
- return contentParser.parse(bis);
+ ContentElementHandler handler = new ContentElementHandler();
+ contentParser.parse(handler, bis);
+ return handler.getRoot();
}
}
-
+
}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java
index 4659991..3a6a747 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java
@@ -24,9 +24,9 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.util.Map;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.parser.ContentElement;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
import org.junit.Test;
@@ -34,7 +34,6 @@ public class ContentFileTest {
private ContentFileCache contentFileCache = new ContentFileCache(0);
- @SuppressWarnings("unchecked")
@Test
public void testRootContent() {
File file = new File("src/test/resources/fs-test/folder2/content.json");
@@ -45,16 +44,15 @@ public class ContentFileTest {
assertTrue(underTest.hasContent());
- Map<String,Object> content = (Map<String,Object>)underTest.getContent();
- assertEquals("app:Page", content.get("jcr:primaryType"));
- assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ ContentElement content = underTest.getContent();
+ assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
+ assertEquals("app:PageContent", content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
ValueMap props = underTest.getValueMap();
assertEquals("app:Page", props.get("jcr:primaryType"));
assertNull(props.get("jcr:content"));
}
- @SuppressWarnings("unchecked")
@Test
public void testContentLevel1() {
File file = new File("src/test/resources/fs-test/folder2/content.json");
@@ -65,14 +63,13 @@ public class ContentFileTest {
assertTrue(underTest.hasContent());
- Map<String,Object> content = (Map<String,Object>)underTest.getContent();
- assertEquals("app:PageContent", content.get("jcr:primaryType"));
+ ContentElement content = underTest.getContent();
+ assertEquals("app:PageContent", content.getProperties().get("jcr:primaryType"));
ValueMap props = underTest.getValueMap();
assertEquals("app:PageContent", props.get("jcr:primaryType"));
}
- @SuppressWarnings("unchecked")
@Test
public void testContentLevel5() {
File file = new File("src/test/resources/fs-test/folder2/content.json");
@@ -83,8 +80,8 @@ public class ContentFileTest {
assertTrue(underTest.hasContent());
- Map<String,Object> content = (Map<String,Object>)underTest.getContent();
- assertEquals("nt:resource", content.get("jcr:primaryType"));
+ ContentElement content = underTest.getContent();
+ assertEquals("nt:resource", content.getProperties().get("jcr:primaryType"));
ValueMap props = underTest.getValueMap();
assertEquals("nt:resource", props.get("jcr:primaryType"));
@@ -98,11 +95,7 @@ public class ContentFileTest {
assertEquals(file, underTest.getFile());
assertEquals("jcr:content/jcr:title", underTest.getSubPath());
- assertTrue(underTest.hasContent());
-
- assertEquals("English", underTest.getContent());
-
- assertTrue(underTest.getValueMap().isEmpty());
+ assertFalse(underTest.hasContent());
}
@Test
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
index 87f2bfd..841ef00 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
@@ -20,7 +20,6 @@ package org.apache.sling.fsprovider.internal.mapper.valuemap;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import java.util.HashMap;
import java.util.Map;
@@ -29,7 +28,6 @@ import org.apache.sling.api.resource.ValueMap;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
public class ValueMapUtilTest {
@@ -38,7 +36,6 @@ public class ValueMapUtilTest {
Map<String,Object> content = new HashMap<>();
content.put("stringProp", "abc");
content.put("intProp", 123);
- content.put("childNode", ImmutableMap.<String,Object>of());
content.put("stringArray", new String[] { "a", "b", "c" });
content.put("stringList", ImmutableList.of("ab", "cd"));
content.put("intList", ImmutableList.of(12, 34));
@@ -46,7 +43,6 @@ public class ValueMapUtilTest {
ValueMap props = ValueMapUtil.toValueMap(content);
assertEquals("abc", props.get("stringProp", String.class));
assertEquals((Integer)123, props.get("intProp", 0));
- assertNull(props.get("childNode"));
assertArrayEquals(new String[] { "a", "b", "c" }, props.get("stringArray", String[].class));
assertArrayEquals(new String[] { "ab", "cd" }, props.get("stringList", String[].class));
assertArrayEquals(new Integer[] { 12, 34 }, props.get("intList", Integer[].class));
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java
index 1eaf1e1..236959a 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
-import java.util.Map;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.Theories;
@@ -44,7 +43,7 @@ public class ContentFileCacheTest {
public void testCache(int cacheSize) {
ContentFileCache underTest = new ContentFileCache(cacheSize);
- Map<String,Object> content1 = underTest.get("/fs-test/folder2/content", new File("src/test/resources/fs-test/folder2/content.json"));
+ ContentElement content1 = underTest.get("/fs-test/folder2/content", new File("src/test/resources/fs-test/folder2/content.json"));
assertNotNull(content1);
switch (cacheSize) {
@@ -57,7 +56,7 @@ public class ContentFileCacheTest {
break;
}
- Map<String,Object> content2 = underTest.get("/fs-test/folder1/file1a", new File("src/test/resources/fs-test/folder1/file1a.txt"));
+ ContentElement content2 = underTest.get("/fs-test/folder1/file1a", new File("src/test/resources/fs-test/folder1/file1a.txt"));
assertNull(content2);
switch (cacheSize) {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
index 9bdaa51..b775c81 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
@@ -23,43 +23,40 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
-import java.util.Map;
import org.junit.Test;
public class ContentFileParserUtilTest {
- @SuppressWarnings("unchecked")
@Test
public void testParseJson() {
File file = new File("src/test/resources/fs-test/folder2/content.json");
- Map<String,Object> content = ContentFileParserUtil.parse(file);
+ ContentElement content = ContentFileParserUtil.parse(file);
assertNotNull(content);
- assertEquals("app:Page", content.get("jcr:primaryType"));
- assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
+ assertEquals("app:PageContent", content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
}
@Test
public void testParseInvalidJson() {
File file = new File("src/test/resources/invalid-test/invalid.json");
- Map<String,Object> content = ContentFileParserUtil.parse(file);
+ ContentElement content = ContentFileParserUtil.parse(file);
assertNull(content);
}
- @SuppressWarnings("unchecked")
@Test
public void testParseJcrXml() {
File file = new File("src/test/resources/fs-test/folder3/content.jcr.xml");
- Map<String,Object> content = ContentFileParserUtil.parse(file);
+ ContentElement content = ContentFileParserUtil.parse(file);
assertNotNull(content);
- assertEquals("app:Page", content.get("jcr:primaryType"));
- assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
+ assertEquals("app:PageContent", content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
}
@Test
public void testParseInvalidJcrXml() {
File file = new File("src/test/resources/invalid-test/invalid.jcr.xml");
- Map<String,Object> content = ContentFileParserUtil.parse(file);
+ ContentElement content = ContentFileParserUtil.parse(file);
assertNull(content);
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 03/23: SLING-6440 simplify
FileMonitor
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 88b3a59294ed3dca3205bf3a5646a342ec298497
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Feb 28 16:14:31 2017 +0000
SLING-6440 simplify FileMonitor
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1784772 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/fsprovider/internal/FileMonitor.java | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index f1d4c90..609fe58 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -21,11 +21,9 @@ package org.apache.sling.fsprovider.internal;
import java.io.File;
import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@@ -263,15 +261,6 @@ public final class FileMonitor extends TimerTask {
}
}
private ResourceChange buildContentResourceChange(final String topic, final Map<String,Object> content, final String path) {
- Set<String> addedPropertyNames = null;
- if (content != null && topic == SlingConstants.TOPIC_RESOURCE_ADDED) {
- addedPropertyNames = new HashSet<>();
- for (Map.Entry<String,Object> entry : content.entrySet()) {
- if (!(entry.getValue() instanceof Map)) {
- addedPropertyNames.add(entry.getKey());
- }
- }
- }
ResourceChange change = new ResourceChange();
change.path = path;
change.resourceType = content != null ? (String)content.get("sling:resourceType") : null;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 01/23: branch fsresource
version before switch to new Sling API
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit f4b94c0cde63116a7978bc8b9bd2a77b55e7a087
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Feb 24 21:17:06 2017 +0000
branch fsresource version before switch to new Sling API
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1784335 13f79535-47bb-0310-9956-ffa450edef68
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 07/23: SLING-6537 FileVault XML
support
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit af87b046380f8cb60220503b6d6891a1599eb9b4
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Mar 6 21:48:44 2017 +0000
SLING-6537 FileVault XML support
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1785772 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
.../fsprovider/internal/ContentFileExtensions.java | 3 +-
.../sling/fsprovider/internal/FileMonitor.java | 159 ++++++++------
.../apache/sling/fsprovider/internal/FsMode.java | 41 ++++
.../fsprovider/internal/FsResourceProvider.java | 116 +++++++---
.../internal/InitialContentImportOptions.java | 76 +++++++
.../fsprovider/internal/mapper/ContentFile.java | 53 +++--
.../internal/mapper/ContentFileResourceMapper.java | 16 +-
.../internal/mapper/FileVaultResourceMapper.java | 201 +++++++++++++++++
.../fsprovider/internal/mapper/jcr/FsNode.java | 20 +-
.../internal/mapper/jcr/FsNodeIterator.java | 9 +-
.../internal/parser/ContentFileParserUtil.java | 6 +-
.../sling/fsprovider/internal/FileMonitorTest.java | 129 +++++------
.../fsprovider/internal/FileVaultContentTest.java | 143 ++++++++++++
.../internal/FileVaultFileMonitorTest.java | 239 +++++++++++++++++++++
.../internal/InitialContentImportOptionsTest.java | 59 +++++
.../fsprovider/internal/JcrXmlContentTest.java | 5 +-
.../sling/fsprovider/internal/JsonContentTest.java | 7 +-
.../sling/fsprovider/internal/TestUtils.java | 33 +++
.../vaultfs-test/META-INF/vault/filter.xml | 4 +-
.../jcr_root/content/dam/talk.png/.content.xml | 2 -
21 files changed, 1103 insertions(+), 220 deletions(-)
diff --git a/pom.xml b/pom.xml
index f7d4a3c..e530623 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>30-SNAPSHOT</version>
+ <version>30</version>
<relativePath />
</parent>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java b/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
index 5097750..f9cacec 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
@@ -41,8 +41,9 @@ public final class ContentFileExtensions {
* @return Content file name suffix or null if not a context file.
*/
public String getSuffix(File file) {
+ String fileName = "/" + file.getName();
for (String suffix : contentFileSuffixes) {
- if (StringUtils.endsWith(file.getName(), suffix)) {
+ if (StringUtils.endsWith(fileName, suffix)) {
return suffix;
}
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index 609fe58..4ac056a 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -18,9 +18,17 @@
*/
package org.apache.sling.fsprovider.internal;
+import static org.apache.jackrabbit.vault.util.Constants.ROOT_DIR;
+import static org.apache.sling.api.SlingConstants.PROPERTY_PATH;
+import static org.apache.sling.api.SlingConstants.PROPERTY_RESOURCE_TYPE;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_CHANGED;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_REMOVED;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -28,7 +36,7 @@ import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.lang3.StringUtils;
-import org.apache.sling.api.SlingConstants;
+import org.apache.jackrabbit.vault.util.PlatformNameFormat;
import org.apache.sling.fsprovider.internal.mapper.ContentFile;
import org.apache.sling.fsprovider.internal.mapper.FileResource;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
@@ -51,7 +59,7 @@ public final class FileMonitor extends TimerTask {
private final Monitorable root;
private final FsResourceProvider provider;
-
+ private final FsMode fsMode;
private final ContentFileExtensions contentFileExtensions;
private final ContentFileCache contentFileCache;
@@ -60,12 +68,19 @@ public final class FileMonitor extends TimerTask {
* @param provider The resource provider.
* @param interval The interval between executions of the task, in milliseconds.
*/
- public FileMonitor(final FsResourceProvider provider, final long interval,
+ public FileMonitor(final FsResourceProvider provider, final long interval, FsMode fsMode,
final ContentFileExtensions contentFileExtensions, final ContentFileCache contentFileCache) {
this.provider = provider;
+ this.fsMode = fsMode;
this.contentFileExtensions = contentFileExtensions;
this.contentFileCache = contentFileCache;
- this.root = new Monitorable(this.provider.getProviderRoot(), this.provider.getRootFile(), null);
+
+ File rootFile = this.provider.getRootFile();
+ if (fsMode == FsMode.FILEVAULT_XML) {
+ rootFile = new File(this.provider.getRootFile(), ROOT_DIR + PlatformNameFormat.getPlatformPath(this.provider.getProviderRoot()));
+ }
+ this.root = new Monitorable(this.provider.getProviderRoot(), rootFile, null);
+
createStatus(this.root, contentFileExtensions, contentFileCache);
log.debug("Starting file monitor for {} with an interval of {}ms", this.root.file, interval);
timer.schedule(this, 0, interval);
@@ -116,9 +131,9 @@ public final class FileMonitor extends TimerTask {
synchronized ( this ) {
try {
// if we don't have an event admin, we just skip the check
- final EventAdmin localEA = this.provider.getEventAdmin();
- if ( localEA != null ) {
- this.check(this.root, localEA);
+ final EventAdmin reporter = this.provider.getEventAdmin();
+ if ( reporter != null ) {
+ this.check(this.root, reporter);
}
} catch (Exception e) {
// ignore this
@@ -133,22 +148,29 @@ public final class FileMonitor extends TimerTask {
/**
* Check the monitorable
* @param monitorable The monitorable to check
- * @param localEA The event admin
+ * @param reporter The EventAdmin
*/
- private void check(final Monitorable monitorable, final EventAdmin localEA) {
+ private void check(final Monitorable monitorable, final EventAdmin reporter) {
log.trace("Checking {}", monitorable.file);
// if the file is non existing, check if it has been readded
if ( monitorable.status instanceof NonExistingStatus ) {
if ( monitorable.file.exists() ) {
// new file and reset status
createStatus(monitorable, contentFileExtensions, contentFileCache);
- sendEvents(monitorable, SlingConstants.TOPIC_RESOURCE_ADDED, localEA);
+ sendEvents(monitorable, TOPIC_RESOURCE_ADDED, reporter);
+ final FileStatus fs = (FileStatus)monitorable.status;
+ if ( fs instanceof DirStatus ) {
+ final DirStatus ds = (DirStatus)fs;
+ // remove monitorables for new folder and update folder children to send events for directory contents
+ ds.children = new Monitorable[0];
+ checkDirStatusChildren(monitorable, reporter);
+ }
}
} else {
// check if the file has been removed
if ( !monitorable.file.exists() ) {
// removed file and update status
- sendEvents(monitorable, SlingConstants.TOPIC_RESOURCE_REMOVED, localEA);
+ sendEvents(monitorable, TOPIC_RESOURCE_REMOVED, reporter);
monitorable.status = NonExistingStatus.SINGLETON;
contentFileCache.remove(monitorable.path);
} else {
@@ -158,7 +180,7 @@ public final class FileMonitor extends TimerTask {
if ( fs.lastModified < monitorable.file.lastModified() ) {
fs.lastModified = monitorable.file.lastModified();
// changed
- sendEvents(monitorable, SlingConstants.TOPIC_RESOURCE_CHANGED, localEA);
+ sendEvents(monitorable, TOPIC_RESOURCE_CHANGED, reporter);
changed = true;
contentFileCache.remove(monitorable.path);
}
@@ -166,105 +188,122 @@ public final class FileMonitor extends TimerTask {
// directory
final DirStatus ds = (DirStatus)fs;
for(int i=0; i<ds.children.length; i++) {
- check(ds.children[i], localEA);
+ check(ds.children[i], reporter);
}
// if the dir changed we have to update
if ( changed ) {
// and now update
- final File[] files = monitorable.file.listFiles();
- if (files != null) {
- final Monitorable[] children = new Monitorable[files.length];
- for (int i = 0; i < files.length; i++) {
- // search in old list
- for (int m = 0; m < ds.children.length; m++) {
- if (ds.children[m].file.equals(files[i])) {
- children[i] = ds.children[m];
- break;
- }
- }
- if (children[i] == null) {
- children[i] = new Monitorable(monitorable.path + '/' + files[i].getName(), files[i],
- contentFileExtensions.getSuffix(files[i]));
- children[i].status = NonExistingStatus.SINGLETON;
- check(children[i], localEA);
- }
- }
- ds.children = children;
- } else {
- ds.children = new Monitorable[0];
- }
+ checkDirStatusChildren(monitorable, reporter);
}
}
}
}
}
+
+ private void checkDirStatusChildren(final Monitorable dirMonitorable, final EventAdmin reporter) {
+ final DirStatus ds = (DirStatus)dirMonitorable.status;
+ final File[] files = dirMonitorable.file.listFiles();
+ if (files != null) {
+ final Monitorable[] children = new Monitorable[files.length];
+ for (int i = 0; i < files.length; i++) {
+ // search in old list
+ for (int m = 0; m < ds.children.length; m++) {
+ if (ds.children[m].file.equals(files[i])) {
+ children[i] = ds.children[m];
+ break;
+ }
+ }
+ if (children[i] == null) {
+ children[i] = new Monitorable(dirMonitorable.path + '/' + files[i].getName(), files[i],
+ contentFileExtensions.getSuffix(files[i]));
+ children[i].status = NonExistingStatus.SINGLETON;
+ check(children[i], reporter);
+ }
+ }
+ ds.children = children;
+ } else {
+ ds.children = new Monitorable[0];
+ }
+ }
/**
* Send the event async via the event admin.
*/
- private void sendEvents(final Monitorable monitorable, final String topic, final EventAdmin localEA) {
+ private void sendEvents(final Monitorable monitorable, final String changeType, final EventAdmin reporter) {
if (log.isDebugEnabled()) {
- log.debug("Detected change for resource {} : {}", monitorable.path, topic);
+ log.debug("Detected change for resource {} : {}", transformPath(monitorable.path), changeType);
}
- List<ResourceChange> changes = collectResourceChanges(monitorable, topic);
+ List<ResourceChange> changes = collectResourceChanges(monitorable, changeType);
for (ResourceChange change : changes) {
if (log.isTraceEnabled()) {
- log.debug("Send change for resource {}: {}", change.path, change.topic);
+ log.debug("Send change for resource {}: {}", transformPath(change.path), change.topic);
}
- final Dictionary<String, String> properties = new Hashtable<String, String>();
- properties.put(SlingConstants.PROPERTY_PATH, change.path);
+ final Dictionary<String, String> properties = new Hashtable<>();
+ properties.put(PROPERTY_PATH, transformPath(change.path));
if (change.resourceType != null) {
- properties.put(SlingConstants.PROPERTY_RESOURCE_TYPE, change.resourceType);
+ properties.put(PROPERTY_RESOURCE_TYPE, change.resourceType);
}
- localEA.postEvent(new org.osgi.service.event.Event(change.topic, properties));
+ reporter.postEvent(new org.osgi.service.event.Event(change.topic, properties));
}
}
+ /**
+ * Transform path for resource event.
+ * @param path Path
+ * @return Transformed path
+ */
+ private String transformPath(String path) {
+ if (fsMode == FsMode.FILEVAULT_XML) {
+ return PlatformNameFormat.getRepositoryPath(path);
+ }
+ else {
+ return path;
+ }
+ }
+
@SuppressWarnings("unchecked")
- private List<ResourceChange> collectResourceChanges(final Monitorable monitorable, final String topic) {
+ private List<ResourceChange> collectResourceChanges(final Monitorable monitorable, final String changeType) {
List<ResourceChange> changes = new ArrayList<>();
if (monitorable.status instanceof ContentFileStatus) {
ContentFile contentFile = ((ContentFileStatus)monitorable.status).contentFile;
- if (StringUtils.equals(topic, SlingConstants.TOPIC_RESOURCE_CHANGED)) {
+ if (StringUtils.equals(changeType, TOPIC_RESOURCE_CHANGED)) {
Map<String,Object> content = (Map<String,Object>)contentFile.getContent();
// we cannot easily report the diff of resource changes between two content files
// so we simulate a removal of the toplevel node and then add all nodes contained in the current content file again.
- changes.add(buildContentResourceChange(SlingConstants.TOPIC_RESOURCE_REMOVED, content, monitorable.path));
- addContentResourceChanges(changes, SlingConstants.TOPIC_RESOURCE_ADDED, content, monitorable.path);
+ changes.add(buildContentResourceChange(TOPIC_RESOURCE_REMOVED, content, transformPath(monitorable.path)));
+ addContentResourceChanges(changes, TOPIC_RESOURCE_ADDED, content, transformPath(monitorable.path));
}
else {
- addContentResourceChanges(changes, topic, (Map<String,Object>)contentFile.getContent(), monitorable.path);
+ addContentResourceChanges(changes, changeType, (Map<String,Object>)contentFile.getContent(), transformPath(monitorable.path));
}
}
else {
- ResourceChange change = new ResourceChange();
- change.path = monitorable.path;
- change.resourceType = monitorable.status instanceof FileStatus ?
- FileResource.RESOURCE_TYPE_FILE : FileResource.RESOURCE_TYPE_FOLDER;
- change.topic = topic;
- changes.add(change);
+ Map<String,Object> content = new HashMap<>();
+ content.put("sling:resourceType", monitorable.status instanceof FileStatus ?
+ FileResource.RESOURCE_TYPE_FILE : FileResource.RESOURCE_TYPE_FOLDER);
+ changes.add(buildContentResourceChange(changeType, content, transformPath(monitorable.path)));
}
return changes;
}
@SuppressWarnings("unchecked")
- private void addContentResourceChanges(final List<ResourceChange> changes, final String topic,
+ private void addContentResourceChanges(final List<ResourceChange> changes, final String changeType,
final Map<String,Object> content, final String path) {
- changes.add(buildContentResourceChange(topic, content, path));
+ changes.add(buildContentResourceChange(changeType, content, path));
if (content != null) {
for (Map.Entry<String,Object> entry : content.entrySet()) {
if (entry.getValue() instanceof Map) {
String childPath = path + "/" + entry.getKey();
- addContentResourceChanges(changes, topic, (Map<String,Object>)entry.getValue(), childPath);
+ addContentResourceChanges(changes, changeType, (Map<String,Object>)entry.getValue(), childPath);
}
}
}
}
- private ResourceChange buildContentResourceChange(final String topic, final Map<String,Object> content, final String path) {
+ private ResourceChange buildContentResourceChange(final String changeType, final Map<String,Object> content, final String path) {
ResourceChange change = new ResourceChange();
change.path = path;
change.resourceType = content != null ? (String)content.get("sling:resourceType") : null;
- change.topic = topic;
+ change.topic = changeType;
return change;
}
@@ -351,5 +390,5 @@ public final class FileMonitor extends TimerTask {
public String resourceType;
public String topic;
}
-
+
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
new file mode 100644
index 0000000..15af91f
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+/**
+ * Different modes for Filesystem provider support and filesystem layouts.
+ */
+public enum FsMode {
+
+ /**
+ * Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files.
+ */
+ INITIAL_CONTENT,
+
+ /**
+ * Sling-Initial-Content filesystem layout, support only files and folders (classic mode).
+ */
+ INITIAL_CONTENT_FILES_FOLDERS,
+
+ /**
+ * FileVault XML format (expanded content package).
+ */
+ FILEVAULT_XML
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index 12e5bf2..6a9d45f 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.fsprovider.internal;
+import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
+
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
@@ -35,6 +37,7 @@ import org.apache.sling.api.resource.ResourceProvider;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.fsprovider.internal.mapper.ContentFileResourceMapper;
import org.apache.sling.fsprovider.internal.mapper.FileResourceMapper;
+import org.apache.sling.fsprovider.internal.mapper.FileVaultResourceMapper;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
import org.apache.sling.fsprovider.internal.parser.ContentFileTypes;
import org.osgi.framework.BundleContext;
@@ -50,6 +53,7 @@ import org.osgi.service.event.EventAdmin;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.osgi.service.metatype.annotations.Option;
/**
* The <code>FsResourceProvider</code> is a resource provider which maps
@@ -72,6 +76,11 @@ import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@Designate(ocd=FsResourceProvider.Config.class, factory=true)
public final class FsResourceProvider implements ResourceProvider {
+ /**
+ * Resource metadata property set by {@link FsResource} if the underlying file reference is a directory.
+ */
+ public static final String RESOURCE_METADATA_FILE_DIRECTORY = ":org.apache.sling.fsprovider.file.directory";
+
@ObjectClassDefinition(name = "Apache Sling File System Resource Provider",
description = "Configure an instance of the filesystem " +
"resource provider in terms of provider root and filesystem location")
@@ -104,17 +113,25 @@ public final class FsResourceProvider implements ResourceProvider {
"filesystem resources are mapped in. This property must contain at least one non-empty string.")
String[] provider_roots();
- @AttributeDefinition(name = "Mount json",
- description = "Mount .json files as content in the resource hierarchy.")
- boolean provider_json_content();
-
- @AttributeDefinition(name = "Mount jcr.xml",
- description = "Mount .jcr.xml files as content in the resource hierarchy.")
- boolean provider_jcrxml_content();
+ @AttributeDefinition(name = "Filesystem layout",
+ description = "Filesystem layout mode for files, folders and content.",
+ options={
+ @Option(value="INITIAL_CONTENT", label="INITIAL_CONTENT - "
+ + "Sling-Initial-Content filesystem layout, with full support for JSON and jcr.xml content files."),
+ @Option(value="INITIAL_CONTENT_FILES_FOLDERS", label="INITIAL_CONTENT_FILES_FOLDERS - "
+ + "Sling-Initial-Content filesystem layout, support only files and folders (classic mode)."),
+ @Option(value="FILEVAULT_XML", label="FILEVAULT_XML - "
+ + "FileVault XML format (expanded content package)."),
+ })
+ FsMode provider_fs_mode() default FsMode.INITIAL_CONTENT;
+
+ @AttributeDefinition(name = "Init. Content Options",
+ description = "Import options for Sling-Initial-Content filesystem layout. Supported options: overwrite, ignoreImportProviders.")
+ String provider_initial_content_import_options();
@AttributeDefinition(name = "Cache Size",
description = "Max. number of content files cached in memory.")
- int provider_cache_size() default 1000;
+ int provider_cache_size() default 10000;
/**
* Internal Name hint for web console.
@@ -132,8 +149,10 @@ public final class FsResourceProvider implements ResourceProvider {
private FileMonitor monitor;
// maps filesystem to resources
+ private FsMode fsMode;
private FsResourceMapper fileMapper;
private FsResourceMapper contentFileMapper;
+ private FileVaultResourceMapper fileVaultMapper;
// cache for parsed content files
private ContentFileCache contentFileCache;
@@ -155,34 +174,56 @@ public final class FsResourceProvider implements ResourceProvider {
* to access the file or folder. If no such file or folder exists, this
* method returns <code>null</code>.
*/
+ @SuppressWarnings("rawtypes")
@Override
public Resource getResource(ResourceResolver resolver, String path) {
- Resource rsrc = contentFileMapper.getResource(resolver, path);
- if (rsrc == null) {
- rsrc = fileMapper.getResource(resolver, path);
+
+ Resource rsrc = null;
+
+ if (fsMode == FsMode.FILEVAULT_XML) {
+ // filevault: check if path matches, if not fallback to parent resource provider
+ if (fileVaultMapper.pathMatches(path)) {
+ rsrc = fileVaultMapper.getResource(resolver, path);
+ }
+ }
+ else {
+ // Sling-Initial-Content: mount folder/files an content files
+ rsrc = contentFileMapper.getResource(resolver, path);
+ if (rsrc == null) {
+ rsrc = fileMapper.getResource(resolver, path);
+ }
}
+
return rsrc;
}
-
+
/**
* Returns an iterator of resources.
*/
@SuppressWarnings("unchecked")
- @Override
public Iterator<Resource> listChildren(Resource parent) {
ResourceResolver resolver = parent.getResourceResolver();
List<Iterator<Resource>> allChildren = new ArrayList<>();
Iterator<Resource> children;
- children = contentFileMapper.getChildren(resolver, parent);
- if (children != null) {
- allChildren.add(children);
+ if (fsMode == FsMode.FILEVAULT_XML) {
+ // filevault: always ask provider, it checks itself if children matches the filters
+ children = fileVaultMapper.getChildren(resolver, parent);
+ if (children != null) {
+ allChildren.add(children);
+ }
}
-
- children = fileMapper.getChildren(resolver, parent);
- if (children != null) {
- allChildren.add(children);
+ else {
+ // Sling-Initial-Content: get all matchind folders/files and content files
+ children = contentFileMapper.getChildren(resolver, parent);
+ if (children != null) {
+ allChildren.add(children);
+ }
+ children = fileMapper.getChildren(resolver, parent);
+ if (children != null) {
+ allChildren.add(children);
+ }
}
if (allChildren.isEmpty()) {
@@ -207,6 +248,7 @@ public final class FsResourceProvider implements ResourceProvider {
// ---------- SCR Integration
@Activate
protected void activate(BundleContext bundleContext, final Config config) {
+ fsMode = config.provider_fs_mode();
String[] providerRoots = config.provider_roots();
if (providerRoots == null || providerRoots.length != 1 || StringUtils.isBlank(providerRoots[0])) {
throw new IllegalArgumentException("provider.roots property must be set to exactly one entry.");
@@ -214,30 +256,42 @@ public final class FsResourceProvider implements ResourceProvider {
String providerRoot = config.provider_roots()[0];
String providerFileName = config.provider_file();
- if (providerFileName == null || providerFileName.length() == 0) {
+ if (StringUtils.isBlank(providerFileName)) {
throw new IllegalArgumentException("provider.file property must be set");
}
this.providerRoot = providerRoot;
this.providerFile = getProviderFile(providerFileName, bundleContext);
+ InitialContentImportOptions options = new InitialContentImportOptions(config.provider_initial_content_import_options());
+
List<String> contentFileSuffixes = new ArrayList<>();
- if (config.provider_json_content()) {
- contentFileSuffixes.add(ContentFileTypes.JSON_SUFFIX);
+ if (fsMode == FsMode.FILEVAULT_XML) {
+ contentFileSuffixes.add("/" + DOT_CONTENT_XML);
}
- if (config.provider_jcrxml_content()) {
- contentFileSuffixes.add(ContentFileTypes.JCR_XML_SUFFIX);
+ else if (fsMode == FsMode.INITIAL_CONTENT) {
+ if (!options.getIgnoreImportProviders().contains("json")) {
+ contentFileSuffixes.add(ContentFileTypes.JSON_SUFFIX);
+ }
+ if (!options.getIgnoreImportProviders().contains("jcr.xml")) {
+ contentFileSuffixes.add(ContentFileTypes.JCR_XML_SUFFIX);
+ }
}
ContentFileExtensions contentFileExtensions = new ContentFileExtensions(contentFileSuffixes);
this.contentFileCache = new ContentFileCache(config.provider_cache_size());
- this.fileMapper = new FileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions);
- this.contentFileMapper = new ContentFileResourceMapper(this.providerRoot, this.providerFile,
- contentFileExtensions, this.contentFileCache);
+ if (fsMode == FsMode.FILEVAULT_XML) {
+ this.fileVaultMapper = new FileVaultResourceMapper(this.providerFile, this.contentFileCache);
+ }
+ else {
+ this.fileMapper = new FileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions);
+ this.contentFileMapper = new ContentFileResourceMapper(this.providerRoot, this.providerFile,
+ contentFileExtensions, this.contentFileCache);
+ }
// start background monitor if check interval is higher than 100
- if ( config.provider_checkinterval() > 100 ) {
- this.monitor = new FileMonitor(this, config.provider_checkinterval(),
+ if (config.provider_checkinterval() > 100) {
+ this.monitor = new FileMonitor(this, config.provider_checkinterval(), fsMode,
contentFileExtensions, this.contentFileCache);
}
}
@@ -252,10 +306,12 @@ public final class FsResourceProvider implements ResourceProvider {
this.providerFile = null;
this.fileMapper = null;
this.contentFileMapper = null;
+ this.fileVaultMapper = null;
if (this.contentFileCache != null) {
this.contentFileCache.clear();
this.contentFileCache = null;
}
+ this.fsMode = null;
}
EventAdmin getEventAdmin() {
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
new file mode 100644
index 0000000..5353d0f
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+
+class InitialContentImportOptions {
+
+ /**
+ * The overwrite directive specifying if content should be overwritten or
+ * just initially added.
+ */
+ private static final String OVERWRITE_DIRECTIVE = "overwrite";
+
+ /**
+ * The ignore content readers directive specifying whether the available ContentReaders
+ * should be used during content loading.
+ */
+ private static final String IGNORE_CONTENT_READERS_DIRECTIVE = "ignoreImportProviders";
+
+
+ private final boolean overwrite;
+ private final Set<String> ignoreImportProviders;
+
+ public InitialContentImportOptions(String optionsString) {
+ Map<String,String> options = parseOptions(optionsString);
+ overwrite = BooleanUtils.toBoolean(options.get(OVERWRITE_DIRECTIVE));
+ ignoreImportProviders = new HashSet<>(Arrays.asList(StringUtils.split(StringUtils.defaultString(options.get(IGNORE_CONTENT_READERS_DIRECTIVE)))));
+ }
+
+ private static Map<String,String> parseOptions(String optionsString) {
+ Map<String,String> options = new HashMap<>();
+ String[] optionsList = StringUtils.split(optionsString, ";");
+ if (optionsList != null) {
+ for (String keyValueString : optionsList) {
+ String[] keyValue = StringUtils.splitByWholeSeparator(keyValueString, ":=");
+ if (keyValue.length == 2) {
+ options.put(StringUtils.trim(keyValue[0]), StringUtils.trim(keyValue[1]));
+ }
+ }
+ }
+ return options;
+ }
+
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+
+ public Set<String> getIgnoreImportProviders() {
+ return ignoreImportProviders;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
index d31a851..27e09d5 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
@@ -19,8 +19,11 @@
package org.apache.sling.fsprovider.internal.mapper;
import java.io.File;
+import java.util.Iterator;
import java.util.Map;
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Predicate;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
@@ -51,19 +54,6 @@ public final class ContentFile {
}
/**
- * @param file File with content fragment
- * @param path Root path of the content file
- * @param subPath Relative path addressing content fragment inside file
- * @param contentFileCache Content file cache
- * @param content Content
- */
- public ContentFile(File file, String path, String subPath, ContentFileCache contentFileCache, Object content) {
- this(file, path, subPath, contentFileCache);
- this.contentInitialized = true;
- this.content = content;
- }
-
- /**
* @return File with content fragment
*/
public File getFile() {
@@ -129,14 +119,47 @@ public final class ContentFile {
}
/**
+ * @return Child maps.
+ */
+ @SuppressWarnings("unchecked")
+ public Iterator<Map.Entry<String,Map<String,Object>>> getChildren() {
+ if (!isResource()) {
+ return IteratorUtils.emptyIterator();
+ }
+ return IteratorUtils.filteredIterator(((Map)getContent()).entrySet().iterator(), new Predicate() {
+ @Override
+ public boolean evaluate(Object object) {
+ Map.Entry<String,Object> entry = (Map.Entry<String,Object>)object;
+ return entry.getValue() instanceof Map;
+ }
+ });
+ }
+
+ /**
* Navigate to another sub path position in content file.
- * @param newSubPath New sub path
+ * @param newSubPath New sub path related to root path of content file
* @return Content file
*/
- public ContentFile navigateTo(String newSubPath) {
+ public ContentFile navigateToAbsolute(String newSubPath) {
return new ContentFile(file, path, newSubPath, contentFileCache);
}
+ /**
+ * Navigate to another sub path position in content file.
+ * @param newSubPath New sub path relative to current sub path in content file
+ * @return Content file
+ */
+ public ContentFile navigateToRelative(String newSubPath) {
+ String absoluteSubPath;
+ if (newSubPath == null) {
+ absoluteSubPath = this.subPath;
+ }
+ else {
+ absoluteSubPath = (this.subPath != null ? this.subPath + "/" : "") + newSubPath;
+ }
+ return new ContentFile(file, path, absoluteSubPath, contentFileCache);
+ }
+
@SuppressWarnings("unchecked")
private static Object getDeepContent(Object object, String subPath) {
if (object == null) {
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
index e6edd04..09b6ffe 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
@@ -106,18 +106,10 @@ public final class ContentFileResourceMapper implements FsResourceMapper {
// get child resources from content fragments in content file
List<ContentFile> children = new ArrayList<>();
if (parentContentFile.hasContent() && parentContentFile.isResource()) {
- Map<String,Object> content = (Map<String,Object>)parentContentFile.getContent();
- for (Map.Entry<String, Object> entry: content.entrySet()) {
- if (entry.getValue() instanceof Map) {
- String subPath;
- if (parentContentFile.getSubPath() == null) {
- subPath = entry.getKey();
- }
- else {
- subPath = parentContentFile.getSubPath() + "/" + entry.getKey();
- }
- children.add(new ContentFile(parentContentFile.getFile(), parentContentFile.getPath(), subPath, contentFileCache, entry.getValue()));
- }
+ Iterator<Map.Entry<String,Map<String,Object>>> childMaps = parentContentFile.getChildren();
+ while (childMaps.hasNext()) {
+ Map.Entry<String,Map<String,Object>> entry = childMaps.next();
+ children.add(parentContentFile.navigateToRelative(entry.getKey()));
}
}
if (children.isEmpty()) {
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
new file mode 100644
index 0000000..88e001e
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
+import static org.apache.jackrabbit.vault.util.Constants.FILTER_XML;
+import static org.apache.jackrabbit.vault.util.Constants.META_DIR;
+import static org.apache.jackrabbit.vault.util.Constants.ROOT_DIR;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.util.PlatformNameFormat;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.fsprovider.internal.FsResourceMapper;
+import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class FileVaultResourceMapper implements FsResourceMapper {
+
+ private static final String DOT_CONTENT_XML_SUFFIX = "/" + DOT_CONTENT_XML;
+ private static final String DOT_DIR_SUFFIX = "/.dir";
+
+ private final File providerFile;
+ private final ContentFileCache contentFileCache;
+ private final WorkspaceFilter workspaceFilter;
+
+ private static final Logger log = LoggerFactory.getLogger(FileVaultResourceMapper.class);
+
+ public FileVaultResourceMapper(File providerFile, ContentFileCache contentFileCache) {
+ this.providerFile = providerFile;
+ this.contentFileCache = contentFileCache;
+ this.workspaceFilter = getWorkspaceFilter();
+ }
+
+ @Override
+ public Resource getResource(final ResourceResolver resolver, final String resourcePath) {
+
+ // direct file
+ File file = getFile(resourcePath);
+ if (file != null && file.isFile()) {
+ return new FileResource(resolver, resourcePath, file);
+ }
+
+ // content file
+ ContentFile contentFile = getContentFile(resourcePath, null);
+ if (contentFile != null) {
+ return new ContentFileResource(resolver, contentFile);
+ }
+
+ // fallback to directory resource if folder was found but nothing else
+ if (file != null && file.isDirectory()) {
+ return new FileResource(resolver, resourcePath, file);
+ }
+
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
+ String parentPath = parent.getPath();
+
+ Set<String> childPaths = new LinkedHashSet<>();
+
+ // get children from content resource of parent
+ ContentFile parentContentFile = getContentFile(parentPath, null);
+ if (parentContentFile != null) {
+ Iterator<Map.Entry<String,Map<String,Object>>> childMaps = parentContentFile.getChildren();
+ while (childMaps.hasNext()) {
+ Map.Entry<String,Map<String,Object>> entry = childMaps.next();
+ String childPath = parentPath + "/" + entry.getKey();
+ if (pathMatches(childPath)) {
+ childPaths.add(childPath);
+ }
+ }
+ }
+
+ // additional check for children in filesystem
+ File parentFile = getFile(parentPath);
+ if (parentFile != null && parentFile.isDirectory()) {
+ for (File childFile : parentFile.listFiles()) {
+ String childPath = parentPath + "/" + PlatformNameFormat.getRepositoryName(childFile.getName());
+ if (pathMatches(childPath) && !childPaths.contains(childPath)) {
+ childPaths.add(childPath);
+ }
+ }
+ }
+
+ if (childPaths.isEmpty()) {
+ return null;
+ }
+ else {
+ return IteratorUtils.transformedIterator(childPaths.iterator(), new Transformer() {
+ @Override
+ public Object transform(Object input) {
+ String path = (String)input;
+ return getResource(resolver, path);
+ }
+ });
+ }
+ }
+
+ /**
+ * @return Workspace filter or null if none found.
+ */
+ private WorkspaceFilter getWorkspaceFilter() {
+ File filter = new File(providerFile, META_DIR + "/" + FILTER_XML);
+ if (filter.exists()) {
+ try {
+ DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
+ workspaceFilter.load(filter);
+ return workspaceFilter;
+ } catch (IOException | ConfigurationException ex) {
+ log.error("Unable to parse workspace filter: " + filter.getPath(), ex);
+ }
+ }
+ else {
+ log.warn("Workspace filter not found: " + filter.getPath());
+ }
+ return null;
+ }
+
+ /**
+ * Checks if the given path matches the workspace filter.
+ * @param path Path
+ * @return true if path matches
+ */
+ public boolean pathMatches(String path) {
+ // ignore .dir folder
+ if (StringUtils.endsWith(path, DOT_DIR_SUFFIX) || StringUtils.endsWith(path, DOT_CONTENT_XML_SUFFIX)) {
+ return false;
+ }
+ if (workspaceFilter == null) {
+ return false;
+ }
+ else {
+ return workspaceFilter.contains(path);
+ }
+ }
+
+ private File getFile(String path) {
+ if (StringUtils.endsWith(path, DOT_CONTENT_XML_SUFFIX)) {
+ return null;
+ }
+ File file = new File(providerFile, ROOT_DIR + PlatformNameFormat.getPlatformPath(path));
+ if (file.exists()) {
+ return file;
+ }
+ return null;
+ }
+
+ private ContentFile getContentFile(String path, String subPath) {
+ File file = new File(providerFile, ROOT_DIR + PlatformNameFormat.getPlatformPath(path) + DOT_CONTENT_XML_SUFFIX);
+ if (file.exists()) {
+ ContentFile contentFile = new ContentFile(file, path, subPath, contentFileCache);
+ if (contentFile.hasContent()) {
+ return contentFile;
+ }
+ }
+
+ // try to find in parent path which contains content fragment
+ String parentPath = ResourceUtil.getParent(path);
+ if (parentPath == null) {
+ return null;
+ }
+ String nextSubPath = path.substring(parentPath.length() + 1)
+ + (subPath != null ? "/" + subPath : "");
+ return getContentFile(parentPath, nextSubPath);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java
index 6f52691..23abe66 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java
@@ -110,22 +110,22 @@ public final class FsNode extends FsItem implements Node {
else {
subPath = path.substring(contentFile.getPath().length() + 1);
}
- ContentFile referencedFile = contentFile.navigateTo(subPath);
+ ContentFile referencedFile = contentFile.navigateToAbsolute(subPath);
if (referencedFile.hasContent()) {
return new FsNode(referencedFile, resolver);
}
}
- else {
- // node is outside content file
- Node refNode = null;
- Resource resource = resolver.getResource(path);
- if (resource != null) {
- refNode = resource.adaptTo(Node.class);
- if (refNode != null) {
- return refNode;
- }
+
+ // check if node is outside content file
+ Node refNode = null;
+ Resource resource = resolver.getResource(path);
+ if (resource != null) {
+ refNode = resource.adaptTo(Node.class);
+ if (refNode != null) {
+ return refNode;
}
}
+
throw new PathNotFoundException(relPath);
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
index f03b0a7..09db7d4 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
@@ -63,14 +63,7 @@ class FsNodeIterator implements NodeIterator {
@Override
public Node nextNode() {
Map.Entry<String,Map<String,Object>> nextEntry = children.next();
- String subPath;
- if (contentFile.getSubPath() == null) {
- subPath = nextEntry.getKey();
- }
- else {
- subPath = contentFile.getSubPath() + "/" + nextEntry.getKey();
- }
- return new FsNode(contentFile.navigateTo(subPath), resolver);
+ return new FsNode(contentFile.navigateToRelative(nextEntry.getKey()), resolver);
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
index 4b46157..6ac72c5 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.fsprovider.internal.parser;
+import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JCR_XML_SUFFIX;
import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JSON_SUFFIX;
@@ -62,11 +63,14 @@ class ContentFileParserUtil {
* @return Content or null if content could not be parsed.
*/
public static Map<String,Object> parse(File file) {
+ if (!file.exists()) {
+ return null;
+ }
try {
if (StringUtils.endsWith(file.getName(), JSON_SUFFIX)) {
return JSON_PARSER.parse(file);
}
- else if (StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
+ else if (StringUtils.equals(file.getName(), DOT_CONTENT_XML) || StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
return JCR_XML_PARSER.parse(file);
}
}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
index 5341ced..a9c842b 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
@@ -18,35 +18,39 @@
*/
package org.apache.sling.fsprovider.internal;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_CHANGED;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_REMOVED;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertChange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.nio.file.Files;
-import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.sling.api.SlingConstants;
import org.apache.sling.fsprovider.internal.FileMonitor.ResourceChange;
+import org.apache.sling.fsprovider.internal.TestUtils.ResourceListener;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.junit.SlingContext;
import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
import org.apache.sling.testing.mock.sling.junit.SlingContextCallback;
import org.junit.Rule;
import org.junit.Test;
-import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
/**
- * Test events when changing filesystem content.
+ * Test events when changing filesystem content (Sling-Initial-Content).
*/
public class FileMonitorTest {
+ private static final int CHECK_INTERVAL = 120;
+ private static final int WAIT_INTERVAL = 250;
+
private final File tempDir;
- private final EventAdminListener eventListener = new EventAdminListener();
+ private final ResourceListener resourceListener = new ResourceListener();
public FileMonitorTest() throws Exception {
tempDir = Files.createTempDirectory(getClass().getName()).toFile();
@@ -66,15 +70,16 @@ public class FileMonitorTest {
context.registerInjectActivateService(new FsResourceProvider(),
"provider.file", tempDir.getPath(),
"provider.roots", "/fs-test",
- "provider.checkinterval", 120,
- "provider.json.content", true);
+ "provider.checkinterval", CHECK_INTERVAL,
+ "provider.fs.mode", FsMode.INITIAL_CONTENT.name(),
+ "provider.initial.content.import.options", "overwrite:=true;ignoreImportProviders:=jcr.xml");
// register resource change listener
- context.registerService(EventHandler.class, eventListener,
+ context.registerService(EventHandler.class, resourceListener,
EventConstants.EVENT_TOPIC, new String[] {
- SlingConstants.TOPIC_RESOURCE_ADDED,
- SlingConstants.TOPIC_RESOURCE_CHANGED,
- SlingConstants.TOPIC_RESOURCE_REMOVED
+ TOPIC_RESOURCE_ADDED,
+ TOPIC_RESOURCE_CHANGED,
+ TOPIC_RESOURCE_REMOVED
});
}
})
@@ -89,150 +94,122 @@ public class FileMonitorTest {
@Test
public void testUpdateFile() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1a = new File(tempDir, "folder1/file1a.txt");
FileUtils.touch(file1a);
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(1, changes.size());
- assertChange(changes, "/fs-test/folder1/file1a.txt", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1a.txt", TOPIC_RESOURCE_CHANGED);
}
@Test
public void testAddFile() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1c = new File(tempDir, "folder1/file1c.txt");
FileUtils.write(file1c, "newcontent");
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
- assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_CHANGED);
- assertChange(changes, "/fs-test/folder1/file1c.txt", SlingConstants.TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder1", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1c.txt", TOPIC_RESOURCE_ADDED);
}
@Test
public void testRemoveFile() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1a = new File(tempDir, "folder1/file1a.txt");
file1a.delete();
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
- assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_CHANGED);
- assertChange(changes, "/fs-test/folder1/file1a.txt", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ assertChange(changes, "/fs-test/folder1", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1a.txt", TOPIC_RESOURCE_REMOVED);
}
@Test
public void testAddFolder() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File folder99 = new File(tempDir, "folder99");
folder99.mkdir();
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
- assertChange(changes, "/fs-test", SlingConstants.TOPIC_RESOURCE_CHANGED);
- assertChange(changes, "/fs-test/folder99", SlingConstants.TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder99", TOPIC_RESOURCE_ADDED);
}
@Test
public void testRemoveFolder() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File folder1 = new File(tempDir, "folder1");
FileUtils.deleteDirectory(folder1);
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
- assertChange(changes, "/fs-test", SlingConstants.TOPIC_RESOURCE_CHANGED);
- assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ assertChange(changes, "/fs-test", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1", TOPIC_RESOURCE_REMOVED);
}
@Test
- public void testUpdateJsonContent() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ public void testUpdateContent() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1a = new File(tempDir, "folder2/content.json");
FileUtils.touch(file1a);
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
- assertTrue(changes.size() > 1);
- assertChange(changes, "/fs-test/folder2/content", SlingConstants.TOPIC_RESOURCE_REMOVED);
- assertChange(changes, "/fs-test/folder2/content", SlingConstants.TOPIC_RESOURCE_ADDED);
- assertChange(changes, "/fs-test/folder2/content/jcr:content", SlingConstants.TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder2/content", TOPIC_RESOURCE_REMOVED);
+ assertChange(changes, "/fs-test/folder2/content", TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder2/content/jcr:content", TOPIC_RESOURCE_ADDED);
}
@Test
- public void testAddJsonContent() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ public void testAddContent() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1c = new File(tempDir, "folder1/file1c.json");
FileUtils.write(file1c, "{\"prop1\":\"value1\",\"child1\":{\"prop2\":\"value1\"}}");
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(3, changes.size());
- assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_CHANGED);
- assertChange(changes, "/fs-test/folder1/file1c", SlingConstants.TOPIC_RESOURCE_ADDED);
- assertChange(changes, "/fs-test/folder1/file1c/child1", SlingConstants.TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder1", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1c", TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder1/file1c/child1", TOPIC_RESOURCE_ADDED);
}
@Test
- public void testRemoveJsonContent() throws Exception {
- List<ResourceChange> changes = eventListener.getChanges();
+ public void testRemoveContent() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1a = new File(tempDir, "folder2/content.json");
file1a.delete();
- Thread.sleep(250);
+ Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
- assertChange(changes, "/fs-test/folder2", SlingConstants.TOPIC_RESOURCE_CHANGED);
- assertChange(changes, "/fs-test/folder2/content", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ assertChange(changes, "/fs-test/folder2", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder2/content", TOPIC_RESOURCE_REMOVED);
}
-
- private void assertChange(List<ResourceChange> changes, String path, String topic) {
- boolean found = false;
- for (ResourceChange change : changes) {
- if (StringUtils.equals(change.path, path) && StringUtils.equals(change.topic, topic)) {
- found = true;
- break;
- }
- }
- assertTrue("Change with path=" + path + ", topic=" + topic, found);
- }
-
- static class EventAdminListener implements EventHandler {
- private final List<ResourceChange> allChanges = new ArrayList<>();
- public List<ResourceChange> getChanges() {
- return allChanges;
- }
- @Override
- public void handleEvent(Event event) {
- ResourceChange change = new ResourceChange();
- change.path = (String)event.getProperty(SlingConstants.PROPERTY_PATH);
- change.resourceType = (String)event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);
- change.topic = event.getTopic();
- allChanges.add(change);
- }
- }
-
}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
new file mode 100644
index 0000000..b6dda6a
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
+import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Test access FileFault XML files, folders and content.
+ */
+public class FileVaultContentTest {
+
+ private Resource damAsset;
+ private Resource sampleContent;
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode", FsMode.FILEVAULT_XML.name(),
+ "provider.file", "src/test/resources/vaultfs-test",
+ "provider.roots", "/content/dam/talk.png"
+ ))
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode", FsMode.FILEVAULT_XML.name(),
+ "provider.file", "src/test/resources/vaultfs-test",
+ "provider.roots", "/content/samples"
+ ))
+ .build();
+
+ @Before
+ public void setUp() {
+ damAsset = context.resourceResolver().getResource("/content/dam/talk.png");
+ sampleContent = context.resourceResolver().getResource("/content/samples");
+ }
+
+ @Test
+ public void testDamAsset() {
+ assertNotNull(damAsset);
+ assertEquals("app:Asset", damAsset.getResourceType());
+
+ Resource content = damAsset.getChild("jcr:content");
+ assertNotNull(content);
+ assertEquals("app:AssetContent", content.getResourceType());
+
+ Resource metadata = content.getChild("metadata");
+ assertNotNull(metadata);
+ ValueMap props = ResourceUtil.getValueMap(metadata);
+ assertEquals((Integer)4, props.get("app:Bitsperpixel", Integer.class));
+
+ assertFolder(content, "renditions");
+ assertFile(content, "renditions/original", null);
+ assertFile(content, "renditions/web.1280.1280.png", null);
+ }
+
+ @Test
+ public void testSampleContent() {
+ assertNotNull(sampleContent);
+ assertEquals("sling:OrderedFolder", sampleContent.getResourceType());
+
+ Resource enContent = sampleContent.getChild("en/jcr:content");
+ assertArrayEquals(new String[] { "/etc/mobile/groups/responsive" }, ResourceUtil.getValueMap(enContent).get("app:deviceGroups", String[].class));
+ }
+
+ @Test
+ public void testListChildren() {
+ Resource en = sampleContent.getChild("en");
+ List<Resource> children = ImmutableList.copyOf(en.listChildren());
+ assertEquals(2, children.size());
+
+ Resource child1 = children.get(0);
+ assertEquals("jcr:content", child1.getName());
+ assertEquals("samples/sample-app/components/content/page/homepage", child1.getResourceType());
+
+ Resource child2 = children.get(1);
+ assertEquals("tools", child2.getName());
+ assertEquals("app:Page", child2.getResourceType());
+
+ // child3 (conference) is hidden because of filter
+ }
+
+ @Test
+ public void testJcrMixedContent() throws RepositoryException {
+ // prepare mixed JCR content
+ Node root = context.resourceResolver().adaptTo(Session.class).getNode("/");
+ Node content = root.addNode("content", "nt:folder");
+ Node samples = content.addNode("samples", "nt:folder");
+ Node en = samples.addNode("en", "nt:folder");
+ Node conference = en.addNode("conference", "nt:folder");
+ conference.addNode("page2", "nt:folder");
+ samples.addNode("it", "nt:folder");
+
+ // pass-through because of filter
+ assertNotNull(context.resourceResolver().getResource("/content/samples/en/conference"));
+ assertNotNull(sampleContent.getChild("en/conference"));
+ assertNotNull(context.resourceResolver().getResource("/content/samples/en/conference/page2"));
+ assertNotNull(sampleContent.getChild("en/conference/page2"));
+
+ // list children with mixed content
+ Resource enResource = sampleContent.getChild("en");
+ assertThat(enResource, ResourceMatchers.containsChildren("jcr:content", "tools", "conference"));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
new file mode 100644
index 0000000..7219033
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_CHANGED;
+import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_REMOVED;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertChange;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.sling.fsprovider.internal.FileMonitor.ResourceChange;
+import org.apache.sling.fsprovider.internal.TestUtils.ResourceListener;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.apache.sling.testing.mock.sling.junit.SlingContextCallback;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * Test events when changing filesystem content (FileVault XML).
+ */
+public class FileVaultFileMonitorTest {
+
+ private static final int CHECK_INTERVAL = 120;
+ private static final int WAIT_INTERVAL = 250;
+
+ private final File tempDir;
+ private final ResourceListener resourceListener = new ResourceListener();
+
+ public FileVaultFileMonitorTest() throws Exception {
+ tempDir = Files.createTempDirectory(getClass().getName()).toFile();
+ }
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .beforeSetUp(new SlingContextCallback() {
+ @Override
+ public void execute(SlingContext context) throws Exception {
+ // copy test content to temp. directory
+ tempDir.mkdirs();
+ File sourceDir = new File("src/test/resources/vaultfs-test");
+ FileUtils.copyDirectory(sourceDir, tempDir);
+
+ // mount temp. directory
+ context.registerInjectActivateService(new FsResourceProvider(),
+ "provider.file", tempDir.getPath(),
+ "provider.roots", "/content/dam/talk.png",
+ "provider.checkinterval", CHECK_INTERVAL,
+ "provider.fs.mode", FsMode.FILEVAULT_XML.name());
+ context.registerInjectActivateService(new FsResourceProvider(),
+ "provider.file", tempDir.getPath(),
+ "provider.roots", "/content/samples",
+ "provider.checkinterval", CHECK_INTERVAL,
+ "provider.fs.mode", FsMode.FILEVAULT_XML.name());
+
+ // register resource change listener
+ context.registerService(EventHandler.class, resourceListener,
+ EventConstants.EVENT_TOPIC, new String[] {
+ TOPIC_RESOURCE_ADDED,
+ TOPIC_RESOURCE_CHANGED,
+ TOPIC_RESOURCE_REMOVED
+ });
+ }
+ })
+ .afterTearDown(new SlingContextCallback() {
+ @Override
+ public void execute(SlingContext context) throws Exception {
+ // remove temp directory
+ tempDir.delete();
+ }
+ })
+ .build();
+
+ @Test
+ public void testUpdateFile() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/renditions/web.1280.1280.png");
+ FileUtils.touch(file);
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(1, changes.size());
+ assertChange(changes, "/content/dam/talk.png/jcr:content/renditions/web.1280.1280.png", TOPIC_RESOURCE_CHANGED);
+ }
+
+ @Test
+ public void testAddFile() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/renditions/text.txt");
+ FileUtils.write(file, "newcontent");
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/content/dam/talk.png/jcr:content/renditions", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/content/dam/talk.png/jcr:content/renditions/text.txt", TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testRemoveFile() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/renditions/web.1280.1280.png");
+ file.delete();
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/content/dam/talk.png/jcr:content/renditions", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/content/dam/talk.png/jcr:content/renditions/web.1280.1280.png", TOPIC_RESOURCE_REMOVED);
+ }
+
+ @Test
+ public void testAddFolder() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File folder = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/newfolder");
+ folder.mkdir();
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/content/dam/talk.png/jcr:content", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/content/dam/talk.png/jcr:content/newfolder", TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testRemoveFolder() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File folder = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/renditions");
+ FileUtils.deleteDirectory(folder);
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/content/dam/talk.png/jcr:content", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/content/dam/talk.png/jcr:content/renditions", TOPIC_RESOURCE_REMOVED);
+ }
+
+ @Test
+ public void testUpdateContent() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/samples/en/.content.xml");
+ FileUtils.touch(file);
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertChange(changes, "/content/samples/en", TOPIC_RESOURCE_REMOVED);
+ assertChange(changes, "/content/samples/en", TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/content/samples/en/jcr:content", TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testAddContent() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/samples/fr/.content.xml");
+ file.getParentFile().mkdir();
+ FileUtils.write(file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ + "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:app=\"http://sample.com/jcr/app/1.0\" "
+ + "xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" jcr:primaryType=\"app:Page\">\n"
+ + "<jcr:content jcr:primaryType=\"app:PageContent\"/>\n"
+ + "</jcr:root>");
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertChange(changes, "/content/samples", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/content/samples/fr", TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/content/samples/fr/jcr:content", TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testRemoveContent() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/samples/en");
+ FileUtils.deleteDirectory(file);
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/content/samples", TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/content/samples/en", TOPIC_RESOURCE_REMOVED);
+ }
+
+ @Test
+ public void testRemoveContentDotXmlOnly() throws Exception {
+ List<ResourceChange> changes = resourceListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file = new File(tempDir, "jcr_root/content/samples/en/.content.xml");
+ file.delete();
+
+ Thread.sleep(WAIT_INTERVAL);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/content/samples/en", TOPIC_RESOURCE_CHANGED);
+ // this second event is not fully correct, but this is a quite special case, accept it for now
+ assertChange(changes, "/content/samples/en", TOPIC_RESOURCE_REMOVED);
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
new file mode 100644
index 0000000..513c51f
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+public class InitialContentImportOptionsTest {
+
+ @Test
+ public void testNull() {
+ InitialContentImportOptions underTest = new InitialContentImportOptions(null);
+ assertFalse(underTest.isOverwrite());
+ assertTrue(underTest.getIgnoreImportProviders().isEmpty());
+ }
+
+ @Test
+ public void testBlank() {
+ InitialContentImportOptions underTest = new InitialContentImportOptions(" ");
+ assertFalse(underTest.isOverwrite());
+ assertTrue(underTest.getIgnoreImportProviders().isEmpty());
+ }
+
+ @Test
+ public void testOptions1() {
+ InitialContentImportOptions underTest = new InitialContentImportOptions("overwrite:=true;ignoreImportProviders:=xml,json");
+ assertTrue(underTest.isOverwrite());
+ assertEquals(ImmutableSet.of("xml,json"), underTest.getIgnoreImportProviders());
+ }
+
+ @Test
+ public void testOptions2() {
+ InitialContentImportOptions underTest = new InitialContentImportOptions(" overwrite := false ; ignoreImportProviders := xml ");
+ assertFalse(underTest.isOverwrite());
+ assertEquals(ImmutableSet.of("xml"), underTest.getIgnoreImportProviders());
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
index d928205..2a677ba 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
@@ -57,7 +57,10 @@ public class JcrXmlContentTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .plugin(new RegisterFsResourcePlugin("provider.jcrxml.content", true))
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode", FsMode.INITIAL_CONTENT.name(),
+ "provider.initial.content.import.options", "overwrite:=true;ignoreImportProviders:=json"
+ ))
.build();
@Before
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 04a9418..5ea4ea5 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -58,7 +58,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/**
- * Test access to files and folders from filesystem.
+ * Test access to files and folders and JSON content from filesystem.
*/
public class JsonContentTest {
@@ -67,7 +67,10 @@ public class JsonContentTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .plugin(new RegisterFsResourcePlugin("provider.json.content", true))
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode", FsMode.INITIAL_CONTENT.name(),
+ "provider.initial.content.import.options", "overwrite:=true;ignoreImportProviders:=jcr.xml"
+ ))
.build();
@Before
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
index 4d62076..0d12a06 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
@@ -28,17 +28,23 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.fsprovider.internal.FileMonitor.ResourceChange;
import org.apache.sling.hamcrest.ResourceMatchers;
import org.apache.sling.testing.mock.osgi.MapUtil;
import org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin;
import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
class TestUtils {
@@ -53,6 +59,7 @@ class TestUtils {
config.put("provider.file", "src/test/resources/fs-test");
config.put("provider.roots", "/fs-test");
config.put("provider.checkinterval", 0);
+ config.put("provider.fs.mode", FsMode.INITIAL_CONTENT_FILES_FOLDERS.name());
config.putAll(props);
context.registerInjectActivateService(new FsResourceProvider(), config);
}
@@ -94,4 +101,30 @@ class TestUtils {
}
}
+ public static void assertChange(List<ResourceChange> changes, String path, String topic) {
+ boolean found = false;
+ for (ResourceChange change : changes) {
+ if (StringUtils.equals(change.path, path) && StringUtils.equals(change.topic, topic)) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue("Change with path=" + path + ", topic=" + topic + " expected", found);
+ }
+
+ public static class ResourceListener implements EventHandler {
+ private final List<ResourceChange> allChanges = new ArrayList<>();
+ public List<ResourceChange> getChanges() {
+ return allChanges;
+ }
+ @Override
+ public void handleEvent(Event event) {
+ ResourceChange change = new ResourceChange();
+ change.path = (String)event.getProperty(SlingConstants.PROPERTY_PATH);
+ change.resourceType = (String)event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);
+ change.topic = event.getTopic();
+ allChanges.add(change);
+ }
+ }
+
}
diff --git a/src/test/resources/vaultfs-test/META-INF/vault/filter.xml b/src/test/resources/vaultfs-test/META-INF/vault/filter.xml
index 20be2d8..a56ee24 100644
--- a/src/test/resources/vaultfs-test/META-INF/vault/filter.xml
+++ b/src/test/resources/vaultfs-test/META-INF/vault/filter.xml
@@ -19,5 +19,7 @@
-->
<workspaceFilter version="1.0">
<filter root="/content/dam/talk.png" />
- <filter root="/content/samples" />
+ <filter root="/content/samples">
+ <exclude pattern="/content/samples/en/conference(/.*)?"/>
+ </filter>
</workspaceFilter>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml
index 4f8312a..e207a1e 100644
--- a/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml
+++ b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml
@@ -39,8 +39,6 @@
dc:format="image/png"
dc:modified="{Date}2014-09-19T21:20:26.812+02:00"
jcr:primaryType="nt:unstructured"
- tiff:ImageLength="{Long}270"
- tiff:ImageWidth="{Long}480"
writebackEnable="{Boolean}true" />
</jcr:content>
</jcr:root>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 13/23: SLING-6537 BigDecimal
support,
use copy of enhanced ValueMap with proper type converstion from Sling API
2.17.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 98a2215535b5b1d96437a4ddd61a9104fedca500
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Mar 10 14:55:56 2017 +0000
SLING-6537 BigDecimal support, use copy of enhanced ValueMap with proper type converstion from Sling API 2.17.0
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786359 13f79535-47bb-0310-9956-ffa450edef68
---
.../fsprovider/internal/mapper/ContentFile.java | 1 +
.../fsprovider/internal/mapper/FileResource.java | 2 +-
.../internal/mapper/valuemap/DateUtils.java | 99 +++++++++
.../internal/mapper/valuemap/ObjectConverter.java | 185 ++++++++++++++++
.../mapper/valuemap/ValueMapDecorator.java | 179 +++++++++++++++
.../mapper/{ => valuemap}/ValueMapUtil.java | 5 +-
.../sling/fsprovider/internal/JsonContentTest.java | 5 +-
.../internal/mapper/valuemap/Convert.java | 242 +++++++++++++++++++++
.../mapper/valuemap/ObjectConverterTest.java | 233 ++++++++++++++++++++
.../mapper/valuemap/ValueMapDecoratorTest.java | 157 +++++++++++++
.../mapper/{ => valuemap}/ValueMapUtilTest.java | 2 +-
11 files changed, 1104 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
index 27e09d5..00c238a 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
@@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Predicate;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapUtil;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
/**
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 e3a61ac..f0adfb8 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
@@ -37,7 +37,7 @@ 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.apache.sling.fsprovider.internal.mapper.valuemap.ValueMapDecorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/DateUtils.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/DateUtils.java
new file mode 100644
index 0000000..cf985f5
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/DateUtils.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.jackrabbit.util.ISO8601;
+
+/**
+ * This is copied from org.apache.sling.api.wrappers.impl.DateUtils
+ * to avoid dependency to latest Sling API.
+ * This can be removed when Sling API 2.17.0 or higher is referenced.
+ */
+final class DateUtils {
+
+ private DateUtils() {
+ // static methods only
+ }
+
+ /**
+ * @param date Date value
+ * @return Calendar value or null
+ */
+ public static Calendar toCalendar(Date input) {
+ if (input == null) {
+ return null;
+ }
+ Calendar result = Calendar.getInstance();
+ result.setTime(input);
+ return result;
+ }
+
+ /**
+ * @param calendar Calendar value
+ * @return Date value or null
+ */
+ public static Date toDate(Calendar input) {
+ if (input == null) {
+ return null;
+ }
+ return input.getTime();
+ }
+
+ /**
+ * @param input Date value
+ * @return ISO8601 string representation or null
+ */
+ public static String dateToString(Date input) {
+ return calendarToString(toCalendar(input));
+ }
+
+ /**
+ * @param input Calendar value
+ * @return ISO8601 string representation or null
+ */
+ public static String calendarToString(Calendar input) {
+ if (input == null) {
+ return null;
+ }
+ return ISO8601.format(input);
+ }
+
+ /**
+ * @param input ISO8601 string representation
+ * @return Date value or null
+ */
+ public static Date dateFromString(String input) {
+ return toDate(calendarFromString(input));
+ }
+
+ /**
+ * @param input ISO8601 string representation
+ * @return Calendar value or null
+ */
+ public static Calendar calendarFromString(String input) {
+ if (input == null) {
+ return null;
+ }
+ return ISO8601.parse(input);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ObjectConverter.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ObjectConverter.java
new file mode 100644
index 0000000..5d91e06
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ObjectConverter.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
+
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * This is copied from org.apache.sling.api.wrappers.impl.ObjectConverter
+ * to avoid dependency to latest Sling API.
+ * This can be removed when Sling API 2.17.0 or higher is referenced.
+ */
+final class ObjectConverter {
+
+ private ObjectConverter() {
+ // static methods only
+ }
+
+ /**
+ * Converts the object to the given type.
+ * @param obj object
+ * @param type type
+ * @return the converted object
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T convert(Object obj, Class<T> type) {
+ if (obj == null) {
+ return null;
+ }
+
+ // check if direct assignment is possible
+ if (type.isAssignableFrom(obj.getClass())) {
+ return (T)obj;
+ }
+
+ // convert array elements individually
+ if (type.isArray()) {
+ return (T)convertToArray(obj, type.getComponentType());
+ }
+
+ // convert Calendar in Date and vice versa
+ if (Calendar.class.isAssignableFrom(type) && obj instanceof Date) {
+ return (T)DateUtils.toCalendar((Date)obj);
+ }
+ if (type == Date.class && obj instanceof Calendar) {
+ return (T)DateUtils.toDate((Calendar)obj);
+ }
+
+ // no direct conversion - format to string and try to parse to target type
+ String result = getSingleValue(obj);
+ if (result == null) {
+ return null;
+ }
+ if (type == String.class) {
+ return (T)result.toString();
+ }
+ if (type == Boolean.class) {
+ // do not rely on Boolean.parseBoolean to avoid converting nonsense to "false" without noticing
+ if ("true".equalsIgnoreCase(result)) {
+ return (T)Boolean.TRUE;
+ }
+ else if ("false".equalsIgnoreCase(result)) {
+ return (T)Boolean.FALSE;
+ }
+ else {
+ return null;
+ }
+ }
+ try {
+ if (type == Byte.class) {
+ return (T)(Byte)Byte.parseByte(result);
+ }
+ if (type == Short.class) {
+ return (T)(Short)Short.parseShort(result);
+ }
+ if (type == Integer.class) {
+ return (T)(Integer)Integer.parseInt(result);
+ }
+ if (type == Long.class) {
+ return (T)(Long)Long.parseLong(result);
+ }
+ if (type == Float.class) {
+ return (T)(Float)Float.parseFloat(result);
+ }
+ if (type == Double.class) {
+ return (T)(Double)Double.parseDouble(result);
+ }
+ if (type == BigDecimal.class) {
+ return (T)new BigDecimal(result);
+ }
+ }
+ catch (NumberFormatException e) {
+ return null;
+ }
+ if (Calendar.class.isAssignableFrom(type)) {
+ return (T)DateUtils.calendarFromString(result);
+ }
+ if (type == Date.class) {
+ return (T)DateUtils.dateFromString(result);
+ }
+ return null;
+ }
+
+ /**
+ * Gets a single value of String from the object. If the object is an array it returns it's first element.
+ * @param obj object or object array.
+ * @return result of <code>toString()</code> on object or first element of an object array. If @param obj is null
+ * or it's an array with first element that is null, then null is returned.
+ */
+ private static String getSingleValue(Object obj) {
+ final String result;
+ if (obj == null) {
+ result = null;
+ }
+ else if (obj.getClass().isArray()) {
+ if (Array.getLength(obj) == 0) {
+ result = null;
+ }
+ else {
+ result = getSingleValue(Array.get(obj, 0));
+ }
+ }
+ else if (obj instanceof Calendar) {
+ result = DateUtils.calendarToString((Calendar)obj);
+ }
+ else if (obj instanceof Date) {
+ result = DateUtils.dateToString((Date)obj);
+ }
+ else {
+ result = obj.toString();
+ }
+ return result;
+ }
+
+ /**
+ * Converts the object to an array of the given type
+ * @param obj the object or object array
+ * @param type the component type of the array
+ * @return and array of type T
+ */
+ @SuppressWarnings("unchecked")
+ private static <T> T[] convertToArray(Object obj, Class<T> type) {
+ if (obj.getClass().isArray()) {
+ List<Object> resultList = new ArrayList<Object>();
+ for (int i = 0; i < Array.getLength(obj); i++) {
+ T singleValueResult = convert(Array.get(obj, i), type);
+ if (singleValueResult != null) {
+ resultList.add(singleValueResult);
+ }
+ }
+ return resultList.toArray((T[])Array.newInstance(type, resultList.size()));
+ }
+ else {
+ final T singleValueResult = convert(obj, type);
+ // return null for type conversion errors instead of single element array with value null
+ if (singleValueResult == null) {
+ return (T[])Array.newInstance(type, 0);
+ }
+ final T[] arrayResult = (T[])Array.newInstance(type, 1);
+ arrayResult[0] = singleValueResult;
+ return arrayResult;
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapDecorator.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapDecorator.java
new file mode 100644
index 0000000..4b0b5a5
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapDecorator.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.api.resource.ValueMap;
+
+/**
+ * This is copied from org.apache.sling.api.wrappers.ValueMapDectorator
+ * to avoid dependency to latest Sling API.
+ * This can be removed when Sling API 2.17.0 or higher is referenced.
+ */
+public final class ValueMapDecorator implements ValueMap {
+
+ /**
+ * underlying map
+ */
+ private final Map<String, Object> base;
+
+ /**
+ * Creates a new wrapper around a given map.
+ * @param base wrapped object
+ */
+ public ValueMapDecorator(Map<String, Object> base) {
+ this.base = base;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <T> T get(String name, Class<T> type) {
+ if (base instanceof ValueMap) {
+ // shortcut if decorated map is ValueMap
+ return ((ValueMap)base).get(name, type);
+ }
+ return ObjectConverter.convert(get(name), type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T get(String name, T defaultValue) {
+ if (base instanceof ValueMap) {
+ // shortcut if decorated map is ValueMap
+ return ((ValueMap)base).get(name, defaultValue);
+ }
+ if (defaultValue == null) {
+ return (T)get(name);
+ }
+ T value = get(name, (Class<T>) defaultValue.getClass());
+ return value == null ? defaultValue : value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int size() {
+ return base.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEmpty() {
+ return base.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean containsKey(Object key) {
+ return base.containsKey(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean containsValue(Object value) {
+ return base.containsValue(value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object get(Object key) {
+ return base.get(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object put(String key, Object value) {
+ return base.put(key, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object remove(Object key) {
+ return base.remove(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void putAll(Map<? extends String, ?> t) {
+ base.putAll(t);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void clear() {
+ base.clear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> keySet() {
+ return base.keySet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<Object> values() {
+ return base.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Entry<String, Object>> entrySet() {
+ return base.entrySet();
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + " : " + this.base.toString();
+ }
+
+ @Override
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode() {
+ return base.hashCode();
+ }
+
+ @Override
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object obj) {
+ return base.equals(obj);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java
similarity index 93%
rename from src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
rename to src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java
index 0d12ee1..b0a079c 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtil.java
@@ -16,16 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.fsprovider.internal.mapper;
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.api.wrappers.ValueMapDecorator;
-final class ValueMapUtil {
+public final class ValueMapUtil {
private ValueMapUtil() {
// static methods only
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 5ea4ea5..5e76a4e 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -140,6 +141,7 @@ public class JsonContentTest {
assertEquals(true, props.get("booleanProp", false));
assertEquals((Long)1234567890123L, props.get("longProp", Long.class));
assertEquals((Double)1.2345d, props.get("decimalProp", Double.class), 0.00001d);
+ assertEquals(new BigDecimal("1.2345"), props.get("decimalProp", BigDecimal.class));
assertArrayEquals(new String[] { "aa", "bb", "cc" }, props.get("stringPropMulti", String[].class));
assertArrayEquals(new Long[] { 1234567890123L, 55L }, props.get("longPropMulti", Long[].class));
@@ -164,8 +166,9 @@ public class JsonContentTest {
assertEquals(true, node.getProperty("booleanProp").getBoolean());
assertEquals(PropertyType.LONG, node.getProperty("longProp").getType());
assertEquals(1234567890123L, node.getProperty("longProp").getLong());
- assertEquals(PropertyType.DOUBLE, node.getProperty("decimalProp").getType());
+ assertEquals(PropertyType.DECIMAL, node.getProperty("decimalProp").getType());
assertEquals(1.2345d, node.getProperty("decimalProp").getDouble(), 0.00001d);
+ assertEquals(new BigDecimal("1.2345"), node.getProperty("decimalProp").getDecimal());
assertEquals(PropertyType.STRING, node.getProperty("stringPropMulti").getType());
assertTrue(node.getProperty("stringPropMulti").isMultiple());
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/Convert.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/Convert.java
new file mode 100644
index 0000000..15657cc
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/Convert.java
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.lang.reflect.Array;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.commons.lang3.ClassUtils;
+
+/**
+ * This is copied from org.apache.sling.api.wrappers.impl.Convert
+ */
+final class Convert {
+
+ private Convert() {
+ // static methods only
+ }
+
+ @SuppressWarnings("unchecked")
+ public static class ConversionAssert<T,U> {
+ private final T input1;
+ private final T input2;
+ private Class<T> inputType;
+ private U expected1;
+ private U expected2;
+ private U nullValue;
+ private Class<U> expectedType;
+
+ private ConversionAssert(T input1, T input2, boolean inputTypePrimitive) {
+ this.input1 = input1;
+ this.input2 = input2;
+ this.inputType = (Class<T>)input1.getClass();
+ if (inputTypePrimitive) {
+ this.inputType = (Class<T>)ClassUtils.wrapperToPrimitive(this.inputType);
+ }
+ }
+
+ private void expected(U expected1, U expected2, boolean expectedTypePrimitive) {
+ this.expected1 = expected1;
+ this.expected2 = expected2;
+ this.expectedType = (Class<U>)expected1.getClass();
+ if (expectedTypePrimitive) {
+ expectedType = (Class<U>)ClassUtils.wrapperToPrimitive(this.expectedType);
+ }
+ }
+
+ /**
+ * @param expected1 Singleton or first array expected result value
+ * @param expected2 Second array expected result value
+ * @return this
+ */
+ public ConversionAssert<T,U> to(U expected1, U expected2) {
+ expected(expected1, expected2, false);
+ return this;
+ }
+
+ /**
+ * @param expected1 Singleton or first array expected result value
+ * @param expected2 Second array expected result value
+ * @return this
+ */
+ public ConversionAssert<T,U> toPrimitive(U expected1, U expected2) {
+ expected(expected1, expected2, true);
+ return this;
+ }
+
+ /**
+ * @param expected1 Singleton or first array expected result value
+ * @param expected2 Second array expected result value
+ * @return this
+ */
+ public ConversionAssert<T,U> toNull(Class<U> expectedType) {
+ expected1 = null;
+ expected2 = null;
+ this.expectedType = expectedType;
+ return this;
+ }
+
+ /**
+ * @param nullValue Result value in case of null
+ */
+ public ConversionAssert<T,U> nullValue(U nullValue) {
+ this.nullValue = nullValue;
+ return this;
+ }
+
+ /**
+ * Do assertion
+ */
+ public void test() {
+ Class<U[]> expectedArrayType = (Class<U[]>)Array.newInstance(this.expectedType, 0).getClass();
+ assertPermuations(input1, input2, inputType, expected1, expected2, nullValue, expectedType, expectedArrayType);
+ }
+ }
+
+ /**
+ * @param input1 Singleton or first array input value
+ * @param input2 Second array input value
+ */
+ public static <T,U> ConversionAssert<T,U> from(T input1, T input2) {
+ return new ConversionAssert<T,U>(input1, input2, false);
+ }
+
+ /**
+ * @param input1 Singleton or first array input value
+ * @param input2 Second array input value
+ */
+ public static <T,U> ConversionAssert<T,U> fromPrimitive(T input1, T input2) {
+ return new ConversionAssert<T,U>(input1, input2, true);
+ }
+
+ private static <T,U> void assertPermuations(T input1, T input2, Class<T> inputType,
+ U expected1, U expected2, U nullValue, Class<U> expectedType, Class<U[]> expectedArrayType) {
+
+ // single value to single value
+ assertConversion(expected1, input1, expectedType);
+
+ // single value to array
+ Object expectedSingletonArray;
+ if (expected1 == null && expected2 == null) {
+ expectedSingletonArray = Array.newInstance(expectedType, 0);
+ }
+ else {
+ expectedSingletonArray = Array.newInstance(expectedType, 1);
+ Array.set(expectedSingletonArray, 0, expected1);
+ }
+ assertConversion(expectedSingletonArray, input1, expectedArrayType);
+
+ // array to array
+ Object inputDoubleArray = Array.newInstance(inputType, 2);
+ Array.set(inputDoubleArray, 0, input1);
+ Array.set(inputDoubleArray, 1, input2);
+ Object expectedDoubleArray;
+ if (expected1 == null && expected2 == null) {
+ expectedDoubleArray = Array.newInstance(expectedType, 0);
+ }
+ else {
+ expectedDoubleArray = Array.newInstance(expectedType, 2);
+ Array.set(expectedDoubleArray, 0, expected1);
+ Array.set(expectedDoubleArray, 1, expected2);
+ }
+ assertConversion(expectedDoubleArray, inputDoubleArray, expectedArrayType);
+
+ // array to single (first) value
+ assertConversion(expected1, inputDoubleArray, expectedType);
+
+ // null to single value
+ assertConversion(nullValue, null, expectedType);
+
+ // null to array
+ assertConversion(null, null, expectedArrayType);
+
+ // empty array to single value
+ Object inputEmptyArray = Array.newInstance(inputType, 0);
+ assertConversion(nullValue, inputEmptyArray, expectedType);
+
+ // empty array to array
+ Object expectedEmptyArray = Array.newInstance(expectedType, 0);
+ assertConversion(expectedEmptyArray, inputEmptyArray, expectedArrayType);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T,U> void assertConversion(Object expected, Object input, Class<U> type) {
+ U result = ObjectConverter.convert(input, type);
+ String msg = "Convert '" + toString(input) + "' to " + type.getSimpleName();
+ if (expected == null) {
+ assertNull(msg, result);
+ }
+ else if (expected.getClass().isArray()) {
+ assertArrayEquals(msg, (U[])toStringIfDate(expected), (U[])toStringIfDate(result));
+ }
+ else {
+ assertEquals(msg, toStringIfDate(expected), toStringIfDate(result));
+ }
+ }
+
+ private static String toString(Object input) {
+ if (input == null) {
+ return "null";
+ }
+ else if (input.getClass().isArray()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+ for (int i=0; i<Array.getLength(input); i++) {
+ if (i > 0) {
+ sb.append(",");
+ }
+ sb.append(toString(Array.get(input, i)));
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+ else {
+ return toStringIfDate(input).toString();
+ }
+ }
+
+ private static Object toStringIfDate(Object input) {
+ if (input == null) {
+ return null;
+ }
+ if (input instanceof Calendar) {
+ return "(Calendar)" + DateUtils.calendarToString((Calendar)input);
+ }
+ if (input instanceof Date) {
+ return "(Date)" + DateUtils.dateToString((Date)input);
+ }
+ if (input.getClass().isArray()) {
+ if (Calendar.class.isAssignableFrom(input.getClass().getComponentType())
+ || input.getClass().getComponentType() == Date.class) {
+ Object[] resultArray = new String[Array.getLength(input)];
+ for (int i=0; i<Array.getLength(input); i++) {
+ resultArray[i] = toStringIfDate(Array.get(input, i));
+ }
+ return resultArray;
+ }
+ }
+ return input;
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ObjectConverterTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ObjectConverterTest.java
new file mode 100644
index 0000000..8c21a70
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ObjectConverterTest.java
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
+
+import static org.apache.sling.fsprovider.internal.mapper.valuemap.DateUtils.calendarToString;
+import static org.apache.sling.fsprovider.internal.mapper.valuemap.DateUtils.toCalendar;
+import static org.apache.sling.fsprovider.internal.mapper.valuemap.DateUtils.toDate;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNull;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.junit.Test;
+
+/**
+ * This is copied from org.apache.sling.api.wrappers.impl.ObjectConverterTest
+ */
+public class ObjectConverterTest {
+
+ private static final String STRING_1 = "item1";
+ private static final String STRING_2 = "item2";
+ private static final boolean BOOLEAN_1 = true;
+ private static final boolean BOOLEAN_2 = false;
+ private static final byte BYTE_1 = (byte)0x01;
+ private static final byte BYTE_2 = (byte)0x02;
+ private static final short SHORT_1 = (short)12;
+ private static final short SHORT_2 = (short)34;
+ private static final int INT_1 = 55;
+ private static final int INT_2 = -123;
+ private static final long LONG_1 = 1234L;
+ private static final long LONG_2 = -4567L;
+ private static final float FLOAT_1 = 1.23f;
+ private static final float FLOAT_2 = -4.56f;
+ private static final double DOUBLE_1 = 12.34d;
+ private static final double DOUBLE_2 = -45.67d;
+ private static final BigDecimal BIGDECIMAL_1 = new BigDecimal("12345.67");
+ private static final BigDecimal BIGDECIMAL_2 = new BigDecimal("-23456.78");
+ private static final Calendar CALENDAR_1 = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
+ private static final Calendar CALENDAR_2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
+ {
+ CALENDAR_1.set(2016, 10, 15, 8, 20, 30);
+ CALENDAR_2.set(2015, 6, 31, 19, 10, 20);
+ }
+ private static final Date DATE_1 = toDate(CALENDAR_1);
+ private static final Date DATE_2 = toDate(CALENDAR_2);
+
+ @Test
+ public void testDateToString() {
+ Convert.from(STRING_1, STRING_2).to(STRING_1, STRING_2).test();
+ Convert.fromPrimitive(BOOLEAN_1, BOOLEAN_2).to(Boolean.toString(BOOLEAN_1), Boolean.toString(BOOLEAN_2)).test();
+ Convert.from(BOOLEAN_1, BOOLEAN_2).to(Boolean.toString(BOOLEAN_1), Boolean.toString(BOOLEAN_2)).test();
+ Convert.fromPrimitive(BYTE_1, BYTE_2).to(Byte.toString(BYTE_1), Byte.toString(BYTE_2)).test();
+ Convert.from(BYTE_1, BYTE_2).to(Byte.toString(BYTE_1), Byte.toString(BYTE_2)).test();
+ Convert.fromPrimitive(SHORT_1, SHORT_2).to(Short.toString(SHORT_1), Short.toString(SHORT_2)).test();
+ Convert.from(SHORT_1, SHORT_2).to(Short.toString(SHORT_1), Short.toString(SHORT_2)).test();
+ Convert.fromPrimitive(INT_1, INT_2).to(Integer.toString(INT_1), Integer.toString(INT_2)).test();
+ Convert.from(INT_1, INT_2).to(Integer.toString(INT_1), Integer.toString(INT_2)).test();
+ Convert.fromPrimitive(LONG_1, LONG_2).to(Long.toString(LONG_1), Long.toString(LONG_2)).test();
+ Convert.from(LONG_1, LONG_2).to(Long.toString(LONG_1), Long.toString(LONG_2)).test();
+ Convert.fromPrimitive(FLOAT_1, FLOAT_2).to(Float.toString(FLOAT_1), Float.toString(FLOAT_2)).test();
+ Convert.from(FLOAT_1, FLOAT_2).to(Float.toString(FLOAT_1), Float.toString(FLOAT_2)).test();
+ Convert.fromPrimitive(DOUBLE_1, DOUBLE_2).to(Double.toString(DOUBLE_1), Double.toString(DOUBLE_2)).test();
+ Convert.from(DOUBLE_1, DOUBLE_2).to(Double.toString(DOUBLE_1), Double.toString(DOUBLE_2)).test();
+ Convert.from(BIGDECIMAL_1, BIGDECIMAL_2).to(BIGDECIMAL_1.toString(), BIGDECIMAL_2.toString()).test();
+ Convert.from(CALENDAR_1, CALENDAR_2).to(calendarToString(CALENDAR_1), calendarToString(CALENDAR_2)).test();
+ Convert.from(DATE_1, DATE_2).to(calendarToString(toCalendar(DATE_1)), calendarToString(toCalendar(DATE_2))).test();
+ }
+
+ @Test
+ public void testToBoolean() {
+ Convert.fromPrimitive(BOOLEAN_1, BOOLEAN_2).to(BOOLEAN_1, BOOLEAN_2).test();
+ Convert.from(BOOLEAN_1, BOOLEAN_2).to(BOOLEAN_1, BOOLEAN_2).test();
+ Convert.from(Boolean.toString(BOOLEAN_1), Boolean.toString(BOOLEAN_2)).to(BOOLEAN_1, BOOLEAN_2).test();
+
+ // test other types that should not be converted
+ Convert.<Integer,Boolean>from(INT_1, INT_2).toNull(Boolean.class).test();
+ Convert.<Date,Boolean>from(DATE_1, DATE_2).toNull(Boolean.class).test();
+ }
+
+ @Test
+ public void testToByte() {
+ Convert.fromPrimitive(BYTE_1, BYTE_2).to(BYTE_1, BYTE_2).test();
+ Convert.from(BYTE_1, BYTE_2).to(BYTE_1, BYTE_2).test();
+ Convert.from(Byte.toString(BYTE_1), Byte.toString(BYTE_2)).to(BYTE_1, BYTE_2).test();
+
+ // test conversion from other number types
+ Convert.from(INT_1, INT_2).to((byte)INT_1, (byte)INT_2).test();
+ Convert.fromPrimitive(INT_1, INT_2).to((byte)INT_1, (byte)INT_2).test();
+
+ // test other types that should not be converted
+ Convert.<Date,Byte>from(DATE_1, DATE_2).toNull(Byte.class).test();
+ }
+
+ @Test
+ public void testToShort() {
+ Convert.fromPrimitive(SHORT_1, SHORT_2).to(SHORT_1, SHORT_2).test();
+ Convert.from(SHORT_1, SHORT_2).to(SHORT_1, SHORT_2).test();
+ Convert.from(Short.toString(SHORT_1), Short.toString(SHORT_2)).to(SHORT_1, SHORT_2).test();
+
+ // test conversion from other number types
+ Convert.from(INT_1, INT_2).to((short)INT_1, (short)INT_2).test();
+ Convert.fromPrimitive(INT_1, INT_2).to((short)INT_1, (short)INT_2).test();
+
+ // test other types that should not be converted
+ Convert.<Date,Short>from(DATE_1, DATE_2).toNull(Short.class).test();
+ }
+
+ @Test
+ public void testToInteger() {
+ Convert.fromPrimitive(INT_1, INT_2).to(INT_1, INT_2).test();
+ Convert.from(INT_1, INT_2).to(INT_1, INT_2).test();
+ Convert.from(Integer.toString(INT_1), Integer.toString(INT_2)).to(INT_1, INT_2).test();
+
+ // test conversion from other number types
+ Convert.from(SHORT_1, SHORT_2).to((int)SHORT_1, (int)SHORT_2).test();
+ Convert.fromPrimitive(SHORT_1, SHORT_2).to((int)SHORT_1, (int)SHORT_2).test();
+
+ // test other types that should not be converted
+ Convert.<Date,Integer>from(DATE_1, DATE_2).toNull(Integer.class).test();
+ }
+
+ @Test
+ public void testToLong() {
+ Convert.fromPrimitive(LONG_1, LONG_2).to(LONG_1, LONG_2).test();
+ Convert.from(LONG_1, LONG_2).to(LONG_1, LONG_2).test();
+ Convert.from(Long.toString(LONG_1), Long.toString(LONG_2)).to(LONG_1, LONG_2).test();
+
+ // test conversion from other number types
+ Convert.from(SHORT_1, SHORT_2).to((long)SHORT_1, (long)SHORT_2).test();
+ Convert.fromPrimitive(SHORT_1, SHORT_2).to((long)SHORT_1, (long)SHORT_2).test();
+
+ // test other types that should not be converted
+ Convert.<Date,Long>from(DATE_1, DATE_2).toNull(Long.class).test();
+ }
+
+ @Test
+ public void testToFloat() {
+ Convert.fromPrimitive(FLOAT_1, FLOAT_2).to(FLOAT_1, FLOAT_2).test();
+ Convert.from(FLOAT_1, FLOAT_2).to(FLOAT_1, FLOAT_2).test();
+ Convert.from(Float.toString(FLOAT_1), Float.toString(FLOAT_2)).to(FLOAT_1, FLOAT_2).test();
+
+ // test conversion from other number types
+ Convert.from(SHORT_1, SHORT_2).to((float)SHORT_1, (float)SHORT_2).test();
+ Convert.fromPrimitive(SHORT_1, SHORT_2).to((float)SHORT_1, (float)SHORT_2).test();
+
+ // test other types that should not be converted
+ Convert.<Date,Float>from(DATE_1, DATE_2).toNull(Float.class).test();
+ }
+
+ @Test
+ public void testToDouble() {
+ Convert.fromPrimitive(DOUBLE_1, DOUBLE_2).to(DOUBLE_1, DOUBLE_2).test();
+ Convert.from(DOUBLE_1, DOUBLE_2).to(DOUBLE_1, DOUBLE_2).test();
+ Convert.from(Double.toString(DOUBLE_1), Double.toString(DOUBLE_2)).to(DOUBLE_1, DOUBLE_2).test();
+
+ // test conversion from other number types
+ Convert.from(SHORT_1, SHORT_2).to((double)SHORT_1, (double)SHORT_2).test();
+ Convert.fromPrimitive(SHORT_1, SHORT_2).to((double)SHORT_1, (double)SHORT_2).test();
+
+ // test other types that should not be converted
+ Convert.<Date,Double>from(DATE_1, DATE_2).toNull(Double.class).test();
+ }
+
+ @Test
+ public void testToBigDecimal() {
+ Convert.from(BIGDECIMAL_1, BIGDECIMAL_2).to(BIGDECIMAL_1, BIGDECIMAL_2).test();
+ Convert.from(BIGDECIMAL_1.toString(), BIGDECIMAL_2.toString()).to(BIGDECIMAL_1, BIGDECIMAL_2).test();
+
+ // test conversion from other number types
+ Convert.from(LONG_1, LONG_2).to(BigDecimal.valueOf(LONG_1), BigDecimal.valueOf(LONG_2)).test();
+ Convert.fromPrimitive(LONG_1, LONG_2).to(BigDecimal.valueOf(LONG_1), BigDecimal.valueOf(LONG_2)).test();
+ Convert.from(DOUBLE_1, DOUBLE_2).to(BigDecimal.valueOf(DOUBLE_1), BigDecimal.valueOf(DOUBLE_2)).test();
+ Convert.fromPrimitive(DOUBLE_1, DOUBLE_2).to(BigDecimal.valueOf(DOUBLE_1), BigDecimal.valueOf(DOUBLE_2)).test();
+
+ // test other types that should not be converted
+ Convert.<Date,BigDecimal>from(DATE_1, DATE_2).toNull(BigDecimal.class).test();
+ }
+
+ @Test
+ public void testToCalendar() {
+ Convert.from(CALENDAR_1, CALENDAR_2).to(CALENDAR_1, CALENDAR_2).test();
+ Convert.from(DateUtils.calendarToString(CALENDAR_1), DateUtils.calendarToString(CALENDAR_2)).to(CALENDAR_1, CALENDAR_2).test();
+
+ // test conversion from other date types
+ Convert.from(DATE_1, DATE_2).to(toCalendar(DATE_1), toCalendar(DATE_2)).test();
+
+ // test other types that should not be converted
+ Convert.<String,Calendar>from(STRING_1, STRING_2).toNull(Calendar.class).test();
+ Convert.<Boolean,Calendar>from(BOOLEAN_1, BOOLEAN_2).toNull(Calendar.class).test();
+ }
+
+ @Test
+ public void testToDate() {
+ Convert.from(DATE_1, DATE_2).to(DATE_1, DATE_2).test();
+ Convert.from(DateUtils.dateToString(DATE_1), DateUtils.dateToString(DATE_2)).to(DATE_1, DATE_2).test();
+
+ // test conversion from other date types
+ Convert.from(CALENDAR_1, CALENDAR_2).to(toDate(CALENDAR_1), toDate(CALENDAR_2)).test();
+
+ // test other types that should not be converted
+ Convert.<String,Date>from(STRING_1, STRING_2).toNull(Date.class).test();
+ Convert.<Boolean,Date>from(BOOLEAN_1, BOOLEAN_2).toNull(Date.class).test();
+ }
+
+ @Test
+ public void testPrimitiveByteArray() {
+ byte[] array = new byte[] { 0x01, 0x02, 0x03 };
+ assertArrayEquals(array, ObjectConverter.convert(array, byte[].class));
+ assertArrayEquals(new byte[0], ObjectConverter.convert(new byte[0], byte[].class));
+ assertNull(ObjectConverter.convert(null, byte[].class));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapDecoratorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapDecoratorTest.java
new file mode 100644
index 0000000..88827e0
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapDecoratorTest.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * This is copied from org.apache.sling.api.wrappers.ValueMapDecoratorTest
+ */
+public class ValueMapDecoratorTest {
+
+ private Map<String, Object> map;
+ private ValueMap valueMap;
+
+ @Before
+ public void setUp() {
+ map = new HashMap<String, Object>();
+ valueMap = new ValueMapDecorator(map);
+ }
+
+ // SLING-4178
+ @Test
+ public void testIncompatibleTypeInArray() {
+ map.put("prop1", new String[] { "test", "test2" });
+ map.put("prop2", "test");
+ Assert.assertArrayEquals("Not convertible type should return empty array", new Integer[0], valueMap.get("prop1", Integer[].class));
+ Assert.assertArrayEquals("Not convertible type should return empt array", new Integer[0], valueMap.get("prop2", Integer[].class));
+ }
+
+ // SLING-662
+ @Test
+ public void testGettingArraysFromSingleValueEntries() {
+ map.put("prop1", "test");
+ map.put("prop2", "1");
+ Assert.assertArrayEquals(
+ "Even though the underlying entry is single-value if should be enclosed in a single element array",
+ new String[] { "test" }, valueMap.get("prop1", String[].class));
+ Assert.assertArrayEquals(
+ "Even though the underlying entry is single-value if should be enclosed in a single element array",
+ new Integer[] { 1 }, valueMap.get("prop2", Integer[].class));
+ }
+
+ @Test
+ public void testGettingArraysFromMultiValueEntries() {
+ map.put("prop1", new String[] { "test", "test2" });
+ map.put("prop2", new String[] { "1", "2" });
+ Assert.assertArrayEquals("Could not get values from underlying array", new String[] { "test", "test2" },
+ valueMap.get("prop1", String[].class));
+ Assert.assertArrayEquals("Conversion to Integer was not possible", new Integer[] { 1, 2 },
+ valueMap.get("prop2", Integer[].class));
+ }
+
+ @Test
+ public void testGettingSingleValuesFromMultiValueEntries() {
+ map.put("prop1", new String[] { "test", "test2" });
+ map.put("prop2", new String[] { "1", "2" });
+ Assert.assertEquals("First element from underlying array should be returned", "test",
+ valueMap.get("prop1", String.class));
+ Assert.assertEquals("First element from underlying array should be returned", Integer.valueOf(1),
+ valueMap.get("prop2", Integer.class));
+ }
+
+ @Test
+ public void testGettingInvalidEntryWithDefaultValue() {
+ Assert.assertEquals(Integer.valueOf(1), valueMap.get("prop1", 1));
+ Assert.assertEquals("test", valueMap.get("prop1", "test"));
+ }
+
+ @Test
+ public void testPrimitiveTypes() {
+ map.put("prop1", new String[] { "1", "2" });
+ Assert.assertNull("ValueMap should not support conversion to primitive type", valueMap.get("prop1", int.class));
+ }
+ @Test(expected=ClassCastException.class)
+ public void testPrimitiveTypesArray() {
+ map.put("prop1", new String[] { "1", "2" });
+ Assert.assertArrayEquals("ValueMap should not support conversion to array of primitive type",
+ new int[0], valueMap.get("prop1", int[].class));
+ }
+
+ @Test
+ public void testEqualsAndHashCodeOfEqualValueMapsWithNonArrayTypes() {
+ map.put("prop1", "some string");
+ ValueMapDecorator valueMap2 = new ValueMapDecorator(map);
+ Assert.assertTrue("Two ValueMapDecorators based on the same map should be equal", valueMap.equals(valueMap2));
+ Assert.assertEquals("Two equal ValueMapDecorators should have the same hash code", valueMap.hashCode(),
+ valueMap2.hashCode());
+
+ ValueMapDecorator valueMap3 = new ValueMapDecorator(new HashMap<String, Object>());
+ valueMap3.put("prop1", "some string");
+ Assert.assertEquals(valueMap, valueMap3);
+ Assert.assertEquals("Two equal ValueMapDecorators should have the same hash code", valueMap.hashCode(),
+ valueMap3.hashCode());
+
+ Assert.assertEquals(map, valueMap);
+ Assert.assertEquals(valueMap, map);
+ }
+
+ @Ignore("SLING-4784")
+ @Test
+ public void testEqualsAndHashCodeOfEqualValueMapsWithArrayTypes() {
+ map.put("prop1", new String[] { "1", "2" });
+ ValueMapDecorator valueMap2 = new ValueMapDecorator(map);
+ Assert.assertTrue("Two ValueMapDecorators based on the same map should be equal", valueMap.equals(valueMap2));
+ Assert.assertEquals("Two equal ValueMapDecorators should have the same hash code", valueMap.hashCode(),
+ valueMap2.hashCode());
+
+ ValueMapDecorator valueMap3 = new ValueMapDecorator(new HashMap<String, Object>());
+ valueMap3.put("prop1", new String[] { "1", "2" });
+ Assert.assertEquals(valueMap, valueMap3);
+ Assert.assertEquals("Two equal ValueMapDecorators should have the same hash code", valueMap.hashCode(),
+ valueMap3.hashCode());
+ }
+
+ @Test
+ public void testEqualsOfInequalValueMapsWithNonArrayTypes() {
+ valueMap.put("prop", "value");
+ ValueMapDecorator valueMap2 = new ValueMapDecorator(new HashMap<String, Object>());
+ valueMap2.put("prop", "value2");
+ Assert.assertFalse("Two ValueMapDecorators based on maps with different entries should not be equal",
+ valueMap.equals(valueMap2));
+
+ }
+
+ @Test
+ public void testEqualsOfInequalValueMapsWithArrayTypes() {
+ valueMap.put("prop", new String[] { "1", "2" });
+ ValueMapDecorator valueMap2 = new ValueMapDecorator(new HashMap<String, Object>());
+ valueMap2.put("prop", new String[] { "3", "4" });
+ Assert.assertFalse("Two ValueMapDecorators based on maps with different entries should not be equal",
+ valueMap.equals(valueMap2));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtilTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
similarity index 97%
rename from src/test/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtilTest.java
rename to src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
index 71d6a38..87f2bfd 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtilTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.fsprovider.internal.mapper;
+package org.apache.sling.fsprovider.internal.mapper.valuemap;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 02/23: backport of changes from
SLING-6440 and SLING-6537 to 1.1.x version of fsresource based on old
resource provider SPI
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 54e89e7508ec978f0bef398bc6b432af89de1593
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Feb 28 15:40:56 2017 +0000
backport of changes from SLING-6440 and SLING-6537 to 1.1.x version of fsresource based on old resource provider SPI
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1784765 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 120 ++++-
.../fsprovider/internal/ContentFileExtensions.java | 75 +++
.../sling/fsprovider/internal/FileMonitor.java | 185 +++++--
.../fsprovider/internal/FsResourceMapper.java | 47 ++
.../fsprovider/internal/FsResourceProvider.java | 368 +++++++-------
.../fsprovider/internal/mapper/ContentFile.java | 166 +++++++
.../internal/mapper/ContentFileResource.java | 127 +++++
.../internal/mapper/ContentFileResourceMapper.java | 155 ++++++
.../{FsResource.java => mapper/FileResource.java} | 77 ++-
.../internal/mapper/FileResourceMapper.java | 145 ++++++
.../fsprovider/internal/mapper/ValueMapUtil.java | 66 +++
.../fsprovider/internal/mapper/jcr/FsItem.java | 161 ++++++
.../fsprovider/internal/mapper/jcr/FsNode.java | 549 +++++++++++++++++++++
.../internal/mapper/jcr/FsNodeIterator.java | 98 ++++
.../fsprovider/internal/mapper/jcr/FsNodeType.java | 157 ++++++
.../fsprovider/internal/mapper/jcr/FsProperty.java | 242 +++++++++
.../internal/mapper/jcr/FsPropertyDefinition.java | 100 ++++
.../internal/mapper/jcr/FsPropertyIterator.java | 82 +++
.../fsprovider/internal/mapper/jcr/FsValue.java | 162 ++++++
.../internal/parser/ContentFileCache.java | 107 ++++
.../internal/parser/ContentFileParser.java | 62 +++
.../internal/parser/ContentFileTypes.java | 40 ++
.../internal/parser/JcrXmlFileParser.java | 147 ++++++
.../internal/parser/JcrXmlValueConverter.java | 168 +++++++
.../fsprovider/internal/parser/JsonFileParser.java | 125 +++++
.../OSGI-INF/metatype/metatype.properties | 45 --
.../sling/fsprovider/internal/FileMonitorTest.java | 238 +++++++++
.../sling/fsprovider/internal/FilesFolderTest.java | 82 +++
.../fsprovider/internal/InvalidRootFolderTest.java | 75 +++
.../sling/fsprovider/internal/JcrMixedTest.java | 103 ++++
.../fsprovider/internal/JcrXmlContentTest.java | 168 +++++++
.../sling/fsprovider/internal/JsonContentTest.java | 259 ++++++++++
.../sling/fsprovider/internal/TestUtils.java | 97 ++++
.../internal/mapper/ContentFileTest.java | 115 +++++
.../internal/mapper/ValueMapUtilTest.java | 55 +++
.../internal/parser/ContentFileCacheTest.java | 92 ++++
.../internal/parser/ContentFileParserTest.java | 66 +++
.../internal/parser/JcrXmlFileParserTest.java | 34 ++
.../internal/parser/JcrXmlValueConverterTest.java | 105 ++++
src/test/resources/fs-test/folder1/file1a.txt | 1 +
src/test/resources/fs-test/folder1/file1b.txt | 1 +
.../resources/fs-test/folder1/folder11/file11a.txt | 1 +
src/test/resources/fs-test/folder2/content.json | 262 ++++++++++
.../fs-test/folder2/content/content2.json | 4 +
.../fs-test/folder2/content/file2content.txt | 1 +
.../resources/fs-test/folder2/folder21/file21a.txt | 1 +
src/test/resources/fs-test/folder3/content.jcr.xml | 192 +++++++
.../fs-test/folder3/content/content2.jcr.xml | 29 ++
.../resources/fs-test/folder3/folder31/file31a.txt | 1 +
src/test/resources/invalid-test/invalid.jcr.xml | 1 +
src/test/resources/invalid-test/invalid.json | 1 +
src/test/resources/simplelogger.properties | 19 +
.../vaultfs-test/META-INF/vault/filter.xml | 23 +
.../vaultfs-test/META-INF/vault/settings.xml | 23 +
.../resources/vaultfs-test/jcr_root/.content.xml | 24 +
.../vaultfs-test/jcr_root/content/.content.xml | 28 ++
.../vaultfs-test/jcr_root/content/dam/.content.xml | 24 +
.../jcr_root/content/dam/talk.png/.content.xml | 46 ++
.../dam/talk.png/_jcr_content/renditions/original | Bin 0 -> 8668 bytes
.../renditions/original.dir/.content.xml | 25 +
.../_jcr_content/renditions/web.1280.1280.png | Bin 0 -> 5252 bytes
.../jcr_root/content/samples/.content.xml | 23 +
.../jcr_root/content/samples/en/.content.xml | 191 +++++++
.../content/samples/en/conference/.content.xml | 89 ++++
.../jcr_root/content/samples/en/tools/.content.xml | 29 ++
.../samples/en/tools/navigation/.content.xml | 27 +
66 files changed, 5979 insertions(+), 352 deletions(-)
diff --git a/pom.xml b/pom.xml
index 896f9f8..c871b0c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,8 +22,8 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>26</version>
- <relativePath/>
+ <version>29</version>
+ <relativePath />
</parent>
<artifactId>org.apache.sling.fsresource</artifactId>
@@ -41,17 +41,10 @@
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource</developerConnection>
<url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource</url>
</scm>
-
+
<build>
<plugins>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- <configuration>
- <specVersion>1.1</specVersion>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<executions>
@@ -68,25 +61,60 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <executions>
+ <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
+ <execution>
+ <id>scr-metadata</id>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ <configuration>
+ <supportIncrementalBuild>true</supportIncrementalBuild>
+ </configuration>
+ </execution>
+ </executions>
<configuration>
+ <!-- Export SCR metadata to classpath to have them available in unit tests -->
+ <exportScr>true</exportScr>
<instructions>
- <Private-Package>
- org.apache.sling.fsprovider.internal
- </Private-Package>
+ <!-- Embed Apache Johnzon -->
+ <Embed-Dependency>
+ johnzon-core;scope=compile;inline=false,
+ geronimo-json_1.0_spec;scope=compile;inline=false
+ </Embed-Dependency>
+ <!-- Embed the nessecary parts of the jackrabbit-jcr-commons bundle as described in http://njbartlett.name/2014/05/26/static-linking.html -->
+ <Conditional-Package>org.apache.jackrabbit.util</Conditional-Package>
+ <Import-Package>
+ !org.apache.jackrabbit.*,
+ *
+ </Import-Package>
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/test/resources/fs-test/**</exclude>
+ <exclude>src/test/resources/invalid-test/**</exclude>
+ <exclude>src/test/resources/vaultfs-test/**/original</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.3.0</version>
+ <version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
@@ -95,19 +123,41 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <artifactId>osgi.cmpn</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.3.2</version>
+ <scope>compile</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-core</artifactId>
+ <version>1.0.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-json_1.0_spec</artifactId>
+ <version>1.0-alpha-1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-commons</artifactId>
+ <version>2.8.0</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
@@ -116,9 +166,33 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- <scope>compile</scope>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock</artifactId>
+ <version>1.9.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+ <version>2.2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.logging-mock</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.hamcrest</artifactId>
+ <version>1.0.2</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java b/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
new file mode 100644
index 0000000..5097750
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Matches file names for content file extensions.
+ */
+public final class ContentFileExtensions {
+
+ private final List<String> contentFileSuffixes;
+
+ public ContentFileExtensions(List<String> contentFileSuffixes) {
+ this.contentFileSuffixes = contentFileSuffixes;
+ }
+
+ /**
+ * Get suffix from file name.
+ * @param file File
+ * @return Content file name suffix or null if not a context file.
+ */
+ public String getSuffix(File file) {
+ for (String suffix : contentFileSuffixes) {
+ if (StringUtils.endsWith(file.getName(), suffix)) {
+ return suffix;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks suffix from file name.
+ * @param file File
+ * @return true if content file
+ */
+ public boolean matchesSuffix(File file) {
+ return getSuffix(file) != null;
+ }
+
+ /**
+ * @return Content file suffixes.
+ */
+ public Collection<String> getSuffixes() {
+ return contentFileSuffixes;
+ }
+
+ /**
+ * @return true if not suffixes are defined.
+ */
+ public boolean isEmpty() {
+ return contentFileSuffixes.isEmpty();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index 336f1c1..f1d4c90 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -19,12 +19,21 @@
package org.apache.sling.fsprovider.internal;
import java.io.File;
+import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingConstants;
+import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+import org.apache.sling.fsprovider.internal.mapper.FileResource;
+import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,10 +42,9 @@ import org.slf4j.LoggerFactory;
* This class is a monitor for the file system
* that periodically checks for changes.
*/
-public class FileMonitor extends TimerTask {
+public final class FileMonitor extends TimerTask {
- /** The logger. */
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
private final Timer timer = new Timer();
private boolean stop = false;
@@ -45,17 +53,23 @@ public class FileMonitor extends TimerTask {
private final Monitorable root;
private final FsResourceProvider provider;
+
+ private final ContentFileExtensions contentFileExtensions;
+ private final ContentFileCache contentFileCache;
/**
* Creates a new instance of this class.
* @param provider The resource provider.
* @param interval The interval between executions of the task, in milliseconds.
*/
- public FileMonitor(final FsResourceProvider provider, final long interval) {
+ public FileMonitor(final FsResourceProvider provider, final long interval,
+ final ContentFileExtensions contentFileExtensions, final ContentFileCache contentFileCache) {
this.provider = provider;
- this.root = new Monitorable(this.provider.getProviderRoot(), this.provider.getRootFile());
- createStatus(this.root);
- logger.debug("Starting file monitor for {} with an interval of {}ms", this.root.file, interval);
+ this.contentFileExtensions = contentFileExtensions;
+ this.contentFileCache = contentFileCache;
+ this.root = new Monitorable(this.provider.getProviderRoot(), this.provider.getRootFile(), null);
+ createStatus(this.root, contentFileExtensions, contentFileCache);
+ log.debug("Starting file monitor for {} with an interval of {}ms", this.root.file, interval);
timer.schedule(this, 0, interval);
}
@@ -85,12 +99,13 @@ public class FileMonitor extends TimerTask {
Thread.currentThread().interrupt();
}
}
- logger.debug("Stopped file monitor for {}", this.root.file);
+ log.debug("Stopped file monitor for {}", this.root.file);
}
/**
* @see java.util.TimerTask#run()
*/
+ @Override
public void run() {
synchronized (timer) {
stopped = false;
@@ -123,24 +138,21 @@ public class FileMonitor extends TimerTask {
* @param localEA The event admin
*/
private void check(final Monitorable monitorable, final EventAdmin localEA) {
- logger.debug("Checking {}", monitorable.file);
+ log.trace("Checking {}", monitorable.file);
// if the file is non existing, check if it has been readded
if ( monitorable.status instanceof NonExistingStatus ) {
if ( monitorable.file.exists() ) {
// new file and reset status
- createStatus(monitorable);
- sendEvents(monitorable,
- SlingConstants.TOPIC_RESOURCE_ADDED,
- localEA);
+ createStatus(monitorable, contentFileExtensions, contentFileCache);
+ sendEvents(monitorable, SlingConstants.TOPIC_RESOURCE_ADDED, localEA);
}
} else {
// check if the file has been removed
if ( !monitorable.file.exists() ) {
// removed file and update status
- sendEvents(monitorable,
- SlingConstants.TOPIC_RESOURCE_REMOVED,
- localEA);
+ sendEvents(monitorable, SlingConstants.TOPIC_RESOURCE_REMOVED, localEA);
monitorable.status = NonExistingStatus.SINGLETON;
+ contentFileCache.remove(monitorable.path);
} else {
// check for changes
final FileStatus fs = (FileStatus)monitorable.status;
@@ -148,10 +160,9 @@ public class FileMonitor extends TimerTask {
if ( fs.lastModified < monitorable.file.lastModified() ) {
fs.lastModified = monitorable.file.lastModified();
// changed
- sendEvents(monitorable,
- SlingConstants.TOPIC_RESOURCE_CHANGED,
- localEA);
+ sendEvents(monitorable, SlingConstants.TOPIC_RESOURCE_CHANGED, localEA);
changed = true;
+ contentFileCache.remove(monitorable.path);
}
if ( fs instanceof DirStatus ) {
// directory
@@ -174,9 +185,8 @@ public class FileMonitor extends TimerTask {
}
}
if (children[i] == null) {
- children[i] = new Monitorable(
- monitorable.path + '/'
- + files[i].getName(), files[i]);
+ children[i] = new Monitorable(monitorable.path + '/' + files[i].getName(), files[i],
+ contentFileExtensions.getSuffix(files[i]));
children[i].status = NonExistingStatus.SINGLETON;
check(children[i], localEA);
}
@@ -195,40 +205,112 @@ public class FileMonitor extends TimerTask {
* Send the event async via the event admin.
*/
private void sendEvents(final Monitorable monitorable, final String topic, final EventAdmin localEA) {
- if ( logger.isDebugEnabled() ) {
- logger.debug("Detected change for resource {} : {}", monitorable.path, topic);
+ if (log.isDebugEnabled()) {
+ log.debug("Detected change for resource {} : {}", monitorable.path, topic);
}
- final Dictionary<String, String> properties = new Hashtable<String, String>();
- properties.put(SlingConstants.PROPERTY_PATH, monitorable.path);
- final String type = monitorable.status instanceof FileStatus ?
- FsResource.RESOURCE_TYPE_FILE : FsResource.RESOURCE_TYPE_FOLDER;
- properties.put(SlingConstants.PROPERTY_RESOURCE_TYPE, type);
- localEA.postEvent(new org.osgi.service.event.Event(topic, properties));
+ List<ResourceChange> changes = collectResourceChanges(monitorable, topic);
+ for (ResourceChange change : changes) {
+ if (log.isTraceEnabled()) {
+ log.debug("Send change for resource {}: {}", change.path, change.topic);
+ }
+ final Dictionary<String, String> properties = new Hashtable<String, String>();
+ properties.put(SlingConstants.PROPERTY_PATH, change.path);
+ if (change.resourceType != null) {
+ properties.put(SlingConstants.PROPERTY_RESOURCE_TYPE, change.resourceType);
+ }
+ localEA.postEvent(new org.osgi.service.event.Event(change.topic, properties));
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<ResourceChange> collectResourceChanges(final Monitorable monitorable, final String topic) {
+ List<ResourceChange> changes = new ArrayList<>();
+ if (monitorable.status instanceof ContentFileStatus) {
+ ContentFile contentFile = ((ContentFileStatus)monitorable.status).contentFile;
+ if (StringUtils.equals(topic, SlingConstants.TOPIC_RESOURCE_CHANGED)) {
+ Map<String,Object> content = (Map<String,Object>)contentFile.getContent();
+ // we cannot easily report the diff of resource changes between two content files
+ // so we simulate a removal of the toplevel node and then add all nodes contained in the current content file again.
+ changes.add(buildContentResourceChange(SlingConstants.TOPIC_RESOURCE_REMOVED, content, monitorable.path));
+ addContentResourceChanges(changes, SlingConstants.TOPIC_RESOURCE_ADDED, content, monitorable.path);
+ }
+ else {
+ addContentResourceChanges(changes, topic, (Map<String,Object>)contentFile.getContent(), monitorable.path);
+ }
+ }
+ else {
+ ResourceChange change = new ResourceChange();
+ change.path = monitorable.path;
+ change.resourceType = monitorable.status instanceof FileStatus ?
+ FileResource.RESOURCE_TYPE_FILE : FileResource.RESOURCE_TYPE_FOLDER;
+ change.topic = topic;
+ changes.add(change);
+ }
+ return changes;
+ }
+ @SuppressWarnings("unchecked")
+ private void addContentResourceChanges(final List<ResourceChange> changes, final String topic,
+ final Map<String,Object> content, final String path) {
+ changes.add(buildContentResourceChange(topic, content, path));
+ if (content != null) {
+ for (Map.Entry<String,Object> entry : content.entrySet()) {
+ if (entry.getValue() instanceof Map) {
+ String childPath = path + "/" + entry.getKey();
+ addContentResourceChanges(changes, topic, (Map<String,Object>)entry.getValue(), childPath);
+ }
+ }
+ }
+ }
+ private ResourceChange buildContentResourceChange(final String topic, final Map<String,Object> content, final String path) {
+ Set<String> addedPropertyNames = null;
+ if (content != null && topic == SlingConstants.TOPIC_RESOURCE_ADDED) {
+ addedPropertyNames = new HashSet<>();
+ for (Map.Entry<String,Object> entry : content.entrySet()) {
+ if (!(entry.getValue() instanceof Map)) {
+ addedPropertyNames.add(entry.getKey());
+ }
+ }
+ }
+ ResourceChange change = new ResourceChange();
+ change.path = path;
+ change.resourceType = content != null ? (String)content.get("sling:resourceType") : null;
+ change.topic = topic;
+ return change;
}
/**
* Create a status object for the monitorable
*/
- private static void createStatus(final Monitorable monitorable) {
+ private static void createStatus(final Monitorable monitorable, ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache) {
if ( !monitorable.file.exists() ) {
monitorable.status = NonExistingStatus.SINGLETON;
} else if ( monitorable.file.isFile() ) {
- monitorable.status = new FileStatus(monitorable.file);
+ if (contentFileExtensions.matchesSuffix(monitorable.file)) {
+ monitorable.status = new ContentFileStatus(monitorable.file,
+ new ContentFile(monitorable.file, monitorable.path, null, contentFileCache));
+ }
+ else {
+ monitorable.status = new FileStatus(monitorable.file);
+ }
} else {
- monitorable.status = new DirStatus(monitorable.file, monitorable.path);
+ monitorable.status = new DirStatus(monitorable.file, monitorable.path, contentFileExtensions, contentFileCache);
}
}
/** The monitorable to hold the resource path, the file and the status. */
private static final class Monitorable {
public final String path;
- public final File file;
+ public final File file;
public Object status;
-
- public Monitorable(final String path, final File file) {
- this.path = path;
+ public Monitorable(final String path, final File file, String contentFileSuffix) {
this.file = file;
+ if (contentFileSuffix != null) {
+ this.path = StringUtils.substringBeforeLast(path, contentFileSuffix);
+ }
+ else {
+ this.path = path;
+ }
}
}
@@ -239,20 +321,30 @@ public class FileMonitor extends TimerTask {
this.lastModified = file.lastModified();
}
}
-
+
+ /** Status for content files */
+ private static class ContentFileStatus extends FileStatus {
+ public final ContentFile contentFile;
+ public ContentFileStatus(final File file, final ContentFile contentFile) {
+ super(file);
+ this.contentFile = contentFile;
+ }
+ }
+
/** Status for directories. */
private static final class DirStatus extends FileStatus {
public Monitorable[] children;
- public DirStatus(final File dir, final String path) {
+ public DirStatus(final File dir, final String path,
+ final ContentFileExtensions contentFileExtensions, final ContentFileCache contentFileCache) {
super(dir);
final File[] files = dir.listFiles();
if (files != null) {
this.children = new Monitorable[files.length];
for (int i = 0; i < files.length; i++) {
- this.children[i] = new Monitorable(path + '/'
- + files[i].getName(), files[i]);
- FileMonitor.createStatus(this.children[i]);
+ this.children[i] = new Monitorable(path + '/' + files[i].getName(), files[i],
+ contentFileExtensions.getSuffix(files[i]));
+ FileMonitor.createStatus(this.children[i], contentFileExtensions, contentFileCache);
}
} else {
this.children = new Monitorable[0];
@@ -264,4 +356,11 @@ public class FileMonitor extends TimerTask {
private static final class NonExistingStatus {
public static NonExistingStatus SINGLETON = new NonExistingStatus();
}
-}
\ No newline at end of file
+
+ static class ResourceChange {
+ public String path;
+ public String resourceType;
+ public String topic;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceMapper.java
new file mode 100644
index 0000000..4cb2c17
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceMapper.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import java.util.Iterator;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+
+/**
+ * Maps files to resources.
+ */
+public interface FsResourceMapper {
+
+ /**
+ * Get single resource.
+ * @param resolver Resource resolver
+ * @param resourcePath Resource path
+ * @return Resource or null if not exists
+ */
+ Resource getResource(ResourceResolver resolver, String resourcePath);
+
+ /**
+ * Get children of resource.
+ * @param resolver Resource resolver.
+ * @param parent Parent resource.
+ * @return Child resources or null if no children exist
+ */
+ Iterator<Resource> getChildren(ResourceResolver resolver, Resource parent);
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index 4b96f05..e3e3bad 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -19,101 +19,135 @@
package org.apache.sling.fsprovider.internal;
import java.io.File;
-import java.util.Collections;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
+import java.util.List;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.felix.scr.annotations.Service;
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceProvider;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.fsprovider.internal.mapper.ContentFileResourceMapper;
+import org.apache.sling.fsprovider.internal.mapper.FileResourceMapper;
+import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
+import org.apache.sling.fsprovider.internal.parser.ContentFileTypes;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.event.EventAdmin;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
/**
* The <code>FsResourceProvider</code> is a resource provider which maps
- * filesystem files and folders into the virtual resource tree. The provider is
+ * file system files and folders into the virtual resource tree. The provider is
* implemented in terms of a component factory, that is multiple instances of
* this provider may be created by creating respective configuration.
* <p>
* Each provider instance is configured with two properties: The location in the
- * resource tree where resources are provided ({@link ResourceProvider#ROOTS})
+ * resource tree where resources are provided (provider.root)
* and the file system path from where files and folders are mapped into the
- * resource ({@link #PROP_PROVIDER_FILE}).
+ * resource (provider.file).
*/
-@Component(
- name="org.apache.sling.fsprovider.internal.FsResourceProvider",
- label="%resource.resolver.name",
- description="%resource.resolver.description",
- configurationFactory=true,
- policy=ConfigurationPolicy.REQUIRE,
- metatype=true
- )
-@Service(ResourceProvider.class)
-@Properties({
- @Property(name="service.description", value="Sling Filesystem Resource Provider"),
- @Property(name="service.vendor", value="The Apache Software Foundation"),
- @Property(name=ResourceProvider.ROOTS),
- @Property(name = "webconsole.configurationFactory.nameHint",
- value = "Root paths: {" + ResourceProvider.ROOTS + "}")
-})
-public class FsResourceProvider implements ResourceProvider {
-
- /**
- * The name of the configuration property providing file system path of
- * files and folders mapped into the resource tree (value is
- * "provider.file").
- */
- @Property
- public static final String PROP_PROVIDER_FILE = "provider.file";
-
- /**
- * The name of the configuration property providing the check interval
- * for file changes (value is "provider.checkinterval").
- */
- @Property(longValue=FsResourceProvider.DEFAULT_CHECKINTERVAL)
- public static final String PROP_PROVIDER_CHECKINTERVAL = "provider.checkinterval";
-
- public static final long DEFAULT_CHECKINTERVAL = 1000;
+@Component(name="org.apache.sling.fsprovider.internal.FsResourceProvider",
+ service=ResourceProvider.class,
+ configurationPolicy=ConfigurationPolicy.REQUIRE,
+ property={
+ Constants.SERVICE_DESCRIPTION + "=Sling Filesystem Resource Provider",
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+ })
+@Designate(ocd=FsResourceProvider.Config.class, factory=true)
+public final class FsResourceProvider implements ResourceProvider {
+
+ @ObjectClassDefinition(name = "Apache Sling Filesystem Resource Provider",
+ description = "Configure an instance of the filesystem " +
+ "resource provider in terms of provider root and filesystem location")
+ public @interface Config {
+ /**
+ * The name of the configuration property providing file system path of
+ * files and folders mapped into the resource tree (value is
+ * "provider.file").
+ */
+ @AttributeDefinition(name = "Filesystem Root",
+ description = "Filesystem directory mapped to the virtual " +
+ "resource tree. This property must not be an empty string. If the path is " +
+ "relative it is resolved against sling.home or the current working directory. " +
+ "The path may be a file or folder. If the path does not address an existing " +
+ "file or folder, an empty folder is created.")
+ String provider_file();
+
+ /**
+ * The name of the configuration property providing the check interval
+ * for file changes (value is "provider.checkinterval").
+ */
+ @AttributeDefinition(name = "Check Interval",
+ description = "If the interval has a value higher than 100, the provider will " +
+ "check the file system for changes periodically. This interval defines the period in milliseconds " +
+ "(the default is 1000). If a change is detected, resource events are sent through the event admin.")
+ long provider_checkinterval() default 1000;
+
+ @AttributeDefinition(name = "Provider Roots",
+ description = "Locations in the virtual resource tree where the " +
+ "filesystem resources are mapped in. This property must contain at least one non-empty string.")
+ String[] provider_roots();
+
+ @AttributeDefinition(name = "Mount json",
+ description = "Mount .json files as content in the resource hierarchy.")
+ boolean provider_json_content();
+
+ @AttributeDefinition(name = "Mount jcr.xml",
+ description = "Mount .jcr.xml files as content in the resource hierarchy.")
+ boolean provider_jcrxml_content();
+
+ @AttributeDefinition(name = "Cache Size",
+ description = "Max. number of content files cached in memory.")
+ int provider_cache_size() default 1000;
+
+ /**
+ * Internal Name hint for web console.
+ */
+ String webconsole_configurationFactory_nameHint() default "Root paths: {" + ResourceProvider.ROOTS + "}";
+ }
// The location in the resource tree where the resources are mapped
private String providerRoot;
- // providerRoot + "/" to be used for prefix matching of paths
- private String providerRootPrefix;
-
// The "root" file or folder in the file system
private File providerFile;
- /** The monitor to detect file changes. */
+ // The monitor to detect file changes.
private FileMonitor monitor;
-
- @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
+
+ // maps filesystem to resources
+ private FsResourceMapper fileMapper;
+ private FsResourceMapper contentFileMapper;
+
+ // cache for parsed content files
+ private ContentFileCache contentFileCache;
+
+ @Reference(cardinality=ReferenceCardinality.OPTIONAL, policy=ReferencePolicy.DYNAMIC)
private volatile EventAdmin eventAdmin;
-
- /**
- * Same as {@link #getResource(ResourceResolver, String)}, i.e. the
- * <code>request</code> parameter is ignored.
- *
- * @see #getResource(ResourceResolver, String)
- */
- public Resource getResource(ResourceResolver resourceResolver,
- HttpServletRequest request, String path) {
+
+ @Override
+ public Resource getResource(ResourceResolver resourceResolver, HttpServletRequest request, String path) {
return getResource(resourceResolver, path);
}
/**
- * Returns a resource wrapping a filesystem file or folder for the given
+ * Returns a resource wrapping a file system file or folder for the given
* path. If the <code>path</code> is equal to the configured resource tree
* location of this provider, the configured file system file or folder is
* used for the resource. Otherwise the configured resource tree location
@@ -121,130 +155,107 @@ public class FsResourceProvider implements ResourceProvider {
* to access the file or folder. If no such file or folder exists, this
* method returns <code>null</code>.
*/
- public Resource getResource(ResourceResolver resourceResolver, String path) {
- return getResource(resourceResolver, path, getFile(path));
+ @Override
+ public Resource getResource(ResourceResolver resolver, String path) {
+ Resource rsrc = contentFileMapper.getResource(resolver, path);
+ if (rsrc == null) {
+ rsrc = fileMapper.getResource(resolver, path);
+ }
+ return rsrc;
}
-
+
/**
* Returns an iterator of resources.
*/
+ @SuppressWarnings("unchecked")
+ @Override
public Iterator<Resource> listChildren(Resource parent) {
- File parentFile = parent.adaptTo(File.class);
-
- // not a FsResource, try to create one from the resource
- if (parentFile == null) {
- // if the parent path is at or below the provider root, get
- // the respective file
- parentFile = getFile(parent.getPath());
-
- // if the parent path is actually the parent of the provider
- // root, return a single element iterator just containing the
- // provider file, unless the provider file is a directory and
- // a repository item with the same path actually exists
- if (parentFile == null) {
-
- String parentPath = parent.getPath().concat("/");
- if (providerRoot.startsWith(parentPath)) {
- String relPath = providerRoot.substring(parentPath.length());
- if (relPath.indexOf('/') < 0) {
- Resource res = getResource(
- parent.getResourceResolver(), providerRoot,
- providerFile);
- if (res != null) {
- return Collections.singletonList(res).iterator();
- }
- }
- }
-
- // no children here
- return null;
- }
+ ResourceResolver resolver = parent.getResourceResolver();
+
+ List<Iterator<Resource>> allChildren = new ArrayList<>();
+ Iterator<Resource> children;
+
+ children = contentFileMapper.getChildren(resolver, parent);
+ if (children != null) {
+ allChildren.add(children);
}
-
- final File[] children = parentFile.listFiles();
-
- if (children != null && children.length > 0) {
- final ResourceResolver resolver = parent.getResourceResolver();
- final String parentPath = parent.getPath();
- return new Iterator<Resource>() {
- int index = 0;
-
- Resource next = seek();
-
- public boolean hasNext() {
- return next != null;
- }
-
- public Resource next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- Resource result = next;
- next = seek();
- return result;
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
-
- private Resource seek() {
- while (index < children.length) {
- File file = children[index++];
- String path = parentPath + "/" + file.getName();
- Resource result = getResource(resolver, path, file);
- if (result != null) {
- return result;
- }
- }
-
- // nothing found any more
- return null;
- }
- };
+
+ children = fileMapper.getChildren(resolver, parent);
+ if (children != null) {
+ allChildren.add(children);
}
-
- // no children
- return null;
+
+ if (allChildren.isEmpty()) {
+ return null;
+ }
+ else if (allChildren.size() == 1) {
+ return allChildren.get(0);
+ }
+ else {
+ // merge all children from the different iterators, but filter out potential duplicates with same resource name
+ return IteratorUtils.filteredIterator(IteratorUtils.chainedIterator(allChildren), new Predicate() {
+ private Set<String> names = new HashSet<>();
+ @Override
+ public boolean evaluate(Object object) {
+ Resource resource = (Resource)object;
+ return names.add(resource.getName());
+ }
+ });
+ }
}
// ---------- SCR Integration
-
- protected void activate(BundleContext bundleContext, Map<?, ?> props) {
- String providerRoot = (String) props.get(ROOTS);
- if (providerRoot == null || providerRoot.length() == 0) {
- throw new IllegalArgumentException(ROOTS + " property must be set");
+ @Activate
+ protected void activate(BundleContext bundleContext, final Config config) {
+ String[] providerRoots = config.provider_roots();
+ if (providerRoots == null || providerRoots.length != 1 || StringUtils.isBlank(providerRoots[0])) {
+ throw new IllegalArgumentException("provider.roots property must be set to exactly one entry.");
}
+ String providerRoot = config.provider_roots()[0];
- String providerFileName = (String) props.get(PROP_PROVIDER_FILE);
+ String providerFileName = config.provider_file();
if (providerFileName == null || providerFileName.length() == 0) {
- throw new IllegalArgumentException(PROP_PROVIDER_FILE
- + " property must be set");
+ throw new IllegalArgumentException("provider.file property must be set");
}
this.providerRoot = providerRoot;
- this.providerRootPrefix = providerRoot.concat("/");
this.providerFile = getProviderFile(providerFileName, bundleContext);
- // start background monitor if check interval is higher than 100
- long checkInterval = DEFAULT_CHECKINTERVAL;
- final Object interval = props.get(PROP_PROVIDER_CHECKINTERVAL);
- if ( interval != null && interval instanceof Long ) {
- checkInterval = (Long)interval;
+
+ List<String> contentFileSuffixes = new ArrayList<>();
+ if (config.provider_json_content()) {
+ contentFileSuffixes.add(ContentFileTypes.JSON_SUFFIX);
}
- if ( checkInterval > 100 ) {
- this.monitor = new FileMonitor(this, checkInterval);
+ if (config.provider_jcrxml_content()) {
+ contentFileSuffixes.add(ContentFileTypes.JCR_XML_SUFFIX);
+ }
+ ContentFileExtensions contentFileExtensions = new ContentFileExtensions(contentFileSuffixes);
+
+ this.contentFileCache = new ContentFileCache(config.provider_cache_size());
+ this.fileMapper = new FileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions);
+ this.contentFileMapper = new ContentFileResourceMapper(this.providerRoot, this.providerFile,
+ contentFileExtensions, this.contentFileCache);
+
+ // start background monitor if check interval is higher than 100
+ if ( config.provider_checkinterval() > 100 ) {
+ this.monitor = new FileMonitor(this, config.provider_checkinterval(),
+ contentFileExtensions, this.contentFileCache);
}
}
+ @Deactivate
protected void deactivate() {
if ( this.monitor != null ) {
this.monitor.stop();
this.monitor = null;
}
this.providerRoot = null;
- this.providerRootPrefix = null;
this.providerFile = null;
+ this.fileMapper = null;
+ this.contentFileMapper = null;
+ if (this.contentFileCache != null) {
+ this.contentFileCache.clear();
+ this.contentFileCache = null;
+ }
}
EventAdmin getEventAdmin() {
@@ -288,41 +299,4 @@ public class FsResourceProvider implements ResourceProvider {
return providerFile;
}
- /**
- * Returns a file corresponding to the given absolute resource tree path. If
- * the path equals the configured provider root, the provider root file is
- * returned. If the path starts with the configured provider root, a file is
- * returned relative to the provider root file whose relative path is the
- * remains of the resource tree path without the provider root path.
- * Otherwise <code>null</code> is returned.
- */
- private File getFile(String path) {
- if (path.equals(providerRoot)) {
- return providerFile;
- }
-
- if (path.startsWith(providerRootPrefix)) {
- String relPath = path.substring(providerRootPrefix.length());
- return new File(providerFile, relPath);
- }
-
- return null;
- }
-
- private Resource getResource(ResourceResolver resourceResolver,
- String resourcePath, File file) {
-
- if (file != null) {
-
- // if the file exists, but is not a directory or no repository entry
- // exists, return it as a resource
- if (file.exists()) {
- return new FsResource(resourceResolver, resourcePath, file);
- }
-
- }
-
- // not applicable or not an existing file path
- return null;
- }
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
new file mode 100644
index 0000000..d31a851
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFile.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
+
+/**
+ * Reference to a file that contains a content fragment (e.g. JSON, JCR XML).
+ */
+public final class ContentFile {
+
+ private final File file;
+ private final String path;
+ private final String subPath;
+ private final ContentFileCache contentFileCache;
+ private boolean contentInitialized;
+ private Object content;
+ private ValueMap valueMap;
+
+ /**
+ * @param file File with content fragment
+ * @param path Root path of the content file
+ * @param subPath Relative path addressing content fragment inside file
+ * @param contentFileCache Content file cache
+ */
+ public ContentFile(File file, String path, String subPath, ContentFileCache contentFileCache) {
+ this.file = file;
+ this.path = path;
+ this.subPath = subPath;
+ this.contentFileCache = contentFileCache;
+ }
+
+ /**
+ * @param file File with content fragment
+ * @param path Root path of the content file
+ * @param subPath Relative path addressing content fragment inside file
+ * @param contentFileCache Content file cache
+ * @param content Content
+ */
+ public ContentFile(File file, String path, String subPath, ContentFileCache contentFileCache, Object content) {
+ this(file, path, subPath, contentFileCache);
+ this.contentInitialized = true;
+ this.content = content;
+ }
+
+ /**
+ * @return File with content fragment
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * @return Root path of content file
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * @return Relative path addressing content fragment inside file
+ */
+ public String getSubPath() {
+ return subPath;
+ }
+
+ /**
+ * Content object referenced by sub path.
+ * @return Map if resource, property value if property.
+ */
+ public Object getContent() {
+ if (!contentInitialized) {
+ Map<String,Object> rootContent = contentFileCache.get(path, file);
+ content = getDeepContent(rootContent, subPath);
+ contentInitialized = true;
+ }
+ return content;
+ }
+
+ /**
+ * @return true if any content was found.
+ */
+ public boolean hasContent() {
+ return getContent() != null;
+ }
+
+ /**
+ * @return true if content references resource map.
+ */
+ public boolean isResource() {
+ return (getContent() instanceof Map);
+ }
+
+ /**
+ * @return ValueMap for resource. Never null.
+ */
+ @SuppressWarnings("unchecked")
+ public ValueMap getValueMap() {
+ if (valueMap == null) {
+ Object currentContent = getContent();
+ if (currentContent instanceof Map) {
+ valueMap = ValueMapUtil.toValueMap((Map<String,Object>)currentContent);
+ }
+ else {
+ valueMap = ValueMap.EMPTY;
+ }
+ }
+ return valueMap;
+ }
+
+ /**
+ * Navigate to another sub path position in content file.
+ * @param newSubPath New sub path
+ * @return Content file
+ */
+ public ContentFile navigateTo(String newSubPath) {
+ return new ContentFile(file, path, newSubPath, contentFileCache);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Object getDeepContent(Object object, String subPath) {
+ if (object == null) {
+ return null;
+ }
+ if (subPath == null) {
+ return object;
+ }
+ if (!(object instanceof Map)) {
+ return null;
+ }
+ String name;
+ String remainingSubPath;
+ int slashIndex = subPath.indexOf('/');
+ if (slashIndex >= 0) {
+ name = subPath.substring(0, slashIndex);
+ remainingSubPath = subPath.substring(slashIndex + 1);
+ }
+ else {
+ name = subPath;
+ remainingSubPath = null;
+ }
+ Object subObject = ((Map<String,Object>)object).get(name);
+ return getDeepContent(subObject, remainingSubPath);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java
new file mode 100644
index 0000000..622deba
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResource.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import javax.jcr.Node;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.mapper.jcr.FsNode;
+
+/**
+ * Represents a JSON File with resource content.
+ */
+public final class ContentFileResource extends AbstractResource {
+
+ // the owning resource resolver
+ private final ResourceResolver resolver;
+
+ // the path of this resource in the resource tree
+ private final String resourcePath;
+
+ // the file wrapped by this instance
+ private final ContentFile contentFile;
+
+ // the resource type, assigned on demand
+ private String resourceType;
+ private String resourceSuperType;
+
+ // the resource metadata, assigned on demand
+ private ResourceMetadata metaData;
+
+ /**
+ * @param resolver The owning resource resolver
+ * @param resourcePath The resource path in the resource tree
+ * @param contentFile Content file with sub path
+ */
+ ContentFileResource(ResourceResolver resolver, ContentFile contentFile) {
+ this.resolver = resolver;
+ this.contentFile = contentFile;
+ this.resourcePath = contentFile.getPath()
+ + (contentFile.getSubPath() != null ? "/" + contentFile.getSubPath() : "");
+ }
+
+ public String getPath() {
+ return resourcePath;
+ }
+
+ public ResourceMetadata getResourceMetadata() {
+ if (metaData == null) {
+ metaData = new ResourceMetadata();
+ metaData.setModificationTime(contentFile.getFile().lastModified());
+ metaData.setResolutionPath(resourcePath);
+ }
+ return metaData;
+ }
+
+ public ResourceResolver getResourceResolver() {
+ return resolver;
+ }
+
+ public String getResourceSuperType() {
+ if (resourceSuperType == null) {
+ resourceSuperType = ResourceUtil.getValueMap(this).get("sling:resourceSuperType", String.class);
+ }
+ return resourceSuperType;
+ }
+
+ public String getResourceType() {
+ if (resourceType == null) {
+ ValueMap props = ResourceUtil.getValueMap(this);
+ resourceType = props.get("sling:resourceType", String.class);
+ if (resourceType == null) {
+ // fallback to jcr:primaryType when resource type not set
+ resourceType = props.get("jcr:primaryType", String.class);
+ }
+ }
+ return resourceType;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ if (type == ContentFile.class) {
+ return (AdapterType)this.contentFile;
+ }
+ else if (type == ValueMap.class) {
+ return (AdapterType)contentFile.getValueMap();
+ }
+ else if (type == Node.class && contentFile.isResource()) {
+ // support a subset of JCR API for content file resources
+ return (AdapterType)new FsNode(contentFile, getResourceResolver());
+ }
+ return super.adaptTo(type);
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("path", resourcePath)
+ .append("file", contentFile.getFile().getPath())
+ .append("subPath", contentFile.getSubPath())
+ .append("resourceType", getResourceType())
+ .build();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
new file mode 100644
index 0000000..e6edd04
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ContentFileResourceMapper.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.fsprovider.internal.ContentFileExtensions;
+import org.apache.sling.fsprovider.internal.FsResourceMapper;
+import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
+
+public final class ContentFileResourceMapper implements FsResourceMapper {
+
+ // providerRoot + "/" to be used for prefix matching of paths
+ private final String providerRootPrefix;
+
+ // The "root" file or folder in the file system
+ private final File providerFile;
+
+ private final ContentFileExtensions contentFileExtensions;
+ private final ContentFileCache contentFileCache;
+
+ public ContentFileResourceMapper(String providerRoot, File providerFile,
+ ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache) {
+ this.providerRootPrefix = providerRoot.concat("/");
+ this.providerFile = providerFile;
+ this.contentFileExtensions = contentFileExtensions;
+ this.contentFileCache = contentFileCache;
+ }
+
+ @Override
+ public Resource getResource(final ResourceResolver resolver, final String resourcePath) {
+ if (contentFileExtensions.isEmpty()) {
+ return null;
+ }
+ ContentFile contentFile = getFile(resourcePath, null);
+ if (contentFile != null && contentFile.hasContent()) {
+ return new ContentFileResource(resolver, contentFile);
+ }
+ else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
+ if (contentFileExtensions.isEmpty()) {
+ return null;
+ }
+ final String parentPath = parent.getPath();
+ ContentFile parentContentFile = parent.adaptTo(ContentFile.class);
+
+ // not a FsResource, try to create one from the resource
+ if (parentContentFile == null) {
+ parentContentFile = getFile(parentPath, null);
+ if (parentContentFile == null) {
+
+ // check if parent is a file resource that contains a file content resource
+ File parentFile = parent.adaptTo(File.class);
+ if (parentFile != null && parentFile.isDirectory()) {
+ List<Resource> childResources = new ArrayList<>();
+ for (File file : parentFile.listFiles()) {
+ String filenameSuffix = contentFileExtensions.getSuffix(file);
+ if (filenameSuffix != null) {
+ String path = parentPath + "/" + StringUtils.substringBeforeLast(file.getName(), filenameSuffix);
+ ContentFile contentFile = new ContentFile(file, path, null, contentFileCache);
+ childResources.add(new ContentFileResource(resolver, contentFile));
+ }
+ }
+ if (!childResources.isEmpty()) {
+ return childResources.iterator();
+ }
+ }
+
+ // no children here
+ return null;
+ }
+ }
+
+ // get child resources from content fragments in content file
+ List<ContentFile> children = new ArrayList<>();
+ if (parentContentFile.hasContent() && parentContentFile.isResource()) {
+ Map<String,Object> content = (Map<String,Object>)parentContentFile.getContent();
+ for (Map.Entry<String, Object> entry: content.entrySet()) {
+ if (entry.getValue() instanceof Map) {
+ String subPath;
+ if (parentContentFile.getSubPath() == null) {
+ subPath = entry.getKey();
+ }
+ else {
+ subPath = parentContentFile.getSubPath() + "/" + entry.getKey();
+ }
+ children.add(new ContentFile(parentContentFile.getFile(), parentContentFile.getPath(), subPath, contentFileCache, entry.getValue()));
+ }
+ }
+ }
+ if (children.isEmpty()) {
+ return null;
+ }
+ else {
+ return IteratorUtils.transformedIterator(children.iterator(), new Transformer() {
+ @Override
+ public Object transform(Object input) {
+ ContentFile contentFile = (ContentFile)input;
+ return new ContentFileResource(resolver, contentFile);
+ }
+ });
+ }
+ }
+
+ private ContentFile getFile(String path, String subPath) {
+ if (!StringUtils.startsWith(path, providerRootPrefix)) {
+ return null;
+ }
+ String relPath = path.substring(providerRootPrefix.length());
+ for (String filenameSuffix : contentFileExtensions.getSuffixes()) {
+ File file = new File(providerFile, relPath + filenameSuffix);
+ if (file.exists()) {
+ return new ContentFile(file, path, subPath, contentFileCache);
+ }
+ }
+ // try to find in parent path which contains content fragment
+ String parentPath = ResourceUtil.getParent(path);
+ String nextSubPath = path.substring(parentPath.length() + 1)
+ + (subPath != null ? "/" + subPath : "");
+ return getFile(parentPath, nextSubPath);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
similarity index 79%
rename from src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
rename to src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
index 1397045..67cd178 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResource.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResource.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.fsprovider.internal;
+package org.apache.sling.fsprovider.internal.mapper;
import java.io.File;
import java.io.FileInputStream;
@@ -28,6 +28,8 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.sling.adapter.annotations.Adaptable;
import org.apache.sling.adapter.annotations.Adapter;
import org.apache.sling.api.resource.AbstractResource;
@@ -47,22 +49,19 @@ import org.slf4j.LoggerFactory;
@Adapter({File.class, URL.class}),
@Adapter(condition="If the resource is an FsResource and is a readable file.", value=InputStream.class)
})
-public class FsResource extends AbstractResource {
+public final class FileResource extends AbstractResource {
/**
* The resource type for file system files mapped into the resource tree by
* the {@link FsResourceProvider} (value is "nt:file").
*/
- static final String RESOURCE_TYPE_FILE = "nt:file";
+ public static final String RESOURCE_TYPE_FILE = "nt:file";
/**
* The resource type for file system folders mapped into the resource tree
* by the {@link FsResourceProvider} (value is "nt:folder").
*/
- static final String RESOURCE_TYPE_FOLDER = "nt:folder";
-
- // default log, assigned on demand
- private Logger log;
+ public static final String RESOURCE_TYPE_FOLDER = "nt:folder";
// the owning resource resolver
private final ResourceResolver resolver;
@@ -79,6 +78,8 @@ public class FsResource extends AbstractResource {
// the resource metadata, assigned on demand
private ResourceMetadata metaData;
+ private static final Logger log = LoggerFactory.getLogger(FileResource.class);
+
/**
* Creates an instance of this Filesystem resource.
*
@@ -86,7 +87,7 @@ public class FsResource extends AbstractResource {
* @param resourcePath The resource path in the resource tree
* @param file The wrapped file
*/
- FsResource(ResourceResolver resolver, String resourcePath, File file) {
+ FileResource(ResourceResolver resolver, String resourcePath, File file) {
this.resolver = resolver;
this.resourcePath = resourcePath;
this.file = file;
@@ -139,11 +140,8 @@ public class FsResource extends AbstractResource {
*/
public String getResourceType() {
if (resourceType == null) {
- resourceType = file.isFile()
- ? RESOURCE_TYPE_FILE
- : RESOURCE_TYPE_FOLDER;
+ resourceType = file.isFile() ? RESOURCE_TYPE_FILE : RESOURCE_TYPE_FOLDER;
}
-
return resourceType;
}
@@ -156,39 +154,31 @@ public class FsResource extends AbstractResource {
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (type == File.class) {
-
return (AdapterType) file;
-
- } else if (type == InputStream.class) {
-
+ }
+ else if (type == InputStream.class) {
if (!file.isDirectory() && file.canRead()) {
-
try {
return (AdapterType) new FileInputStream(file);
- } catch (IOException ioe) {
- getLog().info(
- "adaptTo: Cannot open a stream on the file " + file,
- ioe);
}
-
- } else {
-
- getLog().debug("adaptTo: File {} is not a readable file", file);
-
+ catch (IOException ioe) {
+ log.info("adaptTo: Cannot open a stream on the file " + file, ioe);
+ }
}
-
- } else if (type == URL.class) {
-
+ else {
+ log.debug("adaptTo: File {} is not a readable file", file);
+ }
+ }
+ else if (type == URL.class) {
try {
return (AdapterType) file.toURI().toURL();
- } catch (MalformedURLException mue) {
- getLog().info(
- "adaptTo: Cannot convert the file path " + file
- + " to an URL", mue);
+ }
+ catch (MalformedURLException mue) {
+ log.info("adaptTo: Cannot convert the file path " + file + " to an URL", mue);
}
- } else if (type == ValueMap.class) {
-
+ }
+ 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()) {
@@ -200,18 +190,17 @@ public class FsResource extends AbstractResource {
props.put("jcr:created", lastModifed);
return (AdapterType) new ValueMapDecorator(props);
}
-
}
-
return super.adaptTo(type);
}
- // ---------- internal
-
- private Logger getLog() {
- if (log == null) {
- log = LoggerFactory.getLogger(getClass());
- }
- return log;
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("path", resourcePath)
+ .append("file", file.getPath())
+ .append("resourceType", getResourceType())
+ .build();
}
+
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResourceMapper.java
new file mode 100644
index 0000000..12b0f7a
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResourceMapper.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import java.io.File;
+import java.util.Iterator;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.fsprovider.internal.ContentFileExtensions;
+import org.apache.sling.fsprovider.internal.FsResourceMapper;
+
+public final class FileResourceMapper implements FsResourceMapper {
+
+ // The location in the resource tree where the resources are mapped
+ private final String providerRoot;
+
+ // providerRoot + "/" to be used for prefix matching of paths
+ private final String providerRootPrefix;
+
+ // The "root" file or folder in the file system
+ private final File providerFile;
+
+ private final ContentFileExtensions contentFileExtensions;
+
+ public FileResourceMapper(String providerRoot, File providerFile, ContentFileExtensions contentFileExtensions) {
+ this.providerRoot = providerRoot;
+ this.providerRootPrefix = providerRoot.concat("/");
+ this.providerFile = providerFile;
+ this.contentFileExtensions = contentFileExtensions;
+ }
+
+ @Override
+ public Resource getResource(final ResourceResolver resolver, final String resourcePath) {
+ File file = getFile(resourcePath);
+ if (file != null) {
+ return new FileResource(resolver, resourcePath, file);
+ }
+ else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
+ final String parentPath = parent.getPath();
+ File parentFile = parent.adaptTo(File.class);
+
+ // not a FsResource, try to create one from the resource
+ if (parentFile == null) {
+ // if the parent path is at or below the provider root, get
+ // the respective file
+ parentFile = getFile(parentPath);
+
+ // if the parent path is actually the parent of the provider
+ // root, return a single element iterator just containing the
+ // provider file, unless the provider file is a directory and
+ // a repository item with the same path actually exists
+ if (parentFile == null) {
+
+ if (providerFile.exists() && !StringUtils.startsWith(parentPath, providerRoot)) {
+ String parentPathPrefix = parentPath.concat("/");
+ if (providerRoot.startsWith(parentPathPrefix)) {
+ String relPath = providerRoot.substring(parentPathPrefix.length());
+ if (relPath.indexOf('/') < 0) {
+ Resource res = new FileResource(resolver, providerRoot, providerFile);
+ return IteratorUtils.singletonIterator(res);
+ }
+ }
+ }
+
+ // no children here
+ return null;
+ }
+ }
+
+ // ensure parent is a directory
+ if (!parentFile.isDirectory()) {
+ return null;
+ }
+
+ Iterator<File> children = IteratorUtils.filteredIterator(IteratorUtils.arrayIterator(parentFile.listFiles()), new Predicate() {
+ @Override
+ public boolean evaluate(Object object) {
+ File file = (File)object;
+ return !contentFileExtensions.matchesSuffix(file);
+ }
+ });
+ if (!children.hasNext()) {
+ return null;
+ }
+ return IteratorUtils.transformedIterator(children, new Transformer() {
+ @Override
+ public Object transform(Object input) {
+ File file = (File)input;
+ String path = parentPath + "/" + file.getName();
+ return new FileResource(resolver, path, file);
+ }
+ });
+ }
+
+ /**
+ * Returns a file corresponding to the given absolute resource tree path. If
+ * the path equals the configured provider root, the provider root file is
+ * returned. If the path starts with the configured provider root, a file is
+ * returned relative to the provider root file whose relative path is the
+ * remains of the resource tree path without the provider root path.
+ * Otherwise <code>null</code> is returned.
+ */
+ private File getFile(String path) {
+ if (path.equals(providerRoot)) {
+ return providerFile;
+ }
+ if (path.startsWith(providerRootPrefix)) {
+ String relPath = path.substring(providerRootPrefix.length());
+ File file = new File(providerFile, relPath);
+ if (file.exists() && !contentFileExtensions.matchesSuffix(file)) {
+ return file;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
new file mode 100644
index 0000000..8ddbda7
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+
+final class ValueMapUtil {
+
+ private ValueMapUtil() {
+ // static methods only
+ }
+
+ /**
+ * Convert map to value map.
+ * @param content Content map.
+ * @return Value map.
+ */
+ public static ValueMap toValueMap(Map<String,Object> content) {
+ Map<String,Object> props = new HashMap<>();
+
+ for (Map.Entry<String, Object> entry : ((Map<String,Object>)content).entrySet()) {
+ if (entry.getValue() instanceof Map) {
+ // skip child resources
+ continue;
+ }
+ else if (entry.getValue() instanceof Collection) {
+ // convert lists to arrays
+ props.put(entry.getKey(), ((Collection)entry.getValue()).toArray());
+ }
+ else {
+ props.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ // fallback to default jcr:primaryType is none is set
+ if (!props.containsKey("jcr:primaryType")) {
+ props.put("jcr:primaryType", NodeType.NT_UNSTRUCTURED);
+ }
+
+ return new ValueMapDecorator(props);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsItem.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsItem.java
new file mode 100644
index 0000000..d5689a9
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsItem.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+
+/**
+ * Simplified implementation of read-only content access via the JCR API.
+ */
+abstract class FsItem implements Item {
+
+ protected final ContentFile contentFile;
+ protected final ResourceResolver resolver;
+ protected final ValueMap props;
+
+ public FsItem(ContentFile contentFile, ResourceResolver resolver) {
+ this.contentFile = contentFile;
+ this.resolver = resolver;
+ this.props = contentFile.getValueMap();
+ }
+
+ @Override
+ public String getPath() throws RepositoryException {
+ if (contentFile.getSubPath() == null) {
+ return contentFile.getPath();
+ }
+ else {
+ return contentFile.getPath() + "/" + contentFile.getSubPath();
+ }
+ }
+
+ @Override
+ public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
+ String path;
+ if (depth == 0) {
+ path = "/";
+ }
+ else {
+ String[] pathParts = StringUtils.splitPreserveAllTokens(getPath(), "/");
+ path = StringUtils.join(pathParts, "/", 0, depth + 1);
+ }
+ Resource resource = resolver.getResource(path);
+ if (resource != null) {
+ Node refNode = resource.adaptTo(Node.class);
+ if (refNode != null) {
+ return refNode;
+ }
+ }
+ throw new ItemNotFoundException();
+ }
+
+ @Override
+ public int getDepth() throws RepositoryException {
+ if (StringUtils.equals("/", getPath())) {
+ return 0;
+ } else {
+ return StringUtils.countMatches(getPath(), "/");
+ }
+ }
+
+ @Override
+ public Session getSession() throws RepositoryException {
+ return resolver.adaptTo(Session.class);
+ }
+
+ @Override
+ public boolean isNode() {
+ return (this instanceof Node);
+ }
+
+ @Override
+ public boolean isNew() {
+ return false;
+ }
+
+ @Override
+ public boolean isModified() {
+ return false;
+ }
+
+ @Override
+ public boolean isSame(Item otherItem) throws RepositoryException {
+ return StringUtils.equals(getPath(), otherItem.getPath());
+ }
+
+ @Override
+ public void accept(ItemVisitor visitor) throws RepositoryException {
+ // do nothing
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("path", getPath())
+ .build();
+ }
+ catch (RepositoryException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+
+ // --- unsupported methods ---
+
+ @Override
+ public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException,
+ InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException,
+ NoSuchNodeTypeException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void refresh(boolean keepChanges) throws InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException,
+ RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java
new file mode 100644
index 0000000..6f52691
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNode.java
@@ -0,0 +1,549 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Binary;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.InvalidLifecycleTransitionException;
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.MergeException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.ActivityViolationException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+
+/**
+ * Simplified implementation of read-only content access via the JCR API.
+ */
+public final class FsNode extends FsItem implements Node {
+
+ public FsNode(ContentFile contentFile, ResourceResolver resolver) {
+ super(contentFile, resolver);
+ }
+
+ private String getPrimaryTypeName() {
+ return props.get("jcr:primaryType", String.class);
+ }
+
+ private String[] getMixinTypeNames() {
+ return props.get("jcr:mixinTypes", new String[0]);
+ }
+
+ @Override
+ public String getName() throws RepositoryException {
+ if (contentFile.getSubPath() == null) {
+ return ResourceUtil.getName(contentFile.getPath());
+ }
+ else {
+ return ResourceUtil.getName(contentFile.getSubPath());
+ }
+ }
+
+ @Override
+ public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
+ return getNode(ResourceUtil.getParent(getPath()));
+ }
+
+ @Override
+ public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
+ if (relPath == null) {
+ throw new PathNotFoundException();
+ }
+
+ // get absolute node path
+ String path = relPath;
+ if (!StringUtils.startsWith(path, "/")) {
+ path = ResourceUtil.normalize(getPath() + "/" + relPath);
+ }
+
+ if (StringUtils.equals(path, contentFile.getPath()) || StringUtils.startsWith(path, contentFile.getPath() + "/")) {
+ // node is contained in content file
+ String subPath;
+ if (StringUtils.equals(path, contentFile.getPath())) {
+ subPath = null;
+ }
+ else {
+ subPath = path.substring(contentFile.getPath().length() + 1);
+ }
+ ContentFile referencedFile = contentFile.navigateTo(subPath);
+ if (referencedFile.hasContent()) {
+ return new FsNode(referencedFile, resolver);
+ }
+ }
+ else {
+ // node is outside content file
+ Node refNode = null;
+ Resource resource = resolver.getResource(path);
+ if (resource != null) {
+ refNode = resource.adaptTo(Node.class);
+ if (refNode != null) {
+ return refNode;
+ }
+ }
+ }
+ throw new PathNotFoundException(relPath);
+ }
+
+ @Override
+ public NodeIterator getNodes() throws RepositoryException {
+ return new FsNodeIterator(contentFile, resolver);
+ }
+
+ @Override
+ public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
+ if (props.containsKey(relPath)) {
+ return new FsProperty(contentFile, resolver, relPath, this);
+ }
+ throw new PathNotFoundException(relPath);
+ }
+
+ @Override
+ public PropertyIterator getProperties() throws RepositoryException {
+ return new FsPropertyIterator(props.keySet().iterator(), contentFile, resolver, this);
+ }
+
+ @Override
+ public String getUUID() throws UnsupportedRepositoryOperationException, RepositoryException {
+ String uuid = props.get("jcr:uuid", String.class);
+ if (uuid != null) {
+ return uuid;
+ }
+ else {
+ throw new UnsupportedRepositoryOperationException();
+ }
+ }
+
+ @Override
+ public boolean hasNode(String relPath) throws RepositoryException {
+ try {
+ getNode(relPath);
+ return true;
+ }
+ catch (RepositoryException ex) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean hasProperty(String relPath) throws RepositoryException {
+ return props.containsKey(relPath);
+ }
+
+ @Override
+ public boolean hasNodes() throws RepositoryException {
+ return getNodes().hasNext();
+ }
+
+ @Override
+ public boolean hasProperties() throws RepositoryException {
+ return !props.isEmpty();
+ }
+
+ @Override
+ public boolean isNodeType(String nodeTypeName) throws RepositoryException {
+ return StringUtils.equals(nodeTypeName, getPrimaryTypeName());
+ }
+
+ @Override
+ public boolean canAddMixin(String mixinName) throws NoSuchNodeTypeException, RepositoryException {
+ return false;
+ }
+
+ @Override
+ public boolean isCheckedOut() throws RepositoryException {
+ return false;
+ }
+
+ @Override
+ public boolean holdsLock() throws RepositoryException {
+ return false;
+ }
+
+ @Override
+ public boolean isLocked() throws RepositoryException {
+ return false;
+ }
+
+ @Override
+ public NodeType getPrimaryNodeType() throws RepositoryException {
+ return new FsNodeType(getPrimaryTypeName(), false);
+ }
+
+ @Override
+ public NodeType[] getMixinNodeTypes() throws RepositoryException {
+ String[] mixinTypeNames = getMixinTypeNames();
+ NodeType[] mixinTypes = new NodeType[mixinTypeNames.length];
+ for (int i=0; i<mixinTypeNames.length; i++) {
+ mixinTypes[i] = new FsNodeType(mixinTypeNames[i], true);
+ }
+ return mixinTypes;
+ }
+
+
+ // --- unsupported methods ---
+
+ @Override
+ public Node addNode(String relPath) throws ItemExistsException, PathNotFoundException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Node addNode(String relPath, String primaryNodeTypeName)
+ throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void orderBefore(String srcChildRelPath, String destChildRelPath)
+ throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException,
+ ItemNotFoundException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Value value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Value value, int type) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Value[] values) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Value[] values, int type) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, String[] values) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, String[] values, int type) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, String value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, String value, int type) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, InputStream value) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Binary value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, boolean value) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, double value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, BigDecimal value) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, long value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Calendar value) throws ValueFormatException, VersionException,
+ LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property setProperty(String name, Node value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyIterator getReferences() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyIterator getReferences(String name) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyIterator getWeakReferences() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyIterator getWeakReferences(String name) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setPrimaryType(String nodeTypeName) throws NoSuchNodeTypeException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addMixin(String mixinName) throws NoSuchNodeTypeException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeMixin(String mixinName) throws NoSuchNodeTypeException, VersionException,
+ ConstraintViolationException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeDefinition getDefinition() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Version checkin() throws VersionException, UnsupportedRepositoryOperationException,
+ InvalidItemStateException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void checkout() throws UnsupportedRepositoryOperationException, LockException, ActivityViolationException,
+ RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void doneMerge(Version version) throws VersionException, InvalidItemStateException,
+ UnsupportedRepositoryOperationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void cancelMerge(Version version) throws VersionException, InvalidItemStateException,
+ UnsupportedRepositoryOperationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void update(String srcWorkspace) throws NoSuchWorkspaceException, AccessDeniedException, LockException,
+ InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeIterator merge(String srcWorkspace, boolean bestEffort) throws NoSuchWorkspaceException,
+ AccessDeniedException, MergeException, LockException, InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getCorrespondingNodePath(String workspaceName)
+ throws ItemNotFoundException, NoSuchWorkspaceException, AccessDeniedException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeIterator getSharedSet() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeSharedSet()
+ throws VersionException, LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeShare()
+ throws VersionException, LockException, ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void restore(String versionName, boolean removeExisting) throws VersionException, ItemExistsException,
+ UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void restore(Version version, boolean removeExisting) throws VersionException, ItemExistsException,
+ InvalidItemStateException, UnsupportedRepositoryOperationException, LockException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void restore(Version version, String relPath, boolean removeExisting)
+ throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException,
+ UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void restoreByLabel(String versionLabel, boolean removeExisting)
+ throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException,
+ InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public VersionHistory getVersionHistory() throws UnsupportedRepositoryOperationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Version getBaseVersion() throws UnsupportedRepositoryOperationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException,
+ LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Lock getLock()
+ throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void unlock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException,
+ InvalidItemStateException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void followLifecycleTransition(String transition)
+ throws UnsupportedRepositoryOperationException, InvalidLifecycleTransitionException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String[] getAllowedLifecycleTransistions()
+ throws UnsupportedRepositoryOperationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeIterator getNodes(String namePattern) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeIterator getNodes(String[] nameGlobs) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getIdentifier() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getIndex() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyIterator getProperties(String namePattern) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyIterator getProperties(String[] nameGlobs) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
new file mode 100644
index 0000000..f03b0a7
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeIterator.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+
+/**
+ * Simplified implementation of read-only content access via the JCR API.
+ */
+class FsNodeIterator implements NodeIterator {
+
+ private final ContentFile contentFile;
+ private final ResourceResolver resolver;
+ private final Iterator<Map.Entry<String,Map<String,Object>>> children;
+
+ @SuppressWarnings("unchecked")
+ public FsNodeIterator(ContentFile contentFile, ResourceResolver resolver) {
+ this.contentFile = contentFile;
+ this.resolver = resolver;
+ Map<String,Object> content = (Map<String,Object>)contentFile.getContent();
+ this.children = IteratorUtils.filteredIterator(content.entrySet().iterator(), new Predicate() {
+ @Override
+ public boolean evaluate(Object object) {
+ Map.Entry<String,Object> entry = (Map.Entry<String,Object>)object;
+ return (entry.getValue() instanceof Map);
+ }
+ });
+ }
+
+ public boolean hasNext() {
+ return children.hasNext();
+ }
+
+ public Object next() {
+ return nextNode();
+ }
+
+ @Override
+ public Node nextNode() {
+ Map.Entry<String,Map<String,Object>> nextEntry = children.next();
+ String subPath;
+ if (contentFile.getSubPath() == null) {
+ subPath = nextEntry.getKey();
+ }
+ else {
+ subPath = contentFile.getSubPath() + "/" + nextEntry.getKey();
+ }
+ return new FsNode(contentFile.navigateTo(subPath), resolver);
+ }
+
+
+ // --- unsupported methods ---
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void skip(long skipNum) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getSize() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getPosition() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeType.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeType.java
new file mode 100644
index 0000000..8d60812
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsNodeType.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import org.apache.commons.lang3.StringUtils;
+
+class FsNodeType implements NodeType {
+
+ private final String name;
+ private final boolean mixin;
+
+ public FsNodeType(String name, boolean mixin) {
+ this.name = name;
+ this.mixin = mixin;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String[] getDeclaredSupertypeNames() {
+ return new String[0];
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return false;
+ }
+
+ @Override
+ public boolean isMixin() {
+ return mixin;
+ }
+
+ @Override
+ public boolean hasOrderableChildNodes() {
+ return false;
+ }
+
+ @Override
+ public boolean isQueryable() {
+ return false;
+ }
+
+ @Override
+ public String getPrimaryItemName() {
+ return null;
+ }
+
+ @Override
+ public NodeType[] getSupertypes() {
+ return new NodeType[0];
+ }
+
+ @Override
+ public NodeType[] getDeclaredSupertypes() {
+ return new NodeType[0];
+ }
+
+ @Override
+ public boolean isNodeType(String nodeTypeName) {
+ return StringUtils.equals(name, nodeTypeName);
+ }
+
+
+ // --- unsupported methods ---
+
+ @Override
+ public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeTypeIterator getSubtypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeTypeIterator getDeclaredSubtypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public PropertyDefinition[] getPropertyDefinitions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public NodeDefinition[] getChildNodeDefinitions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canSetProperty(String propertyName, Value value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canSetProperty(String propertyName, Value[] values) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canAddChildNode(String childNodeName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canRemoveItem(String itemName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canRemoveNode(String nodeName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canRemoveProperty(String propertyName) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsProperty.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsProperty.java
new file mode 100644
index 0000000..bf24aa7
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsProperty.java
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Binary;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.version.VersionException;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+
+/**
+ * Simplified implementation of read-only content access via the JCR API.
+ */
+class FsProperty extends FsItem implements Property {
+
+ private final String propertyName;
+ private final Node node;
+
+ public FsProperty(ContentFile contentFile, ResourceResolver resolver, String propertyName, Node node) {
+ super(contentFile, resolver);
+ this.propertyName = propertyName;
+ this.node = node;
+ }
+
+ @Override
+ public String getName() throws RepositoryException {
+ return propertyName;
+ }
+
+ @Override
+ public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
+ return getNode();
+ }
+
+ @Override
+ public Node getNode() throws ItemNotFoundException, ValueFormatException, RepositoryException {
+ return node;
+ }
+
+ @Override
+ public String getPath() throws RepositoryException {
+ return super.getPath() + "/" + propertyName;
+ }
+
+ @Override
+ public Value getValue() throws ValueFormatException, RepositoryException {
+ return new FsValue(props, propertyName);
+ }
+
+ @Override
+ public String getString() throws ValueFormatException, RepositoryException {
+ return getValue().getString();
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public InputStream getStream() throws ValueFormatException, RepositoryException {
+ return getValue().getStream();
+ }
+
+ @Override
+ public Binary getBinary() throws ValueFormatException, RepositoryException {
+ return getValue().getBinary();
+ }
+
+ @Override
+ public long getLong() throws ValueFormatException, RepositoryException {
+ return getValue().getLong();
+ }
+
+ @Override
+ public double getDouble() throws ValueFormatException, RepositoryException {
+ return getValue().getDouble();
+ }
+
+ @Override
+ public BigDecimal getDecimal() throws ValueFormatException, RepositoryException {
+ return getValue().getDecimal();
+ }
+
+ @Override
+ public Calendar getDate() throws ValueFormatException, RepositoryException {
+ return getValue().getDate();
+ }
+
+ @Override
+ public boolean getBoolean() throws ValueFormatException, RepositoryException {
+ return getValue().getBoolean();
+ }
+
+ @Override
+ public Value[] getValues() throws ValueFormatException, RepositoryException {
+ if (!isMultiple()) {
+ throw new ValueFormatException();
+ }
+ Object value = props.get(propertyName);
+ int size = Array.getLength(value);
+ Value[] result = new Value[size];
+ for (int i=0; i<size; i++) {
+ result[i] = new FsValue(props, propertyName, i);
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isMultiple() throws RepositoryException {
+ Object value = props.get(propertyName);
+ return value != null && value.getClass().isArray();
+ }
+
+ @Override
+ public int getType() throws RepositoryException {
+ return getValue().getType();
+ }
+
+ @Override
+ public PropertyDefinition getDefinition() throws RepositoryException {
+ return new FsPropertyDefinition(propertyName);
+ }
+
+
+ // --- unsupported methods ---
+
+ @Override
+ public void setValue(Value value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(Value[] values) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(String value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(String[] values) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(InputStream value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(Binary value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(long value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(double value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(BigDecimal value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(Calendar value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(boolean value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setValue(Node value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Property getProperty() throws ItemNotFoundException, ValueFormatException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getLength() throws ValueFormatException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long[] getLengths() throws ValueFormatException, RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsPropertyDefinition.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsPropertyDefinition.java
new file mode 100644
index 0000000..85920cb
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsPropertyDefinition.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import javax.jcr.PropertyType;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.version.OnParentVersionAction;
+
+class FsPropertyDefinition implements PropertyDefinition {
+
+ private final String name;
+
+ public FsPropertyDefinition(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public NodeType getDeclaringNodeType() {
+ return null;
+ }
+
+ @Override
+ public boolean isAutoCreated() {
+ return false;
+ }
+
+ @Override
+ public boolean isMandatory() {
+ return false;
+ }
+
+ @Override
+ public int getOnParentVersion() {
+ return OnParentVersionAction.COPY;
+ }
+
+ @Override
+ public boolean isProtected() {
+ return false;
+ }
+
+ @Override
+ public int getRequiredType() {
+ return PropertyType.UNDEFINED;
+ }
+
+ @Override
+ public String[] getValueConstraints() {
+ return new String[0];
+ }
+
+ @Override
+ public Value[] getDefaultValues() {
+ return new Value[0];
+ }
+
+ @Override
+ public boolean isMultiple() {
+ return false;
+ }
+
+ @Override
+ public String[] getAvailableQueryOperators() {
+ return new String[0];
+ }
+
+ @Override
+ public boolean isFullTextSearchable() {
+ return false;
+ }
+
+ @Override
+ public boolean isQueryOrderable() {
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsPropertyIterator.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsPropertyIterator.java
new file mode 100644
index 0000000..335472f
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsPropertyIterator.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.fsprovider.internal.mapper.ContentFile;
+
+/**
+ * Simplified implementation of read-only content access via the JCR API.
+ */
+class FsPropertyIterator implements PropertyIterator {
+
+ private final Iterator<String> propertyNames;
+ private final ContentFile contentFile;
+ private final ResourceResolver resolver;
+ private final Node node;
+
+ public FsPropertyIterator(Iterator<String> propertyNames, ContentFile contentFile, ResourceResolver resolver, Node node) {
+ this.propertyNames = propertyNames;
+ this.contentFile = contentFile;
+ this.resolver = resolver;
+ this.node = node;
+ }
+
+ public boolean hasNext() {
+ return propertyNames.hasNext();
+ }
+
+ public Object next() {
+ return nextProperty();
+ }
+
+ @Override
+ public Property nextProperty() {
+ return new FsProperty(contentFile, resolver, propertyNames.next(), node);
+ }
+
+
+ // --- unsupported methods ---
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void skip(long skipNum) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getSize() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long getPosition() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsValue.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsValue.java
new file mode 100644
index 0000000..4ca2873
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsValue.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper.jcr;
+
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
+import javax.jcr.Binary;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+import org.apache.sling.api.resource.ValueMap;
+
+/**
+ * Simplified implementation of read-only content access via the JCR API.
+ */
+class FsValue implements Value {
+
+ private final ValueMap props;
+ private final String propertyName;
+ private final int arrayIndex;
+
+ public FsValue(ValueMap props, String propertyName) {
+ this.props = props;
+ this.propertyName = propertyName;
+ this.arrayIndex = -1;
+ }
+
+ public FsValue(ValueMap props, String propertyName, int arrayIndex) {
+ this.props = props;
+ this.propertyName = propertyName;
+ this.arrayIndex = arrayIndex;
+ }
+
+ @Override
+ public String getString() throws ValueFormatException, IllegalStateException, RepositoryException {
+ if (arrayIndex >= 0) {
+ return props.get(propertyName, String[].class)[arrayIndex];
+ }
+ else {
+ return props.get(propertyName, String.class);
+ }
+ }
+
+ @Override
+ public long getLong() throws ValueFormatException, RepositoryException {
+ if (arrayIndex >= 0) {
+ return props.get(propertyName, Long[].class)[arrayIndex];
+ }
+ else {
+ return props.get(propertyName, 0L);
+ }
+ }
+
+ @Override
+ public double getDouble() throws ValueFormatException, RepositoryException {
+ if (arrayIndex >= 0) {
+ return props.get(propertyName, Double[].class)[arrayIndex];
+ }
+ else {
+ return props.get(propertyName, 0d);
+ }
+ }
+
+ @Override
+ public BigDecimal getDecimal() throws ValueFormatException, RepositoryException {
+ if (arrayIndex >= 0) {
+ return props.get(propertyName, BigDecimal[].class)[arrayIndex];
+ }
+ else {
+ return props.get(propertyName, BigDecimal.ZERO);
+ }
+ }
+
+ @Override
+ public Calendar getDate() throws ValueFormatException, RepositoryException {
+ if (arrayIndex >= 0) {
+ return props.get(propertyName, Calendar[].class)[arrayIndex];
+ }
+ else {
+ return props.get(propertyName, Calendar.class);
+ }
+ }
+
+ @Override
+ public boolean getBoolean() throws ValueFormatException, RepositoryException {
+ if (arrayIndex >= 0) {
+ return props.get(propertyName, Boolean[].class)[arrayIndex];
+ }
+ else {
+ return props.get(propertyName, false);
+ }
+ }
+
+ @Override
+ public int getType() {
+ Object value = props.get(propertyName);
+ if (value == null) {
+ return PropertyType.UNDEFINED;
+ }
+ Class type = value.getClass();
+ if (type.isArray() && Array.getLength(value) > 0) {
+ Object firstItem = Array.get(value, 0);
+ if (firstItem != null) {
+ type = firstItem.getClass();
+ }
+ }
+ if (type == String.class) {
+ return PropertyType.STRING;
+ }
+ if (type == Boolean.class || type == boolean.class) {
+ return PropertyType.BOOLEAN;
+ }
+ if (type == BigDecimal.class) {
+ return PropertyType.DECIMAL;
+ }
+ if (type == Double.class || type == double.class || type == Float.class || type == float.class) {
+ return PropertyType.DOUBLE;
+ }
+ if (Number.class.isAssignableFrom(type)) {
+ return PropertyType.LONG;
+ }
+ if (type == Calendar.class) {
+ return PropertyType.DATE;
+ }
+ return PropertyType.UNDEFINED;
+ }
+
+
+ // --- unsupported methods ---
+
+ @Override
+ public InputStream getStream() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Binary getBinary() throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
new file mode 100644
index 0000000..289fb67
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.commons.collections.map.LRUMap;
+
+/**
+ * Cache for parsed content from content files (e.g. JSON, JCR XML).
+ */
+public final class ContentFileCache {
+
+ private final Map<String,Map<String,Object>> contentCache;
+ private final Map<String,Object> NULL_MAP = Collections.emptyMap();
+
+ /**
+ * @param maxSize Cache size. 0 = caching disabled.
+ */
+ @SuppressWarnings("unchecked")
+ public ContentFileCache(int maxSize) {
+ if (maxSize > 0) {
+ this.contentCache = Collections.synchronizedMap(new LRUMap(maxSize));
+ }
+ else {
+ this.contentCache = null;
+ }
+ }
+
+ /**
+ * Get content.
+ * @param path Path (used as cache key).
+ * @param file File
+ * @return Content or null
+ */
+ public Map<String,Object> get(String path, File file) {
+ Map<String,Object> content = null;
+ if (contentCache != null) {
+ content = contentCache.get(path);
+ }
+ if (content == null) {
+ content = ContentFileParser.parse(file);
+ if (content == null) {
+ content = NULL_MAP;
+ }
+ if (contentCache != null) {
+ contentCache.put(path, content);
+ }
+ }
+ if (content == NULL_MAP) {
+ return null;
+ }
+ else {
+ return content;
+ }
+ }
+
+ /**
+ * Remove content from cache.
+ * @param path Path (used as cache key)
+ */
+ public void remove(String path) {
+ if (contentCache != null) {
+ contentCache.remove(path);
+ }
+ }
+
+ /**
+ * Clear whole cache
+ */
+ public void clear() {
+ if (contentCache != null) {
+ contentCache.clear();
+ }
+ }
+
+ /**
+ * @return Current cache size
+ */
+ public int size() {
+ if (contentCache != null) {
+ return contentCache.size();
+ }
+ else {
+ return 0;
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java
new file mode 100644
index 0000000..81a69a3
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JCR_XML_SUFFIX;
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JSON_SUFFIX;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parses files that contains content fragments (e.g. JSON, JCR XML).
+ */
+class ContentFileParser {
+
+ private static final Logger log = LoggerFactory.getLogger(ContentFileParser.class);
+
+ private ContentFileParser() {
+ // static methods only
+ }
+
+ /**
+ * Parse content from file.
+ * @param file File. Type is detected automatically.
+ * @return Content or null if content could not be parsed.
+ */
+ public static Map<String,Object> parse(File file) {
+ try {
+ if (StringUtils.endsWith(file.getName(), JSON_SUFFIX)) {
+ return JsonFileParser.parse(file);
+ }
+ else if (StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
+ return JcrXmlFileParser.parse(file);
+ }
+ }
+ catch (Throwable ex) {
+ log.warn("Error parsing content from " + file.getPath(), ex);
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
new file mode 100644
index 0000000..85e6445
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+/**
+ * Content file types.
+ */
+public final class ContentFileTypes {
+
+ /**
+ * JSON content files.
+ */
+ public static final String JSON_SUFFIX = ".json";
+
+ /**
+ * JCR XML content files.
+ */
+ public static final String JCR_XML_SUFFIX = ".jcr.xml";
+
+ private ContentFileTypes() {
+ // static methods only
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java
new file mode 100644
index 0000000..6174bf9
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.jackrabbit.util.ISO9075;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Parses JCR XML files that contains content fragments.
+ */
+class JcrXmlFileParser {
+
+ private static final Logger log = LoggerFactory.getLogger(JcrXmlFileParser.class);
+
+ private static final SAXParserFactory SAX_PARSER_FACTORY;
+ static {
+ SAX_PARSER_FACTORY = SAXParserFactory.newInstance();
+ SAX_PARSER_FACTORY.setNamespaceAware(true);
+ }
+
+ private JcrXmlFileParser() {
+ // static methods only
+ }
+
+ /**
+ * Parse JSON file.
+ * @param file File
+ * @return Content
+ */
+ public static Map<String,Object> parse(File file) {
+ log.debug("Parse JCR XML content from {}", file.getPath());
+ try (FileInputStream fis = new FileInputStream(file)) {
+ XmlHandler xmlHandler = new XmlHandler();
+ SAXParser parser = SAX_PARSER_FACTORY.newSAXParser();
+ parser.parse(fis, xmlHandler);
+ if (xmlHandler.hasError()) {
+ throw xmlHandler.getError();
+ }
+ return xmlHandler.getContent();
+ }
+ catch (IOException | ParserConfigurationException | SAXException ex) {
+ log.warn("Error parsing JCR XML content from " + file.getPath(), ex);
+ return null;
+ }
+ }
+
+ /**
+ * Decodes element or attribute names.
+ * @param qname qname
+ * @return Decoded name
+ */
+ static String decodeName(String qname) {
+ return ISO9075.decode(qname);
+ }
+
+ /**
+ * Parses XML stream to Map.
+ */
+ static class XmlHandler extends DefaultHandler {
+ private final Map<String,Object> content = new LinkedHashMap<>();
+ private final Stack<Map<String,Object>> elements = new Stack<>();
+ private SAXParseException error;
+
+ public Map<String,Object> getContent() {
+ return content;
+ }
+
+ public boolean hasError() {
+ return error != null;
+ }
+
+ public SAXParseException getError() {
+ return error;
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes)
+ throws SAXException {
+
+ // prepare map for element
+ Map<String,Object> element;
+ if (elements.isEmpty()) {
+ element = content;
+ }
+ else {
+ element = new HashMap<>();
+ elements.peek().put(decodeName(qName), element);
+ }
+ elements.push(element);
+
+ // get attributes
+ for (int i=0; i<attributes.getLength(); i++) {
+ element.put(decodeName(attributes.getQName(i)), JcrXmlValueConverter.parseValue(attributes.getValue(i)));
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ elements.pop();
+ }
+
+ @Override
+ public void error(SAXParseException ex) throws SAXException {
+ this.error = ex;
+ }
+
+ @Override
+ public void fatalError(SAXParseException ex) throws SAXException {
+ this.error = ex;
+ }
+
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java
new file mode 100644
index 0000000..8a0d0db
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jackrabbit.util.ISO8601;
+
+/**
+ * Parses JCR XML files that contains content fragments.
+ */
+class JcrXmlValueConverter {
+
+ private static final Pattern TYPE_PREFIX = Pattern.compile("^\\{([^\\{\\}]+)\\}(.+)$");
+ private static final Pattern VALUE_ARRAY = Pattern.compile("^\\[(.*)\\]$");
+
+ private JcrXmlValueConverter() {
+ // static methods only
+ }
+
+ /**
+ * Parse JSON value from XML Attribute.
+ * @param value XML attribute value
+ * @return Value object
+ */
+ public static Object parseValue(final String rawValue) {
+ String value = rawValue;
+ String[] valueArray = null;
+
+ if (rawValue == null) {
+ return null;
+ }
+
+ // detect type prefix
+ String typePrefix = null;
+ Matcher typePrefixMatcher = TYPE_PREFIX.matcher(value);
+ if (typePrefixMatcher.matches()) {
+ typePrefix = typePrefixMatcher.group(1);
+ value = typePrefixMatcher.group(2);
+ }
+
+ // check for array
+ Matcher arrayMatcher = VALUE_ARRAY.matcher(value);
+ if (arrayMatcher.matches()) {
+ value = null;
+ valueArray = splitPreserveAllTokens(arrayMatcher.group(1), ',');
+ }
+
+ // convert values
+ if (valueArray != null) {
+ Object[] result = new Object[valueArray.length];
+ for (int i=0; i<valueArray.length; i++) {
+ result[i] = convertValue(valueArray[i], typePrefix, true);
+ }
+ return result;
+ }
+ else {
+ return convertValue(value, typePrefix, false);
+ }
+ }
+
+ /**
+ * Split string preserving all tokens - but ignore separators that are escaped with \.
+ * @param str Combined string
+ * @param sep Separator
+ * @return Tokens
+ */
+ private static String[] splitPreserveAllTokens(String str, char sep) {
+ final int len = str.length();
+ if (len == 0) {
+ return ArrayUtils.EMPTY_STRING_ARRAY;
+ }
+ final List<String> list = new ArrayList<String>();
+ int i = 0, start = 0;
+ boolean match = false;
+ boolean lastMatch = false;
+ boolean escaped = false;
+ while (i < len) {
+ if (str.charAt(i) == '\\' && !escaped) {
+ escaped = true;
+ }
+ else {
+ if (str.charAt(i) == sep && !escaped) {
+ lastMatch = true;
+ list.add(str.substring(start, i));
+ match = false;
+ start = ++i;
+ continue;
+ }
+ lastMatch = false;
+ match = true;
+ escaped = false;
+ }
+ i++;
+ }
+ if (match || lastMatch) {
+ list.add(str.substring(start, i));
+ }
+ return list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Parse value depending on type prefix.
+ * @param value Value
+ * @param typePrefix Type prefix
+ * @param inArray Value is in array
+ * @return Value object
+ */
+ private static Object convertValue(final String value, final String typePrefix, final boolean inArray) {
+ if (typePrefix == null || StringUtils.equals(typePrefix, "Name")) {
+ return deescapeStringValue(value, inArray);
+ }
+ else if (StringUtils.equals(typePrefix, "Boolean")) {
+ return Boolean.valueOf(value);
+ }
+ else if (StringUtils.equals(typePrefix, "Long")) {
+ return Long.valueOf(value);
+ }
+ else if (StringUtils.equals(typePrefix, "Decimal")) {
+ return Double.valueOf(value);
+ }
+ else if (StringUtils.equals(typePrefix, "Date")) {
+ return ISO8601.parse(value);
+ }
+ else {
+ throw new IllegalArgumentException("Unexpected type prefix: " + typePrefix);
+ }
+ }
+
+ /**
+ * De-escape string value.
+ * @param value Escaped string value
+ * @param inArray In array
+ * @return De-escaped string value
+ */
+ private static String deescapeStringValue(final String value, final boolean inArray) {
+ String descapedValue = value;
+ if (inArray) {
+ descapedValue = StringUtils.replace(descapedValue, "\\,", ",");
+ }
+ else if (StringUtils.startsWith(descapedValue, "\\{") || StringUtils.startsWith(descapedValue, "\\[")) {
+ descapedValue = descapedValue.substring(1);
+ }
+ return StringUtils.replace(descapedValue, "\\\\", "\\");
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java
new file mode 100644
index 0000000..8070e0d
--- /dev/null
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+import javax.json.JsonString;
+import javax.json.JsonValue;
+import javax.json.stream.JsonParsingException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parses JSON files that contains content fragments.
+ */
+class JsonFileParser {
+
+ private static final Logger log = LoggerFactory.getLogger(JsonFileParser.class);
+
+ private static final JsonReaderFactory JSON_READER_FACTORY;
+ static {
+ // allow comments in JSON files
+ Map<String,Object> jsonReaderFactoryConfig = new HashMap<>();
+ jsonReaderFactoryConfig.put("org.apache.johnzon.supports-comments", true);
+ // workaround for JsonProvider classloader issue until https://issues.apache.org/jira/browse/GERONIMO-6560 is fixed
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(JsonFileParser.class.getClassLoader());
+ JSON_READER_FACTORY = Json.createReaderFactory(jsonReaderFactoryConfig);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+ }
+
+ private JsonFileParser() {
+ // static methods only
+ }
+
+ /**
+ * Parse JSON file.
+ * @param file File
+ * @return Content
+ */
+ public static Map<String,Object> parse(File file) {
+ log.debug("Parse JSON content from {}", file.getPath());
+ try (FileInputStream fis = new FileInputStream(file);
+ JsonReader reader = JSON_READER_FACTORY.createReader(fis)) {
+ return toMap(reader.readObject());
+ }
+ catch (IOException | JsonParsingException ex) {
+ log.warn("Error parsing JSON content from " + file.getPath(), ex);
+ return null;
+ }
+ }
+
+ private static Map<String,Object> toMap(JsonObject object) {
+ Map<String,Object> map = new LinkedHashMap<>();
+ for (Map.Entry<String, JsonValue> entry : object.entrySet()) {
+ map.put(entry.getKey(), convertValue(entry.getValue()));
+ }
+ return map;
+ }
+
+ private static Object convertValue(JsonValue value) {
+ switch (value.getValueType()) {
+ case STRING:
+ return ((JsonString)value).getString();
+ case NUMBER:
+ JsonNumber numberValue = (JsonNumber)value;
+ if (numberValue.isIntegral()) {
+ return numberValue.longValue();
+ }
+ else {
+ return numberValue.doubleValue();
+ }
+ case TRUE:
+ return true;
+ case FALSE:
+ return false;
+ case NULL:
+ return null;
+ case ARRAY:
+ JsonArray arrayValue = (JsonArray)value;
+ Object[] values = new Object[arrayValue.size()];
+ for (int i=0; i<values.length; i++) {
+ values[i] = convertValue(arrayValue.get(i));
+ }
+ return values;
+ case OBJECT:
+ return toMap((JsonObject)value);
+ default:
+ throw new IllegalArgumentException("Unexpected JSON value type: " + value.getValueType());
+ }
+ }
+
+}
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
deleted file mode 100644
index 03f9ecf..0000000
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-
-#
-# This file contains localization strings for configuration labels and
-# descriptions as used in the metatype.xml descriptor generated by the
-# the SCR plugin
-
-#
-# Localizations for FsResourceProvider configuration
-resource.resolver.name = Apache Sling Filesystem Resource Provider
-resource.resolver.description = Configure an instance of the filesystem \
- resource provider in terms of provider root and filesystem location
-
-provider.roots.name = Provider Root
-provider.roots.description = Location in the virtual resource tree where the \
- filesystem resources are mapped in. This property must not be an empty string.
-provider.file.name = Filesystem Root
-provider.file.description = Filesystem directory mapped to the virtual \
- resource tree. This property must not be an empty string. If the path is \
- relative it is resolved against sling.home or the current working directory. \
- The path may be a file or folder. If the path does not address an existing \
- file or folder, an empty folder is created.
-
-provider.checkinterval.name = Check Interval
-provider.checkinterval.description = If the interval has a value higher than 100, the provider will \
- check the file system for changes periodically. This interval defines the period in milliseconds \
- (the default is 1000). If a change is detected, resource events are sent through the event admin.
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
new file mode 100644
index 0000000..5341ced
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.SlingConstants;
+import org.apache.sling.fsprovider.internal.FileMonitor.ResourceChange;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.apache.sling.testing.mock.sling.junit.SlingContextCallback;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * Test events when changing filesystem content.
+ */
+public class FileMonitorTest {
+
+ private final File tempDir;
+ private final EventAdminListener eventListener = new EventAdminListener();
+
+ public FileMonitorTest() throws Exception {
+ tempDir = Files.createTempDirectory(getClass().getName()).toFile();
+ }
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .beforeSetUp(new SlingContextCallback() {
+ @Override
+ public void execute(SlingContext context) throws Exception {
+ // copy test content to temp. directory
+ tempDir.mkdirs();
+ File sourceDir = new File("src/test/resources/fs-test");
+ FileUtils.copyDirectory(sourceDir, tempDir);
+
+ // mount temp. directory
+ context.registerInjectActivateService(new FsResourceProvider(),
+ "provider.file", tempDir.getPath(),
+ "provider.roots", "/fs-test",
+ "provider.checkinterval", 120,
+ "provider.json.content", true);
+
+ // register resource change listener
+ context.registerService(EventHandler.class, eventListener,
+ EventConstants.EVENT_TOPIC, new String[] {
+ SlingConstants.TOPIC_RESOURCE_ADDED,
+ SlingConstants.TOPIC_RESOURCE_CHANGED,
+ SlingConstants.TOPIC_RESOURCE_REMOVED
+ });
+ }
+ })
+ .afterTearDown(new SlingContextCallback() {
+ @Override
+ public void execute(SlingContext context) throws Exception {
+ // remove temp directory
+ tempDir.delete();
+ }
+ })
+ .build();
+
+ @Test
+ public void testUpdateFile() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file1a = new File(tempDir, "folder1/file1a.txt");
+ FileUtils.touch(file1a);
+
+ Thread.sleep(250);
+
+ assertEquals(1, changes.size());
+ assertChange(changes, "/fs-test/folder1/file1a.txt", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ }
+
+ @Test
+ public void testAddFile() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file1c = new File(tempDir, "folder1/file1c.txt");
+ FileUtils.write(file1c, "newcontent");
+
+ Thread.sleep(250);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1c.txt", SlingConstants.TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testRemoveFile() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file1a = new File(tempDir, "folder1/file1a.txt");
+ file1a.delete();
+
+ Thread.sleep(250);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1a.txt", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ }
+
+ @Test
+ public void testAddFolder() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File folder99 = new File(tempDir, "folder99");
+ folder99.mkdir();
+
+ Thread.sleep(250);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/fs-test", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder99", SlingConstants.TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testRemoveFolder() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File folder1 = new File(tempDir, "folder1");
+ FileUtils.deleteDirectory(folder1);
+
+ Thread.sleep(250);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/fs-test", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ }
+
+ @Test
+ public void testUpdateJsonContent() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file1a = new File(tempDir, "folder2/content.json");
+ FileUtils.touch(file1a);
+
+ Thread.sleep(250);
+
+ assertTrue(changes.size() > 1);
+ assertChange(changes, "/fs-test/folder2/content", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ assertChange(changes, "/fs-test/folder2/content", SlingConstants.TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder2/content/jcr:content", SlingConstants.TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testAddJsonContent() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file1c = new File(tempDir, "folder1/file1c.json");
+ FileUtils.write(file1c, "{\"prop1\":\"value1\",\"child1\":{\"prop2\":\"value1\"}}");
+
+ Thread.sleep(250);
+
+ assertEquals(3, changes.size());
+ assertChange(changes, "/fs-test/folder1", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder1/file1c", SlingConstants.TOPIC_RESOURCE_ADDED);
+ assertChange(changes, "/fs-test/folder1/file1c/child1", SlingConstants.TOPIC_RESOURCE_ADDED);
+ }
+
+ @Test
+ public void testRemoveJsonContent() throws Exception {
+ List<ResourceChange> changes = eventListener.getChanges();
+ assertTrue(changes.isEmpty());
+
+ File file1a = new File(tempDir, "folder2/content.json");
+ file1a.delete();
+
+ Thread.sleep(250);
+
+ assertEquals(2, changes.size());
+ assertChange(changes, "/fs-test/folder2", SlingConstants.TOPIC_RESOURCE_CHANGED);
+ assertChange(changes, "/fs-test/folder2/content", SlingConstants.TOPIC_RESOURCE_REMOVED);
+ }
+
+
+ private void assertChange(List<ResourceChange> changes, String path, String topic) {
+ boolean found = false;
+ for (ResourceChange change : changes) {
+ if (StringUtils.equals(change.path, path) && StringUtils.equals(change.topic, topic)) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue("Change with path=" + path + ", topic=" + topic, found);
+ }
+
+ static class EventAdminListener implements EventHandler {
+ private final List<ResourceChange> allChanges = new ArrayList<>();
+ public List<ResourceChange> getChanges() {
+ return allChanges;
+ }
+ @Override
+ public void handleEvent(Event event) {
+ ResourceChange change = new ResourceChange();
+ change.path = (String)event.getProperty(SlingConstants.PROPERTY_PATH);
+ change.resourceType = (String)event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);
+ change.topic = event.getTopic();
+ allChanges.add(change);
+ }
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
new file mode 100644
index 0000000..1930a94
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
+import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Test access to files and folders from filesystem.
+ */
+public class FilesFolderTest {
+
+ private Resource root;
+ private Resource fsroot;
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .plugin(new RegisterFsResourcePlugin())
+ .build();
+
+ @Before
+ public void setUp() {
+ root = context.resourceResolver().getResource("/");
+ fsroot = context.resourceResolver().getResource("/fs-test");
+ }
+
+ @Test
+ public void testFolders() {
+ assertFolder(fsroot, "folder1");
+ assertFolder(fsroot, "folder1/folder11");
+ assertFolder(fsroot, "folder2");
+ assertFolder(fsroot, "folder3");
+ }
+
+ @Test
+ public void testFiles() {
+ assertFile(fsroot, "folder1/file1a.txt", "file1a");
+ assertFile(fsroot, "folder1/file1b.txt", "file1b");
+ assertFile(fsroot, "folder1/folder11/file11a.txt", "file11a");
+ assertFile(fsroot, "folder2/content.json", null);
+ assertFile(fsroot, "folder2/content/file2content.txt", "file2content");
+ assertFile(fsroot, "folder3/content.jcr.xml", null);
+ }
+
+ @Test
+ public void testListChildren() {
+ assertThat(root, ResourceMatchers.containsChildren("fs-test"));
+ assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2", "folder3"));
+ assertThat(fsroot.getChild("folder1"), ResourceMatchers.hasChildren("folder11", "file1a.txt", "file1b.txt"));
+ assertThat(fsroot.getChild("folder2"), ResourceMatchers.hasChildren("folder21", "content.json"));
+ assertFalse(fsroot.getChild("folder1/file1a.txt").listChildren().hasNext());
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/InvalidRootFolderTest.java b/src/test/java/org/apache/sling/fsprovider/internal/InvalidRootFolderTest.java
new file mode 100644
index 0000000..6d080b1
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/InvalidRootFolderTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.apache.sling.testing.mock.sling.junit.SlingContextCallback;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Test with invalid fs folder.
+ */
+public class InvalidRootFolderTest {
+
+ private Resource fsroot;
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .plugin(new RegisterFsResourcePlugin("provider.file", "target/temp/invalid-folder"))
+ .afterTearDown(new SlingContextCallback() {
+ @Override
+ public void execute(SlingContext context) throws Exception {
+ File file = new File("target/temp/invalid-folder");
+ file.delete();
+ }
+ })
+ .build();
+
+ @Before
+ public void setUp() {
+ fsroot = context.resourceResolver().getResource("/fs-test");
+ }
+
+ @Test
+ public void testFolders() {
+ assertNull(fsroot.getChild("folder1"));
+ }
+
+ @Test
+ public void testFiles() {
+ assertNull(fsroot.getChild("folder1/file1a.txt"));
+ }
+
+ @Test
+ public void testListChildren() {
+ assertFalse(fsroot.listChildren().hasNext());
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JcrMixedTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JcrMixedTest.java
new file mode 100644
index 0000000..9a220d9
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrMixedTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
+import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Test access mixed with JCR content on same path.
+ */
+public class JcrMixedTest {
+
+ private Resource root;
+ private Resource fsroot;
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .plugin(new RegisterFsResourcePlugin())
+ .build();
+
+ @Before
+ public void setUp() throws RepositoryException {
+ root = context.resourceResolver().getResource("/");
+ fsroot = context.resourceResolver().getResource("/fs-test");
+
+ // prepare mixed JCR content
+ Node node = root.adaptTo(Node.class);
+ Node fstest = node.addNode("fs-test", "nt:folder");
+ // folder1
+ Node folder1 = fstest.addNode("folder1", "nt:folder");
+ folder1.setProperty("prop1", "value1");
+ folder1.setProperty("prop2", 123L);
+ // folder1/file1a.txt
+ Node file1a = folder1.addNode("file1a.txt", "nt:file");
+ file1a.setProperty("prop1", "value2");
+ file1a.setProperty("prop2", 234L);
+ // folder1/file1c.txt
+ folder1.addNode("file1c.txt", "nt:file");
+ // folder99
+ fstest.addNode("folder99", "nt:folder");
+ }
+
+ @Test
+ public void testFolders() {
+ // expected properties from JCR for folders
+ Resource folder1 = fsroot.getChild("folder1");
+ assertThat(folder1, ResourceMatchers.props("jcr:primaryType", "nt:folder",
+ "prop1", "value1",
+ "prop2", 123L));
+ }
+
+ @Test
+ public void testFiles() {
+ assertFile(fsroot, "folder1/file1a.txt", "file1a");
+ assertFile(fsroot, "folder1/file1b.txt", "file1b");
+ assertFile(fsroot, "folder1/folder11/file11a.txt", "file11a");
+ assertFile(fsroot, "folder2/content.json", null);
+
+ // do not expected properties from JCR for files
+ Resource file1a = fsroot.getChild("folder1/file1a.txt");
+ assertThat(file1a, not(ResourceMatchers.props(
+ "prop1", "value2",
+ "prop2", 234L)));
+ }
+
+ @Test
+ public void testListChildren() {
+ assertThat(root, ResourceMatchers.containsChildren("fs-test"));
+ assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2", "folder99"));
+ assertThat(fsroot.getChild("folder1"), ResourceMatchers.hasChildren("file1a.txt", "file1b.txt", "file1c.txt"));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
new file mode 100644
index 0000000..3325ed4
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
+import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Test access to files and folders from filesystem.
+ */
+public class JcrXmlContentTest {
+
+ private Resource root;
+ private Resource fsroot;
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .plugin(new RegisterFsResourcePlugin("provider.jcrxml.content", true))
+ .build();
+
+ @Before
+ public void setUp() {
+ root = context.resourceResolver().getResource("/");
+ fsroot = context.resourceResolver().getResource("/fs-test");
+ }
+
+ @Test
+ public void testFolders() {
+ assertFolder(fsroot, "folder1");
+ assertFolder(fsroot, "folder1/folder11");
+ assertFolder(fsroot, "folder2");
+ assertFolder(fsroot, "folder3");
+ }
+
+ @Test
+ public void testFiles() {
+ assertFile(fsroot, "folder1/file1a.txt", "file1a");
+ assertFile(fsroot, "folder1/file1b.txt", "file1b");
+ assertFile(fsroot, "folder1/folder11/file11a.txt", "file11a");
+ assertFile(fsroot, "folder2/content.json", null);
+ assertNull(fsroot.getChild("folder3/content.jcr.xml"));
+ }
+
+ @Test
+ public void testListChildren() {
+ assertThat(root, ResourceMatchers.containsChildren("fs-test"));
+ assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2"));
+ assertThat(fsroot.getChild("folder1"), ResourceMatchers.hasChildren("folder11", "file1a.txt", "file1b.txt"));
+ assertThat(fsroot.getChild("folder2"), ResourceMatchers.hasChildren("folder21", "content"));
+ }
+
+ @Test
+ public void testJsonContent_Root() {
+ Resource underTest = fsroot.getChild("folder3/content");
+ assertNotNull(underTest);
+ assertEquals("app:Page", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
+ assertEquals("app:Page", underTest.getResourceType());
+ assertThat(underTest, ResourceMatchers.hasChildren("jcr:content"));
+ }
+
+ @Test
+ public void testJsonContent_Level1() {
+ Resource underTest = fsroot.getChild("folder3/content/jcr:content");
+ assertNotNull(underTest);
+ assertEquals("app:PageContent", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
+ assertEquals("samples/sample-app/components/content/page/homepage", underTest.getResourceType());
+ assertThat(underTest, ResourceMatchers.hasChildren("teaserbar", "aside", "content"));
+ }
+
+ @Test
+ public void testJsonContent_Level3() {
+ Resource underTest = fsroot.getChild("folder3/content/jcr:content/content/contentheadline");
+ assertNotNull(underTest);
+ assertEquals("nt:unstructured", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
+ assertEquals("samples/sample-app/components/content/common/contentHeadline", underTest.getResourceType());
+ assertFalse(underTest.listChildren().hasNext());
+ }
+
+ @Test
+ public void testJsonContent_Datatypes() {
+ Resource underTest = fsroot.getChild("folder3/content/jcr:content");
+ ValueMap props = ResourceUtil.getValueMap(underTest);
+
+ assertEquals("en", props.get("jcr:title", String.class));
+ assertEquals(true, props.get("includeAside", false));
+ assertEquals((Long)1234567890123L, props.get("longProp", Long.class));
+ assertEquals((Double)1.2345d, props.get("decimalProp", Double.class), 0.00001d);
+
+ assertArrayEquals(new String[] { "aa", "bb", "cc" }, props.get("stringPropMulti", String[].class));
+ assertArrayEquals(new Long[] { 1234567890123L, 55L }, props.get("longPropMulti", Long[].class));
+ }
+
+ @Test
+ public void testJsonContent_InvalidPath() {
+ Resource underTest = fsroot.getChild("folder2/content/jcr:content/xyz");
+ assertNull(underTest);
+ }
+
+ @Test
+ @Ignore // jcr overlay is always active with the old sling resource provider API
+ public void testJcrMixedContent() throws RepositoryException {
+ // prepare mixed JCR content
+ Node node = root.adaptTo(Node.class);
+ Node fstest = node.addNode("fs-test", "nt:folder");
+ fstest.addNode("folder99", "nt:folder");
+
+ assertNull(fsroot.getChild("folder99"));
+ }
+
+ @Test
+ public void testFolder3ChildNodes() throws RepositoryException {
+ Resource folder3 = fsroot.getChild("folder3");
+ List<Resource> children = ImmutableList.copyOf(folder3.listChildren());
+
+ assertEquals(2, children.size());
+ Resource child1 = children.get(0);
+ assertEquals("content", child1.getName());
+ assertEquals("app:Page", child1.getResourceType());
+ assertEquals("app:Page", ResourceUtil.getValueMap(child1).get("jcr:primaryType", String.class));
+
+ Resource child2 = children.get(1);
+ assertEquals("folder31", child2.getName());
+ assertEquals("nt:folder", ResourceUtil.getValueMap(child2).get("jcr:primaryType", String.class));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
new file mode 100644
index 0000000..7aa29aa
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
+import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Test access to files and folders from filesystem.
+ */
+public class JsonContentTest {
+
+ private Resource root;
+ private Resource fsroot;
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
+ .plugin(new RegisterFsResourcePlugin("provider.json.content", true))
+ .build();
+
+ @Before
+ public void setUp() {
+ root = context.resourceResolver().getResource("/");
+ fsroot = context.resourceResolver().getResource("/fs-test");
+ }
+
+ @Test
+ public void testFolders() {
+ assertFolder(fsroot, "folder1");
+ assertFolder(fsroot, "folder1/folder11");
+ assertFolder(fsroot, "folder2");
+ }
+
+ @Test
+ public void testFiles() {
+ assertFile(fsroot, "folder1/file1a.txt", "file1a");
+ assertFile(fsroot, "folder1/file1b.txt", "file1b");
+ assertFile(fsroot, "folder1/folder11/file11a.txt", "file11a");
+ assertNull(fsroot.getChild("folder2/content.json"));
+ assertFile(fsroot, "folder2/content/file2content.txt", "file2content");
+ assertFile(fsroot, "folder3/content.jcr.xml", null);
+ }
+
+ @Test
+ public void testListChildren() {
+ assertThat(root, ResourceMatchers.containsChildren("fs-test"));
+ assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2"));
+ assertThat(fsroot.getChild("folder1"), ResourceMatchers.hasChildren("folder11", "file1a.txt", "file1b.txt"));
+ assertThat(fsroot.getChild("folder2"), ResourceMatchers.hasChildren("folder21", "content"));
+ }
+
+ @Test
+ public void testJsonContent_Root() {
+ Resource underTest = fsroot.getChild("folder2/content");
+ assertNotNull(underTest);
+ assertEquals("app:Page", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
+ assertEquals("app:Page", underTest.getResourceType());
+ assertThat(underTest, ResourceMatchers.hasChildren("jcr:content"));
+ }
+
+ @Test
+ public void testJsonContent_Level1() {
+ Resource underTest = fsroot.getChild("folder2/content/jcr:content");
+ assertNotNull(underTest);
+ assertEquals("app:PageContent", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
+ assertEquals("sample/components/homepage", underTest.getResourceType());
+ assertEquals("sample/components/supertype", underTest.getResourceSuperType());
+ assertThat(underTest, ResourceMatchers.hasChildren("par", "header", "newslist", "lead", "image", "carousel", "rightpar"));
+ }
+
+ @Test
+ public void testJsonContent_Level5() {
+ Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/image/file/jcr:content");
+ assertNotNull(underTest);
+ assertEquals("nt:resource", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
+ assertFalse(underTest.listChildren().hasNext());
+ }
+
+ @Test
+ public void testJsonContent_Datatypes() {
+ Resource underTest = fsroot.getChild("folder2/content/toolbar/profiles/jcr:content");
+ ValueMap props = ResourceUtil.getValueMap(underTest);
+
+ assertEquals("Profiles", props.get("jcr:title", String.class));
+ assertEquals(true, props.get("booleanProp", false));
+ assertEquals((Long)1234567890123L, props.get("longProp", Long.class));
+ assertEquals((Double)1.2345d, props.get("decimalProp", Double.class), 0.00001d);
+
+ assertArrayEquals(new String[] { "aa", "bb", "cc" }, props.get("stringPropMulti", String[].class));
+ assertArrayEquals(new Long[] { 1234567890123L, 55L }, props.get("longPropMulti", Long[].class));
+ }
+
+ @Test
+ public void testJsonContent_Datatypes_JCR() throws RepositoryException {
+ Resource underTest = fsroot.getChild("folder2/content/toolbar/profiles/jcr:content");
+ ValueMap props = ResourceUtil.getValueMap(underTest);
+ Node node = underTest.adaptTo(Node.class);
+
+ assertEquals("/fs-test/folder2/content/toolbar/profiles/jcr:content", node.getPath());
+ assertEquals(6, node.getDepth());
+
+ assertTrue(node.hasProperty("jcr:title"));
+ assertEquals(PropertyType.STRING, node.getProperty("jcr:title").getType());
+ assertFalse(node.getProperty("jcr:title").isMultiple());
+ assertEquals("jcr:title", node.getProperty("jcr:title").getDefinition().getName());
+ assertEquals("/fs-test/folder2/content/toolbar/profiles/jcr:content/jcr:title", node.getProperty("jcr:title").getPath());
+ assertEquals("Profiles", node.getProperty("jcr:title").getString());
+ assertEquals(PropertyType.BOOLEAN, node.getProperty("booleanProp").getType());
+ assertEquals(true, node.getProperty("booleanProp").getBoolean());
+ assertEquals(PropertyType.LONG, node.getProperty("longProp").getType());
+ assertEquals(1234567890123L, node.getProperty("longProp").getLong());
+ assertEquals(PropertyType.DOUBLE, node.getProperty("decimalProp").getType());
+ assertEquals(1.2345d, node.getProperty("decimalProp").getDouble(), 0.00001d);
+
+ assertEquals(PropertyType.STRING, node.getProperty("stringPropMulti").getType());
+ assertTrue(node.getProperty("stringPropMulti").isMultiple());
+ Value[] stringPropMultiValues = node.getProperty("stringPropMulti").getValues();
+ assertEquals(3, stringPropMultiValues.length);
+ assertEquals("aa", stringPropMultiValues[0].getString());
+ assertEquals("bb", stringPropMultiValues[1].getString());
+ assertEquals("cc", stringPropMultiValues[2].getString());
+
+ assertEquals(PropertyType.LONG, node.getProperty("longPropMulti").getType());
+ assertTrue(node.getProperty("longPropMulti").isMultiple());
+ Value[] longPropMultiValues = node.getProperty("longPropMulti").getValues();
+ assertEquals(2, longPropMultiValues.length);
+ assertEquals(1234567890123L, longPropMultiValues[0].getLong());
+ assertEquals(55L, longPropMultiValues[1].getLong());
+
+ // assert property iterator
+ Set<String> propertyNames = new HashSet<>();
+ PropertyIterator propertyIterator = node.getProperties();
+ while (propertyIterator.hasNext()) {
+ propertyNames.add(propertyIterator.nextProperty().getName());
+ }
+ assertTrue(props.keySet().containsAll(propertyNames));
+
+ // assert node iterator
+ Set<String> nodeNames = new HashSet<>();
+ NodeIterator nodeIterator = node.getNodes();
+ while (nodeIterator.hasNext()) {
+ nodeNames.add(nodeIterator.nextNode().getName());
+ }
+ assertEquals(ImmutableSet.of("par", "rightpar"), nodeNames);
+
+ // node hierarchy
+ assertTrue(node.hasNode("rightpar"));
+ Node rightpar = node.getNode("rightpar");
+ assertEquals(7, rightpar.getDepth());
+ Node parent = rightpar.getParent();
+ assertTrue(node.isSame(parent));
+ Node ancestor = (Node)rightpar.getAncestor(5);
+ assertEquals(underTest.getParent().getPath(), ancestor.getPath());
+ Node root = (Node)rightpar.getAncestor(0);
+ assertEquals("/", root.getPath());
+
+ // node types
+ assertTrue(node.isNodeType("app:PageContent"));
+ assertEquals("app:PageContent", node.getPrimaryNodeType().getName());
+ assertFalse(node.getPrimaryNodeType().isMixin());
+ NodeType[] mixinTypes = node.getMixinNodeTypes();
+ assertEquals(2, mixinTypes.length);
+ assertEquals("type1", mixinTypes[0].getName());
+ assertEquals("type2", mixinTypes[1].getName());
+ assertTrue(mixinTypes[0].isMixin());
+ assertTrue(mixinTypes[1].isMixin());
+ }
+
+ @Test
+ public void testFallbackNodeType() throws RepositoryException {
+ Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/title_2");
+ assertEquals(NodeType.NT_UNSTRUCTURED, underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
+ }
+
+ @Test
+ public void testJsonContent_InvalidPath() {
+ Resource underTest = fsroot.getChild("folder2/content/jcr:content/xyz");
+ assertNull(underTest);
+ }
+
+ @Test
+ @Ignore // jcr overlay is always active with the old sling resource provider API
+ public void testJcrMixedContent() throws RepositoryException {
+ // prepare mixed JCR content
+ Node node = root.adaptTo(Node.class);
+ Node fstest = node.addNode("fs-test", "nt:folder");
+ fstest.addNode("folder99", "nt:folder");
+
+ assertNull(fsroot.getChild("folder99"));
+ }
+
+ @Test
+ public void testFolder2ChildNodes() throws RepositoryException {
+ Resource folder2 = fsroot.getChild("folder2");
+ List<Resource> children = ImmutableList.copyOf(folder2.listChildren());
+
+ assertEquals(2, children.size());
+ Resource child1 = children.get(0);
+ assertEquals("content", child1.getName());
+ assertEquals("app:Page", child1.getResourceType());
+ assertEquals("app:Page", ResourceUtil.getValueMap(child1).get("jcr:primaryType", String.class));
+
+ Resource child2 = children.get(1);
+ assertEquals("folder21", child2.getName());
+ assertEquals("nt:folder", ResourceUtil.getValueMap(child2).get("jcr:primaryType", String.class));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
new file mode 100644
index 0000000..4d62076
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.CharEncoding;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.hamcrest.ResourceMatchers;
+import org.apache.sling.testing.mock.osgi.MapUtil;
+import org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin;
+import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
+
+class TestUtils {
+
+ public static class RegisterFsResourcePlugin extends AbstractContextPlugin<SlingContextImpl> {
+ private final Map<String,Object> props;
+ public RegisterFsResourcePlugin(Object... props) {
+ this.props = MapUtil.toMap(props);
+ }
+ @Override
+ public void beforeSetUp(SlingContextImpl context) throws Exception {
+ Map<String,Object> config = new HashMap<>();
+ config.put("provider.file", "src/test/resources/fs-test");
+ config.put("provider.roots", "/fs-test");
+ config.put("provider.checkinterval", 0);
+ config.putAll(props);
+ context.registerInjectActivateService(new FsResourceProvider(), config);
+ }
+ };
+
+ public static void assertFolder(Resource resource, String path) {
+ Resource folder = resource.getChild(path);
+ assertNotNull(path, folder);
+
+ assertThat(folder, ResourceMatchers.props("jcr:primaryType", "nt:folder"));
+ assertEquals("nt:folder", folder.getResourceType());
+
+ assertNull(folder.getResourceSuperType());
+ assertEquals(folder.getName(), folder.adaptTo(File.class).getName());
+ assertTrue(StringUtils.contains(folder.adaptTo(URL.class).toString(), folder.getName()));
+ }
+
+ public static void assertFile(Resource resource, String path, String content) {
+ Resource file = resource.getChild(path);
+ assertNotNull(path, file);
+
+ assertThat(file, ResourceMatchers.props("jcr:primaryType", "nt:file"));
+ assertEquals("nt:file", file.getResourceType());
+
+ assertNull(file.getResourceSuperType());
+ assertEquals(file.getName(), file.adaptTo(File.class).getName());
+ assertTrue(StringUtils.contains(file.adaptTo(URL.class).toString(), file.getName()));
+
+ if (content != null) {
+ try {
+ try (InputStream is = file.adaptTo(InputStream.class)) {
+ String data = IOUtils.toString(is, CharEncoding.UTF_8);
+ assertEquals(content, data);
+ }
+ }
+ catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java
new file mode 100644
index 0000000..4659991
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/ContentFileTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
+import org.junit.Test;
+
+public class ContentFileTest {
+
+ private ContentFileCache contentFileCache = new ContentFileCache(0);
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testRootContent() {
+ File file = new File("src/test/resources/fs-test/folder2/content.json");
+
+ ContentFile underTest = new ContentFile(file, "/fs-test/folder2/content", null, contentFileCache);
+ assertEquals(file, underTest.getFile());
+ assertNull(underTest.getSubPath());
+
+ assertTrue(underTest.hasContent());
+
+ Map<String,Object> content = (Map<String,Object>)underTest.getContent();
+ assertEquals("app:Page", content.get("jcr:primaryType"));
+ assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+
+ ValueMap props = underTest.getValueMap();
+ assertEquals("app:Page", props.get("jcr:primaryType"));
+ assertNull(props.get("jcr:content"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testContentLevel1() {
+ File file = new File("src/test/resources/fs-test/folder2/content.json");
+
+ ContentFile underTest = new ContentFile(file, "/fs-test/folder2/content", "jcr:content", contentFileCache);
+ assertEquals(file, underTest.getFile());
+ assertEquals("jcr:content", underTest.getSubPath());
+
+ assertTrue(underTest.hasContent());
+
+ Map<String,Object> content = (Map<String,Object>)underTest.getContent();
+ assertEquals("app:PageContent", content.get("jcr:primaryType"));
+
+ ValueMap props = underTest.getValueMap();
+ assertEquals("app:PageContent", props.get("jcr:primaryType"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testContentLevel5() {
+ File file = new File("src/test/resources/fs-test/folder2/content.json");
+
+ ContentFile underTest = new ContentFile(file, "/fs-test/folder2/content", "jcr:content/par/image/file/jcr:content", contentFileCache);
+ assertEquals(file, underTest.getFile());
+ assertEquals("jcr:content/par/image/file/jcr:content", underTest.getSubPath());
+
+ assertTrue(underTest.hasContent());
+
+ Map<String,Object> content = (Map<String,Object>)underTest.getContent();
+ assertEquals("nt:resource", content.get("jcr:primaryType"));
+
+ ValueMap props = underTest.getValueMap();
+ assertEquals("nt:resource", props.get("jcr:primaryType"));
+ }
+
+ @Test
+ public void testContentProperty() {
+ File file = new File("src/test/resources/fs-test/folder2/content.json");
+
+ ContentFile underTest = new ContentFile(file, "/fs-test/folder2/content", "jcr:content/jcr:title", contentFileCache);
+ assertEquals(file, underTest.getFile());
+ assertEquals("jcr:content/jcr:title", underTest.getSubPath());
+
+ assertTrue(underTest.hasContent());
+
+ assertEquals("English", underTest.getContent());
+
+ assertTrue(underTest.getValueMap().isEmpty());
+ }
+
+ @Test
+ public void testInvalidFile() {
+ File file = new File("src/test/resources/fs-test/folder1/file1a.txt");
+ ContentFile underTest = new ContentFile(file, "/fs-test/folder1/file1a", null, contentFileCache);
+ assertFalse(underTest.hasContent());
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtilTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtilTest.java
new file mode 100644
index 0000000..71d6a38
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtilTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.mapper;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.api.resource.ValueMap;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class ValueMapUtilTest {
+
+ @Test
+ public void testToValueMap() {
+ Map<String,Object> content = new HashMap<>();
+ content.put("stringProp", "abc");
+ content.put("intProp", 123);
+ content.put("childNode", ImmutableMap.<String,Object>of());
+ content.put("stringArray", new String[] { "a", "b", "c" });
+ content.put("stringList", ImmutableList.of("ab", "cd"));
+ content.put("intList", ImmutableList.of(12, 34));
+
+ ValueMap props = ValueMapUtil.toValueMap(content);
+ assertEquals("abc", props.get("stringProp", String.class));
+ assertEquals((Integer)123, props.get("intProp", 0));
+ assertNull(props.get("childNode"));
+ assertArrayEquals(new String[] { "a", "b", "c" }, props.get("stringArray", String[].class));
+ assertArrayEquals(new String[] { "ab", "cd" }, props.get("stringList", String[].class));
+ assertArrayEquals(new Integer[] { 12, 34 }, props.get("intList", Integer[].class));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java
new file mode 100644
index 0000000..1eaf1e1
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileCacheTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.util.Map;
+
+import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+
+@RunWith(Theories.class)
+public class ContentFileCacheTest {
+
+ @DataPoint
+ public static final int NO_CACHE = 0;
+ @DataPoint
+ public static final int SMALL_CACHE = 1;
+ @DataPoint
+ public static final int HUGE_CACHE = 1000;
+
+ @Theory
+ public void testCache(int cacheSize) {
+ ContentFileCache underTest = new ContentFileCache(cacheSize);
+
+ Map<String,Object> content1 = underTest.get("/fs-test/folder2/content", new File("src/test/resources/fs-test/folder2/content.json"));
+ assertNotNull(content1);
+
+ switch (cacheSize) {
+ case NO_CACHE:
+ assertEquals(0, underTest.size());
+ break;
+ case SMALL_CACHE:
+ case HUGE_CACHE:
+ assertEquals(1, underTest.size());
+ break;
+ }
+
+ Map<String,Object> content2 = underTest.get("/fs-test/folder1/file1a", new File("src/test/resources/fs-test/folder1/file1a.txt"));
+ assertNull(content2);
+
+ switch (cacheSize) {
+ case NO_CACHE:
+ assertEquals(0, underTest.size());
+ break;
+ case SMALL_CACHE:
+ assertEquals(1, underTest.size());
+ break;
+ case HUGE_CACHE:
+ assertEquals(2, underTest.size());
+ break;
+ }
+
+ underTest.remove("/fs-test/folder1/file1a");
+
+ switch (cacheSize) {
+ case NO_CACHE:
+ case SMALL_CACHE:
+ assertEquals(0, underTest.size());
+ break;
+ case HUGE_CACHE:
+ assertEquals(1, underTest.size());
+ break;
+ }
+
+ underTest.clear();
+
+ assertEquals(0, underTest.size());
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java
new file mode 100644
index 0000000..290ea21
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class ContentFileParserTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseJson() {
+ File file = new File("src/test/resources/fs-test/folder2/content.json");
+ Map<String,Object> content = ContentFileParser.parse(file);
+ assertNotNull(content);
+ assertEquals("app:Page", content.get("jcr:primaryType"));
+ assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ }
+
+ @Test
+ public void testParseInvalidJson() {
+ File file = new File("src/test/resources/invalid-test/invalid.json");
+ Map<String,Object> content = ContentFileParser.parse(file);
+ assertNull(content);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseJcrXml() {
+ File file = new File("src/test/resources/fs-test/folder3/content.jcr.xml");
+ Map<String,Object> content = ContentFileParser.parse(file);
+ assertNotNull(content);
+ assertEquals("app:Page", content.get("jcr:primaryType"));
+ assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
+ }
+
+ @Test
+ public void testParseInvalidJcrXml() {
+ File file = new File("src/test/resources/invalid-test/invalid.jcr.xml");
+ Map<String,Object> content = ContentFileParser.parse(file);
+ assertNull(content);
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java
new file mode 100644
index 0000000..7cccbcf
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.jackrabbit.util.ISO9075;
+import org.junit.Test;
+
+public class JcrXmlFileParserTest {
+
+ @Test
+ public void testDecodeName() {
+ assertEquals("jcr:title", JcrXmlFileParser.decodeName("jcr:" + ISO9075.encode("title")));
+ assertEquals("sling:123", JcrXmlFileParser.decodeName("sling:" + ISO9075.encode("123")));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java
new file mode 100644
index 0000000..15fe989
--- /dev/null
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fsprovider.internal.parser;
+
+import static org.apache.sling.fsprovider.internal.parser.JcrXmlValueConverter.parseValue;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.Calendar;
+
+import org.junit.Test;
+
+public class JcrXmlValueConverterTest {
+
+ @Test
+ public void testNull() {
+ assertNull(parseValue(null));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalid() {
+ parseValue("{InvalidType}xyz");
+ }
+
+ @Test
+ public void testString() {
+ assertEquals("myString", parseValue("myString"));
+ assertEquals("prop", "myString [ ] { } \\ ,", parseValue("myString [ ] { } \\\\ ,"));
+ assertEquals("{myString}", parseValue("\\{myString}"));
+ assertEquals("aaa{myString}", parseValue("aaa{myString}"));
+ assertEquals("[myString]", parseValue("\\[myString]"));
+ assertEquals("aaa[myString]", parseValue("aaa[myString]"));
+ }
+
+ @Test
+ public void testStringArray() {
+ assertArrayEquals(new Object[] { "myString1", "myString2" }, (Object[]) parseValue("[myString1,myString2]"));
+ assertArrayEquals(new Object[] { "myString1,[]\\äöü߀", "myString2", "myString3 [ ] { } \\ ,", "", "[myString5]", "{myString6}" },
+ (Object[]) parseValue("[myString1\\,[]\\\\äöü߀,myString2,myString3 [ ] { } \\\\ \\,,,[myString5],{myString6}]"));
+ }
+
+ @Test
+ public void testBoolean() {
+ assertEquals(true, parseValue("{Boolean}true"));
+ assertEquals(false, parseValue("{Boolean}false"));
+ }
+
+ @Test
+ public void testBooleanArray() {
+ assertArrayEquals(new Object[] { true, false }, (Object[]) parseValue("{Boolean}[true,false]"));
+ }
+
+ @Test
+ public void testLong() {
+ assertEquals(1L, parseValue("{Long}1"));
+ assertEquals(10000000000L, parseValue("{Long}10000000000"));
+ }
+
+ @Test
+ public void testLongArray() {
+ assertArrayEquals(new Object[] { 1L, 2L }, (Object[]) parseValue("{Long}[1,2]"));
+ assertArrayEquals(new Object[] { 10000000000L, 20000000000L }, (Object[]) parseValue("{Long}[10000000000,20000000000]"));
+ }
+
+ @Test
+ public void testDouble() {
+ assertEquals(1.234d, parseValue("{Decimal}1.234"));
+ }
+
+ @Test
+ public void testDoubleArray() {
+ assertArrayEquals(new Object[] { 1.234d, 2.345d }, (Object[]) parseValue("{Decimal}[1.234,2.345]"));
+ }
+
+ @Test
+ public void testCalendar() {
+ Calendar value = (Calendar)parseValue("{Date}2010-09-05T15:10:20.000Z");
+ assertEquals(2010, value.get(Calendar.YEAR));
+ assertEquals(8, value.get(Calendar.MONTH));
+ assertEquals(5, value.get(Calendar.DAY_OF_MONTH));
+ }
+
+ @Test
+ public void testStringArrayRepPrivileges() {
+ assertArrayEquals(new Object[] { "rep:write", "crx:replicate", "jcr:read" }, (Object[]) parseValue("{Name}[rep:write,crx:replicate,jcr:read]"));
+ }
+
+}
diff --git a/src/test/resources/fs-test/folder1/file1a.txt b/src/test/resources/fs-test/folder1/file1a.txt
new file mode 100644
index 0000000..9f0f26f
--- /dev/null
+++ b/src/test/resources/fs-test/folder1/file1a.txt
@@ -0,0 +1 @@
+file1a
\ No newline at end of file
diff --git a/src/test/resources/fs-test/folder1/file1b.txt b/src/test/resources/fs-test/folder1/file1b.txt
new file mode 100644
index 0000000..518f63d
--- /dev/null
+++ b/src/test/resources/fs-test/folder1/file1b.txt
@@ -0,0 +1 @@
+file1b
\ No newline at end of file
diff --git a/src/test/resources/fs-test/folder1/folder11/file11a.txt b/src/test/resources/fs-test/folder1/folder11/file11a.txt
new file mode 100644
index 0000000..4940b5d
--- /dev/null
+++ b/src/test/resources/fs-test/folder1/folder11/file11a.txt
@@ -0,0 +1 @@
+file11a
\ No newline at end of file
diff --git a/src/test/resources/fs-test/folder2/content.json b/src/test/resources/fs-test/folder2/content.json
new file mode 100644
index 0000000..b0fc78d
--- /dev/null
+++ b/src/test/resources/fs-test/folder2/content.json
@@ -0,0 +1,262 @@
+/* Comment example */
+{
+ "jcr:primaryType": "app:Page",
+ "jcr:createdBy": "admin",
+ "jcr:created": "Thu Aug 07 2014 16:32:59 GMT+0200",
+ /* Comment example */
+ "jcr:content": {
+ "jcr:primaryType": "app:PageContent", /* Comment example */
+ "jcr:createdBy": "admin",
+ "jcr:title": "English",
+ "app:template": "sample/templates/homepage",
+ "jcr:created": "Thu Aug 07 2014 16:32:59 GMT+0200",
+ "app:lastModified": "Tue Apr 22 2014 15:11:24 GMT+0200",
+ "dateISO8601String": "2014-04-22T15:11:24.000+02:00",
+ "pageTitle": "Sample Homepage",
+ "sling:resourceType": "sample/components/homepage",
+ "sling:resourceSuperType": "sample/components/supertype",
+ "app:designPath": "/etc/designs/sample",
+ "app:lastModifiedBy": "admin",
+ "utf8Property": "äöü߀",
+ "par": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/parsys",
+ "colctrl": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "jcr:lastModifiedBy": "admin",
+ "layout": "2;colctrl-lt0",
+ "jcr:created": "Mon Aug 23 2010 22:02:24 GMT+0200",
+ "jcr:lastModified": "Mon Aug 23 2010 22:02:35 GMT+0200",
+ "sling:resourceType": "foundation/components/parsys/colctrl"
+ },
+ "image": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "fileReference": "/content/dam/sample/portraits/jane_doe.jpg",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Mon Aug 23 2010 22:03:39 GMT+0200",
+ "width": "340",
+ "jcr:lastModified": "Sun Oct 31 2010 21:39:50 GMT+0100",
+ "sling:resourceType": "foundation/components/image",
+ "file": {
+ "jcr:primaryType": "nt:file",
+ "jcr:createdBy": "admin",
+ "jcr:created": "Thu Aug 07 2014 16:32:59 GMT+0200",
+ "jcr:content": {
+ "jcr:primaryType": "nt:resource",
+ "jcr:lastModifiedBy": "anonymous",
+ "jcr:mimeType": "image/jpeg",
+ "jcr:lastModified": "Thu Aug 07 2014 16:32:59 GMT+0200",
+ ":jcr:data": 24377,
+ "jcr:uuid": "eda76d00-b2cd-4b59-878f-c33f71ceaddc"
+ }
+ }
+ },
+ "title_1": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "jcr:title": "Strategic Consulting",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Mon Aug 23 2010 22:12:08 GMT+0200",
+ "jcr:lastModified": "Wed Oct 27 2010 21:33:24 GMT+0200",
+ "sling:resourceType": "sample/components/title"
+ },
+ "text_1": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Sun Oct 31 2010 21:48:04 GMT+0100",
+ "text": "<p><span class=\"Apple-style-span\" style=\"font-size: 12px;\">In today's competitive market, organizations can face several key geometric challenges:<\/span><\/p>\n<ul>\n<li><span class=\"Apple-style-span\" style=\"font-size: 12px;\">Polyhedral Sectioning<\/span><\/li>\n<li><span class=\"Apple-style-span\" style=\"font-size: 12px;\">Triangulation <\/span><\/li>\n<li><span class=\"Apple-style-span\" style=\"font-size: 12px;\">Trigonometric Calculation<\/span><\ [...]
+ "jcr:lastModified": "Sun Oct 31 2010 21:49:06 GMT+0100",
+ "sling:resourceType": "foundation/components/text",
+ "textIsRich": "true"
+ },
+ "col_break12825937554040": {
+ "jcr:primaryType": "nt:unstructured",
+ "controlType": "break",
+ "sling:resourceType": "foundation/components/parsys/colctrl"
+ },
+ "image_0": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "fileReference": "/content/dam/sample/offices/clean_room.jpg",
+ "height": "226",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Mon Aug 23 2010 22:04:46 GMT+0200",
+ "jcr:lastModified": "Fri Nov 05 2010 10:38:15 GMT+0100",
+ "sling:resourceType": "foundation/components/image",
+ "imageRotate": "0",
+ "file": {
+ "jcr:primaryType": "nt:file",
+ "jcr:createdBy": "admin",
+ "jcr:created": "Thu Aug 07 2014 16:32:59 GMT+0200",
+ "jcr:content": {
+ "jcr:primaryType": "nt:resource",
+ "jcr:lastModifiedBy": "anonymous",
+ "jcr:mimeType": "image/jpeg",
+ "jcr:lastModified": "Thu Aug 07 2014 16:32:59 GMT+0200",
+ ":jcr:data": 21142,
+ "jcr:uuid": "6139077f-191f-4337-aaef-55456ebe6784"
+ }
+ }
+ },
+ "title_2": {
+ "jcr:createdBy": "admin",
+ "jcr:title": "Shape Technology",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Mon Aug 23 2010 22:12:13 GMT+0200",
+ "jcr:lastModified": "Tue Oct 26 2010 21:16:29 GMT+0200",
+ "sling:resourceType": "sample/components/title"
+ },
+ "text_0": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Mon Aug 23 2010 22:16:30 GMT+0200",
+ "text": "<p>The Sample investment in R&D has done more than solidify our industry leadership role, we have now outpaced our competitors to such an extent that we are in an altogether new space.<\/p>\n<p>This is why our high quality polygons and polyhedra provide the only turnkey solutions across the whole range of euclidean geometry. And our mathematicians are working on the next generation of fractal curves to bring you shapes that are unthinkable today.<\/p>\n<p><\/p>\n<p>< [...]
+ "jcr:lastModified": "Mon Nov 08 2010 20:39:00 GMT+0100",
+ "sling:resourceType": "foundation/components/text",
+ "textIsRich": "true"
+ },
+ "col_end12825937444810": {
+ "jcr:primaryType": "nt:unstructured",
+ "controlType": "end",
+ "sling:resourceType": "foundation/components/parsys/colctrl"
+ }
+ },
+ "header": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:title": "trust our experience\r\nto manage your business",
+ "imageReference": "/content/dam/sample/header.png",
+ "text": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc eget neque. Nunc condimentum ipsum et orci. Aenean est. Cras eget diam. read more",
+ "sling:resourceType": "sample/components/header"
+ },
+ "newslist": {
+ "jcr:primaryType": "nt:unstructured",
+ "headline": "trust our experience\nto manage your business",
+ "text": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc eget neque. Nunc condimentum ipsum et orci. Aenean est. Cras eget diam. read more",
+ "sling:resourceType": "sample/components/listchildren",
+ "listroot": "/content/sample/en/about/news"
+ },
+ "lead": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:title": "World Leader in Applied Geometry ",
+ "jcr:lastModifiedBy": "admin",
+ "text": "Lead Text",
+ "title": "Lead Title",
+ "jcr:description": "Sample has been selling and servicing shapes for over 2000 years. From our beginnings as a small vendor of squares and rectangles we have grown our business into a leading global provider of platonic solids and fractals. Join us as we lead geometry into the future.",
+ "jcr:lastModified": "Wed Jan 19 2011 14:35:29 GMT+0100",
+ "sling:resourceType": "sample/components/lead",
+ "app:annotations": {"jcr:primaryType": "nt:unstructured"}
+ },
+ "image": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:lastModified": "Wed Oct 27 2010 21:30:59 GMT+0200",
+ "imageRotate": "0"
+ },
+ "carousel": {
+ "jcr:primaryType": "nt:unstructured",
+ "playSpeed": "6000",
+ "jcr:lastModifiedBy": "admin",
+ "pages": [
+ "/content/sample/en/events/techsummit",
+ "/content/sample/en/events/userconf",
+ "/content/sample/en/events/shapecon",
+ "/content/sample/en/events/dsc"
+ ],
+ "jcr:lastModified": "Tue Oct 05 2010 14:14:27 GMT+0200",
+ "transTime": "1000",
+ "sling:resourceType": "foundation/components/carousel",
+ "listFrom": "static"
+ },
+ "rightpar": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/parsys",
+ "teaser": {
+ "jcr:primaryType": "nt:unstructured",
+ "jcr:createdBy": "admin",
+ "jcr:lastModifiedBy": "admin",
+ "jcr:created": "Tue Jan 25 2011 11:30:09 GMT+0100",
+ "campaignpath": "/content/campaigns/sample",
+ "jcr:lastModified": "Wed Feb 02 2011 08:40:30 GMT+0100",
+ "sling:resourceType": "personalization/components/teaser"
+ }
+ }
+ },
+ "toolbar": {
+ "jcr:primaryType": "app:Page",
+ "jcr:createdBy": "admin",
+ "jcr:created": "Thu Aug 07 2014 16:33:00 GMT+0200",
+ "jcr:content": {
+ "jcr:primaryType": "app:PageContent",
+ "subtitle": "Contains the toolbar",
+ "jcr:createdBy": "admin",
+ "jcr:title": "Toolbar",
+ "app:template": "sample/templates/contentpage",
+ "jcr:created": "Thu Aug 07 2014 16:33:00 GMT+0200",
+ "app:lastModified": "Wed Aug 25 2010 22:51:02 GMT+0200",
+ "hideInNav": "true",
+ "sling:resourceType": "sample/components/contentpage",
+ "app:lastModifiedBy": "admin",
+ "par": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/parsys"
+ },
+ "rightpar": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/iparsys",
+ "iparsys_fake_par": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/iparsys/par"
+ }
+ }
+ },
+ "profiles": {
+ "jcr:primaryType": "app:Page",
+ "jcr:createdBy": "admin",
+ "jcr:created": "Thu Aug 07 2014 16:33:00 GMT+0200",
+ "jcr:content": {
+ "jcr:primaryType": "app:PageContent",
+ "jcr:mixinTypes": ["type1","type2"],
+ "jcr:createdBy": "admin",
+ "jcr:title": "Profiles",
+ "app:template": "sample/templates/contentpage",
+ "jcr:created": "Thu Aug 07 2014 16:33:00 GMT+0200",
+ "app:lastModified": "Thu Nov 05 2009 20:27:13 GMT+0100",
+ "hideInNav": true,
+ "sling:resourceType": "sample/components/contentpage",
+ "app:lastModifiedBy": "admin",
+ "longProp": 1234567890123,
+ "decimalProp": 1.2345,
+ "booleanProp": true,
+ "longPropMulti": [1234567890123,55],
+ "decimalPropMulti": [1.2345,1.1],
+ "booleanPropMulti": [true,false],
+ "stringPropMulti": ["aa","bb","cc"],
+ "par": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/parsys",
+ "textimage": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/textimage"
+ },
+ "mygadgets": {
+ "jcr:primaryType": "nt:unstructured",
+ "gadgets": "http://customer.meteogroup.de/meteogroup/gadgets/wetter24.xml\nhttp://germanweatherradar.googlecode.com/svn/trunk/german-weather-radar.xml\nhttp://www.digitalpowered.info/gadget/ski.pictures.xml\nhttp://www.canbuffi.de/gadgets/clock/clock.xml",
+ "sling:resourceType": "personalization/components/mygadgets"
+ }
+ },
+ "rightpar": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/iparsys",
+ "iparsys_fake_par": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "foundation/components/iparsys/par"
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/test/resources/fs-test/folder2/content/content2.json b/src/test/resources/fs-test/folder2/content/content2.json
new file mode 100644
index 0000000..261509a
--- /dev/null
+++ b/src/test/resources/fs-test/folder2/content/content2.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "app:Page",
+ "jcr:createdBy": "admin"
+}
diff --git a/src/test/resources/fs-test/folder2/content/file2content.txt b/src/test/resources/fs-test/folder2/content/file2content.txt
new file mode 100644
index 0000000..667b547
--- /dev/null
+++ b/src/test/resources/fs-test/folder2/content/file2content.txt
@@ -0,0 +1 @@
+file2content
\ No newline at end of file
diff --git a/src/test/resources/fs-test/folder2/folder21/file21a.txt b/src/test/resources/fs-test/folder2/folder21/file21a.txt
new file mode 100644
index 0000000..3d5becc
--- /dev/null
+++ b/src/test/resources/fs-test/folder2/folder21/file21a.txt
@@ -0,0 +1 @@
+file21a
\ No newline at end of file
diff --git a/src/test/resources/fs-test/folder3/content.jcr.xml b/src/test/resources/fs-test/folder3/content.jcr.xml
new file mode 100644
index 0000000..da111ee
--- /dev/null
+++ b/src/test/resources/fs-test/folder3/content.jcr.xml
@@ -0,0 +1,192 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/jcr/app/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="app:Page">
+ <jcr:content
+ jcr:primaryType="app:PageContent"
+ jcr:title="en"
+ sling:resourceType="samples/sample-app/components/content/page/homepage"
+ includeAside="{Boolean}true"
+ includeAsideBar="{Boolean}true"
+ includeTeaserBar="{Boolean}true"
+ includeTeaserbar="{Boolean}true"
+ inheritAside="{Boolean}false"
+ inheritTeaserbar="{Boolean}false"
+ longProp="{Long}1234567890123"
+ decimalProp="{Decimal}1.2345"
+ longPropMulti="{Long}[1234567890123,55]"
+ stringPropMulti="[aa,bb,cc]"
+ navTitle="HOME"
+ pageTitle="Sample Site">
+ <teaserbar
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarParsys">
+ <teaserbaritem
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/conference"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="This should help you with your decision"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/user.png"
+ teaserContent="Still not convinced to attend? Need persuasion? Facts for your boss?"
+ title="Why to attend" />
+ <teaserbaritem_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/venue"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="More information"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/location.png"
+ teaserContent="Take a look at the new venue for 2013. The Kulturbrauerei in the Prenzlauer Berg district."
+ title="Location" />
+ <teaserbaritem_1
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/conference/call-for-papers"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Submit your proposal here"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/talk.png"
+ teaserContent="If you have insight and experiences with Apache Sling and want to share them? We are actually asking for your participation!"
+ title="Want to share?" />
+ <teaserbaritem_2
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/archive"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Dive into the archive"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/archive.png"
+ teaserContent="adaptTo() is not a new event. Take a look at what was said and done previously."
+ title="Take a look back" />
+ </teaserbar>
+ <aside
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideParsys">
+ <asidesponsorteaser
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaser"
+ title="Sponsors">
+ <images
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserParsys">
+ <asidesponsorteaserit_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserItem"
+ imageHeight="41"
+ imageWidth="200"
+ linkExternalRef="http://www.pro-vision.de"
+ linkType="external"
+ linkWindowFeatures="default"
+ linkWindowTarget="_blank"
+ mediaRef="/content/dam/samples/content/provision-logo.png" />
+ </images>
+ </asidesponsorteaser>
+ <asidesocialteaser
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSocialTeaser"
+ title="Follow us">
+ <images
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserParsys">
+ <asidesocialteaserite
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSocialTeaserItem"
+ linkExternalRef="http://twitter.com/adaptto"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="@adaptTo"
+ linkType="external"
+ linkWindowFeatures="default"
+ linkWindowTarget="_blank"
+ mediaRef="/content/dam/samples/content/twitter-icon.png"
+ title="on twitter" />
+ </images>
+ </asidesocialteaser>
+ </aside>
+ <content
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="sample/wcm/parsys/components/parsys">
+ <contentrichtext
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentRichText"
+ text="<p>adaptTo() is a meetup in Berlin focused on Apache Sling including Apache Jackrabbit and Apache Felix and is addressed to all using this stack or parts of it.</p>
<p><a data="{&quot;linkType&quot;:&quot;internal&quot;,&quot;linkContentRef&quot;:&quot;/content/samples/handler/en/conference&quot;,&quot;linkWindowTarget&quot;:&quot;_self&quot;,&quot;linkWindowFeatures&quot;:&quot;defa [...]
+ <contentheadline
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentHeadline"
+ headline="Extended Call for Papers"
+ smaller="{Boolean}true" />
+ <contentrichtext_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentRichText"
+ text="<p>Although we got some great submissions for adaptTo() 2013, we still have some slots for further sessions. Therefore we extend the timeslot for submissions to the call for papers and for feedback by two weeks. This means you still can submit you submissions till 06.05.2013. We're looking forward to get more of your great talks.</p>
<p><a data="{&quot;linkType&quot;:&quot;internal&quot;,&quot;linkContentRef&quot;:& [...]
+ </content>
+ <stage
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="sample/wcm/parsys/components/parsys">
+ <stageheader
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheader"
+ linkMediaDownload="{Boolean}false"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/stageheader-outside2.jpg"
+ subtitle="23.–25. September 2013
Kulturbrauerei Berlin"
+ title="adaptTo() 2013">
+ <links
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheaderParsys">
+ <stageheaderlinkitem
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheaderLinkItem"
+ linkContentRef="/content/samples/en/tickets"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Get tickets now"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self" />
+ <stageheaderlinkitem_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheaderLinkItem"
+ linkContentRef="/content/samples/en/conference/call-for-papers"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Submit paper"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self" />
+ </links>
+ </stageheader>
+ </stage>
+ <image
+ jcr:primaryType="nt:unstructured" />
+ </jcr:content>
+ <tools />
+ <conference />
+</jcr:root>
diff --git a/src/test/resources/fs-test/folder3/content/content2.jcr.xml b/src/test/resources/fs-test/folder3/content/content2.jcr.xml
new file mode 100644
index 0000000..3964ca4
--- /dev/null
+++ b/src/test/resources/fs-test/folder3/content/content2.jcr.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/jcr/app/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="app:Page">
+ <jcr:content
+ app:template="samples/sample-app/templates/admin/structureElement"
+ jcr:primaryType="app:PageContent"
+ jcr:title="tools"
+ sling:resourceType="samples/sample-app/components/admin/page/structureElement"
+ hideInNav="{Boolean}true" />
+ <navigation />
+</jcr:root>
diff --git a/src/test/resources/fs-test/folder3/folder31/file31a.txt b/src/test/resources/fs-test/folder3/folder31/file31a.txt
new file mode 100644
index 0000000..3d5becc
--- /dev/null
+++ b/src/test/resources/fs-test/folder3/folder31/file31a.txt
@@ -0,0 +1 @@
+file21a
\ No newline at end of file
diff --git a/src/test/resources/invalid-test/invalid.jcr.xml b/src/test/resources/invalid-test/invalid.jcr.xml
new file mode 100644
index 0000000..7df8a70
--- /dev/null
+++ b/src/test/resources/invalid-test/invalid.jcr.xml
@@ -0,0 +1 @@
+This is invalid xml.
diff --git a/src/test/resources/invalid-test/invalid.json b/src/test/resources/invalid-test/invalid.json
new file mode 100644
index 0000000..59fc86c
--- /dev/null
+++ b/src/test/resources/invalid-test/invalid.json
@@ -0,0 +1 @@
+This is invalid json.
diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties
new file mode 100644
index 0000000..e62c1ea
--- /dev/null
+++ b/src/test/resources/simplelogger.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.slf4j.simpleLogger.defaultLogLevel=warn
+org.slf4j.simpleLogger.log.org.apache.sling.fsprovider.internal=warn
diff --git a/src/test/resources/vaultfs-test/META-INF/vault/filter.xml b/src/test/resources/vaultfs-test/META-INF/vault/filter.xml
new file mode 100644
index 0000000..20be2d8
--- /dev/null
+++ b/src/test/resources/vaultfs-test/META-INF/vault/filter.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<workspaceFilter version="1.0">
+ <filter root="/content/dam/talk.png" />
+ <filter root="/content/samples" />
+</workspaceFilter>
diff --git a/src/test/resources/vaultfs-test/META-INF/vault/settings.xml b/src/test/resources/vaultfs-test/META-INF/vault/settings.xml
new file mode 100644
index 0000000..3f8e13a
--- /dev/null
+++ b/src/test/resources/vaultfs-test/META-INF/vault/settings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<vault version="1.0">
+ <ignore name=".svn"/>
+ <ignore name=".DS_Store"/>
+</vault>
diff --git a/src/test/resources/vaultfs-test/jcr_root/.content.xml b/src/test/resources/vaultfs-test/jcr_root/.content.xml
new file mode 100644
index 0000000..b264022
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/.content.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:mixinTypes="[rep:AccessControllable,rep:RepoAccessControllable]"
+ jcr:primaryType="rep:root"
+ sling:resourceType="sling:redirect"
+ sling:target="/index.html" />
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/.content.xml
new file mode 100644
index 0000000..115c72c
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/.content.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:mixinTypes="[mix:lockable,rep:AccessControllable,sling:Redirect]"
+ jcr:primaryType="sling:OrderedFolder"
+ jcr:title="Content Root"
+ sling:resourceType="sling:redirect"
+ sling:target="/geohome">
+ <dam />
+ <samples />
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/dam/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/dam/.content.xml
new file mode 100644
index 0000000..64f25b1
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/dam/.content.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:rep="internal" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:mixinTypes="[mix:lockable,rep:AccessControllable]"
+ jcr:primaryType="sling:OrderedFolder">
+ <talk.png />
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml
new file mode 100644
index 0000000..4f8312a
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/.content.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/app/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:primaryType="app:Asset">
+ <jcr:content
+ jcr:primaryType="app:AssetContent">
+ <metadata
+ app:Bitsperpixel="{Long}4"
+ app:extracted="{Date}2015-09-19T14:33:36.078+02:00"
+ app:Fileformat="PNG"
+ app:MIMEtype="image/png"
+ app:Numberofimages="{Long}1"
+ app:Numberoftextualcomments="{Long}3"
+ app:Physicalheightindpi="{Long}72"
+ app:Physicalheightininches="{Decimal}3.750854253768921"
+ app:Physicalwidthindpi="{Long}72"
+ app:Physicalwidthininches="{Decimal}6.668185710906982"
+ app:Progressive="no"
+ app:sha1="29e02b493473c2beaf851002b67b6f1b700be978"
+ app:size="{Long}6652"
+ app:writebackEnable="False"
+ dc:format="image/png"
+ dc:modified="{Date}2014-09-19T21:20:26.812+02:00"
+ jcr:primaryType="nt:unstructured"
+ tiff:ImageLength="{Long}270"
+ tiff:ImageWidth="{Long}480"
+ writebackEnable="{Boolean}true" />
+ </jcr:content>
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/original b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/original
new file mode 100644
index 0000000..0d42760
Binary files /dev/null and b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/original differ
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/original.dir/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/original.dir/.content.xml
new file mode 100644
index 0000000..1813b25
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/original.dir/.content.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:primaryType="nt:file">
+ <jcr:content
+ jcr:mimeType="image/png"
+ jcr:primaryType="nt:resource" />
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/web.1280.1280.png b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/web.1280.1280.png
new file mode 100644
index 0000000..27b0374
Binary files /dev/null and b/src/test/resources/vaultfs-test/jcr_root/content/dam/talk.png/_jcr_content/renditions/web.1280.1280.png differ
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/.content.xml
new file mode 100644
index 0000000..c96141e
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/.content.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="sling:OrderedFolder">
+ <en />
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/en/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/.content.xml
new file mode 100644
index 0000000..83b8626
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/.content.xml
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/jcr/app/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="app:Page">
+ <jcr:content
+ app:cloudserviceconfigs="[[]]"
+ app:deviceGroups="[/etc/mobile/groups/responsive]"
+ app:template="samples/sample-app/templates/content/homepage"
+ jcr:primaryType="app:PageContent"
+ jcr:title="en"
+ sling:resourceType="samples/sample-app/components/content/page/homepage"
+ includeAside="{Boolean}true"
+ includeAsideBar="{Boolean}true"
+ includeTeaserBar="{Boolean}true"
+ includeTeaserbar="{Boolean}true"
+ inheritAside="{Boolean}false"
+ inheritTeaserbar="{Boolean}false"
+ navTitle="HOME"
+ pageTitle="Sample Site">
+ <teaserbar
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarParsys">
+ <teaserbaritem
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/conference"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="This should help you with your decision"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/user.png"
+ teaserContent="Still not convinced to attend? Need persuasion? Facts for your boss?"
+ title="Why to attend" />
+ <teaserbaritem_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/venue"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="More information"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/location.png"
+ teaserContent="Take a look at the new venue for 2013. The Kulturbrauerei in the Prenzlauer Berg district."
+ title="Location" />
+ <teaserbaritem_1
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/conference/call-for-papers"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Submit your proposal here"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/talk.png"
+ teaserContent="If you have insight and experiences with Apache Sling and want to share them? We are actually asking for your participation!"
+ title="Want to share?" />
+ <teaserbaritem_2
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/teaserbar/teaserbarItem"
+ linkContentRef="/content/samples/en/archive"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Dive into the archive"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/archive.png"
+ teaserContent="adaptTo() is not a new event. Take a look at what was said and done previously."
+ title="Take a look back" />
+ </teaserbar>
+ <aside
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideParsys">
+ <asidesponsorteaser
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaser"
+ title="Sponsors">
+ <images
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserParsys">
+ <asidesponsorteaserit_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserItem"
+ imageHeight="41"
+ imageWidth="200"
+ linkExternalRef="http://www.pro-vision.de"
+ linkType="external"
+ linkWindowFeatures="default"
+ linkWindowTarget="_blank"
+ mediaRef="/content/dam/samples/content/provision-logo.png" />
+ </images>
+ </asidesponsorteaser>
+ <asidesocialteaser
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSocialTeaser"
+ title="Follow us">
+ <images
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserParsys">
+ <asidesocialteaserite
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSocialTeaserItem"
+ linkExternalRef="http://twitter.com/adaptto"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="@adaptTo"
+ linkType="external"
+ linkWindowFeatures="default"
+ linkWindowTarget="_blank"
+ mediaRef="/content/dam/samples/content/twitter-icon.png"
+ title="on twitter" />
+ </images>
+ </asidesocialteaser>
+ </aside>
+ <content
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="sample/wcm/parsys/components/parsys">
+ <contentrichtext
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentRichText"
+ text="<p>adaptTo() is a meetup in Berlin focused on Apache Sling including Apache Jackrabbit and Apache Felix and is addressed to all using this stack or parts of it.</p>
<p><a data="{&quot;linkType&quot;:&quot;internal&quot;,&quot;linkContentRef&quot;:&quot;/content/samples/handler/en/conference&quot;,&quot;linkWindowTarget&quot;:&quot;_self&quot;,&quot;linkWindowFeatures&quot;:&quot;defa [...]
+ <contentheadline
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentHeadline"
+ headline="Extended Call for Papers"
+ smaller="{Boolean}true" />
+ <contentrichtext_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentRichText"
+ text="<p>Although we got some great submissions for adaptTo() 2013, we still have some slots for further sessions. Therefore we extend the timeslot for submissions to the call for papers and for feedback by two weeks. This means you still can submit you submissions till 06.05.2013. We're looking forward to get more of your great talks.</p>
<p><a data="{&quot;linkType&quot;:&quot;internal&quot;,&quot;linkContentRef&quot;:& [...]
+ </content>
+ <stage
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="sample/wcm/parsys/components/parsys">
+ <stageheader
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheader"
+ linkMediaDownload="{Boolean}false"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self"
+ mediaRef="/content/dam/samples/content/stageheader-outside2.jpg"
+ subtitle="23.–25. September 2013
Kulturbrauerei Berlin"
+ title="adaptTo() 2013">
+ <links
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheaderParsys">
+ <stageheaderlinkitem
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheaderLinkItem"
+ linkContentRef="/content/samples/en/tickets"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Get tickets now"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self" />
+ <stageheaderlinkitem_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/stage/stageheaderLinkItem"
+ linkContentRef="/content/samples/en/conference/call-for-papers"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Submit paper"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self" />
+ </links>
+ </stageheader>
+ </stage>
+ <image
+ jcr:primaryType="nt:unstructured" />
+ </jcr:content>
+ <tools />
+ <conference />
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/en/conference/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/conference/.content.xml
new file mode 100644
index 0000000..2c2ef86
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/conference/.content.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/jcr/app/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="app:Page">
+ <jcr:content
+ app:template="samples/sample-app/templates/content/content"
+ jcr:primaryType="app:PageContent"
+ jcr:title="Conference"
+ sling:resourceType="samples/sample-app/components/content/page/content"
+ includeAside="{Boolean}true"
+ includeAsideBar="{Boolean}true"
+ includeTeaserBar="{Boolean}true"
+ includeTeaserbar="{Boolean}false"
+ inheritAside="{Boolean}false"
+ inheritTeaserBar="{Boolean}true"
+ inheritTeaserbar="{Boolean}false"
+ navTitle="CONFERENCE">
+ <content
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="sample/wcm/parsys/components/parsys">
+ <contentheadline
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentHeadline"
+ headline="About adaptTo() 2013" />
+ <contentrichtext
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/common/contentRichText"
+ text="<p>adaptTo() is a technical meetup focused on the technical stack of <a data="{&quot;linkType&quot;:&quot;external&quot;,&quot;linkExternalRef&quot;:&quot;http://sling.apache.org/&quot;,&quot;linkWindowTarget&quot;:&quot;_blank&quot;,&quot;linkWindowFeatures&quot;:&quot;default&quot;}" href="#">Apache Sling</a> including <a data="{&quot;linkType&quot;:& [...]
+ </content>
+ <aside
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideParsys">
+ <asideteaser
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideTeaser"
+ teaserContent="<p>Submit your paper to attend the conference as speaker</p>
"
+ title="Call for Papers">
+ <links
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/framework/parsys/linkListParsys">
+ <linkItem
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/framework/item/linkItem"
+ linkContentRef="/content/samples/en/conference/call-for-papers"
+ linkMediaDownload="{Boolean}false"
+ linkTitle="Call for Papers"
+ linkType="internal"
+ linkWindowFeatures="default"
+ linkWindowTarget="_self" />
+ </links>
+ </asideteaser>
+ <asidesponsorteaser
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaser"
+ title="Sponsors">
+ <images
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserParsys">
+ <asidesponsorteaserit_0
+ jcr:primaryType="nt:unstructured"
+ sling:resourceType="samples/sample-app/components/content/aside/asideSponsorTeaserItem"
+ linkExternalRef="http://www.pro-vision.de"
+ linkMediaDownload="{Boolean}false"
+ linkType="external"
+ linkWindowFeatures="default"
+ linkWindowTarget="_blank"
+ mediaRef="/content/dam/samples/content/provision-logo.png" />
+ </images>
+ </asidesponsorteaser>
+ </aside>
+ </jcr:content>
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/en/tools/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/tools/.content.xml
new file mode 100644
index 0000000..3964ca4
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/tools/.content.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/jcr/app/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="app:Page">
+ <jcr:content
+ app:template="samples/sample-app/templates/admin/structureElement"
+ jcr:primaryType="app:PageContent"
+ jcr:title="tools"
+ sling:resourceType="samples/sample-app/components/admin/page/structureElement"
+ hideInNav="{Boolean}true" />
+ <navigation />
+</jcr:root>
diff --git a/src/test/resources/vaultfs-test/jcr_root/content/samples/en/tools/navigation/.content.xml b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/tools/navigation/.content.xml
new file mode 100644
index 0000000..676d8b9
--- /dev/null
+++ b/src/test/resources/vaultfs-test/jcr_root/content/samples/en/tools/navigation/.content.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:app="http://sample.com/jcr/app/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
+ jcr:primaryType="app:Page">
+ <jcr:content
+ app:template="samples/sample-app/templates/admin/structureElement"
+ jcr:primaryType="app:PageContent"
+ jcr:title="navigation"
+ sling:resourceType="samples/sample-app/components/admin/page/structureElement" />
+</jcr:root>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 09/23: update scm urls for
branch
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit a30fb874bb5fc8267b1011eeb41fea6c27dabf8a
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Tue Mar 7 21:16:42 2017 +0000
update scm urls for branch
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1785890 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index e530623..4f0ba96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,9 +36,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/fsresource</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/fsresource</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/branches/fsresource-1.x</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/branches/fsresource-1.x</url>
</scm>
<build>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 16/23: cosmetic: use consistent
wording, reorder config attributes
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 81a06d62bc512ee072b96009cc414ffc1183af71
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Mar 10 16:30:36 2017 +0000
cosmetic: use consistent wording, reorder config attributes
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786380 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/sling/fsprovider/internal/FsMode.java | 2 +-
.../fsprovider/internal/FsResourceProvider.java | 45 +++++++++-------------
.../internal/mapper/FileVaultResourceMapper.java | 2 +-
.../sling/fsprovider/internal/FileMonitorTest.java | 2 +-
.../internal/FileVaultFileMonitorTest.java | 2 +-
.../sling/fsprovider/internal/FilesFolderTest.java | 2 +-
.../fsprovider/internal/JcrXmlContentTest.java | 2 +-
.../sling/fsprovider/internal/JsonContentTest.java | 2 +-
8 files changed, 26 insertions(+), 33 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
index 50eeebd..b255bb2 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
@@ -29,7 +29,7 @@ public enum FsMode {
FILES_FOLDERS,
/**
- * Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format.
+ * Sling-Initial-Content file system layout, supports file and folders ant content files in JSON and jcr.xml format.
*/
INITIAL_CONTENT,
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index 3745107..b00825b 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -82,14 +82,10 @@ public final class FsResourceProvider implements ResourceProvider {
public static final String RESOURCE_METADATA_FILE_DIRECTORY = ":org.apache.sling.fsprovider.file.directory";
@ObjectClassDefinition(name = "Apache Sling File System Resource Provider",
- description = "Configure an instance of the filesystem " +
- "resource provider in terms of provider root and filesystem location")
+ description = "Configure an instance of the file system " +
+ "resource provider in terms of provider root and file system location")
public @interface Config {
- /**
- * The name of the configuration property providing file system path of
- * files and folders mapped into the resource tree (value is
- * "provider.file").
- */
+
@AttributeDefinition(name = "File System Root",
description = "File system directory mapped to the virtual " +
"resource tree. This property must not be an empty string. If the path is " +
@@ -98,41 +94,38 @@ public final class FsResourceProvider implements ResourceProvider {
"file or folder, an empty folder is created.")
String provider_file();
- /**
- * The name of the configuration property providing the check interval
- * for file changes (value is "provider.checkinterval").
- */
- @AttributeDefinition(name = "Check Interval",
- description = "If the interval has a value higher than 100, the provider will " +
- "check the file system for changes periodically. This interval defines the period in milliseconds " +
- "(the default is 1000). If a change is detected, resource events are sent through the event admin.")
- long provider_checkinterval() default 1000;
-
- @AttributeDefinition(name = "Provider Roots",
- description = "Locations in the virtual resource tree where the " +
- "filesystem resources are mapped in. This property must contain at least one non-empty string.")
+ @AttributeDefinition(name = "Provider Root",
+ description = "Location in the virtual resource tree where the " +
+ "file system resources are mapped in. This property must not be an empty string. Only one path is supported.")
String[] provider_roots();
- @AttributeDefinition(name = "Filesystem layout",
- description = "Filesystem layout mode for files, folders and content.",
+ @AttributeDefinition(name = "File system layout",
+ description = "File system layout mode for files, folders and content.",
options={
@Option(value="FILES_FOLDERS", label="FILES_FOLDERS - "
+ "Support only files and folders (classic mode)"),
@Option(value="INITIAL_CONTENT", label="INITIAL_CONTENT - "
- + "Sling-Initial-Content filesystem layout, supports file and folders ant content files in JSON and jcr.xml format"),
+ + "Sling-Initial-Content file system layout, supports file and folders ant content files in JSON and jcr.xml format"),
@Option(value="FILEVAULT_XML", label="FILEVAULT_XML - "
+ "FileVault XML format (expanded content package)"),
})
FsMode provider_fs_mode() default FsMode.FILES_FOLDERS;
@AttributeDefinition(name = "Init. Content Options",
- description = "Import options for Sling-Initial-Content filesystem layout. Supported options: overwrite, ignoreImportProviders.")
+ description = "Import options for Sling-Initial-Content file system layout. Supported options: overwrite, ignoreImportProviders.")
String provider_initial_content_import_options();
@AttributeDefinition(name = "FileVault Filter",
- description = "Path to META-INF/vault/filter.xml when using FileVault XML filesystem layout.")
+ description = "Path to META-INF/vault/filter.xml when using FileVault XML file system layout.")
String provider_filevault_filterxml_path();
+
+ @AttributeDefinition(name = "Check Interval",
+ description = "If the interval has a value higher than 100, the provider will " +
+ "check the file system for changes periodically. This interval defines the period in milliseconds " +
+ "(the default is 1000). If a change is detected, resource events are sent through the event admin.")
+ long provider_checkinterval() default 1000;
+
@AttributeDefinition(name = "Cache Size",
description = "Max. number of content files cached in memory.")
int provider_cache_size() default 10000;
@@ -152,7 +145,7 @@ public final class FsResourceProvider implements ResourceProvider {
// The monitor to detect file changes.
private FileMonitor monitor;
- // maps filesystem to resources
+ // maps file system to resources
private FsMode fsMode;
private FsResourceMapper fileMapper;
private FsResourceMapper contentFileMapper;
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
index cb25230..6585d1e 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
@@ -104,7 +104,7 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
}
}
- // additional check for children in filesystem
+ // additional check for children in file system
File parentFile = getFile(parentPath);
if (parentFile != null && parentFile.isDirectory()) {
for (File childFile : parentFile.listFiles()) {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
index a9c842b..978419b 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
@@ -42,7 +42,7 @@ import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
/**
- * Test events when changing filesystem content (Sling-Initial-Content).
+ * Test events when changing file system content (Sling-Initial-Content).
*/
public class FileMonitorTest {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
index ff7beea..0475f77 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
@@ -42,7 +42,7 @@ import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
/**
- * Test events when changing filesystem content (FileVault XML).
+ * Test events when changing file system content (FileVault XML).
*/
public class FileVaultFileMonitorTest {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
index 1930a94..c1f3470 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
@@ -34,7 +34,7 @@ import org.junit.Rule;
import org.junit.Test;
/**
- * Test access to files and folders from filesystem.
+ * Test access to files and folders from file system.
*/
public class FilesFolderTest {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
index 2a677ba..463963a 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
@@ -48,7 +48,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
/**
- * Test access to files and folders from filesystem.
+ * Test access to files and folders from file system.
*/
public class JcrXmlContentTest {
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 5e76a4e..f38a75f 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -59,7 +59,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
/**
- * Test access to files and folders and JSON content from filesystem.
+ * Test access to files and folders and JSON content from file system.
*/
public class JsonContentTest {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 04/23: SLING-6440 switch to
fscontentparser rename "Filesystem" to "File System" update to latest
parent
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 2ea88527670a02516ee6f8317ce40d6e50847e63
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Mar 2 17:39:13 2017 +0000
SLING-6440 switch to fscontentparser
rename "Filesystem" to "File System"
update to latest parent
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.1.x@1785170 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 44 ++----
.../fsprovider/internal/FsResourceProvider.java | 8 +-
.../fsprovider/internal/mapper/FileResource.java | 2 +-
.../fsprovider/internal/mapper/ValueMapUtil.java | 7 -
.../internal/parser/ContentFileCache.java | 2 +-
...tFileParser.java => ContentFileParserUtil.java} | 27 +++-
.../internal/parser/ContentFileTypes.java | 6 +-
.../internal/parser/JcrXmlFileParser.java | 147 ------------------
.../internal/parser/JcrXmlValueConverter.java | 168 ---------------------
.../fsprovider/internal/parser/JsonFileParser.java | 125 ---------------
.../fsprovider/internal/JcrXmlContentTest.java | 10 +-
.../sling/fsprovider/internal/JsonContentTest.java | 15 +-
...serTest.java => ContentFileParserUtilTest.java} | 10 +-
.../internal/parser/JcrXmlFileParserTest.java | 34 -----
.../internal/parser/JcrXmlValueConverterTest.java | 105 -------------
15 files changed, 62 insertions(+), 648 deletions(-)
diff --git a/pom.xml b/pom.xml
index c871b0c..5db693f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>29</version>
+ <version>30-SNAPSHOT</version>
<relativePath />
</parent>
@@ -30,10 +30,9 @@
<packaging>bundle</packaging>
<version>1.1.5-SNAPSHOT</version>
- <name>Apache Sling Filesystem Resource Provider</name>
+ <name>Apache Sling File System Resource Provider</name>
<description>
- Provides a ResourceProvider implementation supporting filesystem
- based resources.
+ Provides a ResourceProvider implementation supporting file system based resources.
</description>
<scm>
@@ -61,33 +60,14 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
- <executions>
- <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
- <execution>
- <id>scr-metadata</id>
- <goals>
- <goal>manifest</goal>
- </goals>
- <configuration>
- <supportIncrementalBuild>true</supportIncrementalBuild>
- </configuration>
- </execution>
- </executions>
<configuration>
- <!-- Export SCR metadata to classpath to have them available in unit tests -->
- <exportScr>true</exportScr>
<instructions>
- <!-- Embed Apache Johnzon -->
+ <!-- Embed Apache Johnzon and fscontentparser -->
<Embed-Dependency>
johnzon-core;scope=compile;inline=false,
- geronimo-json_1.0_spec;scope=compile;inline=false
+ geronimo-json_1.0_spec;scope=compile;inline=false,
+ org.apache.sling.fscontentparser;scope=compile;inline=false
</Embed-Dependency>
- <!-- Embed the nessecary parts of the jackrabbit-jcr-commons bundle as described in http://njbartlett.name/2014/05/26/static-linking.html -->
- <Conditional-Package>org.apache.jackrabbit.util</Conditional-Package>
- <Import-Package>
- !org.apache.jackrabbit.*,
- *
- </Import-Package>
</instructions>
</configuration>
</plugin>
@@ -154,18 +134,18 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-jcr-commons</artifactId>
- <version>2.8.0</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>org.apache.sling</groupId>
<artifactId>adapter-annotations</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.fscontentparser</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index e3e3bad..12e5bf2 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -66,13 +66,13 @@ import org.osgi.service.metatype.annotations.ObjectClassDefinition;
service=ResourceProvider.class,
configurationPolicy=ConfigurationPolicy.REQUIRE,
property={
- Constants.SERVICE_DESCRIPTION + "=Sling Filesystem Resource Provider",
+ Constants.SERVICE_DESCRIPTION + "=Sling File System Resource Provider",
Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
})
@Designate(ocd=FsResourceProvider.Config.class, factory=true)
public final class FsResourceProvider implements ResourceProvider {
- @ObjectClassDefinition(name = "Apache Sling Filesystem Resource Provider",
+ @ObjectClassDefinition(name = "Apache Sling File System Resource Provider",
description = "Configure an instance of the filesystem " +
"resource provider in terms of provider root and filesystem location")
public @interface Config {
@@ -81,8 +81,8 @@ public final class FsResourceProvider implements ResourceProvider {
* files and folders mapped into the resource tree (value is
* "provider.file").
*/
- @AttributeDefinition(name = "Filesystem Root",
- description = "Filesystem directory mapped to the virtual " +
+ @AttributeDefinition(name = "File System Root",
+ description = "File system directory mapped to the virtual " +
"resource tree. This property must not be an empty string. If the path is " +
"relative it is resolved against sling.home or the current working directory. " +
"The path may be a file or folder. If the path does not address an existing " +
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 67cd178..e3a61ac 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
@@ -81,7 +81,7 @@ public final class FileResource extends AbstractResource {
private static final Logger log = LoggerFactory.getLogger(FileResource.class);
/**
- * Creates an instance of this Filesystem resource.
+ * Creates an instance of this File system resource.
*
* @param resolver The owning resource resolver
* @param resourcePath The resource path in the resource tree
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
index 8ddbda7..0d12ee1 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/ValueMapUtil.java
@@ -22,8 +22,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import javax.jcr.nodetype.NodeType;
-
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
@@ -55,11 +53,6 @@ final class ValueMapUtil {
}
}
- // fallback to default jcr:primaryType is none is set
- if (!props.containsKey("jcr:primaryType")) {
- props.put("jcr:primaryType", NodeType.NT_UNSTRUCTURED);
- }
-
return new ValueMapDecorator(props);
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
index 289fb67..745ae60 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileCache.java
@@ -57,7 +57,7 @@ public final class ContentFileCache {
content = contentCache.get(path);
}
if (content == null) {
- content = ContentFileParser.parse(file);
+ content = ContentFileParserUtil.parse(file);
if (content == null) {
content = NULL_MAP;
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
similarity index 63%
rename from src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java
rename to src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
index 81a69a3..ec9af59 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParser.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtil.java
@@ -25,17 +25,34 @@ import java.io.File;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.fscontentparser.ContentFileExtension;
+import org.apache.sling.fscontentparser.ContentFileParser;
+import org.apache.sling.fscontentparser.ContentFileParserFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Parses files that contains content fragments (e.g. JSON, JCR XML).
*/
-class ContentFileParser {
+class ContentFileParserUtil {
- private static final Logger log = LoggerFactory.getLogger(ContentFileParser.class);
+ private static final Logger log = LoggerFactory.getLogger(ContentFileParserUtil.class);
- private ContentFileParser() {
+ private static final ContentFileParser JSON_PARSER;
+ static {
+ // workaround for JsonProvider classloader issue until https://issues.apache.org/jira/browse/GERONIMO-6560 is fixed
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(ContentFileParserUtil.class.getClassLoader());
+ JSON_PARSER = ContentFileParserFactory.create(ContentFileExtension.JSON);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+ }
+ private static final ContentFileParser JCR_XML_PARSER = ContentFileParserFactory.create(ContentFileExtension.JCR_XML);
+
+ private ContentFileParserUtil() {
// static methods only
}
@@ -47,10 +64,10 @@ class ContentFileParser {
public static Map<String,Object> parse(File file) {
try {
if (StringUtils.endsWith(file.getName(), JSON_SUFFIX)) {
- return JsonFileParser.parse(file);
+ return JSON_PARSER.parse(file);
}
else if (StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
- return JcrXmlFileParser.parse(file);
+ return JCR_XML_PARSER.parse(file);
}
}
catch (Throwable ex) {
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
index 85e6445..689654d 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentFileTypes.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.fsprovider.internal.parser;
+import org.apache.sling.fscontentparser.ContentFileExtension;
+
/**
* Content file types.
*/
@@ -26,12 +28,12 @@ public final class ContentFileTypes {
/**
* JSON content files.
*/
- public static final String JSON_SUFFIX = ".json";
+ public static final String JSON_SUFFIX = "." + ContentFileExtension.JSON;
/**
* JCR XML content files.
*/
- public static final String JCR_XML_SUFFIX = ".jcr.xml";
+ public static final String JCR_XML_SUFFIX = "." + ContentFileExtension.JCR_XML;
private ContentFileTypes() {
// static methods only
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java
deleted file mode 100644
index 6174bf9..0000000
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParser.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.fsprovider.internal.parser;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Stack;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.apache.jackrabbit.util.ISO9075;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Parses JCR XML files that contains content fragments.
- */
-class JcrXmlFileParser {
-
- private static final Logger log = LoggerFactory.getLogger(JcrXmlFileParser.class);
-
- private static final SAXParserFactory SAX_PARSER_FACTORY;
- static {
- SAX_PARSER_FACTORY = SAXParserFactory.newInstance();
- SAX_PARSER_FACTORY.setNamespaceAware(true);
- }
-
- private JcrXmlFileParser() {
- // static methods only
- }
-
- /**
- * Parse JSON file.
- * @param file File
- * @return Content
- */
- public static Map<String,Object> parse(File file) {
- log.debug("Parse JCR XML content from {}", file.getPath());
- try (FileInputStream fis = new FileInputStream(file)) {
- XmlHandler xmlHandler = new XmlHandler();
- SAXParser parser = SAX_PARSER_FACTORY.newSAXParser();
- parser.parse(fis, xmlHandler);
- if (xmlHandler.hasError()) {
- throw xmlHandler.getError();
- }
- return xmlHandler.getContent();
- }
- catch (IOException | ParserConfigurationException | SAXException ex) {
- log.warn("Error parsing JCR XML content from " + file.getPath(), ex);
- return null;
- }
- }
-
- /**
- * Decodes element or attribute names.
- * @param qname qname
- * @return Decoded name
- */
- static String decodeName(String qname) {
- return ISO9075.decode(qname);
- }
-
- /**
- * Parses XML stream to Map.
- */
- static class XmlHandler extends DefaultHandler {
- private final Map<String,Object> content = new LinkedHashMap<>();
- private final Stack<Map<String,Object>> elements = new Stack<>();
- private SAXParseException error;
-
- public Map<String,Object> getContent() {
- return content;
- }
-
- public boolean hasError() {
- return error != null;
- }
-
- public SAXParseException getError() {
- return error;
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes)
- throws SAXException {
-
- // prepare map for element
- Map<String,Object> element;
- if (elements.isEmpty()) {
- element = content;
- }
- else {
- element = new HashMap<>();
- elements.peek().put(decodeName(qName), element);
- }
- elements.push(element);
-
- // get attributes
- for (int i=0; i<attributes.getLength(); i++) {
- element.put(decodeName(attributes.getQName(i)), JcrXmlValueConverter.parseValue(attributes.getValue(i)));
- }
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
- elements.pop();
- }
-
- @Override
- public void error(SAXParseException ex) throws SAXException {
- this.error = ex;
- }
-
- @Override
- public void fatalError(SAXParseException ex) throws SAXException {
- this.error = ex;
- }
-
- }
-
-}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java
deleted file mode 100644
index 8a0d0db..0000000
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverter.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.fsprovider.internal.parser;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.jackrabbit.util.ISO8601;
-
-/**
- * Parses JCR XML files that contains content fragments.
- */
-class JcrXmlValueConverter {
-
- private static final Pattern TYPE_PREFIX = Pattern.compile("^\\{([^\\{\\}]+)\\}(.+)$");
- private static final Pattern VALUE_ARRAY = Pattern.compile("^\\[(.*)\\]$");
-
- private JcrXmlValueConverter() {
- // static methods only
- }
-
- /**
- * Parse JSON value from XML Attribute.
- * @param value XML attribute value
- * @return Value object
- */
- public static Object parseValue(final String rawValue) {
- String value = rawValue;
- String[] valueArray = null;
-
- if (rawValue == null) {
- return null;
- }
-
- // detect type prefix
- String typePrefix = null;
- Matcher typePrefixMatcher = TYPE_PREFIX.matcher(value);
- if (typePrefixMatcher.matches()) {
- typePrefix = typePrefixMatcher.group(1);
- value = typePrefixMatcher.group(2);
- }
-
- // check for array
- Matcher arrayMatcher = VALUE_ARRAY.matcher(value);
- if (arrayMatcher.matches()) {
- value = null;
- valueArray = splitPreserveAllTokens(arrayMatcher.group(1), ',');
- }
-
- // convert values
- if (valueArray != null) {
- Object[] result = new Object[valueArray.length];
- for (int i=0; i<valueArray.length; i++) {
- result[i] = convertValue(valueArray[i], typePrefix, true);
- }
- return result;
- }
- else {
- return convertValue(value, typePrefix, false);
- }
- }
-
- /**
- * Split string preserving all tokens - but ignore separators that are escaped with \.
- * @param str Combined string
- * @param sep Separator
- * @return Tokens
- */
- private static String[] splitPreserveAllTokens(String str, char sep) {
- final int len = str.length();
- if (len == 0) {
- return ArrayUtils.EMPTY_STRING_ARRAY;
- }
- final List<String> list = new ArrayList<String>();
- int i = 0, start = 0;
- boolean match = false;
- boolean lastMatch = false;
- boolean escaped = false;
- while (i < len) {
- if (str.charAt(i) == '\\' && !escaped) {
- escaped = true;
- }
- else {
- if (str.charAt(i) == sep && !escaped) {
- lastMatch = true;
- list.add(str.substring(start, i));
- match = false;
- start = ++i;
- continue;
- }
- lastMatch = false;
- match = true;
- escaped = false;
- }
- i++;
- }
- if (match || lastMatch) {
- list.add(str.substring(start, i));
- }
- return list.toArray(new String[list.size()]);
- }
-
- /**
- * Parse value depending on type prefix.
- * @param value Value
- * @param typePrefix Type prefix
- * @param inArray Value is in array
- * @return Value object
- */
- private static Object convertValue(final String value, final String typePrefix, final boolean inArray) {
- if (typePrefix == null || StringUtils.equals(typePrefix, "Name")) {
- return deescapeStringValue(value, inArray);
- }
- else if (StringUtils.equals(typePrefix, "Boolean")) {
- return Boolean.valueOf(value);
- }
- else if (StringUtils.equals(typePrefix, "Long")) {
- return Long.valueOf(value);
- }
- else if (StringUtils.equals(typePrefix, "Decimal")) {
- return Double.valueOf(value);
- }
- else if (StringUtils.equals(typePrefix, "Date")) {
- return ISO8601.parse(value);
- }
- else {
- throw new IllegalArgumentException("Unexpected type prefix: " + typePrefix);
- }
- }
-
- /**
- * De-escape string value.
- * @param value Escaped string value
- * @param inArray In array
- * @return De-escaped string value
- */
- private static String deescapeStringValue(final String value, final boolean inArray) {
- String descapedValue = value;
- if (inArray) {
- descapedValue = StringUtils.replace(descapedValue, "\\,", ",");
- }
- else if (StringUtils.startsWith(descapedValue, "\\{") || StringUtils.startsWith(descapedValue, "\\[")) {
- descapedValue = descapedValue.substring(1);
- }
- return StringUtils.replace(descapedValue, "\\\\", "\\");
- }
-
-}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java
deleted file mode 100644
index 8070e0d..0000000
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/JsonFileParser.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.fsprovider.internal.parser;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonNumber;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonReaderFactory;
-import javax.json.JsonString;
-import javax.json.JsonValue;
-import javax.json.stream.JsonParsingException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Parses JSON files that contains content fragments.
- */
-class JsonFileParser {
-
- private static final Logger log = LoggerFactory.getLogger(JsonFileParser.class);
-
- private static final JsonReaderFactory JSON_READER_FACTORY;
- static {
- // allow comments in JSON files
- Map<String,Object> jsonReaderFactoryConfig = new HashMap<>();
- jsonReaderFactoryConfig.put("org.apache.johnzon.supports-comments", true);
- // workaround for JsonProvider classloader issue until https://issues.apache.org/jira/browse/GERONIMO-6560 is fixed
- ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(JsonFileParser.class.getClassLoader());
- JSON_READER_FACTORY = Json.createReaderFactory(jsonReaderFactoryConfig);
- }
- finally {
- Thread.currentThread().setContextClassLoader(oldClassLoader);
- }
- }
-
- private JsonFileParser() {
- // static methods only
- }
-
- /**
- * Parse JSON file.
- * @param file File
- * @return Content
- */
- public static Map<String,Object> parse(File file) {
- log.debug("Parse JSON content from {}", file.getPath());
- try (FileInputStream fis = new FileInputStream(file);
- JsonReader reader = JSON_READER_FACTORY.createReader(fis)) {
- return toMap(reader.readObject());
- }
- catch (IOException | JsonParsingException ex) {
- log.warn("Error parsing JSON content from " + file.getPath(), ex);
- return null;
- }
- }
-
- private static Map<String,Object> toMap(JsonObject object) {
- Map<String,Object> map = new LinkedHashMap<>();
- for (Map.Entry<String, JsonValue> entry : object.entrySet()) {
- map.put(entry.getKey(), convertValue(entry.getValue()));
- }
- return map;
- }
-
- private static Object convertValue(JsonValue value) {
- switch (value.getValueType()) {
- case STRING:
- return ((JsonString)value).getString();
- case NUMBER:
- JsonNumber numberValue = (JsonNumber)value;
- if (numberValue.isIntegral()) {
- return numberValue.longValue();
- }
- else {
- return numberValue.doubleValue();
- }
- case TRUE:
- return true;
- case FALSE:
- return false;
- case NULL:
- return null;
- case ARRAY:
- JsonArray arrayValue = (JsonArray)value;
- Object[] values = new Object[arrayValue.size()];
- for (int i=0; i<values.length; i++) {
- values[i] = convertValue(arrayValue.get(i));
- }
- return values;
- case OBJECT:
- return toMap((JsonObject)value);
- default:
- throw new IllegalArgumentException("Unexpected JSON value type: " + value.getValueType());
- }
- }
-
-}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
index 3325ed4..d928205 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
@@ -92,7 +92,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Root() {
+ public void testContent_Root() {
Resource underTest = fsroot.getChild("folder3/content");
assertNotNull(underTest);
assertEquals("app:Page", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
@@ -101,7 +101,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Level1() {
+ public void testContent_Level1() {
Resource underTest = fsroot.getChild("folder3/content/jcr:content");
assertNotNull(underTest);
assertEquals("app:PageContent", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
@@ -110,7 +110,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Level3() {
+ public void testContent_Level3() {
Resource underTest = fsroot.getChild("folder3/content/jcr:content/content/contentheadline");
assertNotNull(underTest);
assertEquals("nt:unstructured", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
@@ -119,7 +119,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_Datatypes() {
+ public void testContent_Datatypes() {
Resource underTest = fsroot.getChild("folder3/content/jcr:content");
ValueMap props = ResourceUtil.getValueMap(underTest);
@@ -133,7 +133,7 @@ public class JcrXmlContentTest {
}
@Test
- public void testJsonContent_InvalidPath() {
+ public void testContent_InvalidPath() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/xyz");
assertNull(underTest);
}
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 7aa29aa..04a9418 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -43,6 +43,7 @@ import javax.jcr.nodetype.NodeType;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.fscontentparser.ParserOptions;
import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
import org.apache.sling.hamcrest.ResourceMatchers;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
@@ -101,7 +102,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Root() {
+ public void testContent_Root() {
Resource underTest = fsroot.getChild("folder2/content");
assertNotNull(underTest);
assertEquals("app:Page", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
@@ -110,7 +111,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Level1() {
+ public void testContent_Level1() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content");
assertNotNull(underTest);
assertEquals("app:PageContent", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
@@ -120,7 +121,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Level5() {
+ public void testContent_Level5() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/image/file/jcr:content");
assertNotNull(underTest);
assertEquals("nt:resource", ResourceUtil.getValueMap(underTest).get("jcr:primaryType", String.class));
@@ -128,7 +129,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Datatypes() {
+ public void testContent_Datatypes() {
Resource underTest = fsroot.getChild("folder2/content/toolbar/profiles/jcr:content");
ValueMap props = ResourceUtil.getValueMap(underTest);
@@ -142,7 +143,7 @@ public class JsonContentTest {
}
@Test
- public void testJsonContent_Datatypes_JCR() throws RepositoryException {
+ public void testContent_Datatypes_JCR() throws RepositoryException {
Resource underTest = fsroot.getChild("folder2/content/toolbar/profiles/jcr:content");
ValueMap props = ResourceUtil.getValueMap(underTest);
Node node = underTest.adaptTo(Node.class);
@@ -220,11 +221,11 @@ public class JsonContentTest {
@Test
public void testFallbackNodeType() throws RepositoryException {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/title_2");
- assertEquals(NodeType.NT_UNSTRUCTURED, underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
+ assertEquals(ParserOptions.DEFAULT_PRIMARY_TYPE, underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
}
@Test
- public void testJsonContent_InvalidPath() {
+ public void testContent_InvalidPath() {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/xyz");
assertNull(underTest);
}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
similarity index 86%
rename from src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java
rename to src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
index 290ea21..9bdaa51 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
@@ -27,13 +27,13 @@ import java.util.Map;
import org.junit.Test;
-public class ContentFileParserTest {
+public class ContentFileParserUtilTest {
@SuppressWarnings("unchecked")
@Test
public void testParseJson() {
File file = new File("src/test/resources/fs-test/folder2/content.json");
- Map<String,Object> content = ContentFileParser.parse(file);
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
assertNotNull(content);
assertEquals("app:Page", content.get("jcr:primaryType"));
assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
@@ -42,7 +42,7 @@ public class ContentFileParserTest {
@Test
public void testParseInvalidJson() {
File file = new File("src/test/resources/invalid-test/invalid.json");
- Map<String,Object> content = ContentFileParser.parse(file);
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
assertNull(content);
}
@@ -50,7 +50,7 @@ public class ContentFileParserTest {
@Test
public void testParseJcrXml() {
File file = new File("src/test/resources/fs-test/folder3/content.jcr.xml");
- Map<String,Object> content = ContentFileParser.parse(file);
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
assertNotNull(content);
assertEquals("app:Page", content.get("jcr:primaryType"));
assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
@@ -59,7 +59,7 @@ public class ContentFileParserTest {
@Test
public void testParseInvalidJcrXml() {
File file = new File("src/test/resources/invalid-test/invalid.jcr.xml");
- Map<String,Object> content = ContentFileParser.parse(file);
+ Map<String,Object> content = ContentFileParserUtil.parse(file);
assertNull(content);
}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java
deleted file mode 100644
index 7cccbcf..0000000
--- a/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlFileParserTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.fsprovider.internal.parser;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.jackrabbit.util.ISO9075;
-import org.junit.Test;
-
-public class JcrXmlFileParserTest {
-
- @Test
- public void testDecodeName() {
- assertEquals("jcr:title", JcrXmlFileParser.decodeName("jcr:" + ISO9075.encode("title")));
- assertEquals("sling:123", JcrXmlFileParser.decodeName("sling:" + ISO9075.encode("123")));
- }
-
-}
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java
deleted file mode 100644
index 15fe989..0000000
--- a/src/test/java/org/apache/sling/fsprovider/internal/parser/JcrXmlValueConverterTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.fsprovider.internal.parser;
-
-import static org.apache.sling.fsprovider.internal.parser.JcrXmlValueConverter.parseValue;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import java.util.Calendar;
-
-import org.junit.Test;
-
-public class JcrXmlValueConverterTest {
-
- @Test
- public void testNull() {
- assertNull(parseValue(null));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testInvalid() {
- parseValue("{InvalidType}xyz");
- }
-
- @Test
- public void testString() {
- assertEquals("myString", parseValue("myString"));
- assertEquals("prop", "myString [ ] { } \\ ,", parseValue("myString [ ] { } \\\\ ,"));
- assertEquals("{myString}", parseValue("\\{myString}"));
- assertEquals("aaa{myString}", parseValue("aaa{myString}"));
- assertEquals("[myString]", parseValue("\\[myString]"));
- assertEquals("aaa[myString]", parseValue("aaa[myString]"));
- }
-
- @Test
- public void testStringArray() {
- assertArrayEquals(new Object[] { "myString1", "myString2" }, (Object[]) parseValue("[myString1,myString2]"));
- assertArrayEquals(new Object[] { "myString1,[]\\äöü߀", "myString2", "myString3 [ ] { } \\ ,", "", "[myString5]", "{myString6}" },
- (Object[]) parseValue("[myString1\\,[]\\\\äöü߀,myString2,myString3 [ ] { } \\\\ \\,,,[myString5],{myString6}]"));
- }
-
- @Test
- public void testBoolean() {
- assertEquals(true, parseValue("{Boolean}true"));
- assertEquals(false, parseValue("{Boolean}false"));
- }
-
- @Test
- public void testBooleanArray() {
- assertArrayEquals(new Object[] { true, false }, (Object[]) parseValue("{Boolean}[true,false]"));
- }
-
- @Test
- public void testLong() {
- assertEquals(1L, parseValue("{Long}1"));
- assertEquals(10000000000L, parseValue("{Long}10000000000"));
- }
-
- @Test
- public void testLongArray() {
- assertArrayEquals(new Object[] { 1L, 2L }, (Object[]) parseValue("{Long}[1,2]"));
- assertArrayEquals(new Object[] { 10000000000L, 20000000000L }, (Object[]) parseValue("{Long}[10000000000,20000000000]"));
- }
-
- @Test
- public void testDouble() {
- assertEquals(1.234d, parseValue("{Decimal}1.234"));
- }
-
- @Test
- public void testDoubleArray() {
- assertArrayEquals(new Object[] { 1.234d, 2.345d }, (Object[]) parseValue("{Decimal}[1.234,2.345]"));
- }
-
- @Test
- public void testCalendar() {
- Calendar value = (Calendar)parseValue("{Date}2010-09-05T15:10:20.000Z");
- assertEquals(2010, value.get(Calendar.YEAR));
- assertEquals(8, value.get(Calendar.MONTH));
- assertEquals(5, value.get(Calendar.DAY_OF_MONTH));
- }
-
- @Test
- public void testStringArrayRepPrivileges() {
- assertArrayEquals(new Object[] { "rep:write", "crx:replicate", "jcr:read" }, (Object[]) parseValue("{Name}[rep:write,crx:replicate,jcr:read]"));
- }
-
-}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-fsresource] 12/23: SLING-6537 FileVault XML
support
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.fsresource-1.3.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 56b09e5df9ca8e1372c91ac40f1622e855d8153d
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Mar 9 17:25:34 2017 +0000
SLING-6537 FileVault XML support
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/fsresource-1.x@1786205 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/fsprovider/internal/FileMonitor.java | 3 +--
.../fsprovider/internal/FsResourceProvider.java | 10 +++++++++-
.../internal/mapper/FileVaultResourceMapper.java | 22 ++++++++++------------
.../fsprovider/internal/FileVaultContentTest.java | 6 ++++--
.../internal/FileVaultFileMonitorTest.java | 6 ++++--
5 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
index d77a2f6..f4db089 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -18,7 +18,6 @@
*/
package org.apache.sling.fsprovider.internal;
-import static org.apache.jackrabbit.vault.util.Constants.ROOT_DIR;
import static org.apache.sling.api.SlingConstants.PROPERTY_PATH;
import static org.apache.sling.api.SlingConstants.PROPERTY_RESOURCE_TYPE;
import static org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED;
@@ -77,7 +76,7 @@ public final class FileMonitor extends TimerTask {
File rootFile = this.provider.getRootFile();
if (fsMode == FsMode.FILEVAULT_XML) {
- rootFile = new File(this.provider.getRootFile(), ROOT_DIR + PlatformNameFormat.getPlatformPath(this.provider.getProviderRoot()));
+ rootFile = new File(this.provider.getRootFile(), "." + PlatformNameFormat.getPlatformPath(this.provider.getProviderRoot()));
}
this.root = new Monitorable(this.provider.getProviderRoot(), rootFile, null);
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
index 4ec8a07..5e42a90 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -129,6 +129,10 @@ public final class FsResourceProvider implements ResourceProvider {
description = "Import options for Sling-Initial-Content filesystem layout. Supported options: overwrite, ignoreImportProviders.")
String provider_initial_content_import_options();
+ @AttributeDefinition(name = "FileVault Filter",
+ description = "Path to META-INF/vault/filter.xml when using FileVault XML filesystem layout.")
+ String provider_filevault_filterxml_path();
+
@AttributeDefinition(name = "Cache Size",
description = "Max. number of content files cached in memory.")
int provider_cache_size() default 10000;
@@ -264,10 +268,14 @@ public final class FsResourceProvider implements ResourceProvider {
this.providerFile = getProviderFile(providerFileName, bundleContext);
InitialContentImportOptions options = new InitialContentImportOptions(config.provider_initial_content_import_options());
+ File filterXmlFile = null;
List<String> contentFileSuffixes = new ArrayList<>();
if (fsMode == FsMode.FILEVAULT_XML) {
contentFileSuffixes.add("/" + DOT_CONTENT_XML);
+ if (StringUtils.isNotBlank(config.provider_filevault_filterxml_path())) {
+ filterXmlFile = new File(config.provider_filevault_filterxml_path());
+ }
}
else if (fsMode == FsMode.INITIAL_CONTENT) {
if (!options.getIgnoreImportProviders().contains("json")) {
@@ -281,7 +289,7 @@ public final class FsResourceProvider implements ResourceProvider {
this.contentFileCache = new ContentFileCache(config.provider_cache_size());
if (fsMode == FsMode.FILEVAULT_XML) {
- this.fileVaultMapper = new FileVaultResourceMapper(this.providerFile, this.contentFileCache);
+ this.fileVaultMapper = new FileVaultResourceMapper(this.providerFile, filterXmlFile, this.contentFileCache);
}
else {
this.fileMapper = new FileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions);
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
index 88e001e..cb25230 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileVaultResourceMapper.java
@@ -19,9 +19,6 @@
package org.apache.sling.fsprovider.internal.mapper;
import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
-import static org.apache.jackrabbit.vault.util.Constants.FILTER_XML;
-import static org.apache.jackrabbit.vault.util.Constants.META_DIR;
-import static org.apache.jackrabbit.vault.util.Constants.ROOT_DIR;
import java.io.File;
import java.io.IOException;
@@ -51,13 +48,15 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
private static final String DOT_DIR_SUFFIX = "/.dir";
private final File providerFile;
+ private final File filterXmlFile;
private final ContentFileCache contentFileCache;
private final WorkspaceFilter workspaceFilter;
private static final Logger log = LoggerFactory.getLogger(FileVaultResourceMapper.class);
- public FileVaultResourceMapper(File providerFile, ContentFileCache contentFileCache) {
+ public FileVaultResourceMapper(File providerFile, File filterXmlFile, ContentFileCache contentFileCache) {
this.providerFile = providerFile;
+ this.filterXmlFile = filterXmlFile;
this.contentFileCache = contentFileCache;
this.workspaceFilter = getWorkspaceFilter();
}
@@ -134,18 +133,17 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
* @return Workspace filter or null if none found.
*/
private WorkspaceFilter getWorkspaceFilter() {
- File filter = new File(providerFile, META_DIR + "/" + FILTER_XML);
- if (filter.exists()) {
+ if (filterXmlFile != null && filterXmlFile.exists()) {
try {
DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
- workspaceFilter.load(filter);
+ workspaceFilter.load(filterXmlFile);
return workspaceFilter;
} catch (IOException | ConfigurationException ex) {
- log.error("Unable to parse workspace filter: " + filter.getPath(), ex);
+ log.error("Unable to parse workspace filter: " + filterXmlFile.getPath(), ex);
}
}
else {
- log.warn("Workspace filter not found: " + filter.getPath());
+ log.debug("Workspace filter not found: " + filterXmlFile.getPath());
}
return null;
}
@@ -161,7 +159,7 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
return false;
}
if (workspaceFilter == null) {
- return false;
+ return true;
}
else {
return workspaceFilter.contains(path);
@@ -172,7 +170,7 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
if (StringUtils.endsWith(path, DOT_CONTENT_XML_SUFFIX)) {
return null;
}
- File file = new File(providerFile, ROOT_DIR + PlatformNameFormat.getPlatformPath(path));
+ File file = new File(providerFile, "." + PlatformNameFormat.getPlatformPath(path));
if (file.exists()) {
return file;
}
@@ -180,7 +178,7 @@ public final class FileVaultResourceMapper implements FsResourceMapper {
}
private ContentFile getContentFile(String path, String subPath) {
- File file = new File(providerFile, ROOT_DIR + PlatformNameFormat.getPlatformPath(path) + DOT_CONTENT_XML_SUFFIX);
+ File file = new File(providerFile, "." + PlatformNameFormat.getPlatformPath(path) + DOT_CONTENT_XML_SUFFIX);
if (file.exists()) {
ContentFile contentFile = new ContentFile(file, path, subPath, contentFileCache);
if (contentFile.hasContent()) {
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
index b6dda6a..13a0bcf 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
@@ -57,12 +57,14 @@ public class FileVaultContentTest {
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
.plugin(new RegisterFsResourcePlugin(
"provider.fs.mode", FsMode.FILEVAULT_XML.name(),
- "provider.file", "src/test/resources/vaultfs-test",
+ "provider.file", "src/test/resources/vaultfs-test/jcr_root",
+ "provider.filevault.filterxml.path", "src/test/resources/vaultfs-test/META-INF/vault/filter.xml",
"provider.roots", "/content/dam/talk.png"
))
.plugin(new RegisterFsResourcePlugin(
"provider.fs.mode", FsMode.FILEVAULT_XML.name(),
- "provider.file", "src/test/resources/vaultfs-test",
+ "provider.file", "src/test/resources/vaultfs-test/jcr_root",
+ "provider.filevault.filterxml.path", "src/test/resources/vaultfs-test/META-INF/vault/filter.xml",
"provider.roots", "/content/samples"
))
.build();
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
index 7219033..ff7beea 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
@@ -68,12 +68,14 @@ public class FileVaultFileMonitorTest {
// mount temp. directory
context.registerInjectActivateService(new FsResourceProvider(),
- "provider.file", tempDir.getPath(),
+ "provider.file", tempDir.getPath() + "/jcr_root",
+ "provider.filevault.filterxml.path", tempDir.getPath() + "/META-INF/vault/filter.xml",
"provider.roots", "/content/dam/talk.png",
"provider.checkinterval", CHECK_INTERVAL,
"provider.fs.mode", FsMode.FILEVAULT_XML.name());
context.registerInjectActivateService(new FsResourceProvider(),
- "provider.file", tempDir.getPath(),
+ "provider.file", tempDir.getPath() + "/jcr_root",
+ "provider.filevault.filterxml.path", tempDir.getPath() + "/META-INF/vault/filter.xml",
"provider.roots", "/content/samples",
"provider.checkinterval", CHECK_INTERVAL,
"provider.fs.mode", FsMode.FILEVAULT_XML.name());
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.