📄 baseaction.java
字号:
/* @LICENSE_COPYRIGHT@ */package net.sf.irunninglog.servlet.action;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.struts.Globals;import org.apache.struts.action.Action;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionMessage;import org.apache.struts.action.ActionMessages;import net.sf.irunninglog.servlet.UserContainer;import net.sf.irunninglog.util.DTO;import net.sf.irunninglog.util.IError;/** * Base class to be used as a subclass for actions within the application. * This class specifies an abstract method, <code>executeAction</code>, which * subclasses must define to implement their behavior. This method is invoked * by the final <code>execute</code> method, which simply delegates the * call, providing access to the user's <code>UserContainer</code>. * * @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a> * @version $Revision: 1.1.1.1 $ $Date: 2005/06/23 01:48:59 $ * @since iRunningLog 1.0 */public abstract class BaseAction extends Action { /** <code>Log</code> instance for this class. */ private static final Log LOG = LogFactory.getLog(BaseAction.class); /** * Override of the <code>execute</code> method from the Struts * <code>Action</code> object. This method is made final here to enforce * that subclasses implement the <code>executeAction</code> method. * * @param mapping The <code>ActionMapping</code> used to select this * instance * @param form The optional <code>ActionForm</code> bean for this request * @param request The HTTP request being processed * @param response The HTTP response being processed * @return The forward describing where/how to forward control * @exception Exception if the application business logic throws * an exception * @see #executeAction(ActionMapping, ActionForm, HttpServletRequest, * HttpServletResponse, UserContainer) */ public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("execute: Forwarding control to executeAction"); } UserContainer container = UserContainer.getUserContainer(request); return executeAction(mapping, form, request, response, container); } /** * Perform the action's actual logic. This method must be overridden * by subclasses in order to specify their behavior. Invoked from the * <code>execute</code> method, which is invoked by the Struts framework * during request processing. * * @param mapping The <code>ActionMapping</code> used to select this * instance * @param form The optional <code>ActionForm</code> bean for this request * @param request The HTTP request being processed * @param response The HTTP response being processed * @param container The <code>UserContainer</code> object for the current * user * @return The forward describing where/how to forward control * @exception Exception if the application business logic throws * an exception * @see #execute(ActionMapping, ActionForm, HttpServletRequest, * HttpServletResponse) */ public abstract ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContainer container) throws Exception; /** * Get the correct forward to which control should be transferred. This * will inspect a value object looking for errors, and will return a * forward to the location specified in the action's 'input' parameter if * any are present (adding the appropriate <code>ActionErrors</code> to the * request). In the absence of errors, a forward to the location specified * in the <code>successMapping</code> parameter will be returned. * * @param mapping The <code>ActionMapping</code> used to find forwards * @param request The HTTP request being processed * @param valueObject The object to be checked for errors * @param successMapping The name of the forward to be retrieved if no * errors are present * @return The forward describing where/how to forward control */ protected ActionForward findForward(ActionMapping mapping, HttpServletRequest request, DTO valueObject, String successMapping) { if (LOG.isDebugEnabled()) { LOG.debug("findForward: Finding appropriate forward, hasErrors=" + valueObject.hasErrors() + ", successMapping=" + successMapping); } ActionForward forward = null; if (valueObject.hasErrors()) { ActionErrors actionErrors = new ActionErrors(); List errors = valueObject.getErrors(); IError error = null; for (int i = 0; i < errors.size(); i++) { error = (IError) errors.get(i); ActionMessage message = new ActionMessage(error.getKey(), error.getInserts()); actionErrors.add(ActionMessages.GLOBAL_MESSAGE, message); request.setAttribute(Globals.ERROR_KEY, actionErrors); } forward = mapping.getInputForward(); } else { forward = mapping.findForward(successMapping); } if (LOG.isDebugEnabled()) { LOG.debug("findForward: Returning forward, name=" + forward.getName() + " path=" + forward.getPath()); } return forward; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -