Class TokenHandler

java.lang.Object
org.forgerock.openidm.repo.util.TokenHandler

public class TokenHandler extends Object
  • Constructor Details

    • TokenHandler

      public TokenHandler()
  • Method Details

    • replaceTokensWithValues

      public String replaceTokensWithValues(String queryString, Map<String,Object> params) throws org.forgerock.json.resource.BadRequestException
      Replaces a query string with tokens of format ${token-name} with the values from the passed in map, where the token-name must be the key in the map
      Parameters:
      queryString - the query with tokens
      params - the parameters to replace the tokens. Values can be String or List.
      Returns:
      the query with all tokens replace with their found values
      Throws:
      org.forgerock.json.resource.BadRequestException - if token in the query is not in the passed parameters
    • replaceTokens

      public String replaceTokens(String queryString, String replacement)
      Replaces a query string with tokens of format ${token-name} with the specified replacement string for all tokens.
      Parameters:
      queryString - the query with tokens to replace
      replacement - the replacement string
      Returns:
      the query with all tokens replaced
    • replaceTokens

      public String replaceTokens(String queryString, String replacement, String... nonReplacementTokenPrefixes)
      Replaces a query string with tokens of format ${token-name} with the specified replacement string for all tokens.
      Parameters:
      queryString - the query with tokens to replace
      replacement - the replacement string
      nonReplacementTokenPrefixes - optional array of prefixes that, if found as part of a token, will not be replaced
      Returns:
      the query with all tokens replaced
    • extractTokens

      public List<String> extractTokens(String queryString)
      Extracts all the token names in the query string of format ${token-name}
      Parameters:
      queryString - the query with tokens
      Returns:
      the list of token names, in the order they appear in the queryString
    • replaceSomeTokens

      public String replaceSomeTokens(String queryString, Map<String,String> replacements)
      Replaces some tokens in a query string with tokens of format ${token-name} with the given replacements, which may again be tokens (e.g. in another format) or values. Tokens that have no replacement defined stay in the original token format.
      Parameters:
      queryString - the query with OpenIDM format tokens ${token}
      replacements - the replacement values/tokens, where the key is the token name in the query string, and the value is the String to replace it with.
      Returns:
      the query with any defined replacement values/tokens replaced, and the remaining tokens left in the original format
    • replaceListTokens

      public String replaceListTokens(String queryString, Map<String,Integer> numberOfReplacements, String replacement)
      Replaces some tokens in a query string with tokens of format ${token-name} where token-name represents a list of values. The numberOfReplacements Map tells how many replacements to produce (comma-separated) for each token. The replacement (for all tokens) is provided. Tokens that have no replacement defined stay in the original token format.
      Parameters:
      queryString - the query with OpenIDM format tokens ${token}
      numberOfReplacements - the number of replacements to replace a ${token} with
      replacement - the replacement values/tokens
      Returns:
      the query with any defined replacement values/tokens replaced, and the remaining tokens left in the original format
    • replaceTokensWithOrientToken

      public String replaceTokensWithOrientToken(String queryString)
      Replaces a query string with tokens of format ${token-name} with the token format in OrientDB, which is of the form :token-name. OrientDB tokens has some limitations, e.g. they can currently only be used in the where clause, and hence the returned string is not guaranteed to be valid for use in a prepared statement. If the parsing fails the system may have to fall back onto non-prepared statements and manual token replacement.
      Parameters:
      queryString - the query with OpenIDM format tokens ${token}
      Returns:
      the query with all tokens replaced with the OrientDB style tokens :token