Here you can find the source of replaceVariables(String chart, Map
public static String replaceVariables(String chart, Map<String, String> variables)
//package com.java2s; //License from project: Mozilla Public License import java.util.Map; public class Main { public static String replaceVariables(String chart, Map<String, String> variables) { //look for special rangetype variable first modifyVariables(variables, true); //replace comments first so if there are variables in the comment, they will not be replaced since //they are removed from the file anyways. chart = chart.replaceAll("\\*\\{[\\w\\W]*?\\}\\*", ""); for (String key : variables.keySet()) { String val = variables.get(key); chart = chart.replaceAll("\\$\\{" + key + "\\}", val); }/*from www .j a v a 2 s . co m*/ return chart; } public static void modifyVariables(Map<String, String> variables, boolean webRequest) { String type = variables.get("_daterangetype"); if (type != null) { String url = variables.get("url"); String shortUrl = addCallbackParam(webRequest, url); variables.put("shortUrl", shortUrl); if ("daterange".equals(type)) { String from = variables.get("_fromepoch"); String to = variables.get("_toepoch"); url += "?start=" + from + "&end=" + to; } else { String number = variables.get("_numberpoints"); String ending = url.substring("/api".length()); if (ending.contains("?")) url = "/api/firstvaluesV1/" + number + ending + "&reverse=true"; else url = "/api/firstvaluesV1/" + number + ending + "?reverse=true"; } url = addCallbackParam(webRequest, url); variables.put("url", url); } } private static String addCallbackParam(boolean webRequest, String url) { if (webRequest) { //add stuff for clean json callback if (url.contains("?")) url = url + "&callback=?"; else url = url + "?callback=?"; } return url; } }