Mercurial > hg > mpdl-group
comparison software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/Transcode.java @ 19:4a3641ae14d2
Erstellung
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 09 Nov 2011 15:32:05 +0100 |
parents | |
children | 4ea0f81a5d08 |
comparison
equal
deleted
inserted
replaced
18:dc5e9fcb3fdc | 19:4a3641ae14d2 |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.servlets.lt; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.PrintWriter; | |
5 | |
6 import javax.servlet.ServletConfig; | |
7 import javax.servlet.ServletException; | |
8 import javax.servlet.http.HttpServlet; | |
9 import javax.servlet.http.HttpServletRequest; | |
10 import javax.servlet.http.HttpServletResponse; | |
11 | |
12 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; | |
13 import de.mpg.mpiwg.berlin.mpdl.lt.text.transcode.Transcoder; | |
14 | |
15 public class Transcode extends HttpServlet { | |
16 private static final long serialVersionUID = 1L; | |
17 private Transcoder transcoder; | |
18 | |
19 public Transcode() { | |
20 super(); | |
21 } | |
22 | |
23 public void init(ServletConfig config) throws ServletException { | |
24 super.init(config); | |
25 transcoder = Transcoder.getInstance(); | |
26 } | |
27 | |
28 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
29 request.setCharacterEncoding("utf-8"); | |
30 response.setCharacterEncoding("utf-8"); | |
31 String inputString = request.getParameter("inputString"); | |
32 String srcEncoding = request.getParameter("srcEncoding"); | |
33 String destEncoding = request.getParameter("destEncoding"); | |
34 if (destEncoding == null) | |
35 destEncoding = "unicode"; | |
36 String result = null; | |
37 try { | |
38 response.setContentType("text/html"); | |
39 PrintWriter out = response.getWriter(); | |
40 if (inputString == null || inputString.isEmpty()) { | |
41 out.print("request parameter \"inputString\" is empty. Please specify \"inputString\""); | |
42 out.close(); | |
43 return; | |
44 } | |
45 if (srcEncoding == null || srcEncoding.isEmpty()) { | |
46 out.print("request parameter \"srcEncoding\" is empty. Please specify \"srcEncoding\""); | |
47 out.close(); | |
48 return; | |
49 } | |
50 if (srcEncoding.equals("buckwalter") && destEncoding.equals("unicode")) { | |
51 result = transcoder.transcodeFromBuckwalter2Unicode(inputString); | |
52 } else if (srcEncoding.equals("betacode") && destEncoding.equals("unicode")) { | |
53 result = transcoder.transcodeFromBetaCode2Unicode(inputString); | |
54 } else if (srcEncoding.equals("unicode") && destEncoding.equals("betacode")) { | |
55 result = transcoder.transcodeFromUnicode2BetaCode(inputString); | |
56 } else if (srcEncoding.equals("unicode") && destEncoding.equals("buckwalter")) { | |
57 result = transcoder.transcodeFromUnicode2Buckwalter(inputString); | |
58 } | |
59 if (result != null) | |
60 out.print(result); | |
61 out.close(); | |
62 } catch (ApplicationException e) { | |
63 throw new ServletException(e); | |
64 } | |
65 } | |
66 | |
67 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
68 | |
69 } | |
70 } |