| 3303 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.serving.utils.Utils;
|
|
|
4 |
|
|
|
5 |
import java.io.BufferedReader;
|
|
|
6 |
import java.io.FileReader;
|
|
|
7 |
import java.io.IOException;
|
|
|
8 |
import java.util.HashMap;
|
|
|
9 |
import java.util.Map;
|
|
|
10 |
|
|
|
11 |
import org.apache.log4j.Logger;
|
|
|
12 |
import org.json.JSONException;
|
|
|
13 |
import org.json.JSONObject;
|
|
|
14 |
|
|
|
15 |
public class SpecialPageConfigurer {
|
| 3311 |
chandransh |
16 |
private static Logger log = Logger.getLogger(SpecialPageConfigurer.class);
|
| 3320 |
rajveer |
17 |
private static Map<String, JSONObject> specialPagesDetails = new HashMap<String, JSONObject>();
|
| 3303 |
rajveer |
18 |
static {
|
|
|
19 |
try {
|
|
|
20 |
loadSpecialPagesDetails();
|
|
|
21 |
}
|
|
|
22 |
catch (IOException e) {
|
|
|
23 |
log.error("Could not load special pages details", e);
|
|
|
24 |
}
|
|
|
25 |
catch (JSONException e) {
|
|
|
26 |
log.error("Could not load special pages details", e);
|
|
|
27 |
}
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Loads all special pages related details
|
|
|
32 |
*/
|
|
|
33 |
private static void loadSpecialPagesDetails() throws IOException, JSONException {
|
| 3320 |
rajveer |
34 |
FileReader fr = new FileReader(Utils.EXPORT_ENTITIES_PATH + "../../javascripts/special-pages.json");
|
| 3303 |
rajveer |
35 |
BufferedReader br = new BufferedReader(fr);
|
|
|
36 |
String str = null;
|
|
|
37 |
|
|
|
38 |
log.info("Start loading special page parameters");
|
|
|
39 |
|
|
|
40 |
while ((str = br.readLine()) != null) {
|
|
|
41 |
JSONObject jsonObject = new JSONObject(str);
|
|
|
42 |
specialPagesDetails.put(jsonObject.getString("saholicURL"),
|
|
|
43 |
jsonObject);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
log.info("Finish loading special page parameters");
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Returns true in case a string passed is a special page name
|
|
|
51 |
*/
|
|
|
52 |
public static boolean isValidSpecialPage(String specialPage) {
|
| 3320 |
rajveer |
53 |
if (specialPage == null) {
|
| 3303 |
rajveer |
54 |
return false;
|
|
|
55 |
}
|
|
|
56 |
return specialPagesDetails.containsKey(specialPage);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public static String getQueryFromUri(String uri) throws JSONException {
|
|
|
60 |
return specialPagesDetails.get(uri).getString("searchQuery");
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public static String getSpecialPageTitleFromUri(String uri) throws JSONException {
|
|
|
64 |
return specialPagesDetails.get(uri).getString("pageTitle");
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public static String getSpecialPageNameFromUri(String uri) throws JSONException {
|
|
|
68 |
return specialPagesDetails.get(uri).getString("displayName");
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public static String getPageMetaKeywords(String uri) throws JSONException {
|
|
|
72 |
return specialPagesDetails.get(uri).getString("metaKeywords");
|
|
|
73 |
}
|
|
|
74 |
}
|