comparison src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java @ 0:3e62083dbcbf

First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
author "jurzua <jurzua@mpiwg-berlin.mpg.de>"
date Thu, 23 Apr 2015 15:46:01 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3e62083dbcbf
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.json.JSONObject;
9
10 import de.mpiwg.gazetteer.bo.LGFile;
11 import de.mpiwg.gazetteer.utils.DataProvider;
12 import de.mpiwg.gazetteer.utils.FileManager;
13 import de.mpiwg.gazetteer.utils.exceptions.GazetteerException;
14
15 public class GetFileText extends AbstractServletMethod {
16
17 public static String name = "getFileText";
18
19 public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
20
21 Long fileId = getQueryLongParam(request, "fileId");
22
23 System.out.println("%%%%% GetFileText [fileId=" + fileId + "]");
24
25 if(fileId != null){
26 LGFile file = DataProvider.getInstance().getFile(fileId);
27 if(file != null){
28
29 String text = FileManager.getFileAsText(file);
30 PrintWriter out = response.getWriter();
31 out.print(text);
32 out.flush();
33 response.setContentType("text/plain; charset=UTF-8");
34
35 }else{
36 response.setContentType("application/json");
37 JSONObject json = new JSONObject();
38 json.put("status", "error");
39 json.put("message", "File no found (" + fileId + ")");
40 json.put("code", GazetteerException.CODE);
41 PrintWriter out = response.getWriter();
42 out.print(json.toString());
43 out.flush();
44 }
45 }else{
46 response.setContentType("application/json");
47 JSONObject json = new JSONObject();
48 json.put("status", "error");
49 json.put("message", "Following parameters are mandatory: fileId.");
50 PrintWriter out = response.getWriter();
51 out.print(json.toString());
52 out.flush();
53 }
54 }
55
56 }