root/SPARQLBuilderWWW/src/java/org/biohackathon/SPARQLBuilder/www/SPServlet.java @ 133

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

最新版に追従

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