public static String resolvePath ( String input ) { if ( null == input ) { return input ; } // matching for 2 groups match ${VAR_NAME} or $VAR_NAME Pattern pathPattern = Pattern . compile ( "\\$\\{(.+?)\\}" ) ; Matcher matcherPattern = pathPattern . matcher ( input ) ; // get a matcher // object StringBuffer sb = new StringBuffer ( ) ; EnvironmentConfiguration config = new EnvironmentConfiguration ( ) ; SystemConfiguration sysConfig = new SystemConfiguration ( ) ; while ( matcherPattern . find ( ) ) { String confVarName = matcherPattern . group ( 1 ) != null ? matcherPattern . group ( 1 ) : matcherPattern . group ( 2 ) ; String envConfVarValue = config . getString ( confVarName ) ; String sysVarValue = sysConfig . getString ( confVarName ) ; if ( envConfVarValue != null ) { matcherPattern . appendReplacement ( sb , envConfVarValue ) ; } else if ( sysVarValue != null ) { matcherPattern . appendReplacement ( sb , sysVarValue ) ; } else { matcherPattern . appendReplacement ( sb , "" ) ; } } matcherPattern . appendTail ( sb ) ; return sb . toString ( ) ; }
Resolves variable in path given as string