dwinterfeldt    01/07/08 20:15:15

  Added:       
contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc
                        ApplicationResources.properties
                        ApplicationResources_fr.properties
                        MultiRegistrationForm.java RegistrationAction.java
                        RegistrationForm.java TypeAction.java TypeForm.java
  Log:
  Adding Struts Validator.
  
  Revision  Changes    Path
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/ApplicationResources.properties
  
  Index: ApplicationResources.properties
  ===================================================================
  # Buttons/Links
  button.cancel=Cancel
  button.confirm=Confirm
  button.reset=Reset
  button.save=Save
  button.search=Search
  button.edit=Edit
  button.delete=Delete
  button.report=Report
  button.add=Add
  button.move=Move
  
  # Errors
  error.system=System error, please try again.
  errors.footer=
  errors.header=<h3><font color="red">Validation Error</font></h3>You must correct the 
following error(s) before proceeding:
  errors.ioException=I/O exception rendering error messages: {0}
  error.database.missing=<li>User database is missing, cannot validate logon 
credentials</li>
  errors.required={0} is required.
  errors.invalid={0} is invalid.
  
  errors.byte={0} must be an byte.
  errors.short={0} must be an short.
  errors.integer={0} must be an integer.
  errors.long={0} must be an long.
  errors.float={0} must be an float.
  errors.double={0} must be an double.
  
  errors.date={0} is not a date.
  
  errors.range={0} is not in the range {1} through {2}.
  
  
  # Application Level Messages
  app.home=Home
  app.logoff=Log off
  app.logon=Log on
  app.search.name=Name
  app.search.noresults=No results were found for your search.
  app.insert.duplicateonunique={0} already exists.
  app.update.duplicateonunique={0} already exists.
  app.delete={0} has been deleted.
  
  
  # Registration Form                                     
  registrationForm.title=Registration
  registrationForm.title.create=Register
  #registrationForm.title.edit=Edit User Information
  registrationForm.title.search=Registration Search
  registrationForm.firstname.displayname=First Name
  registrationForm.lastname.displayname=Last Name
  registrationForm.addr.displayname=Address
  registrationForm.city.displayname=City
  registrationForm.stateprov.displayname=State
  registrationForm.zippostal.displayname=Zip
  registrationForm.phone.displayname=Phone
  registrationForm.email.displayname=E-mail
  registrationForm.lastname.maskmsg=Last Name can only be letters and numbers, no 
spaces.
  
  # Javascript Registration Form                                     
  jsRegistrationForm.title=Javascript Registration
  jsRegistrationForm.title.search=Javascript Registration Search
  
  # Multi-Part Javascript Registration Form                                     
  multiRegistrationForm.title=Multi-Part Javascript Registration
  multiRegistrationForm.title.search=Multi-Part Javascript Registration Search
  
  
  # Type form
  typeForm.title=Type Form
  typeForm.title.create=Type Form
  typeForm.byte.displayname=Byte Field
  typeForm.short.displayname=Short Field
  typeForm.integer.displayname=Integer Field
  typeForm.long.displayname=Long Field
  typeForm.float.displayname=Float Field
  typeForm.double.displayname=Double Field
  typeForm.date.displayname=Date Field
  
  #Language
  changeLanguage.change=Change Language to:
  changeLanguage.english=English
  changeLanguage.french=French
  
  
  
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/ApplicationResources_fr.properties
  
  Index: ApplicationResources_fr.properties
  ===================================================================
  button.cancel=Annulent
  button.confirm=Confirment
  button.reset=Remettent
  button.save=�conomiser
  button.search=Recherche
  button.edit=�ditent
  button.delete=Effacement
  button.report=�tat
  button.add=Ajoutent
  button.move=Se d�placent
  
  
  # Errors
  error.system=L'erreur syst�me, essayent s'il vous pla�t encore.
  errors.footer=
  errors.header=<h3><font color="red">Erreur De Validation</font></h3>Vous devez 
corriger l'error(s) suivant avant proc�dant:
  errors.ioException=Exception de E/S rendant des messages d'erreur: {0}
  error.database.missing=<li>La base de données d'utilisateur est manquante, ne peut 
pas valider des qualifications de procédure de connexion </li>
  errors.required={0} est exig�.
  errors.invalid={0} est incorrect.
  
  errors.byte=Le {0} doit �tre un nombre byte.
  errors.short=Le {0} doit �tre un nombre short.
  errors.integer=Le {0} doit �tre un nombre integer.
  errors.long=Le {0} doit �tre un nombre long.
  errors.float=Le {0} doit �tre un nombre float.
  errors.double=Le {0} doit �tre un nombre double.
  
  errors.date=Le {0} n'est pas une date.
  
  errors.range=Le {0} n'est pas dans l'intervalle {1} � {2}
  
  
  
  # Application Level Messages
  app.home=� la maison
  app.logoff=Fermeture de session
  app.logon=Entrent
  app.search.name=Nom
  app.search.noresults=Aucun r�sultat n'a �t� trouv� pour votre recherche.
  app.insert.duplicateonunique=Le {0} existe d�j�.
  app.update.duplicateonunique=Le {0} existe d�j�.
  app.delete=Le {0} a �t� effac�.
  
  
  # Registration Form                                     
  registrationForm.title=Enregistrement
  registrationForm.title.create=Registre
  registrationForm.title.edit=�ditez L'Information D'Utilisateur
  registrationForm.title.search=Recherche D'Enregistrement
  registrationForm.firstname.displayname=Pr�nom
  registrationForm.lastname.displayname=Dernier Nom
  registrationForm.addr.displayname=Adresse
  registrationForm.city.displayname=Ville
  registrationForm.stateprov.displayname=�tat/Province
  registrationForm.zippostal.displayname=Code postal
  registrationForm.phone.displayname=T�l�phone
  registrationForm.email.displayname=E-mail
  registrationForm.lastname.maskmsg=Le dernier nom peut seulement être des lettres et 
des nombres, aucuns espaces.
  
  # Javascript Registration Form                                     
  jsRegistrationForm.title=Enregistrement De Javascript
  jsRegistrationForm.title.search=Recherche D'Enregistrement De Javascript
  
  # Multi-Part Javascript Registration Form                                     
  multiRegistrationForm.title=Enregistrement De liasse multiple De Javascript
  multiRegistrationForm.title.search=Recherche De liasse multiple D'Enregistrement De 
Javascript
  
  
  # Type form
  typeForm.title=Type Form
  typeForm.title.create=Type Form
  typeForm.byte.displayname=Byte Field
  typeForm.short.displayname=Short Field
  typeForm.integer.displayname=Integer Field
  typeForm.long.displayname=Long Field
  typeForm.float.displayname=Float Field
  typeForm.double.displayname=Double Field
  typeForm.date.displayname=Date Field
  
  #Language
  changeLanguage.change=Changez le langage en:
  changeLanguage.english=Les anglais
  changeLanguage.french=Les fran�ais
  
  
  
  
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/MultiRegistrationForm.java
  
  Index: MultiRegistrationForm.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", "Struts", 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 com.wintecinc.struts.example.validator.jdbc;
  
  import java.io.Serializable;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionMapping;
  
  
  /**
   * Form bean for the user registration page.
   *
   * @author David Wintefeldt
  */
  public class MultiRegistrationForm extends RegistrationForm implements Serializable {
          
      /**
       * Method is overridden so values are not lost since the bean 
       * is in session scope.
       *
       * @param mapping The mapping used to select this instance
       * @param request The servlet request we are processing
       */
      public void reset(ActionMapping mapping, HttpServletRequest request) {
  
      }
  
  }
  
  
  
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/RegistrationAction.java
  
  Index: RegistrationAction.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", "Struts", 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 com.wintecinc.struts.example.validator.jdbc;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionError;
  import org.apache.struts.action.ActionErrors;
  import com.wintecinc.struts.action.ActionMessage;
  import com.wintecinc.struts.action.ActionMessages;
  import com.wintecinc.struts.action.GenericAction;
  import com.wintecinc.struts.action.GenericForm;
  
  
  /**
   * Implementation of <strong>Action</strong> that validates a registration form.
   *
   * @author David Wintefeldt
  */
  public class RegistrationAction extends GenericAction {
  
      /**
       * Inserts a row into the table associated with this Action.
       *
       * @param         request         <code>HttpServletRequest</code> associated 
with this action.
       * @param         form            <code>GenericForm</code> associated with this 
action.
      */  
      protected void insert(HttpServletRequest request, GenericForm form) throws 
Exception {
        RegistrationForm info = (RegistrationForm)form;
          Connection con = null;
          PreparedStatement pstmt = null;     
          Statement stmt = null;        
          ResultSet rs = null;           
          
          try {
              // Need a logged in user.
              String sUserName = ""; //request.getUserPrincipal().getName();
              con = getConnection();
              con.setAutoCommit(false);
  
              stmt = con.createStatement();
             
              rs = stmt.executeQuery("SELECT ID FROM REGISTRATION where 
UPPER(LAST_NAME)='" + info.getLastName().toUpperCase() + "'");
              
              if (rs.next()) {
               ActionErrors errors = new ActionErrors();
               String name = info.getLastName() + " " + info.getLastName();
                 errors.add("lastName", new 
ActionError("app.insert.duplicateonunique", name)); 
  
                 saveErrors(request, errors);
                 throw new DuplicateNameException(name + " already exists.");
              }            
              
              String sQuery = "INSERT INTO REGISTRATION (ID, FIRST_NAME, LAST_NAME, 
ADDR, CITY, STATE_PROV, ZIP_POSTAL, PHONE, EMAIL, " +
                                                       " B_ACTIVE, DATE_CREATED, 
DATE_MODIFIED, USER_NAME) " +
                                                       " VALUES(?, ?, ?, ?, ?, ?, ?, 
?, ?, ?, ?, ?, ?)";
              
              pstmt = con.prepareStatement(sQuery);
  
            pstmt.setInt(1, getNextKey(con, "REGISTRATION", "ID"));
              pstmt.setString(2, info.getFirstName());
            pstmt.setString(3, info.getLastName());
            pstmt.setString(4, info.getAddr());
            pstmt.setString(5, info.getCity());
            pstmt.setString(6, info.getStateProv());
            pstmt.setString(7, info.getZipPostal());
            pstmt.setString(8, info.getPhone());
            pstmt.setString(9, info.getEmail());
            pstmt.setBoolean(10, true);
            pstmt.setTimestamp(11, new java.sql.Timestamp(new 
java.util.Date().getTime())); 
            pstmt.setTimestamp(12, new java.sql.Timestamp(new 
java.util.Date().getTime())); 
            pstmt.setString(13, sUserName);
            
            pstmt.execute();
            
            con.commit();
          } catch (Exception e) {
             if (con != null)
                try { con.rollback(); } catch (Exception ex) {}
             log("RegistrationAction::insert() - " + e.getMessage(), e);
             throw e;
          } finally {
             if (rs != null)
                try { rs.close(); } catch (Exception e) {}
             if (stmt != null)
                try { stmt.close(); } catch (Exception e) {}
             if (pstmt != null)
                try { pstmt.close(); } catch (Exception e) {}
             if (con != null)
                try { con.close(); } catch (Exception e) {}
          }
      }
  
      /**
       * Updates a row into the table associated with this Action.
       *
       * @param         request         <code>HttpServletRequest</code> associated 
with this action.
       * @param         form            <code>GenericForm</code> associated with this 
action.
      */
      protected void update(HttpServletRequest request, GenericForm form) throws 
Exception {
        RegistrationForm info = (RegistrationForm)form;
          Connection con = null;
        PreparedStatement pstmt = null;
        
          try {
              // Need a logged in user.
            String sUserName = ""; //request.getUserPrincipal().getName();
            
              con = getConnection();
              String sQuery = "UPDATE REGISTRATION SET FIRST_NAME = ?, " +
                                                     " LAST_NAME = ?,       " +
                                                     " ADDR = ?," +
                                                     " CITY = ?," +
                                                     " STATE_PROV = ?," +
                                                     " ZIP_POSTAL = ?," +
                                                     " PHONE = ?," +
                                                     " EMAIL = ?," +
                                                     //" B_ACTIVE = ?," +
                                                     " DATE_MODIFIED = ?," +
                                                     " USER_NAME = ? " + 
                                                     " WHERE ID = ?";
  
              pstmt = con.prepareStatement(sQuery);
  
              pstmt.setString(1, info.getFirstName());
              pstmt.setString(2, info.getLastName());
              pstmt.setString(3, info.getAddr());
              pstmt.setString(4, info.getCity());
              pstmt.setString(5, info.getStateProv());
              pstmt.setString(6, info.getZipPostal());
              pstmt.setString(7, info.getPhone());
              pstmt.setString(8, info.getEmail());
            pstmt.setTimestamp(9, new java.sql.Timestamp(new 
java.util.Date().getTime())); 
            pstmt.setString(10, sUserName);
            pstmt.setInt(11, getKey(info.getId()));
  
            pstmt.execute();
            
            con.commit();
          } catch (Exception e) {
            log("RegistrationAction::update() - " + e.getMessage(), e);
            throw e;
          } finally {
             if (pstmt != null)
                try { pstmt.close(); } catch (Exception e) {}
             if (con != null)
                try { con.close(); } catch (Exception e) {}
          }
      }
  
      /**
       * Gets a record from the table associated with this Action and returns 
       * it in a <code>GenericForm</code> object.
       *
       * @param         request         <code>HttpServletRequest</code> associated 
with this action.
      */    
      protected GenericForm getInfo(HttpServletRequest request, GenericForm form) {
          Connection con = null;
          Statement stmt = null;
          ResultSet rs = null;
          
          RegistrationForm info = new RegistrationForm();
  
          try {
             con = getConnection();
             stmt = con.createStatement();
             
             rs = stmt.executeQuery("SELECT ID, FIRST_NAME, LAST_NAME, ADDR, CITY, 
STATE_PROV, ZIP_POSTAL, " +
                                    " PHONE, EMAIL FROM REGISTRATION where ID=" + 
getKey(request));
  
              if (rs.next()) {
                  info.setId(rs.getString("ID"));
                  info.setFirstName(rs.getString("FIRST_NAME"));
                  info.setLastName(rs.getString("LAST_NAME"));
                  info.setAddr(rs.getString("ADDR"));
                  info.setCity(rs.getString("CITY"));
                  info.setStateProv(rs.getString("STATE_PROV"));
                  info.setZipPostal(rs.getString("ZIP_POSTAL"));
                  info.setPhone(rs.getString("PHONE"));
                  info.setEmail(rs.getString("EMAIL"));
              }
              
              // ODBC sticks extra spaces to fill up the field so I remove them 
              // Shouldn't happen if you have a direct driver to MySQL, Oracle, MS 
SQL*SERVER
              info.setId((info.getId() != null ? info.getId().trim() : ""));
              info.setFirstName((info.getFirstName() != null ? 
info.getFirstName().trim() : ""));
              info.setLastName((info.getLastName() != null ? info.getLastName().trim() 
: ""));
              info.setAddr((info.getAddr() != null ? info.getAddr().trim() : ""));
              info.setCity((info.getCity() != null ? info.getCity().trim() : ""));
              info.setStateProv((info.getStateProv() != null ? 
info.getStateProv().trim() : ""));
              info.setZipPostal((info.getZipPostal() != null ? 
info.getZipPostal().trim() : ""));
              info.setPhone((info.getPhone() != null ? info.getPhone().trim() : ""));
              info.setEmail((info.getEmail() != null ? info.getEmail().trim() : ""));
  
          } catch (Exception e) {
            log("RegistrationAction::getInfo() - " + e.getMessage(), e);
          } finally {
             if (rs != null)
                try { rs.close(); } catch (Exception e) {}
             if (stmt != null)
                try { stmt.close(); } catch (Exception e) {}
             if (con != null)
                try { con.close(); } catch (Exception e) {}
          }
          return info;
      }
  
      /**
       * Deletes a record.
       *
       * @param         request         <code>HttpServletRequest</code> associated 
with this action.
       * @param         form            <code>GenericForm</code> associated with this 
action.
      */
      protected void delete(HttpServletRequest request, GenericForm form) throws 
Exception {
        RegistrationForm info = (RegistrationForm)form;
          Connection con = null;
          PreparedStatement pstmt = null;
  
          try {
             con = getConnection();
             String sQuery = "DELETE REGISTRATION WHERE ID=?";
             
             pstmt = con.prepareStatement(sQuery);
  
           pstmt.setInt(1, getKey(info.getId()));
  
           pstmt.execute();
           
           String name = info.getFirstName() + " " + info.getLastName();
           
           ActionMessages messages = new ActionMessages();
           messages.add(new ActionMessage("app.delete", name)); 
           saveMessages(request, messages);
           
           con.commit();
          } catch (Exception e) {
            log("RegistrationAction::delete() - " + e.getMessage(), e);
            throw e;
          } finally {
             if (pstmt != null)
                try { pstmt.close(); } catch (Exception e) {}
             if (con != null)
                try { con.close(); } catch (Exception e) {}
          }
      }
  
      /**
       * Searches the table associated with this Action.
       *
       * @param         request         <code>HttpServletRequest</code> associated 
with this action.
      */
      protected void search(HttpServletRequest request, GenericForm form) throws 
Exception {
          Connection con = null;
          Statement stmt = null;
        ResultSet rs = null;
        
        List lResults = new ArrayList();
        RegistrationForm paramInfo = (RegistrationForm)form;
        
          String sQuery = "SELECT ID, FIRST_NAME, LAST_NAME, PHONE, EMAIL FROM 
REGISTRATION ORDER BY LAST_NAME";
          
          if (paramInfo != null && paramInfo.getLastName() != null && 
paramInfo.getLastName().trim().length() > 0)
             sQuery = "SELECT ID, FIRST_NAME, LAST_NAME, PHONE, EMAIL FROM 
REGISTRATION WHERE UPPER(LAST_NAME) LIKE '" + paramInfo.getLastName().toUpperCase() + 
"%' ORDER BY LAST_NAME";
             
          try {
             con = getConnection();
           stmt = con.createStatement();
             rs = stmt.executeQuery(sQuery);
  
           while (rs.next()) {
                RegistrationForm info = new RegistrationForm();
  
                info.setId(rs.getString("ID"));
                info.setFirstName(rs.getString("FIRST_NAME"));
                info.setLastName(rs.getString("LAST_NAME"));
                info.setPhone(rs.getString("PHONE"));
                info.setEmail(rs.getString("EMAIL"));
                lResults.add(info);
           }
  
           saveSearchResults(request, lResults);
          } catch (Exception e) {
            log("RegistrationAction::search() - " + e.getMessage(), e);
            throw e;
          } finally {
             if (rs != null)
                try { rs.close(); } catch (Exception e) {}
             if (stmt != null)
                try { stmt.close(); } catch (Exception e) {}
             if (con != null)
                try { con.close(); } catch (Exception e) {}
          }
      }
  
      /**
       * Retrieves key from the <code>HttpServletRequest</code>.
      */    
      private int getKey(HttpServletRequest request) {
         return getKey(request.getParameter("id"));
      }
  
      /**
       * Retrieves key from a <code>String</code>.
      */    
      private int getKey(String sKey) {
         int iKey = 0;
         try { 
            iKey = Integer.parseInt(sKey);
         } catch (Exception e) { }      
         
         return iKey;
      }
  
  }
  
  
  
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/RegistrationForm.java
  
  Index: RegistrationForm.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", "Struts", 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 com.wintecinc.struts.example.validator.jdbc;
  
  import java.io.Serializable;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionMapping;
  import com.wintecinc.struts.action.GenericForm;
  
  
  /**
   * Form bean for the user registration page.
   *
   * @author David Wintefeldt
  */
  public class RegistrationForm extends GenericForm implements Serializable {
      protected String id = null;       
      protected String sFirstName = null;
      protected String sLastName = null;
      protected String sAddr = null;
      protected String sCity = null;
      protected String sStateProv = null;
      protected String sZipPostal = null;
      protected String sPhone = null;
      protected String sEmail = null;
  
  
      /**
       * Return the id.
      */
      public String getId() {
        return id;
      }
  
      /**
       * Sets the id.
      */
      public void setId(String id) {
        this.id = id;
      }
  
      public String getFirstName() {
         return sFirstName;     
      }
      
      public void setFirstName(String sFirstName) {
                this.sFirstName = sFirstName;
      }
      
      public String getLastName() {
         return sLastName;      
      }
      
      public void setLastName(String sLastName) {
                this.sLastName = sLastName;
      }
  
      public String getAddr() {
         return sAddr;  
      }
      
      public void setAddr(String sAddr) {
                this.sAddr = sAddr;
      }
  
      public String getCity() {
         return sCity;  
      }
      
      public void setCity(String sCity) {
                this.sCity = sCity;
      }
  
      public String getStateProv() {
         return sStateProv;     
      }
      
      public void setStateProv(String sStateProv) {
                this.sStateProv = sStateProv;
      }
  
      public String getZipPostal() {
         return sZipPostal;     
      }
      
      public void setZipPostal(String sZipPostal) {
                this.sZipPostal = sZipPostal;
      }
  
      public String getPhone() {
         return sPhone; 
      }
      
      public void setPhone(String sPhone) {
                this.sPhone = sPhone;
      }
  
      public String getEmail() {
         return sEmail; 
      }
      
      public void setEmail(String sEmail) {
                this.sEmail = sEmail;
      }
          
      /**
       * 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) {
         super.reset(mapping, request);
         
         id = null;
         sFirstName = null;
         sLastName = null;
         sAddr = null;
         sCity = null;
         sStateProv = null;
         sZipPostal = null;
         sPhone = null;
         sEmail = null;
      }
  
  }
  
  
  
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/TypeAction.java
  
  Index: TypeAction.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", "Struts", 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 com.wintecinc.struts.example.validator.jdbc;
  
  import java.io.IOException;
  import java.util.Locale;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  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.util.MessageResources;
  
  
  /**
   * Implementation of <strong>Action</strong> that validates a different 'types'.
   *
   * @author David Wintefeldt
  */
  public final class TypeAction extends Action {
  
  
      /**
       * Process the specified HTTP request, and create the corresponding HTTP
       * response (or forward to another web component that will create it).
       * Return an <code>ActionForward</code> instance describing where and how
       * control should be forwarded, or <code>null</code> if the response has
       * already been completed.
       *
       * @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 {
  
        // Extract attributes we will need
        HttpSession session = request.getSession();
        Locale locale = getLocale(request);
        MessageResources messages = getResources();
        TypeForm info = (TypeForm)form;
        String action = request.getParameter("action");
        
        // Was this transaction cancelled?
        if (isCancelled(request)) {
            log(" " + mapping.getAttribute() + " - Type transaction was cancelled");
            
            removeFormBean(mapping, request);
  
            return (mapping.findForward("success"));
        }
  
        return mapping.findForward("success");  
      }
  
      /**
       * Convenience method that call the comparable servlet log method and writes 
       * an explanatory message and a stack trace for a given Throwable exception to 
the 
       * servlet log file.
       *
       * @param         message         String that describes the error or exception
      */
      protected void log(String message) {
         if (servlet.getDebug() >= 1)
             servlet.log(message);
      }
      
      /**
       * Convenience method that call the comparable servlet log method and writes 
       * an explanatory message and a stack trace for a given Throwable exception to 
the 
       * servlet log file.
       *
       * @param         message         String that describes the error or exception
       * @param         throwable       Throwable error or exception
      */
      protected void log(String message, Throwable throwable) {
         if (servlet.getDebug() >= 1)
             servlet.log(message, throwable);
      }
  
      /**
       * Convenience method for removing the obsolete form bean.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param request The HTTP request we are processing
      */    
      protected void removeFormBean(ActionMapping mapping, HttpServletRequest request) 
{
         // Remove the obsolete form bean
         if (mapping.getAttribute() != null) {
             if ("request".equals(mapping.getScope())) {
                 request.removeAttribute(mapping.getAttribute());
             } else {
                HttpSession session = request.getSession();
                session.removeAttribute(mapping.getAttribute());
             }
         }
      }
  }
  
  
  
  1.1                  
jakarta-struts/contrib/validator/src/jdbc-example/com/wintecinc/struts/example/validator/jdbc/TypeForm.java
  
  Index: TypeForm.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", "Struts", 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 com.wintecinc.struts.example.validator.jdbc;
  
  import java.io.Serializable;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.struts.action.ActionMapping;
  import com.wintecinc.struts.action.ValidatorForm;
  
  
  /**
   * Form bean for the user type page.
   *
   * @author David Wintefeldt
  */
  public final class TypeForm extends ValidatorForm implements Serializable {
      private String action = null;
         
      private String sByte = null;
      private String sShort = null;
      private String sInteger = null;
      private String sLong = null;
      private String sFloat = null;
      private String sDouble = null;
      private String sDate = null;
  
      public String getAction() {
        return action;
      }
  
      public void setAction(String action) {
          this.action = action;
      }
  
      public String getByte() {
         return sByte;  
      }
      
      public void setByte(String sByte) {
                this.sByte = sByte;
      }
      
      public String getShort() {
         return sShort; 
      }
      
      public void setShort(String sShort) {
                this.sShort = sShort;
      }
  
      public String getInteger() {
         return sInteger;       
      }
      
      public void setInteger(String sInteger) {
                this.sInteger = sInteger;
      }
  
      public String getLong() {
         return sLong;  
      }
      
      public void setLong(String sLong) {
                this.sLong = sLong;
      }
  
      public String getFloat() {
         return sFloat; 
      }
      
      public void setFloat(String sFloat) {
                this.sFloat = sFloat;
      }
  
      public String getDouble() {
         return sDouble;        
      }
      
      public void setDouble(String sDouble) {
                this.sDouble = sDouble;
      }
  
      public String getDate() {
         return sDate;  
      }
      
      public void setDate(String sDate) {
                this.sDate = sDate;
      }
          
      /**
       * 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 = null;
         sByte = null;
         sShort = null;
         sInteger = null;
         sLong = null;
         sFloat = null;
         sDouble = null;
         sDate = null;
      }
  
  }
  
  
  

Reply via email to