nbubna      2003/03/05 16:05:19

  Added:       examples/struts/WEB-INF/src/examples/app1 AddressAction.java
                        AddressBean.java AddressForm.java
               examples/struts/WEB-INF/src/examples/app2 DemoAction.java
                        DemoForm.java
               examples/struts/WEB-INF/src/examples/app3 Constants.java
                        ContinueAction.java LogoffAction.java
                        LogonAction.java LogonForm.java
  Log:
  add example src files from old directory structure
  
  Revision  Changes    Path
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app1/AddressAction.java
  
  Index: AddressAction.java
  ===================================================================
  /*
   * Struts Example Application 1
   *  
   * This demonstrates the use of Velocity templates with the Struts framework.
   */
  
  
  package examples.app1;
  
  
  import java.io.IOException;
  import java.util.Hashtable;
  import java.util.Locale;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionError;
  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.ActionServlet;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * <p>A simple action that handles the display and editing of an
   * addres record. This action works with both JSP and Velocity templates.
   * The type of template to be used is defined in the Struts configuration
   * file.</p>
   *
   * <p>The action support an <i>action</i> URL parameter. This URL parameter
   * controls what this action class does. The following values are supported:</p>
   * <ul>
   *   <li>list - list address record, this is the default if no action parameter is 
specified
   *   <li>edit - edit address record
   *   <li>save - save address record
   * </ul>
   * 
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"/>Gabe Sidler</a>
   * @version $Id: AddressAction.java,v 1.1 2003/03/06 00:05:18 nbubna Exp $
   */
  public class AddressAction extends Action 
  {
  
      // --------------------------------------------------------- Public Methods
  
      /**
       * Handle server requests.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                                   throws IOException, ServletException
      {
          String action;
          HttpSession session;
  
          ActionErrors errors = new ActionErrors();
  
          try
          {
              session = request.getSession();
      
              // fetch action from form
              action = ((AddressForm)form).getAction();
  
              servlet.log("[DEBUG] AddressAction at perform(): Action ist " + action);
  
              // Determine what to do
              if ( action.equals("edit") )
              {
                  // forward to edit formular
                  return (mapping.findForward("editAddress"));
      
              }
              else if (action.equals("save"))
              {
                  // check if an address bean exits already
                  AddressBean bean = (AddressBean)session.getAttribute("address");
                  
                  if (bean == null)
                  {
                      bean = new AddressBean();
                      session.setAttribute("address", bean);
                  }
                   
                  // update bean with the new values submitted
                  bean.setFirstname( ((AddressForm)form).getFirstname() );
                  bean.setLastname( ((AddressForm)form).getLastname() );
                  bean.setStreet( ((AddressForm)form).getStreet() );
                  bean.setZip( ((AddressForm)form).getZip() );
                  bean.setCity( ((AddressForm)form).getCity() );
                  bean.setCountry( ((AddressForm)form).getCountry() );
                  bean.setLanguages( ((AddressForm)form).getLanguages() );
  
                  // forward to list
                  return (mapping.findForward("showAddress"));
      
              }
              else
              {
                  String locale = ((AddressForm)form).getLocale();
                  if (locale.equals("Deutsch"))
                      session.setAttribute(Action.LOCALE_KEY, new Locale("de", ""));
                  else
                      session.setAttribute(Action.LOCALE_KEY, new Locale("en", ""));
                  
                  // forward to edit formular
                  return (mapping.findForward("showAddress"));                
              }
          }
          catch (Exception e)
          {
              //errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("lo053"));
              servlet.log("[ERROR] TskAction at final catch: " + e.getMessage());
              e.printStackTrace();
  
          }
  
          // Default if everthing else fails
          return (mapping.findForward("showAddress"));
  
      }
  }
  
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app1/AddressBean.java
  
  Index: AddressBean.java
  ===================================================================
  /*
   * Struts Example Application 1
   *  
   * This demonstrates the use of Velocity templates with the Struts framework.
   */
  
  
  package examples.app1;
  
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  
  import java.util.Properties;
  
  
  /**
   * <p>A simple bean that represent an address record.</p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"/>Gabe Sidler</a>
   * @version $Id: AddressBean.java,v 1.1 2003/03/06 00:05:18 nbubna Exp $
   */
  
  public class AddressBean extends Object 
  {
  
  
      // ---- Fields ------------------------------------------------------
      private String firstname;
      
      private String lastname;
  
      private String street;
      
      private String zip;
      
      private String city;
      
      private String country;
      
      private String[] languages;
      
  
      // ---- Accessor Methods --------------------------------------------
      
      public String getFirstname()
      {
          return firstname;
              
      }
      
      public void setFirstname(String s)
      {
          firstname = s;
              
      }
      
      public String getLastname()
      {
          return lastname;
              
      }
      
      public void setLastname(String s)
      {
          lastname = s;
              
      }
  
      public String getStreet()
      {
          return street;
              
      }
      
      public void setStreet(String s)
      {
          street = s;
              
      }
  
      public String getZip()
      {
          return zip;
              
      }
      
      public void setZip(String s)
      {
          zip = s;
              
      }
  
      public String getCity()
      {
          return city;
              
      }
      
      public void setCity(String s)
      {
          city = s;
              
      }
  
      public String getCountry()
      {
          return country;
              
      }
      
      public void setCountry(String s)
      {
          country = s;
              
      }
  
      public String[] getLanguages()
      {
          return languages;
      }
      
      public void setLanguages(String[] languages)
      {
          this.languages = languages;   
      }
  
      // Convenience method to simplify repopulation of select lists
      public Properties getLanguagesAsMap()
      {
          Properties p = new Properties();
          if (languages != null)
          {
              for (int i = 0; i < languages.length; i++)
                  p.setProperty((String)languages[i], "SELECTED");
          }            
          return p;
      } 
         
  }
  
  
  
  
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app1/AddressForm.java
  
  Index: AddressForm.java
  ===================================================================
  /*
   * Struts Example Application 1
   *  
   * This demonstrates the use of Velocity templates with the Struts framework.
   */
  
  
  package examples.app1;
  
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  
  import java.util.ArrayList;
  
  
  /**
   * <p>A simple form that allows a user to enter and modify an address.</p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"/>Gabe Sidler</a>
   * @version $Id: AddressForm.java,v 1.1 2003/03/06 00:05:18 nbubna Exp $
   */
  
  public final class AddressForm extends ActionForm 
  {
  
      // ---- Form fields -------------------------------------------------
   
      private String action = "";
      
      private String firstname = "";
      
      private String lastname = "";
  
      private String street = "";
      
      private String zip = "";
      
      private String city = "";
      
      private String country = "";
      
      private String locale = "";
      
      private String[] languages;
      
  
      // ---- Accessor Methods --------------------------------------------
      
      public String getAction()
      {
          return action;
      }
      
      public void setAction(String s)
      {
          action = s;
      }
              
      public String getFirstname()
      {
          return firstname;
      }
      
      public void setFirstname(String s)
      {
          firstname = s;
      }
      
      public String getLastname()
      {
          return lastname;
      }
      
      public void setLastname(String s)
      {
          lastname = s;
      }
  
      public String getStreet()
      {
          return street;
      }
      
      public void setStreet(String s)
      {
          street = s;
      }
  
      public String getZip()
      {
          return zip;
      }
      
      public void setZip(String s)
      {
          zip = s;
      }
  
      public String getCity()
      {
          return city;
      }
      
      public void setCity(String s)
      {
          city = s;
      }
  
      public String getCountry()
      {
          return country;
      }
      
      public void setCountry(String s)
      {
          country = s;
      }
  
      public String getLocale()
      {
          return locale;
      }
      
      public void setLocale(String s)
      {
          locale = s;
      }
  
      public String[] getLanguages()
      {
          return languages;
      }
      
      public void setLanguages(String[] s)
      {
          languages = s;
      }
      
  
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) 
      {
  
          action = "";
          locale = "";
          firstname = "";
          lastname = "";
          street = "";
          zip = "";
          city = "";
          country = "";
  
      }
  
  }
  
  
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app2/DemoAction.java
  
  Index: DemoAction.java
  ===================================================================
  /*
   * Struts Example Application 1
   *  
   * This demonstrates the use of Velocity templates with the Struts framework.
   */
  
  
  package examples.app2;
  
  
  import java.io.IOException;
  import java.util.Hashtable;
  import java.util.Locale;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionError;
  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.ActionServlet;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * <p>A simple action used to demonstrate the view tools.</p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"/>Gabe Sidler</a>
   * @version $Id: DemoAction.java,v 1.1 2003/03/06 00:05:18 nbubna Exp $
   */
  public class DemoAction extends Action 
  {
  
  
      // --------------------------------------------------------- Public Methods
  
        /**
         * Handle server requests.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
         */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                                   throws IOException, ServletException
      {
          String action;
            HttpSession session;
  
          // Create serveral error messages to demontrate the output in a template
          ActionErrors errors = new ActionErrors();
          
          // Add some global errors
          errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error01"));
          errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error02"));
  
          // Add some specific errors
          errors.add("language", new ActionError("error10"));
          errors.add("language", new ActionError("error11"));
          
          // Save error messages to request attributes
          saveErrors(request, errors);
  
          // Create and save a new transaction token
          saveToken(request);
  
          // forward to edit formular
          return (mapping.findForward("home"));
  
      }
  }
  
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app2/DemoForm.java
  
  Index: DemoForm.java
  ===================================================================
  /*
   * Struts Example Application 2
   *  
   * This demonstrates the use of Velocity templates with the Struts framework.
   */
  
  
  package examples.app2;
  
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  
  
  /**
   * <p>A simple form for demo purposes.</p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]"/>Gabe Sidler</a>
   * @version $Id: DemoForm.java,v 1.1 2003/03/06 00:05:18 nbubna Exp $
   */
  
  public final class DemoForm extends ActionForm 
  {
  
      // ---- Form fields -------------------------------------------------
   
      private String language = "";
      
  
      // ---- Accessor Methods --------------------------------------------
      
      public String getLanguage()
      {
          return language;
      }
      
      public void setLanguage(String s)
      {
          language = s;
      }
  
  
  
  
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) 
      {
  
          language = "";
  
      }
  
  }
  
  
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app3/Constants.java
  
  Index: Constants.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package examples.app3;
  
  
  /**
   * Manifest constants for this application.
   *
   * @author Craig R. McClanahan
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2003/03/06 00:05:18 $
   */
  
  public final class Constants 
  {
  
  
      /**
       * The package name for this application.
       */
      public static final String Package = "app";
  
  
      /**
       * The session scope attribute under which the Username
       * for the currently logged in user is stored.
       */
      public static final String USER_KEY = "user";
  
  
      /**
       * The token that represents a nominal outcome
       * in an ActionForward.
       */
      public static final String CONTINUE = "continue";
  
  
      /**
       * The value to indicate debug logging.
       */
      public static final int DEBUG = 1;
  
  
      /**
       * The value to indicate normal logging.
       */
      public static final int NORMAL = 0;
  
  }
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app3/ContinueAction.java
  
  Index: ContinueAction.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package examples.app3;
  
  
  import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.action.ActionServlet;
  
  
  
  /**
   * Standard Action to render image.
   * @author Simon Oldeboershuis
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2003/03/06 00:05:18 $
   */
  public final class ContinueAction extends Action 
  {
  
      /**
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                                   throws IOException, ServletException 
      {
  
          return mapping.findForward(Constants.CONTINUE);
  
      }
  
  } // end ContinueAction
  
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app3/LogoffAction.java
  
  Index: LogoffAction.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package examples.app3;
  
  import java.io.IOException;
  import java.util.Hashtable;
  import java.util.Locale;
  import java.util.Vector;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.action.ActionServlet;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * Implementation of <strong>Action</strong> that processes a
   * user logoff.
   *
   * @author Craig R. McClanahan
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2003/03/06 00:05:18 $
   */
  
  public final class LogoffAction extends Action 
  {
  
      // ---------------------------------------------------- Public Methods
  
      /**
       * Logoff the user.
       * The event is logged if the debug level is >= Constants.DEBUG.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                                   throws IOException, ServletException 
      {
  
        // Extract attributes we will need
        HttpSession session = request.getSession();
        LogonForm user = (LogonForm)
          session.getAttribute(Constants.USER_KEY);
  
        // Log this user logoff
        if (user != null) 
        {
  
          if (servlet.getDebug() >= Constants.DEBUG) 
          {
              StringBuffer message =
                  new StringBuffer("LogoffAction: User '");
              message.append(user.getUsername());
              message.append("' logged off in session ");
              message.append(session.getId());
              servlet.log(message.toString());
          }
        }
  
        else 
        {
  
          if (servlet.getDebug() >= Constants.DEBUG) 
          {
              StringBuffer message =
                  new StringBuffer("LogoffAction: User '");
              message.append(session.getId());
              servlet.log(message.toString());
          }
  
        }
  
        // Remove user login; invalidate session
        session.removeAttribute(Constants.USER_KEY);
        session.invalidate();
  
        // Forward control to the specified success URI
        return (mapping.findForward(Constants.CONTINUE));
  
      }
  
  } // End LogoffAction
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app3/LogonAction.java
  
  Index: LogonAction.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package examples.app3;
  
  import java.io.IOException;
  import java.util.Hashtable;
  import java.util.Locale;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionError;
  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.ActionServlet;
  import org.apache.struts.util.MessageResources;
  
  
  /**
   * Implementation of <strong>Action</strong> that validates a user logon.
   *
   * @author Craig R. McClanahan
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2003/03/06 00:05:18 $
   */
  
  public final class LogonAction extends Action 
  {
  
  
  // ---------------------------------------------------- Public Methods
  
      /**
       * Login the user.
       * The event is logged if the debug level is >= Constants.DEBUG.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param actionForm The ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The HTTP response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                                   throws IOException, ServletException 
      {
  
        String username = ((LogonForm) form).getUsername();
        String password = ((LogonForm) form).getPassword();
  
        // Save our logged-in user in the session,
        // because we use it again later.
        HttpSession session = request.getSession();
        session.setAttribute(Constants.USER_KEY, form);
  
        // Log this event, if appropriate
        if (servlet.getDebug() >= Constants.DEBUG) 
        {
            StringBuffer message =
              new StringBuffer("LogonAction: User '");
            message.append(username);
            message.append("' logged on in session ");
            message.append(session.getId());
            servlet.log(message.toString());
        }
  
        // Forward control to the success URI
        // specified in struts-config.xml
        return (mapping.findForward(Constants.CONTINUE));
  
    }
  
  }
  
  
  
  1.1                  
jakarta-velocity-tools/examples/struts/WEB-INF/src/examples/app3/LogonForm.java
  
  Index: LogonForm.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package examples.app3;
  
  
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionMapping;
  
  
  /**
   * Form bean for the user profile page.
   * This form has the following fields,
   * with default values in square brackets:
   * <ul>
   * <li><b>password</b> - Entered password value
   * <li><b>username</b> - Entered username value
   * </ul>
   *
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2003/03/06 00:05:18 $
   */
  
  public final class LogonForm extends ActionForm 
  {
  
  
  
  
      // ------------------------------------------------ Instance Variables
  
  
      /**
       * The password.
       */
      private String password = null;
  
  
      /**
       * The username.
       */
      private String username = null;
  
  
      // ------------------------------------------------------ Properties
  
      /**
       * Return the password.
       */
      public String getPassword() 
      {
  
          return (this.password);
  
      }
  
  
      /**
       * Set the password.
       *
       * @param password The new password
       */
      public void setPassword(String password) 
      {
  
          this.password = password;
  
      }
  
  
      /**
       * Return the username.
       */
      public String getUsername() 
      {
  
          return (this.username);
  
      }
  
  
      /**
       * Set the username.
       *
       * @param username The new username
       */
      public void setUsername(String username) 
      {
  
          this.username = username;
  
      }
  
  
      // -------------------------------------------------- Public Methods
  
  
      /**
       * Reset all properties to their default values.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping,
          HttpServletRequest request) 
      {
  
          setPassword(null);
          setUsername(null);
  
      }
  
  
      /**
       * Ensure that both fields have been input.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public ActionErrors validate(ActionMapping mapping,
                                   HttpServletRequest request) 
      {
  
          ActionErrors errors = new ActionErrors();
  
          if ((username == null) || (username.length() < 1))
              errors.add("username", new ActionError("error.username.required"));
  
          if ((password == null) || (password.length() < 1))
              errors.add("password", new ActionError("error.password.required"));
  
          return errors;
  
      }
  
  } // End LogonForm
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to