Class BaseAction
java.lang.Object
com.opensymphony.xwork2.ActionSupport
org.conical.common.bbl.web.struts.actions.BaseAction
- All Implemented Interfaces:
com.opensymphony.xwork2.Action
,com.opensymphony.xwork2.interceptor.ValidationAware
,com.opensymphony.xwork2.LocaleProvider
,com.opensymphony.xwork2.TextProvider
,com.opensymphony.xwork2.Validateable
,Serializable
,org.apache.struts2.interceptor.ServletRequestAware
,org.apache.struts2.interceptor.ServletResponseAware
- Direct Known Subclasses:
HelpAction
,LoginAction
,SampleAction
public abstract class BaseAction
extends com.opensymphony.xwork2.ActionSupport
implements org.apache.struts2.interceptor.ServletRequestAware, org.apache.struts2.interceptor.ServletResponseAware
This should be the base class for all actions in Struts2-based
BBL web apps. It takes care of a number of things:
- loads application/developer attributes from properties and exposing them
- PERMISSION_DENIED return value
- does user authentication, denying access if desired and allowing overrides for specific roles
- exposes access to the User object representing the current user
- exposes access to attributes needed by the standard BBL JSP header
- exposes access to common enums
- Author:
- rdoherty
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Encapsulates information about the contact developer for this application -
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Should be returned when permission to view a page or perform an action is deniedFields inherited from class com.opensymphony.xwork2.ActionSupport
container
Fields inherited from interface com.opensymphony.xwork2.Action
ERROR, INPUT, LOGIN, NONE, SUCCESS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
Returns whether this action should require a logged in uservoid
addCookie
(javax.servlet.http.Cookie cookie) Adds the passed cookie to the HTTP responseprotected void
Try to log in user automatically using cookies or some other mechanism (implementation dependent).protected abstract String
doWork()
Child classes must implement.final String
execute()
Method called by Struts to initiate action logic.Returns the name of this applicationReturns a map of application properties read from the application.properties file.List<javax.servlet.http.Cookie>
final User
Returns the user currently logged into this application, or null if no one is logged in, if the user is no longer valid, or if an error occurs (the error having been logged).Returns the developer who should be contacted regarding this applicationgetRaces()
Returns the original URL for this request.Returns the set of access roles required to execute this action (and access the associated page).Exposes session to child classes.getSexes()
void
setServletRequest
(javax.servlet.http.HttpServletRequest request) void
setServletResponse
(javax.servlet.http.HttpServletResponse response) Methods inherited from class com.opensymphony.xwork2.ActionSupport
addActionError, addActionMessage, addFieldError, clearActionErrors, clearErrors, clearErrorsAndMessages, clearFieldErrors, clearMessages, clone, getActionErrors, getActionMessages, getContainer, getFieldErrors, getFormatted, getLocale, getLocaleProvider, getText, getText, getText, getText, getText, getText, getText, getText, getText, getTextProvider, getTexts, getTexts, hasActionErrors, hasActionMessages, hasErrors, hasFieldErrors, hasKey, input, isValidLocale, isValidLocaleString, pause, setActionErrors, setActionMessages, setContainer, setFieldErrors, validate
-
Field Details
-
PERMISSION_DENIED
Should be returned when permission to view a page or perform an action is denied- See Also:
-
-
Constructor Details
-
BaseAction
public BaseAction()
-
-
Method Details
-
actionRequiresLogin
protected abstract boolean actionRequiresLogin()Returns whether this action should require a logged in user- Returns:
- true if action requires user to be logged in, else false
-
doWork
Child classes must implement. This is the "work" of the action and will be called by BaseAction.execute().- Returns:
- action status
- Throws:
Exception
- if something goes wrong
-
doAutoLogin
Try to log in user automatically using cookies or some other mechanism (implementation dependent).- Throws:
Exception
- if something goes wrong
-
execute
Method called by Struts to initiate action logic. Takes care of user authentication via actionRequiresLogin() and access roles. Simply returns the value returned by doWork();- Specified by:
execute
in interfacecom.opensymphony.xwork2.Action
- Overrides:
execute
in classcom.opensymphony.xwork2.ActionSupport
- Returns:
- action status
- Throws:
Exception
- if something goes wrong
-
getCurrentUser
Returns the user currently logged into this application, or null if no one is logged in, if the user is no longer valid, or if an error occurs (the error having been logged).- Returns:
- current user
-
getSession
Exposes session to child classes.- Returns:
- map of session objects
-
getRequiredAccessRoles
Returns the set of access roles required to execute this action (and access the associated page). Base class returns an empty set. Child classes are encouraged to override, returning application-specific roles.- Returns:
- set of roles required to view this page
-
getRequestUrl
Returns the original URL for this request. Useful to redirect to this page, say, after log in- Returns:
- original URL
-
setServletRequest
public void setServletRequest(javax.servlet.http.HttpServletRequest request) - Specified by:
setServletRequest
in interfaceorg.apache.struts2.interceptor.ServletRequestAware
-
setServletResponse
public void setServletResponse(javax.servlet.http.HttpServletResponse response) - Specified by:
setServletResponse
in interfaceorg.apache.struts2.interceptor.ServletResponseAware
-
getApplicationProperties
Returns a map of application properties read from the application.properties file. This allows applications to add their own custom properties to the file and read them at will from actions.- Returns:
- map of key-value pairs read from application.properties
-
getApplicationName
Returns the name of this application- Returns:
- application name
-
getCookies
- Returns:
- list of cookies sent along with HTTP request
-
addCookie
public void addCookie(javax.servlet.http.Cookie cookie) Adds the passed cookie to the HTTP response- Parameters:
cookie
- cookie to attach to response
-
getDeveloper
Returns the developer who should be contacted regarding this application- Returns:
- application developer
-
getStates
- Returns:
- List of all States
-
getSexes
- Returns:
- List of all Sexes
-
getRaces
- Returns:
- List of all Races
-
getEthnicities
- Returns:
- List of all Ethnicities
-
getHandednesses
- Returns:
- List of all Handednesses
-
getNameSuffixes
- Returns:
- List of all NameSuffixes
-
getSexualOrientations
- Returns:
- List of all SexualOrientations
-
getReligions
- Returns:
- List of all Religions
-