atg.commerce.util
Class MapToArrayDefaultFirst

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.commerce.util.MapToArrayDefaultFirst
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, ParameterServlet, java.util.EventListener, javax.servlet.Servlet

public class MapToArrayDefaultFirst
extends DynamoServlet

This droplet is used to convert a map property to a sorted array with the value of the first item being the item that matched the defaultId param. The droplet is primarily to sort the shipping address and credit card properties so that the default address or card is displayed as the first item on the jsp page. Each item in the sorted array is a repository item.

If either the defaultId or map parameters are not set, the droplet will return the map as an unsorted array. In the case of a null map, the returning array would be null.

This droplet takes the following parameters

defaultId
The parameter that defines the repositoryId of the default address/credit card
map
The parameter that defines the map of shipping addresses/credit cards

Example


  <dsp:droplet name="MapToArrayDefaultFirst">
     <param name="defaultId" value="Profile.shippingAddress.repositoryId"/>
     <param name="map" value="Profile.shippingAddrs"/>
     <oparam name="output">
        <dsp:droplet name="ForEach">
           <param name="array" value="sortedArray"/>
           <oparam name="output">
              key: &ltdsp:valueof param="element.key"/&gt
              address city: <dsp:valueof param="element.value.city"&gt/>
           </oparam>
        </dsp:droplet>
     </oparam>>
  </droplet>

 

Parameters:
   output- Rendered on successful sort.
     sortedArray- Array of RepositoryItem object with the default item first      sortedArraySize- Size of returned array


Field Summary
static java.lang.String CLASS_VERSION
          Class version string.
static ParameterName DEFAULT_ID
          Default id parameter name.
static ParameterName MAP
          Map parameter name.
static ParameterName OUTPUT
          Output parameter name.
static java.lang.String SORTED_ARRAY
          Sorted array parameter name.
static java.lang.String SORTED_ARRAY_SIZE
          Sorted array size parameter name.
 
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
MapToArrayDefaultFirst()
           
 
Method Summary
protected  boolean checkIfDefaultIsInMap(java.util.Map pMap, java.lang.String pDefaultId)
          Look in the map and see if an item with the defaultId value is in there.
 void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          See the class documentation above.
protected  java.lang.Object[] sortArray(java.lang.Object[] pUnsortedArray, java.lang.String pDefaultId, DynamoHttpServletRequest pRequest)
          Performs the sorting of the array of RepositoryItem.
 
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.


MAP

public static final ParameterName MAP
Map parameter name.


DEFAULT_ID

public static final ParameterName DEFAULT_ID
Default id parameter name.


OUTPUT

public static final ParameterName OUTPUT
Output parameter name.


SORTED_ARRAY

public static java.lang.String SORTED_ARRAY
Sorted array parameter name.


SORTED_ARRAY_SIZE

public static java.lang.String SORTED_ARRAY_SIZE
Sorted array size parameter name.

Constructor Detail

MapToArrayDefaultFirst

public MapToArrayDefaultFirst()
Method Detail

service

public void service(DynamoHttpServletRequest pRequest,
                    DynamoHttpServletResponse pResponse)
             throws javax.servlet.ServletException,
                    java.io.IOException

See the class documentation above.

Overrides:
service in class DynamoServlet
Parameters:
pRequest - - http request
pResponse - - http response
Throws:
javax.servlet.ServletException - if an error occurs
java.io.IOException - if an error occurs

sortArray

protected java.lang.Object[] sortArray(java.lang.Object[] pUnsortedArray,
                                       java.lang.String pDefaultId,
                                       DynamoHttpServletRequest pRequest)
Performs the sorting of the array of RepositoryItem.

Parameters:
pUnsortedArray - of the propeties from the map.
pDefaultId - of the default RepositoryItem
pRequest - object
Returns:
Object[] sorted array of RepositoryItem with the default Object[0]

checkIfDefaultIsInMap

protected boolean checkIfDefaultIsInMap(java.util.Map pMap,
                                        java.lang.String pDefaultId)
Look in the map and see if an item with the defaultId value is in there.

Parameters:
pMap - - map to check
pDefaultId - - default id
Returns:
true if item is in the map, false - otherwisee