View Javadoc

    1   /*
    2    * $Id: WelcomeAction.java 471754 2006-11-06 14:55:09Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "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  /**
    36   * <p>
    37   * Confirm required resources are available before displaying initial page.
    38   * </p><p>
    39   * If a resource is missing,
    40   * forward to "failure". Otherwise, forward to "success", where
    41   * success is usually the "welcome" page.
    42   * </p><p>
    43   * Since "required resources" includes the application MessageResources
    44   * the failure page must not use the standard error or message tags.
    45   * Instead, it display the Strings stored in an ArrayList stored under
    46   * the request attribute "ERROR".
    47   * </p>
    48   *
    49   * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
    50   */
    51  public final class WelcomeAction extends BaseAction {
    52
    53      // See superclass for Javadoc
    54      public ActionForward execute(
    55              ActionMapping mapping,
    56              ActionForm form,
    57              HttpServletRequest request,
    58              HttpServletResponse response)
    59              throws Exception {
    60
    61          // Setup message array in case there are errors
    62          ArrayList messages = new ArrayList();
    63
    64          // Confirm message resources loaded
    65          MessageResources resources = getResources(request);
    66          if (resources == null) {
    67              messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
    68          }
    69
    70          // Confirm database loaded
    71          UserDatabase userDatabase = doGetUserDatabase();
    72          if (userDatabase == null) {
    73              messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
    74          }
    75
    76          // If there were errors, forward to our failure page
    77          if (messages.size() > 0) {
    78              request.setAttribute(Constants.ERROR_KEY, messages);
    79              return doFindFailure(mapping);
    80          }
    81
    82          // Forward to our success page
    83          return doFindSuccess(mapping);
    84
    85      }
    86
    87  }