Commit 82018905 authored by Nico Mack's avatar Nico Mack

Implemented capability to escape (double $$) variable definitions in

templates
parent 7aa8b1c2
......@@ -18,6 +18,7 @@ package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.StringUtils;
import com.google.common.base.Strings;
......@@ -60,9 +61,11 @@ public class BootstrappingUtils {
// private static final Pattern INDEXED_PATTERN =
// Pattern.compile("\\$\\{([a-z0-9\\-_]+)(\\[\\$\\{([a-z0-9\\-_]+)\\}\\])?\\}",
// Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern BOOTSTRAP_VAR_PATTERN = Pattern.compile("\\$\\{([a-z0-9\\-_]+)\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern BOOTSTRAP_VAR_PATTERN = Pattern.compile("(\\${1,2})\\{([a-z0-9\\-_]+)\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern ANGLE_PATTERN = Pattern.compile("([+-]?\\d+.?\\d*)\\s*(deg|rad)??", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final String VAR_TEMPLATE = "${{}}"; //$NON-NLS-1$
private static final Logger LOGGER = LoggerFactory.getLogger(BootstrappingUtils.class.getSimpleName());
private static final String DEGREES = "deg"; //$NON-NLS-1$
......@@ -98,6 +101,7 @@ public class BootstrappingUtils {
StringBuilder expression = new StringBuilder();
Matcher bootstrapVarMatcher = BOOTSTRAP_VAR_PATTERN.matcher(content);
int position = 0;
String prefix;
String identifier;
Object result = null;
boolean evalRequired = false;
......@@ -105,13 +109,19 @@ public class BootstrappingUtils {
while (bootstrapVarMatcher.find()) {
evalRequired = true;
expression.append(content.substring(position, bootstrapVarMatcher.start()));
identifier = bootstrapVarMatcher.group(1);
if (context.hasProperty(identifier)) {
script.put(identifier, context.getProperty(identifier));
expression.append(identifier);
prefix = bootstrapVarMatcher.group(1);
identifier = bootstrapVarMatcher.group(2);
if (prefix.length() == 1) {
if (context.hasProperty(identifier)) {
script.put(identifier, context.getProperty(identifier));
expression.append(identifier);
} else {
LOGGER.warn("Expression refers to an undefined variable {}!", identifier); //$NON-NLS-1$
}
} else {
LOGGER.warn("Expression refers to an undefined variable {}!", identifier); //$NON-NLS-1$
expression.append(StringUtils.build(VAR_TEMPLATE, identifier));
}
position = bootstrapVarMatcher.end();
}
......
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