changeset 26:c9e5c04f2fad

~ mix Unfiltered with saxon
author Alexandre Bertails <bertails@w3.org>
date Mon, 08 Aug 2011 15:49:43 -0400
parents 41bb4358478e
children bf9461274f7c
files src/main/scala/Main.scala
diffstat 1 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Mon Aug 08 15:44:13 2011 -0400
+++ b/src/main/scala/Main.scala	Mon Aug 08 15:49:43 2011 -0400
@@ -3,20 +3,44 @@
 import unfiltered.request._
 import unfiltered.response._
 
+import java.net.ResponseCache
+import net.sf.saxon.Transform
+
+import net.sf.saxon.s9api._
+import javax.xml.transform.stream.StreamSource
 import java.io._
 import java.net._
 
+
 object Danseur {
 
+  ResponseCache.setDefault(URLResolver("/home/betehess/W3C"))
+
+
   def main(args: Array[String]) {
 
     val resp = new ResponseStreamer {
       def stream(os:OutputStream):Unit = {
-        val data = new DataOutputStream(os)
-        data.writeUTF("les danseurs sont dans le coin")
 
-//        xslt.setOS(os)
-
+        val s = "http://www.w3.org/TR/2011/CR-WOFF-20110804/"
+        val xsl = "http://www.w3.org/2001/10/trdoc2rdf.xslt"
+        val o = "/tmp/toto2.xml"
+        
+        val proc:Processor = new Processor(false)
+        val comp:XsltCompiler = proc.newXsltCompiler()
+        val xsltStreamSource = new StreamSource(new URL(xsl).openStream())
+        xsltStreamSource.setSystemId(xsl)
+        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.setOutputFile(new File(o))
+        out.setOutputStream(os)
+        val trans:XsltTransformer = exp.load()
+        trans.setInitialContextNode(source)
+        trans.setDestination(out)
+        trans.transform()
       }
     }
 
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.