001: /*
002: * $Id: RegistrationAction.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.webapp.validator;
023:
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026: import javax.servlet.http.HttpSession;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.apache.struts.action.Action;
031: import org.apache.struts.action.ActionForm;
032: import org.apache.struts.action.ActionForward;
033: import org.apache.struts.action.ActionMapping;
034:
035: /**
036: * Implementation of <strong>Action</strong> that validates a registration form.
037: *
038: */
039: public final class RegistrationAction extends Action {
040:
041: /**
042: * Commons Logging instance.
043: */
044: private Log log = LogFactory.getFactory().getInstance(
045: this .getClass().getName());
046:
047: /**
048: * Process the specified HTTP request, and create the corresponding HTTP
049: * response (or forward to another web component that will create it).
050: * Return an <code>ActionForward</code> instance describing where and how
051: * control should be forwarded, or <code>null</code> if the response has
052: * already been completed.
053: *
054: * @param mapping The ActionMapping used to select this instance
055: * @param form The optional ActionForm bean for this request (if any)
056: * @param request The HTTP request we are processing
057: * @param response The HTTP response we are creating
058: *
059: * @return Action to forward to
060: * @exception Exception if an input/output error or servlet exception occurs
061: */
062: public ActionForward execute(ActionMapping mapping,
063: ActionForm form, HttpServletRequest request,
064: HttpServletResponse response) throws Exception {
065:
066: // Was this transaction cancelled?
067: if (isCancelled(request)) {
068: if (log.isInfoEnabled()) {
069: log.info(" " + mapping.getAttribute()
070: + " - Registration transaction was cancelled");
071: }
072:
073: removeFormBean(mapping, request);
074:
075: return (mapping.findForward("success"));
076: }
077:
078: return mapping.findForward("success");
079: }
080:
081: /**
082: * Convenience method for removing the obsolete form bean.
083: *
084: * @param mapping The ActionMapping used to select this instance
085: * @param request The HTTP request we are processing
086: */
087: protected void removeFormBean(ActionMapping mapping,
088: HttpServletRequest request) {
089:
090: // Remove the obsolete form bean
091: if (mapping.getAttribute() != null) {
092: if ("request".equals(mapping.getScope())) {
093: request.removeAttribute(mapping.getAttribute());
094: } else {
095: HttpSession session = request.getSession();
096: session.removeAttribute(mapping.getAttribute());
097: }
098: }
099: }
100: }
|