You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2016/11/02 10:22:06 UTC
svn commit: r1767627 -
/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
Author: cziegeler
Date: Wed Nov 2 10:22:06 2016
New Revision: 1767627
URL: http://svn.apache.org/viewvc?rev=1767627&view=rev
Log:
SLING-6229 : Allow configuration of fallback properties in DefaultContextPathStrategy
Modified:
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
Modified: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java?rev=1767627&r1=1767626&r2=1767627&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java (original)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultContextPathStrategy.java Wed Nov 2 10:22:06 2016
@@ -26,6 +26,7 @@ import java.util.NoSuchElementException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.caconfig.resource.spi.ContextPathStrategy;
import org.apache.sling.caconfig.resource.spi.ContextResource;
import org.osgi.service.component.annotations.Activate;
@@ -53,6 +54,10 @@ public class DefaultContextPathStrategy
" If the list is not empty than only those listed resources are used for look up. If you want to include the current resource you can use a dot for the value.")
String[] configRefResourceNames();
+ @AttributeDefinition(name="Config ref. property names",
+ description = "Additional property names to " + PROPERTY_CONFIG_REF + " to look up a configuration reference. The names are used in the order defined, "
+ + "always starting with " + PROPERTY_CONFIG_REF + ". Once a property with a value is found, that value is used and the following property names are skipped.")
+ String[] configRefPropertyNames();
}
private final Logger log = LoggerFactory.getLogger(this.getClass());
@@ -126,14 +131,28 @@ public class DefaultContextPathStrategy
return null;
}
+ private String getConfigRefValue(final Resource resource) {
+ final ValueMap map = resource.getValueMap();
+ String val = map.get(PROPERTY_CONFIG_REF, String.class);
+ if ( val == null && !ArrayUtils.isEmpty(config.configRefPropertyNames()) ) {
+ for(final String name : config.configRefPropertyNames()) {
+ val = map.get(name, String.class);
+ if ( val != null ) {
+ break;
+ }
+ }
+ }
+ return val;
+ }
+
private String getConfigRef(final Resource resource) {
if (ArrayUtils.isEmpty(config.configRefResourceNames())) {
- return resource.getValueMap().get(PROPERTY_CONFIG_REF, String.class);
+ return getConfigRefValue(resource);
}
- for (String name : config.configRefResourceNames()) {
- Resource lookupResource = resource.getChild(name);
+ for (final String name : config.configRefResourceNames()) {
+ final Resource lookupResource = resource.getChild(name);
if (lookupResource != null) {
- String configRef = lookupResource.getValueMap().get(PROPERTY_CONFIG_REF, String.class);
+ String configRef = getConfigRefValue(lookupResource);
if (configRef != null) {
return configRef;
}
@@ -141,7 +160,6 @@ public class DefaultContextPathStrategy
}
return null;
}
-
}
}