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 { 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; } }  static HashMap<QName,ParameterValue> merge(final HashMap<QName,ParameterValue> highPriority, final HashMap<QName,ParameterValue> lowPriority); static Object processParametersReplacement(Object initialValue, final HashMap<QName,ParameterValue> parameters); static String processParametersReplacement(String initialValue, final HashMap<QName,ParameterValue> parameters); static HashMap<QName,ParameterValue> addInputInParameters(final HashMap<QName,ParameterValue> parameters, final File inputFile, final DatatypeFactory factory); static final QName INPUT_BASENAME; static final QName INPUT_NAME; static final QName INPUT_EXTENSION; static final QName INPUT_ABSOLUTE; static final QName INPUT_RELATIVE_FILE; static final QName INPUT_RELATIVE_DIR; static final QName GP_STATIC_BASE_URI; }
@Test public void initialContainsBackslash() { String initial = "C:\\Users\\ext-cmarchand\\$[source]"; HashMap<QName, ParameterValue> parameters = new HashMap<>(); QName qn = new QName("source"); parameters.put(qn, new ParameterValue(qn,"src/main/xsl", factory.XS_STRING)); String ret = ParametersMerger.processParametersReplacement(initial, parameters); assertEquals("C:\\Users\\ext-cmarchand\\src/main/xsl", ret); }
@Test public void noReplacementForXdmValue() { XdmValue initial = new XdmAtomicValue(BigDecimal.ZERO); HashMap<QName, ParameterValue> parameters = new HashMap<>(); QName qn = new QName("source"); parameters.put(qn, new ParameterValue(qn,"src/main/xsl", factory.XS_STRING)); Object ret = ParametersMerger.processParametersReplacement(initial, parameters); assertTrue(ret instanceof XdmValue); assertEquals(((XdmValue)ret).toString(), "0"); }