You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/02/21 16:30:45 UTC
[7/55] git commit: MARMOTTA-106: merged sesame-commons into
marmotta-commons
MARMOTTA-106: merged sesame-commons into marmotta-commons
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/c77916e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/c77916e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/c77916e8
Branch: refs/heads/master
Commit: c77916e81341ebf9604880ae189c958d06258b2d
Parents: 381dd3d
Author: Jakob Frank <ja...@apache.org>
Authored: Thu Feb 21 14:15:05 2013 +0100
Committer: Jakob Frank <ja...@apache.org>
Committed: Thu Feb 21 14:15:05 2013 +0100
----------------------------------------------------------------------
commons/marmotta-commons/pom.xml | 39 +
.../sesame/commons/http/ETagGenerator.java | 105 +
.../sesame/commons/model/BNodeCommons.java | 47 +
.../sesame/commons/model/LiteralCommons.java | 182 ++
.../sesame/commons/model/Namespaces.java | 128 +
.../sesame/commons/model/URICommons.java | 77 +
.../sesame/commons/repository/ExceptionUtils.java | 56 +
.../commons/repository/ResourceConnection.java | 66 +
.../sesame/commons/repository/ResourceUtils.java | 1299 +++++++++++
.../sesame/commons/repository/ResultUtils.java | 137 ++
.../newmedialab/sesame/commons/util/DateUtils.java | 162 ++
.../newmedialab/sesame/commons/util/HashUtils.java | 66 +
.../newmedialab/sesame/commons/util/JSONUtils.java | 172 ++
.../marmotta/commons/constants/Namespace.java | 1793 +++++++++++++++
.../sesame/commons/http/ETagGeneratorTest.java | 120 +
.../sesame/commons/model/LiteralCommonsTest.java | 133 ++
.../sesame/commons/model/ResourceUtilsTest.java | 693 ++++++
.../sesame/commons/model/URICommonsTest.java | 71 +
.../src/test/resources/foaf/demo-data.foaf | 69 +
commons/pom.xml | 3 +-
.../sesame/commons/constants/Namespace.java | 1793 ---------------
.../sesame/commons/http/ETagGenerator.java | 105 -
.../sesame/commons/model/BNodeCommons.java | 47 -
.../sesame/commons/model/LiteralCommons.java | 182 --
.../sesame/commons/model/Namespaces.java | 128 -
.../sesame/commons/model/URICommons.java | 77 -
.../sesame/commons/repository/ExceptionUtils.java | 56 -
.../commons/repository/ResourceConnection.java | 66 -
.../sesame/commons/repository/ResourceUtils.java | 1299 -----------
.../sesame/commons/repository/ResultUtils.java | 137 --
.../newmedialab/sesame/commons/util/DateUtils.java | 162 --
.../newmedialab/sesame/commons/util/HashUtils.java | 66 -
.../newmedialab/sesame/commons/util/JSONUtils.java | 172 --
.../sesame/commons/http/ETagGeneratorTest.java | 120 -
.../sesame/commons/model/LiteralCommonsTest.java | 133 --
.../sesame/commons/model/ResourceUtilsTest.java | 693 ------
.../sesame/commons/model/URICommonsTest.java | 71 -
.../src/test/resources/foaf/demo-data.foaf | 69 -
commons/sesame-tools-facading/pom.xml | 2 +-
libraries/kiwi/kiwi-reasoner/pom.xml | 2 +-
libraries/kiwi/kiwi-transactions/pom.xml | 2 +-
libraries/kiwi/kiwi-triplestore/pom.xml | 2 +-
libraries/kiwi/kiwi-versioning/pom.xml | 2 +-
libraries/ldcache/ldcache-core/pom.xml | 2 +-
libraries/ldcache/ldcache-sail-kiwi/pom.xml | 2 +-
libraries/ldclient/ldclient-core/pom.xml | 2 +-
libraries/ldclient/ldclient-provider-html/pom.xml | 2 +-
libraries/ldclient/ldclient-provider-ldap/pom.xml | 2 +-
.../ldclient/provider/ldap/LdapFoafProvider.java | 3 +-
.../ldclient/ldclient-provider-mediawiki/pom.xml | 2 +-
libraries/ldclient/ldclient-provider-phpbb/pom.xml | 2 +-
libraries/ldclient/ldclient-provider-rdfa/pom.xml | 2 +-
libraries/ldclient/ldclient-provider-vimeo/pom.xml | 2 +-
libraries/ldclient/ldclient-provider-xml/pom.xml | 2 +-
.../ldclient/ldclient-provider-youtube/pom.xml | 2 +-
libraries/ldpath/ldpath-functions-date/pom.xml | 2 +-
parent/pom.xml | 2 +-
platform/marmotta-core/pom.xml | 2 +-
58 files changed, 5438 insertions(+), 5397 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/pom.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/pom.xml b/commons/marmotta-commons/pom.xml
index ee60c04..c690c3a 100644
--- a/commons/marmotta-commons/pom.xml
+++ b/commons/marmotta-commons/pom.xml
@@ -30,6 +30,10 @@
<dependencies>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
</dependency>
@@ -37,12 +41,47 @@
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-repository-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-sail-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <!-- TODO: this should be removed -->
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-repository-sail</artifactId>
+ <optional>true</optional>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-sail-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-rdfxml</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/http/ETagGenerator.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/http/ETagGenerator.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/http/ETagGenerator.java
new file mode 100644
index 0000000..c123625
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/http/ETagGenerator.java
@@ -0,0 +1,105 @@
+/**
+ * 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.sesame.commons.http;
+
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+
+import at.newmedialab.sesame.commons.repository.ResourceUtils;
+
+import com.google.common.hash.HashFunction;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+
+/**
+ * HTTP ETag generator for Sesame
+ *
+ * @author Sergio Fernández
+ *
+ */
+public class ETagGenerator {
+
+ public static String getETag(RepositoryConnection conn, String uri) throws RepositoryException {
+ URI resource = ResourceUtils.getUriResource(conn, uri);
+ return getETag(conn, resource);
+ }
+
+ public static String getETag(RepositoryConnection conn, URI resource) throws RepositoryException {
+ if (resource == null) return "";
+
+ Hasher hasher = buildHasher();
+ hasher.putString(resource.stringValue());
+ //FIXME: The order of the statements is not defined -> might result in different hash!
+ RepositoryResult<Statement> outgoing = conn.getStatements(resource, null, null, true);
+ try {
+ while (outgoing.hasNext()) {
+ Statement statement = outgoing.next();
+ hasher.putString(statement.getPredicate().stringValue());
+ hasher.putString(statement.getObject().stringValue());
+ //TODO: statement modification date?
+ }
+ } finally {
+ outgoing.close();
+ }
+ RepositoryResult<Statement> incoming = conn.getStatements(null, null, resource, true);
+ try {
+ while (incoming.hasNext()) {
+ Statement statement = incoming.next();
+ hasher.putString(statement.getSubject().stringValue());
+ hasher.putString(statement.getPredicate().stringValue());
+ //TODO: statement modification date?
+ }
+ } finally {
+ incoming.close();
+ }
+ return hasher.hash().toString();
+ }
+
+ public static String getWeakETag(RepositoryConnection conn, String uri) throws RepositoryException {
+ URI resource = ResourceUtils.getUriResource(conn, uri);
+ return getWeakETag(conn, resource);
+ }
+
+ public static String getWeakETag(RepositoryConnection conn, URI resource) throws RepositoryException {
+ if (resource == null) return "";
+
+ Hasher hasher = buildHasher();
+ hasher.putString(resource.stringValue());
+ //FIXME: The order of the statements is not defined -> might result in different hash!
+ RepositoryResult<Statement> statements = conn.getStatements(resource, null, null, true);
+ try {
+ while (statements.hasNext()) {
+ Statement statement = statements.next();
+ hasher.putString(statement.getPredicate().stringValue());
+ hasher.putString(statement.getObject().stringValue());
+ //TODO: statement modification date?
+ }
+ } finally {
+ statements.close();
+ }
+ return hasher.hash().toString();
+ }
+
+ private static Hasher buildHasher() {
+ HashFunction function = Hashing.goodFastHash(16);
+ Hasher hasher = function.newHasher();
+ return hasher;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/BNodeCommons.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/BNodeCommons.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/BNodeCommons.java
new file mode 100644
index 0000000..24238fb
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/BNodeCommons.java
@@ -0,0 +1,47 @@
+/**
+ * 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.sesame.commons.model;
+
+import org.openrdf.model.BNode;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class BNodeCommons {
+
+ /**
+ * Return the cache key for the BNode passed as argument.
+ *
+ * @param node a Sesame BNode for which to create a cache key
+ * @return a string that can be used as cache key
+ */
+ public static String createCacheKey(BNode node) {
+ return node.getID();
+ }
+
+
+ /**
+ * Return the cache key for the BNode ID passed as argument.
+ *
+ * @param anonId a Sesame BNode ID for which to create a cache key
+ * @return a string that can be used as cache key
+ */
+ public static String createCacheKey(String anonId) {
+ return anonId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/LiteralCommons.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/LiteralCommons.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/LiteralCommons.java
new file mode 100644
index 0000000..bfbccd6
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/LiteralCommons.java
@@ -0,0 +1,182 @@
+/**
+ * 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.sesame.commons.model;
+
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+import org.openrdf.model.Literal;
+import org.openrdf.model.URI;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Utility methods for working with literals.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LiteralCommons {
+ private static DatatypeFactory dtf;
+ static {
+ try {
+ dtf = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ }
+ }
+
+
+ /**
+ * Create a cache key for a literal with the given content, locale and type
+ *
+ * @param content string content representing the literal (can be an MD5 sum for binary types)
+ * @param language language of the literal (optional)
+ * @param type datatype URI of the literal (optional)
+ * @return a 64bit hash key for the literal
+ */
+ public static String createCacheKey(String content, Locale language, URI type) {
+ return createCacheKey(content, language, type != null ? type.stringValue() : null);
+ }
+
+ /**
+ * Create a cache key for a literal with the given content, locale and type
+ *
+ * @param content string content representing the literal (can be an MD5 sum for binary types)
+ * @param language language of the literal (optional)
+ * @param type datatype URI of the literal (optional)
+ * @return a 64bit hash key for the literal
+ */
+ public static String createCacheKey(String content, Locale language, String type) {
+ Hasher hasher = Hashing.goodFastHash(64).newHasher();
+ hasher.putString(content);
+ if(type != null) {
+ hasher.putString(type);
+ }
+ if(language != null) {
+ hasher.putString(language.getLanguage().toLowerCase());
+ }
+ return hasher.hash().toString();
+ }
+
+ /**
+ * Create a cache key for the date literal with the given date. Converts the date
+ * to a XMLGregorianCalendar with UTC timezone and then calls the method above.
+ *
+ * @param date date object of the date literal
+ * @param type datatype URI of the literal
+ * @return a 64bit hash key for the literal
+ */
+ public static String createCacheKey(Date date, String type) {
+ GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+ cal.setTime(date);
+
+ XMLGregorianCalendar xml_cal = dtf.newXMLGregorianCalendar(cal).normalize();
+ xml_cal.setTimezone(0);
+
+ return createCacheKey(xml_cal.toXMLFormat(), null, type);
+ }
+
+ /**
+ * Create a cache key for the literal passed as argument. Takes content, language
+ * and datatype URI as parameter to create a 64bit hash.
+ *
+ * @param l the literal to create the hash for
+ * @return a 64bit hash key for the literal
+ */
+ public static String createCacheKey(Literal l) {
+ Hasher hasher = Hashing.goodFastHash(64).newHasher();
+ hasher.putString(l.getLabel());
+ if(l.getDatatype() != null) {
+ hasher.putString(l.getDatatype().stringValue());
+ }
+ if(l.getLanguage() != null) {
+ hasher.putString(l.getLanguage().toLowerCase());
+ }
+ return hasher.hash().toString();
+ }
+
+ /**
+ * Get an appropriate RDF type for the mime type passed as argument.
+ * @param mime_type
+ * @return
+ */
+ public static String getRDFType(String mime_type) {
+ String iw_type = "MultimediaObject";
+ if (mime_type.startsWith("image")) {
+ iw_type = "Image";
+ } else if (mime_type.startsWith("video/flash")) {
+ iw_type = "FlashVideo";
+ } else if (mime_type.startsWith("video")) {
+ iw_type = "Video";
+ } else if (mime_type.startsWith("application/pdf")) {
+ iw_type = "PDFDocument";
+ } else if (mime_type.startsWith("application/msword")) {
+ iw_type = "MSWordDocument";
+ } else if (mime_type
+ .startsWith("application/vnd.oasis.opendocument")
+ || mime_type.startsWith("application/postscript")
+ || mime_type.startsWith("application/vnd.ms-")) {
+ iw_type = "Document";
+ } else if (mime_type.startsWith("audio/mpeg")
+ || mime_type.startsWith("audio/mp3")) {
+ iw_type = "MP3Audio";
+ } else if (mime_type.startsWith("audio")) {
+ iw_type = "Audio";
+ } else if (mime_type.startsWith("text/html")) {
+ iw_type = "HTML";
+ } else if (mime_type.startsWith("text")) {
+ iw_type = "TEXT";
+ }
+ return Namespaces.NS_KIWI_CORE + iw_type;
+ }
+
+ /**
+ * Return the appropriate XSD type for RDF literals for the provided Java class.
+ * @param javaClass
+ * @return
+ */
+ public static String getXSDType(Class<?> javaClass) {
+ if(String.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"string";
+ } else if(Integer.class.isAssignableFrom(javaClass) || int.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"integer";
+ } else if(Long.class.isAssignableFrom(javaClass) || long.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"long";
+ } else if(Double.class.isAssignableFrom(javaClass) || double.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"double";
+ } else if(Float.class.isAssignableFrom(javaClass) || float.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"float";
+ } else if(Date.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"dateTime";
+ } else if(Boolean.class.isAssignableFrom(javaClass) || boolean.class.isAssignableFrom(javaClass)) {
+ return Namespaces.NS_XSD+"boolean";
+ } else {
+ return Namespaces.NS_XSD+"string";
+ }
+ }
+
+ /**
+ * The RDF 1.1 datatype for language literals.
+ * @see <a href="http://www.w3.org/TR/2013/WD-rdf11-concepts-20130115/#section-Graph-Literal">http://www.w3.org/TR/2013/WD-rdf11-concepts-20130115/#section-Graph-Literal</a>
+ */
+ public static String getRDFLangStringType() {
+ return Namespaces.NS_RDF + "langString";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/Namespaces.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/Namespaces.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/Namespaces.java
new file mode 100644
index 0000000..8beb06a
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/Namespaces.java
@@ -0,0 +1,128 @@
+/**
+ * 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.sesame.commons.model;
+
+/**
+ * Namespaces static constants
+ *
+ * @author Sebastian Schaffert
+ * @todo see how it fits with the PrefixService
+ */
+public class Namespaces {
+
+ // the KiWi namespace used in XHTML documents for kiwi: attributes and elements
+ public static final String NS_KIWI_HTML = "http://www.kiwi-project.eu/kiwi/html/";
+ public static final String NS_KIWI_EXPORT = "http://www.kiwi-project.eu/kiwi/export/";
+
+ public static final String NS_KIWI_CORE = "http://www.kiwi-project.eu/kiwi/core/";
+ public static final String NS_KIWI_REASONING = "http://www.kiwi-project.eu/kiwi/reasoning/";
+ public static final String NS_KIWI_CORE_KNOWLEDGESPACE = "http://www.kiwi-project.eu/kiwi/core/knowledgespace#";
+ public static final String NS_KIWI_SPECIAL = "http://www.kiwi-project.eu/kiwi/special/";
+ public static final String NS_KIWI_TRIPLE = "http://www.kiwi-project.eu/kiwi/triple/";
+ public static final String NS_TAGIT = "http://www.kiwi-project.eu/tagit/";
+ public static final String NS_EVENTIM = "http://www.eventim.de/";
+
+ public static final String NS_FCP_CORE = "http://www.newmedialab.at/fcp/";
+
+ public static final String NS_DEMO = "http://www.lmf-demo.at/";
+
+ // LMF Namespaces
+ public static final String NS_LMF_TYPES = "http://www.newmedialab.at/lmf/types/1.0/";
+ public static final String NS_LMF_FUNCS = "http://www.newmedialab.at/lmf/functions/1.0/";
+
+ // XML Namespaces
+ public static final String NS_XSD = "http://www.w3.org/2001/XMLSchema#";
+ public static final String NS_XML = "http://www.w3.org/TR/2006/REC-xml11-20060816/#";
+ public static final String NS_XHTML = "http://www.w3.org/1999/xhtml";
+
+ // RDF Namespaces
+ public static final String NS_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+ public static final String NS_RDFS = "http://www.w3.org/2000/01/rdf-schema#";
+ public static final String NS_OWL = "http://www.w3.org/2002/07/owl#";
+
+ public static final String NS_ATOM = "http://www.w3.org/2005/Atom";
+
+ // namespaces of some frequently used ontologies
+ public static final String NS_FOAF = "http://xmlns.com/foaf/0.1/";
+ public static final String NS_LASTFM = "http://foaf.qdos.com/lastfm/schema/";
+ public static final String NS_BIO = "http://purl.org/vocab/bio/0.1/";
+ public static final String NS_CONT = "http://www.w3.org/2000/10/swap/pim/contact#";
+ public static final String NS_GEO = "http://www.w3.org/2003/01/geo/wgs84_pos#";
+ public static final String NS_GEONAMES = "http://www.geonames.org/ontology#";
+ public static final String NS_SIOC = "http://rdfs.org/sioc/ns#";
+ public static final String NS_SIOC_TYPES = "http://rdfs.org/sioc/types#";
+ public static final String NS_MOAT = "http://moat-project.org/ns#";
+ public static final String NS_HGTAGS = "http://www.holygoat.co.uk/owl/redwood/0.1/tags/";
+ public static final String NS_DC = "http://purl.org/dc/elements/1.1/";
+ public static final String NS_DC_TERMS = "http://purl.org/dc/terms/";
+ public static final String NS_SKOS = "http://www.w3.org/2004/02/skos/core#";
+ public static final String NS_SCOT = "http://scot-project.org/scot/ns#";
+ public static final String NS_EXIF = "http://www.kanzaki.com/ns/exif#";
+ public static final String NS_MEDIA = "http://www.w3.org/ns/ma-ont#";
+ public static final String NS_TEMPLATING = "http://newmedialab.at/onthology/templating/";
+
+ public static final String NS_MEDIA_ANALYSIS = "http://linkedmultimedia.org/ontology/";
+
+ public static final String NS_RSS = "http://purl.org/rss/1.0/";
+ public static final String NS_RSS_CONTENT = "http://purl.org/rss/1.0/modules/content/";
+
+ /**
+ * Some language related namespaces from LoC (Library of Congress, USA)
+ */
+ public static final class NSS_LANGUAGE {
+ private NSS_LANGUAGE() {};
+ /**
+ * Use the two-letter identifier, such as "en", "de", "fr"
+ */
+ public static final String NS_ISO639_1 = "http://id.loc.gov/vocabulary/iso639-1/";
+ /**
+ * Use the three-letter identifier, such as "eng", "deu", "fra"
+ */
+ public static final String NS_ISO639_2 = "http://id.loc.gov/vocabulary/iso639-2/";
+ /**
+ * Language Families
+ */
+ public static final String NS_ISO639_5 = "http://id.loc.gov/vocabulary/iso639-5/";
+ /**
+ * MARC List for Languages.
+ * MARC List for Languages provides three-character lowercase alphabetic strings that serve
+ * as the identifiers of languages and language groups.
+ *
+ * @see {@link http://id.loc.gov/vocabulary/languages.html}
+ */
+ public static final String NS_MARC = "http://id.loc.gov/vocabulary/languages/";
+ };
+
+ public static final String MIME_TYPE_ALL = "*/*";
+ public static final String MIME_TYPE_HTML = "text/html";
+ public static final String MIME_TYPE_PLAIN = "text/plain";
+ public static final String MIME_TYPE_TEXT_XML = "text/xml";
+ public static final String MIME_TYPE_JSON = "application/json";
+ public static final String MIME_TYPE_XHTML = "application/xhtml+xml";
+ public static final String MIME_TYPE_RDFXML = "application/rdf+xml";
+ public static final String MIME_TYPE_XML = "application/xml";
+ public static final String MIME_TYPE_FORM_URLENC = "application/x-www-form-urlencoded";
+ public static final String MIME_TYPE_TEMPLATE = "text/html";
+
+ /**
+ * The login for the admin user
+ */
+ public static final String ADMIN_LOGIN = "admin";
+ /**
+ * The login for the anonymous user
+ */
+ public static final String ANONYMOUS_LOGIN = "anonymous";
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/URICommons.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/URICommons.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/URICommons.java
new file mode 100644
index 0000000..41318ec
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/model/URICommons.java
@@ -0,0 +1,77 @@
+/**
+ * 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.sesame.commons.model;
+
+import org.openrdf.model.URI;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class URICommons {
+
+ /**
+ * Return the cache key for the URI passed as argument.
+ *
+ * @param node a Sesame BNode for which to create a cache key
+ * @return a string that can be used as cache key
+ */
+ public static String createCacheKey(URI node) {
+ return node.stringValue();
+ }
+
+
+ /**
+ * Return the cache key for the BNode ID passed as argument.
+ *
+ * @param uri the string representation of a Sesame URI for which to create a cache key
+ * @return a string that can be used as cache key
+ */
+ public static String createCacheKey(String uri) {
+ return uri;
+ }
+
+ /**
+ * Split a String URI into namespace and local name as described in the comment of {@link URI}
+ *
+ * @param uri the URI to split
+ * @return a String array of length 2 where the first argument is the namespace, the second the local name
+ */
+ public static String[] splitNamespace(String uri) {
+ // split according to algorithm in URI class
+ String[] components = uri.split("#",2);
+
+ String namespace, localName;
+ if(components.length > 1) {
+ namespace = components[0]+"#";
+ localName = components[1];
+ } else {
+ components = uri.split("/");
+ if(components.length > 1) {
+ namespace = uri.substring(0,uri.length()-components[components.length-1].length());
+ localName = components[components.length-1];
+ } else {
+ components = uri.split(":");
+
+ namespace = uri.substring(0,uri.length()-components[components.length-1].length());
+ localName = components[components.length-1];
+ }
+ }
+ return new String[] {namespace,localName};
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ExceptionUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ExceptionUtils.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ExceptionUtils.java
new file mode 100644
index 0000000..fed9c59
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ExceptionUtils.java
@@ -0,0 +1,56 @@
+/**
+ * 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.sesame.commons.repository;
+
+import org.openrdf.repository.RepositoryException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ExceptionUtils {
+
+
+ /**
+ * Handle repository exceptions in a uniform way. The output will we written to the logger of the ExceptionUtils
+ * class.
+ *
+ * @param ex
+ */
+ public static void handleRepositoryException(RepositoryException ex) {
+ handleRepositoryException(ex,null);
+ }
+
+ /**
+ * Handle repository exceptions in a uniform way. If the optional caller class is passed as argument,
+ * the logger of this class will be chosen for output, otherwise the output will come from the ExceptionUtils
+ * class.
+ *
+ * @param ex
+ */
+ public static void handleRepositoryException(RepositoryException ex, Class<?> caller) {
+ Logger log;
+ if(caller != null) {
+ log = LoggerFactory.getLogger(caller);
+ } else {
+ log = LoggerFactory.getLogger(ExceptionUtils.class);
+ }
+ log.error("error accessing RDF repository",ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ResourceConnection.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ResourceConnection.java b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ResourceConnection.java
new file mode 100644
index 0000000..50d4e85
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/at/newmedialab/sesame/commons/repository/ResourceConnection.java
@@ -0,0 +1,66 @@
+/**
+ * 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.sesame.commons.repository;
+
+import org.openrdf.model.BNode;
+import org.openrdf.model.Resource;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.openrdf.sail.SailConnection;
+
+/**
+ * A special form of Sesame RepositoryConnection that allows listing resources more efficiently than by listing all
+ * statements (e.g. by direct database access).
+ *
+ * @author Sebastian Schaffert
+ */
+public interface ResourceConnection extends SailConnection {
+
+ /**
+ * Return an iterator over the resources contained in this repository.
+ * @return
+ */
+ RepositoryResult<Resource> getResources() throws RepositoryException;
+
+ /**
+ * Return an iterator over the resources contained in this repository matching the given prefix.
+ * @return
+ */
+ RepositoryResult<URI> getResources(String prefix) throws RepositoryException;
+
+ /**
+ * Return the Sesame URI with the given uri identifier if it exists, or null if it does not exist.
+ *
+ * @param uri
+ * @return
+ */
+ URI getURI(String uri);
+
+ /**
+ * Return the Sesame BNode with the given anonymous ID if it exists, or null if it does not exist.
+ * @param id
+ * @return
+ */
+ BNode getBNode(String id);
+
+ /**
+ * Remove the resource given as argument from the triple store and the resource repository.
+ * @param resource
+ */
+ void removeResource(Resource resource);
+
+}