com.ibm.commerce.giftregistry.struts

Class GiftRegistryRequestFieldsValidator

  • java.lang.Object
    • com.ibm.commerce.giftregistry.struts.GiftRegistryRequestFieldsValidator


  • public class GiftRegistryRequestFieldsValidator
    extends java.lang.Object
    This class validates HTTP request parameters based on rules specified in a property file. This class can be used if users like the commerce way of handling request validation. The rules cover checking required parameters, conditionally required parameters, and parameters that should match a certain regular expression pattern. The property file is store specific, and is normally located in /WEB-INF/classes//. The class validates by using the WebSphere Commerce property resource reader, PropertyResourceBundleReader, to read the property file. PropertyResourceBundleReader Here are the details of the rules that are supported by the validation:

    When you use the property file, ensure you are familiar with the following logic within the file. The properties file parameter names used:

    • addressType: The type of address to be used for the gift registry. Valid values are as follows:
      • R: Indicates the gift registrantís address.
      • C: Indicates the co-registrantís address. Although only one main gift registrant is supported per gift registry, you can specify co-registrants. For example, you may have a wedding gift registry. The main gift registrant can be the bride. A secondary registrant can be the groom.
      • PreEventShipping: Indicates the address where gifts should be shipped to before the event date.
      • PostEventShipping: Indicates the address where gifts should be shipped to after the event has passed.
    • shippingPreference: The kind of address to use for shipping; that is, the address where gifts should be shipped. The shipping preference may be changed to accommodate different phases in an event. For example, gifts may be shipped to the brideís address before the wedding. After the wedding, the gifts may shipped to a new address. Valid values are as follows:
      • R: Indicates that gifts should be shipped to the gift registrantís address.
      • C: Indicates gifts should be shipped to the co-registrantís address. Although only one main gift registrant is supported per gift registry, you can specify co-registrants. For example, you may have a wedding gift registry. The main gift registrant can be the bride. A secondary registrant can be the groom. Note that if you have more multiple co-registrants, only the contact information for one can be changed after the gift registry has been created.
      • O: Indicates gifts should be shipped to another address, as specified when the gift registrant created the gift registry.
    All properties contain a numeric identifier (sometimes referred to as a group ID), which uniquely defines it. For example, in the following excerpt, 30 identifies the firstName parameter within the a request:
                    30.Name=firstName 
                    30.Required=yes 
                    30.addressType=R  
      
    Each property contains at least two lines of information: the name of the parameter (or field), and whether or not the parameter is required. For example, in the following excerpt, the properties file has defined that the parameter description is required:
                    1.Name=description 
                    1.Required=yes
     
    This means an event description for the gift registry must be provided.

    The following is the list of all the rules:

    • Required. If this is specified as yes, the associated field has to have a value in the request
    • RequiredIfFieldEntered: If this is specified, an existence of a field will be checked if any only the specified field has a non-empty value. For example, with RequiredIfFieldEntered=relationship.C, the field name (that is, firstName) is required if relationship of type C is entered by the user:
                              1.Name=firstName
                              1.Required=no
                              1.addressType=C
                              1.RequiredIfFieldEntered=relationship.C
                      
    • pattern: The pattern is a regular expression. If this is specified. A field has to match the pattern. For example, the following lines specify that a phone number has to have at least 6 digits, and at most 10 digits. Regular expressions supported in Java1.4.x are all supported here:
                              1.Name=phone1
                              1.pattern=[0-9]{6,10}
                      
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM copyright notice field.
        See Also:
        Constant Field Values
      • CLASS_NAME

        public static final java.lang.String CLASS_NAME
        The name of this class
      • FIELD_RULE_DELIMITER

        public static final java.lang.String FIELD_RULE_DELIMITER
        The delimiter used for field rules. For example, value=a !! b !! c has delimiter a, b, and c.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GiftRegistryRequestFieldsValidator

        public GiftRegistryRequestFieldsValidator(java.lang.String propertyFileName)
        Validates that uses rules from the file that has the given file name
        Parameters:
        propertyFileName - the name of the property file
    • Method Detail

      • setPathSeparator

        public void setPathSeparator(java.lang.String astrPathSeparator)
        Sets the path separator. path separator is used to separate the store directory and the property file name. For example:
         "store1/UserRegistration"
         
        "/" is the path separator.
        If path separator is not set, the data bean will use the default one: "/" (working under Windows platform).
        Parameters:
        astrPathSeparator - The path separator.
      • setRulePropertyFileName

        public void setRulePropertyFileName(java.lang.String astrPropertyFileName)
        Sets the name of the rule property file.
        Parameters:
        The - name of the property file.
      • setRequestProperties

        public void setRequestProperties(TypedProperty aRequestProperties)
        Sets the request properties
        Parameters:
        aRequestProperties - the parameters passed to the command.
      • setRequestProperties

        public void setRequestProperties(javax.servlet.http.HttpServletRequest request)
        Sets the request properties from the request object
        Parameters:
        request - the request that contains the request proeprties
      • getRequestProperties

        public TypedProperty getRequestProperties()
        Gets the request properties.
        Returns:
        The request properties.
      • setStoreDirectory

        public void setStoreDirectory(java.lang.String astrStoreDirectory)
        This method sets the name of store directory. The directory is used as the path to find the property file. For example, the property files of a store may be under the directory called /store31. The parent directory of store31 directory is included in the class path. Thus, this method should be called to set StoreDirectory to store31. If the store directory is not set, ResourceBundleDataBean will try to get it from commandContext.
        Parameters:
        astrStoreDirectory - The name of store directory.
      • validateFields

        public org.apache.struts.action.ActionErrors validateFields(javax.servlet.http.HttpServletRequest request)
        Validates URL fields using rules specified in a property file
        Parameters:
        errors - a list of errors identified during validation
        request - the request that contains the fields that this validator will validate
        Returns:
        all the errors found during validation
      • getRulePropertyFileName

        public java.lang.String getRulePropertyFileName()
        Returns:
        the name of the validation rule file
      • getStoreDirectory

        public java.lang.String getStoreDirectory()
        Returns:
        the store directory within which the property file will be searched