com.softslate.commerce.customer.core
Class FormUtils

java.lang.Object
  extended bycom.softslate.commerce.customer.core.FormUtils

public class FormUtils
extends java.lang.Object

Provides useful static methods that assist with form validations in the Struts layer.

Author:
David Tobey

Field Summary
(package private) static org.apache.commons.logging.Log log
           
 
Constructor Summary
FormUtils()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String stringToCapitalize)
          Returns a new string with the first letter of a given string capitalized.
static boolean doCardTypeAndNumberMatch(java.lang.String type, java.lang.String number)
          Given a credit card type and a number, checks that the number corresponds correctly with the type.
static java.lang.String getRequestParamsDebugMessage(javax.servlet.http.HttpServletRequest request)
          Given a request object, converts all the incoming parameters to a string for debugging.
static boolean isCreditCardValid(java.lang.String creditCardNumber)
          Runs a given string through the Luhn algorithm to determine if it is a valid credit card number.
static boolean isInteger(java.lang.String value)
          Checks to see if a given string is in the form of a valid integer.
static boolean isValidEmail(java.lang.String email)
          Checks to see if a given string is in the form of a valid email address.
static boolean isValidPhone(java.lang.String phone)
          Checks to see if a given string is in the form of a valid phone number.
static boolean isValidPostalCode(java.lang.String postalCode, java.lang.String country)
          Checks to see if a given string is in the form of a valid postal code, given an associated country.
static boolean stringArrayHasAnElement(BaseDynaForm form, java.lang.String property)
          Determines if at least one element was submitted and is of non-zero length for a string array parameter of a BaseDynaForm.
static boolean stringArrayHasAnElement(java.lang.String[] paramValues)
          Determines if a given string array has at least one element and that it's of non-zero length.
static boolean stringArrayValuesGreaterThan(BaseDynaForm form, java.lang.String property, int value)
          Determines if at least one element was submitted and is greater than a given int for a string array parameter of a BaseDynaForm.
static boolean stringArrayValuesGreaterThan(java.lang.String[] paramValues, int value)
          Determines if at least one element in a string array is greater than a given value.
static boolean stringExists(BaseDynaForm form, java.lang.String property)
          Determines if a given parameter was included in the request for a BaseDynaForm and is of non-zero length.
static boolean stringValueGreaterThan(BaseDynaForm form, java.lang.String property, int value)
          Determines if a given parameter for a BaseDynaForm is greater than a given int.
static boolean stringValueLessThan(BaseDynaForm form, java.lang.String property, int value)
          Determines if a given parameter for a BaseDynaForm is less than a given int.
static boolean twoPropertiesEqual(BaseDynaForm form, java.lang.String property1, java.lang.String property2)
          Determines if two string parameters submitted to a BaseDynaForm exist and are equal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.commons.logging.Log log
Constructor Detail

FormUtils

public FormUtils()
Method Detail

stringExists

public static boolean stringExists(BaseDynaForm form,
                                   java.lang.String property)
Determines if a given parameter was included in the request for a BaseDynaForm and is of non-zero length.

Parameters:
form - The BaseDynaForm being processed.
property - The name of the parameter being tested.
Returns:
true if the given parameter was submitted to the form and is of non-zero length. false if not.

twoPropertiesEqual

public static boolean twoPropertiesEqual(BaseDynaForm form,
                                         java.lang.String property1,
                                         java.lang.String property2)
Determines if two string parameters submitted to a BaseDynaForm exist and are equal.

Parameters:
form - The BaseDynaForm being processed.
property1 - The first parameter to be tested.
property2 - The second parameter to be tested.
Returns:
true if the given parameters were submitted to the form and are equal. false if not.

stringValueGreaterThan

public static boolean stringValueGreaterThan(BaseDynaForm form,
                                             java.lang.String property,
                                             int value)
Determines if a given parameter for a BaseDynaForm is greater than a given int.

Parameters:
form - The BaseDynaForm being processed.
property - The name of the parameter to be tested.
value - The value for the parameter to be tested against.
Returns:
true if the given parameter is greater than the value. false if not.

stringValueLessThan

public static boolean stringValueLessThan(BaseDynaForm form,
                                          java.lang.String property,
                                          int value)
Determines if a given parameter for a BaseDynaForm is less than a given int.

Parameters:
form - The BaseDynaForm being processed.
property - The name of the parameter to be tested.
value - The value for the parameter to be tested against.
Returns:
true if the given parameter is less than the value. false if not.

stringArrayHasAnElement

public static boolean stringArrayHasAnElement(BaseDynaForm form,
                                              java.lang.String property)
Determines if at least one element was submitted and is of non-zero length for a string array parameter of a BaseDynaForm.

Parameters:
form - The BaseDynaForm being processed.
property - The name of the parameter being tested.
Returns:
true if the given parameter has at least one element and is of non-zero length. false if not.

stringArrayValuesGreaterThan

public static boolean stringArrayValuesGreaterThan(BaseDynaForm form,
                                                   java.lang.String property,
                                                   int value)
Determines if at least one element was submitted and is greater than a given int for a string array parameter of a BaseDynaForm.

Parameters:
form - The BaseDynaForm being processed.
property - The name of the parameter being tested.
value - The value for the parameter to be tested against.
Returns:
true if the given parameter has at least one element and is greater than the value. false if not.

stringArrayHasAnElement

public static boolean stringArrayHasAnElement(java.lang.String[] paramValues)
Determines if a given string array has at least one element and that it's of non-zero length.

Parameters:
paramValues - The string array being tested.
Returns:
true if the given string array has one element that's of non-zero length.

stringArrayValuesGreaterThan

public static boolean stringArrayValuesGreaterThan(java.lang.String[] paramValues,
                                                   int value)
Determines if at least one element in a string array is greater than a given value.

Parameters:
paramValues - The string array being tested.
value - The value for the string array's elements to be tested against.
Returns:
true if at least one element in a string array is greater than a given value. false if not.

capitalize

public static java.lang.String capitalize(java.lang.String stringToCapitalize)
Returns a new string with the first letter of a given string capitalized.

Parameters:
stringToCapitalize - The string to capitalize.
Returns:
A new string with the first letter capitalized.

isValidEmail

public static boolean isValidEmail(java.lang.String email)
Checks to see if a given string is in the form of a valid email address. Uses the following regular expression for the test: .+@.+\\.[a-z]+

Parameters:
email - The string to be tested.
Returns:
true if the given string matches a valid email address.

isValidPhone

public static boolean isValidPhone(java.lang.String phone)
Checks to see if a given string is in the form of a valid phone number. Since phone numbers may be U.S. or international in format, and may or may not have an extension, only a light check is done ensuring that at least 10 digits are present.

Parameters:
phone - The string to be tested.
Returns:
true if the given string matches a valid phone number.

isValidPostalCode

public static boolean isValidPostalCode(java.lang.String postalCode,
                                        java.lang.String country)
Checks to see if a given string is in the form of a valid postal code, given an associated country. If the country is US, a simple check on the number of digits is done.

Parameters:
postalCode - The string to be tested.
Returns:
true if the given string matches a valid postal code.

isInteger

public static boolean isInteger(java.lang.String value)
Checks to see if a given string is in the form of a valid integer.

Parameters:
value - The string to be tested.
Returns:
true if the given string is a valid integer

getRequestParamsDebugMessage

public static java.lang.String getRequestParamsDebugMessage(javax.servlet.http.HttpServletRequest request)
Given a request object, converts all the incoming parameters to a string for debugging.

Parameters:
request -
Returns:
A String representing the name value pairs of the request parameters.

isCreditCardValid

public static boolean isCreditCardValid(java.lang.String creditCardNumber)
Runs a given string through the Luhn algorithm to determine if it is a valid credit card number.

Parameters:
creditCardNumber -
Returns:
true, if the string is a valid credit card number; false, otherwise.

doCardTypeAndNumberMatch

public static boolean doCardTypeAndNumberMatch(java.lang.String type,
                                               java.lang.String number)
Given a credit card type and a number, checks that the number corresponds correctly with the type.

Parameters:
type - Four types supported: "VISA", "DISCOVER", "AMEX", and "MASTERCARD"
number -
Returns:
true if the card type matches the number or if the card type is not supported.


Copyright © SoftSlate, Inc. 2003–2005