Class TokenFilter


  • public class TokenFilter
    extends Object
    Filtering object which replaces tokens of the form "${TOKEN_NAME}" with their corresponding values. Unknown tokens are not replaced. If TOKEN_NAME is a valid token, the literal value "${TOKEN_NAME}" can be included by using "$${TOKEN_NAME}".
    • Constructor Detail

      • TokenFilter

        public TokenFilter​(Map<String,​String> tokenValues)
        Creates a new TokenFilter which is initialized with the given token name/value pairs.
        Parameters:
        tokenValues - A map containing token names and their corresponding values.
    • Method Detail

      • setToken

        public void setToken​(String name,
                             String value)
        Sets the token having the given name to the given value. Any existing value for that token is replaced.
        Parameters:
        name - The name of the token to set.
        value - The value to set the token to.
      • getToken

        public String getToken​(String name)
        Returns the value of the token with the given name, or null if no such token has been set.
        Parameters:
        name - The name of the token to return.
        Returns:
        The value of the token with the given name, or null if no such token exists.
      • unsetToken

        public void unsetToken​(String name)
        Removes the value of the token with the given name. If no such token exists, this function has no effect.
        Parameters:
        name - The name of the token whose value should be removed.
      • getTokens

        public Map<String,​String> getTokens()
        Returns a map of all tokens, with each key being a token name, and each value being the corresponding token value. Changes to this map will directly affect the tokens associated with this filter.
        Returns:
        A map of all token names and their corresponding values.
      • setTokens

        public void setTokens​(Map<String,​String> tokens)
        Replaces all current token values with the contents of the given map, where each map key represents a token name, and each map value represents a token value.
        Parameters:
        tokens - A map containing the token names and corresponding values to assign.
      • filter

        public String filter​(String input)
        Filters the given string, replacing any tokens with their corresponding values.
        Parameters:
        input - The string to filter.
        Returns:
        A copy of the input string, with any tokens replaced with their corresponding values.
      • filterValues

        public void filterValues​(Map<?,​String> map)
        Given an arbitrary map containing String values, replace each non-null value with the corresponding filtered value.
        Parameters:
        map - The map whose values should be filtered.