diff --git a/src/main/java/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java b/src/main/java/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java
index cfd29d9..53860b4 100644
--- a/src/main/java/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java
+++ b/src/main/java/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java
@@ -4,6 +4,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
@@ -15,10 +16,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHeaders;
import org.apache.jena.query.ARQ;
import org.apache.jena.riot.Lang;
-import org.apache.jena.sys.JenaSystem;
import org.linkeddatafragments.config.ConfigReader;
import org.linkeddatafragments.datasource.DataSourceFactory;
import org.linkeddatafragments.datasource.DataSourceTypesRegistry;
@@ -30,6 +31,7 @@
import org.linkeddatafragments.fragments.ILinkedDataFragment;
import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest;
import org.linkeddatafragments.util.MIMEParse;
+import org.linkeddatafragments.views.HtmlTriplePatternFragmentWriterImpl;
import org.linkeddatafragments.views.ILinkedDataFragmentWriter;
import org.linkeddatafragments.views.LinkedDataFragmentWriterFactory;
@@ -106,6 +108,8 @@ public void init(ServletConfig servletConfig) throws ServletException {
MIMEParse.register(Lang.NTRIPLES.getHeaderString());
MIMEParse.register(Lang.JSONLD.getHeaderString());
MIMEParse.register(Lang.TTL.getHeaderString());
+
+ HtmlTriplePatternFragmentWriterImpl.setContextPath(servletConfig.getServletContext().getContextPath());
} catch (Exception e) {
throw new ServletException(e);
}
@@ -163,6 +167,22 @@ private IDataSource getDataSource(HttpServletRequest request) throws DataSourceN
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
+
+ // Ensure that 'assets' (favicon, css) resolve
+ int fileNamePos = request.getRequestURI().toLowerCase().lastIndexOf("assets/");
+ if (fileNamePos > 0) {
+ try {
+ String fileName = request.getRequestURI().substring(fileNamePos - 1);
+ InputStream in = LinkedDataFragmentServlet.class.getResourceAsStream(fileName);
+ if (in != null) {
+ IOUtils.copy(in, response.getOutputStream());
+ }
+ return;
+ } catch (IOException ioe) {
+ log("Should never happen", ioe);
+ }
+ }
+
ILinkedDataFragment fragment = null;
try {
// do conneg
diff --git a/src/main/java/org/linkeddatafragments/views/HtmlTriplePatternFragmentWriterImpl.java b/src/main/java/org/linkeddatafragments/views/HtmlTriplePatternFragmentWriterImpl.java
index 704c81f..4ff7923 100644
--- a/src/main/java/org/linkeddatafragments/views/HtmlTriplePatternFragmentWriterImpl.java
+++ b/src/main/java/org/linkeddatafragments/views/HtmlTriplePatternFragmentWriterImpl.java
@@ -36,7 +36,16 @@ public class HtmlTriplePatternFragmentWriterImpl extends TriplePatternFragmentWr
private final Template notfoundTemplate;
private final Template errorTemplate;
- private final String HYDRA = "http://www.w3.org/ns/hydra/core#";
+ private final String HYDRA = "http://www.w3.org/ns/hydra/core#";
+
+ private static String contextPath;
+
+ public static void setContextPath(String path) {
+ contextPath = path;
+ if (!contextPath.endsWith("/")) {
+ contextPath += "/";
+ }
+ }
/**
*
@@ -72,7 +81,8 @@ public void writeFragment(ServletOutputStream outputStream, IDataSource datasour
Map data = new HashMap();
// base.ftl.html
- data.put("assetsPath", "assets/");
+ data.put("homePath", (contextPath != null ? contextPath : ""));
+ data.put("assetsPath", contextPath + "assets/");
data.put("header", datasource.getTitle());
data.put("date", new Date());
@@ -124,6 +134,7 @@ public void writeFragment(ServletOutputStream outputStream, IDataSource datasour
@Override
public void writeNotFound(ServletOutputStream outputStream, HttpServletRequest request) throws Exception {
Map data = new HashMap();
+ data.put("homePath", (contextPath != null ? contextPath : ""));
data.put("assetsPath", "assets/");
data.put("datasources", getDatasources());
data.put("date", new Date());
@@ -135,6 +146,7 @@ public void writeNotFound(ServletOutputStream outputStream, HttpServletRequest r
@Override
public void writeError(ServletOutputStream outputStream, Exception ex) throws Exception {
Map data = new HashMap();
+ data.put("homePath", (contextPath != null ? contextPath : ""));
data.put("assetsPath", "assets/");
data.put("date", new Date());
data.put("error", ex);
diff --git a/src/main/resources/views/base.ftl.html b/src/main/resources/views/base.ftl.html
index c7bd137..911e281 100644
--- a/src/main/resources/views/base.ftl.html
+++ b/src/main/resources/views/base.ftl.html
@@ -5,16 +5,16 @@
${ title!header!"Linked Data Fragments Server" }
-
+
-
+
diff --git a/src/main/resources/views/index.ftl.html b/src/main/resources/views/index.ftl.html
index 76b7fc8..04048b7 100644
--- a/src/main/resources/views/index.ftl.html
+++ b/src/main/resources/views/index.ftl.html
@@ -7,7 +7,7 @@ Available datasets
<#if datasources??>
<#list datasources?keys as datasourceName>
- - ${datasources[datasourceName].getTitle() }
+ - ${datasources[datasourceName].getTitle() }
- ${ datasources[datasourceName].getDescription()!"" }
#list>
#if>