org.activemath.webapp.base
Class ServletUtils

java.lang.Object
  extended by org.activemath.webapp.base.ServletUtils

public class ServletUtils
extends Object

Utility functions for ActiveMath servlets


Field Summary
protected static Category log
          The logger for this class
 
Constructor Summary
ServletUtils()
           
 
Method Summary
static AppSession getAppSession(HttpServletRequest request)
           
static String getClientAddress(HttpServletRequest request)
          Determine IP address, also for proxied requests.
static String getHeaderParameter(HttpServletRequest req, String param, String dflt)
          Safely get an HTTP header parameter.
static String getLanguage(HttpServletRequest request)
          Return the language for this request.
static List getLanguages(HttpServletRequest request)
           
static String getOutputFormat(HttpServletRequest request)
          Return the output format for this request.
static String getRequestParameter(HttpServletRequest req, String param, String dflt)
          Safely get a request parameter.
static String getSessionAttribute(HttpServletRequest req, String param, String dflt)
          Safely get a session parameter.
static String getSessionAttribute(HttpSession session, String param, String dflt)
           
static String getSessionAttrName()
           
static Skin getSkin(HttpServletRequest request)
          Return the skin for this request.
static String getUserId(HttpServletRequest request)
          Determine the current user of this request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Category log
The logger for this class

Constructor Detail

ServletUtils

public ServletUtils()
Method Detail

getUserId

public static final String getUserId(HttpServletRequest request)
Determine the current user of this request. The user id will come from the AppSession's current user.

Returns:
the id of the user currently logged in, or id of AnonUser if no user can be identified.

getSessionAttrName

public static final String getSessionAttrName()
Returns:
session attribute name for ActiveMath's AppSession.

getAppSession

public static final AppSession getAppSession(HttpServletRequest request)
Returns:
the of a user, or null

getLanguage

public static final String getLanguage(HttpServletRequest request)
Return the language for this request.

The language returned is:

  • the language from the request parameter lang, or
  • the language from the AppSession (if the user is logged in), or
  • the preferred language of the browser
  • the default language configured for the application

Returns:
language for this request

getLanguages

public static final List getLanguages(HttpServletRequest request)
Returns:
list of valid Activemath languages a browser supports (String)

getOutputFormat

public static final String getOutputFormat(HttpServletRequest request)
Return the output format for this request.

The output format returned is:

  • the format from the request parameter fmt, or
  • the format from the AppSession (if the user is logged in), or
  • "html"

Returns:
format for this request

getSkin

public static final Skin getSkin(HttpServletRequest request)
Return the skin for this request.

The skin returned is:

  • the skin from the request parameter skin, or
  • the skin from the AppSession (if the user is logged in), or
  • the default skin configured for the application, or
  • the empty skin

Returns:
skin for this request

getRequestParameter

public static String getRequestParameter(HttpServletRequest req,
                                         String param,
                                         String dflt)
Safely get a request parameter. Will return the supplied default value if parameter doesn't exist.

Returns:
parameter from request, or dflt if it doesn't exist

getHeaderParameter

public static String getHeaderParameter(HttpServletRequest req,
                                        String param,
                                        String dflt)
Safely get an HTTP header parameter. Will return the supplied default value if parameter doesn't exist.

Returns:
parameter from request, or dflt if it doesn't exist

getSessionAttribute

public static String getSessionAttribute(HttpServletRequest req,
                                         String param,
                                         String dflt)
Safely get a session parameter. Will return the supplied default value if parameter doesn't exist.

Returns:
parameter from session, or dflt if it doesn't exist

getSessionAttribute

public static String getSessionAttribute(HttpSession session,
                                         String param,
                                         String dflt)

getClientAddress

public static String getClientAddress(HttpServletRequest request)
Determine IP address, also for proxied requests.

Returns:
the ip address of the client host where the request is coming from