atg.droplet
Class EuroTagConverter

java.lang.Object
  extended by atg.droplet.CurrencyTagConverter
      extended by atg.droplet.EuroTagConverter
All Implemented Interfaces:
TagConverter

public class EuroTagConverter
extends CurrencyTagConverter

A tag converter which will parse and format a currency amounts if and only if the user's locale indicates a country/language that supports the Euro.
N.B. the user's locale does not, itself, need to have the "EURO" variant. For example, if the user's locale is fr_FR, then the currency amount will be formatted as though the locale were "fr_FR_EURO".

If the user's locale indicates a country that does not use use the Euro (e.g., en_US), then the tag converter returns null, so that a <VALUEOF> tag will use its default value.

This converter is a subclass of CurrencyTagConverter, and relies upon CurrencyTagConverter to do parsing and formatting.

An example of the use of this converter is as follows:

<valueof param="priceInfo.amount" euro>no price</valueof>
You can also specify a locale as follows:
<valueof param="priceInfo.amount" euro locale="en_US">no price</valueof>
As with CurrencyTagConverter, 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.

You can optionally specify a string to substitute for the euro currency symbol. This is useful because the commonly-used character set ISO Latin-1 (ISO 8859-1) does not include this character. For example, you can specify:

<valueof param="priceInfo.amount" euro symbol="€" >no price</valueof>
This substitutes the HTML entity &euro; in place of the euro currency symbol. Most browsers correctly display this HTML entity as the currency symbol, even when using ISO Latin-1.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static java.lang.String NAME
           
 
Constructor Summary
EuroTagConverter()
          Constructs an instance of EuroTagConverter
 
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.
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 as an amount in euros.
static java.util.Map getFormatMap()
          Returns property formatMap, and, as a side-effect, initializes it if it has not already been initialized.
 java.lang.String getName()
          Returns the unique name for the TagConverter.
 TagAttributeDescriptor[] getTagAttributeDescriptors()
          Returns the list of TagAttributeDescriptors which are used by this converter.
protected static void initializeFormatMap()
          Find all available euro-compatible locales, and construct a Map that associates their language/country with the number format for formatting amounts of money as an amount in Euros.
protected static void initializeIfNecessary()
          Do the initialization in initializeFormatMap on a just-in-time basis.
static void setFormatMap(java.util.Map pFormatMap)
          Sets property formatMap
 
Methods inherited from class atg.droplet.CurrencyTagConverter
convertStringToObject, getDefaultLocale, getNumberFormat, isUseRequestLocale, setDefaultLocale, setUseRequestLocale
 
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

EuroTagConverter

public EuroTagConverter()
Constructs an instance of EuroTagConverter

Method Detail

setFormatMap

public static void setFormatMap(java.util.Map pFormatMap)
Sets property formatMap

The value of this property is a Map that has an entry for each euro-compatible locale. The name for each entry is a language/country locale name. The value for each entry is the NumberFormat to use to format currency for that locale.


getFormatMap

public static java.util.Map getFormatMap()
Returns property formatMap, and, as a side-effect, initializes it if it has not already been initialized.

See Also:
initializeIfNecessary

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
Overrides:
getName in class CurrencyTagConverter

getTagAttributeDescriptors

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

Specified by:
getTagAttributeDescriptors in interface TagConverter
Overrides:
getTagAttributeDescriptors in class CurrencyTagConverter

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.

The implementation here is copied from the superclass CurrencyTagConverter, but calls this class' override of static method formatCurrency.

Specified by:
convertObjectToString in interface TagConverter
Overrides:
convertObjectToString in class CurrencyTagConverter
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

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.

The implementation here differs from that in the superclass, CurrencyTagConverter, in that, here, if there is no (euro-oriented) NumberFormat available, then this method returns null.


getCurrencyFormat

public static java.text.NumberFormat getCurrencyFormat(java.util.Locale pLocale)
Return a NumberFormat object which can be used to format currency as an amount in euros.
If the user's locale is not euro-compatible, then this method returns null.


initializeIfNecessary

protected static void initializeIfNecessary()
Do the initialization in initializeFormatMap on a just-in-time basis. Formerly this was done in a static initalizer, causing a big start-up cost for this class.

See Also:
initializeFormatMap, getFormatMap

initializeFormatMap

protected static void initializeFormatMap()
Find all available euro-compatible locales, and construct a Map that associates their language/country with the number format for formatting amounts of money as an amount in Euros.