atg.commerce.util
Class AddressValidatorImpl

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.util.AddressValidatorImpl
All Implemented Interfaces:
AddressValidator, atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
BillingAddrValidatorImpl, ShippingAddrValidatorImpl

public class AddressValidatorImpl
extends GenericService
implements AddressValidator

This class provides a default implementation of AddressValidator. By default the following address properties are checked :

If the address is an instance of atg.core.util.ContactInfo, the following properties may also be checked:


Field Summary
static java.lang.String ADDRESS1_MISSING
           
static java.lang.String CITY_MISSING
           
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String COUNTRY_MISSING
           
static java.lang.String COUNTY_MISSING
           
static java.lang.String EMAIL_INVALID
           
static java.lang.String EMAIL_MISSING
           
static java.lang.String ERROR_MAP_KEY
           
static java.lang.String FAX_NUMBER_INVALID
           
static java.lang.String FAX_NUMBER_MISSING
           
static java.lang.String FIRST_NAME_MISSING
           
static java.lang.String LAST_NAME_MISSING
           
protected  java.lang.String[] mCountriesWithStates
           
protected  boolean mValidateAddress1
           
protected  boolean mValidateCity
           
protected  boolean mValidateCountry
           
protected  boolean mValidateCounty
           
protected  boolean mValidateEmail
           
protected  boolean mValidateFaxNumber
           
protected  boolean mValidateFirstName
           
protected  boolean mValidateLastName
           
protected  boolean mValidatePhoneNumber
           
protected  boolean mValidatePostalCode
           
protected  boolean mValidateState
           
static java.lang.String PHONE_NUMBER_INVALID
           
static java.lang.String PHONE_NUMBER_MISSING
           
static java.lang.String POSTAL_CODE_MISSING
           
static java.lang.String RESOURCE_MAP_KEY
           
static java.lang.String STATE_MISSING
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
AddressValidatorImpl()
           
 
Method Summary
protected  java.util.Map addError(java.lang.String pKey, java.util.ResourceBundle pResources, java.util.Map pResourceAndErrorKeyMaps, java.util.Map pErrors)
          This method looks up the resourced error message in the resource bundle and adds the error message to the map.
protected  void addHashedError(PipelineResult pResult, java.lang.String pKey, java.lang.String pId, java.lang.Object pError)
          This method adds an error to the PipelineResult object.
 boolean countryNeedsState(java.lang.String pCountry)
          Determine whether a state is required based on the country by consulting the property countriesWithStates.
 java.lang.String[] getCountriesWithStates()
          Return the list of countries for which a state or province is required to have a valid shipping address.
 boolean getValidateAddress1()
          Returns property validateAddress1
 boolean getValidateCity()
          Returns property validateCity
 boolean getValidateCountry()
          Returns the validateCountry flag
 boolean getValidateCounty()
          Returns property validateCounty
 boolean getValidateEmail()
          Returns the validateEmail flag
 boolean getValidateFaxNumber()
          Returns the validateFaxNumber flag
 boolean getValidateFirstName()
          Returns property validateFirstName
 boolean getValidateLastName()
          Returns property validateLastName
 boolean getValidatePhoneNumber()
          Returns the validatePhoneNumber flag
 boolean getValidatePostalCode()
          Returns property validatePostalCode
 boolean getValidateState()
          Returns property validateState
 boolean isEmpty(java.lang.String pStr)
          Return true if pStr is null or consists entirely of whitespace.
 void setCountriesWithStates(java.lang.String[] pCountriesWithStates)
          Specify the set of countries for which a state or province name is required in order to have a valid address.
 void setValidateAddress1(boolean pValidateAddress1)
          Sets property validateAddress1
 void setValidateCity(boolean pValidateCity)
          Sets property validateCity
 void setValidateCountry(boolean pValidateCountry)
          Sets the validateCountry flag.
 void setValidateCounty(boolean pValidateCounty)
          Sets property validateCounty
 void setValidateEmail(boolean pValidateEmail)
          Sets the validateEmail flag.
 void setValidateFaxNumber(boolean pValidateFaxNumber)
          Sets the validateFaxNumber flag.
 void setValidateFirstName(boolean pValidateFirstName)
          Sets property validateFirstName
 void setValidateLastName(boolean pValidateLastName)
          Sets property validateLastName
 void setValidatePhoneNumber(boolean pValidatePhoneNumber)
          Sets the validatePhoneNumber flag.
 void setValidatePostalCode(boolean pValidatePostalCode)
          Sets property validatePostalCode
 void setValidateState(boolean pValidateState)
          Sets property validateState
 java.util.Collection validateAddress(Address pAddress)
          Verify that all required properties are present in an address.
 java.util.Collection validateAddress(Address pAddress, java.util.Locale pLocale)
          Verify that all required properties are present in an address.
 java.util.Collection validateAddress(Address pAddress, java.util.ResourceBundle pResources)
          Verify that all required properties are present in an address.
protected  java.util.Map validateAddress(Address pAddress, java.util.ResourceBundle pResources, java.util.Map pResourceAndErrorKeyMaps)
          Based on the component configuration, this method validates the necessary fields and collects and returns all error messages.
protected  void validateAddress(Address pAddress, java.lang.String pId, PipelineResult pResult, java.util.ResourceBundle pResources, java.util.Map pResourceAndErrorKeyMaps)
          This method is added here to share the code between ShippingAddrValidatorImpl and BillingAddrValidatorImpl.
 boolean validateEmailAddress(java.lang.String pEmail)
          Validates an email address for correctness.
 boolean validatePhoneNumber(java.lang.String pPhoneNumber)
          Validates a phone number for correctness.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


FIRST_NAME_MISSING

public static final java.lang.String FIRST_NAME_MISSING
See Also:
Constant Field Values

LAST_NAME_MISSING

public static final java.lang.String LAST_NAME_MISSING
See Also:
Constant Field Values

ADDRESS1_MISSING

public static final java.lang.String ADDRESS1_MISSING
See Also:
Constant Field Values

CITY_MISSING

public static final java.lang.String CITY_MISSING
See Also:
Constant Field Values

COUNTY_MISSING

public static final java.lang.String COUNTY_MISSING
See Also:
Constant Field Values

STATE_MISSING

public static final java.lang.String STATE_MISSING
See Also:
Constant Field Values

POSTAL_CODE_MISSING

public static final java.lang.String POSTAL_CODE_MISSING
See Also:
Constant Field Values

COUNTRY_MISSING

public static final java.lang.String COUNTRY_MISSING
See Also:
Constant Field Values

PHONE_NUMBER_MISSING

public static final java.lang.String PHONE_NUMBER_MISSING
See Also:
Constant Field Values

PHONE_NUMBER_INVALID

public static final java.lang.String PHONE_NUMBER_INVALID
See Also:
Constant Field Values

EMAIL_MISSING

public static final java.lang.String EMAIL_MISSING
See Also:
Constant Field Values

EMAIL_INVALID

public static final java.lang.String EMAIL_INVALID
See Also:
Constant Field Values

FAX_NUMBER_MISSING

public static final java.lang.String FAX_NUMBER_MISSING
See Also:
Constant Field Values

FAX_NUMBER_INVALID

public static final java.lang.String FAX_NUMBER_INVALID
See Also:
Constant Field Values

RESOURCE_MAP_KEY

public static final java.lang.String RESOURCE_MAP_KEY
See Also:
Constant Field Values

ERROR_MAP_KEY

public static final java.lang.String ERROR_MAP_KEY
See Also:
Constant Field Values

mValidateFirstName

protected boolean mValidateFirstName

mValidateLastName

protected boolean mValidateLastName

mValidateAddress1

protected boolean mValidateAddress1

mValidateCity

protected boolean mValidateCity

mValidateCounty

protected boolean mValidateCounty

mValidateState

protected boolean mValidateState

mValidatePostalCode

protected boolean mValidatePostalCode

mValidateCountry

protected boolean mValidateCountry

mValidatePhoneNumber

protected boolean mValidatePhoneNumber

mValidateFaxNumber

protected boolean mValidateFaxNumber

mValidateEmail

protected boolean mValidateEmail

mCountriesWithStates

protected java.lang.String[] mCountriesWithStates
Constructor Detail

AddressValidatorImpl

public AddressValidatorImpl()
Method Detail

getValidateFirstName

public boolean getValidateFirstName()
Returns property validateFirstName

Returns:
returns property validateFirstName

setValidateFirstName

public void setValidateFirstName(boolean pValidateFirstName)
Sets property validateFirstName

Parameters:
pValidateFirstName - the value to set for property validateFirstName

getValidateLastName

public boolean getValidateLastName()
Returns property validateLastName

Returns:
returns property validateLastName

setValidateLastName

public void setValidateLastName(boolean pValidateLastName)
Sets property validateLastName

Parameters:
pValidateLastName - the value to set for property validateLastName

getValidateAddress1

public boolean getValidateAddress1()
Returns property validateAddress1

Returns:
returns property validateAddress1

setValidateAddress1

public void setValidateAddress1(boolean pValidateAddress1)
Sets property validateAddress1

Parameters:
pValidateAddress1 - the value to set for property validateAddress1

getValidateCity

public boolean getValidateCity()
Returns property validateCity

Returns:
returns property validateCity

setValidateCity

public void setValidateCity(boolean pValidateCity)
Sets property validateCity

Parameters:
pValidateCity - the value to set for property validateCity

getValidateCounty

public boolean getValidateCounty()
Returns property validateCounty

Returns:
returns property validateCounty

setValidateCounty

public void setValidateCounty(boolean pValidateCounty)
Sets property validateCounty

Parameters:
pValidateCounty - the value to set for property validateCounty

getValidateState

public boolean getValidateState()
Returns property validateState

Returns:
returns property validateState

setValidateState

public void setValidateState(boolean pValidateState)
Sets property validateState

Parameters:
pValidateState - the value to set for property validateState

getValidatePostalCode

public boolean getValidatePostalCode()
Returns property validatePostalCode

Returns:
returns property validatePostalCode

setValidatePostalCode

public void setValidatePostalCode(boolean pValidatePostalCode)
Sets property validatePostalCode

Parameters:
pValidatePostalCode - the value to set for property validatePostalCode

getValidateCountry

public boolean getValidateCountry()
Returns the validateCountry flag


setValidateCountry

public void setValidateCountry(boolean pValidateCountry)
Sets the validateCountry flag. If true, then the country property in the Address object will be validated.


getValidatePhoneNumber

public boolean getValidatePhoneNumber()
Returns the validatePhoneNumber flag


setValidatePhoneNumber

public void setValidatePhoneNumber(boolean pValidatePhoneNumber)
Sets the validatePhoneNumber flag. If true, then the phoneNumber property in the ContactInfo object will be validated.


getValidateFaxNumber

public boolean getValidateFaxNumber()
Returns the validateFaxNumber flag


setValidateFaxNumber

public void setValidateFaxNumber(boolean pValidateFaxNumber)
Sets the validateFaxNumber flag. If true, then the faxNumber property in the ContactInfo object will be validated.


getValidateEmail

public boolean getValidateEmail()
Returns the validateEmail flag


setValidateEmail

public void setValidateEmail(boolean pValidateEmail)
Sets the validateEmail flag. If true, then the email property in the ContactInfo object will be validated.


setCountriesWithStates

public void setCountriesWithStates(java.lang.String[] pCountriesWithStates)
Specify the set of countries for which a state or province name is required in order to have a valid address.

This property is a list of countries that are supported by the site for which a state (province) field is required in order to have a valid address. For example, "usa" and "canada" might go on this list, but "germany" would not.

The country names in this list should be lower case and must be spelled as they would be spelled when the user enters or selects them. If the user chooses a country from a menu it is easy to make this list consistent with user input. If the user provides the name through a text input field, this list should contain common variations and misspellings, since the value in the list must match the user's input exactly except. Comparisons are case-insensitive, so it is not necessary to include all possible combinations of capitalization in this list.


getCountriesWithStates

public java.lang.String[] getCountriesWithStates()
Return the list of countries for which a state or province is required to have a valid shipping address.


validateAddress

public java.util.Collection validateAddress(Address pAddress)
Verify that all required properties are present in an address. By default the sever locale is used to look up for error messages.

Specified by:
validateAddress in interface AddressValidator
Parameters:
pAddress - The address being examined.
Returns:
After the validation, returns the error messages
See Also:
validateAddress(Address, ResourceBundle)

validateAddress

public java.util.Collection validateAddress(Address pAddress,
                                            java.util.Locale pLocale)
Verify that all required properties are present in an address.

Specified by:
validateAddress in interface AddressValidator
Parameters:
pAddress - The address being examined.
pLocale - The optional locale to use when looking up the resource bundle that contains error messages. If null, the default server locale will be used.
Returns:
After the validation, returns the error messages
See Also:
validateAddress(Address, ResourceBundle)

validateAddress

public java.util.Collection validateAddress(Address pAddress,
                                            java.util.ResourceBundle pResources)
Verify that all required properties are present in an address. If there is no errors, this method returns an empty list.

Specified by:
validateAddress in interface AddressValidator
Parameters:
pAddress - The address being examined.
pResources - The resource bundle from which to retrieve error messages.
Returns:
After the validation, returns the error messages. If there is no errors, empty list is returned.
See Also:
validateAddress(Address, ResourceBundle, Map)

countryNeedsState

public boolean countryNeedsState(java.lang.String pCountry)
Determine whether a state is required based on the country by consulting the property countriesWithStates.

Parameters:
pCountry - The country name being queried. If null, assume the country does require a state or province designation as part of the shipping address.
Returns:
true if the country is unspecified or the country is specified and appears in the list countriesWithStates, otherwise false.

validatePhoneNumber

public boolean validatePhoneNumber(java.lang.String pPhoneNumber)
Validates a phone number for correctness. By default this method does nothing and returns true. This method can be overridden to do more sophisticated validation.


validateEmailAddress

public boolean validateEmailAddress(java.lang.String pEmail)
Validates an email address for correctness. By default this method checks to see that there is one and only one @ character. This method can be overridden to do more sophisticated validation.


isEmpty

public boolean isEmpty(java.lang.String pStr)
Return true if pStr is null or consists entirely of whitespace.


validateAddress

protected java.util.Map validateAddress(Address pAddress,
                                        java.util.ResourceBundle pResources,
                                        java.util.Map pResourceAndErrorKeyMaps)
Based on the component configuration, this method validates the necessary fields and collects and returns all error messages.

For Example, If the component is configured to validate first and last name, then this method validates the first and last name. Also if there is any error message in the validation, all the error message is collected and returned.

Parameters:
pAddress - The address being examined.
pResources - The resource bundle to look up error messages.
pResourceAndErrorKeyMaps - The optional alternate resource and error key map. This is used in ShippingAddrValidatorImpl and BillingAddrValidatorImpl. These classes pass in alternate resource and error key maps.
Returns:
See Also:
-- This method adds the error message to the map

validateAddress

protected void validateAddress(Address pAddress,
                               java.lang.String pId,
                               PipelineResult pResult,
                               java.util.ResourceBundle pResources,
                               java.util.Map pResourceAndErrorKeyMaps)
This method is added here to share the code between ShippingAddrValidatorImpl and BillingAddrValidatorImpl.

This method first gets the validated error message and loops through the error message and adds the error message to the PipelineResult object.

Parameters:
pAddress - The address being examined
pId - The id of the object that owns the address, used in constructing error messages. For example, when validating the address in a credit card, the caller might provide the credit card id here.
pResult - A PipelineResult object in which to store error messages if any required values are missing from the address.
pResources - The resource bundle to look up error messages.
pResourceAndErrorKeyMaps - The optional alternate resource and error key map. This is used in ShippingAddrValidatorImpl and BillingAddrValidatorImpl. These classes pass in alternate resource and error key maps.
See Also:
-- This method collects all the error messages with error keys., -- This method adds the error messages to the PipelineResult

addError

protected java.util.Map addError(java.lang.String pKey,
                                 java.util.ResourceBundle pResources,
                                 java.util.Map pResourceAndErrorKeyMaps,
                                 java.util.Map pErrors)
This method looks up the resourced error message in the resource bundle and adds the error message to the map. If the alternate resource and error map (pResourceAndErrorKeyMaps)is passed in, use the alternate keys to look up the error message in the resource bundle and save the error message in the map using the error key. Alternatively if this map is not passed in then this method uses the key lookup the error message and the same key is used to save the error message in the map.

Parameters:
pKey - The key to find the resourced error message or locate the alternate resource and error key. If the pResourceAndErrorKeyMaps is passed in, then the resource key is used to find the resourced error message and the error key is used to save the error message.
pResources - The resource bundle to lookup error message.
pResourceAndErrorKeyMaps - This map contains two maps. One for the resource and other for error keys.
pErrors - This map contains the error key and resourced error message.
Returns:
the error message map.

addHashedError

protected void addHashedError(PipelineResult pResult,
                              java.lang.String pKey,
                              java.lang.String pId,
                              java.lang.Object pError)
This method adds an error to the PipelineResult object. This method, rather than just storing a single error object in pResult, stores a Map of errors. This allows more than one error to be stored using the same key in the pResult object. pKey is used to reference a HashMap of errors in pResult. So, calling pResult.getError(pKey) will return an object which should be cast to a Map. Each entry within the map is keyed by pId and its value is pError.

Parameters:
pResult - the PipelineResult object supplied in runProcess()
pKey - the key to use to store the HashMap in the PipelineResult object
pId - the key to use to store the error message within the HashMap in the PipelineResult object
pError - the error object to store in the HashMap
See Also:
PipelineResult, #runProcess(Object, PipelineResult)