diff --git a/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/ServletLdvConfigJs.java b/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/ServletLdvConfigJs.java new file mode 100644 index 0000000..945f92f --- /dev/null +++ b/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/ServletLdvConfigJs.java @@ -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; + } +} diff --git a/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/SparqlIntegrateCmdImpls.java b/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/SparqlIntegrateCmdImpls.java index e6e568f..9e94543 100644 --- a/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/SparqlIntegrateCmdImpls.java +++ b/rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/SparqlIntegrateCmdImpls.java @@ -838,6 +838,8 @@ public void afterExec() { .addServletBuilder(ServletBuilderGraphQlV2.newBuilder() .setGraphQlExecFactory(graphQlExecFactoryV2) ) + .addServletBuilder(ServletLdvConfigJs.newBuilder() + .setDbEngine(cmd.engine)) .setPort(port).create(); server.start();