start working with Scalate and especially the very minimalistic scuery http://scalate.fusesource.org/documentation/scuery.html webid
authorHenry Story <henry.story@bblfish.net>
Thu, 17 Nov 2011 14:30:44 +0100
branchwebid
changeset 123 867d0eb56c5c
parent 122 83097ca48f9f (current diff)
parent 121 38d13793dfae (diff)
child 124 499a60bd845c
start working with Scalate and especially the very minimalistic scuery http://scalate.fusesource.org/documentation/scuery.html
--- a/project/build.scala	Thu Nov 17 14:28:54 2011 +0100
+++ b/project/build.scala	Thu Nov 17 14:30:44 2011 +0100
@@ -10,6 +10,7 @@
   val unfiltered_filter = "net.databinder" %% "unfiltered-filter" % unfiltered_version 
   val unfiltered_jetty = "net.databinder" %% "unfiltered-jetty" % unfiltered_version 
   val unfiltered_netty = "net.databinder" %% "unfiltered-netty" % unfiltered_version 
+  val scalate = "net.databinder" %% "unfiltered-scalate" % unfiltered_version  
   // val unfiltered_spec = "net.databinder" %% "unfiltered-spec" % "0.4.1" % "test"
   val ivyUnfilteredSpec =
     <dependencies>
@@ -17,7 +18,7 @@
         <exclude org="net.databinder" module="dispatch-mime_2.9.0-1"/>
       </dependency>
     </dependencies>
-  val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.6"
+  val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.6.4"
   val antiXML = "com.codecommit" %% "anti-xml" % "0.4-SNAPSHOT" % "test"
   val jena = "com.hp.hpl.jena" % "jena" % "2.6.4"
   val arq = "com.hp.hpl.jena" % "arq" % "2.8.8"
@@ -89,7 +90,7 @@
       libraryDependencies += unfiltered_filter,
       libraryDependencies += unfiltered_jetty,
       libraryDependencies += unfiltered_netty,
-//      libraryDependencies += slf4jSimple,
+      libraryDependencies += slf4jSimple,
       libraryDependencies += jena,
       libraryDependencies += arq,
       libraryDependencies += antiXML,
@@ -98,6 +99,7 @@
       libraryDependencies += jsslutils,
       libraryDependencies += argot,
       libraryDependencies += guava,
+      libraryDependencies += scalate,
 
       jarName in assembly := "read-write-web.jar"
     )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/resources/tmp/hello.html	Thu Nov 17 14:30:44 2011 +0100
@@ -0,0 +1,9 @@
+<html>
+<head>
+  <title>Template Title</title>
+</head>
+<body>
+  <h1 class="title">Template Title</h1>
+  <p> hi</p>
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/resources/tmp/hello.ssp	Thu Nov 17 14:30:44 2011 +0100
@@ -0,0 +1,9 @@
+<html>
+<head>
+  <title>${title}</title>
+</head>
+<body>
+  <h1>again ${title}</h1>
+  <p> hi</p>
+</body>
+</html>
--- a/src/main/scala/ReadWriteWebMain.scala	Thu Nov 17 14:28:54 2011 +0100
+++ b/src/main/scala/ReadWriteWebMain.scala	Thu Nov 17 14:30:44 2011 +0100
@@ -3,6 +3,7 @@
 import auth.{RDFAuthZ, X509view}
 import org.w3.readwriteweb.util._
 
+import ui.WebIDAuthnReport
 import unfiltered.jetty._
 import java.io.File
 import Console.err
@@ -11,6 +12,12 @@
 import org.clapper.argot._
 import ArgotConverters._
 import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
+import unfiltered.scalate.Scalate
+import unfiltered.request.Path
+import org.fusesource.scalate.{Binding, TemplateEngine}
+import org.fusesource.scalate.scuery.Transformer
+import xml.XML
+import unfiltered.response.{HttpResponse, Html, Ok}
 
 trait ReadWriteWebArgs {
   val logger: Logger = LoggerFactory.getLogger(this.getClass)
@@ -95,6 +102,8 @@
       override implicit val authz = new RDFAuthZ[HttpServletRequest,HttpServletResponse](webCache,filesystem)
     }
 
+    def test = new WebIDAuthnReport[HttpServletRequest,HttpServletResponse]() {}
+
     //this is incomplete: we should be able to start both ports.... not sure how to do this yet.
     val service = httpsPort.value match {
       case Some(port) => HttpsTrustAll(port,"0.0.0.0")
@@ -105,7 +114,7 @@
     service.filter(new FilterLogger(logger)).
       context("/public"){ ctx:ContextBuilder =>
         ctx.resources(ClasspathUtils.fromClasspath("public/").toURI.toURL)
-    }.
+    }.filter(Planify(test.intent)).
       filter(Planify(rww.intent)).
       filter(Planify(x509v.intent)).
       filter(new EchoPlan().plan).run()
--- a/src/main/scala/netty/ReadWriteWebNetty.scala	Thu Nov 17 14:28:54 2011 +0100
+++ b/src/main/scala/netty/ReadWriteWebNetty.scala	Thu Nov 17 14:30:44 2011 +0100
@@ -28,7 +28,10 @@
 import org.w3.readwriteweb.auth.{X509view, RDFAuthZ}
 import org.w3.readwriteweb._
 import org.jboss.netty.handler.codec.http.HttpResponse
+import ui.WebIDAuthnReport
 import unfiltered.netty.{ServerErrorResponse, ReceivedMessage, cycle}
+import unfiltered.filter.Planify._
+import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
 
 /**
  * ReadWrite Web for Netty server, allowing TLS renegotiation
@@ -60,6 +63,8 @@
           override val authz = new RDFAuthZ[ReceivedMessage,HttpResponse](webCache,filesystem)
      }
 
+     val test = new cycle.Plan with cycle.ThreadPool with ServerErrorResponse with WebIDAuthnReport[ReceivedMessage,HttpResponse]
+
      //this is incomplete: we should be able to start both ports.... not sure how to do this yet.
      val service = httpsPort.value match {
        case Some(port) => new KeyAuth_Https(port)
@@ -68,7 +73,8 @@
 
      // configures and launches a Netty server
      service.plan( x509v ).
-             plan( rww ).run()
+            plan( test ).
+            plan( rww ).run()
      
    }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/ui/WebIDAuthnReport.scala	Thu Nov 17 14:30:44 2011 +0100
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 Henry Story (bblfish.net)
+ * under the MIT licence defined at
+ *    http://www.opensource.org/licenses/mit-license.html
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in the
+ * Software without restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.w3.readwriteweb.ui
+
+import java.io.File
+import xml.XML
+import unfiltered.response.{Ok, Html}
+import unfiltered.request.Path
+import unfiltered.Cycle
+import org.fusesource.scalate.scuery.Transformer
+import org.fusesource.scalate.{Binding, TemplateEngine}
+import unfiltered.scalate.Scalate
+
+/**
+ *
+ * @author Henry Story
+ */
+
+trait WebIDAuthnReport[A,B] {
+
+  val fileDir: File = new File(this.getClass.getResource("/tmp/").toURI)
+  val templateDirs = List(fileDir)
+  implicit val engine = new TemplateEngine(templateDirs)
+  implicit val bindings: List[Binding] = List(Binding(name = "title", className = "String"))
+  implicit val additionalAttributes = List(("title", "My First Title"))
+
+
+  def intent : Cycle.Intent[A,B] = {
+    case req @ Path("/test/WebIdAuth") =>  Ok ~> Html(transformer.apply(XML.loadFile(new File(fileDir,"hello.html"))))
+    case req @ Path("/test/WebIdAuth2") => Ok ~> Scalate(req, "hello.ssp")
+  }
+
+}
+
+object transformer extends Transformer {
+  $(".title").contents = "The Real Title"
+
+}