Question

I am writing an Java web application that fetches RDF data from URIs and stores them in a Jena Model object. Currently the models contain ordinary triples, some Blank Nodes, no inference. (That is described here already 1). Using Sesame would be an option, too.

After data collection, the application displays some of the collected information in a specified order. It would be necessary to build filters on the model using predicates only and filters specifiying subject & predicate (as we will collect data from several sources); in each case, the object-literal or URI would be displayed.

What would be the best way to generically access the model's contents from a JSP-View (without writing custom tags for each function)?

The JSP-View would look like this:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
    <head></head>
    <body>
        <img src="${modelBean.model.depictionPred}"/>
        Name: <c:out value="${modelBean.model.namePred}"/><br/>
        Life dates: <c:out value="${modelBean.model.birthPred}"/>-<c:out value="${modelBean.model.deathPred}"/><br/>
        Links: <a href="${modelBean.model.linkPred}">Linktext</a><br/>
        ...
    </body>
</html>

Jena-Servlet to collect data:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            ModelBean modelBean = new ModelBean();
            Model model = ModelFactory.createDefaultModel();
            model.read("http://dbpedia.org/resource/Ludwig_van_Beethoven");
            modelBean.setModel(model);
            request.setAttribute("modelBean", modelBean);
            RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
            rd.forward(request, response);
        }

Sesame-Variant of the Servlet:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        ModelBean modelBean = new ModelBean();

        URL url = new URL("http://dbpedia.org/resource/Ludwig_van_Beethoven");
        URLConnection conn = url.openConnection();
        conn.addRequestProperty("Accept", RDFFormat.TURTLE.getDefaultMIMEType());
        InputStream is = conn.getInputStream();
        try {
           Model model = Rio.parse(is, url.toString(), RDFFormat.forMIMEType(conn.getContentType()));
        } catch (RDFParseException ex) {
           Logger.getLogger(ModelViewTester.class.getName()).log(Level.SEVERE, null, ex);
        } 
        finally {
           is.close(); 
        }
        modelBean.setModel(model);
        request.setAttribute("modelBean", modelBean);
        RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
        rd.forward(request, response);
    }
Was it helpful?

Solution

Apart from the fact that something may be possible by providing parameters to calls on bean methods (see How to call parameterized method from JSP using JSTL/EL ) I'm afraid you'll have to either create custom tags, or you need to rethink your access strategy.

For example, rather than putting the entire RDF Model into your response, you could do the extraction of relevant data at the servlet-side, and just put the relevant properties that you want to display in your view response, as separate bean properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top