feature/use-case-acceptance-tests-2 #117
@ -6,6 +6,7 @@ import java.net.URLEncoder;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -121,19 +122,24 @@ public class TemplateResolver {
|
|||||||
skipChar('}');
|
skipChar('}');
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object propVal(final String name) {
|
private Object propVal(final String nameExpression) {
|
||||||
if (name.endsWith(IF_NOT_FOUND_SYMBOL)) {
|
if (nameExpression.endsWith(IF_NOT_FOUND_SYMBOL)) {
|
||||||
final String pureName = name.substring(0, name.length() - IF_NOT_FOUND_SYMBOL.length());
|
final String pureName = nameExpression.substring(0, nameExpression.length() - IF_NOT_FOUND_SYMBOL.length());
|
||||||
return properties.get(pureName);
|
return properties.get(pureName);
|
||||||
} else if (name.contains(IF_NOT_FOUND_SYMBOL)) {
|
} else if (nameExpression.contains(IF_NOT_FOUND_SYMBOL)) {
|
||||||
final var parts = StringUtils.split(name, IF_NOT_FOUND_SYMBOL);
|
final var parts = StringUtils.split(nameExpression, IF_NOT_FOUND_SYMBOL);
|
||||||
final var head = properties.get(parts[0]);
|
return Arrays.stream(parts).filter(Objects::nonNull).findFirst().orElseGet(() -> {
|
||||||
final var tail = properties.get(parts[1]);
|
if ( parts[parts.length-1].isEmpty() ) {
|
||||||
return head != null ? head : tail; // FIXME: What if tail is null as well?
|
// => whole expression ends with IF_NOT_FOUND_SYMBOL, thus last null element was optional
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// => last alternative element in expression was null and not optional
|
||||||
|
throw new IllegalStateException("Missing required value in property-chain: " + nameExpression);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
final var val = properties.get(name);
|
final var val = properties.get(nameExpression);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
throw new IllegalStateException("Missing required property: " + name);
|
throw new IllegalStateException("Missing required property: " + nameExpression);
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user