39
|
1 package de.mpiwg.gazetteer.rest;
|
|
2
|
|
3 import java.io.PrintWriter;
|
|
4
|
|
5 import javax.servlet.http.HttpServletRequest;
|
|
6 import javax.servlet.http.HttpServletResponse;
|
|
7
|
|
8 import org.apache.commons.lang.StringUtils;
|
|
9 import org.apache.log4j.Logger;
|
|
10 import org.json.JSONObject;
|
|
11
|
|
12 import de.mpiwg.gazetteer.bo.LGFile;
|
|
13 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
|
|
14 import de.mpiwg.gazetteer.utils.DataProvider;
|
|
15 import de.mpiwg.gazetteer.utils.FileManager;
|
|
16 import de.mpiwg.gazetteer.utils.HTTPUtils;
|
|
17 import de.mpiwg.gazetteer.utils.exceptions.GazetteerException;
|
|
18 import de.mpiwg.web.jsp.FullTextSearchPage;
|
|
19
|
|
20 public class GetFullTextSearchHtmlFile extends AbstractServletMethod {
|
|
21 public static String name = "getFullTextSearchHtmlFile";
|
|
22
|
|
23 private static Logger logger = Logger.getLogger(GetFullTextSearchHtmlFile.class);
|
|
24
|
|
25
|
|
26 public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
|
27
|
|
28 Long fileId = getQueryLongParam(request, "fileId");
|
|
29
|
|
30 logger.debug("getting full text search html file.");
|
|
31
|
|
32 // get html file from /gazetteer-server/ftsearch-data/html/...
|
|
33 if(fileId != null){
|
|
34
|
|
35 LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId);
|
|
36 if(file != null){
|
|
37
|
|
38 String text = FileManager.getFullTextSearchHtmlFileText(file);
|
|
39 PrintWriter out = response.getWriter();
|
|
40 out.print(text);
|
|
41 out.flush();
|
|
42 response.setContentType("text/plain; charset=UTF-8");
|
|
43
|
|
44 }else{
|
|
45 response.setContentType("application/json");
|
|
46 JSONObject json = new JSONObject();
|
|
47 json.put("status", "error");
|
|
48 json.put("message", "File no found (" + fileId + ")");
|
|
49 json.put("code", GazetteerException.CODE);
|
|
50 PrintWriter out = response.getWriter();
|
|
51 out.print(json.toString());
|
|
52 out.flush();
|
|
53 }
|
|
54
|
|
55
|
|
56
|
|
57 }else{
|
|
58 response.setContentType("application/json");
|
|
59 JSONObject json = new JSONObject();
|
|
60 json.put("status", "error");
|
|
61 json.put("message", "Following parameters are mandatory: fileId, userId");
|
|
62 PrintWriter out = response.getWriter();
|
|
63 out.print(json.toString());
|
|
64 out.flush();
|
|
65 }
|
|
66
|
|
67 }
|
|
68
|
|
69 }
|