Skip to content

Instantly share code, notes, and snippets.

@maeste
Created January 26, 2011 08:38
Show Gist options
  • Select an option

  • Save maeste/796425 to your computer and use it in GitHub Desktop.

Select an option

Save maeste/796425 to your computer and use it in GitHub Desktop.
/**
* System property substitution
* @param input The input string
* @return The output
*/
protected String getSubstitutionValue(String input)
{
if (input == null || input.trim().equals(""))
return input;
while (input.indexOf("${") != -1)
{
int from = input.indexOf("${");
int to = input.indexOf("}");
int dv = input.indexOf(":", from + 2);
if (dv != -1)
{
if (dv > to)
dv = -1;
}
String systemProperty = "";
String defaultValue = "";
if (dv == -1)
{
String s = input.substring(from + 2, to);
if ("/".equals(s))
{
systemProperty = File.separator;
}
else if (":".equals(s))
{
systemProperty = File.pathSeparator;
}
else
{
systemProperty = SecurityActions.getSystemProperty(s);
}
}
else
{
systemProperty = SecurityActions.getSystemProperty(input.substring(from + 2, dv));
defaultValue = input.substring(dv + 1, to);
}
String prefix = "";
String postfix = "";
if (from != 0)
{
prefix = input.substring(0, from);
}
if (to + 1 < input.length() - 1)
{
postfix = input.substring(to + 1);
}
if (systemProperty != null && !systemProperty.trim().equals(""))
{
input = prefix + systemProperty + postfix;
}
else if (defaultValue != null && !defaultValue.trim().equals(""))
{
input = prefix + defaultValue + postfix;
}
}
return input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment