com.hammurapi.config.bootstrap
Class TokenExpander

java.lang.Object
  extended by com.hammurapi.config.bootstrap.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].

Author:
Pavel Vlasov

Nested Class Summary
static interface TokenExpander.TokenSource
          Source of tokens.
 
Field Summary
static String TOKEN_CLOSING_CHAR
           
static String TOKEN_FIRST_OPENING_CHAR
           
static String TOKEN_SECOND_OPENING_CHAR
           
 
Constructor Summary
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
 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 ConfigurationException
Property parsing. Replaces string ${<property name>} with property value. If property value contains ${<other property name>} it will be parsed.

Throws:
ConfigurationException

expand

public String expand(String str)
              throws ConfigurationException
Parses a string by replacing occurences of ${<property name>} with property values. If property value contains ${<other property name>} it will be parsed.

Throws:
ConfigurationException