KickJava   Java API By Example, From Geeks To Geeks.

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


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: MailUserAction.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:19 colinmacleod
35  * Restructured ivata op around Hibernate/PicoContainer.
36  * Renamed ivata groupware.
37  *
38  * Revision 1.8 2004/12/31 18:27:44 colinmacleod
39  * Added MaskFactory to constructor of MaskAction.
40  *
41  * Revision 1.7 2004/12/23 21:01:34 colinmacleod
42  * Updated Struts to v1.2.4.
43  * Changed base classes to use ivata masks.
44  *
45  * Revision 1.6 2004/11/12 18:19:16 colinmacleod
46  * Change action and form classes to extend MaskAction, MaskForm respectively.
47  *
48  * Revision 1.5 2004/11/12 15:57:25 colinmacleod
49  * Removed dependencies on SSLEXT.
50  * Moved Persistence classes to ivata masks.
51  *
52  * Revision 1.4 2004/11/03 15:31:52 colinmacleod
53  * Change method interfaces to remove log.
54  *
55  * Revision 1.3 2004/07/13 19:48:12 colinmacleod
56  * Moved project to POJOs from EJBs.
57  * Applied PicoContainer to services layer (replacing session EJBs).
58  * Applied Hibernate to persistence layer (replacing entity EJBs).
59  *
60  * Revision 1.2 2004/03/21 21:16:39 colinmacleod
61  * Shortened name to ivata op.
62  *
63  * Revision 1.1.1.1 2004/01/27 21:00:00 colinmacleod
64  * Moved ivata openportal to SourceForge..
65  *
66  * Revision 1.3 2003/10/28 13:27:51 jano
67  * commiting webmail,
68  * still fixing compile and building openGroupware project
69  *
70  * Revision 1.2 2003/10/15 14:11:33 colin
71  * fixing for XDoclet
72  * -----------------------------------------------------------------------------
73  */

74 package com.ivata.groupware.business.mail.struts;
75
76 import java.util.Vector JavaDoc;
77
78 import javax.servlet.http.HttpServletRequest JavaDoc;
79 import javax.servlet.http.HttpServletResponse JavaDoc;
80 import javax.servlet.http.HttpSession JavaDoc;
81
82 import org.apache.struts.action.ActionErrors;
83 import org.apache.struts.action.ActionForm;
84 import org.apache.struts.action.ActionMapping;
85
86 import com.ivata.groupware.admin.security.addressbook.AddressBookSecurity;
87 import com.ivata.groupware.admin.security.right.SecurityRights;
88 import com.ivata.groupware.admin.security.server.SecuritySession;
89 import com.ivata.groupware.admin.security.user.UserDO;
90 import com.ivata.groupware.admin.setting.Settings;
91 import com.ivata.groupware.business.addressbook.AddressBook;
92 import com.ivata.groupware.business.addressbook.person.PersonDO;
93 import com.ivata.groupware.business.addressbook.right.AddressBookRights;
94 import com.ivata.groupware.business.addressbook.struts.PersonAction;
95 import com.ivata.groupware.business.mail.Mail;
96 import com.ivata.mask.MaskFactory;
97 import com.ivata.mask.util.StringHandling;
98 import com.ivata.mask.util.SystemException;
99 import com.ivata.mask.web.struts.MaskAuthenticator;
100
101
102 /**
103  * <p>Extends the person action from the standard address book class to add
104  * in mail user settings.</p>
105  *
106  * <p>To use this class rather than the standard AddressBook class, you need to
107  * change the struts config file to specify this class instead of
108  * <code>PersonAction</code>.</p>
109  *
110  * TODO: this class needs to be substituted for the PersonAction in the
111  * struts file.
112  * @author Colin MacLeod
113  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
114  */

115 public class MailUserAction extends PersonAction {
116     Mail mail;
117     /**
118      * TODO
119      * @param mail
120      * @param addressBook
121      * @param addressBookRights
122      * @param security
123      * @param securityRights
124      * @param settings
125      * @param maskFactory This factory is needed to access the masks and groups
126      * of masks.
127      * @param authenticator used to confirm whether or not the
128      * user should be allowed to continue, in the <code>execute</code> method.
129      */

130     public MailUserAction(Mail mail, AddressBook addressBook,
131             AddressBookRights addressBookRights,
132             AddressBookSecurity security, SecurityRights securityRights,
133             Settings settings,
134             MaskFactory maskFactory,
135             MaskAuthenticator authenticator) {
136         super(addressBook, addressBookRights, security, securityRights, settings,
137                 maskFactory, authenticator);
138         this.mail = mail;
139     }
140
141     /* (non-Javadoc)
142      * @see com.ivata.groupware.business.struts.MaskAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionMessages, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpSession)
143      */

144     public String JavaDoc execute(final ActionMapping mapping,
145             final ActionErrors errors,
146             final ActionForm form,
147             final HttpServletRequest JavaDoc request,
148             final HttpServletResponse JavaDoc response,
149             final HttpSession JavaDoc session)
150             throws SystemException {
151         MailUserForm mailUserForm = (MailUserForm) form;
152         if (mailUserForm.getUserAliases() == null) {
153             UserDO user = null;
154             if (mailUserForm.getPerson() != null) {
155                 user = mailUserForm.getPerson().getUser();
156             }
157             // if there is no user, just create an empty user aliases list
158
if ((user == null)
159                     || StringHandling.isNullOrEmpty(user.getName())) {
160                 mailUserForm.setUserAliases(new Vector JavaDoc());
161             }
162             // otherwise get the user aliases for this user
163
else {
164                 SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
165                 mailUserForm.setUserAliases(new Vector JavaDoc(mail.getUserAliases(
166                         securitySession, user.getName())));
167             }
168         }
169
170         return super.execute(mapping, errors, form, request, response, session);
171     }
172     public String JavaDoc onConfirm(final ActionMapping mapping,
173             final ActionErrors errors,
174             final ActionForm form,
175             final HttpServletRequest JavaDoc request,
176             final HttpServletResponse JavaDoc response,
177             final HttpSession JavaDoc session,
178             final String JavaDoc defaultForward) throws SystemException {
179         // first process the default implementation of person action
180
String JavaDoc returnValue = super.onConfirm(mapping, errors, form, request, response,
181                 session, defaultForward);
182         MailUserForm mailUserForm = (MailUserForm) form;
183         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
184         PersonDO person = mailUserForm.getPerson();
185         UserDO user = person.getUser();
186
187         if ((user != null)
188                 && !StringHandling.isNullOrEmpty(user.getName())) {
189             // TODO: - vacation message not currently implemented
190
// mail.setVacationMessage(personForm.getUserName(), personForm.getVacationMessage());
191
// NOTE: This MUST come after updating the user
192
mail.setUserAliases(securitySession, user.getName(),
193                 mailUserForm.getUserAliases());
194         }
195
196         return returnValue;
197     }
198 }
199
Popular Tags