atg.repository.servlet
Class ItemLookupDroplet

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.repository.servlet.ItemLookupDroplet
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:
CatalogItemLookupDroplet

public class ItemLookupDroplet
extends DynamoServlet

This servlet looks for a RepositoryItem by its id from within a Repository. If the item is found, output is rendered. If the item is not found empty is rendered. The repository and item descriptor type can be configured through properties. If the useParams property is true, then the repository and item descriptor can be resolved through input parameters. One can configure this droplet to define a mapping from a key to an alternate set of repositories.
For example: ProductLookup.properties

 $class=atg.repository.servlet.ItemLookupDroplet
 
 repository=/atg/commerce/catalog/ProductCatalog
 itemDescriptor=product
 
 alternateRepositories=\
      fr_FR=/atg/commerce/catalog/FrenchProductCatalog
      ja_JP=/atg/commerce/catalog/JapaneseProductCatalog
      de_DE=/atg/commerce/catalog/GermanProductCatalog
 
The invocation of the droplet can then be invoked with the following parameters:
  <dsp:droplet name="/atg/commerce/catalog/ProductLookup">
    <dsp:param name="id" param="productId"/>
    <dsp:param  name="repositoryKey" bean="/OriginatingRequest.requestLocale.localeString"/>
    <dsp:setvalue param="product" paramvalue="element"/>
    <dsp:oparam name="output">
       <dsp:getvalueof id="a11" param="product.template.url" idtype="java.lang.String">
         <dsp:a href="<%=a11%>">
            <dsp:param name="prod_id" param="product.repositoryId"/>
            <dsp:valueof param="product.displayName"/>
         </dsp:a>
       </dsp:getvalueof>
    </dsp:oparam>
  </dsp:droplet>
 
If the mapping for the provided key is found that repository will be used, otherwise the system will fall back to the default repository and search for the item.

If the item cannot be found in the repository searched (e.g. the french product catalog), then the droplet will once again fall back to the default repository and attempt to find the item using the same id. Obviously this is only useful if the items have the exact same id in each repository.

In this example if you are french and attempt to look at product 1234, and product 1234 is defined in the french product catalog you will see that item. However if 1234 is not defined then you will see the default english version of 1234.

This behavior can be modified with use of the useDefaultRepository and getDefaultItem properties. If useDefaultRepository is false and an alternate repository cannot be found, then no repository is searched and empty is serviced. Like wise, if an alternative repository is selected, but the item cannot be found, and if getDefaultItem is false, then the default repository will not be searched and empty will be serviced.

The required input paramters for this servlet are:

id
The id of the item to lookup
The following parameters are optional:
repositoryKey
If specified this parameter will be used as a key to map to a secondary set of repositories.
elementName
This parameter can be used to change the default name of the element which is bound into the scope of the output oparam.
repository
The repository within which to look for the item. It is recommended to not use this parameter and to define different instances of the ItemLookupDroplet for each set of repositories you wish to use.
itemDescriptor
The name of the Item Descriptor to use to load the item. It is recommended to not use this parameter and to setup the item descriptor through property configuration.

The following parameters are rendered:

output
Rendered if the item was found in the repository
empty
Rendered in all other cases, e.g. item not found, user did not specify a required parameter.

The output parameters for this servlet are:

element
Set to the RepositoryItem corresponding to the id supplied
error
Any exception that may have occured while looking up the item


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
ItemLookupDroplet()
           
 
Method Summary
protected  void commitTransaction(javax.transaction.Transaction pTransaction)
          Commits the supplied transaction
protected  javax.transaction.Transaction ensureTransaction()
          This method ensures that a transaction exists before returning.
 ServiceMap getAlternateRepositories()
          Returns property AlternateRepositories
 java.lang.String getItemDescriptor()
          Returns property ItemDescriptor
 Repository getRepository()
          Returns property Repository
 javax.transaction.TransactionManager getTransactionManager()
          Returns property TransactionManager.
 boolean isEnsureTransaction()
          Returns property EnsureTransaction
 boolean isGetDefaultItem()
          Returns property GetDefaultItem
 boolean isUseDefaultRepository()
          Returns property UseDefaultRepository
 boolean isUseParams()
          Returns property UseParams
 void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Look for the RepositoryItem and if found render the output oparam by binding the item as a parameter.
 void setAlternateRepositories(ServiceMap pAlternateRepositories)
          Sets property AlternateRepositories
 void setEnsureTransaction(boolean pEnsureTransaction)
          Sets property EnsureTransaction
 void setGetDefaultItem(boolean pGetDefaultItem)
          Sets property GetDefaultItem
 void setItemDescriptor(java.lang.String pItemDescriptor)
          Sets property ItemDescriptor
 void setRepository(Repository pRepository)
          Sets property Repository
 void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)
          Sets property TransactionManager
 void setUseDefaultRepository(boolean pUseDefaultRepository)
          Sets property UseDefaultRepository
 void setUseParams(boolean pUseParams)
          Sets property UseParams
 
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
Class version string

Constructor Detail

ItemLookupDroplet

public ItemLookupDroplet()
Method Detail

setRepository

public void setRepository(Repository pRepository)
Sets property Repository


getRepository

public Repository getRepository()
Returns property Repository


setItemDescriptor

public void setItemDescriptor(java.lang.String pItemDescriptor)
Sets property ItemDescriptor


getItemDescriptor

public java.lang.String getItemDescriptor()
Returns property ItemDescriptor


setAlternateRepositories

public void setAlternateRepositories(ServiceMap pAlternateRepositories)
Sets property AlternateRepositories


getAlternateRepositories

public ServiceMap getAlternateRepositories()
Returns property AlternateRepositories


setTransactionManager

public void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)
Sets property TransactionManager


getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Returns property TransactionManager. If the internal transaction manager reference is null, it will be retrieved from the Repository if possible


setEnsureTransaction

public void setEnsureTransaction(boolean pEnsureTransaction)
Sets property EnsureTransaction


isEnsureTransaction

public boolean isEnsureTransaction()
Returns property EnsureTransaction


setUseParams

public void setUseParams(boolean pUseParams)
Sets property UseParams


isUseParams

public boolean isUseParams()
Returns property UseParams


setUseDefaultRepository

public void setUseDefaultRepository(boolean pUseDefaultRepository)
Sets property UseDefaultRepository


isUseDefaultRepository

public boolean isUseDefaultRepository()
Returns property UseDefaultRepository


setGetDefaultItem

public void setGetDefaultItem(boolean pGetDefaultItem)
Sets property GetDefaultItem


isGetDefaultItem

public boolean isGetDefaultItem()
Returns property GetDefaultItem


ensureTransaction

protected javax.transaction.Transaction ensureTransaction()
This method ensures that a transaction exists before returning. If there is no transaction, a new one is started and returned. In this case, you must call commitTransaction when the transaction completes.


commitTransaction

protected void commitTransaction(javax.transaction.Transaction pTransaction)
Commits the supplied transaction


service

public void service(DynamoHttpServletRequest pRequest,
                    DynamoHttpServletResponse pResponse)
             throws javax.servlet.ServletException,
                    java.io.IOException
Look for the RepositoryItem and if found render the output oparam by binding the item as a parameter. If no item can be found render the empty oparam.

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.