|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.droplet.CurrencyTagConverter atg.droplet.CurrencyConversionTagConverter
public class CurrencyConversionTagConverter
A tag converter which is used to parse, format currency amounts and to convert them between an default currency and a locale-specific currency.
This converter is a subclass of CurrencyTagConverter, and relies upon CurrencyTagConverter to do parsing and formatting.
The exchange rates are specified in a properties file that uses 2-letter country codes as the property names. The corresponding value is the number in that country's local currency that corresponds to one unit of the default currency.
If the country of the user's locale (or of the locale specified as an attribute with this TagConverter) does not have a configured exchange rate, then this TagConverter returns null, which causes a <VALUEOF> tag to use its default value.
An example of the use of this converter is as follows:
<valueof param="priceInfo.amount" currencyConversion>no price</valueof>
You can also specify a locale as follows:
<valueof param="priceInfo.amount" currencyConversion 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.
Field Summary | |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string |
protected java.util.Map |
mExchangeRates
|
static java.lang.String |
NAME
|
Constructor Summary | |
---|---|
CurrencyConversionTagConverter()
Constructs an instance of CurrencyConversionTagConverter |
Method Summary | |
---|---|
java.lang.Number |
convertCurrency(java.lang.Number pOriginalValue,
java.util.Locale pLocale,
boolean toLocale)
Convert an amount of money between the default currency and the currency of a specified locale Returns null if the locale does not have a configured exchange rate |
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. |
java.util.Map |
getExchangeRates()
Returns property exchangeRates, and, as a side-effect, initializes it if it has not already been initialized. |
java.lang.String |
getLookupKey(java.util.Locale pLocale)
Obtain the string to use as a look-up key to determine the exchange rate. |
java.lang.String |
getName()
Returns the unique name for the TagConverter. |
TagAttributeDescriptor[] |
getTagAttributeDescriptors()
Returns the list of TagAttributeDescriptors which are used by this converter. |
void |
initializeConversionMap()
Constructs a Map of locale names to currency exchange rates, based on the entries in a ResourceBundle |
protected void |
initializeIfNecessary()
Do the initialization in initializeConversionMap on a just-in-time basis. |
protected static java.lang.String |
replaceEURO(java.lang.String pCurrency,
java.lang.String pReplacement)
Returns a string with the Euro character replaced with the supplied string. |
void |
setExchangeRates(java.util.Map pExchangeRates)
Sets property exchangeRates |
Methods inherited from class atg.droplet.CurrencyTagConverter |
---|
formatCurrency, getCurrencyFormat, 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 |
---|
public static java.lang.String CLASS_VERSION
public static final java.lang.String NAME
protected java.util.Map mExchangeRates
Constructor Detail |
---|
public CurrencyConversionTagConverter()
Method Detail |
---|
public void setExchangeRates(java.util.Map pExchangeRates)
The value of this property is a Map that has an entry for each supported currency conversion. The name for each entry is a 2-letter country code. The value for each entry is a double that indicates how many of the locale-specific currency are equivalent to one (1) unit of the default currency.
public java.util.Map getExchangeRates()
initializeIfNecessary
public java.lang.String getName()
getName
in interface TagConverter
getName
in class CurrencyTagConverter
public TagAttributeDescriptor[] getTagAttributeDescriptors()
getTagAttributeDescriptors
in interface TagConverter
getTagAttributeDescriptors
in class CurrencyTagConverter
public java.lang.Object convertStringToObject(DynamoHttpServletRequest pRequest, java.lang.String pValue, java.util.Properties pAttributes) throws TagConversionException
convertStringToObject
in interface TagConverter
convertStringToObject
in class CurrencyTagConverter
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.
TagConversionException
- if the conversion failed.public java.lang.String convertObjectToString(DynamoHttpServletRequest pRequest, java.lang.Object pValue, java.util.Properties pAttributes) throws TagConversionException
convertObjectToString
in interface TagConverter
convertObjectToString
in class CurrencyTagConverter
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 StringpAttributes
- the set of attributes supplied in this tag
declaration.
TagConversionException
protected void initializeIfNecessary()
initializeConversionMap
,
getExchangeRates
public void initializeConversionMap()
public java.lang.Number convertCurrency(java.lang.Number pOriginalValue, java.util.Locale pLocale, boolean toLocale)
pOriginalValue
- the amount of money to convertpLocale
- the locale indicating the currency from/to which to converttoLocale
- true to convert from default to locale-specific currency,
false to convert from locale-specific currency to default currencypublic java.lang.String getLookupKey(java.util.Locale pLocale)
pLocale
- the user's localeprotected static java.lang.String replaceEURO(java.lang.String pCurrency, java.lang.String pReplacement)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |