Class PropertiesValueResolver


  • public class PropertiesValueResolver
    extends java.lang.Object
    Parses a string and replaces any references to system properties or environment variables in the string
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String replaceProperties​(java.lang.String value)
      Replace properties of the form: ${<[env.]name>[,<[env.]name2>[,<[env.]name3>...]][:<default>]} Method inspects given string and replaces all encountered properties.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PropertiesValueResolver

        public PropertiesValueResolver()
    • Method Detail

      • replaceProperties

        public static java.lang.String replaceProperties​(java.lang.String value)
                                                  throws java.lang.IllegalStateException
        Replace properties of the form: ${<[env.]name>[,<[env.]name2>[,<[env.]name3>...]][:<default>]} Method inspects given string and replaces all encountered properties. If method is able to replace all properties, it returns String with replaced values. If it fails to replace property and ${} does not contain default declaration, method throws IllegalStateException.
        Example1:
         String toReplace = "userLang=${user.language};user=${env.USER}";
         String result    = "userLang=en;user=santa";
         

        Example2:
         String toReplace = "userLang=${IDoneExist,user.language};user=${ImNotThereEither,env.USER}";
         String result    = "userLang=en;user=santa";
         

        Example3:
         String toReplace = "userLang=${IDoneExist:user.language};user=${ImNotThereEither,env.USER:defaultWontBeUsed}";
         String result    = "userLang=user.language;user=santa";
         
        NOTE: in Example 3 value of userLang in result String. The default value IS NOT RESOLVED. It is used as fallback value.
        Parameters:
        value - - string containig system or env variable reference(s)
        Returns:
        the value of the system property or environment variable referenced if it exists
        Throws:
        java.lang.IllegalStateException - - thrown when state of properties does not allow to replace all variable references.