atg.droplet
Class CurrencyTagConverter

java.lang.Object
  extended by atg.droplet.CurrencyTagConverter
All Implemented Interfaces:
TagConverter
Direct Known Subclasses:
CurrencyConversionTagConverter, EuroTagConverter

public class CurrencyTagConverter
extends java.lang.Object
implements TagConverter

A tag converter which is used to parse and format currency amounts.

An example of this is as follows:

<valueof param="priceInfo.amount" currency>no price</valueof>
You can also specify a locale the currency should be rendered with:
<valueof param="priceInfo.amount" currency locale="en_US">no price</valueof>
If no locale is specified then the converter first looks for a request parameter named locale. This parameter can either be a java.util.Locale object or a String which names a locale. If this cannot be found then we fetch the locale from the RequestLocale.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String NAME
           
 
Constructor Summary
CurrencyTagConverter()
          Constructs an instanceof CurrencyTagConverter
 
Method Summary
 java.lang.String convertObjectToString(DynamoHttpServletRequest pRequest, java.lang.Object pValue, java.util.Properties pAttributes)
          Converts the supplied Object value to a String value.
 java.lang.Object convertStringToObject(DynamoHttpServletRequest pRequest, java.lang.String pValue, java.util.Properties pAttributes)
          Converts the supplied String value to an Object value.
static java.lang.String formatCurrency(java.lang.Object pCurrency, java.util.Locale pLocale)
          Return the supplied currency formatted in the given Locale as a String.
static java.text.NumberFormat getCurrencyFormat(java.util.Locale pLocale)
          Return a NumberFormat object which can be used to format currency based on the given Locale
 java.util.Locale getDefaultLocale()
          Returns property DefaultLocale.
 java.lang.String getName()
          Returns the unique name for the TagConverter.
static java.text.NumberFormat getNumberFormat(java.util.Locale pLocale)
           
 TagAttributeDescriptor[] getTagAttributeDescriptors()
          Returns the list of TagAttributeDescriptors which are used by this converter.
 boolean isUseRequestLocale()
          Returns property UseRequestLocale
 void setDefaultLocale(java.util.Locale pDefaultLocale)
          Sets property DefaultLocale
 void setUseRequestLocale(boolean pUseRequestLocale)
          Sets property UseRequestLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


NAME

public static final java.lang.String NAME
See Also:
Constant Field Values
Constructor Detail

CurrencyTagConverter

public CurrencyTagConverter()
Constructs an instanceof CurrencyTagConverter

Method Detail

setDefaultLocale

public void setDefaultLocale(java.util.Locale pDefaultLocale)
Sets property DefaultLocale


getDefaultLocale

public java.util.Locale getDefaultLocale()
Returns property DefaultLocale. If the property value is null, then JVM's default locale is returned.


setUseRequestLocale

public void setUseRequestLocale(boolean pUseRequestLocale)
Sets property UseRequestLocale


isUseRequestLocale

public boolean isUseRequestLocale()
Returns property UseRequestLocale


getName

public java.lang.String getName()
Returns the unique name for the TagConverter. This name can be used by the TagConverterManager to get a handle to this converter. When you specify the use of a TagConverter using the converter attribute in a tag, you use this name to refer to the TagConverter. TagConverter names are case insensitive (as is the convention in HTML).

Specified by:
getName in interface TagConverter

getTagAttributeDescriptors

public TagAttributeDescriptor[] getTagAttributeDescriptors()
Returns the list of TagAttributeDescriptors which are used by this converter.

Specified by:
getTagAttributeDescriptors in interface TagConverter

convertStringToObject

public java.lang.Object convertStringToObject(DynamoHttpServletRequest pRequest,
                                              java.lang.String pValue,
                                              java.util.Properties pAttributes)
                                       throws TagConversionException
Converts the supplied String value to an Object value. This operation is performed if a converter is used with an input tag during the form submission process or if a converter attributes are specified in the param tag when defining a new parameter.

Specified by:
convertStringToObject in interface TagConverter
Parameters:
pRequest - the request object for this conversion. This object can be null if the conversion is not performed in the context of a request.
pAttributes - The list of attributes in the tag that is invoking this converter.
pValue - The original String value to be converted.
Returns:
the converted object value.
Throws:
TagConversionException - if the conversion failed.

convertObjectToString

public java.lang.String convertObjectToString(DynamoHttpServletRequest pRequest,
                                              java.lang.Object pValue,
                                              java.util.Properties pAttributes)
                                       throws TagConversionException
Converts the supplied Object value to a String value. This operation is performed when you are displaying a value using this converter. This occurs when the converter is used in the valueof tag or when rendering the value attribute of an input tag.

Specified by:
convertObjectToString in interface TagConverter
Parameters:
pRequest - the request this conversion applies to. You can use this request to obtain the RequestLocale to localize the conversion process. This can be null if the conversion is not performed in the context of a request.
pValue - the Object value to be converted to a String
pAttributes - the set of attributes supplied in this tag declaration.
Returns:
the converted object value.
Throws:
TagConversionException

getCurrencyFormat

public static java.text.NumberFormat getCurrencyFormat(java.util.Locale pLocale)
Return a NumberFormat object which can be used to format currency based on the given Locale


getNumberFormat

public static java.text.NumberFormat getNumberFormat(java.util.Locale pLocale)

formatCurrency

public static java.lang.String formatCurrency(java.lang.Object pCurrency,
                                              java.util.Locale pLocale)
Return the supplied currency formatted in the given Locale as a String.