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/10/03 17:07:01 UTC
[02/22] MARMOTTA-85: restructure modules to support modular backends
- first draft of kiwi store backend - MARMOTTA-87: first draft of native
store backend - first draft of bigdata store backend
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/about.html
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/about.html b/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/about.html
new file mode 100644
index 0000000..0f39967
--- /dev/null
+++ b/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/about.html
@@ -0,0 +1,98 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+
+-->
+<html>
+<head>
+ <!--###BEGIN_HEAD###-->
+ <title>Versioning Services</title>
+ <link rel="stylesheet" type="text/css" href="../../core/public/style/center.css"/>
+ <!--###END_HEAD###-->
+</head>
+<body>
+<!--###BEGIN_CONTENT###-->
+<h1><a name="Introduction"></a>Introduction<a class="section_anchor" href="#Introduction"></a></h1>
+
+<p>Apache Marmotta offers versioning services that keep track of any resource updates in the triple store.
+ Versioning is transaction based, i.e. every time a transaction is committed successfully, a new version entry is
+ created by the versioning services. Marmotta currently supports listing versions (system-wide and for a single resource)
+ as well as inspecting "snapshots" (i.e. going back in time).
+</p>
+
+
+<h1><a name="Versions"></a>Version Access<a class="section_anchor" href="#Versions"></a></h1>
+
+<p>
+ Marmotta provides basic access to versioning information through the /versions web service:
+</p>
+<ul>
+ <li>/versions/list (optionally with parameters resource, offset, limit) will list all versions of the system or all versions of the specified resource</li>
+ <li>/versions/{id} will display details about the version with the id {id}</li>
+</ul>
+<p>
+ Be aware that listing all versions of the system might be a very expensive operation on large systems and
+ should be used with care.
+</p>
+
+<h1><a name="Snapshots"></a>Snapshots<a class="section_anchor" href="#Snapshots"></a></h1>
+
+<p>
+ The Snapshot service (accessible under /snapshot) allows to access a resource as it used to be at a certain point in time. The /snapshot service accepts the
+ following query parameters:
+</p>
+<ul>
+ <li>resource=... - the URI of the resource of which to return the snapshot; needs to be URL-encoded; REQUIRED</li>
+ <li>time=... - the time for which to return the snapshot; time is in ISO8601 or in GMT format and needs to be URL-encoded</li>
+ <li>version=... - the ID of the version for which to return the snapshot</li>
+</ul>
+<p>
+ The resource parameter is always required. Either the time or the version parameter must also be given. If both are present,
+ the time parameter takes precedence.
+</p>
+<h3>Examples</h3>
+<p>
+ Retrieve version 6 of resource http://localhost:8080/marmotta/resource/1234:
+</p>
+<pre>
+ http://localhost:8080/marmotta/snapshot?resource=http%253A%252F%252Flocalhost%253A8080%252Fmarmotta%252Fresource%252F1234&version=6
+</pre>
+
+
+<h1><a name="Memento"></a>Memento Support<a class="section_anchor" href="#Memento"></a></h1>
+
+<p>
+ In case the versioning.memento configuration property is enabled, Marmotta also provides support for the
+ <a href="http://www.mementoweb.org/guide/rfc/ID/">Memento specification</a>, which allows access to earlier
+ versions of a resource through an extension of the HTTP protocol.
+</p>
+<p>
+ In case memento support is enabled, the Marmotta resource web service will produce additional "Link:" headers for
+ each resource request pointing back to the Memento timegate service (located at /timegate?resource=...) provided
+ by the versioning module. Depending on the Accept-Datetime header, the timegate service will redirect to the
+ appropriate snapshot of the resource.
+</p>
+<p>
+ Several tools exist for accessing Memento
+ archives, e.g. the <a href="https://addons.mozilla.org/de/firefox/addon/mementofox/">MementoFox</a> browser
+ extension.
+</p>
+
+
+<!--###END_CONTENT###-->
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/configuration.html
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/configuration.html b/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/configuration.html
new file mode 100644
index 0000000..1fc1753
--- /dev/null
+++ b/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/configuration.html
@@ -0,0 +1,67 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+
+-->
+<html>
+<head>
+<!--###BEGIN_HEAD###-->
+ <title>Versioning Module Configuration</title>
+ <script type="text/javascript" src="../../webjars/jquery/1.8.2/jquery.min.js"></script>
+ <script type="text/javascript" src="../../core/public/js/widgets/property_config.js"></script>
+ <script type="text/javascript">
+ jQuery(document).ready(function(){
+ var settings = {
+ host: _SERVER_URL,
+ anker_name: 'generic',
+ title: 'Versioning Properties <span style="font-size:12px">(parameter name MUST start with \'versioning.\')</small>',
+ loading_img: '../../core/public/img/ajax-loader_small.gif',
+ blacklist_keys:[],
+ toplink:true,
+ prefix:'versioning'
+ }
+ $('#lmf_configurator').lmf_configurator(settings);
+ });
+ </script>
+ <link rel="stylesheet" type="text/css" href="../../core/public/style/center.css"/>
+ <style type="text/css">
+ h2 {
+ margin: 10px 0;
+ }
+ </style>
+<!--###END_HEAD###-->
+</head>
+<body>
+<div id="main">
+<div id="contents">
+<!--###BEGIN_CONTENT###-->
+<h1>Marmotta Versioning Configuration</h1>
+ <p>
+ Here you can configure the Marmotta Versioning Services.<br/>
+ The configuration contains:
+ </p>
+ <ul>
+ <li><a href="#lmf_configurator">Generic Parameter Configuration</a></li>
+ </ul>
+ <div id="lmf_configurator">
+ <h4>Loading configurator</h4>
+ </div>
+<!--###END_CONTENT###-->
+</div>
+</div>
+</body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/img/clock_small.png
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/img/clock_small.png b/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/img/clock_small.png
new file mode 100755
index 0000000..e34f22f
Binary files /dev/null and b/platform/marmotta-versioning-kiwi/src/main/resources/web/admin/img/clock_small.png differ
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/pom.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/pom.xml b/platform/marmotta-versioning/pom.xml
deleted file mode 100644
index 77590aa..0000000
--- a/platform/marmotta-versioning/pom.xml
+++ /dev/null
@@ -1,168 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>marmotta-parent</artifactId>
- <version>3.2.0-incubating-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
-
- <artifactId>marmotta-versioning</artifactId>
- <packaging>jar</packaging>
-
- <name>Apache Marmotta Platform: Versioning</name>
- <description>
- This module provides versioning support for all modifications of the data contained in the LMF System (triples,
- resources, namespaces). Versions are accessible according to the Memento protocol using a special webservice.
- Versioning is triggered when a transaction finishes successfully and will store additional
- versioning information in the database. Note that this implies a certain performance overhead.
- </description>
-
- <build>
- <pluginManagement>
- <plugins>
- <plugin> <!-- generate JRebel Configuration -->
- <groupId>org.zeroturnaround</groupId>
- <artifactId>jrebel-maven-plugin</artifactId>
- <version>1.1.3</version>
- <executions>
- <execution>
- <id>generate-rebel-xml</id>
- <phase>process-resources</phase>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <relativePath>../../</relativePath>
- <rootPath>$${rebel.root}</rootPath>
- <classpath>
- <resources>
- <resource><!-- default resource --></resource>
- <resource><directory>src/main/resources</directory></resource>
- </resources>
- </classpath>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>buildinfo-maven-plugin</artifactId>
- <configuration>
- <systemProperties>
- <systemProperty>user.name</systemProperty>
- <systemProperty>user.timezone</systemProperty>
- <systemProperty>java.vm.vendor</systemProperty>
- <systemProperty>java.vm.version</systemProperty>
- <systemProperty>java.vm.name</systemProperty>
- <systemProperty>java.runtime.version</systemProperty>
- <systemProperty>os.name</systemProperty>
- <systemProperty>os.version</systemProperty>
- <systemProperty>os.arch</systemProperty>
- </systemProperties>
- </configuration>
- <executions>
- <execution>
- <phase>process-resources</phase>
- <goals>
- <goal>extract</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <executions>
- <!--
- <execution>
- <id>aggregate</id>
- <goals>
- <goal>aggregate</goal>
- </goals>
- <phase>site</phase>
- </execution>
- -->
- <execution>
- <!-- configure how the REST API documentation will be produced -->
- <id>restapi</id>
- <configuration>
- <doclet>com.lunatech.doclets.jax.jaxrs.JAXRSDoclet</doclet>
-
- <name>REST API</name>
- <description>REST API for LMF Webservices</description>
-
- <outputDirectory>${project.build.outputDirectory}/doc</outputDirectory>
- <reportOutputDirectory>${project.build.outputDirectory}/web/doc</reportOutputDirectory>
- <destDir>rest</destDir>
-
- <docletArtifact>
- <groupId>com.lunatech.jax-doclets</groupId>
- <artifactId>doclets</artifactId>
- <version>0.10.0</version>
- </docletArtifact>
- <additionalparam>
- -jaxrscontext {BASE}
- -charset UTF-8
- </additionalparam>
-
- <!--
- <stylesheetfile>${project.parent.basedir}/config/doc/doclet.css</stylesheetfile>
- -->
-
- <header><![CDATA[<!--###BEGIN_CONTENT###--><div class="javadoc">]]></header>
- <footer><![CDATA[</div><!--###END_CONTENT###-->]]></footer>
- <encoding>UTF-8</encoding>
- <detectOfflineLinks>false</detectOfflineLinks>
-
- <!-- For the project-reports page -->
- </configuration>
- <goals>
- <goal>javadoc</goal>
- </goals>
- <phase>generate-resources</phase>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>marmotta-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>kiwi-versioning</artifactId>
- </dependency>
- <dependency>
- <groupId>org.freemarker</groupId>
- <artifactId>freemarker</artifactId>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/MementoService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/MementoService.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/MementoService.java
deleted file mode 100644
index 5524060..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/MementoService.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.api;
-
-import org.apache.marmotta.platform.versioning.exception.MementoException;
-import org.apache.marmotta.platform.versioning.model.MementoVersionSet;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.Resource;
-import java.util.Date;
-
-/**
- * ...
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-public interface MementoService {
-
- //public Version getNextVersion(Resource resource, Version version) throws MementoException;
-
- //public Version getPreviousVersion(Resource resource, Version version) throws MementoException;
-
- /**
- * returns the version for a resource that was current on the given date
- * @param resource a uri resource
- * @param date a date
- * @return the version with respect to the date
- * @throws MementoException
- */
- public Version getVersion(Resource resource, Date date) throws MementoException;
-
- //public Version getLastVersion(Resource resource) throws MementoException;
- //public Version getFirstVersion(Resource resource) throws MementoException;
-
- /**
- * returns a memento version set that includes first, last, current, prev and next version with respect
- * to a given date and resource
- * @param resource a requested resource
- * @param date a requested date
- * @return a memento version set
- * @throws MementoException
- * @see MementoVersionSet
- */
- public MementoVersionSet getVersionSet(Resource resource, Date date) throws MementoException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/VersionSerializerService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/VersionSerializerService.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/VersionSerializerService.java
deleted file mode 100644
index 34c89d3..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/api/VersionSerializerService.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.api;
-
-import org.apache.marmotta.platform.versioning.io.VersionSerializer;
-import org.apache.marmotta.commons.http.ContentType;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * Manages serialisation writers for Version objects
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-public interface VersionSerializerService {
-
- /**
- * returns a serializer for Version objects on a given ContentType
- * @param type a list of mimetype (from Accept header)
- * @return a serializer
- */
- public VersionSerializer getSerializer(List<ContentType> type) throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
deleted file mode 100644
index c5642f9..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.exception;
-
-/**
- * Exception is thrown if something went wrong in memento versioning
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-public class MementoException extends Exception {
-
- public MementoException() {}
-
- public MementoException(String m) {
- super(m);
- }
-
- public MementoException(Throwable t) {
- super(t);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/filter/MementoFilter.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/filter/MementoFilter.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/filter/MementoFilter.java
deleted file mode 100644
index 2c1d62d..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/filter/MementoFilter.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.filter;
-
-import org.apache.marmotta.platform.core.api.modules.MarmottaHttpFilter;
-import org.apache.marmotta.platform.versioning.utils.MementoUtils;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.slf4j.Logger;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Adds memento timegate links to resources that are delivered via ResourceWebService
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-@ApplicationScoped
-public class MementoFilter implements MarmottaHttpFilter {
-
- //filter all requests on resource webservice
- private static final String FILTER_PATTERN = "/(" + ConfigurationService.RESOURCE_PATH + "|" +
- ConfigurationService.META_PATH + "|" +
- ConfigurationService.CONTENT_PATH +")/.*";
-
- @Inject
- private Logger log;
-
- @Inject
- ConfigurationService configurationService;
-
- @Override
- public String getPattern() {
- return FILTER_PATTERN;
- }
-
- @Override
- public int getPriority() {
- return PRIO_MIDDLE;
- }
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- //nothing to do
- log.info("init memento filter");
- }
-
- /**
- * appends memento timegate link to all resources, that are accessed via GET on resource webservice
- * @param servletRequest
- * @param servletResponse
- * @param filterChain
- * @throws IOException
- * @throws ServletException
- */
- @Override
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
- if (servletRequest instanceof HttpServletRequest) {
- HttpServletRequest request = (HttpServletRequest) servletRequest;
-
- //memento is only for reading
- if(request.getMethod().equals("GET") || request.getMethod().equals("HEAD")) {
- HttpServletResponse response = (HttpServletResponse) servletResponse;
-
- URL resource = getResourceURL(request);
-
- // build timegate link
- if(resource != null) {
- response.addHeader("Link",
- "<"+MementoUtils.timegateURI(
- resource.toString(),configurationService.getBaseUri()
- ) +">; rel=\"timegate\"," +
- "<"+MementoUtils.timemapURI(
- resource.toString(),configurationService.getBaseUri()
- ) +">; rel=\"timemap\""
- );
- }
-
- filterChain.doFilter(servletRequest,response);
- return;
- }
- }
- filterChain.doFilter(servletRequest,servletResponse);
- }
-
- /**
- * returns the resource url for a request, null if resource does not exist
- * @param request
- * @return
- */
- private URL getResourceURL(HttpServletRequest request) {
- try {
- if(request.getParameter("uri") != null) {
- //memento is only for http protocol
- if(request.getParameter("uri").startsWith("http://") || request.getParameter("uri").startsWith("https://")) {
- return new URL(request.getParameter("uri"));
- }
- } else {
- //test if it is a resource / meta / content url
- if(request.getRequestURI().startsWith("/"+ ConfigurationService.RESOURCE_PATH+"/")) {
- return new URL(request.getRequestURL().toString());
- } else if(request.getRequestURI().startsWith("/"+ ConfigurationService.CONTENT_PATH+"/") ||
- request.getRequestURI().startsWith("/"+ ConfigurationService.META_PATH+"/")) {
- return new URL(restoreResource(request.getRequestURI()));
- }
- }
- } catch (MalformedURLException e) {
- log.error(e.getMessage());
- }
- return null;
- }
-
- private static final Pattern URI_PATTERN = Pattern.compile("(/[^/]*){3}/(.*)");
-
- /**
- * restore uri from meta or content url
- * @param uri
- * @return
- * @throws MalformedURLException
- */
- private String restoreResource(String uri) throws MalformedURLException {
- Matcher m = URI_PATTERN.matcher(uri);
- if (m.matches()) return configurationService.getBaseUri() + ConfigurationService.RESOURCE_PATH + "/" + m.group(2);
- throw new MalformedURLException("original url can not be restored");
- }
-
- @Override
- public void destroy() {
- //nothing to do
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
deleted file mode 100644
index 7e7c3d0..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.io;
-
-import org.apache.marmotta.platform.versioning.utils.MementoUtils;
-import freemarker.template.Configuration;
-import freemarker.template.TemplateException;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import freemarker.template.Template;
-import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.Resource;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Serializes an ordered list of versions in text/html into an output stream
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-@ApplicationScoped
-public class HtmlVersionSerializer implements VersionSerializer {
-
- @Inject
- ConfigurationService configurationService;
-
- private Configuration configuration;
-
- private static final String TEMPLATE = "timemap";
-
- @PostConstruct
- private void initialize() {
- configuration = new Configuration();
- configuration.setClassForTemplateLoading(HtmlVersionSerializer.class, "/template/");
- }
-
- //a static list that contains the contentTypes
- private static final List<ContentType> contentTypes = new ArrayList(){{
- add(new ContentType("text","html"));
- }};
-
- /**
- * return the content type that will be produced
- * @return
- */
- public ContentType getContentType() {
- return new ContentType("text","html");
- }
-
- /**
- * returns a list of supported content types (text/html)
- * @return a list of types
- */
- @Override
- public List<ContentType> getContentTypes() {
- return contentTypes;
- }
-
- /**
- * writes serialized version list (text/html) to output stream
- * TODO use temmplating engine
- * @param original the original (current) resource
- * @param versions a list of versions in ascending order
- * @param out an output stream
- */
- @Override
- public void write(Resource original, RepositoryResult<Version> versions, OutputStream out) throws IOException {
-
- try {
-
- //write data to map
- Map<String, Object> data = new HashMap<String, Object>();
-
- data.put("original",original.toString());
-
- List<Map<String,String>> vs = new ArrayList<Map<String,String>>();
-
- while (versions.hasNext()) {
- Version v = versions.next();
- Map<String,String> m = new HashMap<String,String>();
- m.put("date",v.getCommitTime().toString());
- m.put("uri",MementoUtils.resourceURI(original.toString(), v.getCommitTime(), configurationService.getBaseUri()).toString());
- vs.add(m);
- }
-
- data.put("versions",vs);
-
- //put generic data
- String project = configurationService.getStringConfiguration("kiwi.pages.project","lmf");
- data.put("LOGO",configurationService.getStringConfiguration("kiwi.pages.project."+project+".logo","logo.png"));
- data.put("FOOTER",configurationService.getStringConfiguration("kiwi.pages.project."+project+".footer","a footer"));
- data.put("SERVER_URL",configurationService.getServerUri());
- data.put("baseUri", configurationService.getServerUri());
-
- //create template
- Template template = configuration.getTemplate("timemap.ftl");
-
- //create writer
- OutputStreamWriter writer = new OutputStreamWriter(out);
-
- //process
- template.process(data, writer);
-
- //flush and close writer
- writer.flush();
- writer.close();
-
- } catch (RepositoryException e) {
- throw new IOException("cannot serialize versions in text/html format");
- } catch (TemplateException e) {
- throw new IOException("cannot finish templating");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
deleted file mode 100644
index 24ae710..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.io;
-
-import org.apache.marmotta.platform.versioning.utils.MementoUtils;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.Resource;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Serializes an ordered list of versions in application/link-format into an output stream
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-@ApplicationScoped
-public class LinkVersionSerializer implements VersionSerializer {
-
- @Inject
- ConfigurationService configurationService;
-
- //a static list thta contains the contentTypes
- private static final List<ContentType> contentTypes = new ArrayList(){{
- add(new ContentType("application","link-format"));
- }};
-
- /**
- * return the content type that will be produced
- * @return
- */
- public ContentType getContentType() {
- return new ContentType("application","link-format");
- }
-
- /**
- * returns a list of supported content types (application/link-format)
- * @return a list of types
- */
- @Override
- public List<ContentType> getContentTypes() {
- return contentTypes;
- }
-
- /**
- * writes serialized version list (application/link-format) to output stream
- * @param original the original (current) resource
- * @param versions a list of versions in ascending order
- * @param out an output stream
- */
- @Override
- public void write(Resource original, RepositoryResult<Version> versions, OutputStream out) throws IOException {
-
- try {
- BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out));
-
- //write original resource
- w.append("<");
- w.append(original.toString());
- w.append(">;rel=\"original\",");
- w.newLine();
-
- //to control the loop
- boolean first = true;
-
- //write versions
- while (versions.hasNext()) {
-
- Version v = versions.next();
-
- //append memento resource uri for versions v
- w.append("<");
- w.append(MementoUtils.resourceURI(original.toString(),v.getCommitTime(),configurationService.getBaseUri()).toString());
- w.append(">; rel=\"");
-
- //write first, last, memento
- if( first && versions.hasNext()) {
- w.append("first memento");
- } else if(!versions.hasNext()) {
- w.append("last memento");
- } else {
- w.append("memento");
- }
-
- //add datetime
- w.append("\"; datetime=\"");
- w.append(v.getCommitTime().toString());
- w.append("\",");
-
- w.newLine();
- first = false;
- }
-
- w.flush();
- w.close();
-
- } catch (RepositoryException e) {
- throw new IOException("cannot serialize versions in application/link-format");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/VersionSerializer.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/VersionSerializer.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/VersionSerializer.java
deleted file mode 100644
index cd8b63e..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/io/VersionSerializer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.io;
-
-import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.Resource;
-import org.openrdf.repository.RepositoryResult;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-
-/**
- * Serializes an ordered list of versions into an output stream
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-public interface VersionSerializer {
-
- /**
- * returns a list of supported content types
- * @return
- */
- public List<ContentType> getContentTypes();
-
- /**
- * return the content type that will be produced
- * @return
- */
- public ContentType getContentType();
-
- /**
- * writes serialized version list to output stream
- * @param original the original (current) resource
- * @param versions a list of versions in ascending order
- * @param out an output stream
- */
- public void write(Resource original, RepositoryResult<Version> versions, OutputStream out) throws IOException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/model/MementoVersionSet.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/model/MementoVersionSet.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/model/MementoVersionSet.java
deleted file mode 100644
index fded920..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/model/MementoVersionSet.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.model;
-
-import org.apache.marmotta.platform.versioning.utils.MementoUtils;
-import org.apache.marmotta.platform.versioning.exception.MementoException;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.Resource;
-
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * This POJO represents a set of resource versions including last, first, prev, next and current versions
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-public class MementoVersionSet {
-
- private Version first;
- private Version last;
- private Version previous;
- private Version next;
- private Version current;
- private Resource original;
-
- public MementoVersionSet(Resource resource) {
- this.original = resource;
- }
-
- public Set<String> buildLinks(String baseURI) throws MementoException {
-
- String prefix = baseURI +
- MementoUtils.MEMENTO_WEBSERVICE + "/" +
- MementoUtils.MEMENTO_RESOURCE + "/";
-
- HashSet<String> links = new HashSet<String>();
-
- //first, last and current are mandatory
- if( first == null || last == null || current == null) throw new MementoException("Memento links cannot be produced");
-
- links.add(buildLink(prefix,original.toString(),first.getCommitTime(),"first memento"));
- links.add(buildLink(prefix,original.toString(),last.getCommitTime(),"last memento"));
- links.add(buildLink(prefix,original.toString(),current.getCommitTime(),"memento"));
-
- //add link to original
- links.add("<"+original.toString()+">;rel=\"original\"");
-
- //add next and previous if they exist
- if( next != null ) links.add(buildLink(prefix,original.toString(),next.getCommitTime(),"next memento"));
- if( previous != null ) links.add(buildLink(prefix,original.toString(),previous.getCommitTime(),"prev memento"));
-
- return links;
- }
-
- private String buildLink( String prefix, String resource, Date date, String rel ) {
- return "<" + prefix + MementoUtils.MEMENTO_DATE_FORMAT.format(date) + "/" + resource +
- ">;datetime=\"" + date.toString() + "\";rel=\"" + rel +"\"";
- }
-
- public Resource getOriginal() {
- return original;
- }
-
- public Version getFirst() {
- return first;
- }
-
- public void setFirst(Version first) {
- this.first = first;
- }
-
- public Version getLast() {
- return last;
- }
-
- public void setLast(Version last) {
- this.last = last;
- }
-
- public Version getPrevious() {
- return previous;
- }
-
- public void setPrevious(Version previous) {
- this.previous = previous;
- }
-
- public Version getNext() {
- return next;
- }
-
- public void setNext(Version next) {
- this.next = next;
- }
-
- public Version getCurrent() {
- return current;
- }
-
- public void setCurrent(Version current) {
- this.current = current;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/MementoServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/MementoServiceImpl.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/MementoServiceImpl.java
deleted file mode 100644
index 2da4841..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/MementoServiceImpl.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.services;
-
-import org.apache.marmotta.platform.versioning.api.MementoService;
-import org.apache.marmotta.platform.versioning.exception.MementoException;
-import org.apache.marmotta.platform.versioning.model.MementoVersionSet;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.Resource;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-import org.openrdf.sail.SailException;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import java.util.Date;
-
-/**
- * ...
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-@ApplicationScoped
-public class MementoServiceImpl implements MementoService {
-
- @Inject
- VersioningSailProvider versioningService;
-
- /**
- * returns the version for a resource that was current on the given date
- * @param resource a uri resource
- * @param date a date
- * @return the version with respect to the date
- * @throws MementoException
- */
- @Override
- public Version getVersion(Resource resource, Date date) throws MementoException {
- try {
- return versioningService.getLatestVersion(resource,date);
- } catch (SailException e) {
- throw new MementoException("version for "+date+" cannot be returned");
- }
- }
-
- /**
- * returns a memento version set that includes first, last, current, prev and next version with respect
- * to a given date and resource
- * @param resource a requested resource
- * @param date a requested date
- * @return a memento version set
- * @throws MementoException
- * @see MementoVersionSet
- */
- @Override
- public MementoVersionSet getVersionSet(Resource resource, Date date) throws MementoException {
- try {
- MementoVersionSet versionset = new MementoVersionSet(resource);
-
- //get current version
- versionset.setCurrent(versioningService.getLatestVersion(resource,date));
-
- //loop to all versions to fill the versionset
- RepositoryResult<Version> versions = versioningService.listVersions(resource);
-
- while(versions.hasNext()) {
-
- Version v = versions.next();
-
- //set first as current if there is no current version yet
- if(versionset.getCurrent() == null) versionset.setCurrent(v);
-
- //set first version
- if(versionset.getFirst() == null) versionset.setFirst(v);
-
- //set last version
- versionset.setLast(v);
-
- //set previous as long as id is smaller than the current one
- if(v.getId() < versionset.getCurrent().getId()) {
- versionset.setPrevious(v);
- }
-
- //set next if it is not set yet and the id is greater than the current one
- if(v.getId() > versionset.getCurrent().getId() && versionset.getNext() == null) {
- versionset.setNext(v);
- }
- }
-
- return versionset;
- } catch (SailException e) {
- throw new MementoException("cannot list versions");
- } catch (RepositoryException e) {
- throw new MementoException("cannot produce version result set");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
deleted file mode 100644
index c288f67..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersionSerializerServiceImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.services;
-
-import org.apache.marmotta.platform.versioning.api.VersionSerializerService;
-import org.apache.marmotta.platform.versioning.io.VersionSerializer;
-import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.MarmottaHttpUtils;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.List;
-
-/**
- * Returns a adequate serializer for a given list of ContentTypes
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-@ApplicationScoped
-public class VersionSerializerServiceImpl implements VersionSerializerService {
-
- @Inject @Any
- Instance<VersionSerializer> serializers;
-
- /**
- * returns an adequate serializer for a mimetype
- * @param type a list of mimetype (from Accept header)
- * @return a serializer
- * @throws IOException if there is no serializer for mimetype
- */
- @Override
- public VersionSerializer getSerializer(List<ContentType> type) throws IOException {
- for(VersionSerializer serializer : serializers) {
- if(MarmottaHttpUtils.bestContentType(serializer.getContentTypes(),type) != null) return serializer;
- }
- throw new IOException("Cannot find serializer for " + type);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
deleted file mode 100644
index f470c6c..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/services/VersioningSailProvider.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.services;
-
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.api.triplestore.SesameService;
-import org.apache.marmotta.platform.core.api.triplestore.TransactionalSailProvider;
-import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
-
-import org.apache.marmotta.commons.sesame.filter.AllOfFilter;
-import org.apache.marmotta.commons.sesame.filter.SesameFilter;
-import org.apache.marmotta.commons.sesame.filter.statement.StatementFilter;
-import org.apache.marmotta.kiwi.transactions.api.TransactionalSail;
-import org.apache.marmotta.kiwi.transactions.wrapper.TransactionalSailWrapper;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.apache.marmotta.kiwi.versioning.repository.SnapshotRepositoryConnection;
-import org.apache.marmotta.kiwi.versioning.sail.KiWiVersioningSail;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-import org.openrdf.sail.SailException;
-import org.slf4j.Logger;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A SAIL provider wrapping a versioning component around the repository
- * <p/>
- * Author: Sebastian Schaffert (sschaffert@apache.org)
- */
-@ApplicationScoped
-public class VersioningSailProvider implements TransactionalSailProvider {
-
- public static final String VERSIONING_ENABLED = "versioning.enabled";
- @Inject
- private Logger log;
-
- @Inject
- private ConfigurationService configurationService;
-
- @Inject
- private SesameService sesameService;
-
- @Inject
- @Named("versioning")
- private Instance<StatementFilter> filters;
-
-
- private KiWiVersioningSail sail;
-
- /**
- * Return the name of the provider. Used e.g. for displaying status information or logging.
- *
- * @return
- */
- @Override
- public String getName() {
- return "Versioning";
- }
-
- /**
- * Return true if this sail provider is enabled in the configuration.
- *
- * @return
- */
- @Override
- public boolean isEnabled() {
- return configurationService.getBooleanConfiguration(VERSIONING_ENABLED,true);
- }
-
-
- public void configurationChanged(@Observes ConfigurationChangedEvent e) {
- if(e.containsChangedKey(VERSIONING_ENABLED)) {
- sesameService.restart();
- }
- }
-
- /**
- * Create the sail wrapper provided by this SailProvider
- *
- * @param parent the parent sail to wrap by the provider
- * @return the wrapped sail
- */
- @Override
- public TransactionalSailWrapper createSail(TransactionalSail parent) {
- Set<SesameFilter<Statement>> sFilters = new HashSet<SesameFilter<Statement>>();
-
- StatementFilter filterCached = new StatementFilter() {
- @Override
- public boolean accept(Statement object) {
- if(object.getContext() != null && configurationService.getCacheContext().equals(object.getContext().stringValue())) return false;
- else
- return true;
- }
- };
- sFilters.add(filterCached);
-
- StatementFilter filterInferred = new StatementFilter() {
- @Override
- public boolean accept(Statement object) {
- if(object.getContext() != null && configurationService.getInferredContext().equals(object.getContext().stringValue())) return false;
- else
- return true;
- }
- };
- sFilters.add(filterInferred);
-
- StatementFilter filterEnhancing = new StatementFilter() {
- @Override
- public boolean accept(Statement object) {
- if(object.getContext() != null && configurationService.getEnhancerContex().equals(object.getContext().stringValue())) return false;
- else
- return true;
- }
- };
- sFilters.add(filterEnhancing);
-
- Iterator<StatementFilter> fIt = filters.iterator();
- while (fIt.hasNext()) {
- StatementFilter f = fIt.next();
- log.info("Auto-Registering filter {}", f.getClass().getSimpleName());
- sFilters.add(f);
- }
-
- sail = new KiWiVersioningSail(parent, new AllOfFilter<Statement>(sFilters));
-
- return sail;
- }
-
- /**
- * Get a read-only snapshot of the repository at the given date. Returns a sail connection that
- * can be used to access the triple data. Any attempts to modify the underlying data will throw
- * a SailReadOnlyException.
- *
- * @param snapshotDate the date of which to take the snapshot; the snapshot will consist of all
- * triples that have been created before or at the date and deleted after that date
- * (or not deleted at all).
- * @return a read-only sail connection to access the data of the triple store at the given date
- */
- public SnapshotRepositoryConnection getSnapshot(Date snapshotDate) throws RepositoryException {
- try {
- return new SnapshotRepositoryConnection(sesameService.getRepository(),sail.getSnapshot(snapshotDate));
- } catch (SailException e) {
- throw new RepositoryException(e);
- }
- }
-
- /**
- * List all versions of this repository.
- *
- * @return
- */
- public RepositoryResult<Version> listVersions() throws SailException {
- return sail.listVersions();
- }
-
- /**
- * List all versions of this repository between a start and end date.
- *
- * @return
- */
- public RepositoryResult<Version> listVersions(Date from, Date to) throws SailException {
- return sail.listVersions(from, to);
- }
-
- /**
- * List all versions of this repository affecting the given resource as subject.
- *
- * @return
- */
- public RepositoryResult<Version> listVersions(Resource r) throws SailException {
- return sail.listVersions(r);
- }
-
- /**
- * List all versions of this repository affecting the given resource as subject between a start and end date.
- *
- * @return
- */
- public RepositoryResult<Version> listVersions(Resource r, Date from, Date to) throws SailException {
- return sail.listVersions(r, from, to);
- }
-
- public Version getVersion(Long id) throws SailException {
- return sail.getVersion(id);
- }
-
- /**
- * Return the version that is the most recent version for a resource given a reference date. The method will either
- * return the version that was current for the resource at the given date or return null in case such a version
- * does not exist (e.g. before the resource was created).
- *
- * @param resource the resource for which to find a version
- * @param date the reference date
- * @return the latest version of the resource at the given date, or null if such a version does not exist
- * @throws java.sql.SQLException
- */
- public Version getLatestVersion(Resource r, Date date) throws SailException {
- return sail.getLatestVersion(r, date);
- }
-
- /**
- * Remove the version with the id passed as argument, including all references to added and removed triples. The
- * triples themselves are not deleted immediately, we let the garbage collector carry this out periodically.
- * @param id the database ID of the version (see {@link org.apache.marmotta.kiwi.versioning.model.Version#getId()})
- * @throws org.openrdf.sail.SailException
- */
- public void removeVersion(Long id) throws SailException {
- sail.removeVersion(id);
- }
-
- /**
- * Remove all versions in the given time interval. Iterates over all versions and deletes them individually.
- * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
- * without version will later be cleaned up by the garbage collector
- * @param from date after which versions will be deleted
- * @param to date before which versions will be deleted
- * @throws org.openrdf.sail.SailException
- */
- public void removeVersions(Date from, Date to) throws SailException {
- sail.removeVersions(from, to);
- }
-
- /**
- * Remove all versions until the date given as argument. Iterates over all versions and deletes them individually.
- * Entries in join tables (added/removed triples) are also deleted, the triples themselves not. Deleted triples
- * without version will later be cleaned up by the garbage collector
- * @param until date until when to delete versions
- * @throws org.openrdf.sail.SailException
- */
- public void removeVersions(Date until) throws SailException {
- sail.removeVersions(until);
- }
-
- /**
- * Revert (undo) the version given as argument. This method creates a new transaction, adds all triples
- * that were deleted in the old version, removes all triples that were added in the old version, and commits
- * the transaction, effectively creating a new (reverted) version.
- *
- * @param version the version to revert
- * @throws org.openrdf.sail.SailException in case reverting the version failed
- */
- public void revertVersion(Version version) throws SailException {
- sail.revertVersion(version);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/utils/MementoUtils.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/utils/MementoUtils.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/utils/MementoUtils.java
deleted file mode 100644
index 2a46738..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/utils/MementoUtils.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.utils;
-
-import java.net.URI;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * ...
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-public class MementoUtils {
-
- public static final String MEMENTO_WEBSERVICE = "memento";
- public static final String MEMENTO_TIMEGATE = "timegate";
- public static final String MEMENTO_TIMEMAP = "timemap";
- public static final String MEMENTO_RESOURCE = "resource";
-
- /**
- * is used for date format used in memento resource uris
- */
- public static final DateFormat MEMENTO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
-
- /**
- * builds a memento permalink
- * @param date the date of the version that should be represented by the permalink
- * @param resource the resource that should be represented by the permalink
- * @return a permalink
- */
- public static URI resourceURI(String resource, Date date, String baseURI) {
- return URI.create(
- baseURI +
- MEMENTO_WEBSERVICE + "/" +
- MEMENTO_RESOURCE + "/" +
- MEMENTO_DATE_FORMAT.format(date) + "/" +
- resource);
- }
-
- /**
- * builds a memento timemap uri
- * @param resource the resource that should be represented
- * @return a timemap uri
- */
- public static URI timemapURI(String resource, String baseURI) {
- return URI.create(
- baseURI +
- MEMENTO_WEBSERVICE + "/" +
- MEMENTO_TIMEMAP + "/" +
- resource);
- }
-
- /**
- * builds a memento timemap uri
- * @param resource the resource that should be represented
- * @return a timemap uri
- */
- public static URI timegateURI(String resource, String baseURI) {
- return URI.create(
- baseURI +
- MEMENTO_WEBSERVICE + "/" +
- MEMENTO_TIMEGATE + "/" +
- resource);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d655b517/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java b/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
deleted file mode 100644
index fc12de1..0000000
--- a/platform/marmotta-versioning/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.versioning.webservices;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.StreamingOutput;
-
-import org.apache.marmotta.platform.core.api.io.MarmottaIOService;
-import org.apache.marmotta.platform.versioning.api.VersionSerializerService;
-import org.apache.marmotta.platform.versioning.io.VersionSerializer;
-import org.apache.marmotta.platform.versioning.utils.MementoUtils;
-import org.apache.marmotta.platform.versioning.api.MementoService;
-import org.apache.marmotta.platform.versioning.exception.MementoException;
-import org.apache.marmotta.platform.versioning.model.MementoVersionSet;
-import org.apache.marmotta.platform.versioning.services.VersioningSailProvider;
-import com.google.common.base.Preconditions;
-import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
-import org.apache.marmotta.commons.util.DateUtils;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.api.triplestore.SesameService;
-import org.apache.marmotta.commons.collections.CollectionUtils;
-import org.apache.marmotta.commons.http.ContentType;
-import org.apache.marmotta.commons.http.MarmottaHttpUtils;
-import org.apache.marmotta.kiwi.versioning.model.Version;
-import org.openrdf.model.URI;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFHandlerException;
-import org.openrdf.rio.RDFWriter;
-import org.openrdf.rio.Rio;
-import org.openrdf.sail.SailException;
-import org.slf4j.Logger;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Webservice manages memento related services, namely:
- * <ul>
- * <li>Memento TimeGate Service: points to permalinks representing resource versions</li>
- * <li>Memento Resource Service: delivers versions of resources based on a permalink</li>
- * <li>Memento TimeBundle Service: TODO implement</li>
- * <li>Memento TimeMap Service: TODO implement</li>
- * </ul>
- * <p/>
- * Author: Thomas Kurz (tkurz@apache.org)
- */
-@ApplicationScoped
-@Path("/" + MementoUtils.MEMENTO_WEBSERVICE)
-public class MementoWebService {
-
- @Inject
- private Logger log;
- @Inject
- private ConfigurationService configurationService;
- @Inject
- private SesameService sesameService;
- @Inject
- private MementoService mementoService;
- @Inject
- private VersioningSailProvider versioningService;
- @Inject
- private MarmottaIOService lmfIOService;
- @Inject
- private VersionSerializerService versionSerializerService;
-
- /**
- * redirects to memento permalink resource
- * @param date_string the requested datetime
- * @param resource_string the requested resource string
- * @return a HTTP response
- * @HTTP 303 found resource on given location
- * @HTTP 400 some errors in request
- * @HTTP 404 resource or version cannot be found
- * @HTTP 500 any other failure
- */
- @GET
- @Path("/" + MementoUtils.MEMENTO_TIMEGATE + "/{resource:.+}")
- public Response timgateService(@PathParam("resource") String resource_string, @HeaderParam("Accept-Datetime") String date_string) {
-
- try {
- //check preconditions
- Preconditions.checkNotNull(resource_string,"Resource URI may not null");
- Preconditions.checkNotNull(date_string, "Accept-Datetime Header may not be null");
-
- RepositoryConnection conn = sesameService.getConnection();
-
- try {
- Date date = DateUtils.parseDate(date_string);
-
- URI resource = ResourceUtils.getUriResource(conn, resource_string);
-
- //get versions
- MementoVersionSet versions = mementoService.getVersionSet(resource, date);
-
- //build version links
- Set<String> links = versions.buildLinks(configurationService.getBaseUri());
-
- //add timemap link
- links.add("<" + MementoUtils.timemapURI(resource_string, configurationService.getBaseUri()) + ">;rel=timemap");
-
- //return permalink
- return Response
- .status(301)
- .location(MementoUtils.resourceURI(resource_string, versions.getCurrent().getCommitTime(), configurationService.getBaseUri()))
- .header("Vary", "negotiate, accept-datetime, accept")
- .header("Memento-Datetime", versions.getCurrent().getCommitTime().toString())
- .header("Link", CollectionUtils.fold(links, ", "))
- .build();
-
- } catch (MementoException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
- } finally {
- conn.commit();
- conn.close();
- }
- } catch (RepositoryException e) {
- return Response.serverError().entity("Versioning sail cannot be initialized").build();
- } catch (IllegalArgumentException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- } catch (NullPointerException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- }
- }
-
- /**
- * returns a serialisation for a given memento resource uri
- * @param date_string the date of the version
- * @param resource_string the original resource uri
- * @param types_string the accepted content types
- * @return a HTTP response
- * @HTTP 200 return resource in requested format
- * @HTTP 400 some errors in request
- * @HTTP 404 resource or version cannot be found
- * @HTTP 500 any other failure
- */
- @GET
- @Path("/" + MementoUtils.MEMENTO_RESOURCE + "/{date:[^/]+}/{resource:.+}")
- public Response resourceService(@PathParam("date")String date_string,
- @PathParam("resource") String resource_string,
- @HeaderParam("Accept") String types_string) {
-
- try {
- //check preconditions
- Preconditions.checkNotNull(resource_string,"Resource URI may not null");
- Preconditions.checkNotNull(date_string, "Date may not be null");
- Preconditions.checkNotNull(types_string, "Accept Header may not be null");
-
- RepositoryConnection conn = sesameService.getConnection();
-
- try {
- final Date date = MementoUtils.MEMENTO_DATE_FORMAT.parse(date_string);
-
- final URI resource = ResourceUtils.getUriResource(conn, resource_string);
-
- final ContentType type = getContentType(types_string);
-
- //get serializer
- final RDFFormat serializer = lmfIOService.getSerializer(type.getMime());
-
- //create response serialisation
- StreamingOutput entity = new StreamingOutput() {
- @Override
- public void write(OutputStream output) throws IOException, WebApplicationException {
- RDFWriter writer = Rio.createWriter(serializer, output);
- try {
- RepositoryConnection con = versioningService.getSnapshot(date);
- URI subject = con.getValueFactory().createURI(resource.stringValue());
- try {
- con.exportStatements(subject,null,null,true,writer);
- } catch (RepositoryException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- } catch (RDFHandlerException e) {
- throw new IOException("error while writing RDF data to stream");
- } finally {
- con.commit();
- con.close();
- }
- } catch (RepositoryException e) {
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
- }
- }
- };
-
- //get versions
- MementoVersionSet versions = mementoService.getVersionSet(resource, date);
-
- //build version links
- Set<String> links = versions.buildLinks(configurationService.getBaseUri());
-
- //add timegate link
- links.add("<" + MementoUtils.timegateURI(resource_string, configurationService.getBaseUri()) + ">;rel=timegate");
-
- //add timemap link
- links.add("<" + MementoUtils.timemapURI(resource_string, configurationService.getBaseUri()) + ">;rel=timemap");
-
- //create response
- return Response
- .ok()
- .header("Link", CollectionUtils.fold(links," ,"))
- .header("Content-Type", type.toString())
- .header("Memento-Datetime", versions.getCurrent().getCommitTime().toString())
- .entity(entity)
- .build();
-
- } catch (ParseException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity("Cannot parse date").build();
- } catch (IllegalArgumentException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- } catch (MementoException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
- } finally {
- conn.commit();
- conn.close();
- }
- } catch (IllegalArgumentException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- } catch (RepositoryException e) {
- return Response.serverError().entity("Versioning sail cannot be initialized").build();
- } catch (NullPointerException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- }
- }
-
- @GET
- @Path("/" + MementoUtils.MEMENTO_TIMEMAP + "/{resource:.+}")
- public Response timemapService(@PathParam("resource") String resource_string,
- @HeaderParam("Accept") String types_string) {
-
- try {
- //check preconditions
- Preconditions.checkNotNull(resource_string,"Resource URI may not null");
- Preconditions.checkNotNull(types_string, "Accept Header may not be null");
-
- RepositoryConnection conn = sesameService.getConnection();
-
- try {
-
- final URI resource = ResourceUtils.getUriResource(conn, resource_string);
-
- List<ContentType> types = MarmottaHttpUtils.parseAcceptHeader(types_string);
-
- //get versions
- final RepositoryResult<Version> versions = versioningService.listVersions(resource);
-
- //get serializer
- final VersionSerializer serializer = versionSerializerService.getSerializer(types);
-
- //create response serialisation
- StreamingOutput entity = new StreamingOutput() {
- @Override
- public void write(OutputStream output) throws IOException, WebApplicationException {
- serializer.write(resource,versions,output);
- }
- };
-
- //create Header Links
- Set<String> links = new HashSet<String>();
- links.add("<" + MementoUtils.timegateURI(resource_string, configurationService.getBaseUri()) + ">;rel=timegate");
-
- links.add("<" + resource_string + ">;rel=original");
-
- //create response
- return Response
- .ok()
- .header("Link", CollectionUtils.fold(links," ,"))
- .header("Content-Type", serializer.getContentType().toString())
- .entity(entity)
- .build();
-
- } catch (SailException e) {
- return Response.status(Response.Status.NOT_FOUND).entity("Cannot list versions").build();
- } catch (IOException e) {
- return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity("cannot produce content type").build();
- } finally {
- conn.commit();
- conn.close();
- }
- } catch (RepositoryException e) {
- return Response.serverError().entity("Versioning sail cannot be initialized").build();
- } catch (NullPointerException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- }
- }
-
- /**
- * returns the best fitting content type for accept type header string
- * @param types a string of types
- * @return a content type that is supported by the running system
- * @throws IllegalArgumentException if no type is supported
- */
- private ContentType getContentType(String types) throws IllegalArgumentException {
- List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
- List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(lmfIOService.getProducedTypes());
- ContentType type = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);
- if(type == null) throw new IllegalArgumentException("Requested type is not supported");
- return type;
- }
-
-}