KickJava   Java API By Example, From Geeks To Geeks.

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


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: DisplayAction.java,v $
31  * Revision 1.3 2005/04/10 20:10:08 colinmacleod
32  * Added new themes.
33  * Changed id type to String.
34  * Changed i tag to em and b tag to strong.
35  * Improved PicoContainerFactory with NanoContainer scripts.
36  *
37  * Revision 1.2 2005/04/09 17:20:01 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:51:18 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.10 2004/12/31 18:27:44 colinmacleod
45  * Added MaskFactory to constructor of MaskAction.
46  *
47  * Revision 1.9 2004/12/23 21:01:34 colinmacleod
48  * Updated Struts to v1.2.4.
49  * Changed base classes to use ivata masks.
50  *
51  * Revision 1.8 2004/11/12 18:19:16 colinmacleod
52  * Change action and form classes to extend MaskAction, MaskForm respectively.
53  *
54  * Revision 1.7 2004/11/12 15:57:25 colinmacleod
55  * Removed dependencies on SSLEXT.
56  * Moved Persistence classes to ivata masks.
57  *
58  * Revision 1.6 2004/11/03 15:31:52 colinmacleod
59  * Change method interfaces to remove log.
60  *
61  * Revision 1.5 2004/07/13 19:48:12 colinmacleod
62  * Moved project to POJOs from EJBs.
63  * Applied PicoContainer to services layer (replacing session EJBs).
64  * Applied Hibernate to persistence layer (replacing entity EJBs).
65  *
66  * Revision 1.4 2004/03/21 21:16:39 colinmacleod
67  * Shortened name to ivata op.
68  *
69  * Revision 1.3 2004/03/21 20:51:33 colinmacleod
70  * Change SecurityServer into interface.
71  * Added checking of mail server.
72  *
73  * Revision 1.2 2004/02/01 22:07:32 colinmacleod
74  * Added full names to author tags
75  *
76  * Revision 1.1.1.1 2004/01/27 20:59:59 colinmacleod
77  * Moved ivata openportal to SourceForge..
78  *
79  * Revision 1.4 2004/01/12 14:02:23 jano
80  * fixing bugs
81  *
82  * Revision 1.3 2003/10/28 13:27:51 jano
83  * commiting webmail,
84  * still fixing compile and building openGroupware project
85  *
86  * Revision 1.2 2003/10/15 14:11:33 colin
87  * fixing for XDoclet
88  *
89  * Revision 1.6 2003/06/03 08:09:13 peter
90  * compose for is in the session nowadays
91  *
92  * Revision 1.5 2003/03/26 16:28:09 peter
93  * after trashing a mail, opener refreshes
94  *
95  * Revision 1.4 2003/03/26 15:19:09 peter
96  * after thrashing a mail, opener goes to index
97  *
98  * Revision 1.3 2003/03/25 08:25:33 jano
99  * if we didn't find a message forward to noMessage.jsp
100  *
101  * Revision 1.2 2003/02/25 11:53:33 colin
102  * bugfixes and minor restructuring
103  *
104  * Revision 1.1 2003/02/24 19:09:24 colin
105  * moved to business
106  *
107  * Revision 1.3 2003/02/04 17:39:10 colin
108  * updated for new MaskAction interface
109  *
110  * Revision 1.2 2003/01/27 07:27:46 colin
111  * added request override for form parameters
112  *
113  * Revision 1.1 2003/01/18 20:24:26 colin
114  * changed design from thread to display based
115  *
116  * Revision 1.1 2002/11/17 20:05:47 colin
117  * first version of struts threading
118  * supports forward/reply but HTML not yet supported
119  * -----------------------------------------------------------------------------
120  */

121 package com.ivata.groupware.business.mail.struts;
122
123 import java.util.Vector JavaDoc;
124
125 import javax.servlet.http.HttpServletRequest JavaDoc;
126 import javax.servlet.http.HttpServletResponse JavaDoc;
127 import javax.servlet.http.HttpSession JavaDoc;
128
129 import org.apache.struts.action.ActionErrors;
130 import org.apache.struts.action.ActionForm;
131 import org.apache.struts.action.ActionMapping;
132 import org.picocontainer.PicoContainer;
133
134 import com.ivata.groupware.admin.security.server.SecuritySession;
135 import com.ivata.groupware.admin.security.user.UserDO;
136 import com.ivata.groupware.admin.setting.Settings;
137 import com.ivata.groupware.business.mail.Mail;
138 import com.ivata.groupware.business.mail.message.MessageDO;
139 import com.ivata.groupware.business.mail.server.NoMailServerException;
140 import com.ivata.groupware.business.mail.session.MailSession;
141 import com.ivata.groupware.container.PicoContainerFactory;
142 import com.ivata.mask.MaskFactory;
143 import com.ivata.mask.util.SystemException;
144 import com.ivata.mask.web.struts.MaskAction;
145 import com.ivata.mask.web.struts.MaskAuthenticator;
146
147
148 /**
149  * <p>This <code>Action</code> is invoked when displaying a message.
150  * This action also handles replying to, forwarding or editing a mail
151  * for resending.</p>
152  *
153  * @since 2002-11-11
154  * @author Colin MacLeod
155  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
156  * @version $Revision: 1.3 $
157  */

158 public class DisplayAction extends MaskAction {
159     Mail mail;
160     Settings settings;
161     /**
162      * TODO
163      * @param mail
164      * @param settings
165      * @param maskFactory This factory is needed to access the masks and groups
166      * of masks.
167      * @param authenticator used to confirm whether or not the
168      * user should be allowed to continue, in the <code>execute</code> method.
169      */

170     public DisplayAction(Mail mail, Settings settings,
171             MaskFactory maskFactory, MaskAuthenticator authenticator) {
172         super(maskFactory, authenticator);
173         this.mail = mail;
174         this.settings = settings;
175     }
176
177     /**
178      * <p>Build the form for <code>/mail/display.jsp</code> from an
179      * existing mail.</p>
180      *
181      * @param mapping The ActionMapping used to select this instance.
182      * @param log valid logging object to write messages to.
183      * @param errors valid errors object to append errors to. If there are
184      * any errors, the action will return to the input.
185      * @param form optional ActionForm bean for this request (if any)
186      * @param request non-HTTP request we are processing
187      * @param response The non-HTTP response we are creating
188      * @param session returned from the <code>request</code> parameter.
189      * @param userName valid, non-null user name from session.
190      * @param settings valid, non-null settings from session.
191      * @exception SystemException if there is any problem which
192      * prevents processing. It will result in the webapp being forwarded
193      * to
194      * the standard error page.
195      * @return this method returns the string used to identify the correct
196      * <em>Struts</em> <code>ActionForward</code> which should follow this
197      * page, or <code>null</code> if it should return to the input.
198      */

199     public String JavaDoc execute(final ActionMapping mapping,
200             final ActionErrors errors,
201             final ActionForm form,
202             final HttpServletRequest JavaDoc request,
203             final HttpServletResponse JavaDoc response,
204             final HttpSession JavaDoc session) throws SystemException {
205         // Was this transaction cancelled? For us, that means the close button
206
// was pressed
207
if (isCancelled(request)) {
208             return "mailIndex";
209         }
210
211         DisplayForm displayForm = (DisplayForm) form;
212         MessageDO message = displayForm.getMessage();
213
214         // request parameters override the form ones
215
if (request.getParameter("folderName") != null) {
216             displayForm.setFolderName(request.getParameter("folderName"));
217         }
218
219         if (request.getParameter("id") != null) {
220             displayForm.setId(request.getParameter("id"));
221         }
222
223         // used if we forward or delete the message
224
Vector JavaDoc idVector = new Vector JavaDoc();
225         idVector.add(message.getMessageID());
226
227         // is there a new thread (forward/reply) from this message?
228
MailSession mailSession;
229         try {
230             mailSession = (MailSession) session.getAttribute("securitySession");
231         } catch (ClassCastException JavaDoc e) {
232             session.setAttribute("mailServerException",
233                 new NoMailServerException(e));
234             return "serverError";
235         }
236         UserDO user = mailSession.getUser();
237
238         if (displayForm.getThread() != null) {
239             SecuritySession securitySession = (SecuritySession)
240                     session.getAttribute("securitySession");
241             PicoContainer picoContainer = securitySession.getContainer();
242             ComposeForm composeForm = (ComposeForm)
243                     PicoContainerFactory.getInstance()
244                         .instantiateOrOverride(picoContainer,
245                             ComposeForm.class);
246
247             MessageDO newMessage = mail.createThreadMessage(mailSession,
248                     displayForm.getFolderName(), idVector,
249                     displayForm.getThread());
250             composeForm.setMessage(newMessage);
251             session.setAttribute("mailComposeForm", composeForm);
252
253             return "mailCompose";
254         }
255
256         // move the current message to trash?
257
if (displayForm.getDelete()) {
258             String JavaDoc trashFolderName = settings.getStringSetting(mailSession,
259                     "emailFolderTrash",
260                     user);
261             mail.moveMessages(mailSession, displayForm.getFolderName(),
262                 idVector, trashFolderName);
263             request.setAttribute("refreshOpener", "1");
264
265             return "success";
266         }
267
268         // delete the current message from trash
269
if (displayForm.getDeleteTrash()) {
270             mail.deleteMessagesFromTrash(mailSession, idVector);
271         }
272
273         // ok, so get the message we actually want to show
274
message = mail.findMessageByFolderMessageId(mailSession,
275                 displayForm.getFolderName(), displayForm.getId());
276
277         // if we didn't find message forward to page with info text
278
if (message == null) {
279             return "noMessage";
280         }
281
282         displayForm.setMessage(message);
283
284         // down here means we've found our message and want to display it
285
return "mailDisplay";
286     }
287 }
288
Popular Tags