comparison software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/Normalize.java @ 19:4a3641ae14d2

Erstellung
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Wed, 09 Nov 2011 15:32:05 +0100
parents
children
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.norm.Normalizer;
14
15 public class Normalize extends HttpServlet {
16 private static final long serialVersionUID = 1L;
17
18 public Normalize() {
19 super();
20 }
21
22 public void init(ServletConfig config) throws ServletException {
23 super.init(config);
24 }
25
26 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
27 request.setCharacterEncoding("utf-8");
28 response.setCharacterEncoding("utf-8");
29 String inputString = request.getParameter("inputString");
30 String language = request.getParameter("language");
31 String method = request.getParameter("method");
32 String typeStr = request.getParameter("type");
33 if (language == null)
34 language = "eng";
35 if (method == null)
36 method = "norm";
37 String[] methods = method.split(" ");
38 if (typeStr == null)
39 typeStr = "display";
40 int type = Normalizer.DISPLAY;
41 if (typeStr.equals("dictionary"))
42 type = Normalizer.DICTIONARY;
43 else if (typeStr.equals("search"))
44 type = Normalizer.SEARCH;
45 String result = null;
46 try {
47 response.setContentType("text/html");
48 PrintWriter out = response.getWriter();
49 if (inputString == null || inputString.isEmpty()) {
50 out.print("request parameter \"inputString\" is empty. Please specify \"inputString\"");
51 out.close();
52 return;
53 }
54 Normalizer normalizer = new Normalizer(methods, language);
55 normalizer.setNormMode(type);
56 result = normalizer.normalize(inputString);
57 if (result != null)
58 out.print(result);
59 out.close();
60 } catch (ApplicationException e) {
61 throw new ServletException(e);
62 }
63 }
64
65 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
66
67 }
68 }