01: /*
02: * $Id: WelcomeAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts.apps.mailreader.actions;
22:
23: import org.apache.struts.action.ActionForm;
24: import org.apache.struts.action.ActionForward;
25: import org.apache.struts.action.ActionMapping;
26: import org.apache.struts.apps.mailreader.Constants;
27: import org.apache.struts.apps.mailreader.dao.UserDatabase;
28: import org.apache.struts.util.MessageResources;
29:
30: import javax.servlet.http.HttpServletRequest;
31: import javax.servlet.http.HttpServletResponse;
32: import java.util.ArrayList;
33:
34: /**
35: * <p>
36: * Confirm required resources are available before displaying initial page.
37: * </p><p>
38: * If a resource is missing,
39: * forward to "failure". Otherwise, forward to "success", where
40: * success is usually the "welcome" page.
41: * </p><p>
42: * Since "required resources" includes the application MessageResources
43: * the failure page must not use the standard error or message tags.
44: * Instead, it display the Strings stored in an ArrayList stored under
45: * the request attribute "ERROR".
46: * </p>
47: *
48: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
49: */
50: public final class WelcomeAction extends BaseAction {
51:
52: // See superclass for Javadoc
53: public ActionForward execute(ActionMapping mapping,
54: ActionForm form, HttpServletRequest request,
55: HttpServletResponse response) throws Exception {
56:
57: // Setup message array in case there are errors
58: ArrayList messages = new ArrayList();
59:
60: // Confirm message resources loaded
61: MessageResources resources = getResources(request);
62: if (resources == null) {
63: messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
64: }
65:
66: // Confirm database loaded
67: UserDatabase userDatabase = doGetUserDatabase();
68: if (userDatabase == null) {
69: messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
70: }
71:
72: // If there were errors, forward to our failure page
73: if (messages.size() > 0) {
74: request.setAttribute(Constants.ERROR_KEY, messages);
75: return doFindFailure(mapping);
76: }
77:
78: // Forward to our success page
79: return doFindSuccess(mapping);
80:
81: }
82:
83: }
|