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