Class InterpolationProperties
Interpolation means the substitution of a string of the form ${some.property} with the value of the property called "some.property".
Interpolation is performed repeatedly, so can values can contain new interpolations. Infinite loops are supported. This is not a feature.
- Author:
- Ben Caradoc-Davies (CSIRO Earth Science and Resource Engineering), Niels Charlier (Curtin University of Technology)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate EmptyInterpolationProperties
(String identifier) Load properties from a configuration file.InterpolationProperties
(Properties theProperties) Load with existing Properties -
Method Summary
Modifier and TypeMethodDescriptiongetProperty
(String propName) Retrieve Propertyinterpolate
(String input) Interpolate all the properties in the input string.protected static Properties
loadProperties
(String identifier) Load properties from a configuration file.void
putAll
(InterpolationProperties other) Copy all properties from anotherInterpolationProperties
into this one.static String
readAll
(InputStream input) Read everything from an input stream into a String, reconstructing line endings.void
setProperty
(String propName, String value) Set Property
-
Field Details
-
theProperties
the properties
-
-
Constructor Details
-
InterpolationProperties
Load with existing Properties- Parameters:
theProperties
- properties
-
InterpolationProperties
Load properties from a configuration file.The name of the properties file is constructed by appending ".properties" to the identifier. If there is a system property with the name of this property file, it is used as a file to load, otherwise the property file is loaded from the root of the classpath.
For example, if the identifier is app-schema:
- If the system property app-schema.properties is set, e.g. -Dapp-schema.properties=/path/to/some/local.properties, the indicated file, in this case /path/to/some/local.properties, is loaded.
- Otherwise, the classpath resource /app-schema.properties is loaded.
- Parameters:
identifier
- string used to construct property file name
-
InterpolationProperties
public InterpolationProperties()Create Empty
-
-
Method Details
-
setProperty
Set Property- Parameters:
propName
- property name
-
getProperty
Retrieve Property- Parameters:
propName
- property name- Returns:
- property value
-
interpolate
Interpolate all the properties in the input string.Properties are of the form ${some.property}, for which the value of property "some.property" is used.
It is an error for interpolated properties to not exist. A
RuntimeException
is thrown if the value of a referenced property is null.- Parameters:
input
- string on which interpolation is to be performed- Returns:
- string with all properties expanded
-
loadProperties
Load properties from a configuration file.The name of the properties file is constructed by appending ".properties" to the identifier. If there is a system property with the name of this property file, it is used as a file to load, otherwise the property file is loaded from the root of the classpath.
For example, if the identifier is app-schema:
- If the system property app-schema.properties is set, e.g. -Dapp-schema.properties=/path/to/some/local.properties, the indicated file, in this case /path/to/some/local.properties, is loaded.
- Otherwise, the classpath resource /app-schema.properties is loaded.
- Parameters:
identifier
- string used to construct property file name- Returns:
- loaded properties
-
readAll
Read everything from an input stream into a String, reconstructing line endings.- Parameters:
input
- the stream to be read- Returns:
- a string that contains the content of input
-
putAll
Copy all properties from anotherInterpolationProperties
into this one.- Parameters:
other
- the sourceInterpolationProperties
.
-