1 /* 2 * $Id: BaseAction.java 54929 2004-10-16 16:38:42Z germuska $ 3 * 4 * Copyright 1999-2004 The 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 19 package org.apache.struts.webapp.example; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.apache.struts.action.Action; 24 import org.apache.struts.action.ActionForward; 25 import org.apache.struts.action.ActionMapping; 26 import org.apache.struts.webapp.example.UserDatabase; 27 import javax.servlet.http.HttpServletRequest; 28 29 /** 30 * Base Action for MailReader application. 31 * 32 * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $ 33 */ 34 public class BaseAction extends Action { 35 36 // ----------------------------------------------------- Instance Variables 37 38 /** 39 * The <code>Log</code> instance for this application. 40 */ 41 protected Log log = LogFactory.getLog(Constants.PACKAGE); 42 43 // ------------------------------------------------------ Protected Methods 44 45 /** 46 * Return a reference to the UserDatabase 47 * or null if the database is not available. 48 * @param request The request we are processing 49 * @return a reference to the UserDatabase or null if the database is not available 50 */ 51 protected UserDatabase getUserDatabase(HttpServletRequest request) { 52 return (UserDatabase) servlet.getServletContext().getAttribute( 53 Constants.DATABASE_KEY); 54 } 55 56 /** 57 * Return the local or global forward named "failure" 58 * or null if there is no such forward. 59 * @param mapping Our ActionMapping 60 * @return Return the mapping named "failure" or null if there is no such mapping. 61 */ 62 protected ActionForward findFailure(ActionMapping mapping) { 63 return (mapping.findForward(Constants.FAILURE)); 64 } 65 66 67 /** 68 * Return the mapping labeled "success" 69 * or null if there is no such mapping. 70 * @param mapping Our ActionMapping 71 * @return Return the mapping named "success" or null if there is no such mapping. 72 */ 73 protected ActionForward findSuccess(ActionMapping mapping) { 74 return (mapping.findForward(Constants.SUCCESS)); 75 } 76 77 } 78