Skip to content

Commit 6a495a1

Browse files
committed
Move configuration file.
1 parent a6a782e commit 6a495a1

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.settings
22
build
3-
WebContent/WEB-INF/config.json
3+
ldf-server.json

src/org/linkeddatafragments/config/ConfigReader.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.linkeddatafragments.config;
22

3-
import java.io.File;
4-
import java.io.FileReader;
3+
import java.io.Reader;
54
import java.util.HashMap;
65
import java.util.Map;
76
import java.util.Map.Entry;
@@ -20,19 +19,10 @@ public class ConfigReader {
2019

2120
/**
2221
* Creates a new configuration reader.
23-
* @param configFile the name of the configuration file
24-
* @throws Exception if the configuration cannot be loaded
22+
* @param configReader the configuration
2523
*/
26-
public ConfigReader(String configFile) throws Exception {
27-
// check the configuration file
28-
if (configFile == null || configFile.length() == 0)
29-
throw new Exception("No configuration file name specified.");
30-
final File config = new File(configFile);
31-
if (!config.exists())
32-
throw new Exception("Configuration file " + configFile + " does not exist.");
33-
34-
// read the configuration file
35-
final JsonObject root = new JsonParser().parse(new FileReader(config)).getAsJsonObject();
24+
public ConfigReader(Reader configReader) {
25+
final JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
3626
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
3727
final JsonObject dataSource = entry.getValue().getAsJsonObject();
3828
this.dataSources.put(entry.getKey(), dataSource.getAsJsonPrimitive("path").getAsString());

src/org/linkeddatafragments/servlet/BasicLdfServlet.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.linkeddatafragments.servlet;
22

3+
import java.io.File;
4+
import java.io.FileReader;
35
import java.util.HashMap;
46
import java.util.Map.Entry;
57
import java.util.regex.Matcher;
@@ -41,7 +43,15 @@ public class BasicLdfServlet extends HttpServlet {
4143
@Override
4244
public void init(ServletConfig servletConfig) throws ServletException {
4345
try {
44-
config = new ConfigReader(servletConfig.getInitParameter("configFile"));
46+
// find the configuration file
47+
final File applicationPath = new File(servletConfig.getServletContext().getRealPath("/"));
48+
final File serverHome = applicationPath.getParentFile().getParentFile();
49+
final File configFile = new File(serverHome, "conf/ldf-server.json");
50+
if (!configFile.exists())
51+
throw new Exception("Configuration file " + configFile + " not found.");
52+
53+
// load the configuration
54+
config = new ConfigReader(new FileReader(configFile));
4555
for (Entry<String, String> dataSource : config.getDataSources().entrySet())
4656
dataSources.put(dataSource.getKey(), new HdtDataSource(dataSource.getValue()));
4757
}
@@ -59,7 +69,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
5969
final String dataSourceName = path.substring(1);
6070
final DataSource dataSource = dataSources.get(dataSourceName);
6171
if (dataSource == null)
62-
throw new Exception("data source not found");
72+
throw new Exception("Data source not found.");
6373

6474
// query the fragment
6575
final Resource subject = parseAsResource(request.getParameter("subject"));

0 commit comments

Comments
 (0)