Class InterpolationProperties


  • public class InterpolationProperties
    extends Object
    Stores properties and provides methods to support interpolation of properties in a file.

    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 
      Modifier and Type Field Description
      protected Properties theProperties
      the properties
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String getProperty​(String propName)
      Retrieve Property
      String interpolate​(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 another InterpolationProperties 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
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • theProperties

        protected Properties theProperties
        the properties
    • Constructor Detail

      • InterpolationProperties

        public InterpolationProperties​(Properties theProperties)
        Load with existing Properties
        Parameters:
        theProperties - properties
      • InterpolationProperties

        public InterpolationProperties​(String identifier)
        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.
        Before the properties are returned, all system properties are copied; this means that system properties override any properties in the configuration file.
        Parameters:
        identifier - string used to construct property file name
      • InterpolationProperties

        public InterpolationProperties()
        Create Empty
    • Method Detail

      • setProperty

        public void setProperty​(String propName,
                                String value)
        Set Property
        Parameters:
        propName - property name
      • getProperty

        public String getProperty​(String propName)
        Retrieve Property
        Parameters:
        propName - property name
        Returns:
        property value
      • interpolate

        public String interpolate​(String input)
        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

        protected static Properties loadProperties​(String identifier)
        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.
        Before the properties are returned, all system properties are copied; this means that system properties override any properties in the configuration file.
        Parameters:
        identifier - string used to construct property file name
        Returns:
        loaded properties
      • readAll

        public static String readAll​(InputStream input)
        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