Rev 3311 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.services;import in.shop2020.serving.utils.Utils;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.HashMap;import java.util.Map;import org.apache.log4j.Logger;import org.json.JSONException;import org.json.JSONObject;public class SpecialPageConfigurer {private static Logger log = Logger.getLogger(SpecialPageConfigurer.class);private static Map<String, JSONObject> specialPagesDetails = new HashMap<String, JSONObject>();static {try {loadSpecialPagesDetails();}catch (IOException e) {log.error("Could not load special pages details", e);}catch (JSONException e) {log.error("Could not load special pages details", e);}}/*** Loads all special pages related details*/private static void loadSpecialPagesDetails() throws IOException, JSONException {FileReader fr = new FileReader(Utils.EXPORT_ENTITIES_PATH + "../../javascripts/special-pages.json");BufferedReader br = new BufferedReader(fr);String str = null;log.info("Start loading special page parameters");while ((str = br.readLine()) != null) {JSONObject jsonObject = new JSONObject(str);specialPagesDetails.put(jsonObject.getString("saholicURL"),jsonObject);}log.info("Finish loading special page parameters");}/*** Returns true in case a string passed is a special page name*/public static boolean isValidSpecialPage(String specialPage) {if (specialPage == null) {return false;}return specialPagesDetails.containsKey(specialPage);}public static String getQueryFromUri(String uri) throws JSONException {return specialPagesDetails.get(uri).getString("searchQuery");}public static String getSpecialPageTitleFromUri(String uri) throws JSONException {return specialPagesDetails.get(uri).getString("pageTitle");}public static String getSpecialPageNameFromUri(String uri) throws JSONException {return specialPagesDetails.get(uri).getString("displayName");}public static String getPageMetaKeywords(String uri) throws JSONException {return specialPagesDetails.get(uri).getString("metaKeywords");}}