Package org.jboss.common.beans.property
Class PropertiesValueResolver
- java.lang.Object
-
- org.jboss.common.beans.property.PropertiesValueResolver
-
public class PropertiesValueResolver extends java.lang.Object
Parses a string and replaces any references to system properties or environment variables in the string
-
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT
private static int
GOT_DOLLAR
private static int
GOT_OPEN_BRACE
private static int
INITIAL
private static int
RESOLVED
-
Constructor Summary
Constructors Constructor Description PropertiesValueResolver()
-
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.
-
-
-
Field Detail
-
INITIAL
private static final int INITIAL
- See Also:
- Constant Field Values
-
GOT_DOLLAR
private static final int GOT_DOLLAR
- See Also:
- Constant Field Values
-
GOT_OPEN_BRACE
private static final int GOT_OPEN_BRACE
- See Also:
- Constant Field Values
-
RESOLVED
private static final int RESOLVED
- See Also:
- Constant Field Values
-
DEFAULT
private static final int DEFAULT
- See Also:
- Constant Field Values
-
-
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 throwsIllegalStateException
.
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.
-
-