FileDocCategorySizeDatePackage
TokenResolver.javaAPI DocGlassfish v2 API5746Fri May 04 22:24:30 BST 2007com.sun.enterprise.admin.servermgmt.launch

TokenResolver

public class TokenResolver extends Object
Here is the contract: You give me a Properties object. Then you can call resolve(List) and/or resolve(String) I will find and replace the tokens, e.g., ${foo} with the value of "foo" in the properties. If the token has no such property -- then I leave the token as is. It purposely does not handle nested tokens. E.g. if the "foo" property has another token embedded in the value -- it will not be further resolved. This is the KISS principle in action...
author
bnevins

Fields Summary
private final Properties
props
Constructors Summary
TokenResolver(Properties p)

        props = p;
    
Methods Summary
private com.sun.enterprise.admin.servermgmt.launch.TokenResolver$TokengetToken(java.lang.String s, int index)

        if(s == null || index >= s.length())
            return null;
        
        Token token = new Token();
        token.start = s.indexOf(token.TOKEN_START, index);
        token.end   = s.indexOf(token.TOKEN_END, token.start + 2);
        
        if(token.end <= 0 || token.start < 0)
            return null;
        
        token.token = s.substring(token.start, token.end + 1);
        token.name = s.substring(token.start + Token.TOKEN_START.length(), token.end);
        
        // if the token exists, but it's value is null -- then set the value 
        // back to the token.

        token.value = props.getProperty(token.name, token.token);
        return token;
    
private java.util.ListgetTokens(java.lang.String s)

        int index = 0;        
        List<Token> tokens = new ArrayList<Token>();
     
        while(true)
        {
            Token token = getToken(s, index);
            
            if(token == null)
                break;
            
            tokens.add(token);
            index = token.start + Token.TOKEN_START.length();
        }

        return tokens;
    
private static booleanhasToken(java.lang.String s)

        return s != null && s.indexOf(Token.TOKEN_START) >= 0;
    
voidresolve(java.util.List list)

        for(int i = 0; i < list.size(); i++)
        {
            String s = list.get(i);
            
            if(hasToken(s))
                list.set(i, resolve(s));
        }
    
java.lang.Stringresolve(java.lang.String s)

        List<Token> tokens = getTokens(s);
        String resolved = s;
        
        for(Token token : tokens)
            resolved = StringUtils.replace(resolved, token.token, token.value);
        
        return resolved;