Includes kludge to fix returned URIs as relative
authorTim Berners-Lee <timbl+hg@w3.org>
Tue, 11 Oct 2011 13:33:50 +0200
changeset 104 10f12bf8bbbd
parent 47 5733487193e1
child 105 81d2fa82b753
Includes kludge to fix returned URIs as relative
src/main/scala/Resource.scala
--- a/src/main/scala/Resource.scala	Sat Oct 08 16:45:44 2011 -0400
+++ b/src/main/scala/Resource.scala	Tue Oct 11 13:33:50 2011 +0200
@@ -12,7 +12,7 @@
 
 import scalaz._
 import Scalaz._
-
+import java.io.StringWriter   // tbl
 import _root_.scala.sys.error
 
 trait ResourceManager {
@@ -55,7 +55,7 @@
           val reader = model.getReader(lang)
           reader.read(model, fis, url.toString)
         } catch {
-          case je:JenaException => error("@@@")
+          case je:JenaException => error("Fail to parse <"+ url.toString +"> : "+ je)
         }
         fis.close()
         model.success
@@ -72,7 +72,17 @@
         createFileOnDisk()
         val fos = new FileOutputStream(fileOnDisk)
         val writer = model.getWriter(lang)
-        writer.write(model, fos, url.toString)
+        
+        val temp = new StringWriter();  // tbl  kludge until Jena fixed @@@
+        writer.write(model, temp, url.toString); //tbl 
+        def baseBit(u:String) = u.slice(0, u.lastIndexOf('/')+1);  //tbl
+        // We remove any base URIs on same server different port as well, for proxying.
+        def generalize(u:String) = u.replaceAll("//localhost[:0-9]*/", "//localhost[:0-9]*/");
+        // fos.write(("# Resource.scala 80: "+generalize(baseBit(url.toString))+"\n").getBytes) 
+        fos.write(temp.toString().replaceAll(generalize(baseBit(url.toString)), "").getBytes); // tbl
+        
+//        writer.write(model, fos, url.toString)
+
         fos.close().success
       } catch {
         case t => t.fail