Mercurial > hg > mpdl-group
comparison software/mpdl-services/mpiwg-mpdl-xml-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/xml/XQuery.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.xml; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.PrintWriter; | |
5 import java.net.URL; | |
6 | |
7 import javax.servlet.ServletConfig; | |
8 import javax.servlet.ServletException; | |
9 import javax.servlet.http.HttpServlet; | |
10 import javax.servlet.http.HttpServletRequest; | |
11 import javax.servlet.http.HttpServletResponse; | |
12 | |
13 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; | |
14 import de.mpg.mpiwg.berlin.mpdl.xml.xquery.XQueryEvaluator; | |
15 | |
16 public class XQuery extends HttpServlet { | |
17 private static final long serialVersionUID = 1L; | |
18 private XQueryEvaluator xqueryEvaluator; | |
19 | |
20 public XQuery() { | |
21 super(); | |
22 } | |
23 | |
24 public void init(ServletConfig config) throws ServletException { | |
25 super.init(config); | |
26 xqueryEvaluator = new XQueryEvaluator(); | |
27 } | |
28 | |
29 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
30 String result = null; | |
31 request.setCharacterEncoding("utf-8"); | |
32 response.setCharacterEncoding("utf-8"); | |
33 String inputString = request.getParameter("inputString"); | |
34 String srcUrlStr = request.getParameter("srcUrl"); | |
35 String xqueryStr = request.getParameter("xquery"); | |
36 try { | |
37 if (inputString != null) { | |
38 result = xqueryEvaluator.evaluateAsString(inputString, xqueryStr); | |
39 } else if (srcUrlStr != null) { | |
40 URL srcUrl = new URL(srcUrlStr); | |
41 result = xqueryEvaluator.evaluateAsString(srcUrl, xqueryStr); | |
42 } | |
43 response.setContentType("text/xml"); | |
44 PrintWriter out = response.getWriter(); | |
45 out.print("<result>" + result + "</result>"); | |
46 out.close(); | |
47 } catch (ApplicationException e) { | |
48 throw new ServletException(e); | |
49 } | |
50 } | |
51 | |
52 } |