KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > email > WebEmail


1 package com.openedit.modules.email;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import javax.mail.MessagingException JavaDoc;
8
9 import com.openedit.OpenEditException;
10 import com.openedit.WebPageRequest;
11 import com.openedit.page.Page;
12 import com.openedit.page.PageRequestKeys;
13
14 public abstract class WebEmail
15 {
16     public static final String JavaDoc EMAIL_TEMPLATE_REQUEST_PARAMETER = "e-mail_layout";
17
18     protected List JavaDoc fieldRecipients;
19     protected String JavaDoc fieldFrom;
20     protected String JavaDoc fieldSubject;
21     protected String JavaDoc fieldWebServerName;
22     protected WebPageRequest fieldWebPageContext;
23     
24     protected String JavaDoc fieldMessage;
25     protected String JavaDoc fieldAlternativeMessage;
26     protected PostMail postMail;
27     public PostMail getPostMail() {
28         return postMail;
29     }
30
31     public void setPostMail(PostMail postMail) {
32         this.postMail = postMail;
33     }
34     protected WebEmail()
35     {
36         
37     }
38     
39     public WebPageRequest getWebPageContext()
40     {
41         return fieldWebPageContext;
42     }
43     public void loadSettings( Page inPage ) throws OpenEditException
44     {
45         String JavaDoc from = inPage.get( "from" );
46         setFrom(from);
47         
48         String JavaDoc subject = inPage.get( "subject" );
49         setSubject(subject);
50         
51         String JavaDoc to = inPage.get( "to" );
52         if( to != null)
53         {
54             setTo(to);
55         }
56         
57     }
58     public void loadSettings( WebPageRequest inContext) throws OpenEditException
59     {
60             Page page = inContext.getPage();
61             loadSettings(page);
62             if( getFrom() == null)
63             {
64                 String JavaDoc from = inContext.getRequestParameter( "from" );
65                 setFrom( from );
66             }
67             if( getSubject() == null)
68             {
69                 String JavaDoc subject = inContext.getRequestParameter( "subject" );
70                 setSubject(subject);
71             }
72             if( getRecipients() == null || getRecipients().size() == 0)
73             {
74                 String JavaDoc to = inContext.getRequestParameter( "to" );
75                 setTo( to );
76             }
77             
78             //TODO: remove this since you can get it from url_utils
79
setWebServerName( (String JavaDoc) inContext.getPageValue(PageRequestKeys.WEB_SERVER_PATH));
80             setWebPageContext(inContext);
81     }
82
83     public List JavaDoc getRecipients()
84     {
85         
86         return fieldRecipients;
87     }
88
89     public String JavaDoc[] getTo()
90     {
91         if( getRecipients() == null)
92         {
93             return null;
94         }
95         String JavaDoc[] tos = new String JavaDoc[getRecipients().size()];
96         for (int i = 0; i < getRecipients().size(); i++)
97         {
98             Recipient rec = (Recipient) getRecipients().get(i);
99             tos[i] = rec.getEmailAddress();
100         }
101         return tos;
102     }
103
104     public void setTo(String JavaDoc inTo)
105     {
106         List JavaDoc recipients = new ArrayList JavaDoc();
107         String JavaDoc[] emails = inTo.split(",");
108         for (int i = 0; i < emails.length; i++)
109         {
110             String JavaDoc value = emails[i].trim();
111             Recipient recipient = parseRecipient(value);
112         
113             recipients.add( recipient );
114         }
115         setRecipients(recipients);
116     }
117
118     private Recipient parseRecipient(String JavaDoc inValue)
119     {
120         Recipient rec = new Recipient();
121         rec.setEmailAddress( inValue );
122
123         return rec;
124     }
125
126     public String JavaDoc getWebServerName()
127     {
128         return fieldWebServerName;
129     }
130
131     public void setWebServerName(String JavaDoc inWebServerName)
132     {
133         fieldWebServerName = inWebServerName;
134     }
135
136     public String JavaDoc getFrom()
137     {
138         return fieldFrom;
139     }
140
141     public void setFrom(String JavaDoc inFrom)
142     {
143         fieldFrom = inFrom;
144     }
145
146     public String JavaDoc getSubject()
147     {
148         return fieldSubject;
149     }
150
151     public void setSubject(String JavaDoc inSubject)
152     {
153         fieldSubject = inSubject;
154     }
155
156     public void setWebPageContext(WebPageRequest inWebPageContext)
157     {
158         fieldWebPageContext = inWebPageContext;
159     }
160
161     public void setRecipients(List JavaDoc inList)
162     {
163         fieldRecipients = inList;
164     }
165
166     public void setRecipientsFromStrings(List JavaDoc inToAddresses)
167     {
168         List JavaDoc all = new ArrayList JavaDoc();
169         for (Iterator JavaDoc iter = inToAddresses.iterator(); iter.hasNext();)
170         {
171             String JavaDoc email = (String JavaDoc) iter.next();
172             Recipient one = parseRecipient(email);
173             all.add(one);
174         }
175         setRecipients(all);
176     }
177
178     public void setRecipient(Recipient inRecipient)
179     {
180         List JavaDoc one = new ArrayList JavaDoc(1);
181         one.add(inRecipient);
182         setRecipients(one);
183     }
184
185     public String JavaDoc getMessage()
186     {
187         return fieldMessage;
188     }
189
190     public void setMessage(String JavaDoc inMessage)
191     {
192         fieldMessage = inMessage;
193     }
194
195     public String JavaDoc getAlternativeMessage()
196     {
197         return fieldAlternativeMessage;
198     }
199
200     public void setAlternativeMessage(String JavaDoc inAlternativeMessage)
201     {
202         fieldAlternativeMessage = inAlternativeMessage;
203     }
204     
205     public abstract void send() throws OpenEditException, MessagingException JavaDoc;
206 }
207
Popular Tags