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

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Encapsulates information about the contact developer for this application
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Should be returned when permission to view a page or perform an action is denied

    Fields inherited from class com.opensymphony.xwork2.ActionSupport

    container

    Fields inherited from interface com.opensymphony.xwork2.Action

    ERROR, INPUT, LOGIN, NONE, SUCCESS
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    Returns whether this action should require a logged in user
    void
    addCookie(javax.servlet.http.Cookie cookie)
    Adds the passed cookie to the HTTP response
    protected void
    Try to log in user automatically using cookies or some other mechanism (implementation dependent).
    protected abstract String
    Child classes must implement.
    final String
    Method called by Struts to initiate action logic.
    Returns the name of this application
    protected Map<String,String>
    Returns 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 application
     
     
     
     
     
    Returns the original URL for this request.
    protected Set<String>
    Returns the set of access roles required to execute this action (and access the associated page).
    protected Map<String,Object>
    Exposes session to child classes.
     
     
     
    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

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PERMISSION_DENIED

      protected static final String 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

      protected abstract String doWork() throws Exception
      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

      protected void doAutoLogin() throws Exception
      Try to log in user automatically using cookies or some other mechanism (implementation dependent).
      Throws:
      Exception - if something goes wrong
    • execute

      public final String execute() throws Exception
      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 interface com.opensymphony.xwork2.Action
      Overrides:
      execute in class com.opensymphony.xwork2.ActionSupport
      Returns:
      action status
      Throws:
      Exception - if something goes wrong
    • getCurrentUser

      public final User 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

      protected Map<String,Object> getSession()
      Exposes session to child classes.
      Returns:
      map of session objects
    • getRequiredAccessRoles

      protected Set<String> 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

      public String 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 interface org.apache.struts2.interceptor.ServletRequestAware
    • setServletResponse

      public void setServletResponse(javax.servlet.http.HttpServletResponse response)
      Specified by:
      setServletResponse in interface org.apache.struts2.interceptor.ServletResponseAware
    • getApplicationProperties

      protected Map<String,String> 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

      public String getApplicationName()
      Returns the name of this application
      Returns:
      application name
    • getCookies

      public List<javax.servlet.http.Cookie> 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

      public BaseAction.Developer getDeveloper()
      Returns the developer who should be contacted regarding this application
      Returns:
      application developer
    • getStates

      public List<State> getStates()
      Returns:
      List of all States
    • getSexes

      public List<Sex> getSexes()
      Returns:
      List of all Sexes
    • getRaces

      public List<Race> getRaces()
      Returns:
      List of all Races
    • getEthnicities

      public List<Ethnicity> getEthnicities()
      Returns:
      List of all Ethnicities
    • getHandednesses

      public List<Handedness> getHandednesses()
      Returns:
      List of all Handednesses
    • getNameSuffixes

      public List<NameSuffix> getNameSuffixes()
      Returns:
      List of all NameSuffixes
    • getSexualOrientations

      public List<SexualOrientation> getSexualOrientations()
      Returns:
      List of all SexualOrientations
    • getReligions

      public List<Religion> getReligions()
      Returns:
      List of all Religions