View Javadoc

1   /*
2    * $Id: WelcomeAction.java 360442 2005-12-31 20:10:04Z husted $
3    *
4    * Copyright 2000-2004 Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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      // See superclass for Javadoc
51      public ActionForward execute(
52              ActionMapping mapping,
53              ActionForm form,
54              HttpServletRequest request,
55              HttpServletResponse response)
56              throws Exception {
57  
58          // Setup message array in case there are errors
59          ArrayList messages = new ArrayList();
60  
61          // Confirm message resources loaded
62          MessageResources resources = getResources(request);
63          if (resources == null) {
64              messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
65          }
66  
67          // Confirm database loaded
68          UserDatabase userDatabase = doGetUserDatabase();
69          if (userDatabase == null) {
70              messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
71          }
72  
73          // If there were errors, forward to our failure page
74          if (messages.size() > 0) {
75              request.setAttribute(Constants.ERROR_KEY, messages);
76              return doFindFailure(mapping);
77          }
78  
79          // Forward to our success page
80          return doFindSuccess(mapping);
81  
82      }
83  
84  }