diff --git a/app/ErrorHandler.java b/app/ErrorHandler.java new file mode 100644 index 0000000..3778f9e --- /dev/null +++ b/app/ErrorHandler.java @@ -0,0 +1,47 @@ +import com.google.inject.Inject; +import play.Configuration; +import play.Environment; +import play.Logger; +import play.api.OptionalSourceMapper; +import play.http.DefaultHttpErrorHandler; +import play.libs.F; +import play.mvc.Http; +import play.mvc.Result; +import play.mvc.Results; +import play.api.routing.Router; + +import services.LayoutProvider; + +import javax.inject.Provider; +import java.io.IOException; + +/** + * Created by fo on 29.04.16. + */ +public class ErrorHandler extends DefaultHttpErrorHandler { + + @Inject + private LayoutProvider layoutProvider; + + @Inject + public ErrorHandler(Configuration configuration, Environment environment, + OptionalSourceMapper sourceMapper, Provider routes) { + super(configuration, environment, sourceMapper, routes); + } + + @Override + public F.Promise onNotFound(Http.RequestHeader request, java.lang.String message) { + + Result result; + try { + result = Results.notFound(layoutProvider.getTemplateLoader().sourceAt("en/404.html").content()).as("text/html"); + } catch (IOException e) { + Logger.error(e.toString()); + result = Results.notFound("Not Found"); + } + + return F.Promise.pure(result); + + } + +} diff --git a/app/controllers/Application.java b/app/controllers/Application.java index 7b84920..0bf16f1 100644 --- a/app/controllers/Application.java +++ b/app/controllers/Application.java @@ -74,7 +74,7 @@ public Result getVocabData(String version, String extension) { Model vocab = getVocabModel(version); if (vocab.isEmpty()) { - return notFound(); + return notFoundPage(); } MimeType mimeType = getMimeType(request(), extension); @@ -94,7 +94,7 @@ public Result getVocabPage(String version, String language) throws IOException { Locale locale = getLocale(request(), language); if (vocab.isEmpty()) { - return notFound(); + return notFoundPage(); } response().setHeader("Link", "<".concat(routes.Application.getVocabPage(version, null) @@ -109,7 +109,7 @@ public Result getStatement(String id, String version) { if (!request().queryString().isEmpty()) { setAlternates(request(), id, version, true); - return status(406); + return notAcceptablePage(); } else if (request().accepts("text/html")) { Locale locale = getLocale(request(), null); return redirect(routes.Application.getStatementPage(id, version, locale.getLanguage()).absoluteURL(request())); @@ -123,13 +123,13 @@ public Result getStatementData(String id, String version, String extension) { if (!request().queryString().isEmpty()) { setAlternates(request(), id, version, false); - return status(406); + return notAcceptablePage(); } Model rightsStatement = getStatementModel(id, version); if (rightsStatement.isEmpty()) { - return notFound(); + return notFoundPage(); } MimeType mimeType = getMimeType(request(), extension); @@ -149,7 +149,7 @@ public Result getStatementPage(String id, String version, String language) throw Locale locale = getLocale(request(), language); if (rightsStatement.isEmpty()) { - return notFound(); + return notFoundPage(); } response().setHeader("Link", "<".concat(routes.Application.getStatementPage(id, version, null) @@ -176,7 +176,7 @@ public Result getCollectionData(String id, String version, String extension) { Model collection = getCollectionModel(id, version); if (collection.isEmpty()) { - return notFound(); + return notFoundPage(); } MimeType mimeType = getMimeType(request(), extension); @@ -196,7 +196,7 @@ public Result getCollectionPage(String id, String version, String language) thro Locale locale = getLocale(request(), language); if (collection.isEmpty()) { - return notFound(); + return notFoundPage(); } response().setHeader("Link", "<".concat(routes.Application.getCollectionPage(id, version, null) @@ -208,6 +208,28 @@ public Result getCollectionPage(String id, String version, String language) thro } + public Result notFoundPage() { + + try { + return notFound(layoutProvider.getTemplateLoader().sourceAt("en/404.html").content()).as("text/html"); + } catch (IOException e) { + Logger.error(e.toString()); + return notFound("Not Found"); + } + + } + + public Result notAcceptablePage() { + + try { + return status(406, layoutProvider.getTemplateLoader().sourceAt("en/406.html").content()).as("text/html"); + } catch (IOException e) { + Logger.error(e.toString()); + return status(406, "Not Acceptable"); + } + + } + private Result getData(Model model, MimeType mimeType) { OutputStream result = new ByteArrayOutputStream(); diff --git a/app/services/GitLayoutProvider.java b/app/services/GitLayoutProvider.java index 9ddbbbb..7997ed2 100644 --- a/app/services/GitLayoutProvider.java +++ b/app/services/GitLayoutProvider.java @@ -2,13 +2,13 @@ import com.github.jknack.handlebars.io.URLTemplateLoader; import com.google.inject.Singleton; +import com.google.inject.Inject; import org.apache.commons.io.FileUtils; import org.apache.jena.atlas.RuntimeIOException; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import play.Configuration; import play.Logger; -import play.Play; import java.io.File; import java.io.IOException; @@ -21,7 +21,7 @@ @Singleton public class GitLayoutProvider implements LayoutProvider { - private Configuration gitSource = Play.application().configuration().getConfig("source.site.git"); + private Configuration gitSource; public URLTemplateLoader getTemplateLoader() { URLTemplateLoader urlTemplateLoader = new ResourceTemplateLoader(); @@ -42,7 +42,10 @@ protected URL getResource(final String location) throws IOException { } - public GitLayoutProvider() { + @Inject + public GitLayoutProvider(Configuration configuration) { + + gitSource = configuration.getConfig("source.site.git"); try { Logger.debug("Checking out template branch ".concat(gitSource.getString("branch"))); diff --git a/app/services/GitVocabProvider.java b/app/services/GitVocabProvider.java index 6cf7bd4..cb9e34d 100644 --- a/app/services/GitVocabProvider.java +++ b/app/services/GitVocabProvider.java @@ -1,5 +1,6 @@ package services; +import com.google.inject.Inject; import com.google.inject.Singleton; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -18,7 +19,6 @@ import org.eclipse.jgit.treewalk.filter.PathSuffixFilter; import play.Configuration; import play.Logger; -import play.Play; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -35,9 +35,10 @@ public class GitVocabProvider implements VocabProvider { private Model vocab = ModelFactory.createDefaultModel(); - public GitVocabProvider() { + @Inject + public GitVocabProvider(Configuration configuration) { - Configuration gitSource = Play.application().configuration().getConfig("source.data.git"); + Configuration gitSource = configuration.getConfig("source.data.git"); try { diff --git a/public/handlebars/statement.hbs b/public/handlebars/statement.hbs deleted file mode 100644 index 60cc2b7..0000000 --- a/public/handlebars/statement.hbs +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - Rights Statements - - - - - - - - - -
-
-
-
- -
-
-
-
-

{{ data.prefLabel.[@value] }}

-

{{ data.definition.[@value] }}

- {{#parameters.date}} -

{{i18n data.identifier . locale=language}}

- {{/parameters.date}} - - {{#parameters.relatedURL}} -

{{{i18n data.identifier . locale=language}}}

- {{/parameters.relatedURL}} -

{{i18n "notices" locale=language}}

-
    - {{#sort data.note direction="asc"}} -
  • {{ [@value] }}
  • - {{/sort}} -
-

{{{i18n "Disclaimer" locale=language}}}

-
-
-
- - -
- - - - - - - - -