Merging Alexandre Bertails move from Strings to URLs. There are some classes missing here, but the next change is quite big, so I'd rather move in steps. webid
authorHenry Story <henry.story@bblfish.net>
Sun, 16 Oct 2011 21:13:38 +0200
branchwebid
changeset 81 fed900642d29
parent 80 4328660e5a0b (current diff)
parent 69 3e84e72b6e82 (diff)
child 82 42e553469cef
Merging Alexandre Bertails move from Strings to URLs. There are some classes missing here, but the next change is quite big, so I'd rather move in steps.
src/main/scala/plan.scala
src/main/scala/util/package.scala
--- a/src/main/scala/Post.scala	Sun Oct 16 20:41:07 2011 +0200
+++ b/src/main/scala/Post.scala	Sun Oct 16 21:13:38 2011 +0200
@@ -3,6 +3,7 @@
 import org.w3.readwriteweb.util.modelFromString
 
 import java.io.{InputStream, StringReader}
+import java.net.URL
 import scala.io.Source
 import org.slf4j.{Logger, LoggerFactory}
 import com.hp.hpl.jena.rdf.model._
@@ -30,17 +31,17 @@
 
   def parse(
       is: InputStream,
-      baseURI: String,
+      base: URL,
       contentType: String): Post = {
     assert(supportContentTypes contains contentType)
     val source = Source.fromInputStream(is, "UTF-8")
     val s = source.getLines.mkString("\n")
-    parse(s, baseURI, contentType)
+    parse(s, base, contentType)
   }
   
   def parse(
       s: String,
-      baseURI: String,
+      base: URL,
       contentType: String): Post = {
     assert(supportContentTypes contains contentType)
     
@@ -48,14 +49,14 @@
     
     def postUpdate =
       try {
-        val update: UpdateRequest = UpdateFactory.create(s, baseURI)
+        val update: UpdateRequest = UpdateFactory.create(s, base.toString)
         PostUpdate(update).success
       } catch {
         case qpe: QueryParseException => qpe.fail
       }
       
     def postRDF(lang: Lang) =
-      modelFromString(s, baseURI, lang) flatMap { model => PostRDF(model).success }
+      modelFromString(s, base, lang) flatMap { model => PostRDF(model).success }
     
     def postQuery =
       try {
--- a/src/main/scala/plan.scala	Sun Oct 16 20:41:07 2011 +0200
+++ b/src/main/scala/plan.scala	Sun Oct 16 21:13:38 2011 +0200
@@ -55,8 +55,8 @@
   val plan = unfiltered.filter.Planify {
     authz.protect {
     case req @ Path(path) if path startsWith rm.basePath => {
-      val baseURI = req.underlying.getRequestURL.toString
-      val r: Resource = rm.resource(new URL(baseURI))
+      val Authoritative(baseURI, _) = req
+      val r: Resource = rm.resource(baseURI)
       req match {
         case GET(_) & Accept(accepts) if isHTML(accepts) => {
           val source = Source.fromFile("src/main/resources/skin.html")("UTF-8")
--- a/src/test/scala/util/utiltest.scala	Sun Oct 16 20:41:07 2011 +0200
+++ b/src/test/scala/util/utiltest.scala	Sun Oct 16 21:13:38 2011 +0200
@@ -1,5 +1,6 @@
 package org.w3.readwriteweb
 
+import java.net.URL
 import javax.servlet._
 import javax.servlet.http._
 import unfiltered.request._
@@ -27,7 +28,7 @@
 
 package object utiltest {
   
-  def baseURI(req: Request): String = "%s%s" format (req.host, req.path)
+  def baseURI(req: Request): URL = new URL("%s%s" format (req.host, req.path))
   
   def beIsomorphicWith(that: Model): Matcher[Model] =
     new Matcher[Model] {
@@ -39,7 +40,7 @@
   
   class RequestW(req: Request) {
 
-    def as_model(base: String, lang: Lang): Handler[Model] =
+    def as_model(base: URL, lang: Lang): Handler[Model] =
       req >> { is => modelFromInputStream(is, base, lang).toOption.get }
 
     def post(body: String, lang: Lang): Request =