Updated Branches:
  refs/heads/develop 7eb304f8e -> 2af1d8ac4

MARMOTTA-168: listing versions did not work at all because of a templating 
error - switched Versioning serialisation to use the templatingService


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2af1d8ac
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2af1d8ac
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2af1d8ac

Branch: refs/heads/develop
Commit: 2af1d8ac4b7a4e2c0b62d0e889cd0d176ed0c0eb
Parents: 7eb304f
Author: Jakob Frank <[email protected]>
Authored: Wed Jan 8 17:04:05 2014 +0100
Committer: Jakob Frank <[email protected]>
Committed: Wed Jan 8 17:06:21 2014 +0100

----------------------------------------------------------------------
 .../versioning/exception/MementoException.java  |  2 +
 .../versioning/io/HtmlVersionSerializer.java    | 54 +++++++---------
 .../versioning/io/LinkVersionSerializer.java    | 23 ++++---
 .../webservices/MementoWebService.java          | 42 ++++++------
 .../webservices/VersioningWebService.java       | 29 ++++++---
 .../src/main/resources/template/timemap.ftl     | 68 --------------------
 .../resources/templates/memento_timemap.ftl     | 68 ++++++++++++++++++++
 7 files changed, 146 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
index c5642f9..74ff54e 100644
--- 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
+++ 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/exception/MementoException.java
@@ -24,6 +24,8 @@ package org.apache.marmotta.platform.versioning.exception;
  */
 public class MementoException extends Exception {
 
+    private static final long serialVersionUID = 1L;
+
     public MementoException() {}
 
     public MementoException(String m) {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
index 17949bc..a32974b 100644
--- 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
+++ 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/HtmlVersionSerializer.java
@@ -17,27 +17,28 @@
  */
 package org.apache.marmotta.platform.versioning.io;
 
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
 import org.apache.marmotta.commons.http.ContentType;
 import org.apache.marmotta.kiwi.versioning.model.Version;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.templating.TemplatingService;
 import org.apache.marmotta.platform.versioning.utils.MementoUtils;
 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;
+import freemarker.template.TemplateException;
 
 /**
  * Serializes an ordered list of versions in text/html into an output stream
@@ -47,23 +48,17 @@ import java.util.Map;
 @ApplicationScoped
 public class HtmlVersionSerializer implements VersionSerializer {
 
-    @Inject
-    ConfigurationService configurationService;
+    private static final String TEMPLATE = "memento_timemap.ftl";
 
-    private Configuration configuration;
+    @Inject
+    private ConfigurationService configurationService;
+    
+    @Inject
+    private TemplatingService templatingService;
 
-    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"));
-    }};
+    private static final List<ContentType> contentTypes = Arrays.asList(new 
ContentType("text","html"));
 
     /**
      * return the content type that will be produced
@@ -84,7 +79,6 @@ public class HtmlVersionSerializer implements 
VersionSerializer {
 
     /**
      * 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
@@ -118,19 +112,15 @@ public class HtmlVersionSerializer implements 
VersionSerializer {
             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);
+            templatingService.process(this.getClass(), TEMPLATE, 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) {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
index fc8ed0b..2a9eafd 100644
--- 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
+++ 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/io/LinkVersionSerializer.java
@@ -17,6 +17,16 @@
  */
 package org.apache.marmotta.platform.versioning.io;
 
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
 import org.apache.marmotta.commons.http.ContentType;
 import org.apache.marmotta.kiwi.versioning.model.Version;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
@@ -25,15 +35,6 @@ 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.BufferedWriter;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * Serializes an ordered list of versions in application/link-format into an 
output stream
  * <p/>
@@ -46,9 +47,7 @@ public class LinkVersionSerializer implements 
VersionSerializer {
     ConfigurationService configurationService;
 
     //a static list thta contains the contentTypes
-    private static final List<ContentType> contentTypes = new ArrayList(){{
-        add(new ContentType("application","link-format"));
-    }};
+    private static final List<ContentType> contentTypes = Arrays.asList(new 
ContentType("application","link-format"));
 
     /**
      * return the content type that will be produced

http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
index 57ae98b..dffac04 100644
--- 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
+++ 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
@@ -17,11 +17,27 @@
  */
 package org.apache.marmotta.platform.versioning.webservices;
 
-import com.google.common.base.Preconditions;
+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;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+
 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.commons.sesame.repository.ResourceUtils;
 import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.kiwi.versioning.model.Version;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
@@ -45,18 +61,7 @@ import org.openrdf.rio.Rio;
 import org.openrdf.sail.SailException;
 import org.slf4j.Logger;
 
-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 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;
+import com.google.common.base.Preconditions;
 
 /**
  * Webservice manages memento related services, namely:
@@ -107,12 +112,11 @@ public class MementoWebService {
             Preconditions.checkNotNull(resource_string,"Resource URI may not 
null");
             Preconditions.checkNotNull(date_string, "Accept-Datetime Header 
may not be null");
 
-            RepositoryConnection conn = sesameService.getConnection();
-
+            final RepositoryConnection conn = sesameService.getConnection();
             try {
                 Date date = DateUtils.parseDate(date_string);
 
-                URI resource = ResourceUtils.getUriResource(conn, 
resource_string);
+                URI resource = 
conn.getValueFactory().createURI(resource_string);
 
                 //get versions
                 MementoVersionSet versions = 
mementoService.getVersionSet(resource, date);
@@ -175,7 +179,7 @@ public class MementoWebService {
             try {
                 final Date date = 
MementoUtils.MEMENTO_DATE_FORMAT.parse(date_string);
 
-                final URI resource = ResourceUtils.getUriResource(conn, 
resource_string);
+                final URI resource = 
conn.getValueFactory().createURI(resource_string);
 
                 final ContentType type = getContentType(types_string);
 
@@ -260,7 +264,7 @@ public class MementoWebService {
 
             try {
 
-                final URI resource = ResourceUtils.getUriResource(conn, 
resource_string);
+                final URI resource = 
conn.getValueFactory().createURI(resource_string);
 
                 List<ContentType> types = 
MarmottaHttpUtils.parseAcceptHeader(types_string);
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
index 3e18508..d742c41 100644
--- 
a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
+++ 
b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/VersioningWebService.java
@@ -18,7 +18,25 @@
 package org.apache.marmotta.platform.versioning.webservices;
 
 import info.aduna.iteration.Iterations;
-import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
 import org.apache.marmotta.commons.util.DateUtils;
 import org.apache.marmotta.commons.util.JSONUtils;
 import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
@@ -34,13 +52,6 @@ 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.inject.Inject;
-import javax.ws.rs.*;
-import javax.ws.rs.core.Response;
-import java.util.*;
-
 /**
  * Webservice allowing access to the versioning functionality of the LMF. 
Provides the following functionalities:
  * <ul>
@@ -98,7 +109,7 @@ public class VersioningWebService {
             RepositoryConnection conn = sesameService.getConnection();
             try {
                 if(resource_uri != null) {
-                    URI resource = 
ResourceUtils.getUriResource(conn,resource_uri);
+                    URI resource = 
conn.getValueFactory().createURI(resource_uri);
                     if(resource != null && resource instanceof 
KiWiUriResource) {
 
                         if(dateFrom == null && dateTo == null) {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/resources/template/timemap.ftl
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/resources/template/timemap.ftl 
b/platform/marmotta-versioning-kiwi/src/main/resources/template/timemap.ftl
deleted file mode 100644
index 44a717d..0000000
--- a/platform/marmotta-versioning-kiwi/src/main/resources/template/timemap.ftl
+++ /dev/null
@@ -1,68 +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.
-
--->
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
-    <title>Timemap in HTML</title>
-    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
-    <script type="text/javascript" 
src="${baseUri}webjars/jquery/1.8.2/jquery.min.js"></script>
-    <link href="${SERVER_URL}${DEFAULT_STYLE}style.css" rel="stylesheet" 
type="text/css" />
-    <link href="${SERVER_URL}${DEFAULT_STYLE}rdfhtml.css" rel="stylesheet" 
type="text/css" />
-</head>
-
-<body>
-
-<div id="wrapper">
-    <div id="header">
-        <a id="logo" href="${SERVER_URL}">
-            <img src="${SERVER_URL}${LOGO}">
-        </a>
-        <h1 style="left:200px">Memento Timemap</h1>
-        <div class="clean"></div>
-    </div>
-    <div id="center" style="width: 100%">
-        <div id="content">
-            <table class="simple_table">
-                <tr>
-                    <th>Verions</th>
-                </tr>
-                <#list versions as version>
-                <tr>
-                    <td><a target="_blank" href="${version.uri}" 
class="ldcache">${version.date}</a></td>
-                </tr>
-            </#list>
-            </table>
-        </div>
-    </div>
-
-    <div class="clear"></div>
-    <div id="footer">
-        <div id="footer_line">
-            <span>
-            ${FOOTER}<br>
-                The version access is following the <a 
href="http://www.mementoweb.org/";>Memento</a> principles.
-            </span>
-        </div>
-    </div>
-</div>
-</body>
-
-</html>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/2af1d8ac/platform/marmotta-versioning-kiwi/src/main/resources/templates/memento_timemap.ftl
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-versioning-kiwi/src/main/resources/templates/memento_timemap.ftl
 
b/platform/marmotta-versioning-kiwi/src/main/resources/templates/memento_timemap.ftl
new file mode 100644
index 0000000..44a717d
--- /dev/null
+++ 
b/platform/marmotta-versioning-kiwi/src/main/resources/templates/memento_timemap.ftl
@@ -0,0 +1,68 @@
+<#--
+
+    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.
+
+-->
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <title>Timemap in HTML</title>
+    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+    <script type="text/javascript" 
src="${baseUri}webjars/jquery/1.8.2/jquery.min.js"></script>
+    <link href="${SERVER_URL}${DEFAULT_STYLE}style.css" rel="stylesheet" 
type="text/css" />
+    <link href="${SERVER_URL}${DEFAULT_STYLE}rdfhtml.css" rel="stylesheet" 
type="text/css" />
+</head>
+
+<body>
+
+<div id="wrapper">
+    <div id="header">
+        <a id="logo" href="${SERVER_URL}">
+            <img src="${SERVER_URL}${LOGO}">
+        </a>
+        <h1 style="left:200px">Memento Timemap</h1>
+        <div class="clean"></div>
+    </div>
+    <div id="center" style="width: 100%">
+        <div id="content">
+            <table class="simple_table">
+                <tr>
+                    <th>Verions</th>
+                </tr>
+                <#list versions as version>
+                <tr>
+                    <td><a target="_blank" href="${version.uri}" 
class="ldcache">${version.date}</a></td>
+                </tr>
+            </#list>
+            </table>
+        </div>
+    </div>
+
+    <div class="clear"></div>
+    <div id="footer">
+        <div id="footer_line">
+            <span>
+            ${FOOTER}<br>
+                The version access is following the <a 
href="http://www.mementoweb.org/";>Memento</a> principles.
+            </span>
+        </div>
+    </div>
+</div>
+</body>
+
+</html>

Reply via email to