com.veriplace.web.views
Class AbstractStatusViewRenderer

java.lang.Object
  extended by com.veriplace.web.views.AbstractStatusViewRenderer
All Implemented Interfaces:
StatusViewRenderer
Direct Known Subclasses:
ServletStatusViewRenderer, SpringStatusViewRenderer

public abstract class AbstractStatusViewRenderer
extends java.lang.Object
implements StatusViewRenderer

Basic implementation of StatusViewRenderer which defines a view name for each error condition and for the "please wait" page, and automatically stores the VeriplaceState object and callback URL in request attributes. How to display a page is left up to subclasses.

Since:
2.0

Field Summary
protected  java.lang.String callbackAttributeName
           
static java.lang.String DEFAULT_ERROR_KEY
           
static java.lang.String ERROR_KEY_PREFIX
           
protected  java.lang.String stateAttributeName
           
static java.lang.String WAITING_KEY
           
 
Constructor Summary
AbstractStatusViewRenderer()
           
 
Method Summary
 boolean canRenderWaitingView()
          Returns true if this StatusViewRenderer is able to display content for the "please wait" condition.
 java.lang.String getCallbackAttributeName()
          See setCallbackAttributeName(String).
 java.lang.String getDefaultErrorViewName()
          See setDefaultErrorViewName(String).
 java.lang.String getErrorViewName(java.lang.Class<?> exceptionClass)
          Returns the name of the error view to use for a particular exception class, as defined by setErrorViewName(Class, String).
 java.lang.String getStateAttributeName()
          See setStateAttributeName(String).
 java.util.Map<java.lang.String,java.lang.String> getViewMap()
          See setViewMap(Map).
 java.lang.String getWaitingViewName()
          See setWaitingViewName(String).
protected  java.lang.Class<?> matchExceptionClass(java.lang.String name)
           
 boolean renderErrorView(HttpServletRequest request, HttpServletResponse response, VeriplaceState state, java.lang.Exception exception)
          Displays an appropriate error response for a given exception.
protected abstract  boolean renderViewInternal(HttpServletRequest request, HttpServletResponse response, VeriplaceState state, java.lang.String viewName)
          Override this method to implement displaying a page based on a view name.
 boolean renderWaitingView(HttpServletRequest request, HttpServletResponse response, VeriplaceState state, java.lang.String callbackUrl)
          Displays appropriate content for the "please wait" condition.
 void setCallbackAttributeName(java.lang.String callbackAttributeName)
          Specifies that when the framework is displaying a "please wait" view, or any view that includes an automatic redirect, the redirect URL should be stored as a request attribute (or model object, if you are using Spring) with the given name.
 void setDefaultErrorViewName(java.lang.String defaultErrorViewName)
          Specifies the name of the view to use for error conditions that were not otherwise specified with setErrorViewName(Class, String).
 void setErrorViewName(java.lang.Class<?> exceptionClass, java.lang.String viewName)
          Specifies the name of the view to use for error conditions that are thrown as the specified exception class.
 void setStateAttributeName(java.lang.String stateAttributeName)
          Specifies that the framework should always store a reference to the current VeriplaceState using the given attribute name.
 void setViewMap(java.util.Map<java.lang.String,java.lang.String> viewMap)
          Specifies the views to display for various conditions, using a list of name-value pairs.
 void setWaitingViewName(java.lang.String waitingViewName)
          Specifies the name of the view to use for the "please wait" condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WAITING_KEY

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

DEFAULT_ERROR_KEY

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

ERROR_KEY_PREFIX

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

callbackAttributeName

protected java.lang.String callbackAttributeName

stateAttributeName

protected java.lang.String stateAttributeName
Constructor Detail

AbstractStatusViewRenderer

public AbstractStatusViewRenderer()
Method Detail

getViewMap

public java.util.Map<java.lang.String,java.lang.String> getViewMap()
See setViewMap(Map).


setViewMap

public void setViewMap(java.util.Map<java.lang.String,java.lang.String> viewMap)
Specifies the views to display for various conditions, using a list of name-value pairs. The string keys used to identify the views are as follows:

Throws:
java.lang.IllegalArgumentException - if the key of an entry does not match one of the rules described above

matchExceptionClass

protected java.lang.Class<?> matchExceptionClass(java.lang.String name)

getWaitingViewName

public java.lang.String getWaitingViewName()
See setWaitingViewName(String).


setWaitingViewName

public void setWaitingViewName(java.lang.String waitingViewName)
Specifies the name of the view to use for the "please wait" condition. This view should contain an automatic refresh to whatever URL is specified in StatusViewRenderer.renderWaitingView(HttpServletRequest, HttpServletResponse, VeriplaceState, String). See WaitingException.


getDefaultErrorViewName

public java.lang.String getDefaultErrorViewName()
See setDefaultErrorViewName(String).


setDefaultErrorViewName

public void setDefaultErrorViewName(java.lang.String defaultErrorViewName)
Specifies the name of the view to use for error conditions that were not otherwise specified with setErrorViewName(Class, String).


setErrorViewName

public void setErrorViewName(java.lang.Class<?> exceptionClass,
                             java.lang.String viewName)
Specifies the name of the view to use for error conditions that are thrown as the specified exception class.

This includes any exception subclasses derived from that class, if they are not covered by a more specific setErrorViewName rule. For instance, given the following configuration--

    statusViewRenderer.setErrorViewName(UserDiscoveryException.class, "userFailed");
    statusViewRenderer.setErrorViewName(UserDiscoveryNotPermittedException.class, "badPermission");
 

--a UserDiscoveryNotPermittedException will be handled with the view "badPermission", but a UserNotFoundException (which is derived from UserDiscoveryException) will be handled with the view "userFailed".


getErrorViewName

public java.lang.String getErrorViewName(java.lang.Class<?> exceptionClass)
Returns the name of the error view to use for a particular exception class, as defined by setErrorViewName(Class, String).


getCallbackAttributeName

public java.lang.String getCallbackAttributeName()
See setCallbackAttributeName(String).


setCallbackAttributeName

public void setCallbackAttributeName(java.lang.String callbackAttributeName)
Specifies that when the framework is displaying a "please wait" view, or any view that includes an automatic redirect, the redirect URL should be stored as a request attribute (or model object, if you are using Spring) with the given name.

Parameters:
callbackAttributeName -

getStateAttributeName

public java.lang.String getStateAttributeName()
See setStateAttributeName(String).


setStateAttributeName

public void setStateAttributeName(java.lang.String stateAttributeName)
Specifies that the framework should always store a reference to the current VeriplaceState using the given attribute name. It will be stored as an attribute on the current HttpServletRequest, and if you are using the Spring framework, it will also be available as a model object with the same name.


canRenderWaitingView

public boolean canRenderWaitingView()
Description copied from interface: StatusViewRenderer
Returns true if this StatusViewRenderer is able to display content for the "please wait" condition. If it returns false, StatusViewRenderer.renderWaitingView(HttpServletRequest, HttpServletResponse, VeriplaceState, String) will never be called.

Specified by:
canRenderWaitingView in interface StatusViewRenderer

renderWaitingView

public boolean renderWaitingView(HttpServletRequest request,
                                 HttpServletResponse response,
                                 VeriplaceState state,
                                 java.lang.String callbackUrl)
                          throws StatusViewException,
                                 ServletException
Description copied from interface: StatusViewRenderer
Displays appropriate content for the "please wait" condition.

Specified by:
renderWaitingView in interface StatusViewRenderer
callbackUrl - the URL to use for an automatic refresh
Throws:
StatusViewException - if there was an error in rendering the view
ServletException

renderErrorView

public boolean renderErrorView(HttpServletRequest request,
                               HttpServletResponse response,
                               VeriplaceState state,
                               java.lang.Exception exception)
                        throws StatusViewException,
                               ServletException
Description copied from interface: StatusViewRenderer
Displays an appropriate error response for a given exception.

Specified by:
renderErrorView in interface StatusViewRenderer
Throws:
StatusViewException - if there was an error in rendering the view
ServletException

renderViewInternal

protected abstract boolean renderViewInternal(HttpServletRequest request,
                                              HttpServletResponse response,
                                              VeriplaceState state,
                                              java.lang.String viewName)
                                       throws StatusViewException,
                                              ServletException
Override this method to implement displaying a page based on a view name. Standard implementations of this for generic servlets and Spring are provided by ServletStatusViewRenderer and SpringStatusViewRenderer.

Parameters:
request - the current HttpServletRequest
response - the current HttpServletResponse
state - the current VeriplaceState
viewName - name of the view to display
Throws:
StatusViewException - for any error that prevents the page from being displayed
ServletException