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