FileDocCategorySizeDatePackage
VariableSubExample.javaAPI DocExample2588Wed May 18 09:39:04 BST 2005com.discursive.jccook.xml.bean

VariableSubExample

public class VariableSubExample extends Object

Fields Summary
private static Logger
logger
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] pArgs)

      LogInit.init(); 
        VariableSubExample example = new VariableSubExample();
        example.testDigest();
    
public voidtestDigest()


    	List emails = new ArrayList();

    	Map vars = new HashMap();
    	vars.put("email.to", "tobrien@discursive.com");
    	vars.put("user.name", "Tim");
    	vars.put("order.id", "1RR2E223WVVS" );
    	vars.put("product.name", "Foundation" );
    	
   	    MultiVariableExpander expander = new MultiVariableExpander();
    	expander.addSource("$", vars);

    	Substitutor substitutor = new VariableSubstitutor(expander);

        
        InputStream input = getClass().getResourceAsStream("./email.xml");

        URL rules = getClass().getResource("./email-rules.xml");
        Digester digester = DigesterLoader.createDigester(rules);
    	digester.setSubstitutor(substitutor);
        digester.push( emails );
        
        digester.parse( input );

        System.out.println("Resulting Email: " + emails.get(0) );