Skip to content

Commit 13e5e66

Browse files
committed
Formatting and upgrade to Jetty 9.3.6
1 parent e3ceeeb commit 13e5e66

12 files changed

+235
-223
lines changed

nb-configuration.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
10+
<!--
11+
Properties that influence various parts of the IDE, especially code formatting and the like.
12+
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
13+
That way multiple projects can share the same settings (useful for formatting rules for example).
14+
Any value defined here will override the pom.xml file value but is only applicable to the current project.
15+
-->
16+
<netbeans.hint.license>mit</netbeans.hint.license>
17+
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
18+
<org-netbeans-modules-whitelist.whitelist-oracle>false</org-netbeans-modules-whitelist.whitelist-oracle>
19+
</properties>
20+
</project-shared-configuration>

pom.xml

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,21 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>LDF-Server</groupId>
55
<artifactId>LDF-Server</artifactId>
6-
<version>0.0.1</version>
6+
<version>0.0.2</version>
77
<packaging>war</packaging>
88

99
<properties>
10-
<jettyVersion>9.2.5.v20141112</jettyVersion>
10+
<jettyVersion>9.3.6.v20151106</jettyVersion>
1111
</properties>
12-
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>
6112
<build>
6213
<sourceDirectory>src</sourceDirectory>
6314
<plugins>
6415
<plugin>
6516
<artifactId>maven-compiler-plugin</artifactId>
6617
<version>3.1</version>
6718
<configuration>
68-
<source>1.7</source>
69-
<target>1.7</target>
19+
<source>1.8</source>
20+
<target>1.8</target>
7021
</configuration>
7122
</plugin>
7223
<plugin>
@@ -104,4 +55,31 @@
10455
</plugin>
10556
</plugins>
10657
</build>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.eclipse.jetty</groupId>
61+
<artifactId>jetty-server</artifactId>
62+
<version>9.3.6.v20151106</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.google.code.gson</groupId>
66+
<artifactId>gson</artifactId>
67+
<version>2.5</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.rdfhdt</groupId>
71+
<artifactId>hdt-jena</artifactId>
72+
<version>1.1</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>commons-cli</groupId>
76+
<artifactId>commons-cli</artifactId>
77+
<version>1.3.1</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.eclipse.jetty</groupId>
81+
<artifactId>jetty-servlet</artifactId>
82+
<version>9.3.6.v20151106</version>
83+
</dependency>
84+
</dependencies>
10785
</project>

src/org/linkeddatafragments/config/ConfigReader.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@
1515
* @author Ruben Verborgh
1616
*/
1717
public class ConfigReader {
18-
19-
private final Map<String, JsonObject> dataSources = new HashMap<String, JsonObject>();
20-
private final Map<String, String> prefixes = new HashMap<String, String>();
18+
private final Map<String, JsonObject> dataSources = new HashMap<>();
19+
private final Map<String, String> prefixes = new HashMap<>();
2120

2221
/**
2322
* Creates a new configuration reader.
2423
*
2524
* @param configReader the configuration
2625
*/
2726
public ConfigReader(Reader configReader) {
28-
final JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
29-
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
30-
final JsonObject dataSource = entry.getValue().getAsJsonObject();
27+
JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
28+
for (Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
29+
JsonObject dataSource = entry.getValue().getAsJsonObject();
3130
this.dataSources.put(entry.getKey(), dataSource);
3231
}
33-
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet()) {
32+
for (Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet()) {
3433
this.prefixes.put(entry.getKey(), entry.getValue().getAsString());
3534
}
3635
}

src/org/linkeddatafragments/datasource/HdtDataSource.java

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,53 +49,61 @@ public TriplePatternFragment getFragment(Resource subject, Property predicate, R
4949
throw new IllegalArgumentException("limit");
5050
}
5151

52-
// look up the result from the HDT datasource
53-
final int subjectId = subject == null ? 0 : dictionary.getIntID(subject.asNode(), TripleComponentRole.SUBJECT);
54-
final int predicateId = predicate == null ? 0 : dictionary.getIntID(predicate.asNode(), TripleComponentRole.PREDICATE);
55-
final int objectId = object == null ? 0 : dictionary.getIntID(object.asNode(), TripleComponentRole.OBJECT);
52+
// look up the result from the HDT datasource)
53+
int subjectId = subject == null ? 0 : dictionary.getIntID(subject.asNode(), TripleComponentRole.SUBJECT);
54+
int predicateId = predicate == null ? 0 : dictionary.getIntID(predicate.asNode(), TripleComponentRole.PREDICATE);
55+
int objectId = object == null ? 0 : dictionary.getIntID(object.asNode(), TripleComponentRole.OBJECT);
56+
5657
if (subjectId < 0 || predicateId < 0 || objectId < 0) {
5758
return new TriplePatternFragmentBase();
5859
}
60+
5961
final Model triples = ModelFactory.createDefaultModel();
60-
final IteratorTripleID matches = datasource.getTriples().search(new TripleID(subjectId, predicateId, objectId));
61-
final boolean hasMatches = matches.hasNext();
62+
IteratorTripleID matches = datasource.getTriples().search(new TripleID(subjectId, predicateId, objectId));
63+
boolean hasMatches = matches.hasNext();
6264

63-
if (hasMatches) {
64-
// try to jump directly to the offset
65-
boolean atOffset;
66-
if (matches.canGoTo()) {
67-
try {
68-
matches.goTo(offset);
69-
atOffset = true;
70-
}
71-
// if the offset is outside the bounds, this page has no matches
72-
catch (IndexOutOfBoundsException exception) { atOffset = false; }
73-
}
74-
// if not possible, advance to the offset iteratively
75-
else {
76-
matches.goToStart();
77-
for (int i = 0; !(atOffset = i == offset) && matches.hasNext(); i++)
78-
matches.next();
79-
}
80-
// try to add `limit` triples to the result model
81-
if (atOffset) {
82-
for (int i = 0; i < limit && matches.hasNext(); i++)
83-
triples.add(triples.asStatement(toTriple(matches.next())));
84-
}
85-
}
86-
87-
// estimates can be wrong; ensure 0 is returned if there are no results, and always more than actual results
88-
final long estimatedTotal = triples.size() > 0 ? Math.max(offset + triples.size() + 1, matches.estimatedNumResults())
89-
: hasMatches ? Math.max(matches.estimatedNumResults(), 1) : 0;
65+
if (hasMatches) {
66+
// try to jump directly to the offset
67+
boolean atOffset;
68+
if (matches.canGoTo()) {
69+
try {
70+
matches.goTo(offset);
71+
atOffset = true;
72+
} // if the offset is outside the bounds, this page has no matches
73+
catch (IndexOutOfBoundsException exception) {
74+
atOffset = false;
75+
}
76+
} // if not possible, advance to the offset iteratively
77+
else {
78+
matches.goToStart();
79+
for (int i = 0; !(atOffset = i == offset) && matches.hasNext(); i++) {
80+
matches.next();
81+
}
82+
}
83+
// try to add `limit` triples to the result model
84+
if (atOffset) {
85+
for (int i = 0; i < limit && matches.hasNext(); i++) {
86+
triples.add(triples.asStatement(toTriple(matches.next())));
87+
}
88+
}
89+
}
90+
91+
// estimates can be wrong; ensure 0 is returned if there are no results, and always more than actual results
92+
final long estimatedTotal = triples.size() > 0 ? Math.max(offset + triples.size() + 1, matches.estimatedNumResults())
93+
: hasMatches ? Math.max(matches.estimatedNumResults(), 1) : 0;
9094

9195
// create the fragment
9296
return new TriplePatternFragment() {
93-
@Override
94-
public Model getTriples() { return triples; }
95-
96-
@Override
97-
public long getTotalSize() { return estimatedTotal; }
98-
};
97+
@Override
98+
public Model getTriples() {
99+
return triples;
100+
}
101+
102+
@Override
103+
public long getTotalSize() {
104+
return estimatedTotal;
105+
}
106+
};
99107
}
100108

101109
/**
@@ -106,9 +114,9 @@ public TriplePatternFragment getFragment(Resource subject, Property predicate, R
106114
*/
107115
private Triple toTriple(TripleID tripleId) {
108116
return new Triple(
109-
dictionary.getNode(tripleId.getSubject(), TripleComponentRole.SUBJECT),
110-
dictionary.getNode(tripleId.getPredicate(), TripleComponentRole.PREDICATE),
111-
dictionary.getNode(tripleId.getObject(), TripleComponentRole.OBJECT)
117+
dictionary.getNode(tripleId.getSubject(), TripleComponentRole.SUBJECT),
118+
dictionary.getNode(tripleId.getPredicate(), TripleComponentRole.PREDICATE),
119+
dictionary.getNode(tripleId.getObject(), TripleComponentRole.OBJECT)
112120
);
113121
}
114122
}

src/org/linkeddatafragments/datasource/IDataSource.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
* @author Ruben Verborgh
1010
*/
1111
public interface IDataSource {
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 TriplePatternFragment getFragment(Resource subject, Property predicate, RDFNode object,
22-
long offset, long limit);
23-
public String getTitle();
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 TriplePatternFragment getFragment(Resource subject, Property predicate,
22+
RDFNode object, long offset, long limit);
23+
public String getTitle();
2424

25-
public String getDescription();
25+
public String getDescription();
2626
}

src/org/linkeddatafragments/datasource/TriplePatternFragment.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* @author Ruben Verborgh
88
*/
99
public interface TriplePatternFragment {
10-
/**
11-
* Gets the data of this fragment (possibly only partial).
12-
* @return the data as triples
13-
*/
14-
public Model getTriples();
15-
16-
/**
17-
* Gets the total number of triples in the fragment (can be an estimate).
18-
* @return the total number of triples
19-
*/
20-
public long getTotalSize();
10+
/**
11+
* Gets the data of this fragment (possibly only partial).
12+
* @return the data as triples
13+
*/
14+
public Model getTriples();
15+
16+
/**
17+
* Gets the total number of triples in the fragment (can be an estimate).
18+
* @return the total number of triples
19+
*/
20+
public long getTotalSize();
2121
}

src/org/linkeddatafragments/datasource/TriplePatternFragmentBase.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88
* @author Ruben Verborgh
99
*/
1010
public class TriplePatternFragmentBase implements TriplePatternFragment {
11-
private final Model triples;
12-
private final long totalSize;
13-
14-
/**
15-
* Creates an empty Basic Linked Data Fragment.
16-
*/
17-
public TriplePatternFragmentBase() {
18-
this(null, 0);
19-
}
20-
21-
/**
22-
* Creates a new Basic Linked Data Fragment.
23-
* @param triples the triples (possibly partial)
24-
* @param totalSize the total size
25-
*/
26-
public TriplePatternFragmentBase(Model triples, long totalSize) {
27-
this.triples = triples == null ? ModelFactory.createDefaultModel() : triples;
28-
this.totalSize = totalSize < 0 ? 0 : totalSize;
29-
}
11+
private final Model triples;
12+
private final long totalSize;
3013

31-
@Override
32-
public Model getTriples() {
33-
return triples;
34-
}
14+
/**
15+
* Creates an empty Basic Linked Data Fragment.
16+
*/
17+
public TriplePatternFragmentBase() {
18+
this(null, 0);
19+
}
3520

36-
@Override
37-
public long getTotalSize() {
38-
return totalSize;
39-
}
21+
/**
22+
* Creates a new Basic Linked Data Fragment.
23+
* @param triples the triples (possibly partial)
24+
* @param totalSize the total size
25+
*/
26+
public TriplePatternFragmentBase(Model triples, long totalSize) {
27+
this.triples = triples == null ? ModelFactory.createDefaultModel() : triples;
28+
this.totalSize = totalSize < 0 ? 0 : totalSize;
29+
}
30+
31+
@Override
32+
public Model getTriples() {
33+
return triples;
34+
}
35+
36+
@Override
37+
public long getTotalSize() {
38+
return totalSize;
39+
}
4040
}

0 commit comments

Comments
 (0)