com.flexive.shared
Class FxFormatUtils

java.lang.Object
  extended by com.flexive.shared.FxFormatUtils

public final class FxFormatUtils
extends java.lang.Object

Miscellaneous formatting utility functions.

Author:
Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at), Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Field Summary
static java.lang.String DEFAULT_COLOR
           
static java.lang.String UNIVERSAL_TIMEFORMAT
           
 
Method Summary
static java.lang.String checkEmail(java.lang.String email)
          Checks the email.
static java.lang.String colorCodeToStyle(java.lang.String code)
          Converts "#FF0000" or "FF0000" rgb values to style="color:#FF0000" and all other style values to class="XXX".
static java.lang.String encodeHex(byte[] bytes)
          Turns an array of bytes into a String representing each byte as an unsigned hex number.
static java.lang.String encodePassword(long accountId, java.lang.String password)
          Checks the password and encodes it.
static java.lang.String escapeForJavaScript(java.lang.String value)
          Escape text content for output in a javascript function call parameter.
static java.lang.String escapeForJavaScript(java.lang.String value, boolean replaceNewlines)
          Escape text content for output in a javascript function call parameter.
static java.lang.String escapeForJavaScript(java.lang.String value, boolean replaceNewlines, boolean filterHtml)
          Escape text content for output in a javascript function call parameter, based on the Struts TagUtils#filter function.
static java.lang.String escapeForSql(java.lang.Object value)
          Generic SQL escape method.
static java.lang.String escapeTreePath(java.lang.String path)
          Escape a path to allow only a-zA-Z0-9/ and replace all other letters with underscores (_)
static java.lang.String formatResource(java.lang.String resource, long languageId, java.lang.Object... values)
          Format a resource, replacing all {x} by the appropriate value in values.
static java.text.SimpleDateFormat getDateFormat()
          Returns a basic date format that is readable but not localized.
static java.text.SimpleDateFormat getDateTimeFormat()
          Returns a basic date/time format that is readable but not localized.
static java.text.SimpleDateFormat getUniversalDateTimeFormat()
          Returns a formatter for the universal date/time format
static boolean isQuoted(java.lang.String value)
          Is the value quoted by ' or " ?
static boolean isRGBCode(java.lang.String value)
          Checks if a value is a RGB color code.
static java.lang.String processColorString(java.lang.String paramName, java.lang.String value)
          Check if a color value is valid.
static java.lang.Boolean toBoolean(java.lang.String value)
          Convert a String to Boolean
static java.util.Date toDate(java.lang.String value)
          Convert a String to Date
static java.util.Date toDateTime(java.lang.String value)
          Convert a String to DateTime
static java.lang.Double toDouble(java.lang.String value)
          Convert a String to Double
static java.lang.Float toFloat(java.lang.String value)
          Convert a String to Float
static java.lang.Integer toInteger(java.lang.String value)
          Convert a String to Integer
static java.lang.Long toLong(java.lang.String value)
          Convert a String to Long
static java.lang.String toString(java.util.Date date)
           
static java.lang.String unquote(java.lang.String value)
          Unquote a quoted value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COLOR

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

UNIVERSAL_TIMEFORMAT

public static final java.lang.String UNIVERSAL_TIMEFORMAT
See Also:
Constant Field Values
Method Detail

isRGBCode

public static boolean isRGBCode(java.lang.String value)
Checks if a value is a RGB color code.

The RGB color code my start with a '#', but is also recognized without it.

Parameters:
value - the string to check
Returns:
true if the value is a valid RGB color code

colorCodeToStyle

public static java.lang.String colorCodeToStyle(java.lang.String code)
Converts "#FF0000" or "FF0000" rgb values to style="color:#FF0000" and all other style values to class="XXX".

Parameters:
code - the color code
Returns:
the style or class value

checkEmail

public static java.lang.String checkEmail(java.lang.String email)
                                   throws FxInvalidParameterException
Checks the email. Also allows local email addresses without a domain (e.g. 'root@localhost').

Parameters:
email - the email to check
Returns:
the email without whitespaces
Throws:
FxInvalidParameterException - if the email is invalid

encodePassword

public static java.lang.String encodePassword(long accountId,
                                              java.lang.String password)
                                       throws FxInvalidParameterException
Checks the password and encodes it.

Parameters:
accountId - the account ID (needed for computing the hash)
password - unencoded the password
Returns:
the encoded password
Throws:
FxInvalidParameterException - if the password is invalid (too short, too simple, ..)

processColorString

public static java.lang.String processColorString(java.lang.String paramName,
                                                  java.lang.String value)
                                           throws FxInvalidParameterException
Check if a color value is valid.

The color may be a RGB value (recognized by a starting '#') or a css class name.
The function returns the default color if value is empty.
If the value defines an invalid RGB value a FxInvalidParameterException is thrown.

Parameters:
paramName - the name of the parameter that is used when a FxInvalidParameterException is thrown
value - the color alue
Returns:
the (corrected) color
Throws:
FxInvalidParameterException - if the color is invalid

escapeTreePath

public static java.lang.String escapeTreePath(java.lang.String path)
Escape a path to allow only a-zA-Z0-9/ and replace all other letters with underscores (_)

Parameters:
path - the path to escape
Returns:
escaped path

toString

public static java.lang.String toString(java.util.Date date)

isQuoted

public static boolean isQuoted(java.lang.String value)
Is the value quoted by ' or " ?

Parameters:
value - value to check
Returns:
if quoted by ' or " ?

unquote

public static java.lang.String unquote(java.lang.String value)
Unquote a quoted value

Parameters:
value - value to unquote
Returns:
unquoted calue

encodeHex

public static java.lang.String encodeHex(byte[] bytes)
Turns an array of bytes into a String representing each byte as an unsigned hex number.

Parameters:
bytes - an array of bytes to convert to a hex-string
Returns:
generated hex string

formatResource

public static java.lang.String formatResource(java.lang.String resource,
                                              long languageId,
                                              java.lang.Object... values)
Format a resource, replacing all {x} by the appropriate value in values. If values is an instance of FxString the given localeId is used

Parameters:
resource - String containing {0}..{n} placeholders
languageId - used locale if values contain FxString instances
values - either FxString, FxException or any Object using toString()
Returns:
formatted resource

escapeForJavaScript

public static java.lang.String escapeForJavaScript(java.lang.String value,
                                                   boolean replaceNewlines,
                                                   boolean filterHtml)
Escape text content for output in a javascript function call parameter, based on the Struts TagUtils#filter function.

Parameters:
value - the text content
replaceNewlines - replaces linebreaks with html
tags if set to true, or simply removes them (replaces them with spaces) if set to false.
filterHtml - filter html?
Returns:
the escaped text

escapeForJavaScript

public static java.lang.String escapeForJavaScript(java.lang.String value,
                                                   boolean replaceNewlines)
Escape text content for output in a javascript function call parameter.

Parameters:
value - the text content
replaceNewlines - replaces linebreaks with html
tags if set to true, or simply removes them (replaces them with spaces) if set to false.
Returns:
the escaped text

escapeForJavaScript

public static java.lang.String escapeForJavaScript(java.lang.String value)
Escape text content for output in a javascript function call parameter.

Parameters:
value - the text content
Returns:
the escaped text

escapeForSql

public static java.lang.String escapeForSql(java.lang.Object value)
Generic SQL escape method.

Parameters:
value - the value to be formatted
Returns:
the formatted value

getDateTimeFormat

public static java.text.SimpleDateFormat getDateTimeFormat()
Returns a basic date/time format that is readable but not localized.

Returns:
a basic date/time format that is readable but not localized.

getUniversalDateTimeFormat

public static java.text.SimpleDateFormat getUniversalDateTimeFormat()
Returns a formatter for the universal date/time format

Returns:
formatter for the universal date/time format

getDateFormat

public static java.text.SimpleDateFormat getDateFormat()
Returns a basic date format that is readable but not localized.

Returns:
a basic date format that is readable but not localized.

toBoolean

public static java.lang.Boolean toBoolean(java.lang.String value)
Convert a String to Boolean

Parameters:
value - value to convert
Returns:
Boolean

toInteger

public static java.lang.Integer toInteger(java.lang.String value)
Convert a String to Integer

Parameters:
value - value to convert
Returns:
Integer

toLong

public static java.lang.Long toLong(java.lang.String value)
Convert a String to Long

Parameters:
value - value to convert
Returns:
Long

toDouble

public static java.lang.Double toDouble(java.lang.String value)
Convert a String to Double

Parameters:
value - value to convert
Returns:
Double

toFloat

public static java.lang.Float toFloat(java.lang.String value)
Convert a String to Float

Parameters:
value - value to convert
Returns:
Float

toDate

public static java.util.Date toDate(java.lang.String value)
Convert a String to Date

Parameters:
value - value to convert
Returns:
Date

toDateTime

public static java.util.Date toDateTime(java.lang.String value)
Convert a String to DateTime

Parameters:
value - value to convert
Returns:
Date