Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
507 rajveer 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
6
 
7
import in.shop2020.model.v1.widgets.WidgetService.Client;
8
import in.shop2020.serving.pages.PageContentKeys;
9
import in.shop2020.serving.pages.PageEnum;
10
import in.shop2020.serving.pages.PageManager;
11
import in.shop2020.thrift.clients.WidgetServiceClient;
12
 
13
import java.io.IOException;
14
import java.util.HashMap;
15
import java.util.Map;
16
import java.util.StringTokenizer;
17
 
18
import javax.servlet.ServletContext;
19
 
20
import org.apache.juli.logging.Log;
21
import org.apache.juli.logging.LogFactory;
22
import org.apache.struts2.convention.annotation.Action;
23
import org.apache.struts2.convention.annotation.Actions;
24
import org.apache.struts2.convention.annotation.Result;
25
import org.apache.struts2.convention.annotation.Results;
26
import org.apache.struts2.rest.DefaultHttpHeaders;
27
import org.apache.struts2.rest.HttpHeaders;
28
import org.apache.struts2.util.ServletContextAware;
29
 
30
import com.opensymphony.xwork2.ModelDriven;
31
 
32
/**
33
 * 
34
 * @author rajveer
35
 *
36
 */
37
@Results({
38
	@Result(name="success", location="/home-index")
39
})
40
public class HomeController extends BaseController 
41
	implements  ModelDriven<Object>, ServletContextAware  {
42
 
43
	private PageManager pageManager = null;
44
 
45
	/**
46
	 * 
47
	 */
48
	private static Log log = LogFactory.getLog(HomeController.class);
49
 
50
	/**
51
	 * 
52
	 */
53
	@SuppressWarnings("unused")
54
	private ServletContext servletContext = null;
55
 
56
	/**
57
	 * 
58
	 */
59
	private String id;
60
 
61
	private Map<String,String> htmlSnippets;
62
 
63
 
64
	public HomeController(){
65
		super();
66
		pageManager = PageManager.getPageManager();
67
	}
68
 
69
 
70
    public HttpHeaders index() throws SecurityException, IOException {
71
    	log.info("id=" + id);
72
    	Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
73
 
74
    	params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
75
    	params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
76
    	params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
77
    	params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
78
    	params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
79
 
80
    	htmlSnippets = pageManager.getPageContents(PageEnum.HOME_PAGE, params);
81
 
82
        return new DefaultHttpHeaders("index");
83
    }
84
 
85
    /**
86
     * 
87
     * @param id
88
     */
89
    public void setId(String id) {
90
    	StringTokenizer tokenizer = new StringTokenizer(id,"-");
91
    	while(tokenizer.hasMoreTokens()){
92
    		this.id = tokenizer.nextToken();
93
    	}
94
    }
95
 
96
	/* (non-Javadoc)
97
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
98
	 */
99
	@Override
100
	public Object getModel() {
101
		System.out.println(" getModer  is called");
102
		return htmlSnippets;
103
		//return this.id;
104
	}
105
 
106
	/**
107
	 * 
108
	 */
109
	@Override
110
	public void setServletContext(ServletContext servletContext) {
111
		this.servletContext = servletContext;
112
	}
113
 
114
	public Map<String,String> getHtmlSnippets(){
115
		System.out.println(" getHtmlSnippets  is called");
116
		return htmlSnippets;
117
	}
118
 
119
	public String getHeaderSnippet(){
120
		return htmlSnippets.get("HEADER");
121
	}
122
 
123
	public String getSlideGuideSnippet(){
124
		return htmlSnippets.get("SLIDE_GUIDE");
125
	}
126
 
127
	public String getMainMenuSnippet(){
128
		return htmlSnippets.get("MAIN_MENU");
129
	}
130
 
131
	public String getSearchBarSnippet(){
132
		return htmlSnippets.get("SEARCH_BAR");
133
	}
134
 
135
 
136
	public String getMainBannerSnippet(){
137
		return htmlSnippets.get("MAIN_BANNER");
138
	}
139
 
140
	public String getBestDealsSnippet(){
141
		return htmlSnippets.get("BEST_DEALS"); 
142
	}
143
 
144
	public String getLatestArrivalsSnippet(){
145
		return htmlSnippets.get("LATEST_ARRIVALS");
146
	}
147
 
148
	public String getBestSellersSnippet(){
149
		return htmlSnippets.get("BEST_SELLERS");
150
	}
151
 
152
	public String getCustomerServiceSnippet(){
153
		return htmlSnippets.get("CUSTOMER_SERVICE");
154
	}
155
 
156
	public String getMyResearchSnippet(){
157
		return htmlSnippets.get("MY_RESEARCH");
158
	}
159
 
160
 
161
	public String getRecommendationsSnippet(){
162
		return htmlSnippets.get("RECOMMENDATIONS");
163
	}
164
 
165
	public String getBrowseHistorySnippet(){
166
		return htmlSnippets.get("BROWSE_HISTORY");
167
	}
168
 
169
	public String getFooterSnippet(){
170
		return htmlSnippets.get("FOOTER");
171
	}
172
 
173
	public String getJsFileSnippet(){
174
		return htmlSnippets.get("JS_FILES");
175
	}
176
 
177
	public String getCssFileSnippet(){
178
		return htmlSnippets.get("CSS_FILES");
179
	}
180
 
181
}