atg.search.formhandlers
Class BaseSearchFormHandler

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.droplet.EmptyFormHandler
              extended by atg.droplet.GenericFormHandler
                  extended by atg.search.formhandlers.BaseSearchFormHandler
All Implemented Interfaces:
DropletFormHandler, atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
CategorizeFormHandler, PagedRequestFormHandler, TypeAheadFormHandler, ViewDocumentFormHandler

public abstract class BaseSearchFormHandler
extends GenericFormHandler

This class provides the generic functionality for executing queries against the search server and retrieving results. Subclasses implement request-specific functionality.


Field Summary
static java.lang.String CLASS_VERSION
           
 
Fields inherited from class atg.droplet.GenericFormHandler
PARAM_DEFER_FORWARD_OR_REDIRECT, PARAM_USE_FORWARDS
 
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
BaseSearchFormHandler()
           
 
Method Summary
protected  SearchResponse afterSearch(SearchRequest pRequest, SearchResponse pResults, atg.search.client.SearchSession pSession)
          This method is called just after a search has been executed and is intended to allow subclasses an opportunity to update the search session or modify the search results object.
protected  SearchRequest beforeSearch(SearchRequest pRequest, atg.search.client.SearchSession pSession)
          This method is called just before a search is executed and is intended to allow subclasses an opportunity to make last minute changes to the request object or to update the search context.
 atg.search.client.SearchSession createSearchSession(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Create the SearchSession by first calling createSessionConfig() to obtain a configuration, then by calling ESSearchService.createSession()
protected  boolean doRedirect(DynamoHttpServletRequest pRequest, java.lang.String pUrl)
          Performs an actual redirection to another page for the given URL.
protected  boolean doRedirect(DynamoHttpServletRequest pRequest, java.lang.String pUrl, boolean pBypassUrlValidation)
          Performs an actual redirection to another page for the given URL.
 java.lang.String getClearFormURL()
          Get the optional URL to redirect to when handleClearQuery() is invoked
 java.util.Collection getEnvironmentTargets()
           
 java.lang.String getErrorURL()
          Get the optional url to redirect to when an error is encountered in handleSearch()
 java.util.Collection getLogicalPartitionNames()
           
 java.lang.String getRedirect()
           
 java.util.List<java.lang.String> getRedirects()
           
 java.lang.String getRequestFile()
           
 ResultsFetchingProxy getResultsFetcher()
          Get the results fetcher.
 atg.repository.search.testing.SearchAssetTools getSearchAssetTools()
           
 SearchClient getSearchClient()
          Get the SearchClient, the interface to the search service
 SearchContext getSearchContext()
          Get the session scoped search context
 boolean getSearchException()
           
 java.util.Vector getSearchExceptions()
           
 SearchRedirectProcessor[] getSearchRedirectProcessors()
           
 SearchRequest getSearchRequest()
           
 SearchRequestProcessor[] getSearchRequestProcessors()
           
 SearchResponse getSearchResponse()
           
 SearchResponseProcessor[] getSearchResponseProcessors()
           
 atg.search.client.SearchSession getSearchSession(java.lang.String pRequestChainToken)
          Return the search session from the search context or null if one does not yet exist.
 java.lang.String getSuccessURL()
          Get the optional url to redirect to on a successful search.
 java.util.Map getSuccessURLDynamicParams()
          An optional map of dynamic parameter data used to include search information in parameters in the success URL.
 RepositoryItem getUserProfile()
          Get the user profile repository item or null.
 boolean handleClearForm(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Handle clear form
 boolean handleConnect(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Connects to the specified search instance.
protected  boolean handleErrorCondition(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse, java.lang.Exception pException)
           
 boolean handleLoad(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Loads an existing request from an xml file.
 boolean handleLoadAndSearch(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Loads an existing request from an xml file and submits the request.
 boolean handleSearch(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Handle new search request.
 boolean isForceDeployedOnlyAssets()
          If set to true then the form handler will ensure that the version of assets used by the processors is the last deployed version.
 boolean isLoggingVerboseResponseXML()
          When true, the search response at all stages of the post-search request processing stages will be logged.
 boolean isPageRequest()
           
 boolean isRedirectEnabled()
          If set to true then the form handler will check the search results for a redirect URL and if found redirect to it.
 boolean isShowDetailedResults()
           
 boolean isShowXml()
           
protected  SearchResponse search(SearchRequest pSearchRequest, atg.search.client.SearchSession pSession)
          Override this to control how search is executed.
 void setClearFormURL(java.lang.String pClearFormURL)
          Set the optional URL to go to when handleClearQuery() is invoked.
 void setErrorURL(java.lang.String pErrorURL)
          Set the optional url to redirect to when an error is encountered in handleSearch()
 void setForceDeployedOnlyAssets(boolean pForceDeployedOnlyAssets)
          If set to true then the form handler will ensure that the version of assets used by the processors is the last deployed version.
 void setLoggingVerboseResponseXML(boolean pLogging)
          When true, the search response at all stages of the post-search request processing stages will be logged.
 void setPageRequest(boolean pPageRequest)
           
 void setRedirectEnabled(boolean pRedirectEnabled)
          If set to true then the form handler will check the search results for a redirect URL and if found redirect to it.
 void setRequestFile(java.lang.String requestFile)
           
 void setResultsFetcher(ResultsFetchingProxy pResultsFetcher)
          Set a results fetching proxy.
 void setSearchAssetTools(atg.repository.search.testing.SearchAssetTools pSearchAssetTools)
           
 void setSearchContext(SearchContext pSearchContext)
          Set the session scoped search context object
 void setSearchExceptions(java.util.Vector pSearchExceptions)
           
 void setSearchRedirectProcessors(SearchRedirectProcessor[] pSearchRedirectProcessors)
           
 void setSearchRequest(SearchRequest pRequest)
           
 void setSearchRequestProcessors(SearchRequestProcessor[] pSearchRequestProcessors)
           
 void setSearchResponse(SearchResponse pResponse)
           
 void setSearchResponseProcessors(SearchResponseProcessor[] pSearchResponseProcessors)
           
 void setShowDetailedResults(boolean pShowDetailedResults)
          Only used for excluding detailed results from rendered HTML.
 void setShowXml(boolean pShowXml)
          Used for excluding original request and response XML from rendered HTML.
 void setSuccessURL(java.lang.String pSuccessURL)
          Set the optional url to redirect to on a successful search (a search which throws no exceptions)
 void setSuccessURLDynamicParams(java.util.Map pParams)
          An optional map of dynamic parameter data used to include search information in parameters in the success URL.
 void setUserProfile(RepositoryItem pUserProfile)
          Set the user user profile for the user executing the search
protected abstract  SearchRequest stringToRequest(java.lang.String pString)
          Converts XML into a request object.
 
Methods inherited from class atg.droplet.GenericFormHandler
addFormException, addUncheckedFormException, afterSet, beforeSet, checkFormRedirect, createFormSubmissionMessage, getCancelURL, getCheckForValidSession, getFormError, getFormExceptions, getFormName, getMessagePort, getMessageSource, getMessageType, getPropertyExceptions, getSendMessages, getUncheckedFormExceptions, handleCancel, handleFormException, handleUncheckedFormException, hasUncheckedFormExceptions, isDeferForwardsAndRedirects, isRestorableForm, isUseForwards, isValidSession, redirectOrForward, resetFormExceptions, setCancelURL, setCheckForValidSession, setDeferForwardsAndRedirects, setFormName, setMessagePort, setMessageSource, setMessageType, setRestorableForm, setSendMessages, setUseForwards
 
Methods inherited from class atg.droplet.EmptyFormHandler
afterGet, beforeGet
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, 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, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, 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
Constructor Detail

BaseSearchFormHandler

public BaseSearchFormHandler()
Method Detail

getSuccessURLDynamicParams

public java.util.Map getSuccessURLDynamicParams()
An optional map of dynamic parameter data used to include search information in parameters in the success URL. This can used to capture data that is part of the search request or response which might otherwise require JavaScript in the page code.

The keys of this map are the URL parameter name strings. The values are the property names of the form handler, or sub-properties of the form handler, the values of which will be used as parameter values in the URL. The value may contain a comma-delimited list of property names. When this is the case, the URL will be constructed with multiple parameters of the same name, one for each value.

For example, the a map with the following associations:

Might produce the following success URL: "page.jsp?q=shoes&p=3"

Returns:
the success URL dynamic parameter map

setSuccessURLDynamicParams

public void setSuccessURLDynamicParams(java.util.Map pParams)
An optional map of dynamic parameter data used to include search information in parameters in the success URL. This can used to capture data that is part of the search request or response which might otherwise require JavaScript in the page code.

The keys of this map are the URL parameter name strings. The values are the property names of the form handler, or sub-properties of the form handler, the values of which will be used as parameter values in the URL. The value may contain a comma-delimited list of property names. When this is the case, the URL will be constructed with multiple parameters of the same name, one for each value.

Parameters:
pParams - the success URL dynamic parameter map

isLoggingVerboseResponseXML

public boolean isLoggingVerboseResponseXML()
When true, the search response at all stages of the post-search request processing stages will be logged. This means one log message for each of the following: the initial response, after calling afterSearch(), after invoking the response processors, after calling mapSearchSession(), and after calling the redirect processors.
If false, the default, the response is logged only after all of the stages mentioned above have completed.

Returns:
true if logging response processing verbosely

setLoggingVerboseResponseXML

public void setLoggingVerboseResponseXML(boolean pLogging)
When true, the search response at all stages of the post-search request processing stages will be logged. This means one log message for each of the following: the initial response, after calling afterSearch(), after invoking the response processors, after calling mapSearchSession(), and after calling the redirect processors.
If false, the default, the response is logged only after all of the stages mentioned above have completed.

Parameters:
pLogging - true to log response processing verbosely

isShowXml

public boolean isShowXml()
Returns:
whther XML will be shown in results

setShowXml

public void setShowXml(boolean pShowXml)
Used for excluding original request and response XML from rendered HTML. As a convenience, the request's keepingXml property is set to the same. If your page doesn't need this control, there is no need to set it.

Parameters:
pShowXml - true to enable XML display

isShowDetailedResults

public boolean isShowDetailedResults()
Returns:
whther detailed results will be shown in results

setShowDetailedResults

public void setShowDetailedResults(boolean pShowDetailedResults)
Only used for excluding detailed results from rendered HTML. If your page doesn't need this control, there is no need to set it.

Parameters:
pShowDetailedResults - true to enable detailed display

setPageRequest

public void setPageRequest(boolean pPageRequest)

isPageRequest

public boolean isPageRequest()

setSearchRequestProcessors

public void setSearchRequestProcessors(SearchRequestProcessor[] pSearchRequestProcessors)

getSearchRequestProcessors

public SearchRequestProcessor[] getSearchRequestProcessors()

setSearchResponseProcessors

public void setSearchResponseProcessors(SearchResponseProcessor[] pSearchResponseProcessors)

getSearchResponseProcessors

public SearchResponseProcessor[] getSearchResponseProcessors()

setSearchRedirectProcessors

public void setSearchRedirectProcessors(SearchRedirectProcessor[] pSearchRedirectProcessors)

getSearchRedirectProcessors

public SearchRedirectProcessor[] getSearchRedirectProcessors()

getSearchAssetTools

public atg.repository.search.testing.SearchAssetTools getSearchAssetTools()

setSearchAssetTools

public void setSearchAssetTools(atg.repository.search.testing.SearchAssetTools pSearchAssetTools)

isForceDeployedOnlyAssets

public boolean isForceDeployedOnlyAssets()
If set to true then the form handler will ensure that the version of assets used by the processors is the last deployed version. This is used by the search testing feature in the Merch UI. By default for production this boolean will be false since there is no need on production to force the asset version.

Returns:
boolean true to force the asset version to the last deployed version.

setForceDeployedOnlyAssets

public void setForceDeployedOnlyAssets(boolean pForceDeployedOnlyAssets)
If set to true then the form handler will ensure that the version of assets used by the processors is the last deployed version. This is used by the search testing feature in the Merch UI. By default for production this boolean will be false since there is no need on production to force the asset version.

Parameters:
pForceDeployedOnlyAssets - boolean true to force the asset version to the last deployed version.

isRedirectEnabled

public boolean isRedirectEnabled()
If set to true then the form handler will check the search results for a redirect URL and if found redirect to it. This takes precedence over any successURL specified.

Returns:
boolean true to use redirect URL in search results

setRedirectEnabled

public void setRedirectEnabled(boolean pRedirectEnabled)
If set to true then the form handler will check the search results for a redirect URL and if found redirect to it. This takes precedence over any successURL specified.


getRedirect

public java.lang.String getRedirect()
Returns:
get first redirect url

getRedirects

public java.util.List<java.lang.String> getRedirects()
Returns:
a list of all potential redirects for the given query, in the order they would have been selected.

setResultsFetcher

public void setResultsFetcher(ResultsFetchingProxy pResultsFetcher)
Set a results fetching proxy. If set, this object will be invoked to fetch the search results instead of the form handler.

Parameters:
pResultsFetcher - the results fetcher proxy
See Also:
atg.search.query.formhandlers.ResultsFetchingProxy, atg.search.query.formhandlers.CollectionFilterFetchingProxy

getResultsFetcher

public ResultsFetchingProxy getResultsFetcher()
Get the results fetcher. If set, this object will be invoked to fetch the search results.

Returns:
the custom results fetcher
See Also:
atg.search.query.formhandlers.ResultsFetchingProxy, atg.search.query.formhandlers.CollectionFilterFetchingProxy

getSearchRequest

public SearchRequest getSearchRequest()
Returns:
the search request

getEnvironmentTargets

public java.util.Collection getEnvironmentTargets()
Returns:
Collection of SearchEnvironmentTargets

getLogicalPartitionNames

public java.util.Collection getLogicalPartitionNames()

setClearFormURL

public void setClearFormURL(java.lang.String pClearFormURL)
Set the optional URL to go to when handleClearQuery() is invoked.

Parameters:
pClearFormURL - the url or null

getClearFormURL

public java.lang.String getClearFormURL()
Get the optional URL to redirect to when handleClearQuery() is invoked

Returns:
the url or null

setErrorURL

public void setErrorURL(java.lang.String pErrorURL)
Set the optional url to redirect to when an error is encountered in handleSearch()

Parameters:
pErrorURL - the url or null

getErrorURL

public java.lang.String getErrorURL()
Get the optional url to redirect to when an error is encountered in handleSearch()

Returns:
the url or null

setSuccessURL

public void setSuccessURL(java.lang.String pSuccessURL)
Set the optional url to redirect to on a successful search (a search which throws no exceptions)

Parameters:
pSuccessURL - the success url or nul

getSuccessURL

public java.lang.String getSuccessURL()
Get the optional url to redirect to on a successful search. A successful search is one that throws no exceptions.

Returns:
the success url or null if not set

setSearchContext

public void setSearchContext(SearchContext pSearchContext)
Set the session scoped search context object

Parameters:
pSearchContext - the search context

getSearchContext

public SearchContext getSearchContext()
Get the session scoped search context

Returns:
the search context

getSearchSession

public atg.search.client.SearchSession getSearchSession(java.lang.String pRequestChainToken)
Return the search session from the search context or null if one does not yet exist.

Parameters:
pRequestChainToken -
Returns:
the search session or null

createSearchSession

public atg.search.client.SearchSession createSearchSession(DynamoHttpServletRequest pRequest,
                                                           DynamoHttpServletResponse pResponse)
Create the SearchSession by first calling createSessionConfig() to obtain a configuration, then by calling ESSearchService.createSession()

Parameters:
pRequest - the Dynamo http request
pResponse - the Dynamo http response
Returns:
the session or null on error

getSearchClient

public SearchClient getSearchClient()
                             throws atg.search.client.SearchClientException
Get the SearchClient, the interface to the search service

Returns:
the search service, never null
Throws:
atg.search.client.SearchClientException - if unable to retrieve the SearchClient

setUserProfile

public void setUserProfile(RepositoryItem pUserProfile)
Set the user user profile for the user executing the search

Parameters:
pUserProfile - the user profile repository item or null

getUserProfile

public RepositoryItem getUserProfile()
Get the user profile repository item or null.

Returns:
the user profile repository item or null

setSearchResponse

public void setSearchResponse(SearchResponse pResponse)
Parameters:
pResponse - the search response

getSearchResponse

public SearchResponse getSearchResponse()
Returns:
the search response, available after a search

getRequestFile

public java.lang.String getRequestFile()
Returns:
location of request xml file

setRequestFile

public void setRequestFile(java.lang.String requestFile)
Parameters:
requestFile - path to xml request file

stringToRequest

protected abstract SearchRequest stringToRequest(java.lang.String pString)
Converts XML into a request object. Useful for "Load old request from file" feature.

Parameters:
pString - XML request string
Returns:
request object of the appropriate type

handleLoad

public boolean handleLoad(DynamoHttpServletRequest pRequest,
                          DynamoHttpServletResponse pResponse)
                   throws java.io.IOException,
                          javax.servlet.ServletException
Loads an existing request from an xml file. You must be using the correct form handler for the request xml.

Parameters:
pRequest - the dynamo request
pResponse - the dynamo response
Returns:
true to continue processing, false otherwise
Throws:
javax.servlet.ServletException
java.io.IOException

handleLoadAndSearch

public boolean handleLoadAndSearch(DynamoHttpServletRequest pRequest,
                                   DynamoHttpServletResponse pResponse)
                            throws java.io.IOException,
                                   javax.servlet.ServletException
Loads an existing request from an xml file and submits the request. You must be using the correct form handler for the request xml.

Parameters:
pRequest - the dynamo request
pResponse - the dynamo response
Returns:
true to continue processing, false otherwise
Throws:
javax.servlet.ServletException
java.io.IOException

handleConnect

public boolean handleConnect(DynamoHttpServletRequest pRequest,
                             DynamoHttpServletResponse pResponse)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Connects to the specified search instance.

Parameters:
pRequest -
pResponse -
Returns:
true to continue processing, false otherwise
Throws:
java.io.IOException
javax.servlet.ServletException

handleSearch

public boolean handleSearch(DynamoHttpServletRequest pRequest,
                            DynamoHttpServletResponse pResponse)
                     throws java.io.IOException,
                            javax.servlet.ServletException
Handle new search request.

Parameters:
pRequest - the dynamo request
pResponse - the dynamo response
Returns:
true to continue processing, false otherwise
Throws:
javax.servlet.ServletException
java.io.IOException

handleClearForm

public boolean handleClearForm(DynamoHttpServletRequest pRequest,
                               DynamoHttpServletResponse pResponse)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Handle clear form

Parameters:
pRequest - the dynamo request
pResponse - the dynamo response
Throws:
javax.servlet.ServletException
java.io.IOException
See Also:
setClearFormURL(String)

doRedirect

protected boolean doRedirect(DynamoHttpServletRequest pRequest,
                             java.lang.String pUrl)
                      throws java.io.IOException
Performs an actual redirection to another page for the given URL.

Parameters:
pRequest - The current DynamoHttpServletRequest
pUrl - The String URL to redirect to
Returns:
true if redirect happened
Throws:
java.io.IOException

doRedirect

protected boolean doRedirect(DynamoHttpServletRequest pRequest,
                             java.lang.String pUrl,
                             boolean pBypassUrlValidation)
                      throws java.io.IOException
Performs an actual redirection to another page for the given URL.

Parameters:
pRequest - The current DynamoHttpServletRequest
pUrl - The String URL to redirect to
pBypassUrlValidation - Can we bypass URL validation?
Returns:
true if redirect happened
Throws:
java.io.IOException

search

protected SearchResponse search(SearchRequest pSearchRequest,
                                atg.search.client.SearchSession pSession)
                         throws atg.search.client.SearchClientException
Override this to control how search is executed.

Parameters:
pSearchRequest - the request
pSession - the session
Returns:
a search response
Throws:
atg.search.client.SearchClientException - if something fails

handleErrorCondition

protected boolean handleErrorCondition(DynamoHttpServletRequest pRequest,
                                       DynamoHttpServletResponse pResponse,
                                       java.lang.Exception pException)
                                throws java.io.IOException,
                                       javax.servlet.ServletException
Returns:
true to stay on page
Throws:
java.io.IOException
javax.servlet.ServletException

getSearchException

public boolean getSearchException()

getSearchExceptions

public java.util.Vector getSearchExceptions()

setSearchExceptions

public void setSearchExceptions(java.util.Vector pSearchExceptions)

setSearchRequest

public void setSearchRequest(SearchRequest pRequest)

beforeSearch

protected SearchRequest beforeSearch(SearchRequest pRequest,
                                     atg.search.client.SearchSession pSession)
This method is called just before a search is executed and is intended to allow subclasses an opportunity to make last minute changes to the request object or to update the search context.

Subclasses may abort the search by returning a null client request. This default implementation returns the unmodified request object.

Parameters:
pRequest - the client query request
pSession - the search session
Returns:
the client request or null to abort the search request

afterSearch

protected SearchResponse afterSearch(SearchRequest pRequest,
                                     SearchResponse pResults,
                                     atg.search.client.SearchSession pSession)
This method is called just after a search has been executed and is intended to allow subclasses an opportunity to update the search session or modify the search results object.

This default implementation returns the result object unmodified.

Parameters:
pRequest - the client query request
pResults - the search results
pSession - the search session
Returns:
the potentially modified search results