Subversion Repositories SmartDukaan

Rev

Rev 9612 | Rev 10300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9269 amit.gupta 1
package in.shop2020.mobileapi.serving.controllers;
9103 anupam.sin 2
 
9269 amit.gupta 3
import in.shop2020.mobileapi.serving.interceptors.UserAware;
4
import in.shop2020.mobileapi.serving.services.PageLoaderHandler;
5
import in.shop2020.mobileapi.serving.services.UserSessionInfo;
6
import in.shop2020.mobileapi.serving.utils.DesEncrypter;
9103 anupam.sin 7
import in.shop2020.model.v1.catalog.Banner;
8
import in.shop2020.model.v1.catalog.BannerMap;
9
 
10
import java.util.ArrayList;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
 
15
import javax.servlet.http.Cookie;
16
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletResponse;
18
import javax.servlet.http.HttpSession;
19
 
20
import org.apache.log4j.Logger;
21
import org.apache.struts2.interceptor.ServletRequestAware;
22
import org.apache.struts2.interceptor.ServletResponseAware;
23
 
24
import com.opensymphony.xwork2.ValidationAwareSupport;
25
 
26
/**
27
 * Base class for all user action handlers i.e. controllers
28
 * 
29
 * @author rajveer
30
 */
31
public abstract class BaseController extends ValidationAwareSupport implements
9601 amit.gupta 32
ServletResponseAware, ServletRequestAware, UserAware {
9103 anupam.sin 33
	/**
34
	 * 
35
	 */
36
	private static final long serialVersionUID = 1L;
37
	protected Map<String, Cookie> cookiesMap = null;
38
	protected HttpServletResponse response;
39
	protected HttpServletRequest request;
40
	protected HttpSession session;
41
	protected String domainName;
42
	protected UserSessionInfo userinfo = null;
43
	private static Logger log = Logger.getLogger(Class.class);
10283 amit.gupta 44
	private String resultJson;
9103 anupam.sin 45
 
46
	protected Cookie userCookie = null;
47
 
48
	protected Map<String, String> htmlSnippets;
49
 
50
	PageLoaderHandler pageLoader = null;
51
 
52
	public static Map<String,List<Banner>> activeBanners = null;
53
	public static Map<String, List<BannerMap>> allBannersMap = null;
54
 
9157 amit.gupta 55
 
9103 anupam.sin 56
 
57
	public List<BannerMap> getbannermapdetails(String bannerName) {
58
		return allBannersMap.get(bannerName);
59
	}
60
 
61
 
62
	public BaseController() {
63
		pageLoader = new PageLoaderHandler();
64
		htmlSnippets = new HashMap<String, String>();
65
	}
66
 
67
	@Override
68
	public void setCookiesMap(Map<String, Cookie> cookiesMap) {
69
		log.info("Received cookiesMap.");
70
		this.cookiesMap = cookiesMap;
71
	}
72
 
73
	@Override
74
	public void setServletResponse(HttpServletResponse response) {
75
		this.response = response;
76
	}
77
 
78
	@Override
79
	public void setServletRequest(HttpServletRequest request) {
80
		this.request = request;
81
	}
82
 
83
	@Override
84
	public void setSession(HttpSession session) {
85
		this.session = session;
86
	}
87
 
88
	@Override
89
	public void setUserSessionInfo(UserSessionInfo userInfo) {
90
		this.userinfo = userInfo;
91
	}
92
 
93
	@Override
94
	public void setUserCookie(Cookie userCookie) {
95
		if(userCookie != null){
96
			log.info("cookie name is:" +  userCookie.getName() + "   value is:"+ userCookie.getValue() + " path : " + userCookie.getPath());
97
		}
98
		this.userCookie = userCookie;
99
	}
100
 
101
	@Override
102
	public void setCookieDomainName(String domainName) {
103
		this.domainName = domainName;
104
	}
105
 
106
	public UserSessionInfo getUserInfo(){
107
		return this.userinfo;
108
	}
109
 
110
	@Override
111
	public List<Cookie> getCookies() {
112
		List<Cookie> cookies = new ArrayList<Cookie>();
113
		return cookies;
114
	}
115
 
116
	public String getCookie(String cookieName, boolean isEncripted, String encriptionString) {
117
		Cookie cookie = (Cookie) cookiesMap.get(cookieName);
118
		String cookieVal = null;
119
		if (cookie != null) {
120
			cookieVal = cookie.getValue();
121
			if (isEncripted) {
122
				DesEncrypter desEncrypter = new DesEncrypter(encriptionString);
123
				cookieVal = desEncrypter.decrypt(cookieVal);
124
			}
125
		}
126
		return cookieVal;
127
	}
10283 amit.gupta 128
 
129
 
130
	public void setResultJson(String resultJSon) {
131
		this.resultJson = resultJSon;
132
	}
133
 
134
 
135
	public String getResultJson() {
136
		return resultJson;
137
	}
9103 anupam.sin 138
}