atg.droplet
Class ForEach

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.ForEach
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
Direct Known Subclasses:
ErrorMessageForEach, ForEachItemInCatalog, NodeForEach, RQLQueryForEach, SQLQueryForEach

public class ForEach
extends DynamoServlet

This servlet renders its output parameter for each element in its array parameter. The array parameter can be a general Collection (Vectors, Lists, Sets), Iterator, Enumeration, Map, Dictionary or an array.

Each iteration will set three parameters: index and count to the current loop index (0-based) and count (1-based), respectively, and element to the value of that element of the array.

A complete description of the parameters to the ForEach droplet are:

array
The parameter that defines the list of items to output. This parameter can be a general Collection (Vectors, Lists, Sets), Iterator, Enumeration, Map, Dictionary or an array.
elementName
The optional parameter that should be used for the name of the element which is bound into the scope of the output oparam.
indexName
The optional parameter that should be used for the name of the index value which is bound into the scope of the output oparam.
outputStart
This parameter is rendered before any output tags if the array is not empty.
outputEnd
This parameter is rendered after all output tags if the array is not empty.
output
This parameter is rendered for once for each element in the array.
index
This parameter is set to the index of the current element of the array each time that the output parameter is rendered. Its value for the first iteration is 0.
count
This parameter is set to the index of the current element of the array each time that the output parameter is rendered. Its value for the first iteration is 1.
element
This parameter is set to the current element of the array each time that the output parameter is rendered.
size
This parameter is set to the size of the array if the array has a size. Arrays of type Enumeration and Iterator have no size so the size will be set to -1.
empty
This optional parameter is rendered if the array contains no elements.
key
This parameter is set once for each element in the array if the array parameter refers to a Map or Dictionary.
sortProperties
A string that specifies how to sort the list of items. Sorting can either be performed on properties of Java Beans, Dynamic Beans, or Dates, Numbers, Strings. To do sorting on Java Beans, this parameter is specified as a comma separated list of property names. The first name specifies the primary sort, the second specifies the secondary sort, etc. If the first character of each keyword is a +, this sort is performed in ascending order. If it has a -, it is a descending order. To sort Numbers, Dates, or Strings, this parameter should contain either a single "+" or a single "-" to indicate ascending or descending order respectively.

To sort on the key value if a Map or Dictionary value is used, use the name _key to refer to the key in the sortProperties list.

reverseOrder
A boolean value that specifies whether the traversal order in the array should be back to front, or front to back. 'true' sorts from back to front. This parameter only takes effect if the sortProperties are not set.


Field Summary
static ParameterName ARRAY
           
static java.lang.String CLASS_VERSION
           
static java.lang.String COUNT
           
static ParameterName DEBUG
           
static java.lang.String ELEMENT
           
static ParameterName ELEMENT_NAME
           
static ParameterName EMPTY
           
static java.lang.String INDEX
           
static ParameterName INDEX_NAME
           
static java.lang.String KEY
           
static ParameterName OUTPUT
           
static ParameterName OUTPUT_END
           
static ParameterName OUTPUT_START
           
static ParameterName REVERSE_ORDER
           
static java.lang.String SIZE
           
static ParameterName SORT_PROPERTIES
           
 
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
ForEach()
           
 
Method Summary
 java.lang.Object getArray(DynamoHttpServletRequest pReq)
          Gets the array-like value (e.g., array, List, Enumeration) to be used by this droplet from the request.
static java.lang.Object getSortedArray(DynamoServlet pServlet, java.lang.Object pArrayParam, DynamoHttpServletRequest pReq)
          This method needs to be static because it is used by the Range, Table, etc.
 void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method provides the default implementation of service, by dispatching to conventionally named methods which begin with "do".
protected  void serviceArray(java.lang.Object[] pArray, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for array objects
protected  void serviceCollection(java.util.Collection pCollection, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for Collection objects
protected  void serviceDictionary(java.util.Dictionary pDictionary, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for Dictionary objects
protected  void serviceEnumeration(java.util.Enumeration pEnumeration, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for Enumeration objects
protected  void serviceIndexedList(java.util.List pIndexedList, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for indexed List objects, i.e.
protected  void serviceIterator(java.util.Iterator pIterator, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for Iterator objects
protected  void serviceMap(java.util.Map pMap, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for Map objects
protected  void serviceMapArray(java.util.Map.Entry[] pArray, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for array objects
protected  void servicePrimitiveArray(java.lang.Object pArray, java.lang.String pIndexName, java.lang.String pElementName, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Renders the foreach operation for primitive array objects using the reflection methods to access values in the array.
protected  void setElementParameter(DynamoHttpServletRequest pReq, java.lang.String pElementName, java.lang.Object pValue)
          This method can be overridden by sub-classes to customize how the element parmeter is set.
 
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, reResolveThis, 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

KEY

public static final java.lang.String KEY
See Also:
Constant Field Values

ELEMENT

public static final java.lang.String ELEMENT
See Also:
Constant Field Values

INDEX

public static final java.lang.String INDEX
See Also:
Constant Field Values

COUNT

public static final java.lang.String COUNT
See Also:
Constant Field Values

SIZE

public static final java.lang.String SIZE
See Also:
Constant Field Values

ARRAY

public static final ParameterName ARRAY

OUTPUT_START

public static final ParameterName OUTPUT_START

OUTPUT_END

public static final ParameterName OUTPUT_END

OUTPUT

public static final ParameterName OUTPUT

DEBUG

public static final ParameterName DEBUG

EMPTY

public static final ParameterName EMPTY

SORT_PROPERTIES

public static final ParameterName SORT_PROPERTIES

REVERSE_ORDER

public static final ParameterName REVERSE_ORDER

ELEMENT_NAME

public static final ParameterName ELEMENT_NAME

INDEX_NAME

public static final ParameterName INDEX_NAME
Constructor Detail

ForEach

public ForEach()
Method Detail

getArray

public java.lang.Object getArray(DynamoHttpServletRequest pReq)
Gets the array-like value (e.g., array, List, Enumeration) to be used by this droplet from the request. Subclasses may override this method to extract the array by some means other than simply looking up its parameter value in the request.


setElementParameter

protected void setElementParameter(DynamoHttpServletRequest pReq,
                                   java.lang.String pElementName,
                                   java.lang.Object pValue)
This method can be overridden by sub-classes to customize how the element parmeter is set.


service

public void service(DynamoHttpServletRequest pRequest,
                    DynamoHttpServletResponse pResponse)
             throws javax.servlet.ServletException,
                    java.io.IOException
Description copied from class: DynamoServlet
This method provides the default implementation of service, by dispatching to conventionally named methods which begin with "do".

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.

serviceMapArray

protected void serviceMapArray(java.util.Map.Entry[] pArray,
                               java.lang.String pIndexName,
                               java.lang.String pElementName,
                               DynamoHttpServletRequest pRequest,
                               DynamoHttpServletResponse pResponse)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Renders the foreach operation for array objects

Parameters:
pArray - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceArray

protected void serviceArray(java.lang.Object[] pArray,
                            java.lang.String pIndexName,
                            java.lang.String pElementName,
                            DynamoHttpServletRequest pRequest,
                            DynamoHttpServletResponse pResponse)
                     throws javax.servlet.ServletException,
                            java.io.IOException
Renders the foreach operation for array objects

Parameters:
pArray - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

servicePrimitiveArray

protected void servicePrimitiveArray(java.lang.Object pArray,
                                     java.lang.String pIndexName,
                                     java.lang.String pElementName,
                                     DynamoHttpServletRequest pRequest,
                                     DynamoHttpServletResponse pResponse)
                              throws javax.servlet.ServletException,
                                     java.io.IOException
Renders the foreach operation for primitive array objects using the reflection methods to access values in the array. This version is slightly slower than the regular array version, but more general and works for int[] etc. arrays.

Parameters:
pArray - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceIndexedList

protected void serviceIndexedList(java.util.List pIndexedList,
                                  java.lang.String pIndexName,
                                  java.lang.String pElementName,
                                  DynamoHttpServletRequest pRequest,
                                  DynamoHttpServletResponse pResponse)
                           throws javax.servlet.ServletException,
                                  java.io.IOException
Renders the foreach operation for indexed List objects, i.e. ArrayList or Vector objects.

Parameters:
pList - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceCollection

protected void serviceCollection(java.util.Collection pCollection,
                                 java.lang.String pIndexName,
                                 java.lang.String pElementName,
                                 DynamoHttpServletRequest pRequest,
                                 DynamoHttpServletResponse pResponse)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
Renders the foreach operation for Collection objects

Parameters:
pCollection - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceIterator

protected void serviceIterator(java.util.Iterator pIterator,
                               java.lang.String pIndexName,
                               java.lang.String pElementName,
                               DynamoHttpServletRequest pRequest,
                               DynamoHttpServletResponse pResponse)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Renders the foreach operation for Iterator objects

Parameters:
pIterator - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceEnumeration

protected void serviceEnumeration(java.util.Enumeration pEnumeration,
                                  java.lang.String pIndexName,
                                  java.lang.String pElementName,
                                  DynamoHttpServletRequest pRequest,
                                  DynamoHttpServletResponse pResponse)
                           throws javax.servlet.ServletException,
                                  java.io.IOException
Renders the foreach operation for Enumeration objects

Parameters:
pEnumeration - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceMap

protected void serviceMap(java.util.Map pMap,
                          java.lang.String pIndexName,
                          java.lang.String pElementName,
                          DynamoHttpServletRequest pRequest,
                          DynamoHttpServletResponse pResponse)
                   throws javax.servlet.ServletException,
                          java.io.IOException
Renders the foreach operation for Map objects

Parameters:
pMap - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

serviceDictionary

protected void serviceDictionary(java.util.Dictionary pDictionary,
                                 java.lang.String pIndexName,
                                 java.lang.String pElementName,
                                 DynamoHttpServletRequest pRequest,
                                 DynamoHttpServletResponse pResponse)
                          throws javax.servlet.ServletException,
                                 java.io.IOException
Renders the foreach operation for Dictionary objects

Parameters:
pDictionary - the object to iterate
pIndexName - the parameter name to use for the index
pElementName - the parameter name to use for the element
pRequest - the request to be processed
pResponse - the response object for this request
Throws:
javax.servlet.ServletException - if an application specific error occurred processing this request
java.io.IOException - if an error occurred reading data from the request or writing data to the response

getSortedArray

public static java.lang.Object getSortedArray(DynamoServlet pServlet,
                                              java.lang.Object pArrayParam,
                                              DynamoHttpServletRequest pReq)
This method needs to be static because it is used by the Range, Table, etc. droplets which are not derived from this droplet. This takes the servlet, the array parameter, and the request and returns the possibly sorted array parameter.