atg.droplet
Class CurrencyFormatter

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.nucleus.TimedOperationService
              extended by atg.nucleus.servlet.ServletService
                  extended by atg.nucleus.servlet.HttpServletService
                      extended by atg.servlet.DynamoServlet
                          extended by atg.droplet.CurrencyFormatter
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, ParameterServlet, java.util.EventListener, javax.servlet.Servlet
Direct Known Subclasses:
CurrencyConversionFormatter

public class CurrencyFormatter
extends DynamoServlet

This droplet can be used to format a numeric amount, within a particular Locale, into a specific currency.

Example:

 <importbean bean="/atg/dynamo/droplet/CurrencyFormatter">
 <droplet bean="CurrencyFormatter">
   <param name="currency" value="param:amount">
   <param name="locale" value="bean:/OriginatingRequest.requestLocale.locale">
   <oparam name="output">
     <valueof param="formattedCurrency">no price</valueof>
   </oparam>
 </droplet>
 
Usage:
currency
A number, expressed as either a java.lang.Number or String, which is the value to format
locale
The locale which should be used to format the currency amount. This value can be either a java.util.Locale object or a String which represents a locale. (e.g. en_US)
output
This parameter is serviced if the instance of this class is used as a droplet
formattedCurrency
Available from within the output parameter, this is the formatted currency


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.servlet.DynamoServlet
mAllowCleanupRequest, mParameters
 
Fields inherited from class atg.nucleus.servlet.ServletService
SERVLET_INFO_KEY
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
CurrencyFormatter()
          Constructs an instanceof CurrencyFormatter
 
Method Summary
protected  java.lang.String formatCurrency(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Return the currency formatted in the given Locale as a String.
protected  java.lang.Number getCurrency(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Returns the currency value from the request.
protected  java.util.Locale getCurrencyLocale(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Returns the locale associated with the request.
 java.util.Locale getDefaultLocale()
          Returns property DefaultLocale.
protected  java.lang.String getEuroSymbol(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Returns the symbol to use when formatting a price in Euros.
 boolean isUseRequestLocale()
          Returns property UseRequestLocale
 void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Takes the formatted currency String and sets a request parameter named formattedCurrency, then services the output parameter.
 void setDefaultLocale(java.util.Locale pDefaultLocale)
          Sets property DefaultLocale
 void setUseRequestLocale(boolean pUseRequestLocale)
          Sets property UseRequestLocale
 
Methods inherited from class atg.servlet.DynamoServlet
doDelete, doGet, doPost, doPut, getParameter, getParameters, getServletContext, service, service, setParameter
 
Methods inherited from class atg.nucleus.servlet.ServletService
destroy, getServletConfig, getServletInfo, init, setServletInfo
 
Methods inherited from class atg.nucleus.TimedOperationService
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
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

Constructor Detail

CurrencyFormatter

public CurrencyFormatter()
Constructs an instanceof CurrencyFormatter

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


getCurrency

protected java.lang.Number getCurrency(DynamoHttpServletRequest pRequest,
                                       DynamoHttpServletResponse pResponse)
                                throws javax.servlet.ServletException,
                                       java.io.IOException
Returns the currency value from the request. The method first searches for a request parameter named currency, and if that cannot be found then return 0.0

Throws:
javax.servlet.ServletException
java.io.IOException

getCurrencyLocale

protected java.util.Locale getCurrencyLocale(DynamoHttpServletRequest pRequest,
                                             DynamoHttpServletResponse pResponse)
                                      throws javax.servlet.ServletException,
                                             java.io.IOException
Returns the locale associated with the request. The method first searches for a request paramater named locale. 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.

Throws:
javax.servlet.ServletException
java.io.IOException

getEuroSymbol

protected java.lang.String getEuroSymbol(DynamoHttpServletRequest pRequest,
                                         DynamoHttpServletResponse pResponse)
                                  throws javax.servlet.ServletException,
                                         java.io.IOException
Returns the symbol to use when formatting a price in Euros. This is optional.

Throws:
javax.servlet.ServletException
java.io.IOException

formatCurrency

protected java.lang.String formatCurrency(DynamoHttpServletRequest pRequest,
                                          DynamoHttpServletResponse pResponse)
                                   throws javax.servlet.ServletException,
                                          java.io.IOException
Return the currency formatted in the given Locale as a String. The currency and locale are extracted from the request using the getCurrency(request, response) and getCurrencyLocale(request, response) methods.

Throws:
javax.servlet.ServletException
java.io.IOException

service

public void service(DynamoHttpServletRequest pRequest,
                    DynamoHttpServletResponse pResponse)
             throws javax.servlet.ServletException,
                    java.io.IOException
Takes the formatted currency String and sets a request parameter named formattedCurrency, then services the output parameter.

Overrides:
service in class DynamoServlet
Parameters:
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - an application specific error occurred processing this request
java.io.IOException - an error occurred reading data from the request or writing data to the response.