1 /* 2 * $Id: RegistrationAction.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 22 package org.apache.struts.webapp.validator; 23 24 import javax.servlet.http.HttpServletRequest; 25 import javax.servlet.http.HttpServletResponse; 26 import javax.servlet.http.HttpSession; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.action.Action; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 35 /** 36 * Implementation of <strong>Action</strong> that validates a registration form. 37 * 38 */ 39 public final class RegistrationAction extends Action { 40 41 /** 42 * Commons Logging instance. 43 */ 44 private Log log = LogFactory.getFactory().getInstance(this.getClass().getName()); 45 46 /** 47 * Process the specified HTTP request, and create the corresponding HTTP 48 * response (or forward to another web component that will create it). 49 * Return an <code>ActionForward</code> instance describing where and how 50 * control should be forwarded, or <code>null</code> if the response has 51 * already been completed. 52 * 53 * @param mapping The ActionMapping used to select this instance 54 * @param form The optional ActionForm bean for this request (if any) 55 * @param request The HTTP request we are processing 56 * @param response The HTTP response we are creating 57 * 58 * @return Action to forward to 59 * @exception Exception if an input/output error or servlet exception occurs 60 */ 61 public ActionForward execute( 62 ActionMapping mapping, 63 ActionForm form, 64 HttpServletRequest request, 65 HttpServletResponse response) 66 throws Exception { 67 68 // Was this transaction cancelled? 69 if (isCancelled(request)) { 70 if (log.isInfoEnabled()) { 71 log.info( 72 " " 73 + mapping.getAttribute() 74 + " - Registration transaction was cancelled"); 75 } 76 77 removeFormBean(mapping, request); 78 79 return (mapping.findForward("success")); 80 } 81 82 return mapping.findForward("success"); 83 } 84 85 /** 86 * Convenience method for removing the obsolete form bean. 87 * 88 * @param mapping The ActionMapping used to select this instance 89 * @param request The HTTP request we are processing 90 */ 91 protected void removeFormBean( 92 ActionMapping mapping, 93 HttpServletRequest request) { 94 95 // Remove the obsolete form bean 96 if (mapping.getAttribute() != null) { 97 if ("request".equals(mapping.getScope())) { 98 request.removeAttribute(mapping.getAttribute()); 99 } else { 100 HttpSession session = request.getSession(); 101 session.removeAttribute(mapping.getAttribute()); 102 } 103 } 104 } 105 }