com.elasticpath.commons.util
Interface Utility

All Known Implementing Classes:
UtilityImpl

public interface Utility

Provides utility methods used throughout the application.


Field Summary
static int MAX_ALLOW_EXPRESSIONS_IN_QUERY
          Maximum allow expressions in a hql query.
 
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 the full stack of the given exception.
 java.util.Map getCardTypeMap()
          Get a map of the supported card types for display in Spring.
 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.
 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.
 

Field Detail

MAX_ALLOW_EXPRESSIONS_IN_QUERY

static final int MAX_ALLOW_EXPRESSIONS_IN_QUERY
Maximum allow expressions in a hql query.

Note: since Oracle only allow 1000 expressions in one query, this value should be set less than 1000.

See Also:
Constant Field Values
Method Detail

array2string

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

Parameters:
array - the array of objects
separator - the separator
Returns:
a concatenation string

bigDecimal2String

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

Parameters:
bigDecimalValue - the BigDecimal object
Returns:
a String object

boolean2String

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

Parameters:
booleanValue - the boolean value
Returns:
a String object

checkLongTextMaxLength

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

Parameters:
value - the value to check
Returns:
true if the length of the given value <= long text max length. Otherwise, false.

checkShortTextMaxLength

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

Parameters:
value - the value to check
Returns:
true if the length of the given value <= short text max length. Otherwise, false.

composeQueries

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.

Parameters:
queryTemplate - the query template
placeHolder - the place holder as a regular expression
values - the values to replace the place holder.
Returns:
a list of queries.

date2String

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

Parameters:
date - the date
Returns:
the converted date string

date2String

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

Parameters:
date - the date
sdf - the simple date format
Returns:
the converted date string

escapeName2UrlFriendly

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

Parameters:
name - the original name
Returns:
a escaped name which is URL-friendly.

exception2string

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

Parameters:
exception - the exception
Returns:
a string with the full stack of the given exception

getCardTypeMap

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

Returns:
the credit card type map

getLocalizedFile

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 locale "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;

Parameters:
baseDir - the base directory
filePath - the file path relative to the base directory
fileExtension - the file extension
locale - the locale
Returns:
the localized file path

getMonthMap

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

Returns:
map of month digit strings

getRandomStringWithLength

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

Parameters:
length - the length of the string to return
Returns:
a random string

getTimeStamp

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

Returns:
a timestamp string.

getYearMap

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

Returns:
map of year strings

int2String

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

Parameters:
intValue - the int value
Returns:
a String object

isAlphaNumeric

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

Parameters:
string - the string
Returns:
true if the given string is all alphanumeric characters. Otherwise, false

isValidGuidStr

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

Parameters:
string - the string
Returns:
true if the given string is a valid guid string. Otherwise, false

isValidZipPostalCode

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

Parameters:
zipPostalCode - the zip postal code.
Returns:
true if the given zip postal code is valid. Otherwise, false.

regexQuote

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

Parameters:
regexString - The string to be escaped
Returns:
the escaped string

string2BigDecimal

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

Parameters:
stringValue - the string
Returns:
a BigDecimal object
Throws:
EpBigDecimalBindException - if the given string cannot be converted to a BigDecimal object

string2Boolean

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

Parameters:
stringValue - the string
Returns:
a boolean value
Throws:
EpBooleanBindException - if the given string cannot be converted to a boolean value

string2Currency

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

Parameters:
stringValue - the string
Returns:
a Currency instance.
Throws:
EpCurrencyBindException - if the given string cannot be converted to a Currency instance

string2Date

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

Parameters:
stringValue - the string
Returns:
a Date object
Throws:
EpDateBindException - if the given string cannot be converted to a Date object

string2Date

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

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 - if the given string cannot be converted to a Date object

string2Int

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

Parameters:
stringValue - the string
Returns:
an int value
Throws:
EpIntBindException - if the given string cannot be converted to an int value

string2Locale

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

Parameters:
stringValue - the string
Returns:
a Locale instance.
Throws:
EpLocaleBindException - if the given string cannot be converted to a Locale instance

string2Long

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

Parameters:
stringValue - the string
Returns:
a long value
Throws:
EpLongBindException - if the given string cannot be converted to an long value

string2Money

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

Parameters:
currency - the currency
value - the value
Returns:
a Money instance