-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate ldv config file with inverse links disabled on binsearch
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...sing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/ServletLdvConfigJs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.aksw.sparql_integrate.cli.main; | ||
|
||
import jakarta.servlet.ServletRegistration; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import jakarta.ws.rs.core.MediaType; | ||
import org.aksw.jenax.web.server.boot.ServletBuilder; | ||
import org.springframework.web.WebApplicationInitializer; | ||
import org.springframework.web.context.support.GenericWebApplicationContext; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
public class ServletLdvConfigJs extends HttpServlet implements ServletBuilder { | ||
|
||
private String dbEngine; | ||
|
||
public static ServletLdvConfigJs newBuilder() { | ||
return new ServletLdvConfigJs(); | ||
} | ||
|
||
@Override | ||
public WebApplicationInitializer build(GenericWebApplicationContext rootContext) { | ||
return servletContext -> { | ||
ServletRegistration.Dynamic servlet = servletContext.addServlet("dbEngineSetting", this); | ||
servlet.addMapping("/dbEngineSetting"); | ||
servlet.addMapping("/dbEngineSetting/"); | ||
servlet.addMapping("/_/js2/config.js"); | ||
servlet.setLoadOnStartup(1); | ||
}; | ||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
PrintWriter writer = resp.getWriter(); | ||
if ("/_/js2/config.js".equals(req.getServletPath())) { | ||
resp.setContentType("text/javascript;charset=utf-8"); | ||
writer.println(""" | ||
(() => { | ||
const ldvConfig = { | ||
endpointUrl: '/sparql', | ||
endpointOptions: { | ||
mode: 'cors', | ||
credentials: 'same-origin', | ||
method: 'POST', | ||
}, | ||
datasetBase: window.location.origin, | ||
exploreUrl: '@EXPLORE_URL@', | ||
graphLookup: '@GRAPH_LOOKUP@', | ||
reverseEnabled: '@SHOW_INVERSE@', | ||
labelLang: 'en', | ||
labelLangChoice: ['en', 'de', 'nl', 'fr'], | ||
infer: false, | ||
fileOnly: 'yes', | ||
} | ||
window.ldvConfig = ldvConfig | ||
})() | ||
""".replace("@SHOW_INVERSE@", "binsearch".equals(this.getDbEngine()) ? "no" : "yes")); | ||
} else { | ||
resp.setContentType(MediaType.TEXT_PLAIN); | ||
writer.println(this.getDbEngine()); | ||
} | ||
writer.close(); | ||
} | ||
|
||
public ServletBuilder setDbEngine(String dbEngine) { | ||
this.dbEngine = dbEngine; | ||
return this; | ||
} | ||
|
||
public String getDbEngine() { | ||
return dbEngine; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters