changeset 31:5cea090725d9

~ some refactoring
author Alexandre Bertails <bertails@w3.org>
date Tue, 09 Aug 2011 13:50:55 -0400
parents 60dcb4210a48
children 25e927e9ca98
files src/main/scala/Main.scala src/main/scala/URLResolver.scala
diffstat 2 files changed, 15 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Tue Aug 09 13:50:45 2011 -0400
+++ b/src/main/scala/Main.scala	Tue Aug 09 13:50:55 2011 -0400
@@ -22,19 +22,13 @@
 
 case class XSLTStreamer(proc:Processor, exp:XsltExecutable) {
 
-  def apply(url:URL, params:Map[String, Seq[String]]):ResponseStreamer = new ResponseStreamer {
+  def apply(url:URL, params:Map[String, String] = Map()):ResponseStreamer = new ResponseStreamer {
     def stream(os:OutputStream):Unit = {
       val source:XdmNode = proc.newDocumentBuilder().build(new StreamSource(url.openStream()))
       val out:Serializer = new Serializer()
-      //out.setOutputProperty(Serializer.Property.METHOD, "html")
-      //out.setOutputProperty(Serializer.Property.INDENT, "yes")
       out.setOutputStream(os)
       val trans:XsltTransformer = exp.load()
-      //trans.setParameter(new QName("", "", "uri"), new XdmAtomicValue("http://www.w3.org/TR/2011/CR-WOFF-20110804/"))
-      //trans.setParameter(new QName("", "", "uimode"), new XdmAtomicValue("checker_full"))
-      //trans.setParameter(new QName("", "", "docstatus"), new XdmAtomicValue("ord-wd-tr"))
-      params foreach ( (p) => trans.setParameter(new QName("", "", p._1), new XdmAtomicValue(p._2.head)))
-
+      params foreach { case (k, v) => trans.setParameter(new QName("", "", k), new XdmAtomicValue(v)) }
       trans.setInitialContextNode(source)
       trans.setDestination(out)
       trans.transform()
@@ -61,10 +55,12 @@
 
 object Danseur {
 
-  ResponseCache.setDefault(URLResolver("/home/denis/W3C"))
+  def main(args: Array[String]) {
 
-
-  def main(args: Array[String]) {
+    args.toList match {
+      case dir :: _ => ResponseCache.setDefault(URLResolver(dir))
+      case _        => ()
+    }
 
     val resp = new ResponseStreamer {
       def stream(os:OutputStream):Unit = {
@@ -80,8 +76,6 @@
         val exp:XsltExecutable = comp.compile(xsltStreamSource)
         val source:XdmNode = proc.newDocumentBuilder().build(new StreamSource(new URL(s).openStream()))
         val out:Serializer = new Serializer()
-        //out.setOutputProperty(Serializer.Property.METHOD, "html")
-        //out.setOutputProperty(Serializer.Property.INDENT, "yes")
         out.setOutputStream(os)
         val trans:XsltTransformer = exp.load()
         trans.setInitialContextNode(source)
@@ -100,7 +94,7 @@
       case Path(Seg("trdoc2rdf" :: Nil)) & Params(params) if params contains "url" => {
         val url = params("url").head
 
-        trdoc2rdfXSLT(new URL(url), params)
+        trdoc2rdfXSLT(new URL(url))
       }
     }
     
@@ -109,9 +103,14 @@
 
     val pubrules = unfiltered.filter.Planify {
       case Path(Seg("pubrules" :: Nil)) & Params(params) if params contains "uri" => {
+        val xsltParams:Map[String, String] =
+          Map(
+            "uimode" -> "checker_full",
+            "docstatus" -> "ord-wd-tr",
+            "uri" -> "http://www.w3.org/TR/2011/CR-WOFF-20110804/"
+          ) ++ ( params map { case(k, v) => (k, v.head) } )
         //val url = params("url").head
-        //pubrulesXSLT(new URL(url))
-        pubrulesXSLT(pubrulesSRC, params)
+        pubrulesXSLT(new URL("http://www.w3.org/2005/07/13-pubrules-src.html"), xsltParams)
       }
     }
 
--- a/src/main/scala/URLResolver.scala	Tue Aug 09 13:50:45 2011 -0400
+++ b/src/main/scala/URLResolver.scala	Tue Aug 09 13:50:55 2011 -0400
@@ -30,7 +30,6 @@
           rqstMethod:String,
           rqstHeaders:JMap[String, JList[String]]):CacheResponse = {
     val uriString = uri.toString
-    println("Trying to resolve: "+uriString)
     URLResolver.prefixes find { uriString startsWith _._1 } match {
       case Some((prefix, path)) => {
         val local = uriString.replaceAll("^"+prefix, path)
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.