01: package org.manentia.kasai.ui.actions;
02:
03: import java.util.Date;
04: import java.util.GregorianCalendar;
05:
06: import javax.servlet.http.HttpServletRequest;
07:
08: import org.apache.struts.action.Action;
09: import org.manentia.kasai.ui.UserView;
10: import org.manentia.kasai.ui.exceptions.SessionExpiredException;
11:
12: public class BaseAction extends Action {
13: protected static final String SUCCESS = "success";
14: protected static final String FAILURE = "failure";
15:
16: private boolean isLoggedIn(HttpServletRequest request) {
17: boolean valida = false;
18: UserView userView;
19: if (request.getSession().getAttribute("userView") != null) {
20: userView = (UserView) request.getSession().getAttribute(
21: "userView");
22: if (userView.getUser() != null) {
23: valida = true;
24: }
25: }
26: return valida;
27: }
28:
29: public UserView validateSession(HttpServletRequest request)
30: throws SessionExpiredException {
31: if (!isLoggedIn(request)) {
32: throw new SessionExpiredException();
33: }
34:
35: return (UserView) request.getSession().getAttribute("userView");
36: }
37:
38: public Date doDate(int day, int month, int year, boolean lastHour) {
39: Date dateResult = null;
40: if ((day != -1) && (month != -1) && (year != -1)) {
41: if (lastHour) {
42: dateResult = new GregorianCalendar(year, month - 1,
43: day, 23, 59, 59).getTime();
44: } else {
45: dateResult = new GregorianCalendar(year, month - 1, day)
46: .getTime();
47: }
48: }
49: return dateResult;
50: }
51:
52: public int doInt(String value) {
53: int result = -1;
54: try {
55: result = Integer.parseInt(value);
56: } catch (Exception e) {
57: }
58: return result;
59: }
60:
61: public int doInt(String value, int defaultValue) {
62: int result = defaultValue;
63: try {
64: result = Integer.parseInt(value);
65: } catch (Exception e) {
66: }
67: return result;
68: }
69:
70: public Integer doInteger(String value) {
71: Integer result = null;
72: try {
73: result = Integer.valueOf(value);
74: } catch (Exception e) {
75: }
76: return result;
77: }
78: }
|