com.taggercat.handlers
Class AbstractRequestHandler

java.lang.Object
  extended by com.taggercat.handlers.AbstractRequestHandler
All Implemented Interfaces:
com.taggercat.el.ELPropertyResolver, RequestHandler
Direct Known Subclasses:
AbstractURIHandler, AbstractURIPatternHandler, ChangeUserSetting, CloseDataSourcesRequestHandler, DataSourceNavigationRequestHandler, DataSourceQBFRequestHandler, DataSourceSortRequestHandler, DuplicateRowRequestHandler, ExecuteMethodRequestHandler, FieldValidationRequestHandler, InsertRequestHandler, LoginRequestHandler, LogoutRequestHandler, ModelActionRequestHandler, MultiActionNameRequestHandler, NoActionNameRequestHandler, NoOPRequestHandler, PageNavigationRequestHandler, ReloadMetaDataRequestHandler, TestExpressionHandler

public abstract class AbstractRequestHandler
extends java.lang.Object
implements RequestHandler, com.taggercat.el.ELPropertyResolver

AbstractRequestHandler is an abstract implementation of the RequestHandler interface.

It provides the basic services that most request handlers are expected to provide, such as:

Additionally, this class provides important life cycle management for request processing.

 

Constructor Summary
AbstractRequestHandler()
           
 
Method Summary
static void disableClientCache(javax.servlet.http.HttpServletResponse response)
          Disables browser caching by setting the magic response header values
 java.lang.String getDataSourceName()
          Gets the dsName parameter or attribute from the request object.
 java.lang.Exception getErrorException()
           
 java.lang.String getErrorPage()
           
 ResponseMethod getErrorPageMethod()
           
 java.lang.String getErrorReason()
           
 java.lang.String getExplicitDataSourceName()
           
 java.lang.String getExplicitDSN()
          Returns the explicit data source name, or null is the explicit DSN has not been set.
 java.util.regex.Pattern getMatchedPattern()
           
 Model getModel()
          Gets the Model from the HttpSession.
 RequestController getRequestController()
           
 java.lang.String getResponsePage()
           
 ResponseMethod getResponsePageMethod()
           
 java.lang.String getSessionExpiredPage()
           
 java.lang.String getUserName4Log()
          Gets the current application user name, if logged in.
 void init(RequestController requestController)
          Called by RequestController to initialize this RequestHandler.
static boolean isAjaxRequest(javax.servlet.http.HttpServletRequest request)
          Returns true if the request is being made from a TC or jQuery Ajax call
 void onChainCompleted(RequestHandler lastRequestHandler, boolean success)
          This method is called on each request handler in the request handler chain after the last request handler has been called.
 java.lang.Object resolveProperty(java.lang.String name, com.taggercat.el.ELContext elContext)
          This is the call back method registered with the expression evaluator.
 void serverTemporaryFile(java.io.File tempFile)
          Sends a file to the output stream.
 void serveTemporaryFile(java.io.File tempFile, java.lang.String contentType, boolean asAttachment)
          Sends a file to the output stream.
 boolean service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, RequestHandlerChain requestChain)
          Called by RequestController to service a single request.
 void setActionName(java.lang.String name)
          Sets the value of the request name associated with this handler.
 void setErrorPage(java.lang.String errorPage)
           
 void setErrorPageMethod(ResponseMethod errorPageMethod)
           
 void setErrorPageMethodToRedirect()
           
 void setExplicitDataSourceName(java.lang.String explicitDataSourceName)
           
 void setExplicitDSN(java.lang.String dsn)
          Sets the explicit data source name.
 void setMatchedPattern(java.util.regex.Pattern matchedPattern)
           
 void setResponsePage(java.lang.String responsePage)
           
 void setResponsePageMethod(ResponseMethod responsePageMethod)
           
 void setResponsePageMethodToRedirect()
           
 void setSessionExpiredPage(java.lang.String sessionExpiredPage)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRequestHandler

public AbstractRequestHandler()
Method Detail

getDataSourceName

public java.lang.String getDataSourceName()
Gets the dsName parameter or attribute from the request object. If the data source name has been explicitly set for the current action, then that data source name is returned.

Returns:
the data source name for this request handler

onChainCompleted

public void onChainCompleted(RequestHandler lastRequestHandler,
                             boolean success)
This method is called on each request handler in the request handler chain after the last request handler has been called. The default implementation does nothing. Override this method in subclasses to add specific functionality.

Specified by:
onChainCompleted in interface RequestHandler
Parameters:
lastRequestHandler - the request handler where chain processing completed
success - true if the last request handler has completed successfully

disableClientCache

public static void disableClientCache(javax.servlet.http.HttpServletResponse response)
Disables browser caching by setting the magic response header values


isAjaxRequest

public static boolean isAjaxRequest(javax.servlet.http.HttpServletRequest request)
Returns true if the request is being made from a TC or jQuery Ajax call

Returns:
true if the request is being made from a TC or jQuery Ajax call

serveTemporaryFile

public void serveTemporaryFile(java.io.File tempFile,
                               java.lang.String contentType,
                               boolean asAttachment)
                        throws java.io.IOException
Sends a file to the output stream. This method is intended to serve temporary files.

After sending, that file will be deleted from the file system.

The requestHandler chain will also be marked as completed. You should NOT being using this method to serve regular static resources.

Throws:
java.io.IOException
java.net.MalformedURLException
Parameters:
tempFile -
contentType - the content type

serverTemporaryFile

public void serverTemporaryFile(java.io.File tempFile)
                         throws java.io.IOException
Sends a file to the output stream. This method is intended to serve temporary files.

After sending, that file will be deleted from the file system.

The requestHandler chain will also be marked as completed. You should NOT being using this methods to server regular static resources.

Throws:
java.io.IOException
Parameters:
tempFile - the file to serve

getModel

public Model getModel()
Gets the Model from the HttpSession.

Returns:
The Model previously set as an attribute of the HttpSession, or null if the session or attribute are not present.

getUserName4Log

public java.lang.String getUserName4Log()
Gets the current application user name, if logged in. This method is typically called by the logging methods.

Returns:
the current user name, if not logged in then returns an "Unknown".

setActionName

public void setActionName(java.lang.String name)
Sets the value of the request name associated with this handler.

Specified by:
setActionName in interface RequestHandler
Parameters:
name - the name of the request

init

public void init(RequestController requestController)
Called by RequestController to initialize this RequestHandler. You can provide your own setup code in this method. The corresponding method at the end of the request processing is AbstractRequestHandler.destroy().

Specified by:
init in interface RequestHandler
Parameters:
requestController - RequestController instance.

service

public final boolean service(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             RequestHandlerChain requestChain)
                      throws java.lang.Exception
Called by RequestController to service a single request. If this request handler is in a chain, then the follow on request handler will be called after this instance's handleRequest method is called.

Specified by:
service in interface RequestHandler
Throws:
java.lang.Exception - Generally the underlying exception thrown for varied reasons during the servicing of a request.
Parameters:
request - current HttpServletRequest instance
response - current HttpServletResponse instance
requestChain - the chain of request handlers being processed
Returns:
true if the request was serviced without error

setExplicitDSN

public void setExplicitDSN(java.lang.String dsn)
Sets the explicit data source name. Setting the data source name explicitly, overrides the data source name that is usually set with a request parameter. The explicit override is typically used by requests actions that explicitly set their target data source.

For, example, update(account).save(customers).

Specified by:
setExplicitDSN in interface RequestHandler
Parameters:
dsn - the data source name

getExplicitDSN

public java.lang.String getExplicitDSN()
Returns the explicit data source name, or null is the explicit DSN has not been set.

Specified by:
getExplicitDSN in interface RequestHandler
Returns:
explicit data source name

resolveProperty

public java.lang.Object resolveProperty(java.lang.String name,
                                        com.taggercat.el.ELContext elContext)
                                 throws java.lang.IllegalArgumentException
This is the call back method registered with the expression evaluator. The evaluator calls this method for all terms of the expression that have a dot delimited name.
The dot delimited name is assumed to be of the form dsn.field or that of a scope prefixed variable.
Where the prefix name is one of:
Examples:

 customer.Name request.orderDate session.user page.isValid

 
The attribute on the scope variables may have been added with the TCSet, TCOut etc. tags or with any other means.

Specified by:
resolveProperty in interface com.taggercat.el.ELPropertyResolver
Throws:
java.lang.IllegalArgumentException
Parameters:
name - the dot delimited name of the term to resolve, eg, customer.Name
elContext - the context values
Returns:
the object representing the named value

getResponsePage

public java.lang.String getResponsePage()

setResponsePage

public void setResponsePage(java.lang.String responsePage)

getErrorPage

public java.lang.String getErrorPage()

setErrorPage

public void setErrorPage(java.lang.String errorPage)

getErrorReason

public java.lang.String getErrorReason()

getSessionExpiredPage

public java.lang.String getSessionExpiredPage()

setSessionExpiredPage

public void setSessionExpiredPage(java.lang.String sessionExpiredPage)

getErrorPageMethod

public ResponseMethod getErrorPageMethod()

setErrorPageMethod

public void setErrorPageMethod(ResponseMethod errorPageMethod)

getErrorException

public java.lang.Exception getErrorException()

getExplicitDataSourceName

public java.lang.String getExplicitDataSourceName()

setExplicitDataSourceName

public void setExplicitDataSourceName(java.lang.String explicitDataSourceName)

getResponsePageMethod

public ResponseMethod getResponsePageMethod()

setResponsePageMethod

public void setResponsePageMethod(ResponseMethod responsePageMethod)

setResponsePageMethodToRedirect

public void setResponsePageMethodToRedirect()

setErrorPageMethodToRedirect

public void setErrorPageMethodToRedirect()

getRequestController

public RequestController getRequestController()

getMatchedPattern

public java.util.regex.Pattern getMatchedPattern()

setMatchedPattern

public void setMatchedPattern(java.util.regex.Pattern matchedPattern)