com.hammurapi.common

## Class TokenExpander

- java.lang.Object
- - com.hammurapi.common.TokenExpander

-     public class TokenExpander
      extends Object

  Expands tokens like $[myToken] to token values. Nested tokens are supported, i.e. if myToken value contains $[someOtherToken] then it will also be expanded. $[ can be escaped by adding extra $, e.g. $$[ will be replaced with $[. Token can contain default value separated from the token name by pipe, e.g. $[myToken|tokenDefaultValue].

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `TokenExpander.TokenSource` Source of tokens.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `TOKEN_CLOSING_CHAR`
    `static String` | `TOKEN_FIRST_OPENING_CHAR`
    `static String` | `TOKEN_SECOND_OPENING_CHAR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TokenExpander(TokenExpander.TokenSource tokens)` Creates a new instance of PropertyParser
    `TokenExpander(TokenExpander.TokenSource tokens, char tokenFirstOpeningChar, char tokenSecondOpeningChar, char tokenClosingChar)` Creates a new instance of TokenExpander.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `expand(String str)` Parses a string by replacing occurences of ${<property name>} with property values.
    `String` | `expandToken(String token, String defaultValue)` Property parsing.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TOKEN_CLOSING_CHAR

          public static final String TOKEN_CLOSING_CHAR

      See Also:
        Constant Field Values

    - #### TOKEN_SECOND_OPENING_CHAR

          public static final String TOKEN_SECOND_OPENING_CHAR

      See Also:
        Constant Field Values

    - #### TOKEN_FIRST_OPENING_CHAR

          public static final String TOKEN_FIRST_OPENING_CHAR

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TokenExpander

          public TokenExpander(TokenExpander.TokenSource tokens)

      Creates a new instance of PropertyParser
      Parameters:
        `properties` - Properties
        `useNameAsDefault` - If true then property name will be used as property default value.

    - #### TokenExpander

          public TokenExpander(TokenExpander.TokenSource tokens,
                       char tokenFirstOpeningChar,
                       char tokenSecondOpeningChar,
                       char tokenClosingChar)

      Creates a new instance of TokenExpander.
      Parameters:
        `tokens` -
        `tokenFirstOpeningChar` - Token first opening char. Default is $.
        `tokenSecondOpeningChar` - Token second opening char. Default is {.
        `tokenClosingChar` - Token closing char. Default is }.

  - ### Method Detail

    - #### expandToken

          public String expandToken(String token,
                           String defaultValue)
                             throws TokenExpansionException

      Property parsing. Replaces string ${<property name>} with property value. If property value contains ${<other property name>} it will be parsed.
      Throws:
        `TokenExpansionException`

    - #### expand

          public String expand(String str)
                        throws TokenExpansionException

      Parses a string by replacing occurences of ${<property name>} with property values. If property value contains ${<other property name>} it will be parsed.
      Throws:
        `TokenExpansionException`