FileDocCategorySizeDatePackage
TokenReplacementTester.javaAPI DocGlassfish v2 API4675Fri May 04 22:25:58 BST 2007com.sun.enterprise.admin.util.test

TokenReplacementTester

public class TokenReplacementTester extends Object
author
kedar

Fields Summary
private final com.sun.enterprise.admin.util.LineTokenReplacer
replacer
Creates a new instance of TokenReplacementTester
Constructors Summary
public TokenReplacementTester(String tokensFileName, String fromFile, String toFile)

        final TokenValueSet tokens = getTokensFromFile(tokensFileName);
        replacer = new LineTokenReplacer(tokens);
        replacer.replace(fromFile, toFile);
    
Methods Summary
private com.sun.enterprise.admin.util.TokenValuegetTokenValue(java.lang.String line)

        final String delim = "=";
        final StringTokenizer parser = new StringTokenizer(line, delim);
        final String[] output = new String[2];
        int i = 0;
        while(parser.hasMoreTokens()) {
            output[i++] = parser.nextToken();
        }
        final String DELIM = "%%%";
        TokenValue tv = new TokenValue(output[0], output[1], DELIM);
        return ( tv );
    
private com.sun.enterprise.admin.util.TokenValueSetgetTokensFromFile(java.lang.String fileName)

        final TokenValueSet tokens  = new TokenValueSet();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(fileName));
            String line = null;
            while ((line = reader.readLine()) != null) {
                final TokenValue tv = getTokenValue(line);
                tokens.add(tv);
            }
            reader.close();
            reader = null;
        }
        catch(Exception e) {
            e.printStackTrace();
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception ex) {}
            }
        } 
        return tokens;
    
public static voidmain(java.lang.String[] args)

param
args the command line arguments

        int length = args.length;
        if (length < 2) {
            usage();
            System.exit(1);
        }
        final String tokensFile = args[0];
        final String fromFile = args[1];
        final String toFile = fromFile + ".out";
        new TokenReplacementTester(tokensFile, fromFile, toFile);
    
private static voidusage()

        System.out.println("java TokenReplacementTester <tokens-file> <template-file>");