1 | /* |
---|
2 | * To change this license header, choose License Headers in Project Properties. |
---|
3 | * To change this template file, choose Tools | Templates |
---|
4 | * and open the template in the editor. |
---|
5 | */ |
---|
6 | |
---|
7 | package org.biohackathon.SPARQLBuilder.www; |
---|
8 | |
---|
9 | import java.io.IOException; |
---|
10 | import java.io.PrintWriter; |
---|
11 | import javax.servlet.ServletException; |
---|
12 | import javax.servlet.annotation.WebServlet; |
---|
13 | import javax.servlet.http.HttpServlet; |
---|
14 | import javax.servlet.http.HttpServletRequest; |
---|
15 | import javax.servlet.http.HttpServletResponse; |
---|
16 | import org.biohackathon.SPARQLBuilder.OWL.*; |
---|
17 | import javax.json.*; |
---|
18 | |
---|
19 | //import java.io.*; |
---|
20 | |
---|
21 | /** |
---|
22 | * |
---|
23 | * @author atsuko |
---|
24 | */ |
---|
25 | @WebServlet(name = "EPServlet", urlPatterns = {"/eplist"}) |
---|
26 | public class EPServlet extends HttpServlet { |
---|
27 | |
---|
28 | private RDFSchemaAnalyzerFactory factory = null; |
---|
29 | private static final String FILENAME = "cdata/"; |
---|
30 | |
---|
31 | /** |
---|
32 | * Processes requests for both HTTP <code>GET</code> and <code>POST</code> |
---|
33 | * methods. |
---|
34 | * |
---|
35 | * @param request servlet request |
---|
36 | * @param response servlet response |
---|
37 | * @throws ServletException if a servlet-specific error occurs |
---|
38 | * @throws IOException if an I/O error occurs |
---|
39 | */ |
---|
40 | protected void processRequest(HttpServletRequest request, HttpServletResponse response) |
---|
41 | throws ServletException, IOException { |
---|
42 | response.setContentType("text/html;charset=UTF-8"); |
---|
43 | try (PrintWriter out = response.getWriter()) { |
---|
44 | /* TODO output your page here. You may use following sample code. */ |
---|
45 | out.println("<!DOCTYPE html>"); |
---|
46 | out.println("<html>"); |
---|
47 | out.println("<head>"); |
---|
48 | out.println("<title>Servlet EPServlet</title>"); |
---|
49 | out.println("</head>"); |
---|
50 | out.println("<body>"); |
---|
51 | out.println("<h1>Servlet EPServlet at " + request.getContextPath() + "</h1>"); |
---|
52 | out.println("</body>"); |
---|
53 | out.println("</html>"); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> |
---|
58 | /** |
---|
59 | * Handles the HTTP <code>GET</code> method. |
---|
60 | * |
---|
61 | * @param request servlet request |
---|
62 | * @param response servlet response |
---|
63 | * @throws ServletException if a servlet-specific error occurs |
---|
64 | * @throws IOException if an I/O error occurs |
---|
65 | */ |
---|
66 | @Override |
---|
67 | protected void doGet(HttpServletRequest request, HttpServletResponse response) |
---|
68 | throws ServletException, IOException { |
---|
69 | //processRequest(request, response); |
---|
70 | |
---|
71 | response.setContentType("application/json;charset=UTF-8"); |
---|
72 | PrintWriter out = response.getWriter(); |
---|
73 | if ( factory == null ){ |
---|
74 | factory = new RDFSchemaAnalyzerFactory(FILENAME); |
---|
75 | } |
---|
76 | String[] elist = factory.getEndpointURIList(); |
---|
77 | JsonBuilderFactory jbfactory = Json.createBuilderFactory(null); |
---|
78 | JsonArrayBuilder jab = jbfactory.createArrayBuilder(); |
---|
79 | for (int i = 0; i < elist.length; i++ ){ |
---|
80 | jab.add(elist[i]); |
---|
81 | } |
---|
82 | JsonArray ja = jab.build(); |
---|
83 | out.print(ja); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Handles the HTTP <code>POST</code> method. |
---|
88 | * |
---|
89 | * @param request servlet request |
---|
90 | * @param response servlet response |
---|
91 | * @throws ServletException if a servlet-specific error occurs |
---|
92 | * @throws IOException if an I/O error occurs |
---|
93 | */ |
---|
94 | @Override |
---|
95 | protected void doPost(HttpServletRequest request, HttpServletResponse response) |
---|
96 | throws ServletException, IOException { |
---|
97 | processRequest(request, response); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Returns a short description of the servlet. |
---|
102 | * |
---|
103 | * @return a String containing servlet description |
---|
104 | */ |
---|
105 | @Override |
---|
106 | public String getServletInfo() { |
---|
107 | return "Short description"; |
---|
108 | }// </editor-fold> |
---|
109 | |
---|
110 | } |
---|