class ParametersMerger {

    public static Object processParametersReplacement(Object initialValue, final HashMap<QName,ParameterValue> parameters) {
        if(initialValue instanceof String) {
            String ret = initialValue.toString();
            if(ret.contains("$[")) {
                for(ParameterValue pv: parameters.values()) {
                    if(pv.getValue() instanceof String) {
                        try {
                            // issue #14
                            ret = ret.replaceAll("\\$\\["+pv.getKey()+"\\]", Matcher.quoteReplacement(pv.getValue().toString()));
                        } catch(java.lang.IllegalArgumentException ex) {
                            LOGGER.error("while replacing "+pv.getKey()+" -> "+pv.getValue(),ex);
                            throw ex;
                        }
                    }
                    if(!ret.contains("$[")) break;
                }
            }
            return ret;
        } else {
            return initialValue;
        }
    }

}