org.gloin.resource.misc
Class PropertyExpander

java.lang.Object
  |
  +--org.gloin.resource.misc.PropertyExpander

public class PropertyExpander
extends java.lang.Object

A utility class to resolve property variables embedded in a string. Strings of the form ${some.property.name} and $some.property.name are resolved to be the value of the system property of that name or the value stored for that property in the overrides list. The override list takes precedence over system bindings. Also, the special $/ and $: properties are resolved to be the same as file.separator and file.pathSeparator. If a property is not set, an empty string will replace the occurrence of the property variable. The syntax for variable specification is described in the documentation for the expand method in this class.

See Also:
expand(java.lang.String[])

Inner Class Summary
static class PropertyExpander.ExpandException
           
 
Constructor Summary
PropertyExpander()
           
PropertyExpander(java.util.Properties overrides)
           
 
Method Summary
 java.lang.String expand(java.lang.String toExpand)
          Expand property variables specified in toExpand by performing various substitutions on that string.
 java.lang.String[] expand(java.lang.String[] toExpand)
          Expand an array of strings by calling the expand(String toExpand) method of this class.
 java.lang.String getValue(java.lang.String name)
           
 void setOverride(java.lang.String name, java.lang.String newValue)
           
 void setOverrides(java.util.Properties overrides)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyExpander

public PropertyExpander()

PropertyExpander

public PropertyExpander(java.util.Properties overrides)
Method Detail

setOverride

public void setOverride(java.lang.String name,
                        java.lang.String newValue)

setOverrides

public void setOverrides(java.util.Properties overrides)

getValue

public java.lang.String getValue(java.lang.String name)

expand

public java.lang.String[] expand(java.lang.String[] toExpand)
                          throws PropertyExpander.ExpandException
Expand an array of strings by calling the expand(String toExpand) method of this class.
Parameters:
toExpand - The arry of strings to expand.
Returns:
The array of strings in expanded form.
See Also:
javasoft.sqe.javatest.util.PropertyExpander#expand(String)

expand

public java.lang.String expand(java.lang.String toExpand)
                        throws PropertyExpander.ExpandException
Expand property variables specified in toExpand by performing various substitutions on that string. Values for specified variables are obtained in the following manner: if the name of a property variable has been listed in the overrides list, then that variable will be expanded to its mapping in the overrides list. Otherwise, the property variable will be expanded to the value of the system property which has the same name as the variable. If the system property is undefined, the property variable will be expanded to "". `$/ and ${/}' are replaced by the platform-specific file separator; `$:' and ${:}' are replaced by the platform-specific path separator; and `$$' is replaced by a single `$'. A `$' not found in any of the above contexts is left unmodified. Quoting is unsupported because strings are not split into white space. The characters ' and " have no special meaning.
Parameters:
toExpand - The string to be expanded.
Returns:
the string toExpand with variable substitutions performed.
Throws:
PropertyExpander.ExpandException - An ExpandException will be thrown for improperly specified property variables (e.g. ${}, ${ or ${ } ).