root/SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/CLServlet.java @ 126

リビジョン 123, 3.7 KB (コミッタ: atsuko, 10 年 前)

SPARQL Builder WWW version

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