Class FormUtilsImpl

java.lang.Object
com.softslate.commerce.customer.core.FormUtilsImpl
All Implemented Interfaces:
FormUtils

public class FormUtilsImpl extends Object implements FormUtils
FormUtilsImpl is the default implementation of the FormUtils interface for the application.
Author:
David Tobey
See Also:
  • Field Details

    • log

      static org.apache.commons.logging.Log log
  • Constructor Details

    • FormUtilsImpl

      public FormUtilsImpl()
  • Method Details

    • stringExists

      public boolean stringExists(BaseDynaForm form, String property)
      Description copied from interface: FormUtils
      Determines if a given parameter was included in the request for a BaseDynaForm and is of non-zero length.
      Specified by:
      stringExists in interface FormUtils
      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 boolean twoPropertiesEqual(BaseDynaForm form, String property1, String property2)
      Description copied from interface: FormUtils
      Determines if two string parameters submitted to a BaseDynaForm exist and are equal.
      Specified by:
      twoPropertiesEqual in interface FormUtils
      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 boolean stringValueGreaterThan(BaseDynaForm form, String property, int value)
      Description copied from interface: FormUtils
      Determines if a given parameter for a BaseDynaForm is greater than a given int.
      Specified by:
      stringValueGreaterThan in interface FormUtils
      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 boolean stringValueLessThan(BaseDynaForm form, String property, int value)
      Description copied from interface: FormUtils
      Determines if a given parameter for a BaseDynaForm is less than a given int.
      Specified by:
      stringValueLessThan in interface FormUtils
      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 boolean stringArrayHasAnElement(BaseDynaForm form, String property)
      Description copied from interface: FormUtils
      Determines if at least one element was submitted and is of non-zero length for a string array parameter of a BaseDynaForm.
      Specified by:
      stringArrayHasAnElement in interface FormUtils
      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 boolean stringArrayValuesGreaterThan(BaseDynaForm form, String property, int value)
      Description copied from interface: FormUtils
      Determines if at least one element was submitted and is greater than a given int for a string array parameter of a BaseDynaForm.
      Specified by:
      stringArrayValuesGreaterThan in interface FormUtils
      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 boolean stringArrayHasAnElement(String[] paramValues)
      Description copied from interface: FormUtils
      Determines if a given string array has at least one element and that it's of non-zero length.
      Specified by:
      stringArrayHasAnElement in interface FormUtils
      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 boolean stringArrayValuesGreaterThan(String[] paramValues, int value)
      Description copied from interface: FormUtils
      Determines if at least one element in a string array is greater than a given value.
      Specified by:
      stringArrayValuesGreaterThan in interface FormUtils
      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 String capitalize(String stringToCapitalize)
      Description copied from interface: FormUtils
      Returns a new string with the first letter of a given string capitalized.
      Specified by:
      capitalize in interface FormUtils
      Parameters:
      stringToCapitalize - The string to capitalize.
      Returns:
      A new string with the first letter capitalized.
    • isValidEmail

      public boolean isValidEmail(String email)
      Description copied from interface: FormUtils
      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]+
      Specified by:
      isValidEmail in interface FormUtils
      Parameters:
      email - The string to be tested.
      Returns:
      true if the given string matches a valid email address.
    • isValidPhone

      public boolean isValidPhone(String phone)
      Description copied from interface: FormUtils
      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.
      Specified by:
      isValidPhone in interface FormUtils
      Parameters:
      phone - The string to be tested.
      Returns:
      true if the given string matches a valid phone number.
    • isValidPostalCode

      public boolean isValidPostalCode(String postalCode, String country)
      Description copied from interface: FormUtils
      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.
      Specified by:
      isValidPostalCode in interface FormUtils
      Parameters:
      postalCode - The string to be tested.
      Returns:
      true if the given string matches a valid postal code.
    • isInteger

      public boolean isInteger(String value)
      Description copied from interface: FormUtils
      Checks to see if a given string is in the form of a valid integer.
      Specified by:
      isInteger in interface FormUtils
      Parameters:
      value - The string to be tested.
      Returns:
      true if the given string is a valid integer
    • isCreditCardValid

      public boolean isCreditCardValid(String creditCardNumber)
      Description copied from interface: FormUtils
      Runs a given string through the Luhn algorithm to determine if it is a valid credit card number.
      Specified by:
      isCreditCardValid in interface FormUtils
      Parameters:
      creditCardNumber - The credit card number
      Returns:
      true, if the string is a valid credit card number; false, otherwise.
    • doCardTypeAndNumberMatch

      public boolean doCardTypeAndNumberMatch(String type, String number)
      Description copied from interface: FormUtils
      Given a credit card type and a number, checks that the number corresponds correctly with the type.
      Specified by:
      doCardTypeAndNumberMatch in interface FormUtils
      Parameters:
      type - Four types supported: "VISA", "DISCOVER", "AMEX", and "MASTERCARD"
      number - The credit card number
      Returns:
      true if the card type matches the number or if the card type is not supported.
    • deriveCardType

      public String deriveCardType(String number)
      Description copied from interface: FormUtils
      Given a credit card number, derive its type (Visa, Discover, MasterCard or AMEX).
      Specified by:
      deriveCardType in interface FormUtils
      Parameters:
      number - The credit card number
      Returns:
      Four types supported: "VISA", "DISCOVER", "AMEX", and "MASTERCARD"
    • containsCharacter

      public Character containsCharacter(String string, String characters)
      Description copied from interface: FormUtils
      Determines if a given string contains a character residing in another string.
      Specified by:
      containsCharacter in interface FormUtils
      Parameters:
      string - The string to check against
      characters - A String containing each of the characters to check
      Returns:
      the first matching Character, if the string contains one of the characters, otherwise null
    • stringArrayAsURLParam

      public String stringArrayAsURLParam(String parameterName, String[] stringArray) throws Exception
      Specified by:
      stringArrayAsURLParam in interface FormUtils
      Throws:
      Exception
    • eliminateDuplicateFacets

      public void eliminateDuplicateFacets(SearchList searchList)
      Specified by:
      eliminateDuplicateFacets in interface FormUtils
    • removeNullsFromMap

      public void removeNullsFromMap(Map map)
      Specified by:
      removeNullsFromMap in interface FormUtils
    • removeAllNotInRequestFromMap

      public void removeAllNotInRequestFromMap(Map map, javax.servlet.http.HttpServletRequest request)
      Specified by:
      removeAllNotInRequestFromMap in interface FormUtils
    • removePrefixedKeysFromMap

      public void removePrefixedKeysFromMap(Map map, String prefix)
      Specified by:
      removePrefixedKeysFromMap in interface FormUtils
    • html5OrXhtml

      public String html5OrXhtml(javax.servlet.http.HttpServletRequest request, Settings settings)
      Specified by:
      html5OrXhtml in interface FormUtils