org.activemath.webapp.base
Class ControllerBase

java.lang.Object
  extended by org.infohazard.maverick.ctl.Throwaway2
      extended by org.infohazard.maverick.ctl.ThrowawayBean2
          extended by org.activemath.webapp.base.ControllerBase
All Implemented Interfaces:
Controller
Direct Known Subclasses:
AboutController, AjaxController, AppletController, BookAdminController, BookController, BookGenerationController, BookmarksController, CacheController, CGWSInternalTestController, CGWSTestController, ClientEventController, ClientEventsLocalizer, ClipController, ContentBrowserController, ContentController, CopyrightController, CourseGenController, CourseGenerationController, CourseGenXMLrpcController, DelegationController, DialogueController, DictionaryController, DomainController, DrAuthoringController, DrTaskFormatter, ExamatController, ExerciseController, ExerciseRepositoryController, ExerciseSequencerController, ExerciseUploadController, ExtasyController, ExtasyController, FeedbackController, GapController, GenerateBookProgress, GenericController, GroupAdminController, HelpController, ImageGenController, ItemInfoController, ItemMenuController, ItemUploadController, JnlpController, LanguageGapController, Login, Logout, MainMenu, MBaseRefController, MunSequencerController, NextBestController, NotesController, OverviewsController, ReportController, SearchController, SearchLinkController, SietteController, SimulationController, SLMGuiController, SpeechOnDemandController, SpeechUniversalController, StatsController, SuggestionRealizer, SurveyController, SymbolPresentationListController, TaskGenerationController, Test, Toc, TOCEditController, TransformationToolController, UlogController, UserAdminController, UserDataController, UserFeedbackController, UserTrackerController, UserUploadController, UserVariables, ViewBook

public class ControllerBase
extends ThrowawayBean2

Base class for all ActiveMath controllers. This class provides:

Uses de.marf.crypt for user authentication and identification.


Field Summary
protected static AppContext appContext
          Applicaton context
protected static String defaultContentType
          Default content type of the HttpServletResponse
static String JSON
          Common name for the JSON view.
protected static Logger log
          The logger for this class
static String REDIRECT
          Common name for the typical "redirect" view.
static String REDIRECT_LOGIN
           
protected  HttpServletRequest request
           
protected  HttpServletResponse response
           
protected  StopWatch stopwatch
           
 
Fields inherited from class org.infohazard.maverick.ctl.Throwaway2
ERROR, SUCCESS
 
Constructor Summary
ControllerBase()
           
 
Method Summary
protected  String action()
          This is the method you should override to implement application logic.
protected  void addError(String message)
          Add a simple error message.
protected  void addError(String field, String message)
          Add an error to this request.
protected  void enableNoCache()
          Tell browser not to cache the response.
protected  String escapeForHtmlSafety(String value)
          Make a string safe for HTML markup.
protected  AccountManager getAccountManager()
          Return the user account management object
protected  AppSession getAppSession()
          Return the AppSession of the current user, of AnonUser, or null.
protected  String getCmdName()
          Returns the name of the command ("/dict/show"), with ".cmd" stripped of.
protected  User getCurrentUser()
          Get the current User object.
 Map getErrors()
          Return a map of error messages added by addError(String, String).
protected  HttpSession getHttpSession()
          Return the HttpSession of this controller context
protected  String getLanguage()
          The language to use for this request, as determined by ServletUtils#getLanguage().
protected  AppModel getModel()
          Give access to the basic model object, which is to be filled by action()
protected  String getOutputFormat()
           
protected  HttpServletRequest getRequest()
          Return the HttpServletRequest of this controller context
protected  HttpServletResponse getResponse()
          Return the HttpServletResponse of this controller context
protected  Skin getSkin()
           
 boolean hasErrors()
           
 String perform()
          Basic request handling method.
protected  void publishControllerEvent(ActivemathEvent event)
          Publish an event for a controller.
protected  String sendError(String message)
           
protected  String sendError(String message, Throwable e)
          Return an error view (with HTTP code 500).
protected  String sendJson(String jsonCode)
          Return a JSON value.
protected  String sendLoginRequired()
          Forward to the login controller.
protected  String sendRedirect(String url)
          Redirect to a redirect view without params.
protected  String sendRedirect(String url, Map params)
          Redirect to a redirect view.
 void setPasswd(String string)
           
 void setUser(String string)
           
 
Methods inherited from class org.infohazard.maverick.ctl.ThrowawayBean2
go
 
Methods inherited from class org.infohazard.maverick.ctl.Throwaway2
getCtx, go
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Logger log
The logger for this class


REDIRECT

public static final String REDIRECT
Common name for the typical "redirect" view.

See Also:
Constant Field Values

REDIRECT_LOGIN

public static final String REDIRECT_LOGIN
See Also:
Constant Field Values

JSON

public static final String JSON
Common name for the JSON view.

See Also:
Constant Field Values

defaultContentType

protected static String defaultContentType
Default content type of the HttpServletResponse


request

protected HttpServletRequest request

response

protected HttpServletResponse response

appContext

protected static AppContext appContext
Applicaton context


stopwatch

protected StopWatch stopwatch
Constructor Detail

ControllerBase

public ControllerBase()
Method Detail

setUser

public void setUser(String string)

setPasswd

public void setPasswd(String string)

escapeForHtmlSafety

protected String escapeForHtmlSafety(String value)
Make a string safe for HTML markup. Calls @link EscapeTool.forHtmlSafety


getAccountManager

protected final AccountManager getAccountManager()
Return the user account management object


getHttpSession

protected HttpSession getHttpSession()
Return the HttpSession of this controller context


getRequest

protected HttpServletRequest getRequest()
Return the HttpServletRequest of this controller context


getResponse

protected HttpServletResponse getResponse()
Return the HttpServletResponse of this controller context


getCmdName

protected String getCmdName()
Returns the name of the command ("/dict/show"), with ".cmd" stripped of.


getModel

protected AppModel getModel()
Give access to the basic model object, which is to be filled by action()

Returns:
the model object (a Map)

publishControllerEvent

protected void publishControllerEvent(ActivemathEvent event)
Publish an event for a controller.

User events will not be published if user is not logged in.

Before publishing, this will fill in the following data for the event:


getAppSession

protected AppSession getAppSession()
Return the AppSession of the current user, of AnonUser, or null.


hasErrors

public boolean hasErrors()

getErrors

public Map getErrors()
Return a map of error messages added by addError(String, String). The interpretation of the map is left to the view. Empty map if no errors have been reported.


addError

protected void addError(String field,
                        String message)
Add an error to this request. Interpretation of the map is left to the view.

Parameters:
field - - error id, use to group messages.
message - - interpreted by the view as text or as phrase key

addError

protected void addError(String message)
Add a simple error message.


sendError

protected String sendError(String message)

sendError

protected String sendError(String message,
                           Throwable e)
Return an error view (with HTTP code 500). The error view will have access to the exception (exception) and a stack traces ($Stacktrace and $StacktraceStripped).


getCurrentUser

protected User getCurrentUser()
Get the current User object.

Returns:
the current User object, or null if no user can be determined.

getLanguage

protected String getLanguage()
The language to use for this request, as determined by ServletUtils#getLanguage(). Note: ONLY CALL THIS METHOD FROM INSIDE action()!

Returns:
language for this request

getSkin

protected Skin getSkin()
Returns:
Skin for this request

getOutputFormat

protected String getOutputFormat()
Returns:
Skin for this request

sendRedirect

protected String sendRedirect(String url)
Redirect to a redirect view without params.


sendRedirect

protected String sendRedirect(String url,
                              Map params)
Redirect to a redirect view. To use this function, you need to the following view definition for your controller: <view name="redirect" type="redirect"/> If you want to redirect to yourself, just do return sendRedirect(request.getRequestURI(), params);

Parameters:
url -
Returns:

sendJson

protected String sendJson(String jsonCode)
Return a JSON value.


sendLoginRequired

protected String sendLoginRequired()
Forward to the login controller. The originating URL is given as the request attribute "dest".

Returns:
the view name "redirect", which must be defined as a "null" view

enableNoCache

protected void enableNoCache()
Tell browser not to cache the response. Do the necessary HTTP magic to avoid caching of pages on the client. If we do this, every .cmd URL is sure to trigger a request, even if IF is set to "automatic" reload. This way, we get more reliably logging data and can even detect usage of the back button. Info on IE here: http://support.microsoft.com/kb/q234067/


perform

public final String perform()
                     throws Exception
Basic request handling method. All requests to controllers go through this method. This function performs the following steps:

Overrides:
perform in class ThrowawayBean2
Throws:
Exception

action

protected String action()
                 throws Exception
This is the method you should override to implement application logic.

Throws:
Exception