Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
5121 varun.gupt 1
/**
2
 * @author Varun Gupta
3
 */
4
 
5
package in.shop2020.serving.controllers;
6
 
7
import java.io.BufferedReader;
8
import java.io.FileReader;
9
import java.io.IOException;
10
import java.util.HashMap;
11
import java.util.Map;
12
 
13
import in.shop2020.serving.utils.Utils;
14
 
5356 varun.gupt 15
import org.apache.commons.lang.WordUtils;
5121 varun.gupt 16
import org.apache.log4j.Logger;
17
 
18
public class GeneratedController extends BaseController {
19
 
20
	private static Logger logger = Logger.getLogger(GeneratedController.class);
21
	private static String BASE_PATH = Utils.EXPORT_ENTITIES_PATH + "../../partners/";
22
	private static Map<String, String> snippetFileNames = new HashMap<String, String>();
23
	private static Map<String, String> snippets = new HashMap<String, String>();
24
 
25
	private String id;
26
 
27
	static	{
28
		try {
29
			snippetFileNames.put("product-index", BASE_PATH + "productindex.html");
30
			snippetFileNames.put("accessories-compatibility-index", BASE_PATH + "compatible-accessories-index.html");
5190 varun.gupt 31
			snippetFileNames.put("most-compared-phones", BASE_PATH + "most-compared-index.html");
5121 varun.gupt 32
 
33
			for (String index: snippetFileNames.keySet())	{
34
 
35
				FileReader fr = new FileReader(snippetFileNames.get(index));
36
				BufferedReader br = new BufferedReader(fr);
37
		        StringBuilder sb = new StringBuilder();
38
		        String str = null;
39
 
40
				while ((str = br.readLine()) != null) {
41
					sb.append(str);
42
				}
43
				snippets.put(index, sb.toString());
44
			}
45
		} catch (IOException e) {
46
			logger.error("", e);
47
		}
48
	}
49
 
50
	public GeneratedController()	{
51
		super();
52
	}
53
 
54
	public String show()	{
55
		return "show";
56
	}
57
 
58
	public String getHTML()	{
59
		return snippets.get(id);
60
	}
61
 
5356 varun.gupt 62
	public String getTitle()	{
63
		String[] urlChunks = request.getServletPath().split("/");
64
		String title = urlChunks[urlChunks.length - 1].replaceAll("-", " ");
65
 
66
		return WordUtils.capitalize(title);
5121 varun.gupt 67
	}
68
 
69
	public void setId(String id) {
70
		this.id = id;
71
	}
72
}