dwinterfeldt 01/07/08 20:11:09
Added: contrib/validator/src/example/com/wintecinc/struts/example/validator
ApplicationResources.properties
ApplicationResources_fr.properties
CityStateZip.java MultiRegistrationAction.java
RegistrationAction.java RegistrationForm.java
TypeAction.java TypeForm.java
Log:
Adding Struts Validator.
Revision Changes Path
1.1
jakarta-struts/contrib/validator/src/example/com/wintecinc/struts/example/validator/ApplicationResources.properties
Index: ApplicationResources.properties
===================================================================
button.cancel=Cancel
button.confirm=Confirm
button.reset=Reset
button.save=Save
# Errors
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}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.
# Registration Form
registrationForm.title=Registration
registrationForm.title.create=Register
registrationForm.title.edit=Edit User Information
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.
# 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
typeForm.creditCard.displayname=Credit Card
1.1
jakarta-struts/contrib/validator/src/example/com/wintecinc/struts/example/validator/ApplicationResources_fr.properties
Index: ApplicationResources_fr.properties
===================================================================
button.cancel=Annulent
button.confirm=Confirment
button.reset=Remettent
button.save=�conomiser
# Errors
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}.
errors.creditcard=Le {0} n'est pas un nombre valide de carte de cr�dit.
errors.email=Le {0} est une adresse incorrecte de e-mail.
# Registration Form
registrationForm.title=Enregistrement
registrationForm.title.create=Registre
registrationForm.title.edit=�ditez L'Information D'Utilisateur
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.
# Type form
typeForm.title=Tapez La Forme
typeForm.title.create=Tapez La Forme
typeForm.byte.displayname=Zone D'Octet
typeForm.short.displayname=Courte Zone
typeForm.integer.displayname=Zone De Nombre entier
typeForm.long.displayname=Longue Zone
typeForm.float.displayname=Gisement De Flotteur
typeForm.double.displayname=Double Zone
typeForm.date.displayname=Zone De Date
typeForm.creditCard.displayname=Carte de cr�dit
1.1
jakarta-struts/contrib/validator/src/example/com/wintecinc/struts/example/validator/CityStateZip.java
Index: CityStateZip.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;
/**
* Just used to provide an indexed properties example.
*
* @author David Wintefeldt
*/
public class CityStateZip implements java.io.Serializable {
private String sCity = null;
private String sStateProv = null;
private String[] sZipPostal = new String[3];
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(int index) {
return sZipPostal[index];
}
public void setZipPostal(int index, String value) {
this.sZipPostal[index] = value;
}
}
1.1
jakarta-struts/contrib/validator/src/example/com/wintecinc/struts/example/validator/MultiRegistrationAction.java
Index: MultiRegistrationAction.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;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
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.util.MessageResources;
/**
* Implementation of <strong>Action</strong> that validates a multi-page
* registration form.
*
* @author David Wintefeldt
*/
public final class MultiRegistrationAction 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();
RegistrationForm info = (RegistrationForm)form;
String action = request.getParameter("action");
// Was this transaction cancelled?
if (isCancelled(request)) {
log(" " + mapping.getAttribute() + " - Registration transaction was
cancelled");
removeFormBean(mapping, request);
return (mapping.findForward("success"));
}
ActionErrors errors = info.validate(mapping, request);
if (errors != null && errors.empty()) {
if (info.getPage() == 1)
return mapping.findForward("input2");
if (info.getPage() == 2)
return mapping.findForward("success");
} else {
saveErrors(request, errors);
if (info.getPage() == 1)
return mapping.findForward("input" + info.getPage());
if (info.getPage() == 2)
return mapping.findForward("input" + info.getPage());
}
return mapping.findForward("input1");
}
/**
* 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/example/com/wintecinc/struts/example/validator/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;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
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.util.MessageResources;
/**
* Implementation of <strong>Action</strong> that validates a registration form.
*
* @author David Wintefeldt
*/
public final class RegistrationAction 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();
RegistrationForm info = (RegistrationForm)form;
String action = request.getParameter("action");
// Was this transaction cancelled?
if (isCancelled(request)) {
log(" " + mapping.getAttribute() + " - Registration 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/example/com/wintecinc/struts/example/validator/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;
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 registration page.
*
* @author David Wintefeldt
*/
public final class RegistrationForm extends ValidatorForm implements Serializable {
private String action = null;
private String sFirstName = null;
private String sLastName = null;
private String sAddr = null;
private CityStateZip csz = new CityStateZip();
private String sPhone = null;
private String sEmail = null;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
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 CityStateZip getCityStateZip() {
return csz;
}
public void setCityStateZip(CityStateZip csz) {
this.csz = csz;
}
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) {
action = null;
sFirstName = null;
sLastName = null;
sAddr = null;
csz = new CityStateZip();
sPhone = null;
sEmail = null;
}
}
1.1
jakarta-struts/contrib/validator/src/example/com/wintecinc/struts/example/validator/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;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
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.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/example/com/wintecinc/struts/example/validator/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;
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;
private String sCreditCard = 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;
}
public String getCreditCard() {
return sCreditCard;
}
public void setCreditCard(String sCreditCard) {
this.sCreditCard = sCreditCard;
}
/**
* 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;
sCreditCard = null;
}
}