magoffin.matt.ma2.web.util
Class WebHelper

java.lang.Object
  extended by magoffin.matt.xweb.util.BasicXwebHelper
      extended by magoffin.matt.ma2.web.util.WebHelper
All Implemented Interfaces:
magoffin.matt.xweb.util.XwebHelper

public final class WebHelper
extends magoffin.matt.xweb.util.BasicXwebHelper

Utility methods for web layer.

The configurable properties of this class are:

userBiz
The UserBiz implementation to use.

Version:
$Revision: 43 $ $Date: 2007-10-21 11:10:01 +1300 (Sun, 21 Oct 2007) $
Author:
Matt Magoffin (spamsqr@msqr.us)

Constructor Summary
WebHelper()
           
 
Method Summary
 void clearSavedRequestURL(javax.servlet.http.HttpServletRequest request)
          Remove the saved session URL.
static void clearSaveRequestURLFlag(javax.servlet.http.HttpServletRequest request)
          Clear the flag indicating the saved session URL should not be cleared on this request.
 void clearUserSessionData(javax.servlet.http.HttpServletRequest request)
          Remove all user session data.
 JobInfo createJobInfo(BizContext context, java.lang.Long ticket)
          Create a JobInfo instance from a WorkInfo instance.
 BizContext getAdminBizContext(javax.servlet.http.HttpServletRequest request)
          Get an admin-level BizContext for the current request.
 BizContext getAnonymousBizContext(javax.servlet.http.HttpServletRequest request)
          Get a BizContext for the current request that can be an anonymous user even if anonymous features are disabled.
 BizContext getBizContext(javax.servlet.http.HttpServletRequest request, boolean userRequired)
          Get a BizContext for the current request.
 BizContext getBizContextWithViewSettings(javax.servlet.http.HttpServletRequest request)
          Get a BizContext for the current request, checking that a Session object exists on the HttpSession.
 java.lang.String getDatePattern()
           
 java.util.TimeZone getDateTimeZone()
           
 DomainObjectFactory getDomainObjectFactory()
           
 MediaBiz getMediaBiz()
           
 org.springframework.context.MessageSource getMessageSource()
           
 Theme getRequestTheme()
          Get the saved theme from the current request.
 SystemBiz getSystemBiz()
           
 UserBiz getUserBiz()
           
 Session getUserSession(javax.servlet.http.HttpServletRequest request)
          Get the Session from the current session.
 java.lang.Long[] getUserWorkTickets(javax.servlet.http.HttpServletRequest request)
          Get a list of work tickets for the current user.
 WorkBiz getWorkBiz()
           
static boolean isSaveRequestURL(javax.servlet.http.HttpServletRequest request)
          Return true if the save request URL flag is currently set.
 void populateMediaSizeAndQuality(java.util.List<MediaSizeDefinition> list)
          Add a MediaSizeDefinition for every MediaSize in the system.
 void populateModelWorkInfo(javax.servlet.http.HttpServletRequest request, WorkBiz.WorkInfo workInfo, java.util.Map<java.lang.String,java.lang.Object> model)
          Populate data from a WorkInfo instance onto a model Map.
 void saveAnonymousUserSession(javax.servlet.http.HttpServletRequest request, MediaSpec thumbnailSpec, MediaSpec viewSpec)
          Save an anonymous user session.
 void saveRequestTheme(Theme theme)
          Save a theme for the current request.
 void saveUserSession(javax.servlet.http.HttpServletRequest request, User user)
          Save the action user to session.
 void setDatePattern(java.lang.String datePattern)
           
 void setDateTimeZone(java.util.TimeZone dateTimeZone)
           
 void setDomainObjectFactory(DomainObjectFactory domainObjectFactory)
           
 void setMediaBiz(MediaBiz mediaBiz)
           
 void setMessageSource(org.springframework.context.MessageSource messageSource)
           
static void setSaveRequestURLFlag(javax.servlet.http.HttpServletRequest request)
          Set a flag indicating the saved session URL should not be cleared on this request.
 void setSystemBiz(SystemBiz systemBiz)
           
 void setUserBiz(UserBiz userBiz)
           
 void setWorkBiz(WorkBiz workBiz)
           
 
Methods inherited from class magoffin.matt.xweb.util.BasicXwebHelper
clearSavedMessage, getAppContextSupport, getSavedMessage, getSavedRequestURL, saveMessage, saveRequestURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebHelper

public WebHelper()
Method Detail

createJobInfo

public JobInfo createJobInfo(BizContext context,
                             java.lang.Long ticket)
Create a JobInfo instance from a WorkInfo instance.

Parameters:
context - the context
ticket - the requested ticket number
Returns:
JobInfo

saveRequestTheme

public void saveRequestTheme(Theme theme)
Save a theme for the current request.

Parameters:
theme - the theme to save for

getRequestTheme

public Theme getRequestTheme()
Get the saved theme from the current request.

Returns:
the Theme, or null if none saved

getBizContextWithViewSettings

public BizContext getBizContextWithViewSettings(javax.servlet.http.HttpServletRequest request)
Get a BizContext for the current request, checking that a Session object exists on the HttpSession.

Parameters:
request - the request
Returns:
BizContext
Throws:
NoUserSessionException - if no Session is available in the HttpSession

getBizContext

public BizContext getBizContext(javax.servlet.http.HttpServletRequest request,
                                boolean userRequired)
Get a BizContext for the current request.

If the userRequired parameter is true then an AuthorizationException will be thrown with a AuthorizationException.Reason.ANONYMOUS_ACCESS_DENIED if the current request is for an anonymous user.

Parameters:
request - the current request
userRequired - if true then a logged-in user must be on the current request, otherwise an AuthorizationException will be thrown
Returns:
the BizContext
Throws:
AuthorizationException - if userRequired is true and no user exists on the current request

getAdminBizContext

public BizContext getAdminBizContext(javax.servlet.http.HttpServletRequest request)
Get an admin-level BizContext for the current request.

If the current request is for an anonymous user, then an AuthorizationException will be thrown with a AuthorizationException.Reason.ANONYMOUS_ACCESS_DENIED reason. If the current request is for a logged in user that does not have admin priveleges, an AuthorizationException will be thrown with a AuthorizationException.Reason.ACCESS_DENIED reason.

Parameters:
request - the current request
Returns:
the BizContext

getAnonymousBizContext

public BizContext getAnonymousBizContext(javax.servlet.http.HttpServletRequest request)
Get a BizContext for the current request that can be an anonymous user even if anonymous features are disabled.

This can be used by actions that can be performed even if anonymous features are disabled, such as self registration.

Parameters:
request - the current request
Returns:
a BizContext

saveUserSession

public void saveUserSession(javax.servlet.http.HttpServletRequest request,
                            User user)
Save the action user to session.

This method will save the user instance to session, allowing the application to maintain a logged-in state for the user. The user is added to a Session instance as the actingUser property. If the user has the UserBiz.ACCESS_ADMIN permission bit set the admin property of the Session will be set to true.

Parameters:
request - the current request
user - the User to save in session

saveAnonymousUserSession

public void saveAnonymousUserSession(javax.servlet.http.HttpServletRequest request,
                                     MediaSpec thumbnailSpec,
                                     MediaSpec viewSpec)
Save an anonymous user session.

Parameters:
request - the request
thumbnailSpec - the MediaSpec to use for thumbnail items
viewSpec - the MediaSpec to use for full-size items

clearUserSessionData

public void clearUserSessionData(javax.servlet.http.HttpServletRequest request)
Remove all user session data.

This method simply invalidates the current session (if available).

Parameters:
request - the current reqeust

getUserSession

public Session getUserSession(javax.servlet.http.HttpServletRequest request)
Get the Session from the current session.

Parameters:
request - the current request
Returns:
the UiSessionData instance, or null if not available

setSaveRequestURLFlag

public static final void setSaveRequestURLFlag(javax.servlet.http.HttpServletRequest request)
Set a flag indicating the saved session URL should not be cleared on this request.

Parameters:
request - the current request

isSaveRequestURL

public static final boolean isSaveRequestURL(javax.servlet.http.HttpServletRequest request)
Return true if the save request URL flag is currently set.

Parameters:
request - the current request
Returns:
true if the save request URL flag is currently set

clearSaveRequestURLFlag

public static final void clearSaveRequestURLFlag(javax.servlet.http.HttpServletRequest request)
Clear the flag indicating the saved session URL should not be cleared on this request.

Parameters:
request - the current request

clearSavedRequestURL

public void clearSavedRequestURL(javax.servlet.http.HttpServletRequest request)
Remove the saved session URL.

Parameters:
request - the current request

getUserWorkTickets

public java.lang.Long[] getUserWorkTickets(javax.servlet.http.HttpServletRequest request)
Get a list of work tickets for the current user.

This method will only return tickets for jobs that the WorkBiz returns job information for. Tickets that do not have any job information associated with them will be pruned from the user's list of tickets and not returned.

Parameters:
request - the request
Returns:
list of tickets

populateModelWorkInfo

public void populateModelWorkInfo(javax.servlet.http.HttpServletRequest request,
                                  WorkBiz.WorkInfo workInfo,
                                  java.util.Map<java.lang.String,java.lang.Object> model)
Populate data from a WorkInfo instance onto a model Map.

Parameters:
request - the request, so can save the ticket into session
workInfo - the WorkInfo
model - the model Map

populateMediaSizeAndQuality

public void populateMediaSizeAndQuality(java.util.List<MediaSizeDefinition> list)
Add a MediaSizeDefinition for every MediaSize in the system.

Parameters:
list - the list to add MediaSizeDefinition objects to

getUserBiz

public UserBiz getUserBiz()
Returns:
Returns the userBiz.

setUserBiz

public void setUserBiz(UserBiz userBiz)
Parameters:
userBiz - The userBiz to set.

getDatePattern

public java.lang.String getDatePattern()
Returns:
the datePattern

setDatePattern

public void setDatePattern(java.lang.String datePattern)
Parameters:
datePattern - the datePattern to set

getDateTimeZone

public java.util.TimeZone getDateTimeZone()
Returns:
the dateTimeZone

setDateTimeZone

public void setDateTimeZone(java.util.TimeZone dateTimeZone)
Parameters:
dateTimeZone - the dateTimeZone to set

getDomainObjectFactory

public DomainObjectFactory getDomainObjectFactory()
Returns:
the domainObjectFactory

setDomainObjectFactory

public void setDomainObjectFactory(DomainObjectFactory domainObjectFactory)
Parameters:
domainObjectFactory - the domainObjectFactory to set

getWorkBiz

public WorkBiz getWorkBiz()
Returns:
the workBiz

setWorkBiz

public void setWorkBiz(WorkBiz workBiz)
Parameters:
workBiz - the workBiz to set

getMessageSource

public org.springframework.context.MessageSource getMessageSource()
Returns:
the messageSource

setMessageSource

public void setMessageSource(org.springframework.context.MessageSource messageSource)
Parameters:
messageSource - the messageSource to set

getSystemBiz

public SystemBiz getSystemBiz()
Returns:
the systemBiz

setSystemBiz

public void setSystemBiz(SystemBiz systemBiz)
Parameters:
systemBiz - the systemBiz to set

getMediaBiz

public MediaBiz getMediaBiz()
Returns:
the mediaBiz

setMediaBiz

public void setMediaBiz(MediaBiz mediaBiz)
Parameters:
mediaBiz - the mediaBiz to set