Input implements Serializable { public static String getSimpleQuery(Map<String, Object> params, String script, boolean noteForm) { String replaced = script; Pattern pattern = noteForm ? VAR_NOTE_PTN : VAR_PTN; Matcher match = pattern.matcher(replaced); while (match.find()) { int first = match.start(); if (!noteForm && first > 0 && replaced.charAt(first - 1) == '$') { continue; } Input input = getInputForm(match); Object value; if (params.containsKey(input.name)) { value = params.get(input.name); } else { value = input.getDefaultValue(); } String expanded; if (value instanceof Object[] || value instanceof Collection) { OptionInput optionInput = (OptionInput) input; 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) { if (optionInput.getOptions() != null) { for (ParamOption option : optionInput.getOptions()) { if (option.getValue().equals(o)) { validChecked.add(o); break; } } } } if (validChecked.isEmpty()) { expanded = StringUtils.join(checked, delimiter); } else { params.put(input.name, validChecked); expanded = StringUtils.join(validChecked, delimiter); } } else { expanded = value.toString(); } replaced = match.replaceFirst(expanded); match = pattern.matcher(replaced); } return replaced; } Input(); boolean isHidden(); String getName(); T getDefaultValue(); String getDisplayName(); void setDisplayName(String displayName); void setArgument(String argument); void setHidden(boolean hidden); String getArgument(); @Override boolean equals(Object o); @Override int hashCode(); static TextBox textbox(String name, String defaultValue); static Select select(String name, Object defaultValue, ParamOption[] options); static CheckBox checkbox(String name, Object[] defaultChecked, ParamOption[] options); static LinkedHashMap<String, Input> extractSimpleQueryForm(String script,
                                                                    boolean noteForm); static String getSimpleQuery(Map<String, Object> params, String script, boolean noteForm); 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); static final RuntimeTypeAdapterFactory TypeAdapterFactory; }
@Test public void testFormSubstitution() { String script = "INPUT=${input_form=}SELECTED=${select_form(Selection Form)=" + ",s_op1|s_op2|s_op3}\nCHECKED=${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, false); 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, false); 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, false); assertEquals("INPUT=some_inputSELECTED=s_op2\nCHECKED=c_op1\n" + "NEW_CHECKED=nc_a and nc_c", replaced); }