Package org.apache.guacamole.token
Class TokenFilter
java.lang.Object
org.apache.guacamole.token.TokenFilter
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
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionFilters the given string, replacing any tokens with their corresponding values.filterStrict
(String input) Filters the given string, replacing any tokens with their corresponding values.void
filterValues
(Map<?, String> map) Given an arbitrary map containing String values, replace each non-null value with the corresponding filtered value.void
filterValuesStrict
(Map<?, String> map) 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
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
unsetToken
(String name) Removes the value of the token with the given name.
-
Constructor Details
-
TokenFilter
public TokenFilter()Creates a new TokenFilter which has no associated tokens. Tokens must later be given usingsetToken(java.lang.String, java.lang.String)
orsetTokens(java.util.Map)
. -
TokenFilter
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
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
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
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
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
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
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
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
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
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.
-