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

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

Session利用を中止

行番号 
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;
11//import 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 javax.servlet.http.HttpSession;
19import org.biohackathon.SPARQLBuilder.OWL.*;
20
21/**
22 *
23 * @author atsuko
24 */
25@WebServlet(name = "CLServlet", urlPatterns = {"/clist"})
26public 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}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。