Author: cziegeler
Date: Wed Feb 10 13:24:29 2016
New Revision: 1729595
URL: http://svn.apache.org/viewvc?rev=1729595&view=rev
Log:
SLING-5509 : Behaviour Change in Resource#getParent
Modified:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControl.java
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControlTest.java
Modified:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1729595&r1=1729594&r2=1729595&view=diff
==============================================================================
---
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Wed Feb 10 13:24:29 2016
@@ -1299,10 +1299,19 @@ public class ResourceResolverImpl extend
@Override
public Resource getParent(final Resource child) {
- Resource rsrc = this.control.getParent(this.context, child);
- if (rsrc != null ) {
- rsrc.getResourceMetadata().setResolutionPath(rsrc.getPath());
- rsrc = this.factory.getResourceDecoratorTracker().decorate(rsrc);
+ Resource rsrc = null;
+ final String parentPath = ResourceUtil.getParent(child.getPath());
+ if ( parentPath != null ) {
+ // if the parent path is relative, resolve using search paths.
+ if ( !parentPath.startsWith("/") ) {
+ rsrc = context.getResourceResolver().getResource(parentPath);
+ } else {
+ rsrc = this.control.getParent(this.context, parentPath, child);
+ if (rsrc != null ) {
+
rsrc.getResourceMetadata().setResolutionPath(rsrc.getPath());
+ rsrc =
this.factory.getResourceDecoratorTracker().decorate(rsrc);
+ }
+ }
}
return rsrc;
}
Modified:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControl.java?rev=1729595&r1=1729594&r2=1729595&view=diff
==============================================================================
---
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControl.java
(original)
+++
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControl.java
Wed Feb 10 13:24:29 2016
@@ -162,27 +162,24 @@ public class ResourceResolverControl {
* resource provider returns parent for this child. See
* {@link #getResource(String, Resource, Map, boolean)} for more details
*/
- public Resource getParent(final ResourceResolverContext context, final
Resource child) {
- final String parentPath = ResourceUtil.getParent(child.getPath());
- if ( parentPath != null ) {
- final AuthenticatedResourceProvider childProvider =
getBestMatchingProvider(context, child.getPath());
- final AuthenticatedResourceProvider parentProvider =
getBestMatchingProvider(context, parentPath);
- if ( parentProvider != null ) {
- final Resource parentCandidate;
- if ( childProvider == parentProvider ) {
- parentCandidate = parentProvider.getParent(child);
- } else {
- parentCandidate = parentProvider.getResource(parentPath,
null, null);
- }
- if (parentCandidate != null) {
- return parentCandidate;
- }
+ public Resource getParent(@Nonnull final ResourceResolverContext context,
@Nonnull final String parentPath, @Nonnull final Resource child) {
+ final AuthenticatedResourceProvider childProvider =
getBestMatchingProvider(context, child.getPath());
+ final AuthenticatedResourceProvider parentProvider =
getBestMatchingProvider(context, parentPath);
+ if ( parentProvider != null ) {
+ final Resource parentCandidate;
+ if ( childProvider == parentProvider ) {
+ parentCandidate = parentProvider.getParent(child);
+ } else {
+ parentCandidate = parentProvider.getResource(parentPath, null,
null);
}
-
- if (isIntermediatePath(parentPath)) {
- return new SyntheticResource(context.getResourceResolver(),
parentPath, ResourceProvider.RESOURCE_TYPE_SYNTHETIC);
+ if (parentCandidate != null) {
+ return parentCandidate;
}
}
+
+ if (isIntermediatePath(parentPath)) {
+ return new SyntheticResource(context.getResourceResolver(),
parentPath, ResourceProvider.RESOURCE_TYPE_SYNTHETIC);
+ }
return null;
}
Modified:
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java?rev=1729595&r1=1729594&r2=1729595&view=diff
==============================================================================
---
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java
(original)
+++
sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java
Wed Feb 10 13:24:29 2016
@@ -72,39 +72,43 @@ public class LegacyResourceProviderWhite
private Map<Object, List<ServiceRegistration>> registrations = new
HashMap<Object, List<ServiceRegistration>>();
- protected void bindResourceProvider(ServiceReference ref) {
- BundleContext bundleContext = ref.getBundle().getBundleContext();
- ResourceProvider provider = (ResourceProvider)
bundleContext.getService(ref);
- String[] propertyNames = ref.getPropertyKeys();
- boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false);
-
- List<ServiceRegistration> newServices = new
ArrayList<ServiceRegistration>();
- for (String path :
PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
- Dictionary<String, Object> newProps = new Hashtable<String,
Object>();
- newProps.put(PROPERTY_AUTHENTICATE, AuthType.no.toString());
- newProps.put(PROPERTY_MODIFIABLE, provider instanceof
ModifyingResourceProvider);
- newProps.put(PROPERTY_ADAPTABLE, provider instanceof Adaptable);
- newProps.put(PROPERTY_ATTRIBUTABLE, provider instanceof
AttributableResourceProvider);
- newProps.put(PROPERTY_REFRESHABLE, provider instanceof
RefreshableResourceProvider);
- newProps.put(PROPERTY_NAME, provider.getClass().getName());
- newProps.put(PROPERTY_ROOT, normalizePath(path));
- if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
- newProps.put(ORIGINAL_SERVICE_PID,
ref.getProperty(SERVICE_PID));
+ protected void bindResourceProvider(final ServiceReference ref) {
+ final BundleContext bundleContext = ref.getBundle().getBundleContext();
+ final ResourceProvider provider = (ResourceProvider)
bundleContext.getService(ref);
+ if ( provider != null ) {
+ final String[] propertyNames = ref.getPropertyKeys();
+ final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS),
false);
+
+ final List<ServiceRegistration> newServices = new
ArrayList<ServiceRegistration>();
+ for (final String path :
PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
+ if ( path != null && !path.isEmpty() ) {
+ final Dictionary<String, Object> newProps = new
Hashtable<String, Object>();
+ newProps.put(PROPERTY_AUTHENTICATE,
AuthType.no.toString());
+ newProps.put(PROPERTY_MODIFIABLE, provider instanceof
ModifyingResourceProvider);
+ newProps.put(PROPERTY_ADAPTABLE, provider instanceof
Adaptable);
+ newProps.put(PROPERTY_ATTRIBUTABLE, provider instanceof
AttributableResourceProvider);
+ newProps.put(PROPERTY_REFRESHABLE, provider instanceof
RefreshableResourceProvider);
+ newProps.put(PROPERTY_NAME, provider.getClass().getName());
+ newProps.put(PROPERTY_ROOT, normalizePath(path));
+ if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
+ newProps.put(ORIGINAL_SERVICE_PID,
ref.getProperty(SERVICE_PID));
+ }
+ if (ArrayUtils.contains(propertyNames,
USE_RESOURCE_ACCESS_SECURITY)) {
+ newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY,
ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
+ }
+ if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
+ newProps.put(SERVICE_RANKING,
ref.getProperty(SERVICE_RANKING));
+ }
+
+ String[] languages =
PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
+ ServiceRegistration reg = bundleContext.registerService(
+
org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(),
+ new LegacyResourceProviderAdapter(provider,
languages, ownsRoot), newProps);
+ newServices.add(reg);
+ }
}
- if (ArrayUtils.contains(propertyNames,
USE_RESOURCE_ACCESS_SECURITY)) {
- newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY,
ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
- }
- if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
- newProps.put(SERVICE_RANKING,
ref.getProperty(SERVICE_RANKING));
- }
-
- String[] languages =
PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
- ServiceRegistration reg = bundleContext.registerService(
-
org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(),
- new LegacyResourceProviderAdapter(provider, languages,
ownsRoot), newProps);
- newServices.add(reg);
+ registrations.put(provider, newServices);
}
- registrations.put(provider, newServices);
}
protected void unbindResourceProvider(final ResourceProvider provider,
final Map<String, Object> props) {
@@ -113,42 +117,46 @@ public class LegacyResourceProviderWhite
}
}
- protected void bindResourceProviderFactory(ServiceReference ref) {
- BundleContext bundleContext = ref.getBundle().getBundleContext();
- ResourceProviderFactory factory = (ResourceProviderFactory)
bundleContext.getService(ref);
- String[] propertyNames = ref.getPropertyKeys();
- boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false);
-
- List<ServiceRegistration> newServices = new
ArrayList<ServiceRegistration>();
- for (String path :
PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
- Dictionary<String, Object> newProps = new Hashtable<String,
Object>();
- if (PropertiesUtil.toBoolean(ref.getProperty(PROPERTY_REQUIRED),
false)) {
- newProps.put(PROPERTY_AUTHENTICATE,
AuthType.required.toString());
- } else {
- newProps.put(PROPERTY_AUTHENTICATE, AuthType.lazy.toString());
- }
- newProps.put(PROPERTY_MODIFIABLE, true);
- newProps.put(PROPERTY_ADAPTABLE, true);
- newProps.put(PROPERTY_ATTRIBUTABLE, true);
- newProps.put(PROPERTY_REFRESHABLE, true);
- newProps.put(PROPERTY_NAME, factory.getClass().getName());
- newProps.put(PROPERTY_ROOT, normalizePath(path));
- if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
- newProps.put(ORIGINAL_SERVICE_PID,
ref.getProperty(SERVICE_PID));
- }
- if (ArrayUtils.contains(propertyNames,
USE_RESOURCE_ACCESS_SECURITY)) {
- newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY,
ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
- }
- if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
- newProps.put(SERVICE_RANKING,
ref.getProperty(SERVICE_RANKING));
+ protected void bindResourceProviderFactory(final ServiceReference ref) {
+ final BundleContext bundleContext = ref.getBundle().getBundleContext();
+ final ResourceProviderFactory factory = (ResourceProviderFactory)
bundleContext.getService(ref);
+ if ( factory != null ) {
+ final String[] propertyNames = ref.getPropertyKeys();
+ final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS),
false);
+
+ final List<ServiceRegistration> newServices = new
ArrayList<ServiceRegistration>();
+ for (final String path :
PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
+ if ( path != null && !path.isEmpty() ) {
+ final Dictionary<String, Object> newProps = new
Hashtable<String, Object>();
+ if
(PropertiesUtil.toBoolean(ref.getProperty(PROPERTY_REQUIRED), false)) {
+ newProps.put(PROPERTY_AUTHENTICATE,
AuthType.required.toString());
+ } else {
+ newProps.put(PROPERTY_AUTHENTICATE,
AuthType.lazy.toString());
+ }
+ newProps.put(PROPERTY_MODIFIABLE, true);
+ newProps.put(PROPERTY_ADAPTABLE, true);
+ newProps.put(PROPERTY_ATTRIBUTABLE, true);
+ newProps.put(PROPERTY_REFRESHABLE, true);
+ newProps.put(PROPERTY_NAME, factory.getClass().getName());
+ newProps.put(PROPERTY_ROOT, normalizePath(path));
+ if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
+ newProps.put(ORIGINAL_SERVICE_PID,
ref.getProperty(SERVICE_PID));
+ }
+ if (ArrayUtils.contains(propertyNames,
USE_RESOURCE_ACCESS_SECURITY)) {
+ newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY,
ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
+ }
+ if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
+ newProps.put(SERVICE_RANKING,
ref.getProperty(SERVICE_RANKING));
+ }
+ String[] languages =
PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
+ ServiceRegistration reg = bundleContext.registerService(
+
org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(),
+ new LegacyResourceProviderFactoryAdapter(factory,
languages, ownsRoot), newProps);
+ newServices.add(reg);
+ }
}
- String[] languages =
PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
- ServiceRegistration reg = bundleContext.registerService(
-
org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(),
- new LegacyResourceProviderFactoryAdapter(factory,
languages, ownsRoot), newProps);
- newServices.add(reg);
+ registrations.put(factory, newServices);
}
- registrations.put(factory, newServices);
}
protected void unbindResourceProviderFactory(final ResourceProviderFactory
factory,
@@ -158,7 +166,7 @@ public class LegacyResourceProviderWhite
}
}
- private static String normalizePath(String path) {
+ private static String normalizePath(final String path) {
String result = path;
result = StringUtils.removeEnd(path, "/");
if (result != null && !result.startsWith("/")) {
Modified:
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControlTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControlTest.java?rev=1729595&r1=1729594&r2=1729595&view=diff
==============================================================================
---
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControlTest.java
(original)
+++
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverControlTest.java
Wed Feb 10 13:24:29 2016
@@ -224,7 +224,7 @@ public class ResourceResolverControlTest
*/
@Test
public void getParent_found() {
- Resource parent = crp.getParent(context, somethingResource);
+ Resource parent = crp.getParent(context,
ResourceUtil.getParent(somethingResource.getPath()), somethingResource);
assertThat(parent, notNullValue());
assertThat("parent.path", parent.getPath(), equalTo("/"));
}
@@ -236,7 +236,7 @@ public class ResourceResolverControlTest
*/
@Test
public void getParent_synthetic() {
- Resource parent = crp.getParent(context, subProviderResource);
+ Resource parent = crp.getParent(context,
ResourceUtil.getParent(subProviderResource.getPath()), subProviderResource);
assertThat(parent, notNullValue());
assertTrue("parent is a synthetic resource",
ResourceUtil.isSyntheticResource(parent));
}
@@ -258,7 +258,7 @@ public class ResourceResolverControlTest
assertNotNull(child);
assertTrue(childResource == child);
- Resource parent = crp.getParent(context, child);
+ Resource parent = crp.getParent(context,
ResourceUtil.getParent(child.getPath()), child);
assertNotNull(parent);
assertTrue(parentResource == parent);
}