in src/main/java/org/apache/sling/caconfig/impl/override/OverrideStringParser.java [77:147]
public static Collection<OverrideItem> parse(Collection<String> overrideStrings) {
List<OverrideItem> result = new ArrayList<>();
for (String overrideString : overrideStrings) {
// check if override generic pattern is matched
Matcher matcher = OVERRIDE_PATTERN.matcher(StringUtils.defaultString(overrideString));
if (!matcher.matches()) {
log.warn("Ignore config override string - invalid syntax: {}", overrideString);
continue;
}
// get single parts
String path = StringUtils.trim(matcher.group(2));
String configName = StringUtils.trim(matcher.group(3));
String value = StringUtils.trim(StringUtils.defaultString(matcher.group(4)));
OverrideItem item;
try {
// check if value is JSON = defines whole parameter map for a config name
JsonObject json = toJson(value);
if (json != null) {
item = new OverrideItem(path, configName, toMap(json), true);
} else {
// otherwise it defines a key/value pair in a single line
String propertyName = StringUtils.substringAfterLast(configName, "/");
if (StringUtils.isEmpty(propertyName)) {
log.warn("Ignore config override string - missing property name: {}", overrideString);
continue;
}
configName = StringUtils.substringBeforeLast(configName, "/");
Map<String, Object> props = new HashMap<>();
props.put(propertyName, convertJsonValue(value));
item = new OverrideItem(path, configName, props, false);
}
} catch (JsonException ex) {
log.warn(
"Ignore config override string - invalid JSON syntax ({}): {}",
ex.getMessage(),
overrideString);
continue;
}
// validate item
if (!isValid(item, overrideString)) {
continue;
}
// if item does not contain a full property set try to merge with existing one
if (!item.isAllProperties()) {
boolean foundMatchingItem = false;
for (OverrideItem existingItem : result) {
if (!existingItem.isAllProperties()
&& StringUtils.equals(item.getPath(), existingItem.getPath())
&& StringUtils.equals(item.getConfigName(), existingItem.getConfigName())) {
existingItem.getProperties().putAll(item.getProperties());
foundMatchingItem = true;
break;
}
}
if (foundMatchingItem) {
continue;
}
}
// add item to result
result.add(item);
}
return result;
}