com.blackbear.flatworm.converters
Class CoreConverters

java.lang.Object
  extended by com.blackbear.flatworm.converters.CoreConverters

public class CoreConverters
extends java.lang.Object

CoreConverters contains methods to convert the most commonly encountered text types to native Java types. It can be used as the class parameter in a Flatworm converter tag, with one of the public methods listed below as the method parameter.

All converters (included the ones listed here and any supplied by the user) should expect to accept and handle the following conversion-options:

justify
Defines the justification rule used to strip/add pad characters to this field. Used in conjunction with the pad-character option. Valid values are: The default if no value is specified is both
pad-character
Defines the character to be used in conjunction with the justify option when removing or adding pad characters from a field. The default value is the space character.
default-value
Defines the default value to be used if the field is empty after being stripped of pad characters.

Version:
$Id: CoreConverters.java,v 1.6 2005/09/21 04:01:44 blackbearnh Exp $
Author:
James M. Turner

Constructor Summary
CoreConverters()
           
 
Method Summary
 java.lang.String convertBigDecimal(java.lang.Object obj, java.util.HashMap options)
           
 java.math.BigDecimal convertBigDecimal(java.lang.String str, java.util.HashMap options)
          Conversion function for BigDecimal, returns the source string with padding removed if requested, converted into a big decimal.
 java.lang.String convertChar(java.lang.Object obj, java.util.HashMap options)
          Object->String conversion function.
 java.lang.String convertChar(java.lang.String str, java.util.HashMap options)
          Conversion function for String, returns the source string with padding removed if requested.
 java.lang.String convertDate(java.lang.Object obj, java.util.HashMap options)
          Date->String conversion function.
 java.util.Date convertDate(java.lang.String str, java.util.HashMap options)
          Conversion function for Date, returns the source string with padding removed if requested, converted into a date.
 java.lang.String convertDecimal(java.lang.Object obj, java.util.HashMap options)
           
 java.lang.Double convertDecimal(java.lang.String str, java.util.HashMap options)
          Conversion function for Double, returns the source string with padding removed if requested, converted into a double.
 java.lang.String convertInteger(java.lang.Object obj, java.util.HashMap options)
           
 java.lang.Integer convertInteger(java.lang.String str, java.util.HashMap options)
          Conversion function for Integer, returns the source string with padding removed if requested, converted into a integer.
 java.lang.String convertLong(java.lang.Object obj, java.util.HashMap options)
           
 java.lang.Long convertLong(java.lang.String str, java.util.HashMap options)
          Conversion function for Long, returns the source string with padding removed if requested, converted into a long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoreConverters

public CoreConverters()
Method Detail

convertChar

public java.lang.String convertChar(java.lang.String str,
                                    java.util.HashMap options)
Conversion function for String, returns the source string with padding removed if requested.

Parameters:
str - The source string
options - The conversion-option values for the field
Returns:
The string with padding removed

convertChar

public java.lang.String convertChar(java.lang.Object obj,
                                    java.util.HashMap options)
Object->String conversion function.

Parameters:
obj - source object
options - The conversion-option values for the field
Returns:
The string result

convertDate

public java.util.Date convertDate(java.lang.String str,
                                  java.util.HashMap options)
                           throws FlatwormConversionException
Conversion function for Date, returns the source string with padding removed if requested, converted into a date.

In addition to the standard conversion options, dates also support the following:

format
A date format string in SimpleDateFormat syntax that defines the format to expect, default is yyyy-MM-dd.

Parameters:
str - The source string
options - The conversion-option values for the field
Returns:
The converted date
Throws:
FlatwormConversionException - if the date fails to parse correctly.

convertDate

public java.lang.String convertDate(java.lang.Object obj,
                                    java.util.HashMap options)
Date->String conversion function.

Parameters:
obj - source object of type Date.
options - The conversion-option values for the field
Returns:
the string result

convertDecimal

public java.lang.Double convertDecimal(java.lang.String str,
                                       java.util.HashMap options)
                                throws FlatwormConversionException
Conversion function for Double, returns the source string with padding removed if requested, converted into a double.

In addition to the standard conversion options, doubles also support the following:

decimal-implied
If set to true, the decimal point is positionally implied rather than explicitly included. If set, decimal-places is required.
decimal-places
The number of digits in the string which are to the right of the decimal point, if decimal-implied is set.

Parameters:
str - The source string
options - The conversion-option values for the field
Returns:
The converted double value
Throws:
FlatwormConversionException - If the source number fails to parse as a double or the decimal places option fails to parse as an integer value.

convertDecimal

public java.lang.String convertDecimal(java.lang.Object obj,
                                       java.util.HashMap options)

convertInteger

public java.lang.Integer convertInteger(java.lang.String str,
                                        java.util.HashMap options)
                                 throws FlatwormConversionException
Conversion function for Integer, returns the source string with padding removed if requested, converted into a integer.

Parameters:
str - The source string
options - The conversion-option values for the field
Returns:
The converted integer value
Throws:
FlatwormConversionException - If the source number fails to parse as an integer value.

convertInteger

public java.lang.String convertInteger(java.lang.Object obj,
                                       java.util.HashMap options)

convertLong

public java.lang.Long convertLong(java.lang.String str,
                                  java.util.HashMap options)
                           throws FlatwormConversionException
Conversion function for Long, returns the source string with padding removed if requested, converted into a long.

Parameters:
str - The source string
options - The conversion-option values for the field
Returns:
The converted long value
Throws:
FlatwormConversionException - If the source number fails to parse as an long value.

convertLong

public java.lang.String convertLong(java.lang.Object obj,
                                    java.util.HashMap options)

convertBigDecimal

public java.math.BigDecimal convertBigDecimal(java.lang.String str,
                                              java.util.HashMap options)
                                       throws FlatwormConversionException
Conversion function for BigDecimal, returns the source string with padding removed if requested, converted into a big decimal.

In addition to the standard conversion options, big decimals also support the following:

decimal-implied
If set to true, the decimal point is positionally implied rather than explicitly included. If set, decimal-places is required.
decimal-places
The number of digits in the string which are to the right of the decimal point, if decimal-implied is set.

Parameters:
str - The source string
options - The conversion-option values for the field
Returns:
The converted big decimal value
Throws:
FlatwormConversionException - If the source number fails to parse as a big decimal or the decimal places option fails to parse as an integer value.

convertBigDecimal

public java.lang.String convertBigDecimal(java.lang.Object obj,
                                          java.util.HashMap options)