public class CurrencyConversionFormatter extends CurrencyFormatter
Example:
<importbean bean="/atg/dynamo/droplet/CurrencyConversionFormatter">
<droplet bean="CurrencyConversionFormatter">
<param name="currency" value="param:amount">
<param name="locale" value="en_US">
<param name="targetLocale" value="bean:/OriginatingRequest.requestLocale.locale">
<param name="euroSymbol" value="&euro">
<oparam name="output">
<valueof param="formattedCurrency" valueishtml>no price</valueof>
</oparam>
</droplet>
Usage:
output parameter, this is the formatted currency
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CLASS_VERSION
Class version string
|
protected java.util.Map |
mExchangeRates |
mAllowCleanupRequest, mParametersSERVLET_INFO_KEYSERVICE_INFO_KEYDEFAULT_LOG_TRACE_STATUSDEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS| Constructor and Description |
|---|
CurrencyConversionFormatter()
Constructs an instanceof CurrencyConversionFormatter
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Number |
convertCurrency(java.lang.Number pOriginalValue,
java.util.Locale pSourceLocale,
java.util.Locale pTargetLocale)
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 |
protected java.lang.String |
formatCurrency(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse)
Return the currency formatted in the given Locale as a
String.
|
protected java.util.Locale |
getCurrencyTargetLocale(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse)
Returns the locale associated with the request.
|
protected java.lang.String |
getEuroSymbol(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse)
Returns the symbol to use when formatting a price in Euros.
|
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.
|
protected java.lang.String |
getYenSymbol(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse)
Returns the symbol to use when formatting a price in Yen.
|
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.
|
void |
service(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse)
Takes the formatted currency String and sets a request parameter named
formattedCurrency, then services the output
parameter. |
void |
setExchangeRates(java.util.Map pExchangeRates)
Sets property exchangeRates
|
getCurrency, getCurrencyLocale, getDefaultLocale, isUseRequestLocale, setDefaultLocale, setUseRequestLocaledoDelete, doGet, doPost, doPut, getParameter, getParameters, getServletContext, init, service, service, setParameterdestroy, getServletConfig, getServletInfo, setServletInfogetAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatisticsaddLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopServicevlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarningpublic static java.lang.String CLASS_VERSION
protected java.util.Map mExchangeRates
public CurrencyConversionFormatter()
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()
initializeIfNecessaryprotected java.util.Locale getCurrencyTargetLocale(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws javax.servlet.ServletException, java.io.IOException
sourceLocale. This value can be
either a java.util.Locale object or a String which represents the locale.
Next if the useRequestLocale property is true, then the locale
of the request will be returned. Finally, if the locale cannot be determined,
the the defaultLocale property is used.javax.servlet.ServletExceptionjava.io.IOExceptionprotected java.lang.String getEuroSymbol(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws javax.servlet.ServletException, java.io.IOException
getEuroSymbol in class CurrencyFormatterjavax.servlet.ServletExceptionjava.io.IOExceptionprotected java.lang.String getYenSymbol(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws javax.servlet.ServletException, java.io.IOException
javax.servlet.ServletExceptionjava.io.IOExceptionprotected java.lang.String formatCurrency(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws javax.servlet.ServletException, java.io.IOException
getCurrency(request, response)
getCurrencyLocale(request, response) and
getCurrencyTargetLocale(request, response) methods.formatCurrency in class CurrencyFormatterjavax.servlet.ServletExceptionjava.io.IOExceptionprotected void initializeIfNecessary()
initializeConversionMap,
getExchangeRatespublic void initializeConversionMap()
ServiceException - if an entry could not be parsed as a Doublepublic java.lang.Number convertCurrency(java.lang.Number pOriginalValue,
java.util.Locale pSourceLocale,
java.util.Locale pTargetLocale)
pOriginalValue - the amount of money to convertpSourceLocale - the locale indicating the currency from which to convertpTargetLocale - the locale indicating the currency to which to convertpublic java.lang.String getLookupKey(java.util.Locale pLocale)
pLocale - the user's localepublic void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws javax.servlet.ServletException, java.io.IOException
formattedCurrency, then services the output
parameter.service in class CurrencyFormatterpRequest - the request to be processedpResponse - the response object for this requestjavax.servlet.ServletException - an application specific error occurred
processing this requestjava.io.IOException - an error occurred reading data from the request
or writing data to the response.