changeset 17:ba437c299c6a

~ use only local names for xpath variables
author Alexandre Bertails <bertails@w3.org>
date Wed, 03 Mar 2010 18:14:28 -0500
parents cc6c7c639fe8
children 78e783c39ef6
files src/main/scala/Main.scala src/main/scala/XML.scala
diffstat 2 files changed, 21 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/scala/Main.scala	Wed Mar 03 17:31:24 2010 -0500
+++ b/src/main/scala/Main.scala	Wed Mar 03 18:14:28 2010 -0500
@@ -37,7 +37,7 @@
     val sectXPath = divHead + "//html:dl/html:dt[matches(normalize-space()," + edregexp(editorSectionName) + ")]"
     val sect = doc.evaluateSingle(sectXPath).get
     // the rights dds are right under the previous section
-    val ddsXPath = "$trd:sect/following-sibling::html:dd[preceding-sibling::html:dt[1] is $trd:sect]"
+    val ddsXPath = "$sect/following-sibling::html:dd[preceding-sibling::html:dt[1] is $sect]"
     val dds = sect.evaluate(ddsXPath, "sect" -> sect)
     // parse and inject the found editors into Editor
     dds map (dd => Editor.parse(dd.text)) toSeq
@@ -47,9 +47,9 @@
     val versionblock = divHead + "//html:dl"
     val dtXPath = versionblock + "/html:dt[matches(normalize-space(.),'version','i') and matches(normalize-space(.),'" + m + "','i')][1]"
     val dt = doc.evaluateSingle(dtXPath).get
-    val ddXPath = "$trd:dt/following-sibling::html:dd[preceding-sibling::html:dt[1] is $trd:dt]"
+    val ddXPath = "$dt/following-sibling::html:dd[preceding-sibling::html:dt[1] is $dt]"
     val dd = dt.evaluateSingle(ddXPath, "dt" -> dt).get
-    val vurisXPath = "$trd:dd//html:a/@href"
+    val vurisXPath = "$dd//html:a/@href"
     // val htmls = dd flatMap (dd => dd.evaluateAsString(vurisXPath, "dd" -> dd))
     val htmls = dd.evaluate(vurisXPath, "dd" -> dd) map (_.normalizeSpace)
     htmls toSeq
--- a/src/main/scala/XML.scala	Wed Mar 03 17:31:24 2010 -0500
+++ b/src/main/scala/XML.scala	Wed Mar 03 18:14:28 2010 -0500
@@ -57,18 +57,8 @@
    */
   def convertUrlToXdmNode(url:String):XdmNode = {
 
-    // we store the full bodies in bytearrays to be able to read from them
-
     val (body, charset) = getBodyAndCharset(url)
 
-    // call the jtidy library to generate a valid xhtml document
-    // the charset corresponds to the one from the http response
-//    val (tidyBody, _) = Tidy.tidy(body, charset)
-
-    // val f = new FileWriter("/tmp/out.xml")
-    // f.write(tidyBody.toString)
-    // f.close()
-
     // parse the XML document using Saxon
     // see http://www.saxonica.com/documentation/xpath-api/s9api-xpath.html
     val proc:Processor = new Processor(false)
@@ -94,13 +84,25 @@
    */
   def XdmNode2Elem(node:XdmNode):Elem = scala.xml.XML.load(new StringReader(node.toString)) 
 
-  val TRD = "http://www.w3.org/2001/10/trdoc-data.xsl"
-  val HTML = Map("html" -> "http://www.w3.org/1999/xhtml",
-		 "trd" -> TRD)
+  val HTML = "html" -> "http://www.w3.org/1999/xhtml"
+  val CONTACT = "contact" -> "http://www.w3.org/2000/10/swap/pim/contact#"
+  val DC = "dc" -> "http://purl.org/dc/elements/1.1/"
+  val DOC = "doc" -> "http://www.w3.org/2000/10/swap/pim/doc#"
+  val LOG = "log" -> "http://www.w3.org/2000/10/swap/log#"
+  val MAT = "mat" -> "http://www.w3.org/2002/05/matrix/vocab#"
+  val ORG = "org" -> "http://www.w3.org/2001/04/roadmap/org#"
+  val RDF = "rdf" -> "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+  val REC = "rec" -> "http://www.w3.org/2001/02pd/rec54#"
+
+  val HTML_NAMESPACES = Map(HTML)
+  val HISTORY_NAMESPACES = Map(DC, DOC, LOG, MAT, ORG, RDF, REC)
 
   val tidy = new NodeInjector with Tidy
+  val nodeInj = new NodeInjector
 
-  def htmlNode(uri:String):Node = new Node(tidy.convertUrlToXdmNode(uri), HTML)
+  def htmlNode(uri:String):Node = new Node(tidy.convertUrlToXdmNode(uri), HTML_NAMESPACES)
+
+  def apply(uri:String, namespaces:Map[String, String]):Node = new Node(nodeInj.convertUrlToXdmNode(uri), namespaces)
 
 }
 
@@ -115,16 +117,14 @@
     val xpathCompiler:XPathCompiler = proc.newXPathCompiler();
     for((prefix, uri) <- namespaces)
       xpathCompiler.declareNamespace(prefix, uri)
-    xpathCompiler.declareNamespace("html", "http://www.w3.org/1999/xhtml")
-    xpathCompiler.declareNamespace("trd", Node.TRD)
     for((v, _) <- variables)
-      xpathCompiler.declareVariable(new QName(Node.TRD, v),
+      xpathCompiler.declareVariable(new QName(v),
 				    ItemType.ANY_NODE,
 				    OccurrenceIndicator.ONE_OR_MORE)
     val selector:XPathSelector = xpathCompiler.compile(xpath).load()
     selector.setContextItem(node)
     for((v, n) <- variables)
-      selector.setVariable(new QName(Node.TRD, v), n.node)
+      selector.setVariable(new QName(v), n.node)
     selector
   }
 
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.