-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
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
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,154 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>sparqlGoodies</groupId> | ||
<artifactId>sparql-splitter</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<build> | ||
<sourceDirectory>src</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<archive> | ||
<manifest> | ||
<mainClass>net.bygle.owlViewer.HtmlGenerator</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<index>true</index> | ||
<manifest> | ||
<mainClass>net.bygle.owlViewer.HtmlGenerator</mainClass> | ||
<addClasspath>true</addClasspath> | ||
<classpathPrefix>dependency/</classpathPrefix> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
<pluginManagement> | ||
<plugins> | ||
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. --> | ||
<plugin> | ||
<groupId>org.eclipse.m2e</groupId> | ||
<artifactId>lifecycle-mapping</artifactId> | ||
<version>1.0.0</version> | ||
<configuration> | ||
<lifecycleMappingMetadata> | ||
<pluginExecutions> | ||
<pluginExecution> | ||
<pluginExecutionFilter> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<versionRange>[3.1,)</versionRange> | ||
<goals> | ||
<goal>testCompile</goal> | ||
<goal>compile</goal> | ||
</goals> | ||
</pluginExecutionFilter> | ||
<action> | ||
<ignore></ignore> | ||
</action> | ||
</pluginExecution> | ||
</pluginExecutions> | ||
</lifecycleMappingMetadata> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.jena</groupId> | ||
<artifactId>jena-arq</artifactId> | ||
<version>2.13.0</version> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<groupId>org.slf4j</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>4.1.7.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>4.1.7.RELEASE</version> | ||
</dependency> | ||
<!-- Servlet --> | ||
<dependency> | ||
<groupId>org.apache.tomcat</groupId> | ||
<artifactId>tomcat-servlet-api</artifactId> | ||
<version>7.0.30</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>jsp-api</artifactId> | ||
<version>2.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp.jstl</groupId> | ||
<artifactId>jstl-api</artifactId> | ||
<version>1.2</version> | ||
<scope>provided</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>1.0.13</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.0.13</version> | ||
</dependency> | ||
</dependencies> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>Codehaus</id> | ||
<url>http://repository.codehaus.org/</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</project> |
48 changes: 48 additions & 0 deletions
48
src/main/java/it/linkeddata/sparqlGoodies/controllers/ErrorController.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,48 @@ | ||
package it.linkeddata.sparqlGoodies.controllers; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.CookieValue; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@Controller | ||
public class ErrorController { | ||
|
||
/* TODO: change the handler to send "error" param to the client */ | ||
@ResponseStatus(value = HttpStatus.NOT_ACCEPTABLE, reason = "unhandled encoding") | ||
@RequestMapping(value = "/406") | ||
public String error406(HttpServletResponse res, ModelMap model) { | ||
model.addAttribute("statusCode", "406"); | ||
res.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); | ||
return "error"; | ||
} | ||
|
||
@RequestMapping(value = "/404") | ||
public String error404(HttpServletResponse res, ModelMap model, @RequestParam(value = "error", defaultValue = "") String error) { | ||
model.addAttribute("error", error); | ||
model.addAttribute("statusCode", "404"); | ||
res.setStatus(HttpServletResponse.SC_NOT_FOUND); | ||
return "error"; | ||
} | ||
|
||
@RequestMapping(value = "/400") | ||
public String error400(HttpServletResponse res, ModelMap model) { | ||
model.addAttribute("statusCode", "400"); | ||
res.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); | ||
return "error"; | ||
} | ||
|
||
@RequestMapping(value = { "/500", "/error" }) | ||
public String error500(HttpServletResponse res, ModelMap model, @RequestParam(value = "error", defaultValue = "") String error) { | ||
model.addAttribute("error", error); | ||
model.addAttribute("statusCode", "500"); | ||
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
return "error"; | ||
} | ||
|
||
} |
128 changes: 128 additions & 0 deletions
128
src/main/java/it/linkeddata/sparqlGoodies/controllers/SparqlSplitter.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,128 @@ | ||
package it.linkeddata.sparqlGoodies.controllers; | ||
|
||
import it.linkeddata.sparqlGoodies.splitter.ConfigurationBean; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.Locale; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.jena.atlas.web.AcceptList; | ||
import org.apache.jena.atlas.web.MediaType; | ||
import org.apache.jena.riot.Lang; | ||
import org.apache.jena.riot.RDFLanguages; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.util.UrlPathHelper; | ||
|
||
@Controller | ||
@RequestMapping(value = "") | ||
public class SparqlSplitter { | ||
|
||
@Autowired | ||
ConfigurationBean conf; | ||
|
||
// final AcceptList offeringRDF = new | ||
// AcceptList("text/turtle, application/turtle, " // | ||
// + "application/x-turtle, application/rdf+xml, " // | ||
// + "application/rdf+json, application/ld+json, " // | ||
// + "text/plain, application/n-triples, text/trig, " // | ||
// + "application/n-quads, application/x-trig, application/trig, " // | ||
// + "text/n-quads, text/nquads, application/trix+xml, " // | ||
// + "application/rdf+json, text/rdf+n3, application/n3, " // | ||
// + "text/n3"); | ||
|
||
final AcceptList offeringRDF = new AcceptList("application/sparql-results+xml, application/sparql-results+json, text/boolean, application/x-binary-rdf-results-table"); | ||
|
||
final AcceptList offeringResources = new AcceptList("text/html, application/xhtml+xml"); | ||
|
||
@RequestMapping(value = { "robots.txt" }, produces = "text/plain") | ||
public ResponseEntity<String> robots() { | ||
return new ResponseEntity<String>("User-agent: *\nAllow: /", HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(value = { "{path:(?!staticResources).*/sparql$}", "{path:(?!staticResources).*$}/**/sparql" }) | ||
public Object home(ConfigurationBean conf, ModelMap model, HttpServletRequest req, HttpServletResponse res, Locale locale, @RequestParam(value = "query", defaultValue = "") String query, @RequestParam(value = "output", defaultValue = "") String output) throws UnsupportedEncodingException { | ||
|
||
String requestUrl = req.getRequestURL().toString(); | ||
String request = requestUrl.replaceAll("/sparql$", ""); | ||
request = request.replaceAll(new UrlPathHelper().getContextPath(req), ""); | ||
|
||
if (query.equals("")) { | ||
|
||
/* form page */ | ||
String user = conf.getSingleConfValueForSubject(request, "user", null); | ||
|
||
if (user == null) { | ||
return new ErrorController().error404(res, model, "sorry, no endpoint configured"); | ||
} | ||
|
||
String staticPath = requestUrl.replaceAll("/$", "") + "/../../" + conf.getStaticResources(); | ||
|
||
model.addAttribute("user", user); | ||
model.addAttribute("staticPath", staticPath); | ||
|
||
return "form"; | ||
} else { | ||
|
||
/* query result */ | ||
|
||
return query(conf, model, req, res, locale, query, output); | ||
} | ||
} | ||
|
||
public Object query(ConfigurationBean conf, ModelMap model, HttpServletRequest req, HttpServletResponse res, Locale locale, String query, String output) throws UnsupportedEncodingException { | ||
|
||
/* guessing the content Lang */ | ||
|
||
String[] acceptedContent = req.getHeader("Accept").split(","); | ||
AcceptList a = AcceptList.create(acceptedContent); | ||
MediaType matchItem = AcceptList.match(offeringRDF, a); | ||
Lang lang = matchItem != null ? RDFLanguages.contentTypeToLang(matchItem.getContentType()) : null; | ||
/* content type override */ | ||
if (!output.equals("")) { | ||
try { | ||
output = output.replaceAll("([a-zA-Z]) ([a-zA-Z])", "$1+$2"); | ||
a = AcceptList.create(output.split(",")); | ||
matchItem = AcceptList.match(offeringRDF, a); | ||
lang = RDFLanguages.contentTypeToLang(matchItem.getContentType()); | ||
} catch (Exception e) { | ||
return new ErrorController().error406(res, model); | ||
} | ||
} | ||
|
||
try { | ||
if (lang == null) { | ||
matchItem = AcceptList.match(offeringResources, a); | ||
if (matchItem != null) { | ||
|
||
/* return HTML content */ | ||
|
||
return null; | ||
} else { | ||
return new ErrorController().error406(res, model); | ||
} | ||
} else { | ||
|
||
/* return RDF content */ | ||
|
||
return null; | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
if (e.getMessage() != null && e.getMessage().startsWith("404")) { | ||
return new ErrorController().error404(res, model, e.getMessage()); | ||
} else { | ||
return new ErrorController().error500(res, model, e.getMessage()); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.