Class TokenFilter

java.lang.Object
org.apache.guacamole.token.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 Summary

    Constructors
    Constructor
    Description
    Creates a new TokenFilter which has no associated tokens.
    TokenFilter(Map<String,String> tokenValues)
    Creates a new TokenFilter which is initialized with the given token name/value pairs.
  • Method Summary

    Modifier and Type
    Method
    Description
    filter(String input)
    Filters the given string, replacing any tokens with their corresponding values.
    Filters the given string, replacing any tokens with their corresponding values.
    void
    Given an arbitrary map containing String values, replace each non-null value with the corresponding filtered value.
    void
    Given an arbitrary map containing String values, replace each non-null value with the corresponding filtered value.
    Returns the value of the token with the given name, or null if no such token has been set.
    Returns a map of all tokens, with each key being a token name, and each value being the corresponding token value.
    void
    setToken(String name, String value)
    Sets the token having the given name to the given value.
    void
    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.
    void
    Removes the value of the token with the given name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TokenFilter

      public TokenFilter()
      Creates a new TokenFilter which has no associated tokens. Tokens must later be given using setToken(java.lang.String, java.lang.String) or setTokens(java.util.Map).
    • 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 Details

    • 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. Any tokens present in the given string which lack values will be interpreted as literals.
      Parameters:
      input - The string to filter.
      Returns:
      A copy of the input string, with any tokens replaced with their corresponding values.
    • filterStrict

      public String filterStrict(String input) throws GuacamoleTokenUndefinedException
      Filters the given string, replacing any tokens with their corresponding values. If any token in the given string has no defined value within this TokenFilter, a GuacamoleTokenUndefinedException will be thrown.
      Parameters:
      input - The string to filter.
      Returns:
      A copy of the input string, with any tokens replaced with their corresponding values.
      Throws:
      GuacamoleTokenUndefinedException - If at least one token in the given string has no corresponding value.
    • filterValues

      public void filterValues(Map<?,String> map)
      Given an arbitrary map containing String values, replace each non-null value with the corresponding filtered value. Any tokens present in the values of the given map which lack defined values within this TokenFilter will be interpreted as literals.
      Parameters:
      map - The map whose values should be filtered.
    • filterValuesStrict

      public void filterValuesStrict(Map<?,String> map) throws GuacamoleTokenUndefinedException
      Given an arbitrary map containing String values, replace each non-null value with the corresponding filtered value. If any token in any string has no defined value within this TokenFilter, a GuacamoleTokenUndefinedException will be thrown.
      Parameters:
      map - The map whose values should be filtered.
      Throws:
      GuacamoleTokenUndefinedException - If at least one token in at least one string has no corresponding value.