Class StringPropertyReplacer


  • public final class StringPropertyReplacer
    extends Object
    A utility class for replacing properties in strings.

    NOTE: Copied from jboss-common-core.jar https://github.com/jboss/jboss-common-core/blob/master/src/main/java/org/jboss/util/StringPropertyReplacer.java

    Version:
    $Revision: 2898 $
    Author:
    Jason Dillon, Scott Stark, Claudio Vesco, Adrian Brock, Dimitris Andreadis
    • Constructor Detail

      • StringPropertyReplacer

        public StringPropertyReplacer()
    • Method Detail

      • replaceClasspath

        public static String replaceClasspath​(String string)
        Go through the input string and replace any occurrence of ${classpath(p)} with the classpath URL value. If there is no such p defined in classpath, then the ${p} reference will remain unchanged.
        Parameters:
        string - - the string with possible ${classpath()} references
        Returns:
        the input string with all property references replaced if any. If there are no valid references the input string will be returned.
      • replaceProperties

        public static String replaceProperties​(String string)
        Go through the input string and replace any occurrence of ${p} with the System.getProtocolProperty(p) value. If there is no such property p defined, then the ${p} reference will remain unchanged.

        If the property reference is of the form ${p:v} and there is no such property p, then the default value v will be returned.

        If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the primary and the secondary properties will be tried in turn, before returning either the unchanged input, or the default value.

        The property ${/} is replaced with System.getProtocolProperty("file.separator") value and the property ${:} is replaced with System.getProtocolProperty("path.separator").

        Prior to resolving variables, environment variables are assigned to the collection of properties. Each environment variable is prefixed with the prefix "env.". If a system property is already defined for the prefixed environment variable, the system property is honored as an override (primarily for testing).

        Parameters:
        string - - the string with possible ${} references
        Returns:
        the input string with all property references replaced if any. If there are no valid references the input string will be returned.