com.elasticpath.commons.util.impl
Class UtilityImpl

java.lang.Object
  extended by com.elasticpath.commons.util.impl.UtilityImpl
All Implemented Interfaces:
Utility

public final class UtilityImpl
extends java.lang.Object
implements Utility

The default implementation of Utility.


Field Summary
 
Fields inherited from interface com.elasticpath.commons.util.Utility
MAX_ALLOW_EXPRESSIONS_IN_QUERY
 
Constructor Summary
UtilityImpl()
           
 
Method Summary
 java.lang.String array2string(java.lang.Object[] array, java.lang.String separator)
          Convert an array of objects to a string.
 java.lang.String bigDecimal2String(java.math.BigDecimal bigDecimalValue)
          Convert a BigDecimal object to a String object.
 java.lang.String boolean2String(boolean booleanValue)
          Convert a boolean value to a String object.
 boolean checkLongTextMaxLength(java.lang.String value)
          Returns true if the length of the given value <= long text max length.
 boolean checkShortTextMaxLength(java.lang.String value)
          Returns true if the length of the given value <= short text max length.
 java.util.List composeQueries(java.lang.String queryTemplate, java.lang.String placeHolder, java.util.Collection values)
          Compose queries based on the given query template, place holder and values.
 java.lang.String date2String(java.util.Date date)
          Convert a Date to a String based on the system default date format.
 java.lang.String date2String(java.util.Date date, java.text.SimpleDateFormat sdf)
          Convert a date to a string based on the given date format.
 java.lang.String escapeName2UrlFriendly(java.lang.String name)
          Returns an escaped name which is URL-friendly.
 java.lang.String exception2string(java.lang.Exception exception)
          Returns a string with full stack of the given exception.
 java.util.Map getCardTypeMap()
          Get a map of the supported card types for display in Spring.
 ElasticPath getElasticPath()
          Returns the elastic path context.
 java.lang.String getLocalizedFile(java.lang.String baseDir, java.lang.String filePath, java.lang.String fileExtension, java.util.Locale locale)
          Return the localized file path of the given file path.
 java.util.Map getMonthMap()
          Get a map of the numbers of months of the year for the Spring form input for credit card expiry.
 java.lang.String getRandomStringWithLength(int length)
          Get a random string with the required length.
 java.lang.String getTimeStamp()
          Returns a timestamp string.
 java.util.Map getYearMap()
          Get a map of years for the Spring form input for credit card expiry.
 java.lang.String int2String(int intValue)
          Convert an int value to a String object.
 boolean isAlphaNumeric(java.lang.String string)
          Returns true if the given string is all alphanumeric characters.
 boolean isValidGuidStr(java.lang.String string)
          Returns true if the given string is a valid guid string.
 boolean isValidZipPostalCode(java.lang.String zipPostalCode)
          Returns true if the given zip postal code is valid.
 java.lang.String regexQuote(java.lang.String regexString)
          Escapes the provided String as a literal String safe for use as a regular expression.
 void setElasticPath(ElasticPath elasticPath)
          Sets the elastic path context.
 java.math.BigDecimal string2BigDecimal(java.lang.String stringValue)
          Convert a String to a BigDecimal object.
 boolean string2Boolean(java.lang.String stringValue)
          Convert a String to a boolean value .
 java.util.Currency string2Currency(java.lang.String stringValue)
          Convert a String to a Currency instance.
 java.util.Date string2Date(java.lang.String stringValue)
          Convert a String to a Date based on the system default date format.
 java.util.Date string2Date(java.lang.String dateString, java.text.SimpleDateFormat sdf)
          Convert a date string and return a Date object.
 int string2Int(java.lang.String stringValue)
          Convert a String to an int value .
 java.util.Locale string2Locale(java.lang.String stringValue)
          Convert a String to a Locale instance.
 long string2Long(java.lang.String stringValue)
          Convert a String to an long value.
 Money string2Money(java.util.Currency currency, java.lang.String value)
          Convert a String to a Money instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UtilityImpl

public UtilityImpl()
Method Detail

array2string

public java.lang.String array2string(java.lang.Object[] array,
                                     java.lang.String separator)
Convert an array of objects to a string.

Specified by:
array2string in interface Utility
Parameters:
array - the array of objects
separator - the separator
Returns:
a concatenation string

bigDecimal2String

public java.lang.String bigDecimal2String(java.math.BigDecimal bigDecimalValue)
Convert a BigDecimal object to a String object.

Specified by:
bigDecimal2String in interface Utility
Parameters:
bigDecimalValue - the BigDecimal object
Returns:
a String object

boolean2String

public java.lang.String boolean2String(boolean booleanValue)
Convert a boolean value to a String object.

Specified by:
boolean2String in interface Utility
Parameters:
booleanValue - the boolean value
Returns:
a String object

checkLongTextMaxLength

public boolean checkLongTextMaxLength(java.lang.String value)
Returns true if the length of the given value <= long text max length. Otherwise, false.

Specified by:
checkLongTextMaxLength in interface Utility
Parameters:
value - the value to check
Returns:
true if the length of the given value <= long text max length. Otherwise, false.

checkShortTextMaxLength

public boolean checkShortTextMaxLength(java.lang.String value)
Returns true if the length of the given value <= short text max length. Otherwise, false.

Specified by:
checkShortTextMaxLength in interface Utility
Parameters:
value - the value to check
Returns:
true if the length of the given value <= short text max length. Otherwise, false.

composeQueries

public java.util.List composeQueries(java.lang.String queryTemplate,
                                     java.lang.String placeHolder,
                                     java.util.Collection values)
Compose queries based on the given query template, place holder and values.

Note: since Oracle only allow 1000 expressions in one query, we have to separate big query over 1000 expressions to multiple queries. This method can be used to create multiple queries for you.

Specified by:
composeQueries in interface Utility
Parameters:
queryTemplate - the query template
placeHolder - the place holder as a regular expression
values - a list of values to replace the place holder.
Returns:
a list of queries.

date2String

public java.lang.String date2String(java.util.Date date)
Convert a Date to a String based on the system default date format.

Specified by:
date2String in interface Utility
Parameters:
date - the date
Returns:
the converted date string

date2String

public java.lang.String date2String(java.util.Date date,
                                    java.text.SimpleDateFormat sdf)
Convert a date to a string based on the given date format.

Specified by:
date2String in interface Utility
Parameters:
date - the date
sdf - the simple date format
Returns:
the converted date string

escapeName2UrlFriendly

public java.lang.String escapeName2UrlFriendly(java.lang.String name)
Returns an escaped name which is URL-friendly.

Specified by:
escapeName2UrlFriendly in interface Utility
Parameters:
name - the original name
Returns:
a escaped name which is URL-friendly.

exception2string

public java.lang.String exception2string(java.lang.Exception exception)
Returns a string with full stack of the given exception.

Specified by:
exception2string in interface Utility
Parameters:
exception - the exception
Returns:
a string with full stack of the given exception

getCardTypeMap

public java.util.Map getCardTypeMap()
Get a map of the supported card types for display in Spring.

Specified by:
getCardTypeMap in interface Utility
Returns:
the credit card type map

getElasticPath

public ElasticPath getElasticPath()
Returns the elastic path context.

Returns:
the elastic path context.

getLocalizedFile

public java.lang.String getLocalizedFile(java.lang.String baseDir,
                                         java.lang.String filePath,
                                         java.lang.String fileExtension,
                                         java.util.Locale locale)
Return the localized file path of the given file path.
Example:
When you are looking for "/dir/file.vm" with local "en_CA"
 If "/dir/file_en_CA.vm" exists, it will be returned;
 If "/dir/file_en_CA.vm" does not exist, but "/dir/file_en.vm" exists, it will be returned;
 If neither of the above files exist, "/dir/file.vm" will be returned;

Specified by:
getLocalizedFile in interface Utility
Parameters:
baseDir - the base directory
filePath - the file path relative the base directory
fileExtension - the file extension
locale - the locale
Returns:
the localized file path

getMonthMap

public java.util.Map getMonthMap()
Get a map of the numbers of months of the year for the Spring form input for credit card expiry.

Specified by:
getMonthMap in interface Utility
Returns:
map of month digit strings

getRandomStringWithLength

public java.lang.String getRandomStringWithLength(int length)
Get a random string with the required length.

Specified by:
getRandomStringWithLength in interface Utility
Parameters:
length - the length of the string to return
Returns:
a random string

getTimeStamp

public java.lang.String getTimeStamp()
Returns a timestamp string.

Specified by:
getTimeStamp in interface Utility
Returns:
a timestamp string.

getYearMap

public java.util.Map getYearMap()
Get a map of years for the Spring form input for credit card expiry.

Specified by:
getYearMap in interface Utility
Returns:
map of year strings

int2String

public java.lang.String int2String(int intValue)
Convert an int value to a String object.

Specified by:
int2String in interface Utility
Parameters:
intValue - the int value
Returns:
a String object

isAlphaNumeric

public boolean isAlphaNumeric(java.lang.String string)
Returns true if the given string is all alphanumeric characters. Otherwise, false

Specified by:
isAlphaNumeric in interface Utility
Parameters:
string - the string
Returns:
true if the given string is all alphanumeric characters. Otherwise, false

isValidGuidStr

public boolean isValidGuidStr(java.lang.String string)
Returns true if the given string is a valid guid string. Otherwise, false

Specified by:
isValidGuidStr in interface Utility
Parameters:
string - the string
Returns:
true if the given string is a valid guid string. Otherwise, false

isValidZipPostalCode

public boolean isValidZipPostalCode(java.lang.String zipPostalCode)
Returns true if the given zip postal code is valid. Otherwise, false.

Specified by:
isValidZipPostalCode in interface Utility
Parameters:
zipPostalCode - the zip postal code.
Returns:
true if the given zip postal code is valid. Otherwise, false.

regexQuote

public java.lang.String regexQuote(java.lang.String regexString)
Escapes the provided String as a literal String safe for use as a regular expression.

Specified by:
regexQuote in interface Utility
Parameters:
regexString - The string to be escaped
Returns:
the escaped string

setElasticPath

public void setElasticPath(ElasticPath elasticPath)
Sets the elastic path context.

Parameters:
elasticPath - the elastic path context

string2BigDecimal

public java.math.BigDecimal string2BigDecimal(java.lang.String stringValue)
                                       throws EpBigDecimalBindException
Convert a String to a BigDecimal object.

Specified by:
string2BigDecimal in interface Utility
Parameters:
stringValue - the string
Returns:
a BigDecimal object
Throws:
EpBigDecimalBindException - if the given string cannot be converted to a BigDecimal object

string2Boolean

public boolean string2Boolean(java.lang.String stringValue)
                       throws EpBooleanBindException
Convert a String to a boolean value .

Specified by:
string2Boolean in interface Utility
Parameters:
stringValue - the string
Returns:
a boolean value
Throws:
EpBooleanBindException - if the given string cannot be converted to a boolean value

string2Currency

public java.util.Currency string2Currency(java.lang.String stringValue)
                                   throws EpCurrencyBindException
Convert a String to a Currency instance.

Specified by:
string2Currency in interface Utility
Parameters:
stringValue - the string
Returns:
a Currency instance.
Throws:
EpCurrencyBindException - if the given string cannot be converted to a Currency instance

string2Date

public java.util.Date string2Date(java.lang.String stringValue)
                           throws EpDateBindException
Convert a String to a Date based on the system default date format.

Specified by:
string2Date in interface Utility
Parameters:
stringValue - the string
Returns:
a Date object
Throws:
EpDateBindException - if the given string cannot be converted to a Date object

string2Date

public java.util.Date string2Date(java.lang.String dateString,
                                  java.text.SimpleDateFormat sdf)
                           throws EpDateBindException
Convert a date string and return a Date object.

Specified by:
string2Date in interface Utility
Parameters:
dateString - A date string to parse
sdf - The simple date format of the date string.
Returns:
Return a Date object if the data string is valid.
Return null if the data string is invalid.
Throws:
EpDateBindException - in case the given string cannot be converted to a Date object

string2Int

public int string2Int(java.lang.String stringValue)
               throws EpIntBindException
Convert a String to an int value .

Specified by:
string2Int in interface Utility
Parameters:
stringValue - the string
Returns:
a int value
Throws:
EpIntBindException - if the given string cannot be converted to a int value

string2Locale

public java.util.Locale string2Locale(java.lang.String stringValue)
                               throws EpLocaleBindException
Convert a String to a Locale instance.

Specified by:
string2Locale in interface Utility
Parameters:
stringValue - the string
Returns:
a Locale instance.
Throws:
EpLocaleBindException - if the given string cannot be converted to a Locale instance

string2Long

public long string2Long(java.lang.String stringValue)
                 throws EpLongBindException
Convert a String to an long value.

Specified by:
string2Long in interface Utility
Parameters:
stringValue - the string
Returns:
a long value
Throws:
EpLongBindException - if the given string cannot be converted to an long value

string2Money

public Money string2Money(java.util.Currency currency,
                          java.lang.String value)
Convert a String to a Money instance.

Specified by:
string2Money in interface Utility
Parameters:
currency - the currency
value - the value
Returns:
a Money instance