Class Envsubst

java.lang.Object
org.aksw.commons.util.string.Envsubst

public class Envsubst extends Object
A basic 'envsubst' implementation. Just uses regex matching for substituting placeholders in a string. Does not precompile templates - we may want to switch to a fully fledged template engine for that.
  • Field Details

    • PLACEHOLDER_PATTERN

      public static final Pattern PLACEHOLDER_PATTERN
      Regex for matching strings such as '${varname}' variable names cannot include the '}' symbol
  • Constructor Details

    • Envsubst

      public Envsubst()
  • Method Details

    • envsubst

      public static String envsubst(String input, Function<String,String> getReplacement)
      Perform substitution of placeholders of form "${name}"
      Parameters:
      input - A string in which to replace placeholder patterns
      getReplacement - Function that receives the variable name of a match and can return a substitution string. A result of null leaves the placeholder unchanged in order to allow for future substitution.
      Returns: