You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:23:42 UTC
[sling-org-apache-sling-resourcecollection] branch master created
(now 27cd97f)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git.
at 27cd97f SLING-7167 Adjust READMEs
This branch includes the following new commits:
new a375e81 SLING-2853 Commit patch 4 by Amit Gupta (Thanks alot)
new 8a4ed62 SLING-2853 - nitpicks
new 024a84c SLING-2853 - remove unused dependencies
new d1cedf8 SLING-2853 - simplify tests
new a31ff55 SLING-2853 - missing license header
new b743956 SLING-2853 - tweak javadocs
new 81925af SLING-2853 : Simplify resource type setting
new f72bcc8 Revert wrong change from revision 1479549
new 6ba70ec SLING-2853 : Add ResourceCollection to Sling - use resource resolver mock
new 17a0a8a SLING-2857 : Fix the name of the members resource in ResourceCollection., Apply patch from Amit Gupta
new f334558 SLING-2857 : Fix the name of the members resource in ResourceCollection., Apply patch from Amit Gupta
new 9622071 SLING-2860 : Make ResourceCollectionManager an OSGi service
new 5fc85fa SLING-2860 : Make ResourceCollectionManager an OSGi service
new 1521cee Update to latest parent pom
new dee4bf4 Fix scm location
new d2aa459 SLING-2854 : Move the ResourceCollectionUtil.createUniqueChildName method to ResourceUtils
new 80cc223 Update to parent pom 18
new c37dd5b Use relesed version of sling.api (2.6.0 is required)
new b8cc0db [maven-release-plugin] prepare release org.apache.sling.resourcecollection-1.0.0
new f8ca373 [maven-release-plugin] prepare for next development iteration
new fc06ee4 Update to parent pom v19
new c4b05f4 Update to latest parent pom 20
new d361178 Update to Sling Parent POM 22 with baselining enabled
new 9fbad36 SLING-4698 - Set parent.relativePath to empty for all modules
new 14f1017 Update contrib modules to Parent 23
new b081577 set parent version to 24 and add empty relativePath where missing
new 1d99ebb Update the contrib reactor to parent 25
new fa1d21e Switch to parent pom 26
new ffbed0c SLING-7040 : Update commons lang 2.x to 3.5
new ad508f5 SLING-7040 : Update commons lang 2.x to 3.5
new 27cd97f SLING-7167 Adjust READMEs
The 31 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].
[sling-org-apache-sling-resourcecollection] 06/31: SLING-2853 -
tweak javadocs
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit b7439569f26fea0217218fba5240e66e8a10ba75
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon May 6 09:05:30 2013 +0000
SLING-2853 - tweak javadocs
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479500 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/sling/resource/collection/ResourceCollection.java | 11 ++++++-----
.../sling/resource/collection/ResourceCollectionManager.java | 5 ++---
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
index b1a4f6f..ad0b257 100755
--- a/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.sling.resource.collection;
import java.util.Iterator;
import java.util.Map;
@@ -27,10 +26,13 @@ import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
/**
- * ResourceCollection is an ordered collection of resources. Actual resources are not stored inside the collection.
+ * ResourceCollection is an ordered collection of {@link Resource}.
+ * The collection does not store the actual Resources, it only points to
+ * them.
*
- * Each entry in a collection is represented as a resource, which contain a reference to original resource
- * and it can have additional properties i.e. creationDate.
+ * Each entry in the collection is represented by a Resource which contains a
+ * reference to original resource. That reference Resource can have additional
+ * properties (creationDate, etc.)
*/
public interface ResourceCollection {
@@ -76,7 +78,6 @@ public interface ResourceCollection {
*/
boolean contains(Resource resource);
-
/**
* Creates a new entry in the collection at the last position and add a reference to resource
* in the entry.
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
index 290e6d7..d6c4093 100755
--- a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.sling.resource.collection;
import java.util.Map;
@@ -28,9 +27,9 @@ import org.apache.sling.api.resource.ResourceResolver;
/**
* The <code>ResourceCollectionManager<code> defines the API to get, create and delete
- * resource collection {@link org.apache.sling.resource.collection.ResourceCollection}.
+ * resource collections {@link org.apache.sling.resource.collection.ResourceCollection}.
*
- * A ResourceCollectionManager instance can be retrieved by adapting ResourceResolver.
+ * A ResourceCollectionManager instance can be retrieved by adapting a {@link ResourceResolver}.
*/
public interface ResourceCollectionManager {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 10/31: SLING-2857 : Fix
the name of the members resource in ResourceCollection.,
Apply patch from Amit Gupta
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 17a0a8a677c4783262aa2e631a1d8e9a6a2790dd
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 7 06:09:02 2013 +0000
SLING-2857 : Fix the name of the members resource in ResourceCollection., Apply patch from Amit Gupta
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479769 13f79535-47bb-0310-9956-ffa450edef68
---
.../collection/impl/ResourceCollectionImpl.java | 40 +++++++++-------------
.../impl/ResourceCollectionManagerImpl.java | 7 ++--
.../impl/ResourceCollectionImplTest.java | 18 ++++++++++
3 files changed, 38 insertions(+), 27 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
index ccf88a0..f1e937b 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
@@ -66,12 +66,6 @@ public class ResourceCollectionImpl implements
private final Resource membersResource;
- private static final String REF_PROPERTY = "sling:resource";
-
- private static final String MEMBERS_NODE_NAME = "members";
-
- private static final String REFERENCES_PROP = "sling:references";
-
/**
* Creates a new collection from the given resource
*
@@ -80,7 +74,7 @@ public class ResourceCollectionImpl implements
public ResourceCollectionImpl(Resource resource) {
this.resource = resource;
resolver = resource.getResourceResolver();
- membersResource = resource.getChild(MEMBERS_NODE_NAME);
+ membersResource = resource.getChild(ResourceCollectionConstants.MEMBERS_NODE_NAME);
}
/**
@@ -103,15 +97,15 @@ public class ResourceCollectionImpl implements
public boolean add(Resource res, Map<String, Object> properties) throws PersistenceException {
if (res != null && !contains(res)) {
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
- String[] order = vm.get(REFERENCES_PROP, new String[]{});
+ String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
order = (String[]) ArrayUtils.add(order, res.getPath());
- vm.put(REFERENCES_PROP, order);
+ vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
if (properties == null) {
properties = new HashMap<String, Object>();
}
- properties.put(REF_PROPERTY, res.getPath());
+ properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
resolver.create(
membersResource,
ResourceCollectionUtil.createUniqueChildName(membersResource,
@@ -130,13 +124,13 @@ public class ResourceCollectionImpl implements
public boolean add(Resource res) throws PersistenceException {
if (res != null && !contains(res)) {
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
- String[] order = vm.get(REFERENCES_PROP, new String[]{});
+ String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
order = (String[]) ArrayUtils.add(order, res.getPath());
- vm.put(REFERENCES_PROP, order);
+ vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(REF_PROPERTY, res.getPath());
+ properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
resolver.create(
membersResource,
ResourceCollectionUtil.createUniqueChildName(membersResource,
@@ -157,7 +151,7 @@ public class ResourceCollectionImpl implements
public Iterator<Resource> getResources() {
ValueMap vm = membersResource.adaptTo(ValueMap.class);
- String[] references = vm.get(REFERENCES_PROP, new String[]{});
+ String[] references = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
List<Resource> resources = new ArrayList<Resource>();
for (String path:references) {
@@ -186,7 +180,7 @@ public class ResourceCollectionImpl implements
public boolean contains(Resource res) {
if (res != null) {
ValueMap vm = membersResource.adaptTo(ValueMap.class);
- String[] order = vm.get(REFERENCES_PROP, new String[]{});
+ String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
int index = ArrayUtils.indexOf(order, res.getPath(), 0);
@@ -208,12 +202,12 @@ public class ResourceCollectionImpl implements
resolver.delete(tobeRemovedRes);
//remove from order array
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
- String[] order = vm.get(REFERENCES_PROP, new String[]{});
+ String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
int index = ArrayUtils.indexOf(order, res.getPath(), 0);
order = (String[]) ArrayUtils.remove(order, index);
- vm.put(REFERENCES_PROP, order);
+ vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
return true;
}
@@ -234,13 +228,13 @@ public class ResourceCollectionImpl implements
String resName = res.getName();
if (membersResource.getChild(resName) != null
&& (res.getPath()).equals(ResourceUtil.getValueMap(
- membersResource.getChild(resName)).get(REF_PROPERTY, "")))
+ membersResource.getChild(resName)).get(ResourceCollectionConstants.REF_PROPERTY, "")))
return membersResource.getChild(resName);
// handle multiple res with same name but different paths
Iterator<Resource> children = membersResource.listChildren();
while (children.hasNext()) {
Resource r = children.next();
- if (ResourceUtil.getValueMap(r).get(REF_PROPERTY, "").equals(
+ if (ResourceUtil.getValueMap(r).get(ResourceCollectionConstants.REF_PROPERTY, "").equals(
res.getPath())) return r;
}
}
@@ -252,7 +246,7 @@ public class ResourceCollectionImpl implements
throw new IllegalArgumentException("Source Resource can not be null");
}
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
- String[] order = vm.get(REFERENCES_PROP, new String[]{});
+ String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
String srcPath = srcResource.getPath();
int srcIndex = ArrayUtils.indexOf(order, srcPath);
if (srcIndex < 0) {
@@ -268,7 +262,7 @@ public class ResourceCollectionImpl implements
String destPath = destResource.getPath();
if (destPath.equals(srcPath)) {
- String message = MessageFormat.format("Collection ordering failed, as source {} and destination {} can not be same",
+ String message = MessageFormat.format("Collection ordering failed, as source {0} and destination {1} can not be same",
srcPath, destPath);
log.error(message);
throw new IllegalArgumentException(message);
@@ -289,7 +283,7 @@ public class ResourceCollectionImpl implements
order = (String[]) ArrayUtils.add(order, destIndex, srcPath);
}
- vm.put(REFERENCES_PROP, order);
+ vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
}
public ModifiableValueMap getProperties(Resource resource) {
@@ -297,7 +291,7 @@ public class ResourceCollectionImpl implements
while (entries.hasNext()) {
Resource entry = entries.next();
String path = ResourceUtil.getValueMap(entry).get(
- REF_PROPERTY, "");
+ ResourceCollectionConstants.REF_PROPERTY, "");
if (resource.getPath().equals(path)) {
return entry.adaptTo(ModifiableValueMap.class);
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
index 450bc7c..4518bf2 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -78,7 +78,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
Map<String, Object> properties) throws PersistenceException {
if (parentResource != null) {
- String fullPath = parentResource.getPath() + name;
+ String fullPath = parentResource.getPath() + "/" + name;
if (resolver.getResource(fullPath) != null) {
throw new IllegalArgumentException("invalid path, " + fullPath
@@ -100,11 +100,10 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
ResourceCollection.RESOURCE_TYPE);
}
Resource collectionRes = resolver.create(parentResource, name, properties);
- resolver.create(collectionRes, "members", null);
+ resolver.create(collectionRes, ResourceCollectionConstants.MEMBERS_NODE_NAME, null);
log.debug("collection {} created", fullPath);
- return new ResourceCollectionImpl(
- resolver.getResource(collectionRes.getPath()));
+ return new ResourceCollectionImpl(collectionRes);
} else {
log.error("parent resource can not be null");
throw new IllegalArgumentException("parent resource can not be null ");
diff --git a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
index d722c3a..dd6b03d 100755
--- a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
+++ b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
@@ -76,6 +76,17 @@ public class ResourceCollectionImplTest {
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
}
+
+ @Test
+ public void testCheckPath() throws Exception {
+ final Resource rootResource = resResolver.create(resResolver.getResource("/"), "root",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+
+ final ResourceCollection collection = rcm.createCollection(rootResource, "test1");
+
+
+ Assert.assertEquals(rootResource.getPath() + "/" + "test1", collection.getPath());
+ }
@Test
public void testGetCollection() throws Exception {
@@ -187,6 +198,13 @@ public class ResourceCollectionImplTest {
Assert.assertEquals(resPaths[numOfRes], entry.getPath());
numOfRes ++;
}
+
+ try {
+ collection.orderBefore(resource, resource);
+ Assert.fail("should have thrown IllegalArgument");
+ } catch (IllegalArgumentException e) {
+
+ }
//change the order
collection.orderBefore(resource2, resource);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 31/31: SLING-7167
Adjust READMEs
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 27cd97f79594fde1697551658e54b4140d327cc0
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Oct 3 09:27:44 2017 +0000
SLING-7167 Adjust READMEs
add missing README
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1810729 13f79535-47bb-0310-9956-ffa450edef68
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..814e956
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Apache Sling Resource Collection API
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 01/31: SLING-2853
Commit patch 4 by Amit Gupta (Thanks alot)
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit a375e816d26ca3ff1dcc231599a924a116aa1844
Author: Felix Meschberger <fm...@apache.org>
AuthorDate: Mon May 6 07:30:46 2013 +0000
SLING-2853 Commit patch 4 by Amit Gupta (Thanks alot)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479479 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 155 +++++++++++
.../resource/collection/ResourceCollection.java | 130 +++++++++
.../collection/ResourceCollectionManager.java | 93 +++++++
.../impl/ResourceCollectionAdapterFactory.java | 103 +++++++
.../collection/impl/ResourceCollectionImpl.java | 309 +++++++++++++++++++++
.../impl/ResourceCollectionManagerImpl.java | 138 +++++++++
.../impl/util/ResourceCollectionUtil.java | 49 ++++
.../impl/ResourceCollectionImplTest.java | 221 +++++++++++++++
.../resource/collection/test/MockResource.java | 104 +++++++
.../collection/test/MockResourceResolver.java | 249 +++++++++++++++++
10 files changed, 1551 insertions(+)
diff --git a/pom.xml b/pom.xml
new file mode 100755
index 0000000..2b066af
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,155 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <!-- ======================================================================= -->
+ <!-- P A R E N T P R O J E C T -->
+ <!-- ======================================================================= -->
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>15</version>
+ <relativePath>../../../parent/pom.xml</relativePath>
+ </parent>
+
+ <!-- ======================================================================= -->
+ <!-- P R O J E C T -->
+ <!-- ======================================================================= -->
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.resourcecollection</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Resource Collection API</name>
+ <description>
+ The Apache sling resource collection bundle provides an api to create collections of resources.
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/resourcecollection</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/resourcecollection</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/bundles/resourcecollection</url>
+ </scm>
+
+ <!-- ======================================================================= -->
+ <!-- B U I L D -->
+ <!-- ======================================================================= -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>maven-sling-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- ======================================================================= -->
+ <!-- D E P E N D E N C I E S -->
+ <!-- ======================================================================= -->
+ <dependencies>
+
+
+ <!-- sling -->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.3.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
+ <version>2.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.resource</artifactId>
+ <version>2.2.6</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- OSGI -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <!-- Felix -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>3.0.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
new file mode 100755
index 0000000..b1a4f6f
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.sling.resource.collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+
+/**
+ * ResourceCollection is an ordered collection of resources. Actual resources are not stored inside the collection.
+ *
+ * Each entry in a collection is represented as a resource, which contain a reference to original resource
+ * and it can have additional properties i.e. creationDate.
+ */
+public interface ResourceCollection {
+
+ /**
+ * Sling resource type for resource representing a </code>ResourceCollection<code>
+ */
+ public static final String RESOURCE_TYPE = "sling/collection";
+
+ /**
+ * Returns name of the collection.
+ *
+ * @return name of the collection.
+ */
+ public String getName();
+
+ /**
+ * Returns path of the collection.
+ *
+ * @return path of the collection.
+ */
+ public String getPath();
+
+ /**
+ * Returns an iterator over resources referred in the collection in the specified order.
+ *
+ * @return iterator over resources referred in collection.
+ */
+ Iterator<Resource> getResources();
+
+ /**
+ * Returns additional properties for a particular resource in Collection entry.
+ *
+ * @return properties of the Collection entry as <code>ModifiableValueMap</code>, returns null if entry found.
+ */
+ ModifiableValueMap getProperties(Resource resource);
+
+ /**
+ * Returns true if resource reference is part of the collection.
+ *
+ * @param resource resource to be checked
+ * @return true if resource is part of the collection.
+ * false otherwise
+ */
+ boolean contains(Resource resource);
+
+
+ /**
+ * Creates a new entry in the collection at the last position and add a reference to resource
+ * in the entry.
+ * Changes are transient & have to be saved by calling resolver.commit()
+ *
+ * @param resource resource to be added
+ * @param properties The additional properties to be stored with the collection entry (can be null).
+ * @return true if addition of resource to collection was successful or
+ * false if collection already contained the resource or resource is null.
+ *
+ * @throws {@link PersistenceException} if the operation fails
+ */
+ boolean add(Resource resource, Map<String, Object> properties) throws PersistenceException;
+
+ /**
+ * Creates a new entry in the collection at the last position and add a reference to resource
+ * in the entry.
+ * Changes are transient & have to be saved by calling resolver.commit()
+ *
+ * @param resource resource to be added
+ * @return true if addition of resource to collection was successful or
+ * false if collection already contained the resource or resource is null.
+ *
+ * @throws {@link PersistenceException} if the operation fails
+ */
+ boolean add(Resource resource) throws PersistenceException;
+
+
+ /**
+ * Removes a entry of resource from collection & returns true if successful.
+ * Changes are transient & have to be saved by calling resolver.commit()
+ *
+ * @param resource resource reference to be removed
+ * @return true if resource reference was successfully removed from the collection.
+ * false if not removed/not present
+ *
+ * @throws {@link PersistenceException} if the operation fails
+ */
+ boolean remove(Resource resource) throws PersistenceException;
+
+ /**
+ * This method inserts the referenced resource <code>srcResource</code>
+ * into the collection entry at the position immediately before the referenced resource <code>destResource</code>.
+ *
+ * To insert the referenced resource into last position, <code>destResource</code> can be null.
+ *
+ * @param srcResource Referenced resource that needs to be moved in the order
+ * @param destResource Referenced resource before which the <code>srcResource</code> will be placed.
+ */
+ void orderBefore(Resource srcResource, Resource destResource);
+}
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
new file mode 100755
index 0000000..290e6d7
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.sling.resource.collection;
+
+import java.util.Map;
+
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+
+/**
+ * The <code>ResourceCollectionManager<code> defines the API to get, create and delete
+ * resource collection {@link org.apache.sling.resource.collection.ResourceCollection}.
+ *
+ * A ResourceCollectionManager instance can be retrieved by adapting ResourceResolver.
+ */
+public interface ResourceCollectionManager {
+
+ /**
+ * This method returns a resource collection for the given <code>resource</code>
+ * that represents a {@link ResourceCollection}.
+ *
+ * It returns null if given resource is not a collection
+ *
+ * @param resource resource that represents a collection
+ * @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing the collection.
+ *
+ */
+ ResourceCollection getCollection(Resource resource);
+
+
+ /**
+ * This method creates a resource collection with a given name under the <code>parentResource</code>.
+ * The changes are transient and have to be saved by resourceResolver.commit()
+ *
+ * @param parentResource parent resource where collection needs to be created.
+ * @param name The name for collection.
+ *
+ * @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing the created collection.
+ *
+ * @throws {@link PersistenceException} if the operation fails
+ */
+ ResourceCollection createCollection(Resource parentResource, String name) throws PersistenceException;
+
+ /**
+ * This method creates a resource collection with a given name under the <code>parentResource</code>.
+ * The changes are transient and have to be saved by resourceResolver.commit()
+ *
+ * @param parentResource parent resource where collection needs to be created.
+ * @param name The name for collection.
+ * @param properties The additional data for resource collection
+ *
+ * @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing the created collection.
+ *
+ * @throws {@link PersistenceException} if the operation fails
+ */
+ ResourceCollection createCollection(Resource parentResource, String name, Map<String,Object> properties) throws PersistenceException;
+
+ /**
+ * Removes the {@link org.apache.sling.resource.collection.ResourceCollection} corresponding to the collection represented by
+ * <code>resource</code>.
+ * The changes are transient and have to be saved by resourceResolver.commit()
+ *
+ * @param resource resource representing a collection to be deleted.
+ * @return <code>true</code> if the collection was successfully removed.
+ *
+ * @throws {@link PersistenceException} if the operation fails
+ */
+ boolean deleteCollection(Resource resource) throws PersistenceException;
+
+ /**
+ * Returns the {@link ResourceResolver} from which this has been retrieved/adapted.
+ */
+ ResourceResolver getResourceResolver();
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
new file mode 100755
index 0000000..c7a2790
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.resource.collection.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.adapter.AdapterFactory;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.resource.collection.ResourceCollection;
+import org.apache.sling.resource.collection.ResourceCollectionManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AdapterFactory that adapts Resources to: {@link ResourceCollection}
+ * And ResourceResolver to: {@link ResourceCollectionManager)
+ */
+@Component(metatype = false)
+@Service
+@Property(name = "service.description", value = "Collection Adapter Factory")
+public class ResourceCollectionAdapterFactory implements AdapterFactory {
+
+ private static final Logger log = LoggerFactory.getLogger(ResourceCollectionAdapterFactory.class);
+
+ private static final Class<ResourceCollection> COLLECTION_CLASS = ResourceCollection.class;
+
+ private static final Class<ResourceCollectionManager> COLLECTION_MGR_CLASS = ResourceCollectionManager.class;
+
+ @Property(name = "adapters")
+ public static final String[] ADAPTER_CLASSES = {
+ COLLECTION_CLASS.getName(), COLLECTION_MGR_CLASS.getName()
+
+ };
+
+ @Property(name = "adaptables")
+ public static final String[] ADAPTABLE_CLASSES = {
+ Resource.class.getName(), ResourceResolver.class.getName()
+
+ };
+
+ // ---------- AdapterFactory -----------------------------------------------
+
+ public <AdapterType> AdapterType getAdapter(Object adaptable,
+ Class<AdapterType> type) {
+ if (adaptable instanceof Resource) {
+ return getAdapter((Resource) adaptable, type);
+ } else if (adaptable instanceof ResourceResolver) {
+ return getAdapter((ResourceResolver) adaptable, type);
+ } else {
+ log.warn("Unable to handle adaptable {}",
+ adaptable.getClass().getName());
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <AdapterType> AdapterType getAdapter(Resource resource,
+ Class<AdapterType> type) {
+ if (resource != null) {
+ if (type == COLLECTION_CLASS) {
+ if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
+ return (AdapterType) new ResourceCollectionImpl(resource);
+ }
+ }
+ log.debug("Unable to adapt resource of {} to type {}",
+ resource.getResourceType(), type.getName());
+
+ }
+ log.debug("Unable to adapt null resource to type {}", type.getName());
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <AdapterType> AdapterType getAdapter(ResourceResolver resolver,
+ Class<AdapterType> type) {
+ if (COLLECTION_MGR_CLASS == type) {
+ return (AdapterType) new ResourceCollectionManagerImpl(resolver);
+ } else {
+ log.warn("Unable to adapt resolver to requested type {}",
+ type.getName());
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
new file mode 100755
index 0000000..ccf88a0
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
@@ -0,0 +1,309 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.resource.collection.impl;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.sling.resource.collection.ResourceCollection;
+import org.apache.sling.resource.collection.impl.util.ResourceCollectionUtil;
+
+/**
+ * Implements <code>ResourceCollection</code>
+ *
+ */
+public class ResourceCollectionImpl implements
+ ResourceCollection {
+
+ private static final Logger log = LoggerFactory.getLogger(ResourceCollectionImpl.class);
+
+ /**
+ * Defines the resource type property
+ */
+ private static final String RESOURCE_TYPE = JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
+
+ /**
+ * underlying resource
+ */
+ private final Resource resource;
+
+ /**
+ * The resource resolver in use by the resource.
+ */
+ private final ResourceResolver resolver;
+
+ private final Resource membersResource;
+
+ private static final String REF_PROPERTY = "sling:resource";
+
+ private static final String MEMBERS_NODE_NAME = "members";
+
+ private static final String REFERENCES_PROP = "sling:references";
+
+ /**
+ * Creates a new collection from the given resource
+ *
+ * @param resource the resource
+ */
+ public ResourceCollectionImpl(Resource resource) {
+ this.resource = resource;
+ resolver = resource.getResourceResolver();
+ membersResource = resource.getChild(MEMBERS_NODE_NAME);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return resource.getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPath() {
+ return resource.getPath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean add(Resource res, Map<String, Object> properties) throws PersistenceException {
+ if (res != null && !contains(res)) {
+ ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
+ String[] order = vm.get(REFERENCES_PROP, new String[]{});
+
+ order = (String[]) ArrayUtils.add(order, res.getPath());
+ vm.put(REFERENCES_PROP, order);
+
+ if (properties == null) {
+ properties = new HashMap<String, Object>();
+ }
+ properties.put(REF_PROPERTY, res.getPath());
+ resolver.create(
+ membersResource,
+ ResourceCollectionUtil.createUniqueChildName(membersResource,
+ res.getName()), properties);
+ log.debug("added member to resource {} to collection {}",
+ new String[] { res.getPath(), resource.getPath() });
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean add(Resource res) throws PersistenceException {
+ if (res != null && !contains(res)) {
+ ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
+ String[] order = vm.get(REFERENCES_PROP, new String[]{});
+
+ order = (String[]) ArrayUtils.add(order, res.getPath());
+ vm.put(REFERENCES_PROP, order);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(REF_PROPERTY, res.getPath());
+ resolver.create(
+ membersResource,
+ ResourceCollectionUtil.createUniqueChildName(membersResource,
+ res.getName()), properties);
+ log.debug("added member to resource {} to collection {}",
+ new String[] { res.getPath(), resource.getPath() });
+ return true;
+ }
+
+ return false;
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Iterator<Resource> getResources() {
+
+ ValueMap vm = membersResource.adaptTo(ValueMap.class);
+ String[] references = vm.get(REFERENCES_PROP, new String[]{});
+ List<Resource> resources = new ArrayList<Resource>();
+
+ for (String path:references) {
+ Resource resource = resolver.getResource(path);
+ if (resource != null){
+ resources.add(resource);
+ }
+ }
+
+ return resources.iterator();
+ }
+
+ /**
+ * Returns the sling resource type on content node of collection
+ *
+ * @param
+ * @return <code>sling:resourceType</code> for the collection resource
+ */
+ public String getType() {
+ return resource.getResourceType();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean contains(Resource res) {
+ if (res != null) {
+ ValueMap vm = membersResource.adaptTo(ValueMap.class);
+ String[] order = vm.get(REFERENCES_PROP, new String[]{});
+
+ int index = ArrayUtils.indexOf(order, res.getPath(), 0);
+
+ return index >= 0 ? true: false;
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean remove(Resource res) throws PersistenceException {
+ //remove the resource
+ Resource tobeRemovedRes = findRes(res);
+ if (tobeRemovedRes == null) {
+ return false;
+ }
+ resolver.delete(tobeRemovedRes);
+ //remove from order array
+ ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
+ String[] order = vm.get(REFERENCES_PROP, new String[]{});
+
+ int index = ArrayUtils.indexOf(order, res.getPath(), 0);
+
+ order = (String[]) ArrayUtils.remove(order, index);
+ vm.put(REFERENCES_PROP, order);
+
+ return true;
+ }
+
+ /**
+ * Sets the sling resource type on content node of collection
+ *
+ * @param type <code>sling:resourceType</code> to be set on the content node
+ * @return
+ */
+ public void setType(String type) throws PersistenceException {
+ ModifiableValueMap mvp = resource.adaptTo(ModifiableValueMap.class);
+ mvp.put(RESOURCE_TYPE, type);
+ }
+
+ private Resource findRes(Resource res) {
+ if (res != null) {
+ String resName = res.getName();
+ if (membersResource.getChild(resName) != null
+ && (res.getPath()).equals(ResourceUtil.getValueMap(
+ membersResource.getChild(resName)).get(REF_PROPERTY, "")))
+ return membersResource.getChild(resName);
+ // handle multiple res with same name but different paths
+ Iterator<Resource> children = membersResource.listChildren();
+ while (children.hasNext()) {
+ Resource r = children.next();
+ if (ResourceUtil.getValueMap(r).get(REF_PROPERTY, "").equals(
+ res.getPath())) return r;
+ }
+ }
+ return null;
+ }
+
+ public void orderBefore(Resource srcResource, Resource destResource) {
+ if (srcResource == null) {
+ throw new IllegalArgumentException("Source Resource can not be null");
+ }
+ ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
+ String[] order = vm.get(REFERENCES_PROP, new String[]{});
+ String srcPath = srcResource.getPath();
+ int srcIndex = ArrayUtils.indexOf(order, srcPath);
+ if (srcIndex < 0) {
+ log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
+ srcPath, getPath());
+ return ;
+ }
+ if (destResource == null) {
+ //add it to the end.
+ order = (String[]) ArrayUtils.remove(order, srcIndex);
+ order = (String[]) ArrayUtils.add(order, srcPath);
+ } else {
+ String destPath = destResource.getPath();
+
+ if (destPath.equals(srcPath)) {
+ String message = MessageFormat.format("Collection ordering failed, as source {} and destination {} can not be same",
+ srcPath, destPath);
+ log.error(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ int destIndex = ArrayUtils.indexOf(order, destPath);
+
+ if (destIndex < 0) {
+ log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
+ destPath, getPath());
+ return;
+ }
+
+ order = (String[]) ArrayUtils.remove(order, srcIndex);
+ if (srcIndex < destIndex) { //recalculate dest index
+ destIndex = ArrayUtils.indexOf(order, destPath);
+ }
+ order = (String[]) ArrayUtils.add(order, destIndex, srcPath);
+ }
+
+ vm.put(REFERENCES_PROP, order);
+ }
+
+ public ModifiableValueMap getProperties(Resource resource) {
+ Iterator<Resource> entries = membersResource.listChildren();
+ while (entries.hasNext()) {
+ Resource entry = entries.next();
+ String path = ResourceUtil.getValueMap(entry).get(
+ REF_PROPERTY, "");
+
+ if (resource.getPath().equals(path)) {
+ return entry.adaptTo(ModifiableValueMap.class);
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
new file mode 100755
index 0000000..450bc7c
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.resource.collection.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.resource.collection.ResourceCollection;
+import org.apache.sling.resource.collection.ResourceCollectionManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * Implements <code>ResourceCollectionManger</code> interface. And provides
+ * create, delete, get apis for ResourceCollection.
+ *
+ * A ResourceCollectionManager instance can be retrieved by adapting ResourceResolver.
+ */
+public class ResourceCollectionManagerImpl implements ResourceCollectionManager {
+
+ private static final Logger log = LoggerFactory.getLogger(ResourceCollectionManager.class);
+
+ private final ResourceResolver resolver;
+
+ public ResourceCollectionManagerImpl(ResourceResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResourceCollection getCollection(Resource resource) {
+ if (resource != null) {
+ if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
+ return new ResourceCollectionImpl(resource);
+ }
+ } else {
+ throw new IllegalArgumentException("resource can not be null");
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResourceCollection createCollection(Resource parentResource, String name)
+ throws PersistenceException {
+ return createCollection(parentResource, name, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResourceCollection createCollection(Resource parentResource, String name,
+ Map<String, Object> properties) throws PersistenceException {
+
+ if (parentResource != null) {
+ String fullPath = parentResource.getPath() + name;
+
+ if (resolver.getResource(fullPath) != null) {
+ throw new IllegalArgumentException("invalid path, " + fullPath
+ + "resource already exists");
+ }
+
+ if (properties == null) {
+ properties = new HashMap<String, Object>();
+ }
+
+ if (properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY) != null
+ && !ResourceCollection.RESOURCE_TYPE.equals(properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY))) {
+ properties.put(
+ JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY,
+ ResourceCollection.RESOURCE_TYPE);
+ } else {
+ properties.put(
+ JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
+ ResourceCollection.RESOURCE_TYPE);
+ }
+ Resource collectionRes = resolver.create(parentResource, name, properties);
+ resolver.create(collectionRes, "members", null);
+ log.debug("collection {} created", fullPath);
+
+ return new ResourceCollectionImpl(
+ resolver.getResource(collectionRes.getPath()));
+ } else {
+ log.error("parent resource can not be null");
+ throw new IllegalArgumentException("parent resource can not be null ");
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws PersistenceException
+ */
+ public boolean deleteCollection(Resource resource)
+ throws PersistenceException {
+ if (resource != null) {
+ log.debug("collection {} deleted", resource.getPath());
+ resolver.delete(resource);
+ return true;
+ } else {
+ throw new IllegalArgumentException("resource can not be null");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ResourceResolver getResourceResolver() {
+ return resolver;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/util/ResourceCollectionUtil.java b/src/main/java/org/apache/sling/resource/collection/impl/util/ResourceCollectionUtil.java
new file mode 100755
index 0000000..2f56494
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/impl/util/ResourceCollectionUtil.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.resource.collection.impl.util;
+
+
+import org.apache.sling.api.resource.Resource;
+
+public class ResourceCollectionUtil {
+
+ /**
+ * Create a unique name for a child of the <code>resource</code>. Generates a unique name and test if child
+ * already exists. If name is already existing, iterate until a unique one is found
+ *
+ * @param resource parent resource
+ * @param name the name to check
+ * @return a unique label string
+ */
+ public static String createUniqueChildName(Resource resource, String name) {
+ if (resource.getChild(name)!=null) {
+ // leaf node already exists, create new unique name
+ String leafNodeName;
+ int i = 0;
+ do {
+ leafNodeName = name + String.valueOf(i);
+ i++;
+ } while (resource.getChild(leafNodeName)!=null);
+ return leafNodeName;
+ }
+ return name;
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
new file mode 100755
index 0000000..f37c207
--- /dev/null
+++ b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
@@ -0,0 +1,221 @@
+package org.apache.sling.resource.collection.impl;
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.resource.collection.ResourceCollection;
+import org.apache.sling.resource.collection.ResourceCollectionManager;
+import org.apache.sling.resource.collection.test.MockResource;
+import org.apache.sling.resource.collection.test.MockResourceResolver;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ResourceCollectionImplTest {
+ private ResourceResolver resResolver;
+
+ @Before
+ public void setUp() throws Exception {
+ resResolver = new MockResourceResolver();
+ //create some root resource
+ Resource resource = new MockResource(resResolver, "/", "type");
+
+ ((MockResourceResolver) resResolver).addResource(resource);
+ }
+
+ @Test
+ public void testAddResource() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+
+ Resource resource = new MockResource(resResolver, "/res1", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource);
+ resource = new MockResource(resResolver, "/res2", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource);
+
+ Assert.assertEquals(true, collection.contains(resource));
+
+ Assert.assertEquals(true, collection.contains(resource));
+ Assert.assertNotNull(resResolver.getResource("/test1"));
+ Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
+ }
+
+ @Test
+ public void testCreateCollection() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+
+ Resource resource = new MockResource(resResolver, "/res1", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+ resource = new MockResource(resResolver, "/res2", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+
+ Assert.assertEquals(true, collection.contains(resource));
+ Assert.assertNotNull(resResolver.getResource("/test1"));
+ Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
+ }
+
+ @Test
+ public void testGetCollection() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+
+ Resource resource = new MockResource(resResolver, "/res1", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+ resource = new MockResource(resResolver, "/res2", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+
+ collection = rcm.getCollection(resResolver.getResource(collection.getPath()));
+
+ Assert.assertEquals(true, collection.contains(resource));
+ Assert.assertNotNull(resResolver.getResource("/test1"));
+ Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
+ }
+
+ @Test
+ public void testListCollection() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection1");
+
+ Resource resource = new MockResource(resResolver, "/res1", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+ resource = new MockResource(resResolver, "/res2", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+
+ Assert.assertEquals(true, collection.contains(resource));
+
+ Iterator<Resource> resources = collection.getResources();
+
+ int numOfRes = 0;
+ while (resources.hasNext()) {
+ resources.next();
+ numOfRes ++;
+ }
+
+ Assert.assertEquals(2, numOfRes);
+ }
+
+ @Test
+ public void testCreateCollectionWithProperties() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, "some/type");
+ props.put("creator", "slingdev");
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3", props);
+
+ Resource resource = new MockResource(resResolver, "/res1", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+
+
+ Resource collectionRes = resResolver.getResource("/collection3");
+ Assert.assertNotNull(collectionRes);
+
+ Assert.assertEquals(true, collection.contains(resource));
+ Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, collectionRes.getResourceSuperType());
+
+ ValueMap vm = collectionRes.adaptTo(ValueMap.class);
+
+ Assert.assertEquals("slingdev", vm.get("creator", ""));
+ }
+
+ @Test
+ public void testAddResourceWithProperties() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("creator", "slingdev");
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3");
+
+ Resource resource = new MockResource(resResolver, "/res1", "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, props);
+
+
+ Resource collectionRes = resResolver.getResource("/collection3");
+ Assert.assertNotNull(collectionRes);
+
+ Assert.assertEquals(true, collection.contains(resource));
+
+ ValueMap vm = collection.getProperties(resource);
+
+ if (vm != null) {
+ Assert.assertEquals("slingdev", vm.get("creator", ""));
+ } else {
+ Assert.fail("no resource entry in collection");
+ }
+ }
+
+ @Test
+ public void testOrdering() throws Exception {
+ ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
+
+ ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+ String[] resPaths = {"/res1", "/res2"};
+ Resource resource = new MockResource(resResolver, resPaths[0], "type");
+ ((MockResourceResolver) resResolver).addResource(resource);
+
+ collection.add(resource, null);
+ Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
+ ((MockResourceResolver) resResolver).addResource(resource2);
+
+ collection.add(resource2, null);
+
+ Assert.assertEquals(true, collection.contains(resource2));
+ Assert.assertNotNull(resResolver.getResource("/test1"));
+ Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
+
+ Iterator<Resource> resources = collection.getResources();
+
+ int numOfRes = 0;
+ while (resources.hasNext()) {
+ Resource entry = resources.next();
+ Assert.assertEquals(resPaths[numOfRes], entry.getPath());
+ numOfRes ++;
+ }
+
+ //change the order
+ collection.orderBefore(resource2, resource);
+
+ resources = collection.getResources();
+
+ numOfRes = 2;
+ while (resources.hasNext()) {
+ numOfRes --;
+ Resource entry = resources.next();
+ Assert.assertEquals(resPaths[numOfRes], entry.getPath());
+ }
+
+ Assert.assertEquals(0, numOfRes);
+ }
+}
diff --git a/src/test/java/org/apache/sling/resource/collection/test/MockResource.java b/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
new file mode 100755
index 0000000..a97369a
--- /dev/null
+++ b/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resource.collection.test;
+
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.SyntheticResource;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ModifiableValueMapDecorator;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MockResource extends SyntheticResource {
+
+ private String resourceType;
+ private String resourceSuperType;
+ private Map<String,Object> properties = new HashMap<String,Object>();
+
+ public MockResource(ResourceResolver resourceResolver, String path,
+ String resourceType) {
+ this(resourceResolver, path, resourceType, null);
+ }
+
+ public MockResource(ResourceResolver resourceResolver, String path,
+ String resourceType, String resourceSuperType) {
+ super(resourceResolver, path, resourceType);
+
+ setResourceType(resourceType);
+ setResourceSuperType(resourceSuperType);
+ }
+
+ public void addProperty(String key, Object value){
+ this.properties.put(key,value);
+ }
+
+ public Map<String,Object> getProperties(){
+ return this.properties;
+ }
+
+ @Override
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+ @Override
+ public String getResourceSuperType() {
+ return resourceSuperType;
+ }
+
+ public void setResourceSuperType(String resourceSuperType) {
+ this.resourceSuperType = resourceSuperType;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ if (type == ValueMap.class) {
+ ValueMap map = new ValueMapDecorator(new HashMap<String, Object>());
+ if (resourceType != null) {
+ map.put("resourceType", resourceType);
+ }
+ if (resourceSuperType != null) {
+ map.put("resourceSuperType", resourceSuperType);
+ }
+ for (String key : this.properties.keySet()) {
+ map.put(key,this.properties.get(key));
+ }
+ return (AdapterType) map;
+ }
+
+ if (type == ModifiableValueMap.class) {
+ ModifiableValueMap map = new ModifiableValueMapDecorator(this.properties);
+ if (resourceType != null) {
+ map.put("resourceType", resourceType);
+ }
+ if (resourceSuperType != null) {
+ map.put("resourceSuperType", resourceSuperType);
+ }
+ return (AdapterType) map;
+ }
+ throw new UnsupportedOperationException("AdaptTo " + type.getSimpleName() + " not implemented");
+ }
+}
diff --git a/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java b/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
new file mode 100755
index 0000000..5b7d9b3
--- /dev/null
+++ b/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resource.collection.test;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
+
+public class MockResourceResolver implements ResourceResolver {
+
+ private String[] searchPath;
+
+ private Map<String, Resource> resources = new LinkedHashMap<String, Resource>();
+
+ private Map<String, Collection<Resource>> children = new LinkedHashMap<String, Collection<Resource>>();
+
+ public void addResource(Resource resource) {
+ this.resources.put(resource.getPath(), resource);
+ }
+
+ public void addChildren(Resource parent, Collection<Resource> children) {
+ this.children.put(parent.getPath(), children);
+ }
+
+ public Resource resolve(HttpServletRequest request) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Resource resolve(String absPath) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public String map(String resourcePath) {
+ return resourcePath; // a rather simplistic 1:1 map...
+
+ }
+
+ public Resource getResource(String path) {
+ return resources.get(path);
+ }
+
+ public Resource getResource(Resource base, String path) {
+ if (!path.startsWith("/")) {
+ path = base.getPath() + "/" + path;
+ }
+ return getResource(path);
+ }
+
+ public String[] getSearchPath() {
+ return searchPath.clone();
+
+ }
+
+ public Iterator<Resource> listChildren(final Resource parent) {
+ Collection<Resource> childCollection = children.get(parent.getPath());
+ if (childCollection != null) {
+ return childCollection.iterator();
+ }
+
+ return new Iterator<Resource>() {
+ final String parentPath = parent.getPath() + "/";
+
+ final Iterator<Resource> elements = resources.values().iterator();
+
+ Resource nextResource = seek();
+
+ public boolean hasNext() {
+ return nextResource != null;
+ }
+
+ public Resource next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ Resource result = nextResource;
+ nextResource = seek();
+ return result;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private Resource seek() {
+ while (elements.hasNext()) {
+ Resource next = elements.next();
+ String path = next.getPath();
+ if (path.startsWith(parentPath)
+ && path.indexOf('/', parentPath.length()) < 0) {
+ return next;
+ }
+ }
+ return null;
+ }
+ };
+ }
+
+ public Iterator<Resource> findResources(String query, String language) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Iterator<Map<String, Object>> queryResources(String query,
+ String language) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void setSearchPath(String... searchPath) {
+ if (searchPath == null) {
+ this.searchPath = new String[0];
+ } else {
+ this.searchPath = new String[searchPath.length];
+ for (int i=0; i < searchPath.length; i++) {
+ String entry = searchPath[i];
+ if (!entry.endsWith("/")) {
+ entry = entry.concat("/");
+ }
+ this.searchPath[i] = entry;
+ }
+ }
+ }
+
+ public String map(HttpServletRequest request, String resourcePath) {
+ return request.getContextPath() + resourcePath;
+ }
+
+ public Resource resolve(HttpServletRequest request, String absPath) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ public void close() {
+ // nothing to do
+ }
+
+ public String getUserID() {
+ return null;
+ }
+
+ public boolean isLive() {
+ return true;
+ }
+
+ public ResourceResolver clone(Map<String, Object> authenticationInfo)
+ throws LoginException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getAttribute(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Iterator<String> getAttributeNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void commit() throws PersistenceException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Resource create(Resource arg0, String arg1, Map<String, Object> arg2)
+ throws PersistenceException {
+ String superType = "SuperType";
+ String resType = "ResType";
+
+ if (arg2 != null) {
+ if (arg2.containsKey(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY)) {
+ superType = (String) arg2.remove(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY);
+ }
+
+ if (arg2.containsKey(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY)) {
+ resType = (String) arg2.remove(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY);
+ }
+ }
+
+ String resourcePath = arg0.getPath();
+ if (arg0.getPath().equals("/")) {
+ resourcePath = resourcePath + arg1;
+ } else {
+ resourcePath = resourcePath + "/" + arg1;
+ }
+ MockResource resource = new MockResource(this, resourcePath, resType, superType);
+ if (arg2 != null) {
+ for (String key: arg2.keySet()) {
+ resource.addProperty(key, arg2.get(key));
+ }
+ }
+ this.resources.put(resource.getPath(), resource);
+ return resource;
+ }
+
+ public void delete(Resource arg0) throws PersistenceException {
+ // TODO Auto-generated method stub
+ }
+
+ public Iterable<Resource> getChildren(Resource arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasChanges() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void revert() {
+ // TODO Auto-generated method stub
+
+ }
+}
+
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 12/31: SLING-2860 :
Make ResourceCollectionManager an OSGi service
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 96220711346cbbba21d4e678ce4841d74924c418
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 7 17:21:30 2013 +0000
SLING-2860 : Make ResourceCollectionManager an OSGi service
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479986 13f79535-47bb-0310-9956-ffa450edef68
---
.../collection/ResourceCollectionManager.java | 43 ++++++++++------------
.../impl/ResourceCollectionAdapterFactory.java | 8 +++-
.../impl/ResourceCollectionManagerImpl.java | 41 ++++++++-------------
.../impl/ResourceCollectionImplTest.java | 12 +++---
4 files changed, 46 insertions(+), 58 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
index d6c4093..a5ba523 100755
--- a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
@@ -28,65 +28,60 @@ import org.apache.sling.api.resource.ResourceResolver;
/**
* The <code>ResourceCollectionManager<code> defines the API to get, create and delete
* resource collections {@link org.apache.sling.resource.collection.ResourceCollection}.
- *
- * A ResourceCollectionManager instance can be retrieved by adapting a {@link ResourceResolver}.
+ *
+ * A ResourceCollectionManager instance can be retrieved by adapting a {@link ResourceResolver}.
*/
public interface ResourceCollectionManager {
-
+
/**
- * This method returns a resource collection for the given <code>resource</code>
+ * This method returns a resource collection for the given <code>resource</code>
* that represents a {@link ResourceCollection}.
- *
+ *
* It returns null if given resource is not a collection
- *
+ *
* @param resource resource that represents a collection
* @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing the collection.
- *
+ *
*/
ResourceCollection getCollection(Resource resource);
-
-
+
+
/**
- * This method creates a resource collection with a given name under the <code>parentResource</code>.
+ * This method creates a resource collection with a given name under the <code>parentResource</code>.
* The changes are transient and have to be saved by resourceResolver.commit()
- *
+ *
* @param parentResource parent resource where collection needs to be created.
* @param name The name for collection.
*
* @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing the created collection.
- *
+ *
* @throws {@link PersistenceException} if the operation fails
*/
ResourceCollection createCollection(Resource parentResource, String name) throws PersistenceException;
-
+
/**
* This method creates a resource collection with a given name under the <code>parentResource</code>.
* The changes are transient and have to be saved by resourceResolver.commit()
- *
+ *
* @param parentResource parent resource where collection needs to be created.
* @param name The name for collection.
* @param properties The additional data for resource collection
*
* @return The {@link org.apache.sling.resource.collection.ResourceCollection} representing the created collection.
- *
+ *
* @throws {@link PersistenceException} if the operation fails
*/
ResourceCollection createCollection(Resource parentResource, String name, Map<String,Object> properties) throws PersistenceException;
-
+
/**
- * Removes the {@link org.apache.sling.resource.collection.ResourceCollection} corresponding to the collection represented by
+ * Removes the {@link org.apache.sling.resource.collection.ResourceCollection} corresponding to the collection represented by
* <code>resource</code>.
* The changes are transient and have to be saved by resourceResolver.commit()
- *
+ *
* @param resource resource representing a collection to be deleted.
* @return <code>true</code> if the collection was successfully removed.
- *
+ *
* @throws {@link PersistenceException} if the operation fails
*/
boolean deleteCollection(Resource resource) throws PersistenceException;
-
- /**
- * Returns the {@link ResourceResolver} from which this has been retrieved/adapted.
- */
- ResourceResolver getResourceResolver();
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
index c7a2790..400796e 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
@@ -21,6 +21,7 @@ package org.apache.sling.resource.collection.impl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.Resource;
@@ -34,7 +35,7 @@ import org.slf4j.LoggerFactory;
* AdapterFactory that adapts Resources to: {@link ResourceCollection}
* And ResourceResolver to: {@link ResourceCollectionManager)
*/
-@Component(metatype = false)
+@Component
@Service
@Property(name = "service.description", value = "Collection Adapter Factory")
public class ResourceCollectionAdapterFactory implements AdapterFactory {
@@ -57,6 +58,9 @@ public class ResourceCollectionAdapterFactory implements AdapterFactory {
};
+ @Reference
+ private ResourceCollectionManager collectionManager;
+
// ---------- AdapterFactory -----------------------------------------------
public <AdapterType> AdapterType getAdapter(Object adaptable,
@@ -93,7 +97,7 @@ public class ResourceCollectionAdapterFactory implements AdapterFactory {
private <AdapterType> AdapterType getAdapter(ResourceResolver resolver,
Class<AdapterType> type) {
if (COLLECTION_MGR_CLASS == type) {
- return (AdapterType) new ResourceCollectionManagerImpl(resolver);
+ return (AdapterType) collectionManager;
} else {
log.warn("Unable to adapt resolver to requested type {}",
type.getName());
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
index 4518bf2..ea78cb9 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -22,9 +22,10 @@ package org.apache.sling.resource.collection.impl;
import java.util.HashMap;
import java.util.Map;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
@@ -32,21 +33,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
+ *
* Implements <code>ResourceCollectionManger</code> interface. And provides
* create, delete, get apis for ResourceCollection.
*
* A ResourceCollectionManager instance can be retrieved by adapting ResourceResolver.
*/
+@Component
+@Service(value=ResourceCollectionManager.class)
public class ResourceCollectionManagerImpl implements ResourceCollectionManager {
- private static final Logger log = LoggerFactory.getLogger(ResourceCollectionManager.class);
-
- private final ResourceResolver resolver;
-
- public ResourceCollectionManagerImpl(ResourceResolver resolver) {
- this.resolver = resolver;
- }
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* {@inheritDoc}
@@ -55,11 +52,11 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
if (resource != null) {
if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
return new ResourceCollectionImpl(resource);
- }
+ }
} else {
throw new IllegalArgumentException("resource can not be null");
}
-
+
return null;
}
@@ -76,15 +73,15 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
*/
public ResourceCollection createCollection(Resource parentResource, String name,
Map<String, Object> properties) throws PersistenceException {
-
+
if (parentResource != null) {
String fullPath = parentResource.getPath() + "/" + name;
- if (resolver.getResource(fullPath) != null) {
+ if (parentResource.getResourceResolver().getResource(fullPath) != null) {
throw new IllegalArgumentException("invalid path, " + fullPath
+ "resource already exists");
}
-
+
if (properties == null) {
properties = new HashMap<String, Object>();
}
@@ -99,8 +96,8 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
ResourceCollection.RESOURCE_TYPE);
}
- Resource collectionRes = resolver.create(parentResource, name, properties);
- resolver.create(collectionRes, ResourceCollectionConstants.MEMBERS_NODE_NAME, null);
+ Resource collectionRes = parentResource.getResourceResolver().create(parentResource, name, properties);
+ parentResource.getResourceResolver().create(collectionRes, ResourceCollectionConstants.MEMBERS_NODE_NAME, null);
log.debug("collection {} created", fullPath);
return new ResourceCollectionImpl(collectionRes);
@@ -113,25 +110,17 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
/**
* {@inheritDoc}
- *
+ *
* @throws PersistenceException
*/
public boolean deleteCollection(Resource resource)
throws PersistenceException {
if (resource != null) {
log.debug("collection {} deleted", resource.getPath());
- resolver.delete(resource);
+ resource.getResourceResolver().delete(resource);
return true;
} else {
throw new IllegalArgumentException("resource can not be null");
}
}
-
- /**
- * {@inheritDoc}
- */
- public ResourceResolver getResourceResolver() {
- return resolver;
- }
-
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
index dd6b03d..341d011 100755
--- a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
+++ b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
@@ -42,7 +42,7 @@ public class ResourceCollectionImplTest {
@Before
public void setUp() throws Exception {
resResolver = new MockResourceResolverFactory().getAdministrativeResourceResolver(null);
- rcm = new ResourceCollectionManagerImpl(resResolver);
+ rcm = new ResourceCollectionManagerImpl();
}
@Test
@@ -76,14 +76,14 @@ public class ResourceCollectionImplTest {
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
}
-
+
@Test
public void testCheckPath() throws Exception {
final Resource rootResource = resResolver.create(resResolver.getResource("/"), "root",
Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
-
+
final ResourceCollection collection = rcm.createCollection(rootResource, "test1");
-
+
Assert.assertEquals(rootResource.getPath() + "/" + "test1", collection.getPath());
}
@@ -198,12 +198,12 @@ public class ResourceCollectionImplTest {
Assert.assertEquals(resPaths[numOfRes], entry.getPath());
numOfRes ++;
}
-
+
try {
collection.orderBefore(resource, resource);
Assert.fail("should have thrown IllegalArgument");
} catch (IllegalArgumentException e) {
-
+
}
//change the order
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 20/31:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit f8ca37315c360fe6287739255aa675cd72a7ed3a
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Mar 5 11:13:55 2014 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1574433 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 86d1a9f..71eaf70 100755
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
<!-- ======================================================================= -->
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.resourcecollection</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Resource Collection API</name>
@@ -43,9 +43,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.resourcecollection-1.0.0</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.resourcecollection-1.0.0</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.resourcecollection-1.0.0</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/collection</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/collection</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection</url>
</scm>
<!-- ======================================================================= -->
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 02/31: SLING-2853 -
nitpicks
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 8a4ed623ad7f64f972fd37b4db462adcfc238b2d
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon May 6 08:23:42 2013 +0000
SLING-2853 - nitpicks
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479487 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2b066af..58fd84e 100755
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@
<name>Apache Sling Resource Collection API</name>
<description>
- The Apache sling resource collection bundle provides an api to create collections of resources.
+ The Apache Sling resource collection bundle provides an api to manage collections of Resources.
</description>
<scm>
@@ -78,7 +78,6 @@
<!-- D E P E N D E N C I E S -->
<!-- ======================================================================= -->
<dependencies>
-
<!-- sling -->
<dependency>
@@ -126,6 +125,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>junit-addons</groupId>
@@ -151,5 +151,4 @@
<scope>test</scope>
</dependency>
</dependencies>
-
</project>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 28/31: Switch to parent
pom 26
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit fa1d21ebb65abd795b1883be3a09f1a1eae1b811
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Jan 3 14:07:46 2016 +0000
Switch to parent pom 26
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1722720 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c551b0e..06c660b 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>25</version>
+ <version>26</version>
<relativePath/>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 05/31: SLING-2853 -
missing license header
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit a31ff55288672074fa07cf8aef88d2cf76bb5d50
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon May 6 08:47:03 2013 +0000
SLING-2853 - missing license header
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479497 13f79535-47bb-0310-9956-ffa450edef68
---
.../collection/impl/ResourceCollectionImplTest.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
index 62b7abb..90435f0 100755
--- a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
+++ b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.sling.resource.collection.impl;
import java.util.HashMap;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 29/31: SLING-7040 :
Update commons lang 2.x to 3.5
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit ffbed0ca5fc13101fee181b950d149345c18c4aa
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 9 15:41:09 2017 +0000
SLING-7040 : Update commons lang 2.x to 3.5
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804554 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 33 ++------
.../resource/collection/ResourceCollection.java | 78 ++++++++---------
.../collection/ResourceCollectionManager.java | 3 +-
.../impl/ResourceCollectionAdapterFactory.java | 34 ++++----
.../collection/impl/ResourceCollectionImpl.java | 98 ++++++++++++----------
.../impl/ResourceCollectionManagerImpl.java | 16 ++--
6 files changed, 129 insertions(+), 133 deletions(-)
diff --git a/pom.xml b/pom.xml
index 06c660b..7f3de08 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>26</version>
+ <version>31</version>
<relativePath/>
</parent>
@@ -54,10 +54,6 @@
<build>
<plugins>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- </plugin>
- <plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
</plugin>
@@ -99,28 +95,23 @@
<version>2.2.6</version>
<scope>provided</scope>
</dependency>
-
- <!-- OSGI -->
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.5</version>
+ <scope>provided</scope>
</dependency>
+
+ <!-- OSGI -->
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
- <!-- Felix -->
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- <scope>provided</scope>
- </dependency>
-
<!-- Testing -->
<dependency>
<groupId>org.slf4j</groupId>
@@ -133,14 +124,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.4</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
+ <artifactId>javax.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
index ad0b257..de88eb0 100755
--- a/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java
@@ -16,114 +16,116 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.resource.collection;
+
import java.util.Iterator;
import java.util.Map;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
+import org.osgi.annotation.versioning.ProviderType;
/**
- * ResourceCollection is an ordered collection of {@link Resource}.
+ * ResourceCollection is an ordered collection of {@link Resource}.
* The collection does not store the actual Resources, it only points to
- * them.
- *
- * Each entry in the collection is represented by a Resource which contains a
- * reference to original resource. That reference Resource can have additional
+ * them.
+ *
+ * Each entry in the collection is represented by a Resource which contains a
+ * reference to original resource. That reference Resource can have additional
* properties (creationDate, etc.)
*/
+@ProviderType
public interface ResourceCollection {
-
+
/**
* Sling resource type for resource representing a </code>ResourceCollection<code>
*/
public static final String RESOURCE_TYPE = "sling/collection";
-
+
/**
* Returns name of the collection.
- *
+ *
* @return name of the collection.
*/
public String getName();
-
+
/**
* Returns path of the collection.
- *
+ *
* @return path of the collection.
*/
public String getPath();
-
+
/**
* Returns an iterator over resources referred in the collection in the specified order.
*
* @return iterator over resources referred in collection.
*/
Iterator<Resource> getResources();
-
+
/**
* Returns additional properties for a particular resource in Collection entry.
- *
+ *
* @return properties of the Collection entry as <code>ModifiableValueMap</code>, returns null if entry found.
*/
ModifiableValueMap getProperties(Resource resource);
-
+
/**
* Returns true if resource reference is part of the collection.
- *
+ *
* @param resource resource to be checked
* @return true if resource is part of the collection.
* false otherwise
*/
boolean contains(Resource resource);
-
+
/**
- * Creates a new entry in the collection at the last position and add a reference to resource
- * in the entry.
+ * Creates a new entry in the collection at the last position and add a reference to resource
+ * in the entry.
* Changes are transient & have to be saved by calling resolver.commit()
- *
+ *
* @param resource resource to be added
* @param properties The additional properties to be stored with the collection entry (can be null).
- * @return true if addition of resource to collection was successful or
+ * @return true if addition of resource to collection was successful or
* false if collection already contained the resource or resource is null.
- *
+ *
* @throws {@link PersistenceException} if the operation fails
*/
boolean add(Resource resource, Map<String, Object> properties) throws PersistenceException;
-
+
/**
- * Creates a new entry in the collection at the last position and add a reference to resource
- * in the entry.
+ * Creates a new entry in the collection at the last position and add a reference to resource
+ * in the entry.
* Changes are transient & have to be saved by calling resolver.commit()
- *
+ *
* @param resource resource to be added
- * @return true if addition of resource to collection was successful or
+ * @return true if addition of resource to collection was successful or
* false if collection already contained the resource or resource is null.
- *
+ *
* @throws {@link PersistenceException} if the operation fails
*/
boolean add(Resource resource) throws PersistenceException;
-
-
+
+
/**
- * Removes a entry of resource from collection & returns true if successful.
+ * Removes a entry of resource from collection & returns true if successful.
* Changes are transient & have to be saved by calling resolver.commit()
- *
+ *
* @param resource resource reference to be removed
* @return true if resource reference was successfully removed from the collection.
* false if not removed/not present
- *
+ *
* @throws {@link PersistenceException} if the operation fails
*/
- boolean remove(Resource resource) throws PersistenceException;
-
+ boolean remove(Resource resource) throws PersistenceException;
+
/**
* This method inserts the referenced resource <code>srcResource</code>
- * into the collection entry at the position immediately before the referenced resource <code>destResource</code>.
- *
+ * into the collection entry at the position immediately before the referenced resource <code>destResource</code>.
+ *
* To insert the referenced resource into last position, <code>destResource</code> can be null.
- *
+ *
* @param srcResource Referenced resource that needs to be moved in the order
* @param destResource Referenced resource before which the <code>srcResource</code> will be placed.
*/
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
index 37f5c22..77814b4 100755
--- a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.sling.resource.collection;
import java.util.Map;
@@ -24,6 +23,7 @@ import java.util.Map;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
+import org.osgi.annotation.versioning.ProviderType;
/**
* The <code>ResourceCollectionManager<code> defines the API to get, create and delete
@@ -32,6 +32,7 @@ import org.apache.sling.api.resource.ResourceResolver;
* The ResourceCollectionManager service can be retrieved by looking it up from the
* service registry or by adapting a {@link ResourceResolver}.
*/
+@ProviderType
public interface ResourceCollectionManager {
/**
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
index 400796e..d7e37ce 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java
@@ -19,15 +19,14 @@
package org.apache.sling.resource.collection.impl;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,34 +34,29 @@ import org.slf4j.LoggerFactory;
* AdapterFactory that adapts Resources to: {@link ResourceCollection}
* And ResourceResolver to: {@link ResourceCollectionManager)
*/
-@Component
-@Service
-@Property(name = "service.description", value = "Collection Adapter Factory")
+@Component(service = AdapterFactory.class,
+ property = {
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+ Constants.SERVICE_DESCRIPTION + "=Apache Sling Resource Collection Adapter Factory",
+ "adapters=org.apache.sling.resource.collection.ResourceCollection",
+ "adapters=org.apache.sling.resource.collection.ResourceCollectionManager",
+ "adaptables=org.apache.sling.api.resource.Resource",
+ "adaptables=org.apache.sling.api.resource.ResourceResolver"
+ })
public class ResourceCollectionAdapterFactory implements AdapterFactory {
- private static final Logger log = LoggerFactory.getLogger(ResourceCollectionAdapterFactory.class);
+ private final Logger log = LoggerFactory.getLogger(ResourceCollectionAdapterFactory.class);
private static final Class<ResourceCollection> COLLECTION_CLASS = ResourceCollection.class;
private static final Class<ResourceCollectionManager> COLLECTION_MGR_CLASS = ResourceCollectionManager.class;
- @Property(name = "adapters")
- public static final String[] ADAPTER_CLASSES = {
- COLLECTION_CLASS.getName(), COLLECTION_MGR_CLASS.getName()
-
- };
-
- @Property(name = "adaptables")
- public static final String[] ADAPTABLE_CLASSES = {
- Resource.class.getName(), ResourceResolver.class.getName()
-
- };
-
@Reference
private ResourceCollectionManager collectionManager;
// ---------- AdapterFactory -----------------------------------------------
+ @Override
public <AdapterType> AdapterType getAdapter(Object adaptable,
Class<AdapterType> type) {
if (adaptable instanceof Resource) {
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
index cf2f885..b1699c0 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
@@ -26,7 +26,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
@@ -34,11 +34,10 @@ import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.resource.collection.ResourceCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.sling.resource.collection.ResourceCollection;
-
/**
* Implements <code>ResourceCollection</code>
*
@@ -67,7 +66,7 @@ public class ResourceCollectionImpl implements
/**
* Creates a new collection from the given resource
- *
+ *
* @param resource the resource
*/
public ResourceCollectionImpl(Resource resource) {
@@ -75,10 +74,11 @@ public class ResourceCollectionImpl implements
resolver = resource.getResourceResolver();
membersResource = resource.getChild(ResourceCollectionConstants.MEMBERS_NODE_NAME);
}
-
+
/**
* {@inheritDoc}
*/
+ @Override
public String getName() {
return resource.getName();
}
@@ -86,6 +86,7 @@ public class ResourceCollectionImpl implements
/**
* {@inheritDoc}
*/
+ @Override
public String getPath() {
return resource.getPath();
}
@@ -93,16 +94,17 @@ public class ResourceCollectionImpl implements
/**
* {@inheritDoc}
*/
+ @Override
public boolean add(Resource res, Map<String, Object> properties) throws PersistenceException {
if (res != null && !contains(res)) {
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
-
- order = (String[]) ArrayUtils.add(order, res.getPath());
+
+ order = ArrayUtils.add(order, res.getPath());
vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
-
+
if (properties == null) {
- properties = new HashMap<String, Object>();
+ properties = new HashMap<>();
}
properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
resolver.create(
@@ -116,19 +118,20 @@ public class ResourceCollectionImpl implements
return false;
}
-
+
/**
* {@inheritDoc}
*/
+ @Override
public boolean add(Resource res) throws PersistenceException {
if (res != null && !contains(res)) {
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
-
- order = (String[]) ArrayUtils.add(order, res.getPath());
+
+ order = ArrayUtils.add(order, res.getPath());
vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
-
- Map<String, Object> properties = new HashMap<String, Object>();
+
+ Map<String, Object> properties = new HashMap<>();
properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
resolver.create(
membersResource,
@@ -142,30 +145,31 @@ public class ResourceCollectionImpl implements
return false;
}
-
+
/**
* {@inheritDoc}
*/
+ @Override
public Iterator<Resource> getResources() {
-
+
ValueMap vm = membersResource.adaptTo(ValueMap.class);
String[] references = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
- List<Resource> resources = new ArrayList<Resource>();
-
+ List<Resource> resources = new ArrayList<>();
+
for (String path:references) {
Resource resource = resolver.getResource(path);
if (resource != null){
resources.add(resource);
}
}
-
+
return resources.iterator();
}
/**
* Returns the sling resource type on content node of collection
- *
+ *
* @param
* @return <code>sling:resourceType</code> for the collection resource
*/
@@ -176,22 +180,24 @@ public class ResourceCollectionImpl implements
/**
* {@inheritDoc}
*/
+ @Override
public boolean contains(Resource res) {
if (res != null) {
ValueMap vm = membersResource.adaptTo(ValueMap.class);
String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
-
+
int index = ArrayUtils.indexOf(order, res.getPath(), 0);
-
+
return index >= 0 ? true: false;
}
-
+
return false;
}
/**
* {@inheritDoc}
*/
+ @Override
public boolean remove(Resource res) throws PersistenceException {
//remove the resource
Resource tobeRemovedRes = findRes(res);
@@ -202,18 +208,18 @@ public class ResourceCollectionImpl implements
//remove from order array
ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
-
+
int index = ArrayUtils.indexOf(order, res.getPath(), 0);
-
- order = (String[]) ArrayUtils.remove(order, index);
+
+ order = ArrayUtils.remove(order, index);
vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
-
+
return true;
}
/**
* Sets the sling resource type on content node of collection
- *
+ *
* @param type <code>sling:resourceType</code> to be set on the content node
* @return
*/
@@ -240,7 +246,8 @@ public class ResourceCollectionImpl implements
return null;
}
- public void orderBefore(Resource srcResource, Resource destResource) {
+ @Override
+ public void orderBefore(Resource srcResource, Resource destResource) {
if (srcResource == null) {
throw new IllegalArgumentException("Source Resource can not be null");
}
@@ -249,54 +256,55 @@ public class ResourceCollectionImpl implements
String srcPath = srcResource.getPath();
int srcIndex = ArrayUtils.indexOf(order, srcPath);
if (srcIndex < 0) {
- log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
+ log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
srcPath, getPath());
- return ;
+ return ;
}
if (destResource == null) {
//add it to the end.
- order = (String[]) ArrayUtils.remove(order, srcIndex);
- order = (String[]) ArrayUtils.add(order, srcPath);
+ order = ArrayUtils.remove(order, srcIndex);
+ order = ArrayUtils.add(order, srcPath);
} else {
String destPath = destResource.getPath();
-
+
if (destPath.equals(srcPath)) {
- String message = MessageFormat.format("Collection ordering failed, as source {0} and destination {1} can not be same",
+ String message = MessageFormat.format("Collection ordering failed, as source {0} and destination {1} can not be same",
srcPath, destPath);
log.error(message);
throw new IllegalArgumentException(message);
}
-
+
int destIndex = ArrayUtils.indexOf(order, destPath);
-
+
if (destIndex < 0) {
- log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
+ log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
destPath, getPath());
return;
}
-
- order = (String[]) ArrayUtils.remove(order, srcIndex);
+
+ order = ArrayUtils.remove(order, srcIndex);
if (srcIndex < destIndex) { //recalculate dest index
destIndex = ArrayUtils.indexOf(order, destPath);
}
- order = (String[]) ArrayUtils.add(order, destIndex, srcPath);
+ order = ArrayUtils.add(order, destIndex, srcPath);
}
-
+
vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
}
- public ModifiableValueMap getProperties(Resource resource) {
+ @Override
+ public ModifiableValueMap getProperties(Resource resource) {
Iterator<Resource> entries = membersResource.listChildren();
while (entries.hasNext()) {
Resource entry = entries.next();
String path = ResourceUtil.getValueMap(entry).get(
ResourceCollectionConstants.REF_PROPERTY, "");
-
+
if (resource.getPath().equals(path)) {
return entry.adaptTo(ModifiableValueMap.class);
}
}
-
+
return null;
}
}
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
index 59eb4ff..293a42d 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -22,14 +22,14 @@ package org.apache.sling.resource.collection.impl;
import java.util.HashMap;
import java.util.Map;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,8 +41,10 @@ import org.slf4j.LoggerFactory;
* This service can be retrieved by looking it up from the
* service registry or by adapting a {@link ResourceResolver}.
*/
-@Component
-@Service(value=ResourceCollectionManager.class)
+@Component(service=ResourceCollectionManager.class,
+ property = {
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+ })
public class ResourceCollectionManagerImpl implements ResourceCollectionManager {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@@ -50,6 +52,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
/**
* {@inheritDoc}
*/
+ @Override
public ResourceCollection getCollection(Resource resource) {
if (resource != null) {
if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
@@ -65,6 +68,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
/**
* {@inheritDoc}
*/
+ @Override
public ResourceCollection createCollection(Resource parentResource, String name)
throws PersistenceException {
return createCollection(parentResource, name, null);
@@ -73,6 +77,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
/**
* {@inheritDoc}
*/
+ @Override
public ResourceCollection createCollection(Resource parentResource, String name,
Map<String, Object> properties) throws PersistenceException {
@@ -85,7 +90,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
}
if (properties == null) {
- properties = new HashMap<String, Object>();
+ properties = new HashMap<>();
}
if (properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY) != null
@@ -115,6 +120,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
*
* @throws PersistenceException
*/
+ @Override
public boolean deleteCollection(Resource resource)
throws PersistenceException {
if (resource != null) {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 24/31: SLING-4698 - Set
parent.relativePath to empty for all modules
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 9fbad366795d0378168bec0dbed854dfeb3c6c43
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu May 7 10:14:40 2015 +0000
SLING-4698 - Set parent.relativePath to empty for all modules
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1678154 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d68c757..952ded7 100755
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
<version>22</version>
- <relativePath>../../../parent/pom.xml</relativePath>
+ <relativePath/>
</parent>
<!-- ======================================================================= -->
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 26/31: set parent
version to 24 and add empty relativePath where missing
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit b081577daee176ca2fe60d390861bbb0b3803e6c
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Jul 7 07:36:29 2015 +0000
set parent version to 24 and add empty relativePath where missing
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1689588 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 366c013..fa64ee6 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>23</version>
+ <version>24</version>
<relativePath/>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 15/31: Fix scm location
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit dee4bf40ba41b9ce3899aec702e401e485fc740c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Aug 13 07:39:58 2013 +0000
Fix scm location
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1513381 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 07be744..9df727a 100755
--- a/pom.xml
+++ b/pom.xml
@@ -43,9 +43,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/resourcecollection</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/resourcecollection</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/trunk/bundles/resourcecollection</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/collection</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/collection</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection</url>
</scm>
<!-- ======================================================================= -->
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 09/31: SLING-2853 : Add
ResourceCollection to Sling - use resource resolver mock
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 6ba70ec2786f33401f35ec01081d8c898f498ec1
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon May 6 18:35:43 2013 +0000
SLING-2853 : Add ResourceCollection to Sling - use resource resolver mock
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479668 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 6 +
.../impl/ResourceCollectionImplTest.java | 116 +++++-----
.../resource/collection/test/MockResource.java | 105 ---------
.../collection/test/MockResourceResolver.java | 249 ---------------------
4 files changed, 71 insertions(+), 405 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9184268..c873525 100755
--- a/pom.xml
+++ b/pom.xml
@@ -143,5 +143,11 @@
<artifactId>servlet-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
+ <version>0.1.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
index 90435f0..d722c3a 100755
--- a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
+++ b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.resource.collection.impl;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -30,8 +31,7 @@ import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
-import org.apache.sling.resource.collection.test.MockResource;
-import org.apache.sling.resource.collection.test.MockResourceResolver;
+import org.apache.sling.testing.resourceresolver.MockResourceResolverFactory;
import org.junit.Before;
import org.junit.Test;
@@ -41,151 +41,165 @@ public class ResourceCollectionImplTest {
@Before
public void setUp() throws Exception {
- resResolver = new MockResourceResolver();
+ resResolver = new MockResourceResolverFactory().getAdministrativeResourceResolver(null);
rcm = new ResourceCollectionManagerImpl(resResolver);
- // need a root resource
- new MockResource(resResolver, "/", "type");
}
-
+
@Test
public void testAddResource() throws Exception {
-
+
final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
- collection.add(new MockResource(resResolver, "/res1", "type"));
- final Resource resource = new MockResource(resResolver, "/res2", "type");
+ final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+ collection.add(res1);
+ final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
collection.add(resource);
-
+
Assert.assertEquals(true, collection.contains(resource));
Assert.assertEquals(true, collection.contains(resource));
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
}
-
+
@Test
public void testCreateCollection() throws Exception {
final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
- collection.add(new MockResource(resResolver, "/res1", "type"), null);
- final Resource resource = new MockResource(resResolver, "/res2", "type");
+ final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+ collection.add(res1, null);
+ final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
collection.add(resource, null);
-
+
Assert.assertEquals(true, collection.contains(resource));
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
}
-
+
@Test
public void testGetCollection() throws Exception {
ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
- collection.add(new MockResource(resResolver, "/res1", "type"), null);
- final Resource resource = new MockResource(resResolver, "/res2", "type");
+ final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+ collection.add(res1, null);
+ final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
collection.add(resource, null);
-
+
collection = rcm.getCollection(resResolver.getResource(collection.getPath()));
-
+
Assert.assertEquals(true, collection.contains(resource));
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
}
-
+
@Test
public void testListCollection() throws Exception {
final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection1");
- collection.add(new MockResource(resResolver, "/res1", "type"), null);
- final Resource resource = new MockResource(resResolver, "/res2", "type");
-
+ final Resource res1 = resResolver.create(resResolver.getResource("/"), "res1",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+ collection.add(res1, null);
+ final Resource resource = resResolver.create(resResolver.getResource("/"), "res2",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+
collection.add(resource, null);
Assert.assertEquals(true, collection.contains(resource));
-
+
final Iterator<Resource> resources = collection.getResources();
int numOfRes = 0;
while (resources.hasNext()) {
resources.next();
numOfRes ++;
}
-
+
Assert.assertEquals(2, numOfRes);
}
-
+
@Test
public void testCreateCollectionWithProperties() throws Exception {
final Map<String, Object> props = new HashMap<String, Object>();
props.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, "some/type");
props.put("creator", "slingdev");
-
+
final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3", props);
- final Resource resource = new MockResource(resResolver, "/res1", "type");
+ final Resource resource = resResolver.create(resResolver.getResource("/"), "res1",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
collection.add(resource, null);
-
+
final Resource collectionRes = resResolver.getResource("/collection3");
Assert.assertNotNull(collectionRes);
-
+
Assert.assertEquals(true, collection.contains(resource));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, collectionRes.getResourceSuperType());
-
+
ValueMap vm = collectionRes.adaptTo(ValueMap.class);
-
+
Assert.assertEquals("slingdev", vm.get("creator", ""));
}
-
+
@Test
public void testAddResourceWithProperties() throws Exception {
final Map<String, Object> props = new HashMap<String, Object>();
props.put("creator", "slingdev");
-
+
final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3");
-
- final Resource resource = new MockResource(resResolver, "/res1", "type");
+
+ final Resource resource = resResolver.create(resResolver.getResource("/"), "res1",
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
collection.add(resource, props);
-
+
final Resource collectionRes = resResolver.getResource("/collection3");
Assert.assertNotNull(collectionRes);
-
+
Assert.assertEquals(true, collection.contains(resource));
-
+
ValueMap vm = collection.getProperties(resource);
-
+
if (vm != null) {
Assert.assertEquals("slingdev", vm.get("creator", ""));
} else {
Assert.fail("no resource entry in collection");
}
}
-
+
@Test
public void testOrdering() throws Exception {
final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
String[] resPaths = {"/res1", "/res2"};
- final Resource resource = new MockResource(resResolver, resPaths[0], "type");
-
+ final Resource resource = resResolver.create(resResolver.getResource("/"), resPaths[0].substring(1),
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
+
collection.add(resource, null);
- final Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
+ final Resource resource2 = resResolver.create(resResolver.getResource("/"), resPaths[1].substring(1),
+ Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object)"type"));
collection.add(resource2, null);
-
+
Assert.assertEquals(true, collection.contains(resource2));
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
-
+
Iterator<Resource> resources = collection.getResources();
-
+
int numOfRes = 0;
while (resources.hasNext()) {
Resource entry = resources.next();
Assert.assertEquals(resPaths[numOfRes], entry.getPath());
numOfRes ++;
}
-
+
//change the order
collection.orderBefore(resource2, resource);
-
+
resources = collection.getResources();
-
+
numOfRes = 2;
while (resources.hasNext()) {
numOfRes --;
Resource entry = resources.next();
Assert.assertEquals(resPaths[numOfRes], entry.getPath());
}
-
+
Assert.assertEquals(0, numOfRes);
}
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/resource/collection/test/MockResource.java b/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
deleted file mode 100755
index 74595d8..0000000
--- a/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.resource.collection.test;
-
-import org.apache.sling.api.resource.ModifiableValueMap;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.SyntheticResource;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.api.wrappers.ModifiableValueMapDecorator;
-import org.apache.sling.api.wrappers.ValueMapDecorator;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class MockResource extends SyntheticResource {
-
- private String resourceType;
- private String resourceSuperType;
- private Map<String,Object> properties = new HashMap<String,Object>();
-
- public MockResource(ResourceResolver resourceResolver, String path,
- String resourceType) {
- this(resourceResolver, path, resourceType, null);
- }
-
- public MockResource(ResourceResolver resourceResolver, String path,
- String resourceType, String resourceSuperType) {
- super(resourceResolver, path, resourceType);
-
- ((MockResourceResolver)resourceResolver).addResource(this);
- setResourceType(resourceType);
- setResourceSuperType(resourceSuperType);
- }
-
- public void addProperty(String key, Object value){
- this.properties.put(key,value);
- }
-
- public Map<String,Object> getProperties(){
- return this.properties;
- }
-
- @Override
- public String getResourceType() {
- return resourceType;
- }
-
- public void setResourceType(String resourceType) {
- this.resourceType = resourceType;
- }
-
- @Override
- public String getResourceSuperType() {
- return resourceSuperType;
- }
-
- public void setResourceSuperType(String resourceSuperType) {
- this.resourceSuperType = resourceSuperType;
- }
-
- @SuppressWarnings("unchecked")
- public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
- if (type == ValueMap.class) {
- ValueMap map = new ValueMapDecorator(new HashMap<String, Object>());
- if (resourceType != null) {
- map.put("resourceType", resourceType);
- }
- if (resourceSuperType != null) {
- map.put("resourceSuperType", resourceSuperType);
- }
- for (String key : this.properties.keySet()) {
- map.put(key,this.properties.get(key));
- }
- return (AdapterType) map;
- }
-
- if (type == ModifiableValueMap.class) {
- ModifiableValueMap map = new ModifiableValueMapDecorator(this.properties);
- if (resourceType != null) {
- map.put("resourceType", resourceType);
- }
- if (resourceSuperType != null) {
- map.put("resourceSuperType", resourceSuperType);
- }
- return (AdapterType) map;
- }
- throw new UnsupportedOperationException("AdaptTo " + type.getSimpleName() + " not implemented");
- }
-}
diff --git a/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java b/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
deleted file mode 100755
index 741a657..0000000
--- a/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.resource.collection.test;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.PersistenceException;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
-
-public class MockResourceResolver implements ResourceResolver {
-
- private String[] searchPath;
-
- private Map<String, Resource> resources = new LinkedHashMap<String, Resource>();
-
- private Map<String, Collection<Resource>> children = new LinkedHashMap<String, Collection<Resource>>();
-
- void addResource(Resource resource) {
- this.resources.put(resource.getPath(), resource);
- }
-
- public void addChildren(Resource parent, Collection<Resource> children) {
- this.children.put(parent.getPath(), children);
- }
-
- public Resource resolve(HttpServletRequest request) {
- throw new UnsupportedOperationException("Not implemented");
-
- }
-
- public Resource resolve(String absPath) {
- throw new UnsupportedOperationException("Not implemented");
-
- }
-
- public String map(String resourcePath) {
- return resourcePath; // a rather simplistic 1:1 map...
-
- }
-
- public Resource getResource(String path) {
- return resources.get(path);
- }
-
- public Resource getResource(Resource base, String path) {
- if (!path.startsWith("/")) {
- path = base.getPath() + "/" + path;
- }
- return getResource(path);
- }
-
- public String[] getSearchPath() {
- return searchPath.clone();
-
- }
-
- public Iterator<Resource> listChildren(final Resource parent) {
- Collection<Resource> childCollection = children.get(parent.getPath());
- if (childCollection != null) {
- return childCollection.iterator();
- }
-
- return new Iterator<Resource>() {
- final String parentPath = parent.getPath() + "/";
-
- final Iterator<Resource> elements = resources.values().iterator();
-
- Resource nextResource = seek();
-
- public boolean hasNext() {
- return nextResource != null;
- }
-
- public Resource next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- Resource result = nextResource;
- nextResource = seek();
- return result;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private Resource seek() {
- while (elements.hasNext()) {
- Resource next = elements.next();
- String path = next.getPath();
- if (path.startsWith(parentPath)
- && path.indexOf('/', parentPath.length()) < 0) {
- return next;
- }
- }
- return null;
- }
- };
- }
-
- public Iterator<Resource> findResources(String query, String language) {
- throw new UnsupportedOperationException("Not implemented");
-
- }
-
- public Iterator<Map<String, Object>> queryResources(String query,
- String language) {
- throw new UnsupportedOperationException("Not implemented");
-
- }
-
- public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
- throw new UnsupportedOperationException("Not implemented");
-
- }
-
- public void setSearchPath(String... searchPath) {
- if (searchPath == null) {
- this.searchPath = new String[0];
- } else {
- this.searchPath = new String[searchPath.length];
- for (int i=0; i < searchPath.length; i++) {
- String entry = searchPath[i];
- if (!entry.endsWith("/")) {
- entry = entry.concat("/");
- }
- this.searchPath[i] = entry;
- }
- }
- }
-
- public String map(HttpServletRequest request, String resourcePath) {
- return request.getContextPath() + resourcePath;
- }
-
- public Resource resolve(HttpServletRequest request, String absPath) {
- throw new UnsupportedOperationException("Not implemented");
- }
-
- public void close() {
- // nothing to do
- }
-
- public String getUserID() {
- return null;
- }
-
- public boolean isLive() {
- return true;
- }
-
- public ResourceResolver clone(Map<String, Object> authenticationInfo)
- throws LoginException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getAttribute(String name) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Iterator<String> getAttributeNames() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void commit() throws PersistenceException {
- // TODO Auto-generated method stub
-
- }
-
- public Resource create(Resource arg0, String arg1, Map<String, Object> arg2)
- throws PersistenceException {
- String superType = "SuperType";
- String resType = "ResType";
-
- if (arg2 != null) {
- if (arg2.containsKey(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY)) {
- superType = (String) arg2.remove(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY);
- }
-
- if (arg2.containsKey(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY)) {
- resType = (String) arg2.remove(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY);
- }
- }
-
- String resourcePath = arg0.getPath();
- if (arg0.getPath().equals("/")) {
- resourcePath = resourcePath + arg1;
- } else {
- resourcePath = resourcePath + "/" + arg1;
- }
- MockResource resource = new MockResource(this, resourcePath, resType, superType);
- if (arg2 != null) {
- for (String key: arg2.keySet()) {
- resource.addProperty(key, arg2.get(key));
- }
- }
- this.resources.put(resource.getPath(), resource);
- return resource;
- }
-
- public void delete(Resource arg0) throws PersistenceException {
- // TODO Auto-generated method stub
- }
-
- public Iterable<Resource> getChildren(Resource arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public boolean hasChanges() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void revert() {
- // TODO Auto-generated method stub
-
- }
-}
-
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 13/31: SLING-2860 :
Make ResourceCollectionManager an OSGi service
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 5fc85fa5a6212bbdb4c56451869e182c78388118
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 7 17:22:45 2013 +0000
SLING-2860 : Make ResourceCollectionManager an OSGi service
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479987 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/sling/resource/collection/ResourceCollectionManager.java | 3 ++-
.../sling/resource/collection/impl/ResourceCollectionManagerImpl.java | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
index a5ba523..37f5c22 100755
--- a/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
+++ b/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java
@@ -29,7 +29,8 @@ import org.apache.sling.api.resource.ResourceResolver;
* The <code>ResourceCollectionManager<code> defines the API to get, create and delete
* resource collections {@link org.apache.sling.resource.collection.ResourceCollection}.
*
- * A ResourceCollectionManager instance can be retrieved by adapting a {@link ResourceResolver}.
+ * The ResourceCollectionManager service can be retrieved by looking it up from the
+ * service registry or by adapting a {@link ResourceResolver}.
*/
public interface ResourceCollectionManager {
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
index ea78cb9..59eb4ff 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
@@ -37,7 +38,8 @@ import org.slf4j.LoggerFactory;
* Implements <code>ResourceCollectionManger</code> interface. And provides
* create, delete, get apis for ResourceCollection.
*
- * A ResourceCollectionManager instance can be retrieved by adapting ResourceResolver.
+ * This service can be retrieved by looking it up from the
+ * service registry or by adapting a {@link ResourceResolver}.
*/
@Component
@Service(value=ResourceCollectionManager.class)
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 17/31: Update to parent
pom 18
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 80cc223de8572042243405d9c1be511438333c76
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Sep 6 12:15:57 2013 +0000
Update to parent pom 18
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1520554 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3153b21..95142c0 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>17</version>
+ <version>18</version>
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 08/31: Revert wrong
change from revision 1479549
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit f72bcc85868cd98151cfe7b6193a5464b598a88a
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon May 6 18:34:43 2013 +0000
Revert wrong change from revision 1479549
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479667 13f79535-47bb-0310-9956-ffa450edef68
---
.../impl/ResourceCollectionManagerImpl.java | 28 +++++++++++++---------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
index 66acdb7..450bc7c 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -25,13 +25,14 @@ import java.util.Map;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
+ *
* Implements <code>ResourceCollectionManger</code> interface. And provides
* create, delete, get apis for ResourceCollection.
*
@@ -54,11 +55,11 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
if (resource != null) {
if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
return new ResourceCollectionImpl(resource);
- }
+ }
} else {
throw new IllegalArgumentException("resource can not be null");
}
-
+
return null;
}
@@ -75,7 +76,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
*/
public ResourceCollection createCollection(Resource parentResource, String name,
Map<String, Object> properties) throws PersistenceException {
-
+
if (parentResource != null) {
String fullPath = parentResource.getPath() + name;
@@ -83,16 +84,21 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
throw new IllegalArgumentException("invalid path, " + fullPath
+ "resource already exists");
}
-
+
if (properties == null) {
properties = new HashMap<String, Object>();
}
- // make sure correct resource type is used
- properties.put(
- ResourceResolver.PROPERTY_RESOURCE_TYPE,
+ if (properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY) != null
+ && !ResourceCollection.RESOURCE_TYPE.equals(properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY))) {
+ properties.put(
+ JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY,
ResourceCollection.RESOURCE_TYPE);
-
+ } else {
+ properties.put(
+ JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
+ ResourceCollection.RESOURCE_TYPE);
+ }
Resource collectionRes = resolver.create(parentResource, name, properties);
resolver.create(collectionRes, "members", null);
log.debug("collection {} created", fullPath);
@@ -108,7 +114,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
/**
* {@inheritDoc}
- *
+ *
* @throws PersistenceException
*/
public boolean deleteCollection(Resource resource)
@@ -121,7 +127,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
throw new IllegalArgumentException("resource can not be null");
}
}
-
+
/**
* {@inheritDoc}
*/
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 14/31: Update to latest
parent pom
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 1521cee6a8aae64e253cbd98a9c182c14d0ac37c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Jul 19 07:04:15 2013 +0000
Update to latest parent pom
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1504788 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c873525..07be744 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>15</version>
+ <version>17</version>
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 18/31: Use relesed
version of sling.api (2.6.0 is required)
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit c37dd5b89a6df1a5ff45d3faec969ef95f2d8f43
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Mar 5 11:12:55 2014 +0000
Use relesed version of sling.api (2.6.0 is required)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1574429 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 95142c0..87d8dbc 100755
--- a/pom.xml
+++ b/pom.xml
@@ -83,7 +83,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.4.3-SNAPSHOT</version>
+ <version>2.6.0</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 30/31: SLING-7040 :
Update commons lang 2.x to 3.5
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit ad508f5a8eabc632f6cad64629e0376abc9a8ca7
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 9 15:41:30 2017 +0000
SLING-7040 : Update commons lang 2.x to 3.5
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804555 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/resource/collection/package-info.java | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/main/java/org/apache/sling/resource/collection/package-info.java b/src/main/java/org/apache/sling/resource/collection/package-info.java
new file mode 100644
index 0000000..bc6c9fd
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+@org.osgi.annotation.versioning.Version("1.0.2")
+package org.apache.sling.resource.collection;
+
+
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 25/31: Update contrib
modules to Parent 23
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 14f101789b2628d9abf9ae2affec6ebf9148f7e3
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jun 25 13:10:59 2015 +0000
Update contrib modules to Parent 23
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1687503 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 952ded7..366c013 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>22</version>
+ <version>23</version>
<relativePath/>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 03/31: SLING-2853 -
remove unused dependencies
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 024a84c7e48bcccdbf80f09b64d62e63d34e411b
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon May 6 08:28:59 2013 +0000
SLING-2853 - remove unused dependencies
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479488 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index 58fd84e..cc15821 100755
--- a/pom.xml
+++ b/pom.xml
@@ -128,15 +128,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit-addons</groupId>
- <artifactId>junit-addons</artifactId>
- <version>1.4</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>3.0.8</version>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 07/31: SLING-2853 :
Simplify resource type setting
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 81925af66cc65c1501a403e375d1b4950cd3521e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon May 6 12:37:19 2013 +0000
SLING-2853 : Simplify resource type setting
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479549 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
.../impl/ResourceCollectionManagerImpl.java | 28 +++++++++-------------
2 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/pom.xml b/pom.xml
index cc15821..9184268 100755
--- a/pom.xml
+++ b/pom.xml
@@ -83,7 +83,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.3.0</version>
+ <version>2.4.0</version>
<scope>provided</scope>
</dependency>
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
index 450bc7c..66acdb7 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java
@@ -25,14 +25,13 @@ import java.util.Map;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
import org.apache.sling.resource.collection.ResourceCollection;
import org.apache.sling.resource.collection.ResourceCollectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
+ *
* Implements <code>ResourceCollectionManger</code> interface. And provides
* create, delete, get apis for ResourceCollection.
*
@@ -55,11 +54,11 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
if (resource != null) {
if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) {
return new ResourceCollectionImpl(resource);
- }
+ }
} else {
throw new IllegalArgumentException("resource can not be null");
}
-
+
return null;
}
@@ -76,7 +75,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
*/
public ResourceCollection createCollection(Resource parentResource, String name,
Map<String, Object> properties) throws PersistenceException {
-
+
if (parentResource != null) {
String fullPath = parentResource.getPath() + name;
@@ -84,21 +83,16 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
throw new IllegalArgumentException("invalid path, " + fullPath
+ "resource already exists");
}
-
+
if (properties == null) {
properties = new HashMap<String, Object>();
}
- if (properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY) != null
- && !ResourceCollection.RESOURCE_TYPE.equals(properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY))) {
- properties.put(
- JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY,
+ // make sure correct resource type is used
+ properties.put(
+ ResourceResolver.PROPERTY_RESOURCE_TYPE,
ResourceCollection.RESOURCE_TYPE);
- } else {
- properties.put(
- JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
- ResourceCollection.RESOURCE_TYPE);
- }
+
Resource collectionRes = resolver.create(parentResource, name, properties);
resolver.create(collectionRes, "members", null);
log.debug("collection {} created", fullPath);
@@ -114,7 +108,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
/**
* {@inheritDoc}
- *
+ *
* @throws PersistenceException
*/
public boolean deleteCollection(Resource resource)
@@ -127,7 +121,7 @@ public class ResourceCollectionManagerImpl implements ResourceCollectionManager
throw new IllegalArgumentException("resource can not be null");
}
}
-
+
/**
* {@inheritDoc}
*/
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 04/31: SLING-2853 -
simplify tests
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit d1cedf8fc5e9774dd87104c7fd92f92bbff163de
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon May 6 08:44:43 2013 +0000
SLING-2853 - simplify tests
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479496 13f79535-47bb-0310-9956-ffa450edef68
---
.../impl/ResourceCollectionImplTest.java | 104 ++++++---------------
.../resource/collection/test/MockResource.java | 1 +
.../collection/test/MockResourceResolver.java | 2 +-
3 files changed, 30 insertions(+), 77 deletions(-)
diff --git a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
index f37c207..62b7abb 100755
--- a/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
+++ b/src/test/java/org/apache/sling/resource/collection/impl/ResourceCollectionImplTest.java
@@ -1,6 +1,5 @@
package org.apache.sling.resource.collection.impl;
-
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -20,33 +19,25 @@ import org.junit.Test;
public class ResourceCollectionImplTest {
private ResourceResolver resResolver;
+ private ResourceCollectionManager rcm;
@Before
public void setUp() throws Exception {
resResolver = new MockResourceResolver();
- //create some root resource
- Resource resource = new MockResource(resResolver, "/", "type");
-
- ((MockResourceResolver) resResolver).addResource(resource);
+ rcm = new ResourceCollectionManagerImpl(resResolver);
+ // need a root resource
+ new MockResource(resResolver, "/", "type");
}
@Test
public void testAddResource() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
- ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
-
- Resource resource = new MockResource(resResolver, "/res1", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
- collection.add(resource);
- resource = new MockResource(resResolver, "/res2", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
+ final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+ collection.add(new MockResource(resResolver, "/res1", "type"));
+ final Resource resource = new MockResource(resResolver, "/res2", "type");
collection.add(resource);
Assert.assertEquals(true, collection.contains(resource));
-
Assert.assertEquals(true, collection.contains(resource));
Assert.assertNotNull(resResolver.getResource("/test1"));
Assert.assertEquals(ResourceCollection.RESOURCE_TYPE, resResolver.getResource("/test1").getResourceType());
@@ -54,17 +45,9 @@ public class ResourceCollectionImplTest {
@Test
public void testCreateCollection() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-
- ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
-
- Resource resource = new MockResource(resResolver, "/res1", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
- collection.add(resource, null);
- resource = new MockResource(resResolver, "/res2", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
+ final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+ collection.add(new MockResource(resResolver, "/res1", "type"), null);
+ final Resource resource = new MockResource(resResolver, "/res2", "type");
collection.add(resource, null);
Assert.assertEquals(true, collection.contains(resource));
@@ -74,17 +57,9 @@ public class ResourceCollectionImplTest {
@Test
public void testGetCollection() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-
ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
-
- Resource resource = new MockResource(resResolver, "/res1", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
- collection.add(resource, null);
- resource = new MockResource(resResolver, "/res2", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
+ collection.add(new MockResource(resResolver, "/res1", "type"), null);
+ final Resource resource = new MockResource(resResolver, "/res2", "type");
collection.add(resource, null);
collection = rcm.getCollection(resResolver.getResource(collection.getPath()));
@@ -96,23 +71,14 @@ public class ResourceCollectionImplTest {
@Test
public void testListCollection() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-
- ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection1");
-
- Resource resource = new MockResource(resResolver, "/res1", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
- collection.add(resource, null);
- resource = new MockResource(resResolver, "/res2", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
+ final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection1");
+ collection.add(new MockResource(resResolver, "/res1", "type"), null);
+ final Resource resource = new MockResource(resResolver, "/res2", "type");
collection.add(resource, null);
-
Assert.assertEquals(true, collection.contains(resource));
- Iterator<Resource> resources = collection.getResources();
-
+ final Iterator<Resource> resources = collection.getResources();
int numOfRes = 0;
while (resources.hasNext()) {
resources.next();
@@ -124,20 +90,15 @@ public class ResourceCollectionImplTest {
@Test
public void testCreateCollectionWithProperties() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
- Map<String, Object> props = new HashMap<String, Object>();
+ final Map<String, Object> props = new HashMap<String, Object>();
props.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, "some/type");
props.put("creator", "slingdev");
- ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3", props);
-
- Resource resource = new MockResource(resResolver, "/res1", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
-
+ final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3", props);
+ final Resource resource = new MockResource(resResolver, "/res1", "type");
collection.add(resource, null);
-
- Resource collectionRes = resResolver.getResource("/collection3");
+ final Resource collectionRes = resResolver.getResource("/collection3");
Assert.assertNotNull(collectionRes);
Assert.assertEquals(true, collection.contains(resource));
@@ -150,19 +111,15 @@ public class ResourceCollectionImplTest {
@Test
public void testAddResourceWithProperties() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
- Map<String, Object> props = new HashMap<String, Object>();
+ final Map<String, Object> props = new HashMap<String, Object>();
props.put("creator", "slingdev");
- ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3");
-
- Resource resource = new MockResource(resResolver, "/res1", "type");
- ((MockResourceResolver) resResolver).addResource(resource);
+ final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "collection3");
+ final Resource resource = new MockResource(resResolver, "/res1", "type");
collection.add(resource, props);
-
- Resource collectionRes = resResolver.getResource("/collection3");
+ final Resource collectionRes = resResolver.getResource("/collection3");
Assert.assertNotNull(collectionRes);
Assert.assertEquals(true, collection.contains(resource));
@@ -178,17 +135,12 @@ public class ResourceCollectionImplTest {
@Test
public void testOrdering() throws Exception {
- ResourceCollectionManager rcm = new ResourceCollectionManagerImpl(resResolver);
-
- ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
+ final ResourceCollection collection = rcm.createCollection(resResolver.getResource("/"), "test1");
String[] resPaths = {"/res1", "/res2"};
- Resource resource = new MockResource(resResolver, resPaths[0], "type");
- ((MockResourceResolver) resResolver).addResource(resource);
+ final Resource resource = new MockResource(resResolver, resPaths[0], "type");
collection.add(resource, null);
- Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
- ((MockResourceResolver) resResolver).addResource(resource2);
-
+ final Resource resource2 = new MockResource(resResolver, resPaths[1], "type");
collection.add(resource2, null);
Assert.assertEquals(true, collection.contains(resource2));
@@ -218,4 +170,4 @@ public class ResourceCollectionImplTest {
Assert.assertEquals(0, numOfRes);
}
-}
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/resource/collection/test/MockResource.java b/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
index a97369a..74595d8 100755
--- a/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
+++ b/src/test/java/org/apache/sling/resource/collection/test/MockResource.java
@@ -43,6 +43,7 @@ public class MockResource extends SyntheticResource {
String resourceType, String resourceSuperType) {
super(resourceResolver, path, resourceType);
+ ((MockResourceResolver)resourceResolver).addResource(this);
setResourceType(resourceType);
setResourceSuperType(resourceSuperType);
}
diff --git a/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java b/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
index 5b7d9b3..741a657 100755
--- a/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
+++ b/src/test/java/org/apache/sling/resource/collection/test/MockResourceResolver.java
@@ -40,7 +40,7 @@ public class MockResourceResolver implements ResourceResolver {
private Map<String, Collection<Resource>> children = new LinkedHashMap<String, Collection<Resource>>();
- public void addResource(Resource resource) {
+ void addResource(Resource resource) {
this.resources.put(resource.getPath(), resource);
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 19/31:
[maven-release-plugin] prepare release
org.apache.sling.resourcecollection-1.0.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit b8cc0dbe2ef15dd4aa5ae20705e1ece737ca46a8
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Mar 5 11:13:29 2014 +0000
[maven-release-plugin] prepare release org.apache.sling.resourcecollection-1.0.0
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1574430 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 87d8dbc..86d1a9f 100755
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
<!-- ======================================================================= -->
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.resourcecollection</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <version>1.0.0</version>
<packaging>bundle</packaging>
<name>Apache Sling Resource Collection API</name>
@@ -43,9 +43,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/collection</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/collection</developerConnection>
- <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.resourcecollection-1.0.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.resourcecollection-1.0.0</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.resourcecollection-1.0.0</url>
</scm>
<!-- ======================================================================= -->
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 21/31: Update to parent
pom v19
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit fc06ee4c6b81297cbe76e1ba062043cd7001b4ba
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Mar 31 14:39:20 2014 +0000
Update to parent pom v19
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1583337 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 71eaf70..e375f2f 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>18</version>
+ <version>19</version>
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 27/31: Update the
contrib reactor to parent 25
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit 1d99ebbb048b156aca756830406c7e57db3cb8c6
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Oct 5 10:04:15 2015 +0000
Update the contrib reactor to parent 25
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1706781 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index fa64ee6..c551b0e 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>24</version>
+ <version>25</version>
<relativePath/>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 22/31: Update to latest
parent pom 20
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit c4b05f49b714e5bf0697ecdf702f99612d0e430f
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Sep 2 14:49:28 2014 +0000
Update to latest parent pom 20
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1622027 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e375f2f..b0d4739 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>19</version>
+ <version>20</version>
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 23/31: Update to Sling
Parent POM 22 with baselining enabled
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit d3611787826156766b760a84947943158f3cf89a
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Oct 1 06:52:29 2014 +0000
Update to Sling Parent POM 22 with baselining enabled
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1628620 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b0d4739..d68c757 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>20</version>
+ <version>22</version>
<relativePath>../../../parent/pom.xml</relativePath>
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 11/31: SLING-2857 : Fix
the name of the members resource in ResourceCollection.,
Apply patch from Amit Gupta
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit f33455819dd6db44c3fe743f4b59acee5585bf17
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 7 11:19:17 2013 +0000
SLING-2857 : Fix the name of the members resource in ResourceCollection., Apply patch from Amit Gupta
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1479861 13f79535-47bb-0310-9956-ffa450edef68
---
.../impl/ResourceCollectionConstants.java | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionConstants.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionConstants.java
new file mode 100644
index 0000000..bb433f2
--- /dev/null
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionConstants.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resource.collection.impl;
+
+public interface ResourceCollectionConstants {
+ /**
+ * property name to store resource reference in collection entry
+ */
+ static final String REF_PROPERTY = "sling:resource";
+
+ /**
+ * node name for the collection members
+ */
+ static final String MEMBERS_NODE_NAME = "sling:members";
+
+ /**
+ * property name to store list of references in a collection
+ */
+ static final String REFERENCES_PROP = "sling:resources";
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-resourcecollection] 16/31: SLING-2854 :
Move the ResourceCollectionUtil.createUniqueChildName method to
ResourceUtils
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcecollection.git
commit d2aa459f0034d890b5be371514343862df9a5b1c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Sep 3 06:57:26 2013 +0000
SLING-2854 : Move the ResourceCollectionUtil.createUniqueChildName method to ResourceUtils
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1519583 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
.../sling/resource/collection/impl/ResourceCollectionImpl.java | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9df727a..3153b21 100755
--- a/pom.xml
+++ b/pom.xml
@@ -83,7 +83,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.4.0</version>
+ <version>2.4.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
diff --git a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
index f1e937b..cf2f885 100755
--- a/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
+++ b/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java
@@ -38,7 +38,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.sling.resource.collection.ResourceCollection;
-import org.apache.sling.resource.collection.impl.util.ResourceCollectionUtil;
/**
* Implements <code>ResourceCollection</code>
@@ -108,7 +107,7 @@ public class ResourceCollectionImpl implements
properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
resolver.create(
membersResource,
- ResourceCollectionUtil.createUniqueChildName(membersResource,
+ ResourceUtil.createUniqueChildName(membersResource,
res.getName()), properties);
log.debug("added member to resource {} to collection {}",
new String[] { res.getPath(), resource.getPath() });
@@ -133,7 +132,7 @@ public class ResourceCollectionImpl implements
properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
resolver.create(
membersResource,
- ResourceCollectionUtil.createUniqueChildName(membersResource,
+ ResourceUtil.createUniqueChildName(membersResource,
res.getName()), properties);
log.debug("added member to resource {} to collection {}",
new String[] { res.getPath(), resource.getPath() });
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.