Commit 44ab3196 authored by Nico Mack's avatar Nico Mack

readTemplate returns empty string if specified template is null

parent aae4c660
......@@ -141,7 +141,7 @@ public class TangibleInterfaceManager extends Stage {
/**
* Constructor initialising several fields and setting up the basic interface.
*
* @param applicationContext
* @param properties
* The {@link TangibleApplication} hosting this manager.
* @param properties
* The properties instance from which to load the default values from.
......@@ -248,35 +248,35 @@ public class TangibleInterfaceManager extends Stage {
// ---------------------------------------------------------------------------
private String renderTemplate(String template, Map<String, Object> placeholders) {
Matcher variableMatcher;
int position = 0;
StringBuilder rendered = new StringBuilder();
variableMatcher = VARIABLE_PATTERN.matcher(template);
while (variableMatcher.find()) {
String fromStart = template.substring(position, variableMatcher.start());
if (Strings.isNotBlank(fromStart)) {
rendered.append(fromStart);
}
String identifier = variableMatcher.group(1);
if (template != null) {
variableMatcher = VARIABLE_PATTERN.matcher(template);
while (variableMatcher.find()) {
String fromStart = template.substring(position, variableMatcher.start());
if (Strings.isNotBlank(fromStart)) {
rendered.append(fromStart);
}
String identifier = variableMatcher.group(1);
if ((identifier != null) && (!identifier.isEmpty())) {
if (placeholders.containsKey(identifier)) {
rendered.append(placeholders.get(identifier));
if ((identifier != null) && (!identifier.isEmpty())) {
if (placeholders.containsKey(identifier)) {
rendered.append(placeholders.get(identifier));
} else {
LOGGER.warn("Encountered reference to unknown placeholder {}!", identifier); //$NON-NLS-1$
}
} else {
LOGGER.warn("Encountered reference to unknown placeholder {}!", identifier); //$NON-NLS-1$
rendered.append(template.substring(variableMatcher.start(), variableMatcher.end()));
}
} else {
rendered.append(template.substring(variableMatcher.start(), variableMatcher.end()));
position = variableMatcher.end();
}
String untilEnd = template.substring(position);
if (Strings.isNotBlank(untilEnd)) {
rendered.append(untilEnd);
}
position = variableMatcher.end();
}
String untilEnd = template.substring(position);
if (Strings.isNotBlank(untilEnd)) {
rendered.append(untilEnd);
}
return rendered.toString();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment