diff options
author | buraq <buraq@epfl.ch> | 2004-08-02 16:09:00 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-08-02 16:09:00 +0000 |
commit | ebfda5b5166d0c50ea062d32c4f33ed412ef0108 (patch) | |
tree | c1de1265b70b5cf89655bc2a9c2fbbf03a3eaff7 /sources | |
parent | 66e469b90433209ae7d180ecc7211a2f18af35f8 (diff) | |
download | scala-ebfda5b5166d0c50ea062d32c4f33ed412ef0108.tar.gz scala-ebfda5b5166d0c50ea062d32c4f33ed412ef0108.tar.bz2 scala-ebfda5b5166d0c50ea062d32c4f33ed412ef0108.zip |
modified xml parsing
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/servlet/engine/config/ConfigHandler.scala | 6 | ||||
-rw-r--r-- | sources/scala/xml/Attribute.scala | 5 | ||||
-rw-r--r-- | sources/scala/xml/AttributeSeq.scala | 12 | ||||
-rw-r--r-- | sources/scala/xml/NodeTraverser.scala | 25 | ||||
-rw-r--r-- | sources/scala/xml/parsing/ConstructingHandler.scala | 4 | ||||
-rw-r--r-- | sources/scala/xml/parsing/MarkupHandler.scala | 2 |
6 files changed, 40 insertions, 14 deletions
diff --git a/sources/scala/tools/servlet/engine/config/ConfigHandler.scala b/sources/scala/tools/servlet/engine/config/ConfigHandler.scala index 9fee0e1ba9..c8cdadf6b6 100644 --- a/sources/scala/tools/servlet/engine/config/ConfigHandler.scala +++ b/sources/scala/tools/servlet/engine/config/ConfigHandler.scala @@ -9,12 +9,6 @@ class ConfigHandler extends MarkupHandler[Config] { final val config_namespace = "http://scala.epfl.ch/scala.tools.servlet.engine/config"; - override def attribute(pos: int, uri:String, key: String, value:String): Attribute = - if( key == "port" ) - new IntAttribute(uri, key, Integer.parseInt(value)); - else - super.attribute(pos, uri, key, value); - var hmap = new mutable.HashMap[String,String]; /** be careful to copy everything from attrMap1, as it will change diff --git a/sources/scala/xml/Attribute.scala b/sources/scala/xml/Attribute.scala index 7a236829eb..b73884488c 100644 --- a/sources/scala/xml/Attribute.scala +++ b/sources/scala/xml/Attribute.scala @@ -29,8 +29,3 @@ case class Attribute(namespace:String, key:String, value:String) with Ordered[At } } - -class IntAttribute(namespace:String, key:String, theIntValue:Int) -extends Attribute(namespace, key, theIntValue.toString()) { - final override def intValue = theIntValue; -} diff --git a/sources/scala/xml/AttributeSeq.scala b/sources/scala/xml/AttributeSeq.scala index f3a8800c98..a47605eafa 100644 --- a/sources/scala/xml/AttributeSeq.scala +++ b/sources/scala/xml/AttributeSeq.scala @@ -10,6 +10,7 @@ package scala.xml ; import scala.collection.Map ; +import scala.collection.mutable ; import scala.collection.immutable.TreeSet ; object AttributeSeq { @@ -85,5 +86,16 @@ abstract class AttributeSeq with Seq[Attribute] { } override def hashCode():Int = sortedSeq.hashCode(); + + def toMap:Map[Pair[String,String],Attribute] = + new Map[Pair[String,String],Attribute] { + def elements = new Iterator[Pair[Pair[String,String],Attribute]] { + val it = AttributeSeq.this.sortedSeq.elements; + def hasNext = it.hasNext; + def next = { val a = it.next; Pair(Pair(a.namespace,a.key),a) } + } + def size = AttributeSeq.this.length; + def get(p:Pair[String,String]) = AttributeSeq.this.lookup(p._1, p._2); + } } diff --git a/sources/scala/xml/NodeTraverser.scala b/sources/scala/xml/NodeTraverser.scala new file mode 100644 index 0000000000..41b7a1fc93 --- /dev/null +++ b/sources/scala/xml/NodeTraverser.scala @@ -0,0 +1,25 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ + +package scala.xml ; + +import scala.collection.mutable ; + +abstract class NodeTraverser[A](handle: parsing.MarkupHandler[A]) { + + def traverse(n: Node): Iterable[A] = { + val nb = new mutable.ArrayBuffer[A](); + val it = n.child.elements; + while(it.hasNext) { + nb.appendAll(traverse(it.next)); + } + handle.element(0, n.namespace, n.label, n.attributes.toMap, nb) + } + +} diff --git a/sources/scala/xml/parsing/ConstructingHandler.scala b/sources/scala/xml/parsing/ConstructingHandler.scala index a70d5b29b9..cf2070320f 100644 --- a/sources/scala/xml/parsing/ConstructingHandler.scala +++ b/sources/scala/xml/parsing/ConstructingHandler.scala @@ -1,6 +1,6 @@ package scala.xml.parsing; -import scala.collection.immutable.Map ; +import scala.collection.Map ; import scala.collection.mutable ; /** */ @@ -10,7 +10,7 @@ class ConstructingHandler extends MarkupHandler[Node] { //def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri); - def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[Node]) = { + def element(pos: int, uri: String, label: String, attrMap1: Map[Pair[String,String],Attribute], args: mutable.Buffer[Node]) = { var attrs = new Array[Attribute](attrMap1.size); { diff --git a/sources/scala/xml/parsing/MarkupHandler.scala b/sources/scala/xml/parsing/MarkupHandler.scala index c35e167e47..53af6eaaf2 100644 --- a/sources/scala/xml/parsing/MarkupHandler.scala +++ b/sources/scala/xml/parsing/MarkupHandler.scala @@ -47,7 +47,7 @@ abstract class MarkupHandler[A] { * @param attrMap1 the attribute map, from Pair(uri,label) to target * @param args the children of this element */ - def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[A]): Iterable[A]; + def element(pos: int, uri: String, label: String, attrMap1: Map[Pair[String,String],Attribute], args: mutable.Buffer[A]): Iterable[A]; def charData(pos: Int, txt: String ): Iterable[A]; def procInstr(pos: Int, target: String, txt: String): Iterable[A]; |