Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
317 ashish 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
387 rajveer 6
 
375 ashish 7
import in.shop2020.serving.pages.PageContentKeys;
8
import in.shop2020.serving.pages.PageEnum;
9
import in.shop2020.serving.pages.PageManager;
10
 
317 ashish 11
import java.io.IOException;
375 ashish 12
import java.util.HashMap;
13
import java.util.Map;
317 ashish 14
 
15
import javax.servlet.ServletContext;
16
 
17
import org.apache.juli.logging.Log;
18
import org.apache.juli.logging.LogFactory;
19
import org.apache.struts2.convention.annotation.Result;
20
import org.apache.struts2.convention.annotation.Results;
21
import org.apache.struts2.rest.DefaultHttpHeaders;
22
import org.apache.struts2.rest.HttpHeaders;
23
import org.apache.struts2.util.ServletContextAware;
24
 
25
import com.opensymphony.xwork2.ModelDriven;
26
 
27
/**
28
 * 
29
 * @author naveen
30
 *
31
 */
32
@Results({
33
    @Result(name="success", type="redirectAction", params = {"actionName" , 
34
    		"entity"})
35
})
36
public class EntityController extends BaseController 
37
	implements  ModelDriven<Object>, ServletContextAware  {
38
 
375 ashish 39
	private PageManager pageManager = null;
40
 
317 ashish 41
	/**
42
	 * 
43
	 */
44
	private static Log log = LogFactory.getLog(EntityController.class);
45
 
46
	/**
47
	 * 
48
	 */
49
	@SuppressWarnings("unused")
50
	private ServletContext servletContext = null;
51
 
52
	/**
53
	 * 
54
	 */
55
	private String id;
375 ashish 56
 
387 rajveer 57
	private Map<String,String> htmlSnippets;
375 ashish 58
 
59
 
60
	public EntityController(){
61
		super();
62
		pageManager = PageManager.getPageManager();
63
	}
317 ashish 64
    // GET /entity/1000001
65
    public HttpHeaders show() throws SecurityException, IOException {
66
    	log.info("id=" + id);
375 ashish 67
    	Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
68
    	params.put(PageContentKeys.ENTITY_ID, id);
69
    	Map<String,String> contents = pageManager.getPageContents(PageEnum.PRODUCT_PAGE, params);
387 rajveer 70
    	htmlSnippets = pageManager.getPageContents(PageEnum.PRODUCT_PAGE, params); 
71
 
72
    	System.out.println(htmlSnippets);
317 ashish 73
    	/*
74
    	String contextPath = this.servletContext.getContextPath();
75
    	log.info("contextPath=" + contextPath);
76
 
77
    	String realPath = this.servletContext.getRealPath("/");
78
    	log.info("realPath=" + realPath);
79
 
80
    	String path = this.servletContext.getRealPath(
81
    			"/WEB-INF/testdir/test.txt");
82
 
83
    	log.info("path=" + path);
84
 
85
    	FileReader fr = new FileReader(new File(path));
86
    	LineNumberReader lnr = new LineNumberReader(fr);
87
 
88
    	String line = lnr.readLine();
89
    	log.info("line=" + line);
90
    	*/
91
        return new DefaultHttpHeaders("show");
92
    }
93
 
94
    /**
95
     * 
96
     * @param id
97
     */
98
    public void setId(String id) {
99
        this.id = id;
100
    }
101
 
102
	/* (non-Javadoc)
103
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
104
	 */
105
	@Override
106
	public Object getModel() {
388 rajveer 107
		System.out.println(" getModer  is called");
108
		return htmlSnippets;
109
		//return this.id;
317 ashish 110
	}
111
 
112
	/**
113
	 * 
114
	 */
115
	@Override
116
	public void setServletContext(ServletContext servletContext) {
117
		this.servletContext = servletContext;
118
	}
375 ashish 119
 
387 rajveer 120
	public Map<String,String> getHtmlSnippets(){
388 rajveer 121
		System.out.println(" getHtmlSnippets  is called");
387 rajveer 122
		return htmlSnippets;
375 ashish 123
	}
388 rajveer 124
 
125
	public String getPriceSnippets(){
126
		return htmlSnippets.get("PRICE_DIV");
127
	}
317 ashish 128
 
388 rajveer 129
	public String getSlideGuideSnippets(){
130
		return htmlSnippets.get("SLIDE_GUIDE");
131
	}
132
 
133
	public String getWidgetSnippets(){
134
		return htmlSnippets.get("WIDGET_DIV");
135
	}
136
 
317 ashish 137
}