@Test public void testFormSubstitution() { String script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3}"; Map<String, Object> params = new HashMap<>(); params.put("input_form", "some_input"); params.put("select_form", "s_op2"); params.put("checkbox_form", new String[]{"c_op1", "c_op3"}); String replaced = Input.getSimpleQuery(params, script); assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1,c_op3", replaced); script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3}\n" + "NEW_CHECKED=${checkbox( and ):new_check=nc_a|nc_c,nc_a|nc_b|nc_c}"; replaced = Input.getSimpleQuery(params, script); assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1,c_op3\n" + "NEW_CHECKED=nc_a and nc_c", replaced); script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=,s_op1|s_op2|s_op3}\n" + "CHECKED=${checkbox:checkbox_form=c_op1|c_op2,c_op1|c_op2|c_op3_new}\n" + "NEW_CHECKED=${checkbox( and ):new_check=nc_a|nc_c,nc_a|nc_b|nc_c}"; replaced = Input.getSimpleQuery(params, script); assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1\n" + "NEW_CHECKED=nc_a and nc_c", replaced); }
public static String getSimpleQuery(Map<String, Object> params, String script) { String replaced = script; Matcher match = VAR_PTN.matcher(replaced); while (match.find()) { Input input = getInputForm(match); Object value; if (params.containsKey(input.name)) { value = params.get(input.name); } else { value = input.defaultValue; } String expanded; if (value instanceof Object[] || value instanceof Collection) { String delimiter = input.argument; if (delimiter == null) { delimiter = DEFAULT_DELIMITER; } Collection<Object> checked = value instanceof Collection ? (Collection<Object>) value : Arrays.asList((Object[]) value); List<Object> validChecked = new LinkedList<>(); for (Object o : checked) { for (ParamOption option : input.getOptions()) { if (option.getValue().equals(o)) { validChecked.add(o); break; } } } params.put(input.name, validChecked); expanded = StringUtils.join(validChecked, delimiter); } else { expanded = value.toString(); } replaced = match.replaceFirst(expanded); match = VAR_PTN.matcher(replaced); } return replaced; }
Input implements Serializable { public static String getSimpleQuery(Map<String, Object> params, String script) { String replaced = script; Matcher match = VAR_PTN.matcher(replaced); while (match.find()) { Input input = getInputForm(match); Object value; if (params.containsKey(input.name)) { value = params.get(input.name); } else { value = input.defaultValue; } String expanded; if (value instanceof Object[] || value instanceof Collection) { String delimiter = input.argument; if (delimiter == null) { delimiter = DEFAULT_DELIMITER; } Collection<Object> checked = value instanceof Collection ? (Collection<Object>) value : Arrays.asList((Object[]) value); List<Object> validChecked = new LinkedList<>(); for (Object o : checked) { for (ParamOption option : input.getOptions()) { if (option.getValue().equals(o)) { validChecked.add(o); break; } } } params.put(input.name, validChecked); expanded = StringUtils.join(validChecked, delimiter); } else { expanded = value.toString(); } replaced = match.replaceFirst(expanded); match = VAR_PTN.matcher(replaced); } return replaced; } }
Input implements Serializable { public static String getSimpleQuery(Map<String, Object> params, String script) { String replaced = script; Matcher match = VAR_PTN.matcher(replaced); while (match.find()) { Input input = getInputForm(match); Object value; if (params.containsKey(input.name)) { value = params.get(input.name); } else { value = input.defaultValue; } String expanded; if (value instanceof Object[] || value instanceof Collection) { String delimiter = input.argument; if (delimiter == null) { delimiter = DEFAULT_DELIMITER; } Collection<Object> checked = value instanceof Collection ? (Collection<Object>) value : Arrays.asList((Object[]) value); List<Object> validChecked = new LinkedList<>(); for (Object o : checked) { for (ParamOption option : input.getOptions()) { if (option.getValue().equals(o)) { validChecked.add(o); break; } } } params.put(input.name, validChecked); expanded = StringUtils.join(validChecked, delimiter); } else { expanded = value.toString(); } replaced = match.replaceFirst(expanded); match = VAR_PTN.matcher(replaced); } return replaced; } Input(String name, Object defaultValue, String type);  Input(String name, Object defaultValue, String type, ParamOption[] options);  Input(String name, String displayName, String type, String argument, Object defaultValue,
      ParamOption[] options, boolean hidden); }
Input implements Serializable { public static String getSimpleQuery(Map<String, Object> params, String script) { String replaced = script; Matcher match = VAR_PTN.matcher(replaced); while (match.find()) { Input input = getInputForm(match); Object value; if (params.containsKey(input.name)) { value = params.get(input.name); } else { value = input.defaultValue; } String expanded; if (value instanceof Object[] || value instanceof Collection) { String delimiter = input.argument; if (delimiter == null) { delimiter = DEFAULT_DELIMITER; } Collection<Object> checked = value instanceof Collection ? (Collection<Object>) value : Arrays.asList((Object[]) value); List<Object> validChecked = new LinkedList<>(); for (Object o : checked) { for (ParamOption option : input.getOptions()) { if (option.getValue().equals(o)) { validChecked.add(o); break; } } } params.put(input.name, validChecked); expanded = StringUtils.join(validChecked, delimiter); } else { expanded = value.toString(); } replaced = match.replaceFirst(expanded); match = VAR_PTN.matcher(replaced); } return replaced; } Input(String name, Object defaultValue, String type);  Input(String name, Object defaultValue, String type, ParamOption[] options);  Input(String name, String displayName, String type, String argument, Object defaultValue,
      ParamOption[] options, boolean hidden); @Override boolean equals(Object o); String getName(); void setName(String name); String getDisplayName(); void setDisplayName(String displayName); String getType(); void setType(String type); Object getDefaultValue(); void setDefaultValue(Object defaultValue); ParamOption[] getOptions(); void setOptions(ParamOption[] options); boolean isHidden(); static LinkedHashMap<String, Input> extractSimpleQueryForm(String script); static String getSimpleQuery(Map<String, Object> params, String script); static String[] split(String str); static String[] splitPipe(String str); static String[] split(String str, char split); static String[] split(String str, String[] splitters, boolean includeSplitter); static String[] split(String str, String escapeSeq, char escapeChar, String[] blockStart,
      String[] blockEnd, String[] splitters, boolean includeSplitter); }
Input implements Serializable { public static String getSimpleQuery(Map<String, Object> params, String script) { String replaced = script; Matcher match = VAR_PTN.matcher(replaced); while (match.find()) { Input input = getInputForm(match); Object value; if (params.containsKey(input.name)) { value = params.get(input.name); } else { value = input.defaultValue; } String expanded; if (value instanceof Object[] || value instanceof Collection) { String delimiter = input.argument; if (delimiter == null) { delimiter = DEFAULT_DELIMITER; } Collection<Object> checked = value instanceof Collection ? (Collection<Object>) value : Arrays.asList((Object[]) value); List<Object> validChecked = new LinkedList<>(); for (Object o : checked) { for (ParamOption option : input.getOptions()) { if (option.getValue().equals(o)) { validChecked.add(o); break; } } } params.put(input.name, validChecked); expanded = StringUtils.join(validChecked, delimiter); } else { expanded = value.toString(); } replaced = match.replaceFirst(expanded); match = VAR_PTN.matcher(replaced); } return replaced; } Input(String name, Object defaultValue, String type);  Input(String name, Object defaultValue, String type, ParamOption[] options);  Input(String name, String displayName, String type, String argument, Object defaultValue,
      ParamOption[] options, boolean hidden); @Override boolean equals(Object o); String getName(); void setName(String name); String getDisplayName(); void setDisplayName(String displayName); String getType(); void setType(String type); Object getDefaultValue(); void setDefaultValue(Object defaultValue); ParamOption[] getOptions(); void setOptions(ParamOption[] options); boolean isHidden(); static LinkedHashMap<String, Input> extractSimpleQueryForm(String script); static String getSimpleQuery(Map<String, Object> params, String script); static String[] split(String str); static String[] splitPipe(String str); static String[] split(String str, char split); static String[] split(String str, String[] splitters, boolean includeSplitter); static String[] split(String str, String escapeSeq, char escapeChar, String[] blockStart,
      String[] blockEnd, String[] splitters, boolean includeSplitter);  }