init
authorAlexandre Bertails <bertails@gmail.com>
Thu, 25 Aug 2011 22:33:54 -0400
changeset 0 686e9da37c4b
child 1 0ee905706f84
init
.hgignore
project/build.scala
project/plugins/build.sbt
sbt
src/main/resources/People/Berners-Lee/card
src/main/scala/Main.scala
src/test/scala/Test.scala
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,17 @@
+syntax: glob
+target/
+lib_managed/
+src_managed/
+lift_example/
+project/boot/
+.classpath
+.project
+.manager
+*~
+*.class
+*.log
+*\#
+src/main/scala.egp
+src/test/scala.egp
+sbt-launch.jar
+.scala_dependencies
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/build.scala	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,77 @@
+import sbt._
+import Keys._
+
+// some usefull libraries
+// they are pulled only if used
+object Dependencies {
+  val specs = "org.scala-tools.testing" % "specs_2.9.0-1" % "1.6.8" % "test"
+  val scalatest = "org.scalatest" % "scalatest_2.9.0" % "1.6.1" % "test"
+  val salat = "com.novus" %% "salat-core" % "0.0.8-SNAPSHOT"
+  val dispatch = "net.databinder" %% "dispatch-http" % "0.8.4"
+  val unfiltered_filter = "net.databinder" %% "unfiltered-filter" % "0.4.1"
+  val unfiltered_jetty = "net.databinder" %% "unfiltered-jetty" % "0.4.1"
+  val unfiltered_scalate = "net.databinder" %% "unfiltered-scalate" % "0.4.1"
+  val unfiltered_json = "net.databinder" %% "unfiltered-json" % "0.4.1"
+  val unfiltered_spec = "net.databinder" %% "unfiltered-spec" % "0.4.1" % "test"
+  val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.6.1"
+  val antiXML = "com.codecommit" %% "anti-xml" % "0.3-SNAPSHOT"
+  val jena = "com.hp.hpl.jena" % "jena" % "2.6.4"
+  val arq = "com.hp.hpl.jena" % "arq" % "2.8.8"
+//  val jenaIri = "com.hp.hpl.jena" % "iri" % "0.8" from "http://openjena.org/repo/com/hp/hpl/jena/iri/0.8/iri-0.8.jar"
+
+
+}
+
+// some usefull repositories
+object Resolvers {
+  val novus = "repo.novus snaps" at "http://repo.novus.com/snapshots/"
+}
+
+// general build settings
+object BuildSettings {
+
+  val buildOrganization = "org.w3"
+  val buildVersion      = "0.1-SNAPSHOT"
+  val buildScalaVersion = "2.9.0-1"
+
+  val buildSettings = Defaults.defaultSettings ++ Seq (
+    organization := buildOrganization,
+    version      := buildVersion,
+    scalaVersion := buildScalaVersion,
+    parallelExecution in Test := false,
+    scalacOptions ++= Seq("-deprecation", "-unchecked")
+  )
+
+}
+
+object YourProjectBuild extends Build {
+
+  import Dependencies._
+  import Resolvers._
+  import BuildSettings._
+
+  val yourProjectSettings =
+    Seq(
+      resolvers += ScalaToolsReleases,
+      resolvers += ScalaToolsSnapshots,
+      libraryDependencies += specs,
+      libraryDependencies += unfiltered_spec,
+      libraryDependencies += dispatch,
+      libraryDependencies += unfiltered_filter,
+      libraryDependencies += unfiltered_jetty,
+      libraryDependencies += unfiltered_scalate,
+      libraryDependencies += slf4jSimple,
+      libraryDependencies += jena,
+      libraryDependencies += arq
+    )
+
+  lazy val yourProject = Project(
+    id = "your-project",
+    base = file("."),
+    settings = buildSettings ++ yourProjectSettings ++ sbtassembly.Plugin.assemblySettings
+  )
+  
+
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/plugins/build.sbt	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,11 @@
+libraryDependencies <+= (sbtVersion) { sv => "com.eed3si9n" %% "sbt-assembly" % ("sbt" + sv + "_0.4") }
+
+resolvers += {
+  val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
+  val pattern = Patterns(false, "[organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]")
+  Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
+}
+
+libraryDependencies <<= (libraryDependencies, sbtVersion) { (deps, version) => 
+  deps :+ ("com.typesafe.sbteclipse" %% "sbteclipse" % "1.3-RC3" extra("sbtversion" -> version))
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbt	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+dir=$(dirname $0)
+cd "$dir"
+
+if [ ! -f sbt-launch.jar ]; then
+    wget http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.10.1/sbt-launch.jar
+fi
+
+java -Xmx512M -jar -Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m "$dir/sbt-launch.jar" "$@"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/resources/People/Berners-Lee/card	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,160 @@
+
+<!-- Processed by Id: cwm.py,v 1.197 2007/12/13 15:38:39 syosi Exp -->
+<!--     using base file:///devel/WWW/People/Berners-Lee/card.n3-->
+
+
+<rdf:RDF xmlns="http://xmlns.com/foaf/0.1/"
+    xmlns:cc="http://creativecommons.org/ns#"
+    xmlns:cert="http://www.w3.org/ns/auth/cert#"
+    xmlns:con="http://www.w3.org/2000/10/swap/pim/contact#"
+    xmlns:dc="http://purl.org/dc/elements/1.1/"
+    xmlns:dct="http://purl.org/dc/terms/"
+    xmlns:doap="http://usefulinc.com/ns/doap#"
+    xmlns:foaf="http://xmlns.com/foaf/0.1/"
+    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
+    xmlns:owl="http://www.w3.org/2002/07/owl#"
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+    xmlns:rsa="http://www.w3.org/ns/auth/rsa#"
+    xmlns:s="http://www.w3.org/2000/01/rdf-schema#">
+
+    <rdf:Description rdf:about="../../DesignIssues/Overview.html">
+        <dc:title>Design Issues for the World Wide Web</dc:title>
+        <maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <PersonalProfileDocument rdf:about="">
+        <cc:license rdf:resource="http://creativecommons.org/licenses/by-nc/3.0/"/>
+        <dc:title>Tim Berners-Lee's FOAF file</dc:title>
+        <maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+        <primaryTopic rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </PersonalProfileDocument>
+
+    <rdf:Description rdf:about="http://dig.csail.mit.edu/2005/ajar/ajaw/data#Tabulator">
+        <doap:developer rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://dig.csail.mit.edu/2007/01/camp/data#course">
+        <maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <PersonalProfileDocument rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf">
+        <cc:license rdf:resource="http://creativecommons.org/licenses/by-nc/3.0/"/>
+        <dc:title>Tim Berners-Lee's editable FOAF file</dc:title>
+        <maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+        <primaryTopic rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </PersonalProfileDocument>
+
+    <rdf:Description rdf:about="http://dig.csail.mit.edu/breadcrumbs/blog/4">
+        <dc:title>timbl's blog</dc:title>
+        <s:seeAlso rdf:resource="http://dig.csail.mit.edu/breadcrumbs/blog/feed/4"/>
+        <maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://dig.csail.mit.edu/data#DIG">
+        <member rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://wiki.ontoworld.org/index.php/_IRW2006">
+        <dc:title>Identity, Reference and the Web workshop 2006</dc:title>
+        <con:participant rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://www.ecs.soton.ac.uk/~dt2/dlstuff/www2006_data#panel-panelk01">
+        <s:label>The Next Wave of the Web (Plenary Panel)</s:label>
+        <con:participant rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://www.w3.org/2000/10/swap/data#Cwm">
+        <doap:developer rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://www.w3.org/2011/Talks/0331-hyderabad-tbl/data#talk">
+        <dct:title>Designing the Web for an Open Society</dct:title>
+        <maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <con:Male rdf:about="http://www.w3.org/People/Berners-Lee/card#i">
+        <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
+        <s:label>Tim Berners-Lee</s:label>
+        <s:seeAlso rdf:resource="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf"/>
+        <s:seeAlso rdf:resource="http://www.w3.org/2007/11/Talks/search/query?date=All+past+and+future+talks&#38;event=None&#38;activity=None&#38;name=Tim+Berners-Lee&#38;country=None&#38;language=None&#38;office=None&#38;rdfOnly=yes&#38;submit=Submit"/>
+        <con:assistant rdf:resource="http://www.w3.org/People/Berners-Lee/card#amy"/>
+        <con:homePage rdf:resource="./"/>
+        <con:office rdf:parseType="Resource">
+            <con:address rdf:parseType="Resource">
+                <con:city>Cambridge</con:city>
+                <con:country>USA</con:country>
+                <con:postalCode>02139</con:postalCode>
+                <con:street>32 Vassar Street</con:street>
+                <con:street2>MIT CSAIL Room 32-G524</con:street2>
+            </con:address>
+            <con:phone rdf:resource="tel:+1-617-253-5702"/>
+            <geo:location rdf:parseType="Resource">
+                <geo:lat>42.361860</geo:lat>
+                <geo:long>-71.091840</geo:long>
+            </geo:location>
+        </con:office>
+        <con:preferredURI>http://www.w3.org/People/Berners-Lee/card#i</con:preferredURI>
+        <con:publicHomePage rdf:resource="./"/>
+        <owl:sameAs rdf:resource="http://identi.ca/user/45563"/>
+        <owl:sameAs rdf:resource="http://www.advogato.org/person/timbl/foaf.rdf#me"/>
+        <owl:sameAs rdf:resource="http://www4.wiwiss.fu-berlin.de/bookmashup/persons/Tim+Berners-Lee"/>
+        <owl:sameAs rdf:resource="http://www4.wiwiss.fu-berlin.de/dblp/resource/person/100007"/>
+        <account rdf:resource="http://en.wikipedia.org/User:Timbl"/>
+        <account rdf:resource="http://identi.ca/timbl"/>
+        <account rdf:resource="http://twitter.com/timberners_lee"/>
+        <based_near rdf:parseType="Resource">
+            <geo:lat>42.361860</geo:lat>
+            <geo:long>-71.091840</geo:long>
+        </based_near>
+        <family_name>Berners-Lee</family_name>
+        <givenname>Timothy</givenname>
+        <homepage rdf:resource="http://www.w3.org/People/Berners-Lee/"/>
+        <img rdf:resource="http://www.w3.org/Press/Stock/Berners-Lee/2001-europaeum-eighth.jpg"/>
+        <mbox rdf:resource="mailto:timbl@w3.org"/>
+        <mbox_sha1sum>965c47c5a70db7407210cef6e4e6f5374a525c5c</mbox_sha1sum>
+        <name>Timothy Berners-Lee</name>
+        <nick>TimBL</nick>
+        <nick>timbl</nick>
+        <openid rdf:resource="http://www.w3.org/People/Berners-Lee/"/>
+        <phone rdf:resource="tel:+1-(617)-253-5702"/>
+        <title>Sir</title>
+        <weblog rdf:resource="http://dig.csail.mit.edu/breadcrumbs/blog/4"/>
+        <workplaceHomepage rdf:resource="http://www.w3.org/"/>
+    </con:Male>
+
+    <rdf:Description rdf:about="http://www.w3.org/data#W3C">
+        <member rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+    </rdf:Description>
+
+    <rdf:Description rdf:about="http://www4.wiwiss.fu-berlin.de/booksMeshup/books/006251587X">
+        <dc:creator rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+        <dc:title>Weaving the Web: The Original Design and Ultimate Destiny of the World Wide Web</dc:title>
+    </rdf:Description>
+
+    <rdf:Description>
+        <rdf:type rdf:resource="http://www.w3.org/ns/auth/rsa#RSAPublicKey"/>
+        <cert:identity rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
+        <rsa:modulus rdf:parseType="Resource">
+            <cert:hex>d7 a0 e9 1e ed dd cc 90 5d 5e cc d1 e4 12 ab 0c 
+5b db e1 18 fa 99 b7 13 2d 91 54 52 f0 b0 9a f5 
+eb c0 09 6c a1 db de ec 32 72 3f 5d dd 2b 05 56 
+4e 2c e6 7e ff ba 8e 86 77 8e 11 4a 02 a3 90 7c 
+2e 6c 6b 28 cf 16 fe e7 7d 0e f0 c4 4d 2e 3c cd 
+3e 0b 6e 8c fd d1 97 e3 aa 86 ec 19 99 80 72 9a 
+f4 45 1f 79 99 bc e5 5e b3 4b d5 a5 35 04 70 46 
+37 00 f7 30 8e 37 2b db 6e 07 5e 0b b8 a8 db a9 
+36 86 fa 4a e5 13 17 a4 43 82 bb 09 d0 92 94 c1 
+68 5b 10 97 ff d5 9c 44 6a e5 67 fa ec e6 b6 aa 
+27 89 79 06 b5 24 a6 49 89 bd 48 cf ea ec 61 d1 
+2c c0 b6 3d db 88 5d 2d ad b0 b3 58 c6 66 aa 93 
+f5 a4 43 fb 91 fc 2a 3d c6 99 eb 46 15 9b 05 c5 
+75 8c 9f 13 ed 28 44 09 4c c5 39 e5 82 e1 1d e3 
+6c 67 33 a6 7b 51 25 ef 40 7b 32 9e f5 e9 22 ca 
+57 46 a5 ff c6 7b 65 0b 4a e3 66 10 fc a0 cd 7b</cert:hex>
+        </rsa:modulus>
+        <rsa:public_exponent rdf:parseType="Resource">
+            <cert:decimal>65537</cert:decimal>
+        </rsa:public_exponent>
+    </rdf:Description>
+</rdf:RDF>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/Main.scala	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,88 @@
+package org.w3.readwriteweb
+
+import org.w3.yourapp.util.ResourceManager.fromClasspath
+
+import javax.servlet._
+import javax.servlet.http._
+import unfiltered.request._
+import unfiltered.response._
+import unfiltered.scalate._
+import unfiltered.jetty._
+
+import java.io._
+import scala.io.Source
+
+import org.slf4j.{Logger, LoggerFactory}
+import com.hp.hpl.jena.rdf.model._
+
+// holds some Unfiltered plans
+class ReadWriteWeb(base:File) {
+  
+  val logger:Logger = LoggerFactory.getLogger(this.getClass)
+
+  val echo = unfiltered.filter.Planify {
+    case Path(Seg("echo" :: p :: Nil)) => ResponseString(p)
+  }
+
+  val read = unfiltered.filter.Planify {
+    case req @ Path(path) => {
+      val fis = new FileInputStream(new File(base, path))
+      /* http://jena.sourceforge.net/tutorial/RDF_API/index.html#ch-Reading%20RDF */
+      val model:Model = ModelFactory.createDefaultModel()
+      model.read(fis, null)
+      req match {
+        case GET(_) => {
+          Ok ~> new ResponseStreamer {
+            def stream(os:OutputStream):Unit = {
+              /* http://jena.sourceforge.net/tutorial/RDF_API/index.html#ch-Writing%20RDF */
+              // val lang = "RDF/XML-ABBREV"
+              val lang = "TURTLE"
+              model.write(os, lang)
+            }
+          }
+        }
+        // case POST(_) => {
+        //   val query = 
+        // }
+      }
+    }
+  }
+
+}
+
+object ReadWriteWebMain {
+
+  val logger:Logger = LoggerFactory.getLogger(this.getClass)
+
+  // regular Java main
+  def main(args: Array[String]) {
+    
+    // can provide the port as first argument
+    // default to 2719
+    val (port, directory) = args.toList match {
+      case port :: directory :: Nil => (port.toInt, directory)
+      case _ => sys.error("wrong arguments")
+    }
+
+    val app = new ReadWriteWeb(new File(directory))
+
+    // configures and launches a Jetty server
+    unfiltered.jetty.Http(port).filter {
+      // a jee Servlet filter that logs request
+      new Filter {
+        def destroy():Unit = ()
+        def doFilter(request:ServletRequest, response:ServletResponse, chain:FilterChain):Unit = {
+          val r:HttpServletRequest = request.asInstanceOf[HttpServletRequest]
+          val method = r.getMethod
+          val uri = r.getRequestURI 
+          logger.info("%s %s" format (method, uri))
+          chain.doFilter(request, response)
+        }
+        def init(filterConfig:FilterConfig):Unit = ()
+      }
+    // Unfiltered filters
+    }.filter(app.read).run()
+    
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/scala/Test.scala	Thu Aug 25 22:33:54 2011 -0400
@@ -0,0 +1,23 @@
+package org.w3.readwriteweb
+
+import org.specs._
+import java.net.URL
+import unfiltered.response._
+import unfiltered.request._
+import dispatch._
+import java.io.File
+
+object ReadWriteWebSpec extends Specification with unfiltered.spec.jetty.Served {
+
+  def setup = { _.filter(new ReadWriteWeb(new File("src/main/resources")).read) }
+
+  val get:Request = host / "/People/Berners-Lee/card#i"
+    
+  "GET on TimBL's FOAF profile" should {
+    "return something" in {
+      val body:String = Http(get as_str)
+      body must not be empty
+    }
+  }
+  
+}