/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
/** * Go through the input string and replace any occurance of ${p} with * the System.getProperty(p) value. If there is no such property p defined, * then the ${p} reference will remain unchanged. * * If the property reference is of the form ${p:v} and there is no such property p, * then the default value v will be returned. * * If the property reference is of the form ${p1,p2} or ${p1,p2:v} then * the primary and the secondary properties will be tried in turn, before * returning either the unchanged input, or the default value. * * The property ${/} is replaced with System.getProperty("file.separator") * value and the property ${:} is replaced with System.getProperty("path.separator"). * * @param string - the string with possible ${} references * @return the input string with all property references replaced if any. * If there are no valid references the input string will be returned. */ public static String replaceProperties(final String string) { return replaceProperties(string, null); }
private static Properties loadFromFile(String uri) throws IOException { InputStream inputStream = null; Properties inputProperties = new Properties(); Properties outputProperties = new Properties(); if( new File(uri).exists() ) { inputStream = new FileInputStream(uri); } else { inputStream = new URL(uri).openStream(); } try { inputProperties.loadFromXML(inputStream); } finally { inputStream.close(); } Enumeration namesEnumeration = inputProperties.propertyNames(); while(namesEnumeration.hasMoreElements()) { String propertyName = (String)namesEnumeration.nextElement(); String propertyValue = inputProperties.getProperty(propertyName); propertyValue = propertyValue.trim(); // perform JBossAS style property substitutions. JBTM-369 propertyValue = StringPropertyReplacer.replaceProperties(propertyValue); outputProperties.setProperty(propertyName, propertyValue); } return outputProperties; }
private void secondaryPropertyTest(boolean useSysProps) { String input = "${"+PROP_B+","+PROP_C+"}"; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(VALUE, output); }
private void defaultValueTest(boolean useSysProps) { String input = "${"+PROP_B+":"+DEFAULT+"}"; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(DEFAULT, output); }
private void secondaryPropertyAndMissingTest(boolean useSysProps) { String input = "${"+PROP_B+","+PROP_D+"}"; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(input, output); }
private void secondaryPropertyAndDefaultTest(boolean useSysProps) { String input = "${"+PROP_B+","+PROP_D+":"+DEFAULT+"}"; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(DEFAULT, output); }
private void basicReplacementTest(boolean useSysProps) { String input = "${"+PROP_A+"}"; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(VALUE, output); }
private void missingPropertyTest(boolean useSysProps) { String input = WRAPPER+"${"+PROP_B+"}"+WRAPPER; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(input, output); }
private void wrappedMissingPropertyTest(boolean useSysProps) { String input = WRAPPER+"${"+PROP_B+"}"+WRAPPER; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(input, output); }
private void multipleReplacementTest(boolean useSysProps) { String input = "${"+PROP_A+"}${"+PROP_C+"}"; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(VALUE+VALUE, output); }
private void partialMissingTest(boolean useSysProps) { String badinput = "${"+PROP_B+"}"; String input = WRAPPER+"${"+PROP_A+"}"+badinput+"${"+PROP_C+"}"+WRAPPER; String output = null; if (useSysProps) { setupSystemProperties(); output = replaceProperties(input); } else { output = replaceProperties(input, setupProperties()); } assertEquals(WRAPPER+VALUE+badinput+VALUE+WRAPPER, output); }
@Test public void testNullInput() { try { assertNull(replaceProperties(null)); fail("NPE expected with null input"); } catch (NullPointerException good) {} try { assertNull(replaceProperties(null, setupProperties())); fail("NPE expected with null input"); } catch (NullPointerException good) {} }