changeset 28:eea23294c353

~ add request parameters to xsl transformation
author Denis Ah-Kang <denis@w3.org>
date Tue, 09 Aug 2011 14:44:04 +0200
parents bf9461274f7c
children 1c98f0a6d38e
files src/main/scala/Main.scala
diffstat 1 files changed, 25 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Mon Aug 08 16:32:31 2011 -0400
+++ b/src/main/scala/Main.scala	Tue Aug 09 14:44:04 2011 +0200
@@ -22,14 +22,19 @@
 
 case class XSLTStreamer(proc:Processor, exp:XsltExecutable) {
 
-  def apply(url:URL):ResponseStreamer = new ResponseStreamer {
+  def apply(url:URL, params:Map[String, Seq[String]]):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.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)))
+
       trans.setInitialContextNode(source)
       trans.setDestination(out)
       trans.transform()
@@ -56,7 +61,7 @@
 
 object Danseur {
 
-  ResponseCache.setDefault(URLResolver("/home/betehess/W3C"))
+  ResponseCache.setDefault(URLResolver("/home/denis/W3C"))
 
 
   def main(args: Array[String]) {
@@ -75,8 +80,8 @@
         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.setOutputProperty(Serializer.Property.METHOD, "html")
+        //out.setOutputProperty(Serializer.Property.INDENT, "yes")
         out.setOutputStream(os)
         val trans:XsltTransformer = exp.load()
         trans.setInitialContextNode(source)
@@ -94,11 +99,23 @@
     val trdoc2rdf = unfiltered.filter.Planify {
       case Path(Seg("trdoc2rdf" :: Nil)) & Params(params) if params contains "url" => {
         val url = params("url").head
-        trdoc2rdfXSLT(new URL(url))
+
+        trdoc2rdfXSLT(new URL(url), params)
       }
     }
     
-    unfiltered.jetty.Http.local(2719).filter(test).filter(echo).run()
+    val pubrulesXSLT = XSLTStreamer(new URL("http://www.w3.org/2005/07/13-pubrules.xsl"))
+    val pubrulesSRC = new URL("http://www.w3.org/2005/07/13-pubrules-src.html")
+
+    val pubrules = unfiltered.filter.Planify {
+      case Path(Seg("pubrules" :: Nil)) & Params(params) if params contains "uri" => {
+        //val url = params("url").head
+        //pubrulesXSLT(new URL(url))
+        pubrulesXSLT(pubrulesSRC, params)
+      }
+    }
+
+    unfiltered.jetty.Http.local(2719).filter(pubrules).filter(trdoc2rdf).filter(echo).run()
 
 
   }
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.