Author: cziegeler
Date: Wed Nov 2 15:14:54 2016
New Revision: 1767703
URL: http://svn.apache.org/viewvc?rev=1767703&view=rev
Log:
SLING-6233 : Allow configuration of fallback properties for inheritance
Modified:
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
Modified:
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java?rev=1767703&r1=1767702&r2=1767703&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
(original)
+++
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
Wed Nov 2 15:14:54 2016
@@ -36,6 +36,7 @@ import org.apache.commons.collections.it
import org.apache.commons.collections.iterators.FilterIterator;
import org.apache.commons.collections.iterators.IteratorChain;
import org.apache.commons.collections.iterators.TransformIterator;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
@@ -75,6 +76,16 @@ public class DefaultConfigurationResourc
@AttributeDefinition(name="Fallback paths",
description = "Global fallback configurations, ordered from
most specific (checked first) to least specific.")
String[] fallbackPaths() default {"/conf/global", "/apps/conf",
"/libs/conf"};
+
+ @AttributeDefinition(name="Config collection inheritance property
names",
+ description = "Additional property names to " +
PROPERTY_CONFIG_COLLECTION_INHERIT + " to handle configuration inheritance. The
names are used in the order defined, "
+ + "always starting with " +
PROPERTY_CONFIG_COLLECTION_INHERIT + ". Once a property with a value is found,
that value is used and the following property names are skipped.")
+ String[] configCollectionInheritancePropertyNames();
+
+ @AttributeDefinition(name="Config property inheritance property names",
+ description = "Additional property names to " +
PROPERTY_CONFIG_PROPERTY_INHERIT + " to handle property inheritance. The names
are used in the order defined, "
+ + "always starting with " +
PROPERTY_CONFIG_PROPERTY_INHERIT + ". Once a property with a value is found,
that value is used and the following property names are skipped.")
+ String[] configPropertyInheritancePropertyNames();
}
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -218,7 +229,7 @@ public class DefaultConfigurationResourc
final Resource item =
contentResource.getResourceResolver().getResource(buildResourcePath(path,
name));
if (item != null) {
logger.debug("Resolved config item at [{}]: {}", idx,
item.getPath());
-
+
if (propertyInheritance) {
// merge property map with values from inheritance parent
Map<String,Object> mergedValueMap = new
HashMap<>(item.getValueMap());
@@ -298,8 +309,9 @@ public class DefaultConfigurationResourc
}
// check collection and property inheritance mode on current
level - should we check on next-highest level as well?
- inheritCollection =
item.getValueMap().get(PROPERTY_CONFIG_COLLECTION_INHERIT, false);
- inheritProperties =
item.getValueMap().get(PROPERTY_CONFIG_PROPERTY_INHERIT, false);
+ final ValueMap valueMap = item.getValueMap();
+ inheritCollection = getBooleanValue(valueMap,
PROPERTY_CONFIG_COLLECTION_INHERIT,
config.configCollectionInheritancePropertyNames());
+ inheritProperties = getBooleanValue(valueMap,
PROPERTY_CONFIG_PROPERTY_INHERIT,
config.configPropertyInheritancePropertyNames());
inherit = inheritCollection || inheritProperties;
if (!inherit) {
break;
@@ -316,7 +328,7 @@ public class DefaultConfigurationResourc
if (logger.isTraceEnabled()) {
logger.trace("- final list has {} items", result.size());
}
-
+
// replace config resources with wrappers with merged properties if
property inheritance was applied
if (propertyInheritanceApplied) {
List<Resource> transformedResult = new ArrayList<>();
@@ -341,6 +353,19 @@ public class DefaultConfigurationResourc
return !StringUtils.equals(resource.getName(), "jcr:content");
}
+ private boolean getBooleanValue(final ValueMap valueMap, final String key,
final String[] additionalKeys) {
+ Boolean result = valueMap.get(key, Boolean.class);
+ if ( result != null && !ArrayUtils.isEmpty(additionalKeys) ) {
+ for(final String name : additionalKeys) {
+ result = valueMap.get(name, Boolean.class);
+ if ( result != null ) {
+ break;
+ }
+ }
+ }
+ return result == null ? false : result.booleanValue();
+ }
+
@Override
public String getResourcePath(Resource contentResource, String bucketName,
String configName) {
if (!isEnabledAndParamsValid(contentResource, bucketName, configName))
{