1 /* 2 * $Id$ 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 java.util.ArrayList; 24 25 import jakarta.servlet.http.HttpServletRequest; 26 import jakarta.servlet.http.HttpServletResponse; 27 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.action.ActionMapping; 31 import org.apache.struts.apps.mailreader.Constants; 32 import org.apache.struts.apps.mailreader.dao.UserDatabase; 33 import org.apache.struts.util.MessageResources; 34 35 36 /** 37 * <p> 38 * Confirm required resources are available before displaying initial page. 39 * </p><p> 40 * If a resource is missing, 41 * forward to "failure". Otherwise, forward to "success", where 42 * success is usually the "welcome" page. 43 * </p><p> 44 * Since "required resources" includes the application MessageResources 45 * the failure page must not use the standard error or message tags. 46 * Instead, it display the Strings stored in an ArrayList stored under 47 * the request attribute "ERROR". 48 * </p> 49 * 50 * @version $Rev$ $Date$ 51 */ 52 public final class WelcomeAction extends BaseAction { 53 private static final long serialVersionUID = -472331143659176877L; 54 55 // See superclass for Javadoc 56 public ActionForward execute( 57 ActionMapping mapping, 58 ActionForm form, 59 HttpServletRequest request, 60 HttpServletResponse response) 61 throws Exception { 62 63 // Setup message array in case there are errors 64 ArrayList<String> messages = new ArrayList<>(); 65 66 // Confirm message resources loaded 67 MessageResources resources = getResources(request); 68 if (resources == null) { 69 messages.add(Constants.ERROR_MESSAGES_NOT_LOADED); 70 } 71 72 // Confirm database loaded 73 UserDatabase userDatabase = doGetUserDatabase(); 74 if (userDatabase == null) { 75 messages.add(Constants.ERROR_DATABASE_NOT_LOADED); 76 } 77 78 // If there were errors, forward to our failure page 79 if (messages.size() > 0) { 80 request.setAttribute(Constants.ERROR_KEY, messages); 81 return doFindFailure(mapping); 82 } 83 84 // Forward to our success page 85 return doFindSuccess(mapping); 86 } 87 }