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

Commit

Permalink
Create object to handle RWW configuration with fail-fast behavior. fixes
Browse files Browse the repository at this point in the history
 #3 #29
  • Loading branch information
slorber committed Nov 19, 2013
1 parent 19687f6 commit 1d152a8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
19 changes: 1 addition & 18 deletions app/controllers/RDFViewer.scala
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
package controllers

import play.api.mvc.Action
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 {

val HtmlTemplatePathKey = "rdf.html.viewer.template.path"

def htmlTemplate: String = {
import scalax.io.{Resource=>xResource}
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 template = RwwConfiguration.rdfViewerHtmlTemplate
val response = template.replace("window.location.href",s"'https://localhost:8443$url'")
Ok(response).as("text/html")
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ReadWriteWebApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ class ReadWriteWebApp(base: URL, path: Path)(implicit val ops: RDFOps[Plantain],

import plantain._

object ReadWriteWebApp extends ReadWriteWebApp(plantain.rwwRoot,new File("test_www/").toPath.toAbsolutePath)
object ReadWriteWebApp extends ReadWriteWebApp(plantain.rwwRoot, RwwConfiguration.rootContainerPath)
43 changes: 43 additions & 0 deletions app/controllers/RwwConfiguration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package controllers

import play.api.Play
import java.io.File
import java.nio.file.Path


object RwwConfiguration {

val RdfViewerHtmlTemplatePathKey = "rww.rdf.html.viewer.template.path"
val RootContainerPathKey = "rww.root.container.path"

/**
* we check the existence of the file because Resource.fromFile creates the file if it doesn't exist
* (the doc says it raises an exception but it's not the case)
* @param key
* @return
*/
def getFileForConfigurationKey(key: String): File = {
val path = Play.current.configuration.getString(key)
require(path.isDefined,s"Missing configuration for key $key")
val file = new File(path.get)
require(file.exists() && file.canRead,s"Unable to find or read file/directory: $file")
file
}


val rdfViewerHtmlTemplate: String = {
import scalax.io.{Resource=>xResource}
val file = getFileForConfigurationKey(RdfViewerHtmlTemplatePathKey)
require(file.isFile,s"The RDF viewer template file ($file) is not a file")
xResource.fromFile(file).string
}


val rootContainerPath: Path = {
val file = getFileForConfigurationKey(RootContainerPathKey)
require(file.isDirectory,s"The root container ($file) is not a directory")
file.toPath.toAbsolutePath
}


}
19 changes: 15 additions & 4 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ https.trustStore="noCA"
# running this will currently take up the whole server space, and works
# well only with web servers that use relative URLs for their content


# TODO to remove? not used anymore?
# the web server to proxy ( W3C works well)
rww.proxy.for="http://www.w3.org/"

# TODO to remove? not used anymore?
# the url for the directory containing the acls
rww.proxy.acl="test_www"

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

# Path of the root container that will contain the rdf and acl files
rww.root.container.path="test_www"



#####################################################################################
#####################################################################################
#####################################################################################

# Web Server Setup
# ================
# This is the usual Play setup file, except for the TrustManager stuff
Expand Down Expand Up @@ -86,7 +101,3 @@ logger.rww=DEBUG

# Trust Manager
#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 1d152a8

Please sign in to comment.