changeset 45:2cd3a150d581

~ avoid multiple parsing of XSL templates
author Alexandre Bertails <bertails@w3.org>
date Mon, 15 Aug 2011 16:45:38 -0400
parents 82ddda254f91
children c7b8bbeb877a
files src/main/scala/Main.scala
diffstat 1 files changed, 17 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Mon Aug 15 16:19:37 2011 -0400
+++ b/src/main/scala/Main.scala	Mon Aug 15 16:45:38 2011 -0400
@@ -54,6 +54,11 @@
 }
 
 
+object PubrulesXSL {
+  val trdoc2rdf = XSLTStreamer(new URL("http://www.w3.org/2001/10/trdoc2rdf.xslt"))
+  val pubrules = XSL("http://www.w3.org/2005/07/13-pubrules.xsl")
+  val frame = XSL("http://www.w3.org/2005/09/checker/frame.xsl")
+}
 
 object Danseur {
 
@@ -64,30 +69,20 @@
       case _        => ()
     }
 
-
     val echo = unfiltered.filter.Planify {
       case Path(Seg(p :: Nil)) => ResponseString(p)
     }
 
-    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))
+        PubrulesXSL.trdoc2rdf(new URL(url))
       }
     }
     
-    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("/2005/07/pubrules") & Params(params) if params contains "uri" => {
 
-
-        //val spec = "http://www.w3.org/TR/2004/WD-i18n-html-tech-char-20040509/"
-
         val spec = params("uri").head
 
         val paramsNoURI = params - "uri" map { case(k, v) => (k, v.head) }
@@ -107,29 +102,32 @@
             "recursive" -> "off",
             "recurse_auth" -> "on")
 
-        val pubrulesXSL = XSL("http://www.w3.org/2005/07/13-pubrules.xsl")
+        /* first we generate the an HTML page were parameters in the form are set */
+
         val pubrulesXML = Source("http://www.w3.org/2005/07/13-pubrules-src.html")
 
-        // because they are Maps, paramsNoURI overrides the default parameters in defaultParams
+        /* because they are Maps, paramsNoURI overrides the default parameters in defaultParams */
         val paramsForPubrulesSpecialized = defaultParams ++ paramsNoURI + ( "uri" -> spec )
 
-        val pubrulesHTML = pubrulesXSL using paramsForPubrulesSpecialized applyOn pubrulesXML getSource()
+        val pubrulesHTML = PubrulesXSL.pubrules using paramsForPubrulesSpecialized applyOn pubrulesXML getSource()
 
-        val frame = XSL("http://www.w3.org/2005/09/checker/frame.xsl") using ("display" -> "all") using ("recurse_auth" -> "on")
+        /* the pubrules checker is just a wrapper from frame.xsl applied on the HTML above  */
+
+        val frame = PubrulesXSL.frame using ("display" -> "all") using ("recurse_auth" -> "on")
         
         val pubrulesWrapper = XSL(frame applyOn pubrulesHTML getSource())
 
-        val paramsW = defaultParams ++ paramsNoURI + ( "doc_uri" -> spec )        
+        /* the result comes from applying the wrapper on the document being checked */
+
+        val paramsW = defaultParams ++ paramsNoURI + ( "doc_uri" -> spec )
 
         pubrulesWrapper using paramsW applyOn (Source(spec)) getResponder()
 
       }
     }
 
-
     unfiltered.jetty.Http(2719).filter(pubrules).filter(trdoc2rdf).filter(echo).run()
 
-
   }
 
 }
@@ -174,7 +172,7 @@
       }
     }
 
-  def applyOn(destination:Destination): Unit = {
+  private def applyOn(destination:Destination): Unit = {
     val doc:XdmNode = XSL.proc.newDocumentBuilder().build(this.source.source)
     transformer.setInitialContextNode(doc)
     transformer.setDestination(destination)
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.