Mercurial > hg > ismi-richfaces
view src/main/java/de/mpiwg/itgroup/ismi/servlets/jsonmethods/JSONNormString.java @ 67:34d0f1187b0f norm_json
add arabic normalization type to normalize_string JSON method.
author | casties |
---|---|
date | Thu, 10 Dec 2015 17:24:08 -0500 |
parents | a241cef14561 |
children | 8ae989269f51 |
line wrap: on
line source
package de.mpiwg.itgroup.ismi.servlets.jsonmethods; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.json.JSONObject; import org.mpi.openmind.cache.WrapperService; import org.mpi.openmind.repository.utils.ArabicNormalizerUtils; import org.mpi.openmind.repository.utils.ArabicTranslitNormalizer; public class JSONNormString extends AbstractServletJSONMethod { public static void execute(WrapperService ws, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject json = new JSONObject(); long startExecution = System.currentTimeMillis(); try { String text = request.getParameter("text"); String type = request.getParameter("type"); if (StringUtils.isEmpty(type)) { json.put(RESPONSE, EXCEPTION); json.put(RESPONSE_INFO, "Normalization type parameter missing."); PrintWriter out = response.getWriter(); out.print(json.toString()); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Normalization type parameter missing."); return; } if (type.equalsIgnoreCase("arabic_translit")) { if (text != null) { String normText = ArabicTranslitNormalizer.normalize(text); json.put("text", text); json.put("normalization_type", "arabic_translit"); json.put("normalized_text", normText); } } else if (type.equalsIgnoreCase("arabic")) { if (text != null) { String normText = ArabicNormalizerUtils.normalize(text); json.put("text", text); json.put("normalization_type", type); json.put("normalized_text", normText); } } } catch (Exception e) { PrintWriter out = response.getWriter(); out.print(json.toString()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } finally { json = finallyExecution(json, parametersToString(request.getParameterMap()), startExecution); } PrintWriter out = response.getWriter(); out.print(json.toString()); } }