Author: cziegeler Date: Wed Aug 9 15:41:09 2017 New Revision: 1804554 URL: http://svn.apache.org/viewvc?rev=1804554&view=rev Log: SLING-7040 : Update commons lang 2.x to 3.5
Modified: sling/trunk/contrib/extensions/collection/pom.xml sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java Modified: sling/trunk/contrib/extensions/collection/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/pom.xml?rev=1804554&r1=1804553&r2=1804554&view=diff ============================================================================== --- sling/trunk/contrib/extensions/collection/pom.xml (original) +++ sling/trunk/contrib/extensions/collection/pom.xml Wed Aug 9 15:41:09 2017 @@ -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> Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java?rev=1804554&r1=1804553&r2=1804554&view=diff ============================================================================== --- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java (original) +++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollection.java Wed Aug 9 15:41:09 2017 @@ -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. */ Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java?rev=1804554&r1=1804553&r2=1804554&view=diff ============================================================================== --- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java (original) +++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/ResourceCollectionManager.java Wed Aug 9 15:41:09 2017 @@ -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.Res * The ResourceCollectionManager service can be retrieved by looking it up from the * service registry or by adapting a {@link ResourceResolver}. */ +@ProviderType public interface ResourceCollectionManager { /** Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java?rev=1804554&r1=1804553&r2=1804554&view=diff ============================================================================== --- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java (original) +++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionAdapterFactory.java Wed Aug 9 15:41:09 2017 @@ -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) { Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java?rev=1804554&r1=1804553&r2=1804554&view=diff ============================================================================== --- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java (original) +++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionImpl.java Wed Aug 9 15:41:09 2017 @@ -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.Res 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 impl /** * Creates a new collection from the given resource - * + * * @param resource the resource */ public ResourceCollectionImpl(Resource resource) { @@ -75,10 +74,11 @@ public class ResourceCollectionImpl impl 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 impl /** * {@inheritDoc} */ + @Override public String getPath() { return resource.getPath(); } @@ -93,16 +94,17 @@ public class ResourceCollectionImpl impl /** * {@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 impl 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 impl 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 impl /** * {@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 impl //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 impl 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 impl 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; } } Modified: sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java?rev=1804554&r1=1804553&r2=1804554&view=diff ============================================================================== --- sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java (original) +++ sling/trunk/contrib/extensions/collection/src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java Wed Aug 9 15:41:09 2017 @@ -22,14 +22,14 @@ package org.apache.sling.resource.collec 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 ResourceCollectionManagerIm /** * {@inheritDoc} */ + @Override public ResourceCollection getCollection(Resource resource) { if (resource != null) { if (resource.isResourceType(ResourceCollection.RESOURCE_TYPE)) { @@ -65,6 +68,7 @@ public class ResourceCollectionManagerIm /** * {@inheritDoc} */ + @Override public ResourceCollection createCollection(Resource parentResource, String name) throws PersistenceException { return createCollection(parentResource, name, null); @@ -73,6 +77,7 @@ public class ResourceCollectionManagerIm /** * {@inheritDoc} */ + @Override public ResourceCollection createCollection(Resource parentResource, String name, Map<String, Object> properties) throws PersistenceException { @@ -85,7 +90,7 @@ public class ResourceCollectionManagerIm } 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 ResourceCollectionManagerIm * * @throws PersistenceException */ + @Override public boolean deleteCollection(Resource resource) throws PersistenceException { if (resource != null) {