Skip to content

Commit 6c35d95

Browse files
author
Miel Vander Sande
committed
Small refactoring for better extendability
1 parent 3617d83 commit 6c35d95

16 files changed

+692
-492
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.settings
22
target
33
ldf-server.json
4+
/data/

WebContent/WEB-INF/web.xml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xmlns="http://java.sun.com/xml/ns/javaee"
4-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5-
id="WebApp_ID" version="2.5">
6-
<display-name>Linked Data Fragments Server</display-name>
7-
<servlet>
8-
<display-name>BasicLdfServlet</display-name>
9-
<servlet-name>BasicLdfServlet</servlet-name>
10-
<servlet-class>org.linkeddatafragments.servlet.BasicLdfServlet</servlet-class>
11-
</servlet>
12-
<servlet-mapping>
13-
<servlet-name>BasicLdfServlet</servlet-name>
14-
<url-pattern>/*</url-pattern>
15-
</servlet-mapping>
16-
</web-app>
2+
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
3+
<display-name>Linked Data Fragments Server</display-name>
4+
<servlet>
5+
<display-name>BasicLdfServlet</display-name>
6+
<servlet-name>BasicLdfServlet</servlet-name>
7+
<servlet-class>org.linkeddatafragments.servlet.TriplePatternFragmentServlet</servlet-class>
8+
</servlet>
9+
<servlet-mapping>
10+
<servlet-name>BasicLdfServlet</servlet-name>
11+
<url-pattern>/*</url-pattern>
12+
</servlet-mapping>
13+
</web-app>

config-example.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"title": "My Linked Data Fragments server",
3+
4+
"datasources": {
5+
"dbpedia": {
6+
"title": "Semantic Web Dog Food",
7+
"type": "HdtDatasource",
8+
"description": "Semantic Web Dog Food with an HDT back-end",
9+
"settings": { "file": "data/swdf.hdt" }
10+
}
11+
},
12+
13+
"prefixes": {
14+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
15+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
16+
"xsd": "http://www.w3.org/2001/XMLSchema#",
17+
"dc": "http://purl.org/dc/terms/",
18+
"foaf": "http://xmlns.com/foaf/0.1/",
19+
"dbpedia": "http://dbpedia.org/resource/",
20+
"dbpedia-owl": "http://dbpedia.org/ontology/",
21+
"dbpprop": "http://dbpedia.org/property/",
22+
"hydra": "http://www.w3.org/ns/hydra/core#",
23+
"void": "http://rdfs.org/ns/void#"
24+
}
25+
}

pom.xml

Lines changed: 99 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,103 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>LDF-Server</groupId>
5-
<artifactId>LDF-Server</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
7-
<packaging>war</packaging>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>LDF-Server</groupId>
5+
<artifactId>LDF-Server</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
88

9-
<properties>
10-
<jettyVersion>9.2.5.v20141112</jettyVersion>
11-
</properties>
9+
<properties>
10+
<jettyVersion>9.2.5.v20141112</jettyVersion>
11+
</properties>
1212

13-
<dependencies>
14-
<dependency>
15-
<groupId>org.rdfhdt</groupId>
16-
<artifactId>hdt-jena</artifactId>
17-
<version>1.1</version>
18-
</dependency>
19-
<dependency>
20-
<groupId>org.apache.jena</groupId>
21-
<artifactId>jena-core</artifactId>
22-
<version>2.11.1</version>
23-
</dependency>
24-
<dependency>
25-
<groupId>org.apache.jena</groupId>
26-
<artifactId>jena-arq</artifactId>
27-
<version>2.11.1</version>
28-
</dependency>
29-
<dependency>
30-
<groupId>org.apache.httpcomponents</groupId>
31-
<artifactId>httpclient</artifactId>
32-
<version>4.3.5</version>
33-
</dependency>
34-
<dependency>
35-
<groupId>com.google.code.gson</groupId>
36-
<artifactId>gson</artifactId>
37-
<version>2.3</version>
38-
</dependency>
39-
<dependency>
40-
<groupId>javax.servlet</groupId>
41-
<artifactId>javax.servlet-api</artifactId>
42-
<version>3.1.0</version>
43-
<scope>compile</scope>
44-
</dependency>
45-
<dependency>
46-
<groupId>org.eclipse.jetty</groupId>
47-
<artifactId>jetty-server</artifactId>
48-
<version>${jettyVersion}</version>
49-
</dependency>
50-
<dependency>
51-
<groupId>org.eclipse.jetty</groupId>
52-
<artifactId>jetty-servlet</artifactId>
53-
<version>${jettyVersion}</version>
54-
</dependency>
55-
<dependency>
56-
<groupId>commons-cli</groupId>
57-
<artifactId>commons-cli</artifactId>
58-
<version>1.2</version>
59-
</dependency>
60-
</dependencies>
61-
<build>
62-
<sourceDirectory>src</sourceDirectory>
63-
<plugins>
64-
<plugin>
65-
<artifactId>maven-compiler-plugin</artifactId>
66-
<version>3.1</version>
67-
<configuration>
68-
<source>1.7</source>
69-
<target>1.7</target>
70-
</configuration>
71-
</plugin>
72-
<plugin>
73-
<artifactId>maven-war-plugin</artifactId>
74-
<version>2.3</version>
75-
<configuration>
76-
<warSourceDirectory>WebContent</warSourceDirectory>
77-
<failOnMissingWebXml>false</failOnMissingWebXml>
78-
</configuration>
79-
</plugin>
80-
</plugins>
81-
</build>
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.rdfhdt</groupId>
16+
<artifactId>hdt-jena</artifactId>
17+
<version>1.1</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.apache.jena</groupId>
21+
<artifactId>jena-core</artifactId>
22+
<version>2.11.1</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.apache.jena</groupId>
26+
<artifactId>jena-arq</artifactId>
27+
<version>2.11.1</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.apache.httpcomponents</groupId>
31+
<artifactId>httpclient</artifactId>
32+
<version>4.3.5</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.google.code.gson</groupId>
36+
<artifactId>gson</artifactId>
37+
<version>2.3</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>javax.servlet</groupId>
41+
<artifactId>javax.servlet-api</artifactId>
42+
<version>3.1.0</version>
43+
<scope>compile</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.eclipse.jetty</groupId>
47+
<artifactId>jetty-server</artifactId>
48+
<version>${jettyVersion}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.eclipse.jetty</groupId>
52+
<artifactId>jetty-servlet</artifactId>
53+
<version>${jettyVersion}</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>commons-cli</groupId>
57+
<artifactId>commons-cli</artifactId>
58+
<version>1.2</version>
59+
</dependency>
60+
</dependencies>
61+
<build>
62+
<sourceDirectory>src</sourceDirectory>
63+
<plugins>
64+
<plugin>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<version>3.1</version>
67+
<configuration>
68+
<source>1.7</source>
69+
<target>1.7</target>
70+
</configuration>
71+
</plugin>
72+
<plugin>
73+
<artifactId>maven-war-plugin</artifactId>
74+
<version>2.3</version>
75+
<configuration>
76+
<warSourceDirectory>WebContent</warSourceDirectory>
77+
<failOnMissingWebXml>false</failOnMissingWebXml>
78+
</configuration>
79+
</plugin>
80+
<plugin>
81+
<artifactId>maven-assembly-plugin</artifactId>
82+
<executions>
83+
<execution>
84+
<phase>package</phase>
85+
<goals>
86+
<goal>single</goal>
87+
</goals>
88+
</execution>
89+
</executions>
90+
<configuration>
91+
<archive>
92+
<manifest>
93+
<mainClass>org.linkeddatafragments.standalone.JettyServer</mainClass>
94+
</manifest>
95+
</archive>
96+
<descriptorRefs>
97+
<descriptorRef>jar-with-dependencies</descriptorRef>
98+
</descriptorRefs>
99+
</configuration>
100+
</plugin>
101+
</plugins>
102+
</build>
82103
</project>

src/org/linkeddatafragments/config/ConfigReader.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,45 @@
1111

1212
/**
1313
* Reads the configuration of a Linked Data Fragments server.
14+
*
1415
* @author Ruben Verborgh
1516
*/
1617
public class ConfigReader {
17-
private final Map<String, String> dataSources = new HashMap<String, String>();
18-
private final Map<String, String> prefixes = new HashMap<String, String>();
19-
20-
/**
21-
* Creates a new configuration reader.
22-
* @param configReader the configuration
23-
*/
24-
public ConfigReader(Reader configReader) {
18+
19+
private final Map<String, JsonObject> dataSources = new HashMap<String, JsonObject>();
20+
private final Map<String, String> prefixes = new HashMap<String, String>();
21+
22+
/**
23+
* Creates a new configuration reader.
24+
*
25+
* @param configReader the configuration
26+
*/
27+
public ConfigReader(Reader configReader) {
2528
final JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
2629
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
27-
final JsonObject dataSource = entry.getValue().getAsJsonObject();
28-
this.dataSources.put(entry.getKey(), dataSource.getAsJsonPrimitive("path").getAsString());
30+
final JsonObject dataSource = entry.getValue().getAsJsonObject();
31+
this.dataSources.put(entry.getKey(), dataSource);
32+
}
33+
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet()) {
34+
this.prefixes.put(entry.getKey(), entry.getValue().getAsString());
2935
}
30-
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet())
31-
this.prefixes.put(entry.getKey(), entry.getValue().getAsString());
32-
}
33-
34-
/**
35-
* Gets the data sources.
36-
* @return the data sources
37-
*/
38-
public Map<String, String> getDataSources() {
39-
return dataSources;
40-
}
41-
42-
/**
43-
* Gets the prefixes.
44-
* @return the prefixes
45-
*/
46-
public Map<String, String> getPrefixes() {
47-
return prefixes;
48-
}
36+
}
37+
38+
/**
39+
* Gets the data sources.
40+
*
41+
* @return the data sources
42+
*/
43+
public Map<String, JsonObject> getDataSources() {
44+
return dataSources;
45+
}
46+
47+
/**
48+
* Gets the prefixes.
49+
*
50+
* @return the prefixes
51+
*/
52+
public Map<String, String> getPrefixes() {
53+
return prefixes;
54+
}
4955
}
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package org.linkeddatafragments.datasource;
22

3-
import com.hp.hpl.jena.rdf.model.Property;
4-
import com.hp.hpl.jena.rdf.model.RDFNode;
5-
import com.hp.hpl.jena.rdf.model.Resource;
6-
73
/**
8-
* A data source of Basic Linked Data Fragments.
9-
* @author Ruben Verborgh
4+
*
5+
* @author mielvandersande
106
*/
11-
public interface DataSource {
12-
/**
13-
* Gets a page of the Basic Linked Data Fragment matching the specified triple pattern.
14-
* @param subject the subject (null to match any subject)
15-
* @param predicate the predicate (null to match any predicate)
16-
* @param object the object (null to match any object)
17-
* @param offset the triple index at which to start the page
18-
* @param limit the number of triples on the page
19-
* @return the first page of the fragment
20-
*/
21-
public BasicLinkedDataFragment getFragment(Resource subject, Property predicate, RDFNode object,
22-
long offset, long limit);
7+
public abstract class DataSource implements IDataSource {
8+
protected String title;
9+
protected String description;
10+
11+
public DataSource(String title, String description) {
12+
this.title = title;
13+
this.description = description;
14+
}
15+
16+
@Override
17+
public String getDescription() {
18+
return this.description;
19+
};
20+
21+
@Override
22+
public String getTitle() {
23+
return this.title;
24+
};
2325
}

0 commit comments

Comments
 (0)