Revision: 1836
Author: [email protected]
Date: Wed Feb 3 10:48:02 2010
Log: First version of Joseki integration; only works for TDB (non-default
db) and shows query result in plain text only. (issue 116)
http://code.google.com/p/simal/source/detail?r=1836
Added:
/trunk/uk.ac.osswatch.simal.web/src/main/resources/joseki-config.ttl
Modified:
/trunk/uk.ac.osswatch.simal.web
/trunk/uk.ac.osswatch.simal.web/pom.xml
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/SparqlQueryPage.html
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/SparqlQueryPage.java
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SparqlQueryInputModel.java
/trunk/uk.ac.osswatch.simal.web/src/main/webapp/WEB-INF/web.xml
=======================================
--- /dev/null
+++ /trunk/uk.ac.osswatch.simal.web/src/main/resources/joseki-config.ttl
Wed Feb 3 10:48:02 2010
@@ -0,0 +1,112 @@
+#
+# Copyright 2010 University of Oxford
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+## --------------------------------------------------------------
+## This file is written in N3 / Turtle
+## It is an RDF graph - order of RDF triples does not matter
+## to the machine but it does help people who need to edit this file.
+
+...@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+...@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+...@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+...@prefix module: <http://joseki.org/2003/06/module#> .
+...@prefix joseki: <http://joseki.org/2005/06/configuration#> .
+...@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
+...@prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
+
+## Note: web.xml must be in-step with this file.
+## for each service,
+
+## Note: adding rdfs:label to blank nodes will cause Joseki
+## to print that in log messages.
+
+## See also file:joseki-config-example.ttl
+
+
+## --------------------------------------------------------------
+## About this configuration
+
+<> rdfs:label "Joseki Configuration File - TDB example" .
+
+# Stripped down to support one service that exposes an
+# TDB store as a SPARQL endpoint for query.
+
+[] rdf:type joseki:Server .
+
+## --------------------------------------------------------------
+## Services
+
+## Services are the points that request are sent to.
+## serviceRef that will be used to match requests to services,
+## not some resource URI for the description.
+
+## Note that the service reference and the routing of incoming
+## requests by URI as defined by web.xml have to align.
+
+# Service 1
+# General purpose SPARQL processor, no dataset, expects the
+# request to specify the dataset (either by parameters in the
+# protocol request or in the query itself).
+
+<#service1>
+ rdf:type joseki:Service ;
+ rdfs:label "SPARQL-TDB" ;
+ joseki:serviceRef "joseki/sparql" ; # web.xml just route
this name to Joseki
+ joseki:dataset <#dataset> ;
+ joseki:processor joseki:ProcessorSPARQL ;
+ .
+
+## --------------------------------------------------------------
+## Datasets
+
+## Initialize TDB.
+
+[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
+tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset .
+tdb:GraphTDB rdfs:subClassOf ja:Model .
+
+## ---- A whole dataset managed by TDB
+<#dataset> rdf:type tdb:DatasetTDB ;
+## this works:
+## tdb:location "C:\\dev\\simal\\simal-webapp\\Simal_TDB" ;
+ tdb:location "simal_TDB" ;
+ .
+
+## --------------------------------------------------------------
+## Processors
+
+joseki:ProcessorSPARQL
+ rdfs:label "General SPARQL processor" ;
+ rdf:type joseki:Processor ;
+ module:implementation joseki:ImplSPARQL ;
+
+ # Parameters - this processor processes FROM/FROM NAMED
+ joseki:allowExplicitDataset "true"^^xsd:boolean ;
+ joseki:allowWebLoading "true"^^xsd:boolean ;
+ ## And has no locking policy (it loads data each time).
+ ## The default is mutex (one request at a time)
+ joseki:lockingPolicy joseki:lockingPolicyNone ;
+ .
+
+joseki:ImplSPARQL
+ rdf:type joseki:ServiceImpl ;
+ module:className
+ <java:org.joseki.processors.SPARQL> .
+
+# End:
=======================================
--- /trunk/uk.ac.osswatch.simal.web/pom.xml Mon Nov 30 16:36:24 2009
+++ /trunk/uk.ac.osswatch.simal.web/pom.xml Wed Feb 3 10:48:02 2010
@@ -195,6 +195,13 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.joseki</groupId>
+ <artifactId>joseki</artifactId>
+ <version>3.4.1</version>
+ </dependency>
+
</dependencies>
<build>
@@ -274,12 +281,13 @@
<excludes>
<exclude>.pmd</exclude>
<exclude>derby.log</exclude>
- <exclude>simal/**.*</exclude>
+ <exclude>simal*/**.*</exclude>
<exclude>build/**/*</exclude>
<exclude>simalDOAPFilestore/**/*</exclude>
<exclude>simalRepository/**/*</exclude>
<exclude>local.simal.properties</exclude>
<exclude>local.simal.test.properties</exclude>
+ <exclude>src/main/webapp/joseki/**/*</exclude>
</excludes>
</configuration>
<executions>
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/SparqlQueryPage.html
Sun Jan 10 04:50:59 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/SparqlQueryPage.html
Wed Feb 3 10:48:02 2010
@@ -15,30 +15,23 @@
-->
<html>
<head>
- <title>Query the Simal Project Registry</title>
+<title>Query the Simal Project Registry</title>
</head>
<body>
<wicket:extend>
- <h2>SPARQL Query</h2>
-
- <h2>This form allows raw querying of the data</h2>
-
- <form wicket:id="sparqlQueryForm">
- <fieldset>
- <legend>SPARQLQuery</legend>
- <p>
- <textarea wicket:id="sparqlQueryString" cols="80" rows="15">Type your
query here.</textarea>
- </p>
+ <h2>SPARQL Query</h2>
+
+ <h2>This form allows raw querying of the data</h2>
+
+ <form action="joseki/sparql">
+ <fieldset><legend>SPARQLQuery</legend>
+ <p><textarea wicket:id="query" cols="80" rows="15">Type your query
here.</textarea>
+ </p>
</fieldset>
-
- <p>
- <input type="submit" value="Execute" />
- </p>
- </form>
- <div wicket:id="queryResults">
- <span wicket:id="queryResult" >Query results</span>
- </div>
-
+ <input type="hidden" name="output" value="text" />
+
+ <p><input type="submit" value="Execute" /></p>
+ </form>
</wicket:extend>
</body>
</html>
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/SparqlQueryPage.java
Sun Jan 10 04:58:09 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/SparqlQueryPage.java
Wed Feb 3 10:48:02 2010
@@ -16,27 +16,11 @@
*/
package uk.ac.osswatch.simal.wicket;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.apache.commons.lang.StringEscapeUtils;
import org.apache.wicket.PageParameters;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.PropertyModel;
-import uk.ac.osswatch.simal.model.jena.SparqlResult;
-import uk.ac.osswatch.simal.model.jena.simal.JenaSimalRepository;
-import uk.ac.osswatch.simal.rdf.ISimalRepository;
-import uk.ac.osswatch.simal.rdf.SimalRepositoryException;
import uk.ac.osswatch.simal.wicket.data.SparqlQueryInputModel;
-import uk.ac.osswatch.simal.wicket.doap.DoapFormPage;
-
-import com.hp.hpl.jena.rdf.model.RDFNode;
/**
* A page for querying the RDF backend using SPARQL
@@ -46,128 +30,27 @@
*/
public class SparqlQueryPage extends BasePage {
- private static final String SPARQL_QUERY_STRING_FIELD
= "sparqlQueryString";
+ private static final String SPARQL_QUERY_STRING_FIELD = "query";
private static final String QUERY_PREFIX = " PREFIX xsd:
<http://www.w3.org/2001/XMLSchema#> \n"
+ " PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ " PREFIX doap: <http://usefulinc.com/ns/doap#> \n"
+ " PREFIX simal: <http://oss-watch.ac.uk/ns/0.2/simal#> \n\n";
- private final ListView<ListItem<String>> queryListView;
-
- private static final List<List<String>> queryList = new
Vector<List<String>>();
+ private final SparqlQueryInputModel inputModel = new
SparqlQueryInputModel();
/**
* Create default SPARQL query page
*/
- @SuppressWarnings("unchecked")
public SparqlQueryPage(PageParameters parameters) {
super();
- add(new SparqlQueryForm("sparqlQueryForm"));
-
- add(queryListView = new ListView("queryResults", queryList) {
- private static final long serialVersionUID = 2012355500166601921L;
-
- public void populateItem(final ListItem listItem) {
- final List<String> resultRow = (List<String>)
listItem.getModelObject();
- listItem.add(new Label("queryResult",
processResultRow(resultRow)));
- }
-
- /**
- * TODO Query result representation should be a table but don't know
how
- * to create a table with a dynamic nr. of columns in Wicket
- *
- * @param resultRow
- * @return
- */
- private String processResultRow(List<String> resultRow) {
- String result = "";
- for (String cell : resultRow) {
- if (!"".equals(result)) {
- result += ", ";
- }
- result += cell;
- }
- return result;
- }
- });
- }
-
- /**
- * Query the backend db with the queryStr and return result as received
from
- * backend.
- *
- * @param queryStr
- * @return
- */
- private SparqlResult getSparqlQueryResults(String queryStr) {
- String sparqlQuery = StringEscapeUtils.unescapeXml(queryStr);
- // @REFACTOR the UI should not be aware of the back end
implementation, we need a generic result interface for queries
- SparqlResult result = null;
- try {
- ISimalRepository repo = UserApplication.getRepository();
- // @REFACTOR the UI application should not be aware of the back end
implementation.
- if (repo instanceof JenaSimalRepository) {
- result = ((JenaSimalRepository)
repo).getSparqlQueryResult(sparqlQuery);
- }
-
- } catch (SimalRepositoryException e) {
- setResponsePage(new ErrorReportPage(new UserReportableException(
- "Unable to add doap using RDF supplied", DoapFormPage.class,
e)));
- }
- return result;
- }
-
- /**
- * Update display list with new query result.
- *
- * @param sparqlResults
- */
- private void processQueryResults(SparqlResult sparqlResults) {
- queryList.clear();
- queryList.add(sparqlResults.getVarNames());
- Iterator<List<RDFNode>> resultIter =
sparqlResults.getResultsIterator();
- while (resultIter.hasNext()) {
- List<RDFNode> result = resultIter.next();
- List<String> displayRow = new Vector<String>();
- for (RDFNode cell : result) {
- displayRow.add(cell.toString());
- }
- queryList.add(displayRow);
- }
- }
-
- /**
- * Form for entering the SPARQL query in the web page.
- *
- */
- private class SparqlQueryForm extends Form<SparqlQueryInputModel> {
- private static final long serialVersionUID = 1005521653425155426L;
-
- private final SparqlQueryInputModel inputModel = new
SparqlQueryInputModel();
-
- public SparqlQueryForm(String id) {
- super(id);
- TextArea<SparqlQueryInputModel> sparqlQueryField = new
TextArea<SparqlQueryInputModel>(
- SPARQL_QUERY_STRING_FIELD, new
PropertyModel<SparqlQueryInputModel>(
- inputModel, SPARQL_QUERY_STRING_FIELD));
- sparqlQueryField.add(new FocusBehaviour());
- String[] defaultValue = { QUERY_PREFIX };
- sparqlQueryField.setModelValue(defaultValue);
- add(sparqlQueryField);
- }
-
- @Override
- protected void onSubmit() {
- super.onSubmit();
- String sparqlQuery = inputModel.getSparqlQueryString();
- if (sparqlQuery != null && !"".equals(sparqlQuery)) {
- SparqlResult sparqlResults = getSparqlQueryResults(sparqlQuery);
- processQueryResults(sparqlResults);
- queryListView.modelChanged();
- }
- }
-
+ TextArea<SparqlQueryInputModel> sparqlQueryField = new
TextArea<SparqlQueryInputModel>(
+ SPARQL_QUERY_STRING_FIELD, new
PropertyModel<SparqlQueryInputModel>(
+ inputModel, SPARQL_QUERY_STRING_FIELD));
+ sparqlQueryField.add(new FocusBehaviour());
+ String[] defaultValue = { QUERY_PREFIX };
+ sparqlQueryField.setModelValue(defaultValue);
+ add(sparqlQueryField);
}
}
=======================================
---
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SparqlQueryInputModel.java
Fri Jan 8 09:33:39 2010
+++
/trunk/uk.ac.osswatch.simal.web/src/main/java/uk/ac/osswatch/simal/wicket/data/SparqlQueryInputModel.java
Wed Feb 3 10:48:02 2010
@@ -20,20 +20,19 @@
/**
* Provide inputs for the SPARQL query page
- * @author svanderwaal
*
*/
public class SparqlQueryInputModel implements IClusterable {
private static final long serialVersionUID = -638867731076925909L;
- private String sparqlQueryString;
-
- public void setSparqlQueryString(String sparqlQueryString) {
- this.sparqlQueryString = sparqlQueryString;
+ private String query;
+
+ public void setQuery(String query) {
+ this.query = query;
}
- public String getSparqlQueryString() {
- return sparqlQueryString;
+ public String getQuery() {
+ return query;
}
}
=======================================
--- /trunk/uk.ac.osswatch.simal.web/src/main/webapp/WEB-INF/web.xml Wed Sep
24 00:35:18 2008
+++ /trunk/uk.ac.osswatch.simal.web/src/main/webapp/WEB-INF/web.xml Wed
Feb 3 10:48:02 2010
@@ -38,6 +38,46 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
+ <!-- The Joseki SPARQL servlet -->
+
+ <servlet>
+ <servlet-name>SPARQL service processor</servlet-name>
+ <servlet-class>org.joseki.http.Servlet</servlet-class>
+
+ <!-- Configuration file -->
+ <init-param>
+ <param-name>org.joseki.rdfserver.config</param-name>
+ <param-value>joseki-config.ttl</param-value>
+ </init-param>
+
+ </servlet>
+
+ <!-- Validator -->
+
+ <servlet>
+ <servlet-name>Validator</servlet-name>
+ <servlet-class>
+ org.joseki.validator.Validator
+ </servlet-class>
+ </servlet>
+
+ <!-- Well-known servlets for testing -->
+
+ <servlet>
+ <servlet-name>Dumper</servlet-name>
+ <servlet-class>
+ org.joseki.servlets.DumpServlet
+ </servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>DumpBody</servlet-name>
+ <servlet-class>
+ org.joseki.servlets.DumpBodyServlet
+ </servlet-class>
+ </servlet>
+
+ <!-- end The Joseki SPARQL servlet -->
<!-- Simal REST API -->
@@ -51,4 +91,39 @@
<url-pattern>/simal-rest/*</url-pattern>
</servlet-mapping>
+ <!-- Demo service -->
+
+ <servlet-mapping>
+ <servlet-name>SPARQL service processor</servlet-name>
+ <url-pattern>/joseki/sparql/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>SPARQL service processor</servlet-name>
+ <url-pattern>/joseki/sparql</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>SPARQL service processor</servlet-name>
+ <url-pattern>/joseki/service/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>Validator</servlet-name>
+ <url-pattern>/joseki/validator</url-pattern>
+ </servlet-mapping>
+
+ <!-- A few utilities -->
+
+ <servlet-mapping>
+ <servlet-name>Dumper</servlet-name>
+ <url-pattern>/joseki/dump</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>DumpBody</servlet-name>
+ <url-pattern>/joseki/dump-body</url-pattern>
+ </servlet-mapping>
+
+
</web-app>
--
You received this message because you are subscribed to the Google Groups "Simal
Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simal-commits?hl=en.