Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
#29 Make RDFViewer html template being configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Nov 18, 2013
1 parent a96b1ba commit 19687f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 20 additions & 4 deletions app/controllers/RDFViewer.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package controllers

import play.api.mvc.Action
import scalax.io.Input
import scalax.io.{Resource, Input}
import play.api.mvc.Results._
import play.api.Logger
import play.api.Play
import java.io.File

/**
* Created by hjs on 18/11/2013.
*/
object RDFViewer {

def htmlFor(url: String) = Action { request =>
val HtmlTemplatePathKey = "rdf.html.viewer.template.path"

def htmlTemplate: String = {
import scalax.io.{Resource=>xResource}
val input:Input = xResource.fromFile("public/ldp/index.html")
val response = input.string.replace("window.location.href",s"'https://localhost:8443$url'")
val path = Play.current.configuration.getString(HtmlTemplatePathKey)
require(path.isDefined,s"Missing configuration for key $HtmlTemplatePathKey")
val file = new File(path.get)
require(file.exists() && file.isFile && file.canRead,s"Unable to read file: $file")
// we have checked the existence of the file before because this method xResource.fromFile creates the file if it doesn't exist
// (the doc says it raises an exception but it's not the case)
xResource.fromFile(file).string
}

// TODO it would probably be more elegant to use a real template key instead of "window.location.href"
def htmlFor(url: String) = Action { request =>
val template = htmlTemplate
val response = template.replace("window.location.href",s"'https://localhost:8443$url'")
Ok(response).as("text/html")
}

Expand Down
2 changes: 2 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ logger.rww=DEBUG
#https.trustStore=test.WebIDTrustManager


# Path of the base html template that is used to render the rdf content
rdf.html.viewer.template.path="public/ldp/index.html"

0 comments on commit 19687f6

Please sign in to comment.