You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2025/02/26 09:52:07 UTC
(sling-org-apache-sling-fsresource) branch feature/parent-62 created (now 553956e)
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a change to branch feature/parent-62
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
at 553956e SLING-12677 apply spotless formatting
This branch includes the following new commits:
new e4b3bb2 SLING-12677 Update to parent 62
new 553956e SLING-12677 apply spotless formatting
The 2 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.
(sling-org-apache-sling-fsresource) 02/02: SLING-12677 apply spotless formatting
Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/parent-62
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit 553956e39024e8e6660414178dadc4742540f6f5
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Feb 26 10:51:34 2025 +0100
SLING-12677 apply spotless formatting
---
pom.xml | 182 +++++++++---------
.../fsprovider/internal/ContentFileExtensions.java | 6 +-
.../sling/fsprovider/internal/FileMonitor.java | 119 +++++++-----
.../sling/fsprovider/internal/FileStatCache.java | 2 -
.../apache/sling/fsprovider/internal/FsMode.java | 1 -
.../fsprovider/internal/FsResourceProvider.java | 140 ++++++++------
.../internal/InitialContentImportOptions.java | 8 +-
.../fsprovider/internal/mapper/ContentFile.java | 15 +-
.../internal/mapper/ContentFileResource.java | 17 +-
.../internal/mapper/ContentFileResourceMapper.java | 65 ++++---
.../sling/fsprovider/internal/mapper/Escape.java | 28 +--
.../fsprovider/internal/mapper/FileResource.java | 64 ++++---
.../internal/mapper/FileResourceMapper.java | 133 +++++++------
.../internal/mapper/FileVaultResourceMapper.java | 49 +++--
.../fsprovider/internal/mapper/jcr/FsItem.java | 23 +--
.../fsprovider/internal/mapper/jcr/FsNode.java | 188 ++++++++++--------
.../internal/mapper/jcr/FsNodeIterator.java | 12 +-
.../fsprovider/internal/mapper/jcr/FsNodeType.java | 2 -
.../fsprovider/internal/mapper/jcr/FsProperty.java | 74 +++----
.../internal/mapper/jcr/FsPropertyDefinition.java | 8 +-
.../internal/mapper/jcr/FsPropertyIterator.java | 9 +-
.../fsprovider/internal/mapper/jcr/FsValue.java | 30 ++-
.../internal/mapper/valuemap/DateUtils.java | 1 -
.../internal/mapper/valuemap/ObjectConverter.java | 72 +++----
.../mapper/valuemap/ValueMapDecorator.java | 9 +-
.../internal/mapper/valuemap/ValueMapUtil.java | 10 +-
.../fsprovider/internal/parser/ContentElement.java | 1 -
.../internal/parser/ContentElementHandler.java | 7 +-
.../internal/parser/ContentElementImpl.java | 10 +-
.../internal/parser/ContentFileCache.java | 5 +-
.../internal/parser/ContentFileParserUtil.java | 43 ++---
.../internal/parser/ContentFileTypes.java | 1 -
.../fsprovider/internal/parser/ContentType.java | 2 -
.../sling/fsprovider/internal/FileMonitorTest.java | 83 ++++----
.../fsprovider/internal/FileVaultContentTest.java | 65 ++++---
.../internal/FileVaultFileMonitorTest.java | 114 ++++++-----
.../sling/fsprovider/internal/FilesFolderTest.java | 21 +-
.../internal/InitialContentImportOptionsTest.java | 16 +-
.../fsprovider/internal/InvalidRootFolderTest.java | 25 ++-
.../sling/fsprovider/internal/JcrMixedTest.java | 25 ++-
.../fsprovider/internal/JcrXmlContentTest.java | 42 ++--
.../sling/fsprovider/internal/JsonContentTest.java | 108 ++++++-----
.../internal/ResourcePathComparator.java | 1 -
.../sling/fsprovider/internal/TestUtils.java | 31 +--
.../internal/mapper/ContentFileTest.java | 21 +-
.../fsprovider/internal/mapper/EscapeTest.java | 5 +-
.../internal/mapper/valuemap/Convert.java | 86 +++++----
.../mapper/valuemap/ObjectConverterTest.java | 213 ++++++++++++++-------
.../mapper/valuemap/ValueMapDecoratorTest.java | 87 +++++----
.../internal/mapper/valuemap/ValueMapUtilTest.java | 20 +-
.../internal/parser/ContentFileCacheTest.java | 63 +++---
.../internal/parser/ContentFileParserUtilTest.java | 17 +-
52 files changed, 1312 insertions(+), 1067 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3452c58..fa18520 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?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
@@ -30,108 +30,19 @@
<version>2.2.1-SNAPSHOT</version>
<name>Apache Sling File System Resource Provider</name>
- <description>
- Provides a ResourceProvider implementation supporting file system based resources.
- </description>
+ <description>Provides a ResourceProvider implementation supporting file system based resources.</description>
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git</developerConnection>
- <url>https://github.com/apache/sling-org-apache-sling-fsresource.git</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/sling-org-apache-sling-fsresource.git</url>
</scm>
<properties>
<sling.java.version>8</sling.java.version>
<project.build.outputTimestamp>2021-08-30T16:40:10Z</project.build.outputTimestamp>
</properties>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-adapter-metadata</id>
- <goals>
- <goal>generate-adapter-metadata</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>bnd-simple.bnd</exclude>
- <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>
-
- <!-- Simple JAR -->
- <plugin>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-classes-to-simple</id>
- <phase>process-classes</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/classes-simple</outputDirectory>
- <resources>
- <resource>
- <directory>${project.build.outputDirectory}</directory>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>bnd-process-simple</id>
- <goals>
- <goal>bnd-process</goal>
- </goals>
- <configuration>
- <bndfile>bnd-simple.bnd</bndfile>
- <classesDir>${project.build.directory}/classes-simple</classesDir>
- <outputDir>${project.build.directory}/classes-simple</outputDir>
- <manifestPath>${project.build.directory}/classes-simple/manifest/MANIFEST.MF</manifestPath>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <id>simple-jar</id>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
- <classifier>simple</classifier>
- <classesDirectory>${project.build.directory}/classes-simple</classesDirectory>
- <archive>
- <manifestFile>${project.build.directory}/classes-simple/manifest/MANIFEST.MF</manifestFile>
- </archive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
@@ -268,4 +179,91 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-adapter-metadata</id>
+ <goals>
+ <goal>generate-adapter-metadata</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>bnd-simple.bnd</exclude>
+ <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>
+
+ <!-- Simple JAR -->
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-classes-to-simple</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>process-classes</phase>
+ <configuration>
+ <outputDirectory>${project.build.directory}/classes-simple</outputDirectory>
+ <resources>
+ <resource>
+ <directory>${project.build.outputDirectory}</directory>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>bnd-process-simple</id>
+ <goals>
+ <goal>bnd-process</goal>
+ </goals>
+ <configuration>
+ <bndfile>bnd-simple.bnd</bndfile>
+ <classesDir>${project.build.directory}/classes-simple</classesDir>
+ <outputDir>${project.build.directory}/classes-simple</outputDir>
+ <manifestPath>${project.build.directory}/classes-simple/manifest/MANIFEST.MF</manifestPath>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>simple-jar</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>simple</classifier>
+ <classesDirectory>${project.build.directory}/classes-simple</classesDirectory>
+ <archive>
+ <manifestFile>${project.build.directory}/classes-simple/manifest/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</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
index 49946b8..dd55339 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/ContentFileExtensions.java
@@ -18,13 +18,13 @@
*/
package org.apache.sling.fsprovider.internal;
-import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JCR_XML_SUFFIX;
-import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.XML_SUFFIX;
-
import java.io.File;
import java.util.Collection;
import java.util.List;
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.JCR_XML_SUFFIX;
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.XML_SUFFIX;
+
/**
* Matches file names for content file extensions.
*/
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 5963be6..31c6d64 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileMonitor.java
@@ -63,12 +63,13 @@ public final class FileMonitor extends TimerTask {
* @param contentFileCache Content file cache
* @param fileStatCache Cache reducing file-stat lookups (file exists or not, directory vs file).
*/
- public FileMonitor(final FsResourceProvider provider,
- final File rootFile,
- final long interval,
- final ContentFileExtensions contentFileExtensions,
- final ContentFileCache contentFileCache,
- final FileStatCache fileStatCache) {
+ public FileMonitor(
+ final FsResourceProvider provider,
+ final File rootFile,
+ final long interval,
+ final ContentFileExtensions contentFileExtensions,
+ final ContentFileCache contentFileCache,
+ final FileStatCache fileStatCache) {
this.provider = provider;
this.contentFileExtensions = contentFileExtensions;
this.contentFileCache = contentFileCache;
@@ -98,8 +99,7 @@ public final class FileMonitor extends TimerTask {
while (!stopped) {
try {
timer.wait();
- }
- catch (InterruptedException e) {
+ } catch (InterruptedException e) {
interrupted = true;
}
}
@@ -123,11 +123,11 @@ public final class FileMonitor extends TimerTask {
return;
}
}
- synchronized ( this ) {
+ synchronized (this) {
try {
// if we don't have an observation reporter, we just skip the check
final ObservationReporter reporter = this.provider.getObservationReporter();
- if ( reporter != null ) {
+ if (reporter != null) {
this.check(this.root, reporter);
}
} catch (Exception e) {
@@ -148,23 +148,24 @@ public final class FileMonitor extends TimerTask {
private void check(final Monitorable monitorable, final ObservationReporter 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() ) {
+ if (monitorable.status instanceof NonExistingStatus) {
+ if (monitorable.file.exists()) {
// new file and reset status
createStatus(monitorable, contentFileExtensions, contentFileCache);
fileStatCache.clear();
sendEvents(monitorable, ChangeType.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
+ 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() ) {
+ if (!monitorable.file.exists()) {
// removed file and update status
if (contentFileCache != null) {
contentFileCache.remove(this.provider.transformPath(monitorable.path));
@@ -174,9 +175,9 @@ public final class FileMonitor extends TimerTask {
sendEvents(monitorable, ChangeType.REMOVED, reporter);
} else {
// check for changes
- final FileStatus fs = (FileStatus)monitorable.status;
+ final FileStatus fs = (FileStatus) monitorable.status;
boolean changed = false;
- if ( fs.lastModified < monitorable.file.lastModified() ) {
+ if (fs.lastModified < monitorable.file.lastModified()) {
fs.lastModified = monitorable.file.lastModified();
// changed
if (contentFileCache != null) {
@@ -185,14 +186,14 @@ public final class FileMonitor extends TimerTask {
sendEvents(monitorable, ChangeType.CHANGED, reporter);
changed = true;
}
- if ( fs instanceof DirStatus ) {
+ if (fs instanceof DirStatus) {
// directory
- final DirStatus ds = (DirStatus)fs;
- for(int i=0; i<ds.children.length; i++) {
+ final DirStatus ds = (DirStatus) fs;
+ for (int i = 0; i < ds.children.length; i++) {
check(ds.children[i], reporter);
}
// if the dir changed we have to update
- if ( changed ) {
+ if (changed) {
// and now update
checkDirStatusChildren(monitorable, reporter);
}
@@ -202,7 +203,7 @@ public final class FileMonitor extends TimerTask {
}
private void checkDirStatusChildren(final Monitorable dirMonitorable, final ObservationReporter reporter) {
- final DirStatus ds = (DirStatus)dirMonitorable.status;
+ final DirStatus ds = (DirStatus) dirMonitorable.status;
final File[] files = dirMonitorable.file.listFiles();
if (files != null) {
final Monitorable[] children = new Monitorable[files.length];
@@ -215,7 +216,9 @@ public final class FileMonitor extends TimerTask {
}
}
if (children[i] == null) {
- children[i] = new Monitorable(dirMonitorable.path + '/' + files[i].getName(), files[i],
+ children[i] = new Monitorable(
+ dirMonitorable.path + '/' + files[i].getName(),
+ files[i],
contentFileExtensions.getSuffix(files[i]));
children[i].status = NonExistingStatus.SINGLETON;
check(children[i], reporter);
@@ -230,7 +233,8 @@ public final class FileMonitor extends TimerTask {
/**
* Send the event async via the event admin.
*/
- private void sendEvents(final Monitorable monitorable, final ChangeType changeType, final ObservationReporter reporter) {
+ private void sendEvents(
+ final Monitorable monitorable, final ChangeType changeType, final ObservationReporter reporter) {
final String path = this.provider.transformPath(monitorable.path);
log.debug("Detected change for resource {} : {}", path, changeType);
@@ -255,29 +259,34 @@ public final class FileMonitor extends TimerTask {
private List<ResourceChange> collectResourceChanges(final Monitorable monitorable, final ChangeType changeType) {
List<ResourceChange> changes = new ArrayList<>();
if (monitorable.status instanceof ContentFileStatus) {
- ContentFile contentFile = ((ContentFileStatus)monitorable.status).contentFile;
+ ContentFile contentFile = ((ContentFileStatus) monitorable.status).contentFile;
if (changeType == ChangeType.CHANGED) {
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(ChangeType.REMOVED, this.provider.transformPath(monitorable.path)));
- addContentResourceChanges(changes, ChangeType.ADDED, content, this.provider.transformPath(monitorable.path));
- }
- else {
- addContentResourceChanges(changes, changeType, contentFile.getContent(), this.provider.transformPath(monitorable.path));
+ // so we simulate a removal of the toplevel node and then add all nodes contained in the current content
+ // file again.
+ changes.add(
+ buildContentResourceChange(ChangeType.REMOVED, this.provider.transformPath(monitorable.path)));
+ addContentResourceChanges(
+ changes, ChangeType.ADDED, content, this.provider.transformPath(monitorable.path));
+ } else {
+ addContentResourceChanges(
+ changes, changeType, contentFile.getContent(), this.provider.transformPath(monitorable.path));
}
- }
- else {
+ } else {
changes.add(buildContentResourceChange(changeType, this.provider.transformPath(monitorable.path)));
}
return changes;
}
- private void addContentResourceChanges(final List<ResourceChange> changes, final ChangeType changeType,
- final ContentElement content, final String path) {
- changes.add(buildContentResourceChange(changeType, path));
+ private void addContentResourceChanges(
+ final List<ResourceChange> changes,
+ final ChangeType changeType,
+ final ContentElement content,
+ final String path) {
+ changes.add(buildContentResourceChange(changeType, path));
if (content != null) {
- for (Map.Entry<String,ContentElement> entry : content.getChildren().entrySet()) {
+ for (Map.Entry<String, ContentElement> entry : content.getChildren().entrySet()) {
String childPath = path + "/" + entry.getKey();
addContentResourceChanges(changes, changeType, entry.getValue(), childPath);
}
@@ -291,18 +300,22 @@ public final class FileMonitor extends TimerTask {
/**
* Create a status object for the monitorable
*/
- private static void createStatus(final Monitorable monitorable, ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache) {
- if ( !monitorable.file.exists() ) {
+ private static void createStatus(
+ final Monitorable monitorable,
+ ContentFileExtensions contentFileExtensions,
+ ContentFileCache contentFileCache) {
+ if (!monitorable.file.exists()) {
monitorable.status = NonExistingStatus.SINGLETON;
- } else if ( monitorable.file.isFile() ) {
+ } else if (monitorable.file.isFile()) {
if (contentFileExtensions != null && contentFileExtensions.matchesSuffix(monitorable.file)) {
- monitorable.status = new ContentFileStatus(monitorable.file,
- new ContentFile(monitorable.file, monitorable.path, null, contentFileCache));
+ 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, contentFileExtensions, contentFileCache);
+ monitorable.status =
+ new DirStatus(monitorable.file, monitorable.path, contentFileExtensions, contentFileCache);
}
}
@@ -311,6 +324,7 @@ public final class FileMonitor extends TimerTask {
public final String path;
public final File file;
public Object status;
+
public Monitorable(final String path, final File file, final String contentFileSuffix) {
this.file = file;
if (contentFileSuffix != null) {
@@ -324,6 +338,7 @@ public final class FileMonitor extends TimerTask {
/** Status for files. */
private static class FileStatus {
public long lastModified;
+
public FileStatus(final File file) {
this.lastModified = file.lastModified();
}
@@ -332,6 +347,7 @@ public final class FileMonitor extends TimerTask {
/** 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;
@@ -342,14 +358,19 @@ public final class FileMonitor extends TimerTask {
private static final class DirStatus extends FileStatus {
public Monitorable[] children;
- public DirStatus(final File dir, final String path,
- final ContentFileExtensions contentFileExtensions, final ContentFileCache contentFileCache) {
+ 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],
+ this.children[i] = new Monitorable(
+ path + '/' + files[i].getName(),
+ files[i],
contentFileExtensions == null ? null : contentFileExtensions.getSuffix(files[i]));
FileMonitor.createStatus(this.children[i], contentFileExtensions, contentFileCache);
}
@@ -363,4 +384,4 @@ public final class FileMonitor extends TimerTask {
private static final class NonExistingStatus {
public static NonExistingStatus SINGLETON = new NonExistingStatus();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/FileStatCache.java b/src/main/java/org/apache/sling/fsprovider/internal/FileStatCache.java
index 58a8911..8894a01 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FileStatCache.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FileStatCache.java
@@ -73,7 +73,6 @@ public class FileStatCache {
return exists && !isDirectory;
}
-
@Override
public String toString() {
return exists() ? (isDirectory() ? "existing directory" : "existing file") : "non existing file";
@@ -169,7 +168,6 @@ public class FileStatCache {
}
}
-
private enum CacheStatistics {
EXISTS_ACCESS("Does exist (cached: {}/{}): {}", "Does exist (added to cache: {}/{}): {}"),
NOT_EXISTS_ACCESS("Does not exist (cached: {}/{}): {}", "Does not exist (added to cache: {}/{}): {}");
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 a974b36..9eb1e5c 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsMode.java
@@ -37,5 +37,4 @@ public enum FsMode {
* 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 cb88787..eb6da10 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/FsResourceProvider.java
@@ -18,12 +18,11 @@
*/
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.Iterator;
import java.util.List;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.fsprovider.internal.mapper.FileResourceMapper;
@@ -49,6 +48,8 @@ import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.osgi.service.metatype.annotations.Option;
+import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
+
/**
* The <code>FsResourceProvider</code> is a resource provider which maps
* file system files and folders into the virtual resource tree. The provider is
@@ -60,14 +61,15 @@ import org.osgi.service.metatype.annotations.Option;
* and the file system path from where files and folders are mapped into the
* resource (provider.file).
*/
-@Component(name="org.apache.sling.fsprovider.internal.FsResourceProvider",
- service=ResourceProvider.class,
- configurationPolicy=ConfigurationPolicy.REQUIRE,
- property={
- Constants.SERVICE_DESCRIPTION + "=Sling File System Resource Provider",
- Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
- })
-@Designate(ocd=FsResourceProvider.Config.class, factory=true)
+@Component(
+ name = "org.apache.sling.fsprovider.internal.FsResourceProvider",
+ service = ResourceProvider.class,
+ configurationPolicy = ConfigurationPolicy.REQUIRE,
+ property = {
+ 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 extends ResourceProvider<Object> {
/**
@@ -76,57 +78,70 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
*/
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 file system " +
- "resource provider in terms of provider root and file system location")
+ @ObjectClassDefinition(
+ name = "Apache Sling File System Resource Provider",
+ description = "Configure an instance of the file system "
+ + "resource provider in terms of provider root and file system location")
public @interface Config {
- @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 " +
- "file or folder, an empty folder is created.")
+ @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 "
+ + "file or folder, an empty folder is created.")
String provider_file();
- @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.")
+ @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.")
String provider_root();
- @AttributeDefinition(name = "File system layout",
+ @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 file system layout, supports file and folders ant content files in JSON, xml and jcr.xml format"),
- @Option(value="FILEVAULT_XML", label="FILEVAULT_XML - "
- + "FileVault XML format (expanded content package)"),
+ 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 file system layout, supports file and folders ant content files in JSON, xml 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 file system layout. Supported options: overwrite, ignoreImportProviders.")
+ @AttributeDefinition(
+ name = "Init. Content Options",
+ description =
+ "Import options for Sling-Initial-Content file system layout. Supported options: overwrite, ignoreImportProviders.")
String provider_initial_content_import_options();
- @AttributeDefinition(name = "FileVault Filter",
+ @AttributeDefinition(
+ name = "FileVault Filter",
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.")
+ @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.")
+ @AttributeDefinition(name = "Cache Size", description = "Max. number of content files cached in memory.")
int provider_cache_size() default 10000;
// Internal Name hint for web console.
- String webconsole_configurationFactory_nameHint() default "{provider.fs.mode}: {" + ResourceProvider.PROPERTY_ROOT + "}";
+ String webconsole_configurationFactory_nameHint() default
+ "{provider.fs.mode}: {" + ResourceProvider.PROPERTY_ROOT + "}";
}
// The location in the resource tree where the resources are mapped
@@ -153,8 +168,9 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
* to access the file or folder. If no such file or folder exists, this
* method returns <code>null</code>.
*/
- @Override
- public Resource getResource(final @NotNull ResolveContext<Object> ctx,
+ @Override
+ public Resource getResource(
+ final @NotNull ResolveContext<Object> ctx,
final @NotNull String path,
final @NotNull ResourceContext resourceContext,
final @Nullable Resource parent) {
@@ -194,7 +210,8 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
} else if (fsMode == FsMode.FILES_FOLDERS) {
overlayParentResourceProvider = true;
} else if (fsMode == FsMode.INITIAL_CONTENT) {
- InitialContentImportOptions options = new InitialContentImportOptions(config.provider_initial_content_import_options());
+ InitialContentImportOptions options =
+ new InitialContentImportOptions(config.provider_initial_content_import_options());
overlayParentResourceProvider = !options.isOverwrite();
if (!options.getIgnoreImportProviders().contains(ContentType.JSON.getExtension())) {
contentFileSuffixes.add(ContentFileTypes.JSON_SUFFIX);
@@ -206,9 +223,11 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
contentFileSuffixes.add(ContentFileTypes.XML_SUFFIX);
}
}
- final ContentFileExtensions contentFileExtensions = contentFileSuffixes.isEmpty() ? null : new ContentFileExtensions(contentFileSuffixes);
+ final ContentFileExtensions contentFileExtensions =
+ contentFileSuffixes.isEmpty() ? null : new ContentFileExtensions(contentFileSuffixes);
- this.contentFileCache = fsMode != FsMode.FILES_FOLDERS ? new ContentFileCache(config.provider_cache_size()) : null;
+ this.contentFileCache =
+ fsMode != FsMode.FILES_FOLDERS ? new ContentFileCache(config.provider_cache_size()) : null;
// cache for files that were requested but don't exist
final FileStatCache fileStatCache = new FileStatCache(this.providerFile);
@@ -217,9 +236,23 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
if (StringUtils.isNotBlank(config.provider_filevault_filterxml_path())) {
filterXmlFile = new File(config.provider_filevault_filterxml_path());
}
- this.fileMapper = new FileVaultResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions, this.contentFileCache, fileStatCache, overlayParentResourceProvider, filterXmlFile);
+ this.fileMapper = new FileVaultResourceMapper(
+ this.providerRoot,
+ this.providerFile,
+ contentFileExtensions,
+ this.contentFileCache,
+ fileStatCache,
+ overlayParentResourceProvider,
+ filterXmlFile);
} else {
- this.fileMapper = new FileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions, this.contentFileCache, fileStatCache, overlayParentResourceProvider, true);
+ this.fileMapper = new FileResourceMapper(
+ this.providerRoot,
+ this.providerFile,
+ contentFileExtensions,
+ this.contentFileCache,
+ fileStatCache,
+ overlayParentResourceProvider,
+ true);
}
// start background monitor if check interval is higher than 100
@@ -228,7 +261,8 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
if (fsMode == FsMode.FILEVAULT_XML) {
rootFile = new File(this.providerFile, ".".concat(fileMapper.transformPath(this.getProviderRoot())));
}
- this.monitor = new FileMonitor(this,
+ this.monitor = new FileMonitor(
+ this,
rootFile,
config.provider_checkinterval(),
contentFileExtensions,
@@ -239,7 +273,7 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
@Deactivate
protected void deactivate() {
- if ( this.monitor != null ) {
+ if (this.monitor != null) {
this.monitor.stop();
this.monitor = null;
}
@@ -262,8 +296,7 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
// ---------- internal
- private File getProviderFile(String providerFileName,
- BundleContext bundleContext) {
+ private File getProviderFile(String providerFileName, BundleContext bundleContext) {
// the file object from the plain name
File providerFile = new File(providerFileName);
@@ -282,8 +315,7 @@ public final class FsResourceProvider extends ResourceProvider<Object> {
// if the provider file does not exist, create an empty new folder
if (!providerFile.exists() && !providerFile.mkdirs()) {
- throw new IllegalArgumentException(
- "Cannot create provider file root " + providerFile);
+ throw new IllegalArgumentException("Cannot create provider file root " + providerFile);
}
return providerFile;
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 1ab3b1d..71c055a 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/InitialContentImportOptions.java
@@ -42,7 +42,6 @@ class InitialContentImportOptions {
*/
private static final String IGNORE_CONTENT_READERS_DIRECTIVE = "ignoreImportProviders";
-
private final boolean overwrite;
private final Set<String> ignoreImportProviders;
@@ -51,10 +50,10 @@ class InitialContentImportOptions {
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));
+ String ignoreImportProvidersString =
+ StringUtils.defaultString(entries[0].getDirectiveValue(IGNORE_CONTENT_READERS_DIRECTIVE));
ignoreImportProviders = new HashSet<>(Arrays.asList(StringUtils.split(ignoreImportProvidersString, ",")));
- }
- else {
+ } else {
overwrite = false;
ignoreImportProviders = Collections.emptySet();
}
@@ -67,5 +66,4 @@ class InitialContentImportOptions {
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 1867c90..c438cca 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
@@ -59,7 +59,8 @@ public final class ContentFile {
* @param contentFileCache Content file cache
* @param contentType Content type
*/
- public ContentFile(File file, String path, String subPath, ContentFileCache contentFileCache, ContentType contentType) {
+ public ContentFile(
+ File file, String path, String subPath, ContentFileCache contentFileCache, ContentType contentType) {
this.file = file;
this.path = path;
this.subPath = subPath;
@@ -97,8 +98,7 @@ public final class ContentFile {
ContentElement rootContent = contentFileCache.get(path, file, contentType);
if (subPath == null) {
content = rootContent;
- }
- else if (rootContent != null) {
+ } else if (rootContent != null) {
content = rootContent.getChild(subPath);
}
contentInitialized = true;
@@ -121,8 +121,7 @@ public final class ContentFile {
ContentElement currentContent = getContent();
if (currentContent != null) {
valueMap = ValueMapUtil.toValueMap(currentContent.getProperties());
- }
- else {
+ } else {
valueMap = ValueMap.EMPTY;
}
}
@@ -132,7 +131,7 @@ public final class ContentFile {
/**
* @return Child maps.
*/
- public Iterator<Map.Entry<String,ContentElement>> getChildren() {
+ public Iterator<Map.Entry<String, ContentElement>> getChildren() {
return getContent().getChildren().entrySet().iterator();
}
@@ -154,11 +153,9 @@ public final class ContentFile {
String absoluteSubPath;
if (newSubPath == null) {
absoluteSubPath = this.subPath;
- }
- else {
+ } else {
absoluteSubPath = (this.subPath != null ? this.subPath + "/" : "") + newSubPath;
}
return new ContentFile(file, path, absoluteSubPath, contentFileCache);
}
-
}
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 e2a37c7..8ca9636 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
@@ -59,8 +59,8 @@ public final class ContentFileResource extends AbstractResource {
ContentFileResource(ResourceResolver resolver, ContentFile contentFile) {
this.resolver = resolver;
this.contentFile = contentFile;
- this.resourcePath = contentFile.getPath()
- + (contentFile.getSubPath() != null ? "/" + contentFile.getSubPath() : "");
+ this.resourcePath =
+ contentFile.getPath() + (contentFile.getSubPath() != null ? "/" + contentFile.getSubPath() : "");
}
public @NotNull String getPath() {
@@ -102,14 +102,12 @@ public final class ContentFileResource extends AbstractResource {
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(@Nullable Class<AdapterType> type) {
if (type == ContentFile.class) {
- return (AdapterType)this.contentFile;
- }
- else if (type == ValueMap.class) {
- return (AdapterType)new DeepReadValueMapDecorator(this, contentFile.getValueMap());
- }
- else if (type == Node.class) {
+ return (AdapterType) this.contentFile;
+ } else if (type == ValueMap.class) {
+ return (AdapterType) new DeepReadValueMapDecorator(this, contentFile.getValueMap());
+ } else if (type == Node.class) {
// support a subset of JCR API for content file resources
- return (AdapterType)new FsNode(contentFile, getResourceResolver());
+ return (AdapterType) new FsNode(contentFile, getResourceResolver());
}
return super.adaptTo(type);
}
@@ -123,5 +121,4 @@ public final class ContentFileResource extends AbstractResource {
.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
index 51218f3..ac0943c 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
@@ -46,9 +46,12 @@ public final class ContentFileResourceMapper {
private final ContentFileCache contentFileCache;
private final FileStatCache fileStatCache;
- public ContentFileResourceMapper(String providerRoot, File providerFile,
- ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache,
- FileStatCache fileStatCache) {
+ public ContentFileResourceMapper(
+ String providerRoot,
+ File providerFile,
+ ContentFileExtensions contentFileExtensions,
+ ContentFileCache contentFileCache,
+ FileStatCache fileStatCache) {
this.providerRootPrefix = providerRoot.concat("/");
this.providerFile = providerFile;
this.contentFileExtensions = contentFileExtensions;
@@ -66,18 +69,21 @@ public final class ContentFileResourceMapper {
public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
final String parentPath = parent.getPath();
- final ContentFile parentContentFile = getFile(parentPath, null);;
+ final ContentFile parentContentFile = getFile(parentPath, null);
+ ;
final List<Iterator<? extends Resource>> childIterators = new ArrayList<>(2);
// add children from parsed content
if (parentContentFile != null && parentContentFile.hasContent()) {
- childIterators.add(IteratorUtils.transformedIterator(parentContentFile.getContent().getChildren().keySet().iterator(), new Transformer<String, Resource>() {
- @Override
- public Resource transform(final String name) {
- return new ContentFileResource(resolver, parentContentFile.navigateToRelative(name));
- }
- }));
+ childIterators.add(IteratorUtils.transformedIterator(
+ parentContentFile.getContent().getChildren().keySet().iterator(),
+ new Transformer<String, Resource>() {
+ @Override
+ public Resource transform(final String name) {
+ return new ContentFileResource(resolver, parentContentFile.navigateToRelative(name));
+ }
+ }));
}
// add children from filesystem folder
@@ -86,20 +92,27 @@ public final class ContentFileResourceMapper {
File[] files = parentDir.listFiles();
if (files != null) {
Arrays.sort(files, FileNameComparator.INSTANCE);
- childIterators.add(IteratorUtils.transformedIterator(IteratorUtils.arrayIterator(files), new Transformer<File, Resource>() {
- @Override
- public Resource transform(final File file) {
- String path = parentPath + "/" + Escape.fileToResourceName(file.getName());
- String filenameSuffix = contentFileExtensions.getSuffix(file);
- if (filenameSuffix != null) {
- path = StringUtils.substringBeforeLast(path, filenameSuffix);
- ContentFile contentFile = new ContentFile(file, path, null, contentFileCache);
- return new ContentFileResource(resolver, contentFile);
- } else {
- return new FileResource(resolver, path, file, contentFileExtensions, contentFileCache, fileStatCache);
- }
- }
- }));
+ childIterators.add(IteratorUtils.transformedIterator(
+ IteratorUtils.arrayIterator(files), new Transformer<File, Resource>() {
+ @Override
+ public Resource transform(final File file) {
+ String path = parentPath + "/" + Escape.fileToResourceName(file.getName());
+ String filenameSuffix = contentFileExtensions.getSuffix(file);
+ if (filenameSuffix != null) {
+ path = StringUtils.substringBeforeLast(path, filenameSuffix);
+ ContentFile contentFile = new ContentFile(file, path, null, contentFileCache);
+ return new ContentFileResource(resolver, contentFile);
+ } else {
+ return new FileResource(
+ resolver,
+ path,
+ file,
+ contentFileExtensions,
+ contentFileCache,
+ fileStatCache);
+ }
+ }
+ }));
}
}
@@ -126,9 +139,7 @@ public final class ContentFileResourceMapper {
if (parentPath == null) {
return null;
}
- String nextSubPath = path.substring(parentPath.length() + 1)
- + (subPath != null ? "/" + subPath : "");
+ 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/mapper/Escape.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/Escape.java
index fd41e9a..67b11fe 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/Escape.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/Escape.java
@@ -33,20 +33,12 @@ public final class Escape {
* List of characters typically prohibited on unix and windows file systems.
* "/" is not included because it is neither allowed in resource nor in file names on any system.
*/
- private static final char[] RESERVED_CHARS = {
- '<',
- '>',
- ':',
- '"',
- '\\',
- '|',
- '?',
- '*',
- 0x00
- };
+ private static final char[] RESERVED_CHARS = {'<', '>', ':', '"', '\\', '|', '?', '*', 0x00};
+
private static final BitSet RESERVED_CHARS_SET = new BitSet();
+
static {
- for (int i=0; i<RESERVED_CHARS.length; i++) {
+ for (int i = 0; i < RESERVED_CHARS.length; i++) {
RESERVED_CHARS_SET.set(RESERVED_CHARS[i]);
}
}
@@ -67,8 +59,7 @@ public final class Escape {
if (path.indexOf('%') >= 0) {
try {
return URLDecoder.decode(path, "UTF-8");
- }
- catch (UnsupportedEncodingException ex) {
+ } catch (UnsupportedEncodingException ex) {
throw new RuntimeException("Unsupported encoding.", ex);
}
}
@@ -84,20 +75,17 @@ public final class Escape {
public static String resourceToFileName(String path) {
try {
StringBuilder result = new StringBuilder();
- for (int i=0; i<path.length(); i++) {
+ for (int i = 0; i < path.length(); i++) {
char c = path.charAt(i);
if (RESERVED_CHARS_SET.get(c)) {
result.append(URLEncoder.encode(String.valueOf(c), StandardCharsets.UTF_8.name()));
- }
- else {
+ } else {
result.append(c);
}
}
return result.toString();
- }
- catch (UnsupportedEncodingException ex) {
+ } catch (UnsupportedEncodingException ex) {
throw new RuntimeException("Unsupported encoding.", ex);
}
}
-
}
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 72401d4..582d9cf 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
@@ -18,6 +18,8 @@
*/
package org.apache.sling.fsprovider.internal.mapper;
+import javax.jcr.Node;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -28,8 +30,6 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
-import javax.jcr.Node;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -57,11 +57,18 @@ import org.slf4j.LoggerFactory;
* The <code>FileResource</code> represents a file system file or folder as
* a Sling Resource.
*/
-@Adaptable(adaptableClass=Resource.class, adapters={
- @Adapter({File.class, URL.class, ValueMap.class}),
- @Adapter(value=InputStream.class, condition="If the adaptable is a FileResource and is a readable file."),
- @Adapter(value=Node.class, condition="If the adaptable is a FileResource and is providing content in JSON or FileVault XML format.")
-})
+@Adaptable(
+ adaptableClass = Resource.class,
+ adapters = {
+ @Adapter({File.class, URL.class, ValueMap.class}),
+ @Adapter(
+ value = InputStream.class,
+ condition = "If the adaptable is a FileResource and is a readable file."),
+ @Adapter(
+ value = Node.class,
+ condition =
+ "If the adaptable is a FileResource and is providing content in JSON or FileVault XML format.")
+ })
public final class FileResource extends AbstractResource {
/**
@@ -112,9 +119,13 @@ public final class FileResource extends AbstractResource {
this(resolver, resourcePath, file, null, null, fileStatCache);
}
- FileResource(ResourceResolver resolver, String resourcePath, File file,
- ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache,
- FileStatCache fileStatCache) {
+ FileResource(
+ ResourceResolver resolver,
+ String resourcePath,
+ File file,
+ ContentFileExtensions contentFileExtensions,
+ ContentFileCache contentFileCache,
+ FileStatCache fileStatCache) {
this.resolver = resolver;
this.resourcePath = resourcePath;
this.file = file;
@@ -180,40 +191,33 @@ public final class FileResource extends AbstractResource {
* plus those supported by the adapter manager.
*/
@Override
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public @Nullable <AdapterType> AdapterType adaptTo(@NotNull Class<AdapterType> type) {
if (type == File.class) {
return (AdapterType) file;
- }
- else if (type == InputStream.class) {
+ } else if (type == InputStream.class) {
if (fileStatCache.isFile(file) && file.canRead()) {
try {
return (AdapterType) new FileInputStream(file);
- }
- catch (IOException ioe) {
+ } catch (IOException ioe) {
log.info("adaptTo: Cannot open a stream on the file " + file, ioe);
}
- }
- else {
+ } else {
log.debug("adaptTo: File {} is not a readable file", file);
}
- }
- else if (type == URL.class) {
+ } else if (type == URL.class) {
try {
return (AdapterType) file.toURI().toURL();
- }
- catch (MalformedURLException 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) {
return (AdapterType) getValueMap();
- }
- else if (type == Node.class) {
+ } else if (type == Node.class) {
ContentFile contentFile = getNodeDescriptorContentFile();
if (contentFile != null) {
// support a subset of JCR API for content file resources
- return (AdapterType)new FsNode(contentFile, getResourceResolver());
+ return (AdapterType) new FsNode(contentFile, getResourceResolver());
}
}
return super.adaptTo(type);
@@ -234,7 +238,7 @@ public final class FileResource extends AbstractResource {
// 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 (fileStatCache.exists(file) && file.canRead()) {
- Map<String,Object> props = new HashMap<String, Object>();
+ Map<String, Object> props = new HashMap<String, Object>();
props.put("jcr:primaryType", fileStatCache.isFile(file) ? RESOURCE_TYPE_FILE : RESOURCE_TYPE_FOLDER);
props.put("jcr:createdBy", "system");
@@ -245,10 +249,11 @@ public final class FileResource extends AbstractResource {
// overlay properties with those from node descriptor content file, if it exists
ContentFile contentFile = getNodeDescriptorContentFile();
if (contentFile != null) {
- for (Map.Entry<String, Object> entry : contentFile.getValueMap().entrySet()) {
+ for (Map.Entry<String, Object> entry :
+ contentFile.getValueMap().entrySet()) {
// skip primary type if it is the default type assigned by contentparser when none is defined
if (StringUtils.equals(entry.getKey(), "jcr:primaryType")
- && StringUtils.equals((String)entry.getValue(), ParserOptions.DEFAULT_PRIMARY_TYPE)) {
+ && StringUtils.equals((String) entry.getValue(), ParserOptions.DEFAULT_PRIMARY_TYPE)) {
continue;
}
props.put(entry.getKey(), entry.getValue());
@@ -273,5 +278,4 @@ public final class FileResource extends AbstractResource {
}
return null;
}
-
}
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
index 8d68f8e..ded23d1 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResourceMapper.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/mapper/FileResourceMapper.java
@@ -19,6 +19,7 @@
package org.apache.sling.fsprovider.internal.mapper;
import java.io.File;
+import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -26,7 +27,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.AbstractMap.SimpleEntry;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.collections4.Predicate;
@@ -61,15 +61,18 @@ public class FileResourceMapper {
private final ContentFileResourceMapper contentFileMapper;
- // if true resources from file system are only "overlayed" to JCR resources, serving JCR as fallback within the same path
+ // if true resources from file system are only "overlayed" to JCR resources, serving JCR as fallback within the same
+ // path
protected final boolean overlayParentResourceProvider;
- public FileResourceMapper(String providerRoot, File providerFile,
- ContentFileExtensions contentFileExtensions,
- ContentFileCache contentFileCache,
- FileStatCache fileStatCache,
- final boolean overlayParentResourceProvider,
- final boolean createContentFileMapper) {
+ public FileResourceMapper(
+ String providerRoot,
+ File providerFile,
+ ContentFileExtensions contentFileExtensions,
+ ContentFileCache contentFileCache,
+ FileStatCache fileStatCache,
+ final boolean overlayParentResourceProvider,
+ final boolean createContentFileMapper) {
this.providerRoot = providerRoot;
this.providerRootPrefix = providerRoot.concat("/");
this.providerFile = providerFile;
@@ -78,8 +81,12 @@ public class FileResourceMapper {
this.fileStatCache = fileStatCache;
this.overlayParentResourceProvider = overlayParentResourceProvider;
if (contentFileExtensions != null && createContentFileMapper) {
- this.contentFileMapper = new ContentFileResourceMapper(this.providerRoot, this.providerFile,
- contentFileExtensions, this.contentFileCache, this.fileStatCache);
+ this.contentFileMapper = new ContentFileResourceMapper(
+ this.providerRoot,
+ this.providerFile,
+ contentFileExtensions,
+ this.contentFileCache,
+ this.fileStatCache);
} else {
this.contentFileMapper = null;
}
@@ -98,10 +105,14 @@ public class FileResourceMapper {
return new SimpleEntry<>(rsrc, askParentResourceProvider);
}
- protected boolean resolveChildren(final ResourceResolver resolver, final Resource parent, final List<Iterator<? extends Resource>> allChildren) {
+ protected boolean resolveChildren(
+ final ResourceResolver resolver,
+ final Resource parent,
+ final List<Iterator<? extends Resource>> allChildren) {
// Sling-Initial-Content: get all matching folders/files and content files
final boolean askParentResourceProvider = this.overlayParentResourceProvider;
- Iterator<Resource> children = contentFileMapper == null ? null : contentFileMapper.getChildren(resolver, parent);
+ Iterator<Resource> children =
+ contentFileMapper == null ? null : contentFileMapper.getChildren(resolver, parent);
if (children != null) {
allChildren.add(children);
}
@@ -122,7 +133,8 @@ public class FileResourceMapper {
* method returns <code>null</code>.
*/
@SuppressWarnings("unchecked")
- public Resource getResource(final @NotNull ResolveContext<Object> ctx,
+ public Resource getResource(
+ final @NotNull ResolveContext<Object> ctx,
final @NotNull String path,
final @NotNull ResourceContext resourceContext,
final @Nullable Resource parent) {
@@ -134,29 +146,31 @@ public class FileResourceMapper {
Resource rsrc = resolved.getKey();
if (askParentResourceProvider) {
- // make sure directory resources from parent resource provider have higher precedence than from this provider
+ // make sure directory resources from parent resource provider have higher precedence than from this
+ // provider
// this allows properties like sling:resourceSuperType to take effect
- if ( rsrc == null || rsrc.getResourceMetadata().containsKey(FsResourceProvider.RESOURCE_METADATA_FILE_DIRECTORY) ) {
- // get resource from shadowed provider
- @SuppressWarnings("rawtypes")
+ if (rsrc == null
+ || rsrc.getResourceMetadata().containsKey(FsResourceProvider.RESOURCE_METADATA_FILE_DIRECTORY)) {
+ // get resource from shadowed provider
+ @SuppressWarnings("rawtypes")
final ResourceProvider rp = ctx.getParentResourceProvider();
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings("rawtypes")
final ResolveContext resolveContext = ctx.getParentResolveContext();
- if ( rp != null && resolveContext != null ) {
- Resource resourceFromParentResourceProvider = rp.getResource(resolveContext,
- path,
- resourceContext, parent);
- if (resourceFromParentResourceProvider != null) {
- rsrc = resourceFromParentResourceProvider;
- }
- }
+ if (rp != null && resolveContext != null) {
+ Resource resourceFromParentResourceProvider =
+ rp.getResource(resolveContext, path, resourceContext, parent);
+ if (resourceFromParentResourceProvider != null) {
+ rsrc = resourceFromParentResourceProvider;
+ }
+ }
}
}
return rsrc;
}
- protected void addChildren(final List<Iterator<? extends Resource>> allChildren, final Iterator<Resource> children) {
+ protected void addChildren(
+ final List<Iterator<? extends Resource>> allChildren, final Iterator<Resource> children) {
allChildren.add(children);
}
@@ -170,34 +184,37 @@ public class FileResourceMapper {
final List<Iterator<? extends Resource>> allChildren = new ArrayList<>();
final boolean askParentResourceProvider = this.resolveChildren(resolver, parent, allChildren);
- // get children from from shadowed provider
+ // get children from from shadowed provider
if (askParentResourceProvider) {
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings("rawtypes")
final ResourceProvider parentResourceProvider = ctx.getParentResourceProvider();
@SuppressWarnings("rawtypes")
final ResolveContext resolveContext = ctx.getParentResolveContext();
- if (parentResourceProvider != null && resolveContext != null) {
- Iterator<Resource> children = parentResourceProvider.listChildren(resolveContext, parent);
+ if (parentResourceProvider != null && resolveContext != null) {
+ Iterator<Resource> children = parentResourceProvider.listChildren(resolveContext, parent);
if (children != null) {
this.addChildren(allChildren, children);
}
- }
+ }
}
- if (allChildren.isEmpty()) {
- return null;
- } else if (allChildren.size() == 1) {
- return (Iterator<Resource>)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<Resource>() {
- private Set<String> names = new HashSet<>();
- @Override
- public boolean evaluate(final Resource resource) {
- return names.add(resource.getName());
- }
- });
- }
+ if (allChildren.isEmpty()) {
+ return null;
+ } else if (allChildren.size() == 1) {
+ return (Iterator<Resource>) 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<Resource>() {
+ private Set<String> names = new HashSet<>();
+
+ @Override
+ public boolean evaluate(final Resource resource) {
+ return names.add(resource.getName());
+ }
+ });
+ }
}
private Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
@@ -221,7 +238,13 @@ public class FileResourceMapper {
if (providerRoot.startsWith(parentPathPrefix)) {
String relPath = providerRoot.substring(parentPathPrefix.length());
if (relPath.indexOf('/') < 0) {
- Resource res = new FileResource(resolver, providerRoot, providerFile, contentFileExtensions, contentFileCache, fileStatCache);
+ Resource res = new FileResource(
+ resolver,
+ providerRoot,
+ providerFile,
+ contentFileExtensions,
+ contentFileCache,
+ fileStatCache);
return IteratorUtils.singletonIterator(res);
}
}
@@ -238,12 +261,13 @@ public class FileResourceMapper {
}
Arrays.sort(files, FileNameComparator.INSTANCE);
- Iterator<File> children = IteratorUtils.filteredIterator(IteratorUtils.arrayIterator(files), new Predicate<File>() {
- @Override
- public boolean evaluate(final File file) {
- return contentFileExtensions == null || !contentFileExtensions.matchesSuffix(file);
- }
- });
+ Iterator<File> children =
+ IteratorUtils.filteredIterator(IteratorUtils.arrayIterator(files), new Predicate<File>() {
+ @Override
+ public boolean evaluate(final File file) {
+ return contentFileExtensions == null || !contentFileExtensions.matchesSuffix(file);
+ }
+ });
if (!children.hasNext()) {
return null;
}
@@ -271,7 +295,8 @@ public class FileResourceMapper {
if (path.startsWith(providerRootPrefix)) {
String relPath = Escape.resourceToFileName(path.substring(providerRootPrefix.length()));
File file = new File(providerFile, relPath);
- if ((contentFileExtensions == null || !contentFileExtensions.matchesSuffix(file)) && fileStatCache.exists(file)) {
+ if ((contentFileExtensions == null || !contentFileExtensions.matchesSuffix(file))
+ && fileStatCache.exists(file)) {
return file;
}
}
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 506ae2b..076e78b 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
@@ -18,9 +18,6 @@
*/
package org.apache.sling.fsprovider.internal.mapper;
-import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
-import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.XML_SUFFIX;
-
import java.io.File;
import java.io.IOException;
import java.util.AbstractMap.SimpleEntry;
@@ -50,6 +47,9 @@ import org.apache.sling.fsprovider.internal.parser.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.jackrabbit.vault.util.Constants.DOT_CONTENT_XML;
+import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.XML_SUFFIX;
+
public final class FileVaultResourceMapper extends FileResourceMapper {
private static final String DOT_CONTENT_XML_SUFFIX = "/" + DOT_CONTENT_XML;
@@ -61,12 +61,22 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
private static final Logger log = LoggerFactory.getLogger(FileVaultResourceMapper.class);
- public FileVaultResourceMapper(String providerRoot, File providerFile,
- ContentFileExtensions contentFileExtensions, ContentFileCache contentFileCache,
- FileStatCache fileStatCache,
- final boolean overlayParentResourceProvider,
- final File filterXmlFile) {
- super(providerRoot, providerFile, contentFileExtensions, contentFileCache, fileStatCache, overlayParentResourceProvider, false);
+ public FileVaultResourceMapper(
+ String providerRoot,
+ File providerFile,
+ ContentFileExtensions contentFileExtensions,
+ ContentFileCache contentFileCache,
+ FileStatCache fileStatCache,
+ final boolean overlayParentResourceProvider,
+ final File filterXmlFile) {
+ super(
+ providerRoot,
+ providerFile,
+ contentFileExtensions,
+ contentFileCache,
+ fileStatCache,
+ overlayParentResourceProvider,
+ false);
this.filterXmlFile = filterXmlFile;
this.workspaceFilter = getWorkspaceFilter();
}
@@ -91,7 +101,10 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
}
@Override
- protected boolean resolveChildren(final ResourceResolver resolver, final Resource parent, final List<Iterator<? extends Resource>> allChildren) {
+ protected boolean resolveChildren(
+ final ResourceResolver resolver,
+ final Resource parent,
+ final List<Iterator<? extends Resource>> allChildren) {
// filevault: always ask provider, it checks itself if children matches the filters
final boolean askParentResourceProvider = true;
final Iterator<Resource> children = this.findChildren(resolver, parent);
@@ -102,7 +115,8 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
}
@Override
- protected void addChildren(final List<Iterator<? extends Resource>> allChildren, final Iterator<Resource> children) {
+ protected void addChildren(
+ final List<Iterator<? extends Resource>> allChildren, final Iterator<Resource> children) {
// filevault: include all children from parent resource provider that do not match the filters
allChildren.add(IteratorUtils.filteredIterator(children, new Predicate<Resource>() {
@Override
@@ -142,9 +156,9 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
// get children from content resource of parent
ContentFile parentContentFile = getContentFile(parentPath, null);
if (parentContentFile != null) {
- Iterator<Map.Entry<String,ContentElement>> childMaps = parentContentFile.getChildren();
+ Iterator<Map.Entry<String, ContentElement>> childMaps = parentContentFile.getChildren();
while (childMaps.hasNext()) {
- Map.Entry<String,ContentElement> entry = childMaps.next();
+ Map.Entry<String, ContentElement> entry = childMaps.next();
String childPath = parentPath + "/" + entry.getKey();
if (pathMatches(childPath)) {
childPaths.add(childPath);
@@ -201,8 +215,7 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
} catch (IOException | ConfigurationException ex) {
log.error("Unable to parse workspace filter: " + filterXmlFile.getPath(), ex);
}
- }
- else {
+ } else {
log.debug("Workspace filter not found: {}", filterXmlFile.getPath());
}
}
@@ -221,8 +234,7 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
}
if (workspaceFilter == null) {
return true;
- }
- else {
+ } else {
return workspaceFilter.contains(path);
}
}
@@ -263,8 +275,7 @@ public final class FileVaultResourceMapper extends FileResourceMapper {
if (parentPath == null) {
return null;
}
- String nextSubPath = path.substring(parentPath.length() + 1)
- + (subPath != null ? "/" + subPath : "");
+ 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/FsItem.java b/src/main/java/org/apache/sling/fsprovider/internal/mapper/jcr/FsItem.java
index d711bf6..5caf810 100644
--- 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
@@ -60,8 +60,7 @@ abstract class FsItem implements Item {
public String getPath() throws RepositoryException {
if (contentFile.getSubPath() == null) {
return contentFile.getPath();
- }
- else {
+ } else {
return contentFile.getPath() + "/" + contentFile.getSubPath();
}
}
@@ -71,8 +70,7 @@ abstract class FsItem implements Item {
String path;
if (depth == 0) {
path = "/";
- }
- else {
+ } else {
String[] pathParts = StringUtils.splitPreserveAllTokens(getPath(), "/");
path = StringUtils.join(pathParts, "/", 0, depth + 1);
}
@@ -131,19 +129,18 @@ abstract class FsItem implements Item {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("path", getPath())
.build();
- }
- catch (RepositoryException ex) {
+ } catch (RepositoryException ex) {
throw new RuntimeException(ex);
}
}
-
// --- unsupported methods ---
@Override
- public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException,
- InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException,
- NoSuchNodeTypeException, RepositoryException {
+ public void save()
+ throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException,
+ ReferentialIntegrityException, VersionException, LockException, NoSuchNodeTypeException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@@ -153,9 +150,9 @@ abstract class FsItem implements Item {
}
@Override
- public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException,
- RepositoryException {
+ 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
index 061ffdc..85d7161 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
@@ -18,10 +18,6 @@
*/
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;
@@ -51,6 +47,10 @@ import javax.jcr.version.Version;
import javax.jcr.version.VersionException;
import javax.jcr.version.VersionHistory;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
@@ -78,8 +78,7 @@ public final class FsNode extends FsItem implements Node {
public String getName() throws RepositoryException {
if (contentFile.getSubPath() == null) {
return ResourceUtil.getName(contentFile.getPath());
- }
- else {
+ } else {
return ResourceUtil.getName(contentFile.getSubPath());
}
}
@@ -98,17 +97,17 @@ public final class FsNode extends FsItem implements Node {
// get absolute node path
String path = relPath;
- if (!StringUtils.startsWith(path, "/")) {
+ if (!StringUtils.startsWith(path, "/")) {
path = ResourceUtil.normalize(getPath() + "/" + relPath);
}
- if (StringUtils.equals(path, contentFile.getPath()) || StringUtils.startsWith(path, contentFile.getPath() + "/")) {
+ 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 {
+ } else {
subPath = path.substring(contentFile.getPath().length() + 1);
}
ContentFile referencedFile = contentFile.navigateToAbsolute(subPath);
@@ -153,8 +152,7 @@ public final class FsNode extends FsItem implements Node {
String uuid = props.get("jcr:uuid", String.class);
if (uuid != null) {
return uuid;
- }
- else {
+ } else {
throw new UnsupportedRepositoryOperationException();
}
}
@@ -164,8 +162,7 @@ public final class FsNode extends FsItem implements Node {
try {
getNode(relPath);
return true;
- }
- catch (RepositoryException ex) {
+ } catch (RepositoryException ex) {
return false;
}
}
@@ -219,128 +216,144 @@ public final class FsNode extends FsItem implements Node {
public NodeType[] getMixinNodeTypes() throws RepositoryException {
String[] mixinTypeNames = getMixinTypeNames();
NodeType[] mixinTypes = new NodeType[mixinTypeNames.length];
- for (int i=0; i<mixinTypeNames.length; i++) {
+ 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 {
+ 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 {
+ ConstraintViolationException, RepositoryException {
throw new UnsupportedOperationException();
}
@Override
public void orderBefore(String srcChildRelPath, String destChildRelPath)
throws UnsupportedRepositoryOperationException, VersionException, ConstraintViolationException,
- ItemNotFoundException, LockException, RepositoryException {
+ ItemNotFoundException, LockException, RepositoryException {
throw new UnsupportedOperationException();
}
@Override
- public Property setProperty(String name, Value value) throws ValueFormatException, VersionException, LockException,
- ConstraintViolationException, RepositoryException {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ public Property setProperty(String name, Node value)
+ throws ValueFormatException, VersionException, LockException, ConstraintViolationException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@@ -365,20 +378,23 @@ public final class FsNode extends FsItem implements Node {
}
@Override
- public void setPrimaryType(String nodeTypeName) throws NoSuchNodeTypeException, VersionException,
- ConstraintViolationException, LockException, RepositoryException {
+ 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 {
+ 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 {
+ public void removeMixin(String mixinName)
+ throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@@ -388,38 +404,44 @@ public final class FsNode extends FsItem implements Node {
}
@Override
- public Version checkin() throws VersionException, UnsupportedRepositoryOperationException,
- InvalidItemStateException, LockException, RepositoryException {
+ public Version checkin()
+ throws VersionException, UnsupportedRepositoryOperationException, InvalidItemStateException, LockException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@Override
- public void checkout() throws UnsupportedRepositoryOperationException, LockException, ActivityViolationException,
- RepositoryException {
+ public void checkout()
+ throws UnsupportedRepositoryOperationException, LockException, ActivityViolationException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@Override
- public void doneMerge(Version version) throws VersionException, InvalidItemStateException,
- UnsupportedRepositoryOperationException, RepositoryException {
+ public void doneMerge(Version version)
+ throws VersionException, InvalidItemStateException, UnsupportedRepositoryOperationException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@Override
- public void cancelMerge(Version version) throws VersionException, InvalidItemStateException,
- UnsupportedRepositoryOperationException, RepositoryException {
+ 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 {
+ 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 {
+ public NodeIterator merge(String srcWorkspace, boolean bestEffort)
+ throws NoSuchWorkspaceException, AccessDeniedException, MergeException, LockException,
+ InvalidItemStateException, RepositoryException {
throw new UnsupportedOperationException();
}
@@ -447,28 +469,31 @@ public final class FsNode extends FsItem implements Node {
}
@Override
- public void restore(String versionName, boolean removeExisting) throws VersionException, ItemExistsException,
- UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
+ 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 {
+ 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 {
+ UnsupportedRepositoryOperationException, LockException, InvalidItemStateException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@Override
public void restoreByLabel(String versionLabel, boolean removeExisting)
throws VersionException, ItemExistsException, UnsupportedRepositoryOperationException, LockException,
- InvalidItemStateException, RepositoryException {
+ InvalidItemStateException, RepositoryException {
throw new UnsupportedOperationException();
}
@@ -483,8 +508,9 @@ public final class FsNode extends FsItem implements Node {
}
@Override
- public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException,
- LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
+ public Lock lock(boolean isDeep, boolean isSessionScoped)
+ throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException,
+ InvalidItemStateException, RepositoryException {
throw new UnsupportedOperationException();
}
@@ -495,8 +521,9 @@ public final class FsNode extends FsItem implements Node {
}
@Override
- public void unlock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException,
- InvalidItemStateException, RepositoryException {
+ public void unlock()
+ throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException,
+ InvalidItemStateException, RepositoryException {
throw new UnsupportedOperationException();
}
@@ -546,5 +573,4 @@ public final class FsNode extends FsItem implements Node {
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
index 3877ac6..407b867 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
@@ -18,12 +18,12 @@
*/
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 java.util.Iterator;
+import java.util.Map;
+
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.fsprovider.internal.mapper.ContentFile;
import org.apache.sling.fsprovider.internal.parser.ContentElement;
@@ -35,7 +35,7 @@ class FsNodeIterator implements NodeIterator {
private final ContentFile contentFile;
private final ResourceResolver resolver;
- private final Iterator<Map.Entry<String,ContentElement>> children;
+ private final Iterator<Map.Entry<String, ContentElement>> children;
public FsNodeIterator(ContentFile contentFile, ResourceResolver resolver) {
this.contentFile = contentFile;
@@ -54,11 +54,10 @@ class FsNodeIterator implements NodeIterator {
@Override
public Node nextNode() {
- Map.Entry<String,ContentElement> nextEntry = children.next();
+ Map.Entry<String, ContentElement> nextEntry = children.next();
return new FsNode(contentFile.navigateToRelative(nextEntry.getKey()), resolver);
}
-
// --- unsupported methods ---
public void remove() {
@@ -79,5 +78,4 @@ class FsNodeIterator implements NodeIterator {
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
index 945d7e4..d7bb96e 100644
--- 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
@@ -86,7 +86,6 @@ class FsNodeType implements NodeType {
return StringUtils.equals(name, nodeTypeName);
}
-
// --- unsupported methods ---
@Override
@@ -153,5 +152,4 @@ class FsNodeType implements NodeType {
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
index 0ff2947..69b73b5 100644
--- 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
@@ -18,11 +18,6 @@
*/
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;
@@ -36,6 +31,11 @@ import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.version.VersionException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.fsprovider.internal.mapper.ContentFile;
@@ -127,7 +127,7 @@ class FsProperty extends FsItem implements Property {
Object value = props.get(propertyName);
int size = Array.getLength(value);
Value[] result = new Value[size];
- for (int i=0; i<size; i++) {
+ for (int i = 0; i < size; i++) {
result[i] = new FsValue(props, propertyName, i);
}
return result;
@@ -149,78 +149,89 @@ class FsProperty extends FsItem implements Property {
return new FsPropertyDefinition(propertyName);
}
-
// --- unsupported methods ---
@Override
- public void setValue(Value value) throws ValueFormatException, VersionException, LockException,
- ConstraintViolationException, RepositoryException {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ 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 {
+ public void setValue(Node value)
+ throws ValueFormatException, VersionException, LockException, ConstraintViolationException,
+ RepositoryException {
throw new UnsupportedOperationException();
}
@@ -238,5 +249,4 @@ class FsProperty extends FsItem implements Property {
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
index 594e215..8285094 100644
--- 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
@@ -18,20 +18,21 @@
*/
package org.apache.sling.fsprovider.internal.mapper.jcr;
-import java.util.HashSet;
-import java.util.Set;
-
import javax.jcr.PropertyType;
import javax.jcr.Value;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.version.OnParentVersionAction;
+import java.util.HashSet;
+import java.util.Set;
+
import org.apache.jackrabbit.JcrConstants;
class FsPropertyDefinition implements PropertyDefinition {
private static final Set<String> PROTECTED_PROPERTY_NAMES = new HashSet<>();
+
static {
// from nt:base
PROTECTED_PROPERTY_NAMES.add(JcrConstants.JCR_PRIMARYTYPE);
@@ -111,5 +112,4 @@ class FsPropertyDefinition implements PropertyDefinition {
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
index 3d85e6f..498e83d 100644
--- 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
@@ -18,12 +18,12 @@
*/
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 java.util.Iterator;
+
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.fsprovider.internal.mapper.ContentFile;
@@ -37,7 +37,8 @@ class FsPropertyIterator implements PropertyIterator {
private final ResourceResolver resolver;
private final Node node;
- public FsPropertyIterator(Iterator<String> propertyNames, ContentFile contentFile, ResourceResolver resolver, Node node) {
+ public FsPropertyIterator(
+ Iterator<String> propertyNames, ContentFile contentFile, ResourceResolver resolver, Node node) {
this.propertyNames = propertyNames;
this.contentFile = contentFile;
this.resolver = resolver;
@@ -57,7 +58,6 @@ class FsPropertyIterator implements PropertyIterator {
return new FsProperty(contentFile, resolver, propertyNames.next(), node);
}
-
// --- unsupported methods ---
public void remove() {
@@ -78,5 +78,4 @@ class FsPropertyIterator implements PropertyIterator {
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
index 4143f8f..a90ab3a 100644
--- 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
@@ -18,17 +18,17 @@
*/
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 java.io.InputStream;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.util.Calendar;
+
import org.apache.sling.api.resource.ValueMap;
/**
@@ -60,8 +60,7 @@ class FsValue implements Value {
return null;
}
return array[arrayIndex];
- }
- else {
+ } else {
return props.get(propertyName, String.class);
}
}
@@ -74,8 +73,7 @@ class FsValue implements Value {
return 0;
}
return array[arrayIndex];
- }
- else {
+ } else {
return props.get(propertyName, 0L);
}
}
@@ -88,8 +86,7 @@ class FsValue implements Value {
return 0;
}
return array[arrayIndex];
- }
- else {
+ } else {
return props.get(propertyName, 0d);
}
}
@@ -102,8 +99,7 @@ class FsValue implements Value {
return null;
}
return array[arrayIndex];
- }
- else {
+ } else {
return props.get(propertyName, BigDecimal.ZERO);
}
}
@@ -116,8 +112,7 @@ class FsValue implements Value {
return null;
}
return array[arrayIndex];
- }
- else {
+ } else {
return props.get(propertyName, Calendar.class);
}
}
@@ -130,8 +125,7 @@ class FsValue implements Value {
return false;
}
return array[arrayIndex];
- }
- else {
+ } else {
return props.get(propertyName, false);
}
}
@@ -170,7 +164,6 @@ class FsValue implements Value {
return PropertyType.UNDEFINED;
}
-
// --- unsupported methods ---
@Override
@@ -182,5 +175,4 @@ class FsValue implements Value {
public Binary getBinary() throws RepositoryException {
throw new UnsupportedOperationException();
}
-
}
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
index 7b074e9..22be260 100644
--- 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
@@ -95,5 +95,4 @@ final class DateUtils {
}
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
index 9a6fe4a..b20657e 100644
--- 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
@@ -42,7 +42,7 @@ final class ObjectConverter {
* @param type type
* @return the converted object
*/
- @SuppressWarnings({ "unchecked", "null" })
+ @SuppressWarnings({"unchecked", "null"})
public static <T> T convert(Object obj, Class<T> type) {
if (obj == null) {
return null;
@@ -50,20 +50,20 @@ final class ObjectConverter {
// check if direct assignment is possible
if (type.isAssignableFrom(obj.getClass())) {
- return (T)obj;
+ return (T) obj;
}
// convert array elements individually
if (type.isArray()) {
- return (T)convertToArray(obj, type.getComponentType());
+ 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);
+ return (T) DateUtils.toCalendar((Date) obj);
}
if (type == Date.class && obj instanceof Calendar) {
- return (T)DateUtils.toDate((Calendar)obj);
+ return (T) DateUtils.toDate((Calendar) obj);
}
// no direct conversion - format to string and try to parse to target type
@@ -72,51 +72,48 @@ final class ObjectConverter {
return null;
}
if (type == String.class) {
- return (T)result.toString();
+ 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 (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);
+ return (T) (Byte) Byte.parseByte(result);
}
if (type == Short.class) {
- return (T)(Short)Short.parseShort(result);
+ return (T) (Short) Short.parseShort(result);
}
if (type == Integer.class) {
- return (T)(Integer)Integer.parseInt(result);
+ return (T) (Integer) Integer.parseInt(result);
}
if (type == Long.class) {
- return (T)(Long)Long.parseLong(result);
+ return (T) (Long) Long.parseLong(result);
}
if (type == Float.class) {
- return (T)(Float)Float.parseFloat(result);
+ return (T) (Float) Float.parseFloat(result);
}
if (type == Double.class) {
- return (T)(Double)Double.parseDouble(result);
+ return (T) (Double) Double.parseDouble(result);
}
if (type == BigDecimal.class) {
- return (T)new BigDecimal(result);
+ return (T) new BigDecimal(result);
}
- }
- catch (NumberFormatException e) {
+ } catch (NumberFormatException e) {
return null;
}
if (Calendar.class.isAssignableFrom(type)) {
- return (T)DateUtils.calendarFromString(result);
+ return (T) DateUtils.calendarFromString(result);
}
if (type == Date.class) {
- return (T)DateUtils.dateFromString(result);
+ return (T) DateUtils.dateFromString(result);
}
return null;
}
@@ -131,22 +128,17 @@ final class ObjectConverter {
final String result;
if (obj == null) {
result = null;
- }
- else if (obj.getClass().isArray()) {
+ } else if (obj.getClass().isArray()) {
if (Array.getLength(obj) == 0) {
result = null;
- }
- else {
+ } 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 {
+ } 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;
@@ -168,18 +160,16 @@ final class ObjectConverter {
resultList.add(singleValueResult);
}
}
- return resultList.toArray((T[])Array.newInstance(type, resultList.size()));
- }
- else {
+ 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);
+ return (T[]) Array.newInstance(type, 0);
}
- final T[] arrayResult = (T[])Array.newInstance(type, 1);
+ 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
index f6808c2..6f9544f 100644
--- 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
@@ -52,7 +52,7 @@ public final class ValueMapDecorator implements ValueMap {
public <T> T get(@NotNull String name, @NotNull Class<T> type) {
if (base instanceof ValueMap) {
// shortcut if decorated map is ValueMap
- return ((ValueMap)base).get(name, type);
+ return ((ValueMap) base).get(name, type);
}
return ObjectConverter.convert(get(name), type);
}
@@ -60,14 +60,14 @@ public final class ValueMapDecorator implements ValueMap {
/**
* {@inheritDoc}
*/
- @SuppressWarnings({ "unchecked", "unused" })
+ @SuppressWarnings({"unchecked", "unused"})
public <T> @NotNull T get(@NotNull String name, @NotNull T defaultValue) {
if (base instanceof ValueMap) {
// shortcut if decorated map is ValueMap
- return ((ValueMap)base).get(name, defaultValue);
+ return ((ValueMap) base).get(name, defaultValue);
}
if (defaultValue == null) {
- return (T)get(name);
+ return (T) get(name);
}
T value = get(name, (Class<T>) defaultValue.getClass());
return value == null ? defaultValue : value;
@@ -177,5 +177,4 @@ public final class ValueMapDecorator implements ValueMap {
public boolean equals(Object obj) {
return base.equals(obj);
}
-
}
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 5ba7b04..fb37577 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
@@ -35,20 +35,18 @@ public final class ValueMapUtil {
* @param content Content map.
* @return Value map.
*/
- public static ValueMap toValueMap(Map<String,Object> content) {
- Map<String,Object> props = new HashMap<>();
+ public static ValueMap toValueMap(Map<String, Object> content) {
+ Map<String, Object> props = new HashMap<>();
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());
- }
- else {
+ props.put(entry.getKey(), ((Collection) entry.getValue()).toArray());
+ } else {
props.put(entry.getKey(), entry.getValue());
}
}
return new ValueMapDecorator(props);
}
-
}
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
index 77e3cca..cd5cbc7 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElement.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElement.java
@@ -48,5 +48,4 @@ public interface ContentElement {
* @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
index 1303b7f..26891f1 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementHandler.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementHandler.java
@@ -37,8 +37,7 @@ final class ContentElementHandler implements ContentHandler {
public void resource(String path, Map<String, Object> properties) {
if (StringUtils.equals(path, "/")) {
root = new ContentElementImpl(null, properties);
- }
- else {
+ } else {
if (root == null) {
throw new RuntimeException("Root resource not set.");
}
@@ -51,8 +50,7 @@ final class ContentElementHandler implements ContentHandler {
ContentElement parent;
if (StringUtils.isEmpty(relativeParentPath)) {
parent = root;
- }
- else {
+ } else {
parent = root.getChild(relativeParentPath);
}
if (parent == null) {
@@ -65,5 +63,4 @@ final class ContentElementHandler implements ContentHandler {
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
index 9f139bb..02184ba 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementImpl.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentElementImpl.java
@@ -54,15 +54,13 @@ final class ContentElementImpl implements ContentElement {
String name = StringUtils.substringBefore(path, "/");
ContentElement child = children.get(name);
if (child == null) {
- return null;
+ return null;
}
String remainingPath = StringUtils.substringAfter(path, "/");
if (StringUtils.isEmpty(remainingPath)) {
- return child;
- }
- else {
- return child.getChild(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 6001b30..c1a753b 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.collections4.map.LRUMap;
*/
public final class ContentFileCache {
- private final Map<String,ContentElement> contentCache;
- private final ContentElement NULL_ELEMENT = new ContentElementImpl(null, Collections.<String,Object>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.
@@ -114,5 +114,4 @@ public final class ContentFileCache {
return 0;
}
}
-
}
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 0ec28b7..65075ec 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,11 +18,6 @@
*/
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;
-import static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.XML_SUFFIX;
-
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -39,6 +34,11 @@ import org.apache.sling.contentparser.xml.jcr.internal.JCRXMLContentParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+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 static org.apache.sling.fsprovider.internal.parser.ContentFileTypes.XML_SUFFIX;
+
/**
* Parses files that contains content fragments (e.g. JSON, JCR XML).
*/
@@ -47,8 +47,8 @@ class ContentFileParserUtil {
private static final Logger log = LoggerFactory.getLogger(ContentFileParserUtil.class);
private static final ParserOptions DEFAULT_PARSER_OPTIONS = new ParserOptions();
- private static final ParserOptions JSON_PARSER_OPTIONS = new JSONParserOptions()
- .withFeatures(JSONParserFeature.COMMENTS, JSONParserFeature.QUOTE_TICK);
+ private static final ParserOptions JSON_PARSER_OPTIONS =
+ new JSONParserOptions().withFeatures(JSONParserFeature.COMMENTS, JSONParserFeature.QUOTE_TICK);
private static final ContentParser JSON_PARSER = new JSONContentParser();
private static final ContentParser JCR_XML_PARSER = new JCRXMLContentParser();
private static final ContentParser XML_PARSER = new XMLContentParser();
@@ -68,11 +68,11 @@ class ContentFileParserUtil {
}
if (StringUtils.endsWith(file.getName(), JSON_SUFFIX)) {
return parse(file, ContentType.JSON);
- }
- else if (StringUtils.equals(file.getName(), DOT_CONTENT_XML) || StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
+ } else if (StringUtils.equals(file.getName(), DOT_CONTENT_XML)
+ || StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
return parse(file, ContentType.JCR_XML);
- }
- else if (StringUtils.endsWith(file.getName(), XML_SUFFIX) && !StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
+ } else if (StringUtils.endsWith(file.getName(), XML_SUFFIX)
+ && !StringUtils.endsWith(file.getName(), JCR_XML_SUFFIX)) {
return parse(file, ContentType.XML);
}
return null;
@@ -90,23 +90,23 @@ class ContentFileParserUtil {
}
try {
switch (contentType) {
- case JSON:
- return parse(JSON_PARSER, file, JSON_PARSER_OPTIONS);
- case XML:
- return parse(XML_PARSER, file, DEFAULT_PARSER_OPTIONS);
- case JCR_XML:
- return parse(JCR_XML_PARSER, file, DEFAULT_PARSER_OPTIONS);
- default:
+ case JSON:
+ return parse(JSON_PARSER, file, JSON_PARSER_OPTIONS);
+ case XML:
+ return parse(XML_PARSER, file, DEFAULT_PARSER_OPTIONS);
+ case JCR_XML:
+ return parse(JCR_XML_PARSER, file, DEFAULT_PARSER_OPTIONS);
+ default:
throw new IllegalArgumentException("Unexpected content type: " + contentType);
}
- }
- catch (Throwable ex) {
+ } catch (Throwable ex) {
log.warn("Error parsing content from " + file.getPath(), ex);
}
return null;
}
- private static ContentElement parse(ContentParser contentParser, File file, ParserOptions parserOptions) throws IOException {
+ private static ContentElement parse(ContentParser contentParser, File file, ParserOptions parserOptions)
+ throws IOException {
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis)) {
ContentElementHandler handler = new ContentElementHandler();
@@ -114,5 +114,4 @@ class ContentFileParserUtil {
return handler.getRoot();
}
}
-
}
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 87cabac..9d90a6c 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
@@ -41,5 +41,4 @@ public final class ContentFileTypes {
private ContentFileTypes() {
// static methods only
}
-
}
diff --git a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentType.java b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentType.java
index d21888e..025b7da 100644
--- a/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentType.java
+++ b/src/main/java/org/apache/sling/fsprovider/internal/parser/ContentType.java
@@ -40,7 +40,6 @@ public enum ContentType {
*/
JCR_XML("jcr.xml");
-
private final String extension;
private ContentType(String extension) {
@@ -53,5 +52,4 @@ public enum ContentType {
public String getExtension() {
return extension;
}
-
}
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 71dc901..cc9c24c 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileMonitorTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.fsprovider.internal;
-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.charset.StandardCharsets;
import java.nio.file.Files;
@@ -40,6 +36,10 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertChange;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Test events when changing file system content (Sling-Initial-Content).
*/
@@ -57,36 +57,50 @@ public class FileMonitorTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .beforeSetUp(new SlingContextCallback() {
- @Override
- public void execute(@NotNull 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.root", "/fs-test",
- "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(ResourceChangeListener.class, resourceListener,
- ResourceChangeListener.PATHS, new String[] { "/fs-test" },
- ResourceChangeListener.CHANGES, new String[] { ChangeType.CHANGED.toString(), ChangeType.ADDED.toString(), ChangeType.REMOVED.toString() });
- }
- })
- .afterTearDown(new SlingContextCallback() {
- @Override
- public void execute(@NotNull SlingContext context) throws Exception {
- // remove temp directory
- tempDir.delete();
- }
- })
- .build();
+ .beforeSetUp(new SlingContextCallback() {
+ @Override
+ public void execute(@NotNull 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.root",
+ "/fs-test",
+ "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(
+ ResourceChangeListener.class,
+ resourceListener,
+ ResourceChangeListener.PATHS,
+ new String[] {"/fs-test"},
+ ResourceChangeListener.CHANGES,
+ new String[] {
+ ChangeType.CHANGED.toString(),
+ ChangeType.ADDED.toString(),
+ ChangeType.REMOVED.toString()
+ });
+ }
+ })
+ .afterTearDown(new SlingContextCallback() {
+ @Override
+ public void execute(@NotNull SlingContext context) throws Exception {
+ // remove temp directory
+ tempDir.delete();
+ }
+ })
+ .build();
@Test
public void testUpdateFile() throws Exception {
@@ -207,5 +221,4 @@ public class FileMonitorTest {
assertChange(changes, "/fs-test/folder2", ChangeType.CHANGED);
assertChange(changes, "/fs-test/folder2/content", ChangeType.REMOVED);
}
-
}
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 18edd2d..5bb19f1 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultContentTest.java
@@ -18,22 +18,13 @@
*/
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.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
-
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
@@ -45,6 +36,15 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
/**
* Test access FileFault XML files, folders and content.
*/
@@ -56,19 +56,17 @@ public class FileVaultContentTest {
@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/jcr_root",
- "provider.filevault.filterxml.path", "src/test/resources/vaultfs-test/META-INF/vault/filter.xml",
- "provider.root", "/content/dam/talk.png"
- ))
- .plugin(new RegisterFsResourcePlugin(
- "provider.fs.mode", FsMode.FILEVAULT_XML.name(),
- "provider.file", "src/test/resources/vaultfs-test/jcr_root",
- "provider.filevault.filterxml.path", "src/test/resources/vaultfs-test/META-INF/vault/filter.xml",
- "provider.root", "/content/samples"
- ))
- .build();
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode", FsMode.FILEVAULT_XML.name(),
+ "provider.file", "src/test/resources/vaultfs-test/jcr_root",
+ "provider.filevault.filterxml.path", "src/test/resources/vaultfs-test/META-INF/vault/filter.xml",
+ "provider.root", "/content/dam/talk.png"))
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode", FsMode.FILEVAULT_XML.name(),
+ "provider.file", "src/test/resources/vaultfs-test/jcr_root",
+ "provider.filevault.filterxml.path", "src/test/resources/vaultfs-test/META-INF/vault/filter.xml",
+ "provider.root", "/content/samples"))
+ .build();
@Before
public void setUp() {
@@ -88,7 +86,7 @@ public class FileVaultContentTest {
Resource metadata = content.getChild("metadata");
assertNotNull(metadata);
ValueMap props = metadata.getValueMap();
- assertEquals((Integer)4, props.get("app:Bitsperpixel", Integer.class));
+ assertEquals((Integer) 4, props.get("app:Bitsperpixel", Integer.class));
assertFolder(content, "renditions");
assertFile(content, "renditions/original", null);
@@ -101,7 +99,9 @@ public class FileVaultContentTest {
assertEquals("sling:OrderedFolder", sampleContent.getResourceType());
Resource enContent = sampleContent.getChild("en/jcr:content");
- assertArrayEquals(new String[] { "/etc/mobile/groups/responsive" }, enContent.getValueMap().get("app:deviceGroups", String[].class));
+ assertArrayEquals(
+ new String[] {"/etc/mobile/groups/responsive"},
+ enContent.getValueMap().get("app:deviceGroups", String[].class));
}
@Test
@@ -109,7 +109,9 @@ public class FileVaultContentTest {
Resource en = sampleContent.getChild("en");
// about_us and about_them are not defined for ordering in en/.content.xml and thus sorted last
assertThat(en, ResourceMatchers.containsChildren("jcr:content", "tools", "extra", "about_them", "about_us"));
- assertEquals("samples/sample-app/components/content/page/homepage", en.getChild("jcr:content").getResourceType());
+ assertEquals(
+ "samples/sample-app/components/content/page/homepage",
+ en.getChild("jcr:content").getResourceType());
assertEquals("app:Page", en.getChild("tools").getResourceType());
// another child (conference) is hidden because of filter
@@ -138,7 +140,10 @@ public class FileVaultContentTest {
// list children with mixed content
Resource enResource = sampleContent.getChild("en");
- assertThat(enResource, ResourceMatchers.containsChildren("jcr:content", "tools", "extra", "about_them", "about_us", "conference"));
+ assertThat(
+ enResource,
+ ResourceMatchers.containsChildren(
+ "jcr:content", "tools", "extra", "about_them", "about_us", "conference"));
}
@Test
@@ -176,7 +181,7 @@ public class FileVaultContentTest {
childrenByName.put(child.getName(), child);
}
- assertEquals("Wrong child count for 'aggregates'",1, childrenByName.size());
+ assertEquals("Wrong child count for 'aggregates'", 1, childrenByName.size());
assertTrue("Child named 'sling:aggregate' does not exist", childrenByName.containsKey("sling:aggregate"));
}
}
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 1e06283..3e65601 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FileVaultFileMonitorTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.fsprovider.internal;
-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.charset.StandardCharsets;
import java.nio.file.Files;
@@ -40,6 +36,10 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertChange;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* Test events when changing file system content (FileVault XML).
*/
@@ -57,42 +57,62 @@ public class FileVaultFileMonitorTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .beforeSetUp(new SlingContextCallback() {
- @Override
- public void execute(@NotNull 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() + "/jcr_root",
- "provider.filevault.filterxml.path", tempDir.getPath() + "/META-INF/vault/filter.xml",
- "provider.root", "/content/dam/talk.png",
- "provider.checkinterval", CHECK_INTERVAL,
- "provider.fs.mode", FsMode.FILEVAULT_XML.name());
- context.registerInjectActivateService(new FsResourceProvider(),
- "provider.file", tempDir.getPath() + "/jcr_root",
- "provider.filevault.filterxml.path", tempDir.getPath() + "/META-INF/vault/filter.xml",
- "provider.root", "/content/samples",
- "provider.checkinterval", CHECK_INTERVAL,
- "provider.fs.mode", FsMode.FILEVAULT_XML.name());
-
- // register resource change listener
- context.registerService(ResourceChangeListener.class, resourceListener,
- ResourceChangeListener.PATHS, new String[] { "/content/dam/talk.png", "/content/samples" },
- ResourceChangeListener.CHANGES, new String[] { ChangeType.CHANGED.toString(), ChangeType.ADDED.toString(), ChangeType.REMOVED.toString() });
- }
- })
- .afterTearDown(new SlingContextCallback() {
- @Override
- public void execute(@NotNull SlingContext context) throws Exception {
- // remove temp directory
- tempDir.delete();
- }
- })
- .build();
+ .beforeSetUp(new SlingContextCallback() {
+ @Override
+ public void execute(@NotNull 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() + "/jcr_root",
+ "provider.filevault.filterxml.path",
+ tempDir.getPath() + "/META-INF/vault/filter.xml",
+ "provider.root",
+ "/content/dam/talk.png",
+ "provider.checkinterval",
+ CHECK_INTERVAL,
+ "provider.fs.mode",
+ FsMode.FILEVAULT_XML.name());
+ context.registerInjectActivateService(
+ new FsResourceProvider(),
+ "provider.file",
+ tempDir.getPath() + "/jcr_root",
+ "provider.filevault.filterxml.path",
+ tempDir.getPath() + "/META-INF/vault/filter.xml",
+ "provider.root",
+ "/content/samples",
+ "provider.checkinterval",
+ CHECK_INTERVAL,
+ "provider.fs.mode",
+ FsMode.FILEVAULT_XML.name());
+
+ // register resource change listener
+ context.registerService(
+ ResourceChangeListener.class,
+ resourceListener,
+ ResourceChangeListener.PATHS,
+ new String[] {"/content/dam/talk.png", "/content/samples"},
+ ResourceChangeListener.CHANGES,
+ new String[] {
+ ChangeType.CHANGED.toString(),
+ ChangeType.ADDED.toString(),
+ ChangeType.REMOVED.toString()
+ });
+ }
+ })
+ .afterTearDown(new SlingContextCallback() {
+ @Override
+ public void execute(@NotNull SlingContext context) throws Exception {
+ // remove temp directory
+ tempDir.delete();
+ }
+ })
+ .build();
@Test
public void testUpdateFile() throws Exception {
@@ -190,11 +210,14 @@ public class FileVaultFileMonitorTest {
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>", StandardCharsets.UTF_8);
+ 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>",
+ StandardCharsets.UTF_8);
Thread.sleep(WAIT_INTERVAL);
@@ -233,5 +256,4 @@ public class FileVaultFileMonitorTest {
// this second event is not fully correct, but this is a quite special case, accept it for now
assertChange(changes, "/content/samples/en", ChangeType.REMOVED);
}
-
}
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 17e3a04..14b9dfb 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/FilesFolderTest.java
@@ -18,12 +18,6 @@
*/
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.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
@@ -35,6 +29,12 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
/**
* Test access to files and folders from file system.
*/
@@ -46,8 +46,8 @@ public class FilesFolderTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .plugin(new RegisterFsResourcePlugin())
- .build();
+ .plugin(new RegisterFsResourcePlugin())
+ .build();
@Before
public void setUp() {
@@ -78,7 +78,9 @@ public class FilesFolderTest {
public void testListChildren() {
assertThat(root, ResourceMatchers.containsChildren("fs-test"));
assertThat(fsroot, ResourceMatchers.containsChildren("folder1", "folder2", "folder3"));
- assertThat(fsroot.getChild("folder1"), ResourceMatchers.containsChildren("file1a.txt", "folder11", "sling:file1b.txt"));
+ assertThat(
+ fsroot.getChild("folder1"),
+ ResourceMatchers.containsChildren("file1a.txt", "folder11", "sling:file1b.txt"));
assertThat(fsroot.getChild("folder2"), ResourceMatchers.hasChildren("folder21", "content.json"));
assertFalse(fsroot.getChild("folder1/file1a.txt").listChildren().hasNext());
}
@@ -90,5 +92,4 @@ public class FilesFolderTest {
String type = properties.get("folder11/jcr:primaryType", String.class);
assertEquals("nt:folder", type);
}
-
}
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 3a0d166..565cd7a 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/InitialContentImportOptionsTest.java
@@ -18,14 +18,13 @@
*/
package org.apache.sling.fsprovider.internal;
+import com.google.common.collect.ImmutableSet;
+import org.junit.Test;
+
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
@@ -44,16 +43,17 @@ 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
public void testOptions2() {
- InitialContentImportOptions underTest = new InitialContentImportOptions(" overwrite := false ; ignoreImportProviders := xml ");
+ 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/InvalidRootFolderTest.java b/src/test/java/org/apache/sling/fsprovider/internal/InvalidRootFolderTest.java
index c9bd6c7..91ad0bb 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/InvalidRootFolderTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/InvalidRootFolderTest.java
@@ -18,9 +18,6 @@
*/
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;
@@ -34,6 +31,9 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
/**
* Test with invalid fs folder.
*/
@@ -43,15 +43,15 @@ public class InvalidRootFolderTest {
@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(@NotNull SlingContext context) throws Exception {
- File file = new File("target/temp/invalid-folder");
- file.delete();
- }
- })
- .build();
+ .plugin(new RegisterFsResourcePlugin("provider.file", "target/temp/invalid-folder"))
+ .afterTearDown(new SlingContextCallback() {
+ @Override
+ public void execute(@NotNull SlingContext context) throws Exception {
+ File file = new File("target/temp/invalid-folder");
+ file.delete();
+ }
+ })
+ .build();
@Before
public void setUp() {
@@ -72,5 +72,4 @@ public class InvalidRootFolderTest {
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
index 6b0ff82..e3f1ab7 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JcrMixedTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrMixedTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.fsprovider.internal;
-import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.not;
-
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -35,6 +31,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.not;
+
/**
* Test access mixed with JCR content on same path.
*/
@@ -46,8 +46,8 @@ public class JcrMixedTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .plugin(new RegisterFsResourcePlugin())
- .build();
+ .plugin(new RegisterFsResourcePlugin())
+ .build();
@Before
public void setUp() throws RepositoryException {
@@ -75,9 +75,7 @@ public class JcrMixedTest {
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));
+ assertThat(folder1, ResourceMatchers.props("jcr:primaryType", "nt:folder", "prop1", "value1", "prop2", 123L));
}
@Test
@@ -89,16 +87,15 @@ public class JcrMixedTest {
// do not expected properties from JCR for files
Resource file1a = fsroot.getChild("folder1/file1a.txt");
- assertThat(file1a, not(ResourceMatchers.props(
- "prop1", "value2",
- "prop2", 234L)));
+ 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", "sling:file1b.txt", "file1c.txt"));
+ assertThat(
+ fsroot.getChild("folder1"),
+ ResourceMatchers.hasChildren("file1a.txt", "sling: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
index 4c96990..9228018 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JcrXmlContentTest.java
@@ -18,21 +18,13 @@
*/
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.hamcrest.MatcherAssert.assertThat;
-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 javax.jcr.Node;
+import javax.jcr.RepositoryException;
import java.util.Collections;
import java.util.List;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
+import com.google.common.collect.Lists;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.fsprovider.internal.TestUtils.RegisterFsResourcePlugin;
@@ -44,7 +36,14 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import com.google.common.collect.Lists;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.hamcrest.MatcherAssert.assertThat;
+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;
/**
* Test access to files and folders from file system.
@@ -58,10 +57,11 @@ public class JcrXmlContentTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
.plugin(new RegisterFsResourcePlugin(
- "provider.fs.mode", FsMode.INITIAL_CONTENT.name(),
- "provider.initial.content.import.options", "overwrite:=true;ignoreImportProviders:=json"
- ))
- .build();
+ "provider.fs.mode",
+ FsMode.INITIAL_CONTENT.name(),
+ "provider.initial.content.import.options",
+ "overwrite:=true;ignoreImportProviders:=json"))
+ .build();
@Before
public void setUp() {
@@ -90,7 +90,9 @@ public class JcrXmlContentTest {
public void testListChildren() {
assertThat(root, ResourceMatchers.containsChildren("fs-test"));
assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2"));
- assertThat(fsroot.getChild("folder1"), ResourceMatchers.containsChildren("file1a.txt", "folder11", "sling:file1b.txt"));
+ assertThat(
+ fsroot.getChild("folder1"),
+ ResourceMatchers.containsChildren("file1a.txt", "folder11", "sling:file1b.txt"));
assertThat(fsroot.getChild("folder2"), ResourceMatchers.hasChildren("folder21", "content"));
}
@@ -128,11 +130,11 @@ public class JcrXmlContentTest {
assertEquals("en", props.get("jcr:title", String.class));
assertEquals(true, props.get("includeAside", false));
- assertEquals((Long)1234567890123L, props.get("longProp", Long.class));
+ assertEquals((Long) 1234567890123L, props.get("longProp", Long.class));
assertEquals(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));
+ assertArrayEquals(new String[] {"aa", "bb", "cc"}, props.get("stringPropMulti", String[].class));
+ assertArrayEquals(new Long[] {1234567890123L, 55L}, props.get("longPropMulti", Long[].class));
}
@Test
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 002a542..bd753c3 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/JsonContentTest.java
@@ -18,23 +18,6 @@
*/
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.hamcrest.MatcherAssert.assertThat;
-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.assertTrue;
-
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PropertyIterator;
@@ -43,6 +26,15 @@ import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.nodetype.NodeType;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
@@ -57,8 +49,15 @@ import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFile;
+import static org.apache.sling.fsprovider.internal.TestUtils.assertFolder;
+import static org.hamcrest.MatcherAssert.assertThat;
+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.assertTrue;
/**
* Test access to files and folders and JSON content from file system.
@@ -71,11 +70,12 @@ public class JsonContentTest {
@Rule
public SlingContext context = new SlingContextBuilder(ResourceResolverType.JCR_MOCK)
- .plugin(new RegisterFsResourcePlugin(
- "provider.fs.mode", FsMode.INITIAL_CONTENT.name(),
- "provider.initial.content.import.options", "overwrite:=true;ignoreImportProviders:=jcr.xml"
- ))
- .build();
+ .plugin(new RegisterFsResourcePlugin(
+ "provider.fs.mode",
+ FsMode.INITIAL_CONTENT.name(),
+ "provider.initial.content.import.options",
+ "overwrite:=true;ignoreImportProviders:=jcr.xml"))
+ .build();
@Before
public void setUp() {
@@ -104,11 +104,22 @@ public class JsonContentTest {
public void testListChildren() {
assertThat(root, ResourceMatchers.containsChildren("fs-test"));
assertThat(fsroot, ResourceMatchers.hasChildren("folder1", "folder2"));
- assertThat(fsroot.getChild("folder1"), ResourceMatchers.containsChildren("file1a.txt", "folder11", "sling:file1b.txt"));
+ assertThat(
+ fsroot.getChild("folder1"),
+ ResourceMatchers.containsChildren("file1a.txt", "folder11", "sling:file1b.txt"));
assertThat(fsroot.getChild("folder2"), ResourceMatchers.containsChildren("content", "folder21"));
- assertThat(fsroot.getChild("folder2/content"), ResourceMatchers.containsChildren(
- "jcr:content", "toolbar", "child", "file2content.txt", "fileWithOverwrittenMimeType.scss", "sling:content2"));
- assertThat(fsroot.getChild("folder2/content/child"), ResourceMatchers.containsChildren("jcr:content", "grandchild"));
+ assertThat(
+ fsroot.getChild("folder2/content"),
+ ResourceMatchers.containsChildren(
+ "jcr:content",
+ "toolbar",
+ "child",
+ "file2content.txt",
+ "fileWithOverwrittenMimeType.scss",
+ "sling:content2"));
+ assertThat(
+ fsroot.getChild("folder2/content/child"),
+ ResourceMatchers.containsChildren("jcr:content", "grandchild"));
}
@Test
@@ -127,7 +138,9 @@ public class JsonContentTest {
assertEquals("app:PageContent", underTest.getValueMap().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"));
+ assertThat(
+ underTest,
+ ResourceMatchers.hasChildren("par", "header", "newslist", "lead", "image", "carousel", "rightpar"));
}
@Test
@@ -145,12 +158,12 @@ public class JsonContentTest {
assertEquals("Profiles", props.get("jcr:title", String.class));
assertEquals(true, props.get("booleanProp", false));
- assertEquals((Long)1234567890123L, props.get("longProp", Long.class));
+ assertEquals((Long) 1234567890123L, props.get("longProp", Long.class));
assertEquals(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));
+ assertArrayEquals(new String[] {"aa", "bb", "cc"}, props.get("stringPropMulti", String[].class));
+ assertArrayEquals(new Long[] {1234567890123L, 55L}, props.get("longPropMulti", Long[].class));
}
@Test
@@ -163,14 +176,17 @@ public class JsonContentTest {
assertEquals(6, node.getDepth());
assertTrue(node.hasProperty(JcrConstants.JCR_PRIMARYTYPE));
- assertTrue(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getDefinition().isProtected());
+ assertTrue(
+ node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getDefinition().isProtected());
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());
assertFalse(node.getProperty("jcr:title").getDefinition().isProtected());
- assertEquals("/fs-test/folder2/content/toolbar/profiles/jcr:content/jcr:title", node.getProperty("jcr:title").getPath());
+ 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());
@@ -217,9 +233,9 @@ public class JsonContentTest {
assertEquals(7, rightpar.getDepth());
Node parent = rightpar.getParent();
assertTrue(node.isSame(parent));
- Node ancestor = (Node)rightpar.getAncestor(5);
+ Node ancestor = (Node) rightpar.getAncestor(5);
assertEquals(underTest.getParent().getPath(), ancestor.getPath());
- Node root = (Node)rightpar.getAncestor(0);
+ Node root = (Node) rightpar.getAncestor(0);
assertEquals("/", root.getPath());
// node types
@@ -237,7 +253,9 @@ public class JsonContentTest {
@Test
public void testFallbackNodeType() throws RepositoryException {
Resource underTest = fsroot.getChild("folder2/content/jcr:content/par/title_2");
- assertEquals(ParserOptions.DEFAULT_PRIMARY_TYPE, underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
+ assertEquals(
+ ParserOptions.DEFAULT_PRIMARY_TYPE,
+ underTest.adaptTo(Node.class).getPrimaryNodeType().getName());
}
@Test
@@ -283,13 +301,14 @@ public class JsonContentTest {
assertEquals("nt:file", props.get("jcr:primaryType", String.class));
assertEquals("/my/super/type", props.get("sling:resourceSuperType", String.class));
assertEquals("en", props.get("jcr:language", String.class));
- assertArrayEquals(new String[] { "mix:language" }, props.get("jcr:mixinTypes", String[].class));
+ assertArrayEquals(new String[] {"mix:language"}, props.get("jcr:mixinTypes", String[].class));
assertNull(fsroot.getChild("folder2/folder21/file21a.txt.xml"));
Node node = file21a.adaptTo(Node.class);
assertNotNull(node);
- assertEquals("/my/super/type", node.getProperty("sling:resourceSuperType").getString());
+ assertEquals(
+ "/my/super/type", node.getProperty("sling:resourceSuperType").getString());
assertEquals("en", node.getProperty("jcr:language").getString());
}
@@ -314,20 +333,23 @@ public class JsonContentTest {
assertEquals("Profiles", profilesTitle);
}
- @Test @Ignore
+ @Test
+ @Ignore
public void testFileHasJcrContentAndData() {
Resource underTest = fsroot.getChild("folder2/content/file2content.txt");
assertNotNull("failed adapting file2content.txt to InputStream", underTest.adaptTo(InputStream.class));
- //assertThat(underTest, ResourceMatchers.hasChildren("jcr:content"));
+ // assertThat(underTest, ResourceMatchers.hasChildren("jcr:content"));
Resource content = underTest.getChild("jcr:content");
ValueMap props = content.getValueMap();
assertNotNull("jcr:data is missing", props.get("jcr:data", InputStream.class));
}
- @Test @Ignore
+ @Test
+ @Ignore
public void testFileWithOverwrittenMimeType() {
Resource underTest = fsroot.getChild("folder2/content/fileWithOverwrittenMimeType.scss");
- assertNotNull("failed adapting fileWithOverwrittenMimeType.scss to InputStream",
+ assertNotNull(
+ "failed adapting fileWithOverwrittenMimeType.scss to InputStream",
underTest.adaptTo(InputStream.class));
Resource content = underTest.getChild("jcr:content");
ValueMap props = content.getValueMap();
diff --git a/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java b/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java
index f1c6272..f8ac49b 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/ResourcePathComparator.java
@@ -28,5 +28,4 @@ class ResourcePathComparator implements Comparator<Resource> {
public int compare(Resource o1, Resource o2) {
return o1.getPath().compareTo(o2.getPath());
}
-
}
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 b3acb49..e3701ac 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/TestUtils.java
@@ -18,12 +18,6 @@
*/
package org.apache.sling.fsprovider.internal;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -47,17 +41,25 @@ import org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin;
import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
import org.jetbrains.annotations.NotNull;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
@SuppressWarnings("null")
class TestUtils {
public static class RegisterFsResourcePlugin extends AbstractContextPlugin<SlingContextImpl> {
- private final Map<String,Object> props;
+ 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<>();
+ Map<String, Object> config = new HashMap<>();
config.put("provider.file", "src/test/resources/fs-test");
config.put("provider.root", "/fs-test");
config.put("provider.checkinterval", 0);
@@ -65,7 +67,8 @@ class TestUtils {
config.putAll(props);
context.registerInjectActivateService(new FsResourceProvider(), config);
}
- };
+ }
+ ;
public static void assertFolder(Resource resource, String path) {
Resource folder = resource.getChild(path);
@@ -87,7 +90,9 @@ class TestUtils {
assertEquals("nt:file", file.getResourceType());
assertNull(file.getResourceSuperType());
- assertEquals(file.getName(), Escape.fileToResourceName(file.adaptTo(File.class).getName()));
+ assertEquals(
+ file.getName(),
+ Escape.fileToResourceName(file.adaptTo(File.class).getName()));
if (content != null) {
try {
@@ -95,8 +100,7 @@ class TestUtils {
String data = IOUtils.toString(is, StandardCharsets.UTF_8);
assertEquals(content, data);
}
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new RuntimeException(ex);
}
}
@@ -115,13 +119,14 @@ class TestUtils {
public static class ResourceListener implements ResourceChangeListener {
private final List<ResourceChange> allChanges = new ArrayList<>();
+
@Override
public void onChange(@NotNull List<ResourceChange> changes) {
allChanges.addAll(changes);
}
+
public List<ResourceChange> getChanges() {
return allChanges;
}
}
-
}
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 f51dcb3..63e12b8 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
@@ -18,11 +18,6 @@
*/
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 org.apache.sling.api.resource.ValueMap;
@@ -30,6 +25,11 @@ import org.apache.sling.fsprovider.internal.parser.ContentElement;
import org.apache.sling.fsprovider.internal.parser.ContentFileCache;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
public class ContentFileTest {
private ContentFileCache contentFileCache = new ContentFileCache(0);
@@ -46,7 +46,9 @@ public class ContentFileTest {
ContentElement content = underTest.getContent();
assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
- assertEquals("app:PageContent", content.getChild("jcr: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"));
@@ -74,7 +76,8 @@ public class ContentFileTest {
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);
+ 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());
@@ -91,7 +94,8 @@ public class ContentFileTest {
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);
+ 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());
@@ -104,5 +108,4 @@ public class ContentFileTest {
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/EscapeTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/EscapeTest.java
index a44bda4..1111b4c 100644
--- a/src/test/java/org/apache/sling/fsprovider/internal/mapper/EscapeTest.java
+++ b/src/test/java/org/apache/sling/fsprovider/internal/mapper/EscapeTest.java
@@ -18,10 +18,10 @@
*/
package org.apache.sling.fsprovider.internal.mapper;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class EscapeTest {
@Test
@@ -42,5 +42,4 @@ public class EscapeTest {
assertEquals("a%3C%3E%3A%22/%5C%7C%3F*b", Escape.resourceToFileName("a<>:\"/\\|?*b"));
assertEquals("", Escape.resourceToFileName(""));
}
-
}
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
index ef48c38..fd1e64a 100644
--- 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
@@ -18,16 +18,16 @@
*/
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;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
/**
* This is copied from org.apache.sling.api.wrappers.impl.Convert
*/
@@ -39,7 +39,7 @@ final class Convert {
}
@SuppressWarnings("unchecked")
- public static class ConversionAssert<T,U> {
+ public static class ConversionAssert<T, U> {
private final T input1;
private final T input2;
private Class<T> inputType;
@@ -51,18 +51,18 @@ final class Convert {
private ConversionAssert(T input1, T input2, boolean inputTypePrimitive) {
this.input1 = input1;
this.input2 = input2;
- this.inputType = (Class<T>)input1.getClass();
+ this.inputType = (Class<T>) input1.getClass();
if (inputTypePrimitive) {
- this.inputType = (Class<T>)ClassUtils.wrapperToPrimitive(this.inputType);
+ 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();
+ this.expectedType = (Class<U>) expected1.getClass();
if (expectedTypePrimitive) {
- expectedType = (Class<U>)ClassUtils.wrapperToPrimitive(this.expectedType);
+ expectedType = (Class<U>) ClassUtils.wrapperToPrimitive(this.expectedType);
}
}
@@ -71,7 +71,7 @@ final class Convert {
* @param expected2 Second array expected result value
* @return this
*/
- public ConversionAssert<T,U> to(U expected1, U expected2) {
+ public ConversionAssert<T, U> to(U expected1, U expected2) {
expected(expected1, expected2, false);
return this;
}
@@ -81,7 +81,7 @@ final class Convert {
* @param expected2 Second array expected result value
* @return this
*/
- public ConversionAssert<T,U> toPrimitive(U expected1, U expected2) {
+ public ConversionAssert<T, U> toPrimitive(U expected1, U expected2) {
expected(expected1, expected2, true);
return this;
}
@@ -91,7 +91,7 @@ final class Convert {
* @param expected2 Second array expected result value
* @return this
*/
- public ConversionAssert<T,U> toNull(Class<U> expectedType) {
+ public ConversionAssert<T, U> toNull(Class<U> expectedType) {
expected1 = null;
expected2 = null;
this.expectedType = expectedType;
@@ -101,7 +101,7 @@ final class Convert {
/**
* @param nullValue Result value in case of null
*/
- public ConversionAssert<T,U> nullValue(U nullValue) {
+ public ConversionAssert<T, U> nullValue(U nullValue) {
this.nullValue = nullValue;
return this;
}
@@ -110,8 +110,10 @@ final class Convert {
* 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);
+ Class<U[]> expectedArrayType =
+ (Class<U[]>) Array.newInstance(this.expectedType, 0).getClass();
+ assertPermuations(
+ input1, input2, inputType, expected1, expected2, nullValue, expectedType, expectedArrayType);
}
}
@@ -119,20 +121,27 @@ final class Convert {
* @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);
+ 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);
+ 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) {
+ 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);
@@ -141,8 +150,7 @@ final class Convert {
Object expectedSingletonArray;
if (expected1 == null && expected2 == null) {
expectedSingletonArray = Array.newInstance(expectedType, 0);
- }
- else {
+ } else {
expectedSingletonArray = Array.newInstance(expectedType, 1);
Array.set(expectedSingletonArray, 0, expected1);
}
@@ -155,11 +163,10 @@ final class Convert {
Object expectedDoubleArray;
if (expected1 == null && expected2 == null) {
expectedDoubleArray = Array.newInstance(expectedType, 0);
- }
- else {
+ } else {
expectedDoubleArray = Array.newInstance(expectedType, 2);
- Array.set(expectedDoubleArray, 0, expected1);
- Array.set(expectedDoubleArray, 1, expected2);
+ Array.set(expectedDoubleArray, 0, expected1);
+ Array.set(expectedDoubleArray, 1, expected2);
}
assertConversion(expectedDoubleArray, inputDoubleArray, expectedArrayType);
@@ -182,16 +189,14 @@ final class Convert {
}
@SuppressWarnings("unchecked")
- private static <T,U> void assertConversion(Object expected, Object input, Class<U> type) {
+ 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 {
+ } else if (expected.getClass().isArray()) {
+ assertArrayEquals(msg, (U[]) toStringIfDate(expected), (U[]) toStringIfDate(result));
+ } else {
assertEquals(msg, toStringIfDate(expected), toStringIfDate(result));
}
}
@@ -199,11 +204,10 @@ final class Convert {
private static String toString(Object input) {
if (input == null) {
return "null";
- }
- else if (input.getClass().isArray()) {
+ } else if (input.getClass().isArray()) {
StringBuilder sb = new StringBuilder();
sb.append("[");
- for (int i=0; i<Array.getLength(input); i++) {
+ for (int i = 0; i < Array.getLength(input); i++) {
if (i > 0) {
sb.append(",");
}
@@ -211,8 +215,7 @@ final class Convert {
}
sb.append("]");
return sb.toString();
- }
- else {
+ } else {
return toStringIfDate(input).toString();
}
}
@@ -222,16 +225,16 @@ final class Convert {
return null;
}
if (input instanceof Calendar) {
- return "(Calendar)" + DateUtils.calendarToString((Calendar)input);
+ return "(Calendar)" + DateUtils.calendarToString((Calendar) input);
}
if (input instanceof Date) {
- return "(Date)" + DateUtils.dateToString((Date)input);
+ 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++) {
+ for (int i = 0; i < Array.getLength(input); i++) {
resultArray[i] = toStringIfDate(Array.get(input, i));
}
return resultArray;
@@ -239,5 +242,4 @@ final class Convert {
}
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
index a0a46f8..c43f35f 100644
--- 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
@@ -18,12 +18,6 @@
*/
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;
@@ -32,6 +26,12 @@ import java.util.TimeZone;
import org.junit.Test;
+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;
+
/**
* This is copied from org.apache.sling.api.wrappers.impl.ObjectConverterTest
*/
@@ -41,10 +41,10 @@ public class ObjectConverterTest {
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 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;
@@ -57,177 +57,252 @@ public class ObjectConverterTest {
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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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();
+ 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 };
+ 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
index f432b6f..0c7c6ce 100644
--- 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
@@ -44,10 +44,16 @@ public class ValueMapDecoratorTest {
// SLING-4178
@Test
public void testIncompatibleTypeInArray() {
- map.put("prop1", new String[] { "test", "test2" });
+ 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));
+ 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
@@ -57,29 +63,35 @@ public class ValueMapDecoratorTest {
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));
+ 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));
+ 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" },
+ 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));
+ 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),
+ 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));
}
@@ -91,14 +103,17 @@ public class ValueMapDecoratorTest {
@Test
public void testPrimitiveTypes() {
- map.put("prop1", new String[] { "1", "2" });
+ 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)
+
+ @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));
+ 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
@@ -106,13 +121,17 @@ public class ValueMapDecoratorTest {
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(),
+ 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(),
+ Assert.assertEquals(
+ "Two equal ValueMapDecorators should have the same hash code",
+ valueMap.hashCode(),
valueMap3.hashCode());
Assert.assertEquals(map, valueMap);
@@ -122,16 +141,20 @@ public class ValueMapDecoratorTest {
@Ignore("SLING-4784")
@Test
public void testEqualsAndHashCodeOfEqualValueMapsWithArrayTypes() {
- map.put("prop1", new String[] { "1", "2" });
+ 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(),
+ 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" });
+ valueMap3.put("prop1", new String[] {"1", "2"});
Assert.assertEquals(valueMap, valueMap3);
- Assert.assertEquals("Two equal ValueMapDecorators should have the same hash code", valueMap.hashCode(),
+ Assert.assertEquals(
+ "Two equal ValueMapDecorators should have the same hash code",
+ valueMap.hashCode(),
valueMap3.hashCode());
}
@@ -140,18 +163,18 @@ public class ValueMapDecoratorTest {
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",
+ 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" });
+ 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",
+ 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/valuemap/ValueMapUtilTest.java b/src/test/java/org/apache/sling/fsprovider/internal/mapper/valuemap/ValueMapUtilTest.java
index 048927c..c64932c 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
@@ -18,34 +18,32 @@
*/
package org.apache.sling.fsprovider.internal.mapper.valuemap;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
import java.util.HashMap;
import java.util.Map;
+import com.google.common.collect.ImmutableList;
import org.apache.sling.api.resource.ValueMap;
import org.junit.Test;
-import com.google.common.collect.ImmutableList;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
public class ValueMapUtilTest {
@Test
public void testToValueMap() {
- Map<String,Object> content = new HashMap<>();
+ Map<String, Object> content = new HashMap<>();
content.put("stringProp", "abc");
content.put("intProp", 123);
- content.put("stringArray", new String[] { "a", "b", "c" });
+ 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));
- 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));
+ assertEquals((Integer) 123, props.get("intProp", 0));
+ 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 07d739e..bde327f 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
@@ -18,10 +18,6 @@
*/
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 org.junit.experimental.theories.DataPoint;
@@ -29,13 +25,19 @@ import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
@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;
@@ -43,49 +45,50 @@ public class ContentFileCacheTest {
public void testCache(int cacheSize) {
ContentFileCache underTest = new ContentFileCache(cacheSize);
- ContentElement 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) {
- case NO_CACHE:
- assertEquals(0, underTest.size());
- break;
- case SMALL_CACHE:
- case HUGE_CACHE:
- assertEquals(1, underTest.size());
- break;
+ case NO_CACHE:
+ assertEquals(0, underTest.size());
+ break;
+ case SMALL_CACHE:
+ case HUGE_CACHE:
+ assertEquals(1, underTest.size());
+ break;
}
- ContentElement 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) {
- case NO_CACHE:
- assertEquals(0, underTest.size());
- break;
- case SMALL_CACHE:
- assertEquals(1, underTest.size());
- break;
- case HUGE_CACHE:
- assertEquals(2, underTest.size());
- break;
+ 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;
+ 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/ContentFileParserUtilTest.java b/src/test/java/org/apache/sling/fsprovider/internal/parser/ContentFileParserUtilTest.java
index 0d5671c..2cbfdf4 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
@@ -18,14 +18,14 @@
*/
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 org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
public class ContentFileParserUtilTest {
@Test
@@ -34,7 +34,9 @@ public class ContentFileParserUtilTest {
ContentElement content = ContentFileParserUtil.parse(file);
assertNotNull(content);
assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
- assertEquals("app:PageContent", content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
+ assertEquals(
+ "app:PageContent",
+ content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
}
@Test
@@ -50,7 +52,9 @@ public class ContentFileParserUtilTest {
ContentElement content = ContentFileParserUtil.parse(file);
assertNotNull(content);
assertEquals("app:Page", content.getProperties().get("jcr:primaryType"));
- assertEquals("app:PageContent", content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
+ assertEquals(
+ "app:PageContent",
+ content.getChild("jcr:content").getProperties().get("jcr:primaryType"));
}
@Test
@@ -67,5 +71,4 @@ public class ContentFileParserUtilTest {
assertNotNull(content);
assertEquals("sling:OrderedFolder", content.getProperties().get("jcr:primaryType"));
}
-
}
(sling-org-apache-sling-fsresource) 01/02: SLING-12677 Update to parent 62
Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/parent-62
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-fsresource.git
commit e4b3bb27ee5824e4da6289654f74da68f926a7c1
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Feb 26 10:50:20 2025 +0100
SLING-12677 Update to parent 62
---
.sling-module.json | 5 +++++
pom.xml | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/.sling-module.json b/.sling-module.json
new file mode 100644
index 0000000..cfad4d2
--- /dev/null
+++ b/.sling-module.json
@@ -0,0 +1,5 @@
+{
+ "jenkins": {
+ "jdks": [17, 21]
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index dd21747..3452c58 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling-bundle-parent</artifactId>
- <version>52</version>
+ <version>62</version>
<relativePath />
</parent>
@@ -42,6 +42,7 @@
</scm>
<properties>
+ <sling.java.version>8</sling.java.version>
<project.build.outputTimestamp>2021-08-30T16:40:10Z</project.build.outputTimestamp>
</properties>
@@ -50,7 +51,6 @@
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>sling-maven-plugin</artifactId>
- <version>3.0.2</version>
<executions>
<execution>
<id>generate-adapter-metadata</id>