You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/02/22 16:21:36 UTC
[33/37] MARMOTTA-105: refactoring of packages in remaining platform
modules
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
new file mode 100644
index 0000000..0ede59a
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparql/SparqlServiceImpl.java
@@ -0,0 +1,221 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.services.sparql;
+
+import org.apache.marmotta.platform.sparql.api.sparql.SparqlService;
+import org.apache.marmotta.platform.sparql.services.sparqlio.rdf.SPARQLGraphResultWriter;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.triplestore.SesameService;
+import org.apache.marmotta.platform.core.exception.InvalidArgumentException;
+import org.apache.marmotta.platform.core.exception.LMFException;
+import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
+import org.openrdf.model.Value;
+import org.openrdf.query.*;
+import org.openrdf.query.resultio.BooleanQueryResultWriter;
+import org.openrdf.query.resultio.TupleQueryResultWriter;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.slf4j.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * Add file description here!
+ * <p/>
+ * User: sschaffe
+ */
+@Named("kiwi.core.query.sparqlService")
+@ApplicationScoped
+public class SparqlServiceImpl implements SparqlService {
+
+
+ /**
+ * Get the seam logger for issuing logging statements.
+ */
+ @Inject
+ private Logger log;
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ @Inject
+ private SesameService sesameService;
+
+
+ @Override
+ public void query(QueryLanguage queryLanguage, String query, TupleQueryResultWriter tupleWriter, BooleanQueryResultWriter booleanWriter, SPARQLGraphResultWriter graphWriter) throws LMFException, MalformedQueryException, QueryEvaluationException {
+ long start = System.currentTimeMillis();
+
+ log.debug("executing SPARQL query:\n{}", query);
+
+ try {
+ RepositoryConnection connection = sesameService.getConnection();
+ try {
+ connection.begin();
+ Query sparqlQuery = connection.prepareQuery(queryLanguage, query);
+
+ if (sparqlQuery instanceof TupleQuery) {
+ TupleQuery tupleQuery = (TupleQuery) sparqlQuery;
+ tupleQuery.evaluate(tupleWriter);
+ } else if (sparqlQuery instanceof BooleanQuery) {
+ BooleanQuery booleanQuery = (BooleanQuery) sparqlQuery;
+ booleanWriter.write(booleanQuery.evaluate());
+ } else if (sparqlQuery instanceof GraphQuery) {
+ GraphQuery graphQuery = (GraphQuery) sparqlQuery;
+ graphWriter.write(graphQuery.evaluate());
+ } else {
+ connection.rollback();
+ throw new InvalidArgumentException("SPARQL query type " + sparqlQuery.getClass() + " not supported!");
+ }
+
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+ } catch(RepositoryException ex) {
+ log.error("error while getting repository connection");
+ throw new LMFException("error while getting repository connection",ex);
+ } catch (TupleQueryResultHandlerException e) {
+ throw new LMFException("error while writing query result in format ",e);
+ } catch (IOException e) {
+ throw new LMFException("error while writing query result in format ",e);
+ }
+
+ log.debug("SPARQL execution took {}ms",System.currentTimeMillis()-start);
+ }
+
+
+
+ private static Pattern subTypePattern = Pattern.compile("[a-z]+/([a-z0-9-._]+\\+)?([a-z0-9-._]+)(;.*)?");
+ private String parseSubType(String mimeType) {
+ Matcher matcher = subTypePattern.matcher(mimeType);
+ if(matcher.matches()) return matcher.group(2);
+ else
+ return mimeType;
+ }
+
+
+
+ /**
+ * Evaluate a SPARQL query on the LMF TripleStore. Returns the results as a list of result maps, each element
+ * a KiWiNode.
+ * <p/>
+ * see http://www.w3.org/TR/sparql11-query/
+ *
+ * @param queryLanguage the query language to use
+ * @param query the SPARQL query to evaluate in SPARQL 1.1 syntax
+ */
+ @Override
+ public List<Map<String, Value>> query(QueryLanguage queryLanguage, String query) throws LMFException {
+ long start = System.currentTimeMillis();
+
+ log.debug("executing {} query:\n{}", queryLanguage.getName(), query);
+
+ List<Map<String,Value>> result = new LinkedList<Map<String, Value>>();
+
+ try {
+ RepositoryConnection connection = sesameService.getConnection();
+ try {
+ connection.begin();
+ TupleQuery tupleQuery = connection.prepareTupleQuery(queryLanguage, query);
+ TupleQueryResult r = tupleQuery.evaluate();
+ try {
+ while (r.hasNext()) {
+ BindingSet s = r.next();
+ Map<String, Value> map = new HashMap<String, Value>();
+ for (Binding binding : s) {
+ if (binding.getValue() instanceof KiWiNode) {
+ map.put(binding.getName(), binding.getValue());
+ } else {
+ log.error("binding value {} is not a KiWiNode!", binding.getValue());
+ }
+ }
+ result.add(map);
+ }
+ } finally {
+ r.close();
+ }
+ //
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+ } catch(RepositoryException ex) {
+ log.error("error while getting repository connection");
+ throw new LMFException("error while getting repository connection",ex);
+ } catch (QueryEvaluationException e) {
+ throw new LMFException("error while evaluating SPARQL query "+query,e);
+ } catch (MalformedQueryException e) {
+ throw new InvalidArgumentException("malformed SPARQL query ("+query+") for language "+queryLanguage,e);
+ }
+
+ log.debug("SPARQL execution took {}ms",System.currentTimeMillis()-start);
+ return result;
+ }
+
+ /**
+ * Execute a SPARQL update on the LMF TripleStore. Throws a KiWiException in case the update execution fails.
+ * <p/>
+ * see http://www.w3.org/TR/sparql11-update/
+ *
+ * @param queryLanguage
+ * @param query a string representing the update query in SPARQL Update 1.1 syntax
+ * @throws Exception
+ */
+ @Override
+ public void update(QueryLanguage queryLanguage, String query) throws LMFException {
+ long start = System.currentTimeMillis();
+
+ log.debug("executing SPARQL update:\n{}", query);
+
+ try {
+ RepositoryConnection connection = sesameService.getConnection();
+ try {
+ connection.begin();
+ Update update = connection.prepareUpdate(queryLanguage,query,configurationService.getBaseUri());
+ update.execute();
+ connection.commit();
+ } catch (UpdateExecutionException e) {
+ connection.rollback();
+ throw new LMFException("error while executing update",e);
+ } catch (MalformedQueryException e) {
+ connection.rollback();
+ throw new LMFException("malformed query, update failed",e);
+ } finally {
+ connection.close();
+ }
+ } catch(RepositoryException ex) {
+ log.error("error while getting repository connection", ex);
+ throw new LMFException("error while getting repository connection",ex);
+ }
+ log.debug("SPARQL update execution took {}ms",System.currentTimeMillis()-start);
+
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
new file mode 100644
index 0000000..8149a99
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/rdf/SPARQLGraphResultWriter.java
@@ -0,0 +1,92 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.services.sparqlio.rdf;
+
+import org.openrdf.query.GraphQueryResult;
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.rio.RDFWriter;
+import org.openrdf.rio.Rio;
+import org.openrdf.sail.memory.MemoryStore;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class SPARQLGraphResultWriter {
+
+
+ private OutputStream outputStream;
+
+
+ private RDFFormat format;
+
+
+ public SPARQLGraphResultWriter(OutputStream outputStream) {
+ this.outputStream = outputStream;
+ format = RDFFormat.RDFXML;
+ }
+
+ public SPARQLGraphResultWriter(OutputStream outputStream, String mimeType) {
+ this.outputStream = outputStream;
+ this.format = RDFFormat.forMIMEType(mimeType, RDFFormat.RDFXML);
+ }
+
+
+ public void write(GraphQueryResult result) throws IOException {
+ Repository repository = new SailRepository(new MemoryStore());
+ try {
+ repository.initialize();
+
+ RepositoryConnection con = repository.getConnection();
+ for(Map.Entry<String,String> namespace : result.getNamespaces().entrySet()) {
+ con.setNamespace(namespace.getKey(),namespace.getValue());
+ }
+
+ while(result.hasNext()) {
+ con.add(result.next());
+ }
+ con.commit();
+
+ RDFWriter writer = Rio.createWriter(format,outputStream);
+ con.export(writer);
+ con.close();
+ repository.shutDown();
+
+ outputStream.flush();
+ outputStream.close();
+
+ } catch (RepositoryException e) {
+ throw new IOException("query result writing failed because there was an error while creating temporary triple store",e);
+ } catch (QueryEvaluationException e) {
+ throw new IOException("query result writing failed because query evaluation had a problem",e);
+ } catch (RDFHandlerException e) {
+ throw new IOException("query result writing failed because writer could not handle rdf data",e);
+ }
+
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLBooleanHTMLWriter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLBooleanHTMLWriter.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLBooleanHTMLWriter.java
new file mode 100644
index 0000000..f233cff
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLBooleanHTMLWriter.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml;
+
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.util.KiWiContext;
+import org.jdom2.Document;
+import org.jdom2.output.Format;
+import org.jdom2.output.XMLOutputter;
+import org.jdom2.transform.JDOMResult;
+import org.openrdf.query.resultio.BooleanQueryResultFormat;
+import org.openrdf.query.resultio.BooleanQueryResultWriter;
+import org.openrdf.query.resultio.sparqlxml.SPARQLBooleanXMLWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamSource;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+
+/**
+ * Add file description here!
+ * <p/>
+ * User: sschaffe
+ */
+public class SPARQLBooleanHTMLWriter implements BooleanQueryResultWriter {
+
+ private static final Logger log = LoggerFactory.getLogger(SPARQLBooleanHTMLWriter.class);
+
+ private OutputStream out;
+ private ByteArrayOutputStream xmlOut;
+
+ private SPARQLBooleanXMLWriter xmlWriter;
+
+ private Templates stylesheet;
+
+ public SPARQLBooleanHTMLWriter(OutputStream out) {
+ this.out = out;
+ this.xmlOut = new ByteArrayOutputStream();
+ this.xmlWriter = new SPARQLBooleanXMLWriter(xmlOut);
+
+ Source s_stylesheet = new StreamSource(SPARQLBooleanHTMLWriter.class.getResourceAsStream("style.xsl"));
+ try {
+ stylesheet = TransformerFactory.newInstance().newTemplates(s_stylesheet);
+ } catch (TransformerConfigurationException e) {
+ log.error("could not compile stylesheet for rendering SPARQL results; result display not available!");
+ }
+ }
+
+ /**
+ * Gets the query result format that this writer uses.
+ */
+ @Override
+ public BooleanQueryResultFormat getBooleanQueryResultFormat() {
+ return new BooleanQueryResultFormat("SPARQL/HTML","text/html", Charset.forName("UTF-8"), "html");
+ }
+
+ /**
+ * Writes the specified boolean value.
+ */
+ @Override
+ public void write(boolean value) throws IOException {
+ xmlWriter.write(value);
+
+ byte[] queryResult = xmlOut.toByteArray();
+
+ // get server uri
+ String server_uri = KiWiContext.getInstance(ConfigurationService.class).getServerUri();
+
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
+ try {
+ Source input = new StreamSource(new ByteArrayInputStream(queryResult));
+
+
+ Transformer transformer = stylesheet.newTransformer();
+ transformer.setParameter("serverurl", server_uri);
+
+ JDOMResult result = new JDOMResult();
+ transformer.transform(input,result);
+ Document output = result.getDocument();
+
+ XMLOutputter printer = new XMLOutputter(Format.getPrettyFormat());
+ printer.output(output, writer);
+ writer.flush();
+ } catch (Exception ex) {
+ throw new IOException("error while transforming XML results to HTML",ex);
+ } finally {
+ writer.close();
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLResultsHTMLWriter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLResultsHTMLWriter.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLResultsHTMLWriter.java
new file mode 100644
index 0000000..a4507d9
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/SPARQLResultsHTMLWriter.java
@@ -0,0 +1,141 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml;
+
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.util.KiWiContext;
+import org.jdom2.Document;
+import org.jdom2.output.Format;
+import org.jdom2.output.XMLOutputter;
+import org.jdom2.transform.JDOMResult;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.TupleQueryResultHandlerException;
+import org.openrdf.query.resultio.TupleQueryResultFormat;
+import org.openrdf.query.resultio.TupleQueryResultWriter;
+import org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamSource;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+import java.util.List;
+
+/**
+ * Add file description here!
+ * <p/>
+ * User: sschaffe
+ */
+public class SPARQLResultsHTMLWriter implements TupleQueryResultWriter {
+
+ private static final Logger log = LoggerFactory.getLogger(SPARQLResultsHTMLWriter.class);
+
+ private OutputStream out;
+ private ByteArrayOutputStream xmlOut;
+
+ private SPARQLResultsXMLWriter xmlWriter;
+
+ private Templates stylesheet;
+
+ public SPARQLResultsHTMLWriter(OutputStream out) {
+ this.out = out;
+ this.xmlOut = new ByteArrayOutputStream();
+ this.xmlWriter = new SPARQLResultsXMLWriter(xmlOut);
+ Source s_stylesheet = new StreamSource(SPARQLResultsHTMLWriter.class.getResourceAsStream("style.xsl"));
+ try {
+ stylesheet = TransformerFactory.newInstance().newTemplates(s_stylesheet);
+ } catch (TransformerConfigurationException e) {
+ log.error("could not compile stylesheet for rendering SPARQL results; result display not available!");
+ }
+ }
+
+
+ /**
+ * Gets the query result format that this writer uses.
+ */
+ @Override
+ public TupleQueryResultFormat getTupleQueryResultFormat() {
+ return new TupleQueryResultFormat("SPARQL/HTML","text/html", Charset.forName("UTF-8"), "html");
+ }
+
+ /**
+ * Indicates the start of a sequence of Solutions. The supplied bindingNames
+ * are an indication of the values that are in the Solutions. For example, a
+ * SeRQL query like <tt>select X, Y from {X} P {Y} </tt> will have binding
+ * names <tt>X</tt> and <tt>Y</tt>.
+ *
+ * @param bindingNames An ordered set of binding names.
+ */
+ @Override
+ public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
+ xmlWriter.startQueryResult(bindingNames);
+ }
+
+ /**
+ * Indicates the end of a sequence of solutions.
+ */
+ @Override
+ public void endQueryResult() throws TupleQueryResultHandlerException {
+ xmlWriter.endQueryResult();
+
+ // get server uri
+ String server_uri = KiWiContext.getInstance(ConfigurationService.class).getServerUri();
+
+ byte[] queryResult = xmlOut.toByteArray();
+
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
+ try {
+ Source input = new StreamSource(new ByteArrayInputStream(queryResult));
+
+ Transformer transformer = stylesheet.newTransformer();
+ transformer.setParameter("serverurl", server_uri);
+
+ JDOMResult result = new JDOMResult();
+ transformer.transform(input,result);
+ Document output = result.getDocument();
+
+ XMLOutputter printer = new XMLOutputter(Format.getPrettyFormat());
+ printer.output(output, writer);
+ writer.flush();
+
+ } catch (Exception ex) {
+ throw new TupleQueryResultHandlerException("error while transforming XML results to HTML",ex);
+ } finally {
+ try {
+ writer.close();
+ } catch (IOException e) {}
+ }
+
+ }
+
+ /**
+ * Handles a solution.
+ */
+ @Override
+ public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
+ xmlWriter.handleSolution(bindingSet);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/style.xsl
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/style.xsl b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/style.xsl
new file mode 100644
index 0000000..2b01551
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqlhtml/style.xsl
@@ -0,0 +1,193 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (C) 2013 Salzburg Research.
+
+ 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.
+
+-->
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:res="http://www.w3.org/2005/sparql-results#"
+ exclude-result-prefixes="res xsl">
+
+ <!--
+ <xsl:output
+ method="html"
+ media-type="text/html"
+ doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
+ indent="yes"
+ encoding="UTF-8"/>
+ -->
+
+ <!-- or this? -->
+
+ <xsl:output
+ method="xml"
+ indent="yes"
+ encoding="UTF-8"
+ doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
+ doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
+ omit-xml-declaration="no" />
+
+ <xsl:param name="serverurl" select="'http://localhost:8080/LMF/'"/>
+
+ <xsl:template name="header">
+ <div>
+ <h2>Header</h2>
+ <xsl:for-each select="res:head/res:link">
+ <p>Link to <xsl:value-of select="@href"/></p>
+ </xsl:for-each>
+ </div>
+ </xsl:template>
+
+ <xsl:template name="boolean-result">
+ <div>
+ <!--
+ <h2>Boolean Result</h2>
+ -->
+ <p>ASK => <xsl:value-of select="res:boolean"/></p>
+ </div>
+ </xsl:template>
+
+
+ <xsl:template name="vb-result">
+ <div>
+ <!--
+ <h2>Variable Bindings Result</h2>
+ <p>Ordered: <xsl:value-of select="res:results/@ordered"/></p>
+ <p>Distinct: <xsl:value-of select="res:results/@distinct"/></p>
+ -->
+
+ <table>
+ <xsl:text>
+ </xsl:text>
+ <tr style="background-color: #006D8F;color: white;">
+ <xsl:for-each select="res:head/res:variable">
+ <th><xsl:value-of select="@name"/></th>
+ </xsl:for-each>
+ </tr>
+ <xsl:text>
+ </xsl:text>
+ <xsl:for-each select="res:results/res:result">
+ <xsl:choose>
+ <xsl:when test="(position() mod 2) = 0">
+ <tr style="background-color:lightblue;">
+ <xsl:apply-templates select="."/>
+ </tr>
+ </xsl:when>
+ <xsl:otherwise>
+ <tr style="background-color:#DFF7FF;">
+ <xsl:apply-templates select="."/>
+ </tr>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </table>
+ </div>
+ </xsl:template>
+
+ <xsl:template match="res:result">
+ <xsl:variable name="current" select="."/>
+ <xsl:for-each select="//res:head/res:variable">
+ <xsl:variable name="name" select="@name"/>
+ <td>
+ <xsl:choose>
+ <xsl:when test="$current/res:binding[@name=$name]">
+ <!-- apply template for the correct value type (bnode, uri, literal) -->
+ <xsl:apply-templates select="$current/res:binding[@name=$name]"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- no binding available for this variable in this solution -->
+ </xsl:otherwise>
+ </xsl:choose>
+ </td>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template match="res:bnode">
+ <xsl:text>_:</xsl:text>
+ <xsl:value-of select="text()"/>
+ </xsl:template>
+
+ <xsl:template match="res:uri">
+ <xsl:variable name="uri" select="text()"/>
+ <a href="{$serverurl}resource?uri={$uri}">
+ <xsl:text><</xsl:text>
+ <xsl:value-of select="$uri"/>
+ <xsl:text>></xsl:text>
+ </a>
+ </xsl:template>
+
+ <xsl:template match="res:literal">
+ <xsl:text>"</xsl:text>
+ <xsl:value-of select="text()"/>
+ <xsl:text>"</xsl:text>
+
+ <xsl:choose>
+ <xsl:when test="@datatype">
+ <!-- datatyped literal value -->
+ ^^<<xsl:value-of select="@datatype"/>>
+ </xsl:when>
+ <xsl:when test="@xml:lang">
+ <!-- lang-string -->
+ @<xsl:value-of select="@xml:lang"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="res:sparql">
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
+ <title>SPARQL Query Results</title>
+ <style>
+ <![CDATA[
+ h1 { font-size: 150% ; }
+ h2 { font-size: 125% ; }
+ table { border-collapse: collapse ; border: 2px solid white ; }
+ td, th
+ { border: 2px solid white ;
+ padding-left:0.5em; padding-right: 0.5em;
+ padding-top:0.2ex ; padding-bottom:0.2ex
+ }
+
+ ]]>
+ </style>
+ </head>
+ <body>
+
+
+ <h1>SPARQL Query Results</h1>
+
+ <xsl:if test="res:head/res:link">
+ <xsl:call-template name="header"/>
+ </xsl:if>
+
+ <xsl:choose>
+ <xsl:when test="res:boolean">
+ <xsl:call-template name="boolean-result" />
+ </xsl:when>
+
+ <xsl:when test="res:results">
+ <xsl:call-template name="vb-result" />
+ </xsl:when>
+
+ </xsl:choose>
+
+
+ </body>
+ </html>
+ </xsl:template>
+</xsl:stylesheet>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLBooleanJSONWriter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLBooleanJSONWriter.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLBooleanJSONWriter.java
new file mode 100644
index 0000000..6c93cbc
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLBooleanJSONWriter.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.services.sparqlio.sparqljson;
+
+import org.openrdf.query.resultio.BooleanQueryResultFormat;
+import org.openrdf.query.resultio.BooleanQueryResultWriter;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.Charset;
+
+/**
+ * Add file description here!
+ * <p/>
+ * User: sschaffe
+ */
+public class SPARQLBooleanJSONWriter implements BooleanQueryResultWriter {
+
+
+ private OutputStream out;
+
+ public SPARQLBooleanJSONWriter(OutputStream out) {
+ this.out = out;
+ }
+
+ /**
+ * Gets the query result format that this writer uses.
+ */
+ @Override
+ public BooleanQueryResultFormat getBooleanQueryResultFormat() {
+ return new BooleanQueryResultFormat("SPARQL/JSON",
+ "application/sparql-results+json", Charset.forName("UTF-8"), "srj");
+ }
+
+ /**
+ * Writes the specified boolean value.
+ */
+ @Override
+ public void write(boolean value) throws IOException {
+ PrintWriter writer = new PrintWriter(new OutputStreamWriter(out));
+ writer.println("{ \"head\": {}, \"boolean\": \""+value+"\" }");
+ writer.flush();
+ writer.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLResultsJSONWriter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLResultsJSONWriter.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLResultsJSONWriter.java
new file mode 100644
index 0000000..5c691f8
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/services/sparqlio/sparqljson/SPARQLResultsJSONWriter.java
@@ -0,0 +1,290 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.services.sparqlio.sparqljson;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.Iterator;
+import java.util.List;
+
+import info.aduna.io.IndentingWriter;
+import info.aduna.text.StringUtil;
+
+import org.openrdf.model.BNode;
+import org.openrdf.model.Literal;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.query.Binding;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.TupleQueryResultHandlerException;
+import org.openrdf.query.resultio.TupleQueryResultFormat;
+import org.openrdf.query.resultio.TupleQueryResultWriter;
+
+/**
+ * A TupleQueryResultWriter that writes query results in the <a
+ * href="http://www.w3.org/TR/rdf-sparql-json-res/">SPARQL Query Results JSON
+ * Format</a>.
+ */
+public class SPARQLResultsJSONWriter implements TupleQueryResultWriter {
+
+ /*-----------*
+ * Variables *
+ *-----------*/
+
+ private IndentingWriter writer;
+
+ private boolean firstTupleWritten;
+
+ /*--------------*
+ * Constructors *
+ *--------------*/
+
+ public SPARQLResultsJSONWriter(OutputStream out) {
+ Writer w = new OutputStreamWriter(out, Charset.forName("UTF-8"));
+ w = new BufferedWriter(w, 1024);
+ writer = new IndentingWriter(w);
+ }
+
+ /*---------*
+ * Methods *
+ *---------*/
+
+ public final TupleQueryResultFormat getTupleQueryResultFormat() {
+ return TupleQueryResultFormat.JSON;
+ }
+
+ public void startQueryResult(List<String> columnHeaders)
+ throws TupleQueryResultHandlerException
+ {
+ try {
+ openBraces();
+
+ // Write header
+ writeKey("head");
+ openBraces();
+ writeKeyValue("vars", columnHeaders);
+ closeBraces();
+
+ writeComma();
+
+ // Write results
+ writeKey("results");
+ openBraces();
+
+ writeKey("bindings");
+ openArray();
+
+ firstTupleWritten = false;
+ }
+ catch (IOException e) {
+ throw new TupleQueryResultHandlerException(e);
+ }
+ }
+
+ public void endQueryResult()
+ throws TupleQueryResultHandlerException
+ {
+ try {
+ closeArray(); // bindings array
+ closeBraces(); // results braces
+ closeBraces(); // root braces
+ writer.flush();
+ }
+ catch (IOException e) {
+ throw new TupleQueryResultHandlerException(e);
+ }
+ }
+
+ public void handleSolution(BindingSet bindingSet)
+ throws TupleQueryResultHandlerException
+ {
+ try {
+ if (firstTupleWritten) {
+ writeComma();
+ }
+ else {
+ firstTupleWritten = true;
+ }
+
+ openBraces(); // start of new solution
+
+ Iterator<Binding> bindingIter = bindingSet.iterator();
+ while (bindingIter.hasNext()) {
+ Binding binding = bindingIter.next();
+
+ writeKeyValue(binding.getName(), binding.getValue());
+
+ if (bindingIter.hasNext()) {
+ writeComma();
+ }
+ }
+
+ closeBraces(); // end solution
+
+ writer.flush();
+ }
+ catch (IOException e) {
+ throw new TupleQueryResultHandlerException(e);
+ }
+ }
+
+ private void writeKeyValue(String key, String value)
+ throws IOException
+ {
+ writeKey(key);
+ writeString(value);
+ }
+
+ private void writeKeyValue(String key, Value value)
+ throws IOException, TupleQueryResultHandlerException
+ {
+ writeKey(key);
+ writeValue(value);
+ }
+
+ private void writeKeyValue(String key, Iterable<String> array)
+ throws IOException
+ {
+ writeKey(key);
+ writeArray(array);
+ }
+
+ private void writeKey(String key)
+ throws IOException
+ {
+ writeString(key);
+ writer.write(": ");
+ }
+
+ private void writeValue(Value value)
+ throws IOException, TupleQueryResultHandlerException
+ {
+ writer.write("{ ");
+
+ if (value instanceof URI) {
+ writeKeyValue("type", "uri");
+ writer.write(", ");
+ writeKeyValue("value", ((URI)value).toString());
+ }
+ else if (value instanceof BNode) {
+ writeKeyValue("type", "bnode");
+ writer.write(", ");
+ writeKeyValue("value", ((BNode)value).getID());
+ }
+ else if (value instanceof Literal) {
+ Literal lit = (Literal)value;
+
+ if (lit.getLanguage() != null) {
+ writeKeyValue("xml:lang", lit.getLanguage());
+ writer.write(", ");
+ }
+ if (lit.getDatatype() != null) {
+ writeKeyValue("datatype", lit.getDatatype().toString());
+ writer.write(", ");
+ }
+
+ writeKeyValue("type", "literal");
+
+ writer.write(", ");
+ writeKeyValue("value", lit.getLabel());
+ }
+ else {
+ throw new TupleQueryResultHandlerException("Unknown Value object type: " + value.getClass());
+ }
+
+ writer.write(" }");
+ }
+
+ private void writeString(String value)
+ throws IOException
+ {
+ // Escape special characters
+ value = StringUtil.gsub("\\", "\\\\", value);
+ value = StringUtil.gsub("\"", "\\\"", value);
+ value = StringUtil.gsub("/", "\\/", value);
+ value = StringUtil.gsub("\b", "\\b", value);
+ value = StringUtil.gsub("\f", "\\f", value);
+ value = StringUtil.gsub("\n", "\\n", value);
+ value = StringUtil.gsub("\r", "\\r", value);
+ value = StringUtil.gsub("\t", "\\t", value);
+
+ writer.write("\"");
+ writer.write(value);
+ writer.write("\"");
+ }
+
+ private void writeArray(Iterable<String> array)
+ throws IOException
+ {
+ writer.write("[ ");
+
+ Iterator<String> iter = array.iterator();
+ while (iter.hasNext()) {
+ String value = iter.next();
+
+ writeString(value);
+
+ if (iter.hasNext()) {
+ writer.write(", ");
+ }
+ }
+
+ writer.write(" ]");
+ }
+
+ private void openArray()
+ throws IOException
+ {
+ writer.write("[");
+ writer.writeEOL();
+ writer.increaseIndentation();
+ }
+
+ private void closeArray()
+ throws IOException
+ {
+ writer.writeEOL();
+ writer.decreaseIndentation();
+ writer.write("]");
+ }
+
+ private void openBraces()
+ throws IOException
+ {
+ writer.write("{");
+ writer.writeEOL();
+ writer.increaseIndentation();
+ }
+
+ private void closeBraces()
+ throws IOException
+ {
+ writer.writeEOL();
+ writer.decreaseIndentation();
+ writer.write("}");
+ }
+
+ private void writeComma()
+ throws IOException
+ {
+ writer.write(", ");
+ writer.writeEOL();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
new file mode 100644
index 0000000..a36e6fe
--- /dev/null
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
@@ -0,0 +1,452 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * 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.
+ */
+package org.apache.marmotta.platform.sparql.webservices;
+
+import org.apache.marmotta.platform.sparql.api.sparql.SparqlService;
+import org.apache.marmotta.platform.sparql.services.sparqlio.rdf.SPARQLGraphResultWriter;
+import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLBooleanHTMLWriter;
+import org.apache.marmotta.platform.sparql.services.sparqlio.sparqlhtml.SPARQLResultsHTMLWriter;
+import org.apache.marmotta.platform.sparql.services.sparqlio.sparqljson.SPARQLBooleanJSONWriter;
+import org.apache.marmotta.platform.sparql.services.sparqlio.sparqljson.SPARQLResultsJSONWriter;
+import com.google.common.collect.Lists;
+import com.google.common.io.CharStreams;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.exception.InvalidArgumentException;
+import org.apache.marmotta.platform.core.exception.LMFException;
+import org.apache.marmotta.platform.core.util.WebServiceUtil;
+import org.apache.commons.lang.StringUtils;
+import org.apache.marmotta.commons.http.ContentType;
+import org.apache.marmotta.commons.http.LMFHttpUtils;
+import org.openrdf.query.MalformedQueryException;
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.UpdateExecutionException;
+import org.openrdf.query.resultio.BooleanQueryResultWriter;
+import org.openrdf.query.resultio.TupleQueryResultWriter;
+import org.openrdf.query.resultio.sparqlxml.SPARQLBooleanXMLWriter;
+import org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLWriter;
+import org.openrdf.query.resultio.text.BooleanTextWriter;
+import org.openrdf.query.resultio.text.csv.SPARQLResultsCSVWriter;
+import org.slf4j.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Execute SPARQL query (both query and update) on the LMF triple store
+ * according the SPARQL 1.1 Protocol
+ *
+ * @link http://www.w3.org/TR/sparql11-protocol/
+ * @author Sebastian Schaffert
+ * @author Sergio Fernández
+ */
+@ApplicationScoped
+@Path("/sparql")
+public class SparqlWebService {
+
+ @Inject
+ private Logger log;
+
+ @Inject
+ private SparqlService sparqlService;
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ /**
+ * For CORS operations TODO: make it more fine grained (maybe user dependent)
+ * + TODO filter chain do not work properly
+ *
+ * @param reqHeaders
+ * @return responde
+ */
+ @OPTIONS
+ @Path("/update")
+ public Response optionsResourceRemote(@HeaderParam("Access-Control-Request-Headers") String reqHeaders) {
+ if(reqHeaders == null) {
+ reqHeaders = "Accept, Content-Type";
+ }
+ return Response.ok()
+ .header("Allow", "POST")
+ .header("Access-Control-Allow-Methods","POST")
+ .header("Access-Control-Allow-Headers", reqHeaders)
+ .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("sparql.allow_origin","*"))
+ .build();
+
+ }
+
+ /**
+ * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed as query parameter to the
+ * GET request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
+ * <p/>
+ * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
+ *
+ * @param query the SPARQL 1.1 Query as a string parameter
+ * @param resultType the format for serializing the query results ("html", "json", or "xml")
+ * @HTTP 200 in case the query was executed successfully
+ * @HTTP 500 in case there was an error during the query evaluation
+ * @return the query result in the format passed as argument
+ */
+ @GET
+ @Path("/select")
+ public Response query(@QueryParam("query") String query, @QueryParam("output") String resultType, @Context HttpServletRequest request) {
+ if(resultType == null) {
+ List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
+ List<ContentType> offeredTypes = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json","text/html", "application/rdf+xml", "text/csv"));
+
+ ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+
+ if(bestType != null) {
+ resultType = bestType.getMime();
+ }
+ }
+
+ try {
+ if(resultType != null) {
+ if (StringUtils.isNotBlank(query))
+ return buildQueryResponse(resultType, query);
+ else {
+ if (parseSubType(resultType).equals("html"))
+ return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/snorql/snorql.html")).build();
+ else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
+ }
+ } else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
+ } catch (InvalidArgumentException ex) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
+ } catch(Exception e) {
+ log.error("query execution threw an exception",e);
+
+ return Response.serverError().entity("query not supported").build();
+ }
+ }
+
+ /**
+ * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed as form parameter to the
+ * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
+ * <p/>
+ * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
+ *
+ * @param query the SPARQL 1.1 Query as a string parameter
+ * @param resultType the format for serializing the query results ("html", "json", or "xml")
+ * @HTTP 200 in case the query was executed successfully
+ * @HTTP 500 in case there was an error during the query evaluation
+ * @return the query result in the format passed as argument
+ */
+ @POST
+ @Consumes("application/x-www-form-urlencoded")
+ @Path("/select")
+ public Response queryPostForm(@QueryParam("output") String resultType, @FormParam("query") String query, @Context HttpServletRequest request) {
+ try {
+ if(resultType == null) {
+ List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
+ List<ContentType> offeredTypes = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json","text/html", "application/rdf+xml", "text/csv"));
+
+ ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+
+ if(bestType != null) {
+ resultType = bestType.getMime();
+ }
+ }
+ if(resultType != null) {
+ if (StringUtils.isNotBlank(query))
+ return buildQueryResponse(resultType, query);
+ else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
+ } else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
+ } catch (InvalidArgumentException ex) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
+ } catch(Exception e) {
+ log.error("query execution threw an exception",e);
+
+ return Response.serverError().entity("query not supported").build();
+ }
+ }
+
+ /**
+ * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed in the body of the
+ * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
+ * <p/>
+ * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
+ *
+ * @param request the servlet request (to retrieve the SPARQL 1.1 Query passed in the body of the POST request)
+ * @param resultType the format for serializing the query results ("html", "json", or "xml")
+ * @HTTP 200 in case the query was executed successfully
+ * @HTTP 500 in case there was an error during the query evaluation
+ * @return the query result in the format passed as argument
+ */
+ @POST
+ @Path("/select")
+ public Response queryPost(@QueryParam("output") String resultType, @Context HttpServletRequest request) {
+ try {
+ if(resultType == null) {
+ List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
+ List<ContentType> offeredTypes = LMFHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json","text/html", "application/rdf+xml", "text/csv"));
+
+ ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+
+ if(bestType != null) {
+ resultType = bestType.getMime();
+ }
+ }
+
+ if(resultType != null) {
+ String query = CharStreams.toString(request.getReader());
+ if (query != null && !query.equals(""))
+ return buildQueryResponse(resultType, query);
+ else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
+ } else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no result format specified or unsupported result format").build();
+ } catch (InvalidArgumentException ex) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
+ } catch(Exception e) {
+ log.error("query execution threw an exception",e);
+
+ return Response.serverError().entity("query not supported").build();
+ }
+ }
+
+ /**
+ * Execute a SPARQL 1.1 tuple query on the LMF triple store using the query passed as form parameter to the
+ * POST request. Result will be formatted using the result type passed as argument (either "html", "json" or "xml").
+ * <p/>
+ * see SPARQL 1.1 Query syntax at http://www.w3.org/TR/sparql11-query/
+ *
+ * @param query the SPARQL 1.1 Query as a string parameter
+ * @param resultType the format for serializing the query results ("html", "json", or "xml")
+ * @HTTP 200 in case the query was executed successfully
+ * @HTTP 500 in case there was an error during the query evaluation
+ * @return the query result in the format passed as argument
+ */
+ @POST
+ @Path("/snorql")
+ public Response snorqlPost(@FormParam("output") String resultType, @FormParam("query") String query) {
+ try {
+ return buildQueryResponse(resultType, query);
+ } catch(Exception e) {
+ log.error("query execution threw an exception",e);
+
+ return Response.serverError().entity("query not supported").build();
+ }
+ }
+
+ /**
+ * Execute a SPARQL 1.1 Update request passed in the query parameter of the GET. The update will
+ * be carried out
+ * on the LMF triple store.
+ * <p/>
+ * see SPARQL 1.1 Update syntax at http://www.w3.org/TR/sparql11-update/
+ *
+ * @param update the update query in SPARQL 1.1 syntax
+ * @param query the update query in SPARUL syntax
+ * @HTTP 200 in case the update was carried out successfully
+ * @HTTP 500 in case the update was not successful
+ * @return empty content in case the update was successful, the error message in case an error occurred
+ */
+ @GET
+ @Path("/update")
+ public Response updateGet(@QueryParam("update") String update, @QueryParam("query") String query, @QueryParam("output") String resultType,
+ @Context HttpServletRequest request) {
+ try {
+ String q = getUpdateQuery(update, query);
+ if (StringUtils.isNotBlank(q)) {
+ sparqlService.update(QueryLanguage.SPARQL, q);
+ return Response.ok().build();
+ } else {
+ if (resultType == null) {
+ List<ContentType> acceptedTypes = LMFHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
+ List<ContentType> offeredTypes = LMFHttpUtils.parseStringList(Lists.newArrayList("*/*", "text/html"));
+ ContentType bestType = LMFHttpUtils.bestContentType(offeredTypes, acceptedTypes);
+ if (bestType != null) {
+ resultType = bestType.getMime();
+ }
+ }
+ if (parseSubType(resultType).equals("html"))
+ return Response.seeOther(new URI(configurationService.getServerUri() + "sparql/admin/update.html")).build();
+ else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query specified").build();
+ }
+ } catch (MalformedQueryException ex) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(ex)).build();
+ } catch(UpdateExecutionException e) {
+ log.error("update execution threw an exception",e);
+ return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+ } catch (LMFException e) {
+ return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+ } catch (URISyntaxException e) {
+ return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+ }
+ }
+
+ /**
+ * Get right update query from both possible parameters, for keeping
+ * backward compatibility with the old parameter
+ *
+ * @param update update parameter
+ * @param query query parameter
+ * @return
+ */
+ private String getUpdateQuery(String update, String query) {
+ if (StringUtils.isNotBlank(update))
+ return update;
+ else if (StringUtils.isNotBlank(query)) {
+ log.warn("Update query still uses the old 'query' parameter");
+ return query;
+ } else
+ return null;
+ }
+
+ /**
+ * Execute a SPARQL 1.1 Update request passed in the request body of the POST. The update will
+ * be carried out
+ * on the LMF triple store.
+ * <p/>
+ * see SPARQL 1.1 Update syntax at http://www.w3.org/TR/sparql11-update/
+ *
+ * @param request the servlet request (to retrieve the SPARQL 1.1 Update query passed in the
+ * body of the POST request)
+ * @HTTP 200 in case the update was carried out successfully
+ * @HTTP 500 in case the update was not successful
+ * @return empty content in case the update was successful, the error message in case an error
+ * occurred
+ */
+ @POST
+ @Path("/update")
+ public Response updatePost(@Context HttpServletRequest request) {
+ try {
+ String query = CharStreams.toString(request.getReader());
+ if (StringUtils.isNotBlank(query)) {
+ sparqlService.update(QueryLanguage.SPARQL, query);
+ return Response.ok().build();
+ } else
+ return Response.status(Response.Status.BAD_REQUEST).entity("no SPARQL query given").build();
+ } catch (MalformedQueryException ex) {
+ return Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(ex)).build();
+ } catch(UpdateExecutionException e) {
+ log.error("update execution threw an exception",e);
+ return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+ } catch (LMFException e) {
+ return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+ } catch (IOException e) {
+ return Response.serverError().entity(WebServiceUtil.jsonErrorResponse(e)).build();
+ }
+ }
+
+ private Response buildQueryResponse(final String resultType, final String query) throws Exception {
+ StreamingOutput entity = new StreamingOutput() {
+ @Override
+ public void write(OutputStream output) throws IOException, WebApplicationException {
+ try {
+ sparqlService.query(QueryLanguage.SPARQL,query,getTupleResultWriter(resultType,output),getBooleanResultWriter(resultType,output), getGraphResultWriter(resultType,output));
+ } catch (LMFException ex) {
+ throw new WebApplicationException(ex.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(ex)).build());
+ } catch (QueryEvaluationException e) {
+ throw new WebApplicationException(e.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(e)).build());
+ } catch (MalformedQueryException e) {
+ throw new WebApplicationException(e.getCause(), Response.status(Response.Status.BAD_REQUEST).entity(WebServiceUtil.jsonErrorResponse(e)).build());
+ }
+ }
+ };
+
+ //set returntype
+ String s = "";
+ if(resultType ==null) {
+ s = "application/sparql-results+xml;charset=utf-8";
+ } else if(parseSubType(resultType).equals("html") ) {
+ s = "text/html;charset=utf-8";
+ } else if(parseSubType(resultType).equals("json") ) {
+ s = "application/sparql-results+json;charset=utf-8";
+ } else if(parseSubType(resultType).equals("rdf+xml") ) {
+ s = "application/rdf+xml;charset=utf-8";
+ } else if(parseSubType(resultType).equals("rdf+n3") ) {
+ s = "text/rdf+n3;charset=utf-8";
+ } else if(parseSubType(resultType).equals("n3") ) {
+ s = "text/rdf+n3;charset=utf-8";
+ } else if(parseSubType(resultType).equals("csv") ) {
+ s = "text/csv;charset=utf-8";
+ } else {
+ s = "application/sparql-results+xml;charset=utf-8";
+ }
+
+ Response r = Response.ok().entity(entity).header("Content-Type", s).build();
+ return r;
+ }
+
+ private static Pattern subTypePattern = Pattern.compile("[a-z]+/([a-z0-9-._]+\\+)?([a-z0-9-._]+)(;.*)?");
+ private String parseSubType(String mimeType) {
+ Matcher matcher = subTypePattern.matcher(mimeType);
+ if (matcher.matches())
+ return matcher.group(2);
+ else
+ return mimeType;
+ }
+
+
+ private TupleQueryResultWriter getTupleResultWriter(String format, OutputStream os) {
+ //build outputwriter
+ final TupleQueryResultWriter out;
+ if(format == null) {
+ out = new SPARQLResultsXMLWriter(os);
+ } else if(parseSubType(format).equals("html")) {
+ out = new SPARQLResultsHTMLWriter(os);
+ } else if(parseSubType(format).equals("json")) {
+ out = new SPARQLResultsJSONWriter(os);
+ } else if(parseSubType(format).equals("xml")) {
+ out = new SPARQLResultsXMLWriter(os);
+ } else if(parseSubType(format).equals("csv")) {
+ out = new SPARQLResultsCSVWriter(os);
+ } else throw new InvalidArgumentException("could not produce format "+format);
+ return out;
+ }
+
+ private BooleanQueryResultWriter getBooleanResultWriter(String format, OutputStream os) {
+ //build outputwriter
+ final BooleanQueryResultWriter out;
+ if(format == null) {
+ out = new SPARQLBooleanXMLWriter(os);
+ } else if(parseSubType(format).equals("html")) {
+ out = new SPARQLBooleanHTMLWriter(os);
+ } else if(parseSubType(format).equals("json")) {
+ out = new SPARQLBooleanJSONWriter(os);
+ } else if(parseSubType(format).equals("xml")) {
+ out = new SPARQLBooleanXMLWriter(os);
+ } else if(parseSubType(format).equals("csv")) {
+ out = new BooleanTextWriter(os);
+ } else throw new InvalidArgumentException("could not produce format "+format);
+ return out;
+ }
+
+ protected SPARQLGraphResultWriter getGraphResultWriter(String format, OutputStream os) {
+ return new SPARQLGraphResultWriter(os,format);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-sparql/src/main/resources/kiwi-module.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/resources/kiwi-module.properties b/platform/marmotta-sparql/src/main/resources/kiwi-module.properties
index de3957d..35d02fe 100644
--- a/platform/marmotta-sparql/src/main/resources/kiwi-module.properties
+++ b/platform/marmotta-sparql/src/main/resources/kiwi-module.properties
@@ -22,7 +22,7 @@ subtitle = Queries and Updates
icon_small = /admin/img/sparql_small.png
-webservices=at.newmedialab.lmf.sparql.webservices.SparqlWebService
+webservices=org.apache.marmotta.platform.sparql.webservices.SparqlWebService
adminpages=/admin/about.html,/admin/configuration.html,/admin/snorql/snorql.html,/admin/update.html
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AccountService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AccountService.java b/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AccountService.java
deleted file mode 100644
index 9ce7fa5..0000000
--- a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AccountService.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * 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.
- */
-package at.newmedialab.lmf.user.api;
-
-import at.newmedialab.lmf.user.model.UserAccount;
-import org.apache.marmotta.platform.core.model.user.KiWiUser;
-import org.openrdf.model.URI;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * Service to manage UserAccounts. {@link UserAccount}s are used to manage login and access to the
- * LMF System.
- *
- * @author Jakob Frank <ja...@salzburgresearch.at>
- * @see UserAccount
- */
-public interface AccountService {
-
- /**
- * Create an user account
- *
- * @param login the unique username/login
- * @return the newly created {@link UserAccount}
- */
- UserAccount createAccount(String login);
-
- /**
- * Create an user account and set first- and lastName in the user profile (foaf)
- *
- * @param login the unique username/login (also foaf:nick)
- * @param firstName the value for foaf:firstName, may be null
- * @param lastName the value for foaf:lastName, may be null
- * @return the newly created {@link UserAccount}
- */
- UserAccount createAccount(String login, String firstName, String lastName);
-
- /**
- * Create the default accounts, currently only admin
- */
- void createDefaultAccounts();
-
- /**
- * Retrieve the user account for the given login name
- *
- * @param login the login name
- * @return the {@link UserAccount} for the given login name
- */
- UserAccount getAccount(String login);
-
- /**
- * Retrieve the user account for the given (User)-Resource
- *
- *
- * @param userResource the user resource (foaf:person)
- * @return the corresponding {@link UserAccount}, or <code>null</code> if no account present.
- */
- UserAccount getAccount(URI userResource);
-
- /**
- * Retrieve the user account for a given {@link KiWiUser} (facaded user resource)
- *
- * @param user the {@link KiWiUser}
- * @return the corresponding {@link UserAccount}, of <code>null</code> if none present.
- * @see #getAccount(org.openrdf.model.URI)
- */
- UserAccount getAccount(KiWiUser user);
-
- /**
- * Deletes the given user account. The user will (obviously loose all access-rights to the
- * system)
- *
- * @param account the {@link UserAccount} to delete.
- */
- void deleteAccount(UserAccount account);
-
- /**
- * Update/Set the password for the given {@link UserAccount}
- *
- * @param account the {@link UserAccount} to modify
- * @param passwd the new password
- * @return the modified {@link UserAccount}
- */
- UserAccount setPassword(UserAccount account, String passwd);
-
- /**
- * Check the credentials for the given {@link UserAccount}
- *
- * @param account the {@link UserAccount} to authenticate
- * @param passwd the password (plain)
- * @return <code>true</code> if the password matched the password of the {@link UserAccount}
- */
- boolean checkPassword(UserAccount account, String passwd);
-
- /**
- * Check the credentials for the given login
- *
- * @param login the login/account name/user name
- * @param passwd the password (plain)
- * @return <code>true</code> if the password matched the logins' {@link UserAccount} password
- */
- boolean checkPassword(String login, String passwd);
-
- /**
- * Set the roles for the given {@link UserAccount}
- *
- * @param account the {@link UserAccount} to modify
- * @param roles the roles (names) of the account
- * @see UserAccount#setRoles(Set)
- */
- void setRoles(UserAccount account, Set<String> roles);
-
- /**
- * Retrieve the roles for the given {@link UserAccount}
- *
- * @param account the {@link UserAccount}
- * @return a {@link Set} containing the role-names of the given {@link UserAccount}
- * @see UserAccount#getRoles()
- */
- Set<String> getRoles(UserAccount account);
-
- /**
- * Add a single role to the roles of the given {@link UserAccount}
- *
- * @param account the {@link UserAccount} to modify
- * @param role the role(-name) to add
- */
- void addRole(UserAccount account, String role);
-
- /**
- * Remove a single role from the roles of the given {@link UserAccount}
- *
- * @param account the {@link UserAccount} to modify
- * @param role the role(-name) to remove
- */
- void removeRole(UserAccount account, String role);
-
- /**
- * Check whether the given {@link UserAccount} has the role in question.
- *
- * @param account the {@link UserAccount} to query
- * @param role the role(-name) in question.
- * @return true if the given {@link UserAccount} has the role in question
- */
- boolean hasRole(UserAccount account, String role);
-
- /**
- * Returns a {@link List} of {@link UserAccount} that have the given role associated.
- *
- * @param role the role(-name)
- * @return a {@link List} of {@link UserAccount} that have the given role associated.
- */
- List<UserAccount> listAccounts(String role);
-
- /**
- * List all {@link UserAccount}.
- *
- * @return a {@link List} of all {@link UserAccount}
- */
- List<UserAccount> listAccounts();
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationProvider.java b/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationProvider.java
deleted file mode 100644
index e6987fc..0000000
--- a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * 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.
- */
-package at.newmedialab.lmf.user.api;
-
-import at.newmedialab.lmf.user.model.UserAccount;
-
-public interface AuthenticationProvider {
-
- boolean checkPassword(UserAccount login, String passwd);
-
- boolean updatePassword(UserAccount login, String newPasswd);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationService.java b/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationService.java
deleted file mode 100644
index 6915592..0000000
--- a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/AuthenticationService.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * 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.
- */
-package at.newmedialab.lmf.user.api;
-
-import java.util.Set;
-
-/**
- * A service that abstracts simple user authentication. The standard backend implements authentication from the
- * LMF configuration file using the following configuration properties:
- * security.user.<username>.password - the plaintext password of the user with login <username>
- * security.user.<username>.roles - the roles of the user with login <username>
- * <p/>
- * Author: Sebastian Schaffert
- */
-public interface AuthenticationService {
-
- /**
- * Authenticate the user with the given login and password. Returns true on success, false if the user does not
- * exist or the passwords do not match.
- *
- * @param login login of the user to authenticate
- * @param password password of the user to authenticate
- * @return true on success, false if the user does not exist or the passwords do not match.
- */
- public boolean authenticateUser(String login, String password);
-
-
- /**
- * Change the password of the user with the given login to the given new password. The implementation may decide
- * where to persist the password in a secure manner and whether to apply additional security like password hashing.
- *
- * @param login
- * @param password
- * @return
- */
- public void setUserPassword(String login, String password);
-
-
- /**
- * Return the roles that are assigned to the user (a list of strings that can be chosen by the administrator as
- * needed).
- * @param login login name of the user for whom to return the roles
- * @return a list of strings with the role names currently assigned to the user
- */
- public Set<String> listUserRoles(String login);
-
-
- /**
- * Add the role with the given name to the user with the given login.
- *
- * @param login the login name of the user with whom to associate roles
- * @param role the role name to associate with the user
- */
- public void addUserRole(String login, String role);
-
- /**
- * Remove the role with the given name from the user with the given login.
- *
- * @param login the login name of the user from whom to remove the role
- * @param role the role name to remove from the list of roles of the user
- */
- public void removeUserRole(String login, String role);
-
- /**
- * Returns a list of available {@link AuthenticationProvider} names.
- */
- public Set<String> listAuthProviderNames();
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/69cbd57a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/UserConfigurationService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/UserConfigurationService.java b/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/UserConfigurationService.java
deleted file mode 100644
index cc425ba..0000000
--- a/platform/marmotta-user/src/main/java/at/newmedialab/lmf/user/api/UserConfigurationService.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * 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.
- */
-package at.newmedialab.lmf.user.api;
-
-import at.newmedialab.lmf.user.model.UserAccount;
-
-import java.util.List;
-
-/**
- * Add file description here!
- * <p/>
- * Author: Sebastian Schaffert
- */
-public interface UserConfigurationService {
-
-
- /**
- * Check whether the given configuration is set for the given user.
- *
- * @param user
- * @param key
- * @return
- */
- public boolean isUserConfigurationSet(UserAccount user, String key);
-
- /**
- * Get the configuration for the given user and key. If there is no such configuration, a new one is
- * created with empty value (returns null).
- *
- * @param user the user for whom to get the configuration
- * @param key unique configuration key for lookup
- * @return a configuration object with either the configured value or null as value
- */
- public String getUserConfiguration(UserAccount user, String key);
-
- /**
- * Get the configuration for the given user and key. If there is no such configuration, a new one is
- * created using the provided defaultValue as string value.
- *
- * @param user the user for whom to get the configuration
- * @param key unique configuration key for lookup
- * @param defaultValue default value if configuration not found
- * @return a configuration object with either the configured value or defaultValue
- */
- public String getUserConfiguration(UserAccount user, String key, String defaultValue);
-
-
- /**
- * Set the configuration "key" to the string value "value".
- * @param key
- * @param value
- */
- public void setUserConfiguration(UserAccount user, String key, String value);
-
- /**
- * Set the configuration "key" to the string value "value".
- * @param key
- * @param values
- */
- public void setUserListConfiguration(UserAccount user, String key, List<String> values);
-
-
- /**
- * Return the list configuration value of the given key for the given user. If there is
- * no value for the key, returns the empty list.
- *
- * @param user
- */
- public List<Object> getUserListConfiguration(UserAccount user, String key);
-
- /**
- * Return the list configuration value of the given key for the given user. Returns the
- * given defaultValue if no configuration is found for the given key.
- *
- * @param user
- */
- public List<Object> getUserListConfiguration(UserAccount user, String key, List<Object> defaultValue);
-
- /**
- * Remove the user configuration identified by "key" from the database.
- * @param key
- */
- public void removeUserConfiguration(UserAccount user, String key);
-
-
-}