KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > mail > struts > MailUserForm


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: MailUserForm.java,v $
31  * Revision 1.2 2005/04/09 17:20:01 colinmacleod
32  * Changed copyright text to GPL v2 explicitly.
33  *
34  * Revision 1.1.1.1 2005/03/10 17:51:18 colinmacleod
35  * Restructured ivata op around Hibernate/PicoContainer.
36  * Renamed ivata groupware.
37  *
38  * Revision 1.4 2005/01/01 12:49:50 colinmacleod
39  * Added check for null user name.
40  *
41  * Revision 1.3 2004/11/12 18:19:16 colinmacleod
42  * Change action and form classes to extend MaskAction, MaskForm respectively.
43  *
44  * Revision 1.2 2004/11/12 15:57:25 colinmacleod
45  * Removed dependencies on SSLEXT.
46  * Moved Persistence classes to ivata masks.
47  *
48  * Revision 1.1 2004/11/03 16:18:50 colinmacleod
49  * First version in CVS. Adds user aliases to PersonForm.
50  *
51  * -----------------------------------------------------------------------------
52  */

53 package com.ivata.groupware.business.mail.struts;
54
55 import java.util.List JavaDoc;
56 import java.util.Vector JavaDoc;
57
58 import javax.servlet.http.HttpServletRequest JavaDoc;
59
60 import org.apache.struts.action.ActionMapping;
61
62 import com.ivata.groupware.admin.security.Security;
63 import com.ivata.groupware.admin.security.server.SecuritySession;
64 import com.ivata.groupware.admin.security.user.UserDO;
65 import com.ivata.groupware.admin.setting.Settings;
66 import com.ivata.groupware.business.addressbook.AddressBook;
67 import com.ivata.groupware.business.addressbook.struts.PersonForm;
68 import com.ivata.groupware.business.mail.Mail;
69 import com.ivata.groupware.util.SettingDateFormatter;
70 import com.ivata.mask.MaskFactory;
71 import com.ivata.mask.util.CollectionHandling;
72 import com.ivata.mask.util.StringHandling;
73 import com.ivata.mask.util.SystemException;
74
75 /**
76  * <p>
77  * Extends the standard ivata groupware person form to add functionality for a mail
78  * user, such as user aliases.
79  * </p>
80  *
81  * @since Nov 2, 2004
82  * @author Colin MacLeod
83  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
84  * @version $Revision: 1.2 $
85  */

86
87 public class MailUserForm extends PersonForm {
88
89     /**
90      * <p>
91      * Stores the email address host to append to user aliases to make new
92      * email addresses. This is read from the settings.
93      * </p>
94      */

95     String JavaDoc emailAddressHost = "localhost";
96
97     /**
98      * <p>
99      * System mail implemenation. Used to add email addresses based on aliases.
100      * </p>
101      */

102     private Mail mail;
103     /**
104      * <p>
105      * Stores the security session of the current user.
106      * </p>
107      */

108     private SecuritySession securitySession;
109     /**
110      * <p>
111      * Settings implementation. Used to retrieve the email address host.
112      * </p>
113      */

114     private Settings settings;
115     /**
116      * <p>Contains 'local parts' (i.e. 'johnny.tester', not
117      * 'johnny.tester@acme.com') of the email addresses which will be sent
118      * to this user.</p>
119      */

120     private List JavaDoc userAliases;
121     /**
122      * <p>If non-<code>null</code>, indicates a message which should be
123      * sent to users who send this user an email, to indicate (s)he is on
124      * holiday or otherwise unavailable.</p>
125      */

126     private String JavaDoc vacationMessage;
127
128     /**
129      * <p>
130      * Constructor - necessary to initialize <code>PersonForm</code>. Called
131      * by <code>PicoContainer</code>.
132      * </p>
133      *
134      * @param addressBook address book implementation.
135      * @param settings settings implementation. Used to retrieve the email
136      * address host.
137      * @param dateFormatter date formatter for the current session.
138      */

139     public MailUserForm(final Mail mail,
140             final AddressBook addressBook,
141             final Settings settings,
142             final SettingDateFormatter dateFormatter,
143             final Security security,
144             final MaskFactory maskFactory) {
145         super(addressBook, dateFormatter, security, maskFactory);
146         this.mail = mail;
147         this.settings = settings;
148     }
149     /**
150      * <p>
151      * Return all form state to initial values.
152      * </p>
153      *
154      * @see com.ivata.mask.web.struts.MaskForm#clear()
155      */

156     protected void clear() {
157         super.clear();
158         userAliases = null;
159         vacationMessage = null;
160     }
161
162     /**
163      * <p>Contains 'local parts' (i.e. 'johnny.tester', not
164      * 'johnny.tester@acme.com') of the email addresses which will be sent
165      * to this user.</p>
166      *
167      * @return the current value of userAliases.
168      */

169     public List JavaDoc getUserAliases() {
170         return userAliases;
171     }
172
173     /**
174      * <p>Contains 'local parts' (i.e. 'johnny.tester', not
175      * 'johnny.tester@acme.com') of the email addresses which will be sent
176      * to this user. This version of the getter reutrns the local parts
177      * separated by new lines.</p>
178      *
179      * @return current value of userAliases.
180      */

181     public final String JavaDoc getUserAliasesAsLines() {
182         return CollectionHandling.convertToLines(userAliases);
183     }
184
185     /**
186      * <p>If non-<code>null</code>, indicates a message which should be
187      * sent to users who send this user an email, to indicate (s)he is on
188      * holiday or otherwise unavailable.</p>
189      *
190      * @return the current value of vacationMessage.
191      */

192     public final String JavaDoc getVacationMessage() {
193         return vacationMessage;
194     }
195     /**
196      * <p>Reset all bean properties to their default state. This method
197      * is called before the properties are repopulated by the controller
198      * servlet.</p>
199      *
200      * @param mapping The mapping used to select this instance
201      * @param request The servlet request we are processing
202      * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
203      */

204     public void reset(final ActionMapping mapping,
205             final HttpServletRequest JavaDoc request) {
206         super.reset(mapping, request);
207         securitySession = (SecuritySession) request.getSession().getAttribute("securitySesssion");
208         if (!StringHandling.isNullOrEmpty(getUserName())) {
209             // if the user has not been updated yet, use the site default
210
// for the email host
211
UserDO user = getPerson().getUser().getId() == null ?
212                     null : getPerson().getUser();
213             try {
214                 emailAddressHost =
215                     settings.getStringSetting(
216                         securitySession,
217                         "emailAddressHost",
218                         user);
219             } catch (SystemException e) {
220                 throw new RuntimeException JavaDoc(e);
221             }
222         }
223
224         // we're only interested in extending functionality for the user tab
225
if ("/addressBook/user.jsp".equals(getTabPage())) {
226             userAliases = null;
227             vacationMessage = "";
228         }
229     }
230     /**
231      * <p>
232      * Update the person to show all the addresses currently in the form. This
233      * method has been overridden to add a default email address for users.
234      * </p>
235      *
236      * @see com.ivata.groupware.business.addressbook.struts.PersonForm#setPersonFromTelecomAddresses()
237      */

238     public void setPersonFromTelecomAddresses() {
239         try {
240             String JavaDoc userName = getUserName();
241             if (!StringHandling.isNullOrEmpty(userName)) {
242                 mail.addUserAliasEmailAddresses(securitySession, userName,
243                         userAliases, getTelecomAddresses(), emailAddressHost);
244             }
245         } catch (SystemException e) {
246             throw new RuntimeException JavaDoc(e);
247         }
248         super.setPersonFromTelecomAddresses();
249     }
250
251     /**
252      * <p>Contains 'local parts' (i.e. 'johnny.tester', not
253      * 'johnny.tester@acme.com') of the email addresses which will be sent
254      * to this user.</p>
255      *
256      * @param userAliases the new value of userAliases.
257      */

258     public final void setUserAliases(final List JavaDoc userAliases) {
259         this.userAliases = userAliases;
260     }
261
262     /**
263      * <p>Contains 'local parts' (i.e. 'johnny.tester', not
264      * 'johnny.tester@acme.com') of the email addresses which will be sent
265      * to this user. This version of the setter contains the local parts
266      * separated by new lines.</p>
267      *
268      * @param userAliases the new value of userAliases.
269      */

270     public final void setUserAliasesAsLines(final String JavaDoc userAliases) {
271         this.userAliases = new Vector JavaDoc(CollectionHandling.convertFromLines(userAliases));
272     }
273
274     /**
275      * <p>If non-<code>null</code>, indicates a message which should be
276      * sent to users who send this user an email, to indicate (s)he is on
277      * holiday or otherwise unavailable.</p>
278      *
279      * @param vacationMessage the new value of vacationMessage.
280      */

281     public final void setVacationMessage(final String JavaDoc vacationMessage) {
282         this.vacationMessage = vacationMessage;
283     }
284 }
285
Popular Tags