1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.apps.mailreader.actions;
19
20 import org.apache.struts.action.ActionForm;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.action.ActionMapping;
23 import org.apache.struts.apps.mailreader.Constants;
24 import org.apache.struts.apps.mailreader.dao.UserDatabase;
25 import org.apache.struts.util.MessageResources;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import java.util.ArrayList;
30
31
32 /***
33 * <p>
34 * Confirm required resources are available before displaying initial page.
35 * </p><p>
36 * If a resource is missing,
37 * forward to "failure". Otherwise, forward to "success", where
38 * success is usually the "welcome" page.
39 * </p><p>
40 * Since "required resources" includes the application MessageResources
41 * the failure page must not use the standard error or message tags.
42 * Instead, it display the Strings stored in an ArrayList stored under
43 * the request attribute "ERROR".
44 * </p>
45 *
46 * @version $Rev: 360442 $ $Date: 2005-12-31 13:10:04 -0700 (Sat, 31 Dec 2005) $
47 */
48 public final class WelcomeAction extends BaseAction {
49
50
51 public ActionForward execute(
52 ActionMapping mapping,
53 ActionForm form,
54 HttpServletRequest request,
55 HttpServletResponse response)
56 throws Exception {
57
58
59 ArrayList messages = new ArrayList();
60
61
62 MessageResources resources = getResources(request);
63 if (resources == null) {
64 messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
65 }
66
67
68 UserDatabase userDatabase = doGetUserDatabase();
69 if (userDatabase == null) {
70 messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
71 }
72
73
74 if (messages.size() > 0) {
75 request.setAttribute(Constants.ERROR_KEY, messages);
76 return doFindFailure(mapping);
77 }
78
79
80 return doFindSuccess(mapping);
81
82 }
83
84 }