| 7068 |
anupam.sin |
1 |
package in.shop2020.recharge.controllers;
|
|
|
2 |
|
|
|
3 |
import java.text.SimpleDateFormat;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.Map;
|
|
|
6 |
|
|
|
7 |
import javax.servlet.http.HttpServletRequest;
|
|
|
8 |
import javax.servlet.http.HttpServletResponse;
|
|
|
9 |
import javax.servlet.http.HttpSession;
|
|
|
10 |
|
|
|
11 |
import org.apache.log4j.Logger;
|
|
|
12 |
import org.apache.shiro.SecurityUtils;
|
|
|
13 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
14 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
15 |
import org.apache.struts2.interceptor.SessionAware;
|
|
|
16 |
|
|
|
17 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Base class for all user action handlers i.e. controllers
|
|
|
21 |
*
|
|
|
22 |
* @author Vikas
|
|
|
23 |
*/
|
|
|
24 |
public abstract class BaseController extends ValidationAwareSupport implements
|
|
|
25 |
ServletResponseAware, ServletRequestAware, SessionAware
|
|
|
26 |
{
|
|
|
27 |
private static final long serialVersionUID = 3339523094497219816L;
|
|
|
28 |
protected static Logger log = Logger.getLogger(BaseController.class);
|
|
|
29 |
|
|
|
30 |
protected static final String INPUT = "input";
|
|
|
31 |
protected static final String INDEX = "index";
|
|
|
32 |
protected static final String EDIT_NEW = "editNew";
|
|
|
33 |
protected static final String EDIT = "edit";
|
|
|
34 |
protected static final String SHOW = "show";
|
|
|
35 |
protected static final String EXCEPTION = "exception";
|
|
|
36 |
|
|
|
37 |
protected final SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy hh:mm a");
|
|
|
38 |
|
|
|
39 |
protected HttpServletResponse response;
|
|
|
40 |
protected HttpServletRequest request;
|
|
|
41 |
protected HttpSession session;
|
|
|
42 |
protected Map<String, Object> sessionMap;
|
|
|
43 |
|
|
|
44 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
45 |
this.response = response;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
49 |
this.request = request;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public void setSession(Map<String, Object> sessionMap) {
|
|
|
53 |
this.session = request.getSession();
|
|
|
54 |
this.sessionMap = sessionMap;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Utility method to convert a date to a readable format
|
|
|
59 |
*/
|
|
|
60 |
public String convertDate(Long date) {
|
|
|
61 |
if (date == null || date == 0) {
|
|
|
62 |
return "N/A";
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
return SDF.format(new Date(date));
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public String index() {
|
|
|
69 |
return INDEX;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public String editNew() {
|
|
|
73 |
return EDIT_NEW;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public String edit() {
|
|
|
77 |
return EDIT;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public boolean isPermitted(String permission) {
|
|
|
81 |
return SecurityUtils.getSubject().isPermitted(permission);
|
|
|
82 |
}
|
|
|
83 |
}
|