com.mmm.cms.util
Class MacroProperties
java.lang.Object
java.util.Dictionary<K,V>
java.util.Hashtable<java.lang.Object,java.lang.Object>
java.util.Properties
com.mmm.cms.util.MacroProperties
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>
public class MacroProperties
- extends java.util.Properties
This extends the java.util.Properties class to override the getProperty()
methods to allow automatic conversion of macros in the property to the
actual property value. Marcos are defined as ${...}
For example, if the properties file has the next two entries:
base.dir=C:/MyPlace
data.dir=${base.dir}/dataAndStuff
Then the value of data.dir, when using getProperties(), the macro would be
substituted to be "C:/MyPlace/dataAndStuff"
Using the getPropertyRaw() methods would be the same as the original
Properties.getProperty() methods.
methods
- See Also:
- Serialized Form
| Fields inherited from class java.util.Properties |
defaults |
|
Constructor Summary |
MacroProperties()
|
MacroProperties(java.util.Properties props)
This overrides the Properties() constructor to set the props with
the super(props), but also to set the props in the current table |
|
Method Summary |
java.lang.String |
getProperty(java.lang.String arg0)
|
java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
Gets the property identified by key, and then parses it for any
macro information and replaces the macros that can be replaced |
java.lang.String |
getPropertyRaw(java.lang.String key)
Gets the property value without substituting any macro information. |
static void |
main(java.lang.String[] args)
|
java.lang.String |
parsePropertiesInString(java.lang.String string,
boolean failIfMissing)
Parses a string by replacing all occurrences of a property macro with
the resolved value of the property. |
| Methods inherited from class java.util.Properties |
list, list, load, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML |
| Methods inherited from class java.util.Hashtable |
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
MacroProperties
public MacroProperties()
MacroProperties
public MacroProperties(java.util.Properties props)
- This overrides the Properties() constructor to set the props with
the super(props), but also to set the props in the current table
- Parameters:
arg0 -
main
public static void main(java.lang.String[] args)
getProperty
public java.lang.String getProperty(java.lang.String arg0)
- Overrides:
getProperty in class java.util.Properties
getProperty
public java.lang.String getProperty(java.lang.String key,
java.lang.String defaultValue)
- Gets the property identified by key, and then parses it for any
macro information and replaces the macros that can be replaced
- Overrides:
getProperty in class java.util.Properties
- Parameters:
key - defaultValue -
- Returns:
parsePropertiesInString
public java.lang.String parsePropertiesInString(java.lang.String string,
boolean failIfMissing)
throws java.lang.Exception
- Parses a string by replacing all occurrences of a property macro with
the resolved value of the property. Nested macros are allowed - the
inner most macro will be resolved first, moving out from there.
- Parameters:
string - The string to be parseddefaultValue - The value if the string does not exist.
- Returns:
- The parsed string
- Throws:
CruiseControlException - if a property cannot be resolved
java.lang.Exception
getPropertyRaw
public java.lang.String getPropertyRaw(java.lang.String key)
- Gets the property value without substituting any macro information. So,
using the example at the top of this class, getting "data.dir" would
return the value ${base.dir}/dataAndStuff
- Parameters:
key -
- Returns:
- the unchanged value of the property for key. null if the
property does not exist.