01: package org.claros.mini.common;
02:
03: import java.util.ArrayList;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: import org.apache.struts.action.ActionForm;
09: import org.apache.struts.action.ActionForward;
10: import org.apache.struts.action.ActionMapping;
11: import org.claros.commons.exception.ClarosBaseException;
12: import org.claros.commons.mail.exception.ServerDownException;
13: import org.claros.commons.models.AuthProfile;
14:
15: /**
16: * @author Umut Gokbayrak
17: */
18: public abstract class BaseLoggedAction extends BaseClarosAction {
19: public abstract ActionForward myExecute(ActionMapping mapping,
20: ActionForm form, HttpServletRequest request,
21: HttpServletResponse response) throws Exception;
22:
23: /* (non-Javadoc)
24: * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
25: */
26: public ActionForward execute(ActionMapping mapping,
27: ActionForm form, HttpServletRequest request,
28: HttpServletResponse response) throws Exception {
29: commonFunctions(response);
30:
31: ActionForward forward = null;
32: try {
33: AuthProfile auth = getAuthProfile(request);
34: if (auth != null) {
35: forward = myExecute(mapping, form, request, response);
36: } else {
37: request.setAttribute("myexception", "Login again");
38: forward = mapping.findForward("login");
39: }
40: } catch (ServerDownException e) {
41: request.setAttribute("myexception", e.getMessage());
42: forward = mapping.findForward("login");
43: } catch (Exception e) {
44: ClarosBaseException ce = new ClarosBaseException(e);
45: request.setAttribute("myexception", ce);
46: forward = mapping.findForward("generalerror");
47: }
48: return forward;
49: }
50:
51: public AuthProfile getAuthProfile(HttpServletRequest request) {
52: return (AuthProfile) request.getSession().getAttribute("auth");
53: }
54:
55: public ArrayList getUserSettings(HttpServletRequest request) {
56: return (ArrayList) request.getSession().getAttribute("prefs");
57: }
58: }
|