mergine A. Bertail's " enforce the use of Scala types in the API for better dialog with Jena" which extends a patch to modelFromInputStream I had added to do this. My patch is therefore no longer needed. webid
authorHenry Story <henry.story@bblfish.net>
Sun, 16 Oct 2011 20:31:37 +0200
branchwebid
changeset 79 572e802db0eb
parent 78 abbf9e663c35 (current diff)
parent 66 42222285bfea (diff)
child 80 4328660e5a0b
mergine A. Bertail's " enforce the use of Scala types in the API for better dialog with Jena" which extends a patch to modelFromInputStream I had added to do this. My patch is therefore no longer needed.
src/main/scala/plan.scala
src/main/scala/util/package.scala
--- a/src/main/scala/Post.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/main/scala/Post.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -45,8 +45,9 @@
         case qpe: QueryParseException => qpe.fail
       }
       
+    // TODO
     def postRDF =
-      modelFromString(s, baseURI) flatMap { model => PostRDF(model).success }
+      modelFromString(s, baseURI, RDFXML) flatMap { model => PostRDF(model).success }
     
     def postQuery =
       try {
--- a/src/main/scala/plan.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/main/scala/plan.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -75,7 +75,7 @@
           }
         case PUT(_) & Lang(lang) =>
           for {
-            bodyModel <- modelFromInputStream(Body.stream(req), baseURI) failMap { t => BadRequest ~> ResponseString(t.getStackTraceString) }
+            bodyModel <- modelFromInputStream(Body.stream(req), baseURI, lang) failMap { t => BadRequest ~> ResponseString(t.getStackTraceString) }
             _ <- r.save(bodyModel) failMap { t => InternalServerError ~> ResponseString(t.getStackTraceString) }
           } yield Created
         case PUT(_) =>
--- a/src/main/scala/util/package.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/main/scala/util/package.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -34,18 +34,14 @@
       }
   }
 
-  //Passing strings into method arguments, especially as these differ completely between rdf stacks is not so good
-  //passing objects is better
-  def modelFromInputStream(is:InputStream, base: String,  lang: Lang): Validation[Throwable, Model]=
-      modelFromInputStream(is, base, lang.jenaLang)
 
   def modelFromInputStream(
       is: InputStream,
       base: String,
-      lang: String = "RDF/XML-ABBREV"): Validation[Throwable, Model] =
+      lang: Lang): Validation[Throwable, Model] =
     try {
       val m = ModelFactory.createDefaultModel()
-      m.read(is, base, lang)
+      m.getReader(lang.jenaLang).read(m, is, base)
       m.success
     } catch {
       case t => t.fail
@@ -54,11 +50,11 @@
   def modelFromString(
       s: String,
       base: String,
-      lang: String = "RDF/XML-ABBREV"): Validation[Throwable, Model] =
+      lang: Lang): Validation[Throwable, Model] =
     try {
       val reader = new StringReader(s)
       val m = ModelFactory.createDefaultModel()
-      m.read(reader, base, lang)
+      m.getReader(lang.jenaLang).read(m, reader, base)
       m.success
     } catch {
       case t => t.fail
--- a/src/test/scala/AccessContentSpecs.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/test/scala/AccessContentSpecs.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -24,7 +24,7 @@
     "return a 200 and an empty model" in {
       val (statusCode, model) = Http(uri >+ {
         req => (req.get_statusCode,
-                req as_model(uriBase))
+                req as_model(uriBase, RDFXML))
       } )
       statusCode must_== 200
       model must beIsomorphicWith (emptyModel)
@@ -37,8 +37,8 @@
 
   "a GET on Joe's URI" should {
     "deliver TURTLE and RDF/XML graphs that are isomorphic to each other" in {
-      val rdfxml = Http(uri as_model(uriBase))
-      val turtle = Http(uri <:< Map("Accept" -> "text/turtle") as_model(uriBase, lang="TURTLE"))
+      val rdfxml = Http(uri as_model(uriBase, RDFXML))
+      val turtle = Http(uri <:< Map("Accept" -> "text/turtle") as_model(uriBase, TURTLE))
       rdfxml must beIsomorphicWith(turtle)
     }
   }
--- a/src/test/scala/CreateContentSpecs.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/test/scala/CreateContentSpecs.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -21,7 +21,7 @@
     "now exist and be isomorphic with the original document" in {
       val (statusCode, via, model) = Http(uri >++ { req => (req.get_statusCode,
                                                             req.get_header("MS-Author-Via"),
-                                                            req as_model(uriBase))
+                                                            req as_model(uriBase, RDFXML))
                                                   } )
       statusCode must_== 200
       via must_== "SPARQL"
@@ -56,7 +56,7 @@
 </rdf:RDF>
 """  
     
-  val expectedFinalModel = modelFromString(finalRDF, uriBase).toOption.get
+  val expectedFinalModel = modelFromString(finalRDF, uriBase, RDFXML).toOption.get
 
   "POSTing an RDF document to Joe's URI" should {
     "succeed" in {
@@ -64,7 +64,7 @@
       httpCode must_== 200
     }
     "append the diff graph to the initial graph" in {
-      val model = Http(uri as_model(uriBase))
+      val model = Http(uri as_model(uriBase, RDFXML))
       model must beIsomorphicWith (expectedFinalModel)
     }
   }
--- a/src/test/scala/SparqlQuerySpecs.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/test/scala/SparqlQuerySpecs.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -57,7 +57,7 @@
   
   """POSTing "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }" to Joe's URI""" should {
     "return an isomorphic RDF graph" in {
-      val model = Http(uri as_model(uriBase))
+      val model = Http(uri as_model(uriBase, RDFXML))
       model must beIsomorphicWith (referenceModel)
     }
   }
--- a/src/test/scala/SparqlUpdateSpecs.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/test/scala/SparqlUpdateSpecs.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -19,7 +19,7 @@
       httpCode must_== 200
     }
     "produce a graph with one more triple than the original one" in {
-      val model = Http(uri as_model(uriBase))
+      val model = Http(uri as_model(uriBase, RDFXML))
       model.size must_== (referenceModel.size + 1)
     }
   }
--- a/src/test/scala/util/specs.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/test/scala/util/specs.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -62,7 +62,7 @@
 """
 """
     
-  val referenceModel = modelFromString(rdfxml, uriBase).toOption.get
+  val referenceModel = modelFromString(rdfxml, uriBase, RDFXML).toOption.get
 
 }
 
--- a/src/test/scala/util/utiltest.scala	Sun Oct 16 20:16:40 2011 +0200
+++ b/src/test/scala/util/utiltest.scala	Sun Oct 16 20:31:37 2011 +0200
@@ -39,7 +39,7 @@
   
   class RequestW(req: Request) {
 
-    def as_model(base: String, lang: String = "RDF/XML-ABBREV"): Handler[Model] =
+    def as_model(base: String, lang: Lang): Handler[Model] =
       req >> { is => modelFromInputStream(is, base, lang).toOption.get }
 
     def post(body: String): Request =