1 4 package org.infoglue.cms.applications.workflowtool.function.email; 5 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 9 import javax.mail.internet.InternetAddress ; 10 11 import org.infoglue.cms.applications.workflowtool.function.InfoglueFunction; 12 13 import com.opensymphony.workflow.WorkflowException; 14 15 18 public abstract class AddressProvider extends InfoglueFunction 19 { 20 23 private static final String REQUIRED_ARGUMENT = "required"; 24 25 28 private Collection addresses; 30 33 private Collection illegalAddresses; 35 38 private boolean required; 39 40 43 public AddressProvider() 44 { 45 super(); 46 } 47 48 52 protected abstract void populate() throws WorkflowException; 53 54 57 protected final void execute() throws WorkflowException 58 { 59 populate(); 60 setParameter(EmailFunction.TO_PARAMETER, addresses); 61 } 62 63 66 protected final void addRecipient(final String email) 67 { 68 final boolean isEmpty = (email == null || email.trim().length() == 0); 69 70 if(!isEmpty) 71 { 72 try 73 { 74 addresses.add(new InternetAddress (email.trim())); 75 } 76 catch(Exception e) 77 { 78 illegalAddresses.add(email); 79 } 80 } 81 else if(required) 82 { 83 illegalAddresses.add(""); 84 } 85 } 86 87 93 protected void initialize() throws WorkflowException 94 { 95 super.initialize(); 96 this.required = getArgument(REQUIRED_ARGUMENT, "true").equalsIgnoreCase("true"); 97 this.addresses = (Collection ) getParameter(EmailFunction.TO_PARAMETER, new ArrayList ()); 98 this.illegalAddresses = (Collection ) getParameter(EmailFunction.ILLEGAL_ADDRESSES_PARAMETER, new ArrayList ()); 99 } 100 } 101 | Popular Tags |