KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.openedit.modules.email;
2
3 import javax.mail.MessagingException JavaDoc;
4
5 import com.openedit.OpenEditException;
6 import com.openedit.WebPageRequest;
7
8 public class FormWebEmail extends WebEmail
9 {
10     protected String JavaDoc fieldBody;
11
12     public void send() throws OpenEditException
13     {
14         
15         if (isValidMessage())
16         {
17             try
18             {
19                 postMail.postMail(getTo(),getSubject(),null,getBody().toString(),getFrom());
20             }
21             catch (MessagingException JavaDoc ex)
22             {
23                 throw new OpenEditException(ex);
24             }
25         }
26         else
27         {
28             throw new OpenEditException("Invalid message");
29         }
30     }
31
32     public String JavaDoc getBody()
33     {
34         return fieldBody;
35     }
36
37     public void setBody(String JavaDoc inBody)
38     {
39         fieldBody = inBody;
40     }
41
42     public void loadSettings( WebPageRequest inReq ) throws OpenEditException
43     {
44         super.loadSettings(inReq);
45         
46         String JavaDoc body = inReq.getRequestParameter("body");
47         setBody(body);
48     }
49     
50     private boolean isValidMessage()
51     {
52         return (isValidField(getTo()) && isValidField(getBody())
53                 && isValidField(getFrom()) );
54     }
55     
56     private boolean isValidField(String JavaDoc field[])
57     {
58         if (field.length <= 0)
59         {
60             return false;
61         }
62         
63         for (int i = 0; i < field.length; i++)
64         {
65             if (field[i] == null || field[i].length() <= 0)
66             {
67                 return false;
68             }
69         }
70         return true;
71     }
72     
73     private boolean isValidField(String JavaDoc field)
74     {
75         return (field != null && field.length() > 0);
76     }
77 }
78
Popular Tags