|
| 1 | +package org.aksw.sparql_integrate.cli.main; |
| 2 | + |
| 3 | +import jakarta.servlet.ServletRegistration; |
| 4 | +import jakarta.servlet.http.HttpServlet; |
| 5 | +import jakarta.servlet.http.HttpServletRequest; |
| 6 | +import jakarta.servlet.http.HttpServletResponse; |
| 7 | +import jakarta.ws.rs.core.MediaType; |
| 8 | +import org.aksw.jenax.web.server.boot.ServletBuilder; |
| 9 | +import org.springframework.web.WebApplicationInitializer; |
| 10 | +import org.springframework.web.context.support.GenericWebApplicationContext; |
| 11 | + |
| 12 | +import java.io.IOException; |
| 13 | +import java.io.PrintWriter; |
| 14 | + |
| 15 | +public class ServletLdvConfigJs extends HttpServlet implements ServletBuilder { |
| 16 | + |
| 17 | + private String dbEngine; |
| 18 | + |
| 19 | + public static ServletLdvConfigJs newBuilder() { |
| 20 | + return new ServletLdvConfigJs(); |
| 21 | + } |
| 22 | + |
| 23 | + @Override |
| 24 | + public WebApplicationInitializer build(GenericWebApplicationContext rootContext) { |
| 25 | + return servletContext -> { |
| 26 | + ServletRegistration.Dynamic servlet = servletContext.addServlet("dbEngineSetting", this); |
| 27 | + servlet.addMapping("/dbEngineSetting"); |
| 28 | + servlet.addMapping("/dbEngineSetting/"); |
| 29 | + servlet.addMapping("/_/js2/config.js"); |
| 30 | + servlet.setLoadOnStartup(1); |
| 31 | + }; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { |
| 36 | + PrintWriter writer = resp.getWriter(); |
| 37 | + if ("/_/js2/config.js".equals(req.getServletPath())) { |
| 38 | + resp.setContentType("text/javascript;charset=utf-8"); |
| 39 | + writer.println(""" |
| 40 | +(() => { |
| 41 | + const ldvConfig = { |
| 42 | + endpointUrl: '/sparql', |
| 43 | + endpointOptions: { |
| 44 | + mode: 'cors', |
| 45 | + credentials: 'same-origin', |
| 46 | + method: 'POST', |
| 47 | + }, |
| 48 | + datasetBase: window.location.origin, |
| 49 | + exploreUrl: '@EXPLORE_URL@', |
| 50 | + graphLookup: '@GRAPH_LOOKUP@', |
| 51 | + reverseEnabled: '@SHOW_INVERSE@', |
| 52 | + labelLang: 'en', |
| 53 | + labelLangChoice: ['en', 'de', 'nl', 'fr'], |
| 54 | + infer: false, |
| 55 | + fileOnly: 'yes', |
| 56 | + } |
| 57 | +
|
| 58 | + window.ldvConfig = ldvConfig |
| 59 | +})() |
| 60 | +""".replace("@SHOW_INVERSE@", "binsearch".equals(this.getDbEngine()) ? "no" : "yes")); |
| 61 | + } else { |
| 62 | + resp.setContentType(MediaType.TEXT_PLAIN); |
| 63 | + writer.println(this.getDbEngine()); |
| 64 | + } |
| 65 | + writer.close(); |
| 66 | + } |
| 67 | + |
| 68 | + public ServletBuilder setDbEngine(String dbEngine) { |
| 69 | + this.dbEngine = dbEngine; |
| 70 | + return this; |
| 71 | + } |
| 72 | + |
| 73 | + public String getDbEngine() { |
| 74 | + return dbEngine; |
| 75 | + } |
| 76 | +} |
0 commit comments