JBoss Common Beans 1.1.0.Final-redhat-1

org.jboss.common.beans.property
Class PropertiesValueResolver

java.lang.Object
  extended by org.jboss.common.beans.property.PropertiesValueResolver

public class PropertiesValueResolver
extends Object

Parses a string and replaces any references to system properties or environment variables in the string

Author:
Jaikiran Pai (copied from JBoss DMR project), David M. Lloyd

Constructor Summary
PropertiesValueResolver()
           
 
Method Summary
static String replaceProperties(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 String replaceProperties(String value)
                                throws 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:
IllegalStateException - - thrown when state of properties does not allow to replace all variable references.

JBoss Common Beans 1.1.0.Final-redhat-1

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.