You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/07/03 04:52:57 UTC

cvs commit: jakarta-struts/src/example/org/apache/struts/webapp/example EditSubscriptionAction.java EditRegistrationAction.java

dgraham     2003/07/02 19:52:57

  Modified:    src/example/org/apache/struts/webapp/example
                        EditSubscriptionAction.java
                        EditRegistrationAction.java
  Log:
  Formatting changes only.
  
  Revision  Changes    Path
  1.11      +62 -57    jakarta-struts/src/example/org/apache/struts/webapp/example/EditSubscriptionAction.java
  
  Index: EditSubscriptionAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/EditSubscriptionAction.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- EditSubscriptionAction.java	11 Jan 2003 03:08:23 -0000	1.10
  +++ EditSubscriptionAction.java	3 Jul 2003 02:52:57 -0000	1.11
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,16 +59,16 @@
    *
    */
   
  -
   package org.apache.struts.webapp.example;
   
  -
   import java.lang.reflect.InvocationTargetException;
   import java.util.Locale;
  +
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
  -import javax.servlet.http.HttpSession;
   import javax.servlet.http.HttpServletResponse;
  +import javax.servlet.http.HttpSession;
  +
   import org.apache.commons.beanutils.PropertyUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -78,7 +78,6 @@
   import org.apache.struts.action.ActionMapping;
   import org.apache.struts.util.MessageResources;
   
  -
   /**
    * Implementation of <strong>Action</strong> that populates an instance of
    * <code>SubscriptionForm</code> from the currently specified subscription.
  @@ -86,23 +85,17 @@
    * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    */
  -
   public final class EditSubscriptionAction extends Action {
   
  -
       // ----------------------------------------------------- Instance Variables
   
  -
       /**
        * The <code>Log</code> instance for this application.
        */
  -    private Log log =
  -        LogFactory.getLog("org.apache.struts.webapp.Example");
  -
  +    private Log log = LogFactory.getLog("org.apache.struts.webapp.Example");
   
       // --------------------------------------------------------- Public Methods
   
  -
       /**
        * Process the specified HTTP request, and create the corresponding HTTP
        * response (or forward to another web component that will create it).
  @@ -118,91 +111,103 @@
        * @exception Exception if the application business logic throws
        *  an exception
        */
  -    public ActionForward execute(ActionMapping mapping,
  -				 ActionForm form,
  -				 HttpServletRequest request,
  -				 HttpServletResponse response)
  -	throws Exception {
  -
  -	// Extract attributes we will need
  -	Locale locale = getLocale(request);
  -	MessageResources messages = getResources(request);
  -	HttpSession session = request.getSession();
  -	String action = request.getParameter("action");
  -	if (action == null) {
  -	    action = "Create";
  +    public ActionForward execute(
  +        ActionMapping mapping,
  +        ActionForm form,
  +        HttpServletRequest request,
  +        HttpServletResponse response)
  +        throws Exception {
  +
  +        // Extract attributes we will need
  +        Locale locale = getLocale(request);
  +        MessageResources messages = getResources(request);
  +        HttpSession session = request.getSession();
  +        String action = request.getParameter("action");
  +        if (action == null) {
  +            action = "Create";
           }
  -	String host = request.getParameter("host");
  +        
  +        String host = request.getParameter("host");
           if (log.isDebugEnabled()) {
  -            log.debug("EditSubscriptionAction:  Processing " + action +
  -                      " action");
  +            log.debug("EditSubscriptionAction:  Processing " + action + " action");
           }
   
  -	// Is there a currently logged on user?
  -	User user = (User) session.getAttribute(Constants.USER_KEY);
  -	if (user == null) {
  +        // Is there a currently logged on user?
  +        User user = (User) session.getAttribute(Constants.USER_KEY);
  +        if (user == null) {
               if (log.isTraceEnabled()) {
  -                log.trace(" User is not logged on in session "
  -                          + session.getId());
  +                log.trace(" User is not logged on in session " + session.getId());
               }
  -	    return (mapping.findForward("logon"));
  -	}
  +            return (mapping.findForward("logon"));
  +        }
   
  -	// Identify the relevant subscription
  -	Subscription subscription =
  +        // Identify the relevant subscription
  +        Subscription subscription =
               user.findSubscription(request.getParameter("host"));
  -	if ((subscription == null) && !action.equals("Create")) {
  +            
  +        if ((subscription == null) && !action.equals("Create")) {
               if (log.isTraceEnabled()) {
  -                log.trace(" No subscription for user " +
  -                          user.getUsername() + " and host " + host);
  +                log.trace(
  +                    " No subscription for user "
  +                        + user.getUsername()
  +                        + " and host "
  +                        + host);
               }
  -	    return (mapping.findForward("failure"));
  -	}
  +            
  +            return (mapping.findForward("failure"));
  +        }
  +        
           if (subscription != null) {
               session.setAttribute(Constants.SUBSCRIPTION_KEY, subscription);
           }
   
  -	// Populate the subscription form
  -	if (form == null) {
  +        // Populate the subscription form
  +        if (form == null) {
               if (log.isTraceEnabled()) {
  -                log.trace(" Creating new SubscriptionForm bean under key "
  -                          + mapping.getAttribute());
  +                log.trace(
  +                    " Creating new SubscriptionForm bean under key "
  +                        + mapping.getAttribute());
               }
  -	    form = new SubscriptionForm();
  +            
  +            form = new SubscriptionForm();
               if ("request".equals(mapping.getScope())) {
                   request.setAttribute(mapping.getAttribute(), form);
               } else {
                   session.setAttribute(mapping.getAttribute(), form);
               }
  -	}
  -	SubscriptionForm subform = (SubscriptionForm) form;
  -	subform.setAction(action);
  +        }
  +        
  +        SubscriptionForm subform = (SubscriptionForm) form;
  +        subform.setAction(action);
           if (!action.equals("Create")) {
               if (log.isTraceEnabled()) {
                   log.trace(" Populating form from " + subscription);
               }
  +            
               try {
                   PropertyUtils.copyProperties(subform, subscription);
                   subform.setAction(action);
  +                
               } catch (InvocationTargetException e) {
                   Throwable t = e.getTargetException();
                   if (t == null)
                       t = e;
                   log.error("SubscriptionForm.populate", t);
                   throw new ServletException("SubscriptionForm.populate", t);
  +                
               } catch (Throwable t) {
                   log.error("SubscriptionForm.populate", t);
                   throw new ServletException("SubscriptionForm.populate", t);
               }
           }
   
  -	// Forward control to the edit subscription page
  +        // Forward control to the edit subscription page
           if (log.isTraceEnabled()) {
               log.trace(" Forwarding to 'success' page");
           }
  -	return (mapping.findForward("success"));
  +        
  +        return (mapping.findForward("success"));
   
       }
  -
   
   }
  
  
  
  1.11      +58 -55    jakarta-struts/src/example/org/apache/struts/webapp/example/EditRegistrationAction.java
  
  Index: EditRegistrationAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/EditRegistrationAction.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- EditRegistrationAction.java	11 Jan 2003 03:08:23 -0000	1.10
  +++ EditRegistrationAction.java	3 Jul 2003 02:52:57 -0000	1.11
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,16 +59,16 @@
    *
    */
   
  -
   package org.apache.struts.webapp.example;
   
  -
   import java.lang.reflect.InvocationTargetException;
   import java.util.Locale;
  +
   import javax.servlet.ServletException;
  -import javax.servlet.http.HttpSession;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  +import javax.servlet.http.HttpSession;
  +
   import org.apache.commons.beanutils.PropertyUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -78,7 +78,6 @@
   import org.apache.struts.action.ActionMapping;
   import org.apache.struts.util.MessageResources;
   
  -
   /**
    * Implementation of <strong>Action</strong> that populates an instance of
    * <code>RegistrationForm</code> from the profile of the currently logged on
  @@ -87,23 +86,17 @@
    * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    */
  -
   public final class EditRegistrationAction extends Action {
   
  -
       // ----------------------------------------------------- Instance Variables
   
  -
       /**
        * The <code>Log</code> instance for this application.
        */
  -    private Log log =
  -        LogFactory.getLog("org.apache.struts.webapp.Example");
  -
  +    private Log log = LogFactory.getLog("org.apache.struts.webapp.Example");
   
       // --------------------------------------------------------- Public Methods
   
  -
       /**
        * Process the specified HTTP request, and create the corresponding HTTP
        * response (or forward to another web component that will create it).
  @@ -119,84 +112,94 @@
        * @exception Exception if the application business logic throws
        *  an exception
        */
  -    public ActionForward execute(ActionMapping mapping,
  -				 ActionForm form,
  -				 HttpServletRequest request,
  -				 HttpServletResponse response)
  -	throws Exception {
  -
  -	// Extract attributes we will need
  -	Locale locale = getLocale(request);
  -	MessageResources messages = getResources(request);
  -	HttpSession session = request.getSession();
  -	String action = request.getParameter("action");
  -	if (action == null)
  -	    action = "Create";
  +    public ActionForward execute(
  +        ActionMapping mapping,
  +        ActionForm form,
  +        HttpServletRequest request,
  +        HttpServletResponse response)
  +        throws Exception {
  +
  +        // Extract attributes we will need
  +        Locale locale = getLocale(request);
  +        MessageResources messages = getResources(request);
  +        HttpSession session = request.getSession();
  +        String action = request.getParameter("action");
  +        if (action == null) {
  +            action = "Create";
  +        }
  +        
           if (log.isDebugEnabled()) {
  -            log.debug("EditRegistrationAction:  Processing " + action +
  -                        " action");
  +            log.debug("EditRegistrationAction:  Processing " + action + " action");
           }
   
  -	// Is there a currently logged on user?
  -	User user = null;
  -	if (!"Create".equals(action)) {
  -	    user = (User) session.getAttribute(Constants.USER_KEY);
  -	    if (user == null) {
  +        // Is there a currently logged on user?
  +        User user = null;
  +        if (!"Create".equals(action)) {
  +            user = (User) session.getAttribute(Constants.USER_KEY);
  +            if (user == null) {
                   if (log.isDebugEnabled()) {
  -                    log.debug(" User is not logged on in session "
  -                              + session.getId());
  +                    log.debug(
  +                        " User is not logged on in session " + session.getId());
                   }
  -		return (mapping.findForward("logon"));
  -	    }
  -	}
  +                return (mapping.findForward("logon"));
  +            }
  +        }
   
  -	// Populate the user registration form
  -	if (form == null) {
  +        // Populate the user registration form
  +        if (form == null) {
               if (log.isTraceEnabled()) {
  -                log.trace(" Creating new RegistrationForm bean under key "
  -                          + mapping.getAttribute());
  +                log.trace(
  +                    " Creating new RegistrationForm bean under key "
  +                        + mapping.getAttribute());
               }
  -	    form = new RegistrationForm();
  -            if ("request".equals(mapping.getScope()))
  +            
  +            form = new RegistrationForm();
  +            if ("request".equals(mapping.getScope())) {
                   request.setAttribute(mapping.getAttribute(), form);
  -            else
  +            } else {
                   session.setAttribute(mapping.getAttribute(), form);
  -	}
  -	RegistrationForm regform = (RegistrationForm) form;
  -	if (user != null) {
  +            }
  +        }
  +        
  +        RegistrationForm regform = (RegistrationForm) form;
  +        if (user != null) {
               if (log.isTraceEnabled()) {
                   log.trace(" Populating form from " + user);
               }
  +            
               try {
                   PropertyUtils.copyProperties(regform, user);
                   regform.setAction(action);
                   regform.setPassword(null);
                   regform.setPassword2(null);
  +                
               } catch (InvocationTargetException e) {
                   Throwable t = e.getTargetException();
                   if (t == null)
                       t = e;
                   log.error("RegistrationForm.populate", t);
                   throw new ServletException("RegistrationForm.populate", t);
  +                
               } catch (Throwable t) {
                   log.error("RegistrationForm.populate", t);
                   throw new ServletException("RegistrationForm.populate", t);
               }
  -	}
  +        }
   
           // Set a transactional control token to prevent double posting
           if (log.isTraceEnabled()) {
               log.trace(" Setting transactional control token");
           }
  +        
           saveToken(request);
   
  -	// Forward control to the edit user registration page
  +        // Forward control to the edit user registration page
           if (log.isTraceEnabled()) {
               log.trace(" Forwarding to 'success' page");
           }
  -	return (mapping.findForward("success"));
  +        
  +        return (mapping.findForward("success"));
   
       }
  -
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org