private DecoratedText replaceSimpleParameter(DecoratedText text, Map<String, Object> parameters, String head, String tail, String key) { if (tail.startsWith("\n")) { text.append(head + parameters.get(key) + "\n"); tail = tail.substring(1); if (tail.length() > 0) { return replaceParameters(text, tail, parameters); } else { return text; } } else { text.append(head + parameters.get(key)); if (tail.length() > 0) { return replaceParameters(text, tail, parameters); } else { return text; } } } private String replaceSimpleParameter(Map<String, Object> parameters, String head, String tail, String key) {
private DecoratedText replaceParameters(DecoratedText text, String template, Map<String, Object> parameters) { int start = template.indexOf('['); int end = template.indexOf(']'); if (start >= 0 && end > start) { String head = template.substring(0, start); String tail = template.substring(end + 1); if (tail.startsWith(" ")) { tail = tail.substring(1); } String key = template.substring(start + 1, end); Preconditions.checkNotNull(parameters, "Parameters object may not be null"); if (isSpecialKey(key)) { text.append(head); return replaceSpecialParameter(text, parameters, tail, key); } else { Preconditions.checkArgument(parameters.containsKey(key), "Parameters object does not contain key: "+key); return replaceSimpleParameter(text, parameters, head, tail, key); } } text.append(template); return text; } private DecoratedText replaceSpecialParameter(DecoratedText text, Map<String, Object> parameters, String tail, String key) {
text.append(specialNode); return replaceParameters(text, tail, parameters);