code: private String replaceTokens(String text, Map<String, Object> replacements) {
          Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}");
          Matcher matcher = pattern.matcher(text);
          StringBuffer buffer = new StringBuffer();
          while (matcher.find()) {
              Object replacement = replacements.get(matcher.group(1));
              matcher.appendReplacement(buffer, "");
  
              if (replacement != null) {
                  buffer.append(replacement.toString());
              }
          }
          matcher.appendTail(buffer);
          return buffer.toString();
      }
docs: Replace ${...} placeholders in a string looking up in a replacement map.
  
  @param text         the text to replace.
  @param replacements the map of replacements.
  @return the replaced text.