Mercurial > hg > LGServices
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,56 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; + +public class GetFileText extends AbstractServletMethod { + + public static String name = "getFileText"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long fileId = getQueryLongParam(request, "fileId"); + + System.out.println("%%%%% GetFileText [fileId=" + fileId + "]"); + + if(fileId != null){ + LGFile file = DataProvider.getInstance().getFile(fileId); + if(file != null){ + + String text = FileManager.getFileAsText(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."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } + +}