org.apache.commons.scaffold.text
Class ConvertUtils

java.lang.Object
  extended by org.apache.commons.scaffold.text.ConvertUtils

public class ConvertUtils
extends Object

An experimental class with some standard conversion utilities. Needs more proof of concept and unit testing.

Version:
$Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $
Author:
Ted Husted, OK State DEQ, WXXI Public Broadcasting Council

Field Summary
static char CARRIAGE_RETURN
          Carriage return character.
static String CURRENCY_PATTERN
          Standard currency pattern.
static String DATE_SEPARATOR
          Date separator ["-"].
static String DATE_TIME_SEPARATOR
          Date Time separator [" "].
static String DECIMAL_PATTERN
          Default decimal pattern.
static int DEFAULT
          Default style for dates and times.
static Double DOUBLE_ONE
          An Double 1.
static Double DOUBLE_ZERO
          An Double 0.
static String EMPTY_STRING
          Deprecated. Use STRING_EMPTY
static String ESCAPE_DATE_PATTERN
          A "default" date format.
static char FILE_SEPARATOR
          File separator character.
static char FORM_FEED
          Form feed character.
static int FULL
          Full style for dates and times.
static char GROUP_SEPARATOR
          Group separator character.
static char HORIZONTAL_TABULATION
          Horizontal tab character.
static Integer INTEGER_ONE
          An Integer 1.
static Integer INTEGER_ZERO
          An Integer 0.
static char LINE_FEED
          Line feed character.
static int LONG
          Long style for dates and times.
static Timestamp MAX_TIMESTAMP
          Timestamp representing "December 31, 2029, 23:59:59.9"
static int MEDIUM
          Medium style for dates and times.
static long NULL_TIME
          Value needed to create Timestamp representing "January 1, 1970 00:00:00".
static Timestamp NULL_TIMESTAMP
          Timestamp representing "January 1, 1970 00:00:00".
static String NULL_TIMESTAMP_DISPLAY
          Escape string to create Timestamp representing "January 1, 1970 00:00:00".
static String NULL_TIMESTAMP_TEXT
          Deprecated. Use NULL_TIMESTAMP_DISPLAY.
static String QS_DELIM
          The token that delimits two or more attributes of a query string ["&"].
static String QS_SEP
          The token that seperates an attribute name and value.
static String QS_START
          The token that signifies the begnning of a query string ["?"].
static char RECORD_SEPARATOR
          Record separator character.
static char[] SEPARATORS
          Array of line separator characters.
static int SHORT
          Short style for dates and times.
static Short SHORT_ONE
          A Short 1.
static Short SHORT_ZERO
          A Short 0.
static char SPACE
          Space character.
static String STRING_EMPTY
          An empty string.
static String STRING_ONE
          A String 1.
static String STRING_SPACE
          An single-space string.
static String STRING_ZERO
          A String 0.
static String TIME_SEPARATOR
          Time separator [":"].
static String TIMESTAMP_DATE_ZERO
          String to prepend to time [HH:MM:SS.d] to create a Timestamp escape string ["0002-11-30"].
static String TIMESTAMP_TIME_ZERO
          String to append to date [YEAR-MM-DD] to create a Timestamp escape string [" 00:00:00.0"].
static char UNIT_SEPARATOR
          Unit separator character.
static char VERTICAL_TABULATION
          Vertical tab character.
static Timestamp ZERO_TIMESTAMP
          Timestamp representing ""November 30, 0002 00:00:00".
static String ZERO_TIMESTAMP_DISPLAY
          Escape string representing "November 30, 0002 00:00:00".
 
Method Summary
static String addLuhnDigit(String number)
          Returns number with the appropriate digit appended so that is passes a "luhnCheck".
static String addParam(String path, String name, String value)
          Appends name=value parameter.
static String addParams(String path, Map parameters)
          Appends name=value parameters to path from Map.
static boolean blank(Number key)
          Deprecated. Use blank instead.
static boolean blank(String s)
          Deprecated. Use blank instead.
static boolean blankValue(String s)
          Returns true if null, trims to an empty string, or to "0".
static String getCurrency(Number value)
          Return currency for default locale using standard pattern.
static String getDate(Date date)
          Convert date to String for default locale in DEFAULT style.
static String getDate(Date date, int style)
          Convert date to String for default locale in given style.
static String getDate(Date date, Locale locale, int style)
          Convert date to String for given locale in given style.
static Date getDate(String dateDisplay)
          Convert String to Date using a medium (weekday day month year) format.
static Date getDate(String dateDisplay, String format)
          Convert String to Date using given format.
static Date getDate(String dateDisplay, String format, boolean lenient)
          Convert String to Date using given format.
static String getDecimal(Number value)
          Return decimal for default locale using standard pattern.
static String getDecimal(Number value, Locale locale)
          Return decimal number formatted for default or given locale.
static String getDecimal(Number value, Locale locale, String pattern)
          Return decimal number formatted for default or given locale using given pattern.
static String getDigits(String s)
          Return String with of digits only (0..9).
static DecimalFormatSymbols getGenericDecimal(Locale locale)
          Symbols that can be used in a decimal pattern.
static String getNumber(Number value, Locale locale)
          Returns number formatted for default or given locale.
static String getPercent(Number value, Locale locale)
          Returns percent formatted for default or given locale.
static Timestamp getTimestamp()
          Factory method to return timestamp initialized to current system time.
static String getTimestamp(Timestamp timestamp)
          Convert date to String for default locale in DEFAULT style.
static String getTimestamp(Timestamp timestamp, int style)
          Convert date to String for default locale in given style.
static String getTimestamp(Timestamp timestamp, Locale locale, int style)
          Convert timestamp to String for given locale in given style.
static String getTimestampDisplay()
          Return the String representing the current timestamp;
static String getTimestampDisplayNull()
          Return the String representing "January 1, 1970 00:00:00".
static String getTimestampText()
          Deprecated. Use getTimestampDisplay.
static Integer ipNode(String ipAddress)
          Return the integer value of an IP address in dotted octet form, like that returned by request.getRemotehost).
static boolean isBlank(Integer key)
          Deprecated. Use blank instead.
static boolean isBlank(String s)
          Deprecated. Use blank instead.
static boolean isBlankValue(String s)
          Deprecated. Use blankValue instead.
static boolean isNull(Timestamp timestamp)
          Return null if timestamp is null or equals "January 1, 1970 00:00:00".
static boolean luhnCheck(String number)
           
static String renderHiddenFields(Map parameters)
          Returns parameters as a series of hidden HTML fields.
static Date toDate(String string)
          Return Date value using a String.
static String toEscape(Date date)
          Return String value representing Date.
static String[] tokensToArray(String tokens, String separator)
          Return array of tokens, using the result of getTokeSep() as the separator.
static List tokensToList(String tokens, String separator)
          Return list of tokens, using the result of getTokeSep() as the separator.
static String toString(Date date)
          Return String value representing Date.
static String toString(Timestamp timestamp)
          Return String value representing Timestamp.
static Timestamp toTimestamp(String string)
          Return Timestamp value using a String.
static Timestamp toTimestamp(String year, String month, String day)
          Return a Timestamp based on the parameters.
static String toTrimOrEmpty(String string)
          Return a trimmed or empty string (but not null).
static String toUpperOrNull(String string)
          Returns null or a trimmed uppercase string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRING_EMPTY

public static String STRING_EMPTY
An empty string.


EMPTY_STRING

public static String EMPTY_STRING
Deprecated. Use STRING_EMPTY
An empty string.


STRING_SPACE

public static final String STRING_SPACE
An single-space string.

See Also:
Constant Field Values

SPACE

public static final char SPACE
Space character.

See Also:
Constant Field Values

HORIZONTAL_TABULATION

public static final char HORIZONTAL_TABULATION
Horizontal tab character.

See Also:
Constant Field Values

LINE_FEED

public static final char LINE_FEED
Line feed character.

See Also:
Constant Field Values

VERTICAL_TABULATION

public static final char VERTICAL_TABULATION
Vertical tab character.

See Also:
Constant Field Values

FORM_FEED

public static final char FORM_FEED
Form feed character.

See Also:
Constant Field Values

CARRIAGE_RETURN

public static final char CARRIAGE_RETURN
Carriage return character.

See Also:
Constant Field Values

FILE_SEPARATOR

public static final char FILE_SEPARATOR
File separator character.

See Also:
Constant Field Values

GROUP_SEPARATOR

public static final char GROUP_SEPARATOR
Group separator character.

See Also:
Constant Field Values

RECORD_SEPARATOR

public static final char RECORD_SEPARATOR
Record separator character.

See Also:
Constant Field Values

UNIT_SEPARATOR

public static final char UNIT_SEPARATOR
Unit separator character.

See Also:
Constant Field Values

SEPARATORS

public static final char[] SEPARATORS
Array of line separator characters. http://java.sun.com/j2se/1.3/docs/api/java/lang/Character.html#isWhitespace(char)


QS_START

public static String QS_START
The token that signifies the begnning of a query string ["?"].


QS_DELIM

public static String QS_DELIM
The token that delimits two or more attributes of a query string ["&"].


QS_SEP

public static String QS_SEP
The token that seperates an attribute name and value.


DOUBLE_ZERO

public static Double DOUBLE_ZERO
An Double 0.


DOUBLE_ONE

public static Double DOUBLE_ONE
An Double 1.


INTEGER_ZERO

public static Integer INTEGER_ZERO
An Integer 0.


INTEGER_ONE

public static Integer INTEGER_ONE
An Integer 1.


SHORT_ZERO

public static Short SHORT_ZERO
A Short 0.


SHORT_ONE

public static Short SHORT_ONE
A Short 1.


STRING_ZERO

public static String STRING_ZERO
A String 0.


STRING_ONE

public static String STRING_ONE
A String 1.


DECIMAL_PATTERN

public static String DECIMAL_PATTERN
Default decimal pattern. http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html


CURRENCY_PATTERN

public static String CURRENCY_PATTERN
Standard currency pattern. http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html


DEFAULT

public static int DEFAULT
Default style for dates and times.


SHORT

public static int SHORT
Short style for dates and times.


MEDIUM

public static int MEDIUM
Medium style for dates and times.


LONG

public static int LONG
Long style for dates and times.


FULL

public static int FULL
Full style for dates and times.


ESCAPE_DATE_PATTERN

public static String ESCAPE_DATE_PATTERN
A "default" date format.


DATE_SEPARATOR

public static final String DATE_SEPARATOR
Date separator ["-"].

See Also:
Constant Field Values

TIME_SEPARATOR

public static final String TIME_SEPARATOR
Time separator [":"].

See Also:
Constant Field Values

DATE_TIME_SEPARATOR

public static final String DATE_TIME_SEPARATOR
Date Time separator [" "].

See Also:
Constant Field Values

TIMESTAMP_DATE_ZERO

public static final String TIMESTAMP_DATE_ZERO
String to prepend to time [HH:MM:SS.d] to create a Timestamp escape string ["0002-11-30"].

See Also:
Constant Field Values

TIMESTAMP_TIME_ZERO

public static final String TIMESTAMP_TIME_ZERO
String to append to date [YEAR-MM-DD] to create a Timestamp escape string [" 00:00:00.0"]. Note: includes leading space.

See Also:
Constant Field Values

ZERO_TIMESTAMP_DISPLAY

public static String ZERO_TIMESTAMP_DISPLAY
Escape string representing "November 30, 0002 00:00:00".


ZERO_TIMESTAMP

public static Timestamp ZERO_TIMESTAMP
Timestamp representing ""November 30, 0002 00:00:00".


NULL_TIMESTAMP_DISPLAY

public static String NULL_TIMESTAMP_DISPLAY
Escape string to create Timestamp representing "January 1, 1970 00:00:00".


NULL_TIMESTAMP_TEXT

public static String NULL_TIMESTAMP_TEXT
Deprecated. Use NULL_TIMESTAMP_DISPLAY.

NULL_TIME

public static long NULL_TIME
Value needed to create Timestamp representing "January 1, 1970 00:00:00". From the documentation, you would think this would be Timestamp(0), but empirical tests show it to be Timestamp(18000000).


NULL_TIMESTAMP

public static Timestamp NULL_TIMESTAMP
Timestamp representing "January 1, 1970 00:00:00".


MAX_TIMESTAMP

public static Timestamp MAX_TIMESTAMP
Timestamp representing "December 31, 2029, 23:59:59.9"

Method Detail

tokensToArray

public static String[] tokensToArray(String tokens,
                                     String separator)
Return array of tokens, using the result of getTokeSep() as the separator. Blanks are trimmed from tokens.

Parameters:
parameter - The string to tokenize into an array

tokensToList

public static List tokensToList(String tokens,
                                String separator)
Return list of tokens, using the result of getTokeSep() as the separator. Blanks are trimmed from tokens.

Parameters:
parameter - The string to tokenize into an array

isBlank

public static boolean isBlank(String s)
Deprecated. Use blank instead.

Returns true if null or trims to an empty string.


isBlank

public static boolean isBlank(Integer key)
Deprecated. Use blank instead.

Returns true if null or zero.


isBlankValue

public static boolean isBlankValue(String s)
Deprecated. Use blankValue instead.

Returns true if null or trims to an empty string.


blank

public static boolean blank(String s)
Deprecated. Use blank instead.

Returns true if null or trims to an empty string.


blank

public static boolean blank(Number key)
Deprecated. Use blank instead.

Returns true if null or zero.


blankValue

public static boolean blankValue(String s)
Returns true if null, trims to an empty string, or to "0".


toTrimOrEmpty

public static String toTrimOrEmpty(String string)
Return a trimmed or empty string (but not null).


toUpperOrNull

public static String toUpperOrNull(String string)
Returns null or a trimmed uppercase string.


addParam

public static String addParam(String path,
                              String name,
                              String value)
Appends name=value parameter.


addParams

public static String addParams(String path,
                               Map parameters)
Appends name=value parameters to path from Map.


renderHiddenFields

public static String renderHiddenFields(Map parameters)
Returns parameters as a series of hidden HTML fields.


getDigits

public static String getDigits(String s)
Return String with of digits only (0..9). http://java.sun.com/j2se/1.4/docs/api/java/lang/Character.html


getNumber

public static String getNumber(Number value,
                               Locale locale)
Returns number formatted for default or given locale.


getPercent

public static String getPercent(Number value,
                                Locale locale)
Returns percent formatted for default or given locale.


luhnCheck

public static boolean luhnCheck(String number)

addLuhnDigit

public static String addLuhnDigit(String number)
Returns number with the appropriate digit appended so that is passes a "luhnCheck".

Parameters:
Number - - Number to process. Must be all digits and not null.

getGenericDecimal

public static DecimalFormatSymbols getGenericDecimal(Locale locale)
Symbols that can be used in a decimal pattern.


getDecimal

public static String getDecimal(Number value,
                                Locale locale)
Return decimal number formatted for default or given locale.


getDecimal

public static String getDecimal(Number value,
                                Locale locale,
                                String pattern)
Return decimal number formatted for default or given locale using given pattern.


getDecimal

public static String getDecimal(Number value)
Return decimal for default locale using standard pattern.


getCurrency

public static String getCurrency(Number value)
Return currency for default locale using standard pattern.


getDate

public static Date getDate(String dateDisplay,
                           String format,
                           boolean lenient)
Convert String to Date using given format. Returns null if conversion fails. Set lenient=false to disallow dates like 2001-9-32. http://java.sun.com/j2se/1.4/docs/api/java/text/SimpleDateFormat.html


getDate

public static Date getDate(String dateDisplay,
                           String format)
Convert String to Date using given format. Returns null if conversion fails. Uses "strict" coNversion (lenient=false).


getDate

public static Date getDate(String dateDisplay)
Convert String to Date using a medium (weekday day month year) format. Returns null if conversion fails. Uses "strict" coNversion (lenient=false).


toDate

public static Date toDate(String string)
Return Date value using a String. Null or conversion error returns null.

Parameters:
String - representing Date

getDate

public static String getDate(Date date,
                             Locale locale,
                             int style)
Convert date to String for given locale in given style. A null locale will return the default locale.


getDate

public static String getDate(Date date,
                             int style)
Convert date to String for default locale in given style. A null locale will return the default locale.


getDate

public static String getDate(Date date)
Convert date to String for default locale in DEFAULT style. A null locale will return the default locale.


toString

public static String toString(Date date)
Return String value representing Date. Null returns null.

Parameters:
Date -

toEscape

public static String toEscape(Date date)
Return String value representing Date. Null returns null.

Parameters:
Date -

getTimestampDisplayNull

public static String getTimestampDisplayNull()
Return the String representing "January 1, 1970 00:00:00".


getTimestampDisplay

public static String getTimestampDisplay()
Return the String representing the current timestamp;


getTimestampText

public static String getTimestampText()
Deprecated. Use getTimestampDisplay.


isNull

public static boolean isNull(Timestamp timestamp)
Return null if timestamp is null or equals "January 1, 1970 00:00:00".


getTimestamp

public static Timestamp getTimestamp()
Factory method to return timestamp initialized to current system time. For timestamp as a String in the default format, use getTimestamp().toString().


getTimestamp

public static String getTimestamp(Timestamp timestamp,
                                  Locale locale,
                                  int style)
Convert timestamp to String for given locale in given style. A null locale will return the default locale.


getTimestamp

public static String getTimestamp(Timestamp timestamp,
                                  int style)
Convert date to String for default locale in given style. A null locale will return the default locale.


getTimestamp

public static String getTimestamp(Timestamp timestamp)
Convert date to String for default locale in DEFAULT style. A null locale will return the default locale.


toTimestamp

public static Timestamp toTimestamp(String string)
Return Timestamp value using a String. Null or conversion error returns null.

Parameters:
String - representing Timestamp

toTimestamp

public static Timestamp toTimestamp(String year,
                                    String month,
                                    String day)
Return a Timestamp based on the parameters. Any nulls or conversion error returns null.

Parameters:
year - The year
month - The month
day - The day

toString

public static String toString(Timestamp timestamp)
Return String value representing Timestamp. Null returns null.

Parameters:
Timestamp -

ipNode

public static Integer ipNode(String ipAddress)
Return the integer value of an IP address in dotted octet form, like that returned by request.getRemotehost). :FIXME: Needs to be implemented; just returns zero.

Parameters:
Timestamp -


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.