changeset 27:bf9461274f7c

+ trdoc2rdf as an Unfiltered pattern
author Alexandre Bertails <bertails@w3.org>
date Mon, 08 Aug 2011 16:32:31 -0400
parents c9e5c04f2fad
children eea23294c353
files src/main/scala/Main.scala
diffstat 1 files changed, 49 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Mon Aug 08 15:49:43 2011 -0400
+++ b/src/main/scala/Main.scala	Mon Aug 08 16:32:31 2011 -0400
@@ -12,6 +12,48 @@
 import java.net._
 
 
+/*
+ * - isoler/factoriser le template
+ * - recuperer l'input en tant que parametre
+ * - generer un .jar
+ * - integrer le xsl du pubrules checker
+ */
+
+
+case class XSLTStreamer(proc:Processor, exp:XsltExecutable) {
+
+  def apply(url:URL):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.setInitialContextNode(source)
+      trans.setDestination(out)
+      trans.transform()
+    }
+  }
+
+}
+
+object XSLTStreamer {
+
+  def apply(xsl:URL):XSLTStreamer = {
+    val proc:Processor = new Processor(false)
+    val comp:XsltCompiler = proc.newXsltCompiler()
+    val xsltStreamSource = new StreamSource(xsl.openStream())
+    xsltStreamSource.setSystemId(xsl.toString)
+    val exp:XsltExecutable = comp.compile(xsltStreamSource)
+    XSLTStreamer(proc, exp)
+  }
+
+
+}
+
+
+
 object Danseur {
 
   ResponseCache.setDefault(URLResolver("/home/betehess/W3C"))
@@ -35,7 +77,6 @@
         val out:Serializer = new Serializer()
         out.setOutputProperty(Serializer.Property.METHOD, "html")
         out.setOutputProperty(Serializer.Property.INDENT, "yes")
-//        out.setOutputFile(new File(o))
         out.setOutputStream(os)
         val trans:XsltTransformer = exp.load()
         trans.setInitialContextNode(source)
@@ -48,8 +89,13 @@
       case Path(Seg(p :: Nil)) => ResponseString(p)
     }
 
-    val test = unfiltered.filter.Planify {
-      case Path(Seg("test" :: Nil)) => resp
+    val trdoc2rdfXSLT = XSLTStreamer(new URL("http://www.w3.org/2001/10/trdoc2rdf.xslt"))
+
+    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))
+      }
     }
     
     unfiltered.jetty.Http.local(2719).filter(test).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.