Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java @ 39:37840afb7b80
new: full text search
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 04 Dec 2015 14:28:44 +0100 |
parents | |
children | b8ad346e39a0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,69 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; +import de.mpiwg.web.jsp.FullTextSearchPage; + +public class GetFullTextSearchHtmlFile extends AbstractServletMethod { + public static String name = "getFullTextSearchHtmlFile"; + + private static Logger logger = Logger.getLogger(GetFullTextSearchHtmlFile.class); + + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long fileId = getQueryLongParam(request, "fileId"); + + logger.debug("getting full text search html file."); + + // get html file from /gazetteer-server/ftsearch-data/html/... + if(fileId != null){ + + LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId); + if(file != null){ + + String text = FileManager.getFullTextSearchHtmlFileText(file); + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "File no found (" + fileId + ")"); + json.put("code", GazetteerException.CODE); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + + + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: fileId, userId"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + + } + +}