djpowell.net

The Web, RDF, and other stuff

sparqltag

Status page for my JSP taglib for executing SPARQL queries.


djpowell.net SPARQL taglibs

Download it here!

This taglib provides a set of tags for executing SPARQL queries on a JSP page.

The requirements are:

  • Jena 2.4
  • Log4J
  • a JSP 2.0-compatable servlet container, such as Tomcat 5.x.

To use the taglibs, place the sparqltag.jar file in your web application's WEB-INF/lib directory, and provide a web.xml file, such as:

  <web-app version="2.4"
           xmlns="http://java.sun.com/xml/ns/j2ee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  ...
      <jsp-config>
        <taglib>
          <taglib-uri>http://djpowell.net/tmp/sparql-tag/0.1/</taglib-uri>
          <taglib-location>/WEB-INF/lib/sparqltag.jar</taglib-location>
        </taglib>
      </jsp-config>

  </web-app>

The JSP page, in doc/examples/test.jsp provides a simple example to get you started.

Tags Summary

sparql:load

This tag is for testing purposes only. It allows you to write quick prototypes using JSP only. Its purpose is to create an in-memory RDF-model initialised with RDF/XML from a URL.

<sparql:load var="<var>" uri="<uri>" />

var - the name of a variable that will be created to hold the model in the request context.

uri - a URI to initialise the model with.

sparql:sparql

This tag is a container for <sparql:select> elements. All <sparql:select> elements must execute in the context of a <sparql:sparql> element.

<sparql:select> returns live ResultSets, so the purpose of this tag is to ensure that the ResultSet gets disposed of when the </sparql:sparql> end tag is reached.

  <sparql:sparql>
    ...
    <sparql:select...>
      ...               
    </sparql:select>
    ...
  </sparql:sparql>

sparql:lock

This tag implements concurrency control for the model. If the model is not modified at all by any part of the application, then it is not necessary to use <sparql:lock>. In most applications, however, it will be required.

<sparql:lock> can implement concurrency control either by using transactions or critical sections.

Transactions may not be available with all types of models, specifically with in-memory models.

To execute sparql tags in a transaction:

  <sparql:lock model="${model}" transactions="true">
  ...
  </sparql:lock>

To execute sparql tags in a critical section, where the model will not be modified by the JSP page:

  <sparql:lock model="${model}" transactions="false" readonly="true">
  ...
  </sparql:lock>

To execute sparql tags in a critical section, where the model may be modified by the JSP page (none of the currently supplied tags modify the model):

  <sparql:lock model="${model}" transactions="false" readonly="false">
  ...
  </sparql:lock>

The defaults are transactions="false" and readonly="true".

sparql:select

Implements the standard SPARQL select query. The 'model' attribute provides the model used to execute the query; the 'var' attribute provides the name of a variable that will be created to hold the result set in the request context.

The body of the tag contains the SPARQL query. If you are using the JSP XML syntax, it is useful to use a CDATA section to avoid the need to quote less-than signs (<).

The result set object that is returned in the 'var' variable, provides a single public property called "rows" which may be used in a JSTL <c:forEach> tag to iterate the result set. The result set will be closed if the iteration reaches the end of the result set, or when the </sparql:sparql> end-tag is reached.

  <sparql:sparql>
    <sparql:select var=${resultset} model="${model}">
      <![CDATA[
          SELECT ?lab ?com
          WHERE {
          ?pu a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
          ?pu <http://www.w3.org/2000/01/rdf-schema#label> ?lab .
          ?pu <http://www.w3.org/2000/01/rdf-schema#comment> ?com .
          }
          ORDER BY ?lab
      ]]&gt;
    </sparql:select>
  </sparql:sparql>

The <sparql:select> tag also accepts dynamic attributes, which can be used to provide values to unbound query parameters so that a query can be parameterized. The value of dynamic attributes can also come from variables, such as loop-variables, and query-string parameters.

  <sparql:sparql>
    <sparql:select var=${resultset} model="${model}" dom="&lt;http://djpowell.net/schemas/atomrdf/0.3/EntryInstance>">
      <![CDATA[
          SELECT ?lab ?com
          WHERE {
          ?pu a <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
          ?pu <http://www.w3.org/2000/01/rdf-schema#label> ?lab .
          ?pu <http://www.w3.org/2000/01/rdf-schema#comment> ?com .
          ?pu <http://www.w3.org/2000/01/rdf-schema#domain> ?dom .
          }
          ORDER BY ?lab
      ]]&gt;
    </sparql:select>
  </sparql:sparql>

sparql:ask

Implements the standard SPARQL ask query. The 'model' attribute provides the model used to execute the query; the 'var' attribute provides the name of a variable that will be created to hold the result as a Boolean variable in the request context.

The body of the tag contains the SPARQL query.

The <sparql:ask> tag also accepts dynamic attributes, like the select tag.

sparql:construct

Implements the standard SPARQL construct query. The 'model' attribute provides the model used to execute the query; the 'var' attribute provides the name of a variable that will be created to hold the result as a Jena Model in the request context.

The body of the tag contains the SPARQL query.

The <sparql:construct> tag also accepts dynamic attributes, like the select tag.

sparql:describe

Implements the standard SPARQL describe query. The 'model' attribute provides the model used to execute the query; the 'var' attribute provides the name of a variable that will be created to hold the result as a Jena Model in the request context.

The body of the tag contains the SPARQL query.

The <sparql:describe> tag also accepts dynamic attributes, like the select tag.


(c) Copyright 2006 David Powell
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

[Email a comment]

[Latest] [Archive by Date] [Archive by Category] [Atom Feed]

Last updated: 6th August 10:13 PM (+0100)