diff options
author | buraq <buraq@epfl.ch> | 2004-08-02 14:25:30 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-08-02 14:25:30 +0000 |
commit | 20de82010be891861b83f40358154788afc5d832 (patch) | |
tree | 347d76deca6780c7433f66e1104492b9471d41e5 | |
parent | 8ac6b339272befc95e4596c6c957b1316782439d (diff) | |
download | scala-20de82010be891861b83f40358154788afc5d832.tar.gz scala-20de82010be891861b83f40358154788afc5d832.tar.bz2 scala-20de82010be891861b83f40358154788afc5d832.zip |
modified xml parsing
-rw-r--r-- | sources/scala/tools/servlet/engine/config/ConfigHandler.scala | 20 | ||||
-rw-r--r-- | sources/scala/xml/Attribute.scala | 7 | ||||
-rw-r--r-- | sources/scala/xml/parsing/ConstructingHandler.scala | 11 | ||||
-rw-r--r-- | sources/scala/xml/parsing/MarkupHandler.scala | 38 | ||||
-rw-r--r-- | sources/scala/xml/parsing/MarkupParser.scala | 11 |
5 files changed, 32 insertions, 55 deletions
diff --git a/sources/scala/tools/servlet/engine/config/ConfigHandler.scala b/sources/scala/tools/servlet/engine/config/ConfigHandler.scala index dcbd659866..9fee0e1ba9 100644 --- a/sources/scala/tools/servlet/engine/config/ConfigHandler.scala +++ b/sources/scala/tools/servlet/engine/config/ConfigHandler.scala @@ -2,22 +2,16 @@ package scala.tools.servlet.engine.config ; import scala.collection.mutable; -import scala.xml.{ Attribute, AttributeSeq, Elem }; +import scala.xml.{ Attribute, IntAttribute, AttributeSeq, Elem }; import scala.xml.parsing._; class ConfigHandler extends MarkupHandler[Config] { final val config_namespace = "http://scala.epfl.ch/scala.tools.servlet.engine/config"; - def attributeCDataValue(pos: int, str:String) = CDataValue(str); - - def attributeIntValue(pos: int, value:Int) = IntValue(value); - - def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri); - - override def attribute(pos: int, uri:String, key: String, value:String): AttribValue = + override def attribute(pos: int, uri:String, key: String, value:String): Attribute = if( key == "port" ) - attributeIntValue(pos, Integer.parseInt(value)); + new IntAttribute(uri, key, Integer.parseInt(value)); else super.attribute(pos, uri, key, value); @@ -26,7 +20,7 @@ class ConfigHandler extends MarkupHandler[Config] { /** be careful to copy everything from attrMap1, as it will change * @param attrMap1 the attribute map. */ - def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],AttribValue], args: mutable.Buffer[Config]): Option[Config] = { + def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[Config]): Option[Config] = { if( uri == config_namespace ) { label match { @@ -39,13 +33,13 @@ class ConfigHandler extends MarkupHandler[Config] { } Some(EngineConfig( list )); - case "connector" if attrMap1(Pair(config_namespace,"protocol")).asString == "http" => - val res = HttpConnectorConfig( attrMap1(Pair(config_namespace,"port")).asInt, hmap ); + case "connector" if attrMap1(Pair(config_namespace,"protocol")).value == "http" => + val res = HttpConnectorConfig( attrMap1(Pair(config_namespace,"port")).intValue, hmap ); hmap = new mutable.HashMap[String,String]; Some(res) case "map" => - hmap.update(attrMap1(Pair(config_namespace,"url")).asString, attrMap1(Pair(config_namespace,"to")).asString); + hmap.update(attrMap1(Pair(config_namespace,"url")).value, attrMap1(Pair(config_namespace,"to")).value); None } } else None diff --git a/sources/scala/xml/Attribute.scala b/sources/scala/xml/Attribute.scala index 92eeedf93c..7a236829eb 100644 --- a/sources/scala/xml/Attribute.scala +++ b/sources/scala/xml/Attribute.scala @@ -19,6 +19,8 @@ package scala.xml ; */ case class Attribute(namespace:String, key:String, value:String) with Ordered[Attribute] { + def intValue: Int = Integer.parseInt(value); + def compareTo [b >: Attribute <% Ordered[b]](that: b): int = that match { case z:Attribute => val i = key.compareTo( z.key ); @@ -27,3 +29,8 @@ 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/parsing/ConstructingHandler.scala b/sources/scala/xml/parsing/ConstructingHandler.scala index dcbf0d7d28..a70d5b29b9 100644 --- a/sources/scala/xml/parsing/ConstructingHandler.scala +++ b/sources/scala/xml/parsing/ConstructingHandler.scala @@ -6,21 +6,24 @@ import scala.collection.mutable ; /** */ class ConstructingHandler extends MarkupHandler[Node] { - def attributeCDataValue(pos: int, str:String) = CDataValue(str); + //def attributeCDataValue(pos: int, str:String) = CDataValue(str); - def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri); + //def attributeNamespaceDecl(pos: int, uri: String) = NamespaceDecl(uri); - def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],AttribValue], args: mutable.Buffer[Node]) = { + def element(pos: int, uri: String, label: String, attrMap1: mutable.Map[Pair[String,String],Attribute], args: mutable.Buffer[Node]) = { var attrs = new Array[Attribute](attrMap1.size); { var i = 0; val it = attrMap1.elements; while( it.hasNext ) { - val Pair(Pair(uri:String, key:String), va: AttribValue) = it.next; + val Pair(Pair(uri:String, key:String), va: Attribute) = it.next; + attrs( i ) = va; + /* va match { case CDataValue(str) => attrs( i ) = Attribute(uri, key, str); } + */ i = i + 1; } } diff --git a/sources/scala/xml/parsing/MarkupHandler.scala b/sources/scala/xml/parsing/MarkupHandler.scala index ced3895035..c35e167e47 100644 --- a/sources/scala/xml/parsing/MarkupHandler.scala +++ b/sources/scala/xml/parsing/MarkupHandler.scala @@ -29,44 +29,16 @@ abstract class MarkupHandler[A] { /** removes xmlns attributes from attr as a side effect, and returns a prefix * map resulting from them - * / - final def namespaceDecl1(aMap: mutable.Map[String, AttribValue]): Map[String, String] = { - val setNS = new mutable.HashMap[String, String]; - / * DEBUG * / - val attrIt = aMap.keys; - while( attrIt.hasNext ) { - val z = attrIt.next; - if( z.startsWith("xmlns") ) { - val uri = aMap( z ) match { - case NamespaceDecl(uri1) => uri1; - case _ => throw FatalError("bad namespace declaration"); - } - val i = z.indexOf(':'); - if( i == -1 ) - setNS.update("", uri ); - else { - val zz = z.substring( i+1, z.length() ); - setNS.update( zz, uri ); - } - aMap -= z; - } - } - setNS; - } - */ - - /** removes xmlns attributes from attr as a side effect, and returns a prefix - * map resulting from them */ final def internal_namespaceDecl(prefix:String, uri:String): Unit = { tmpPrefix.update(prefix, uri); } - def attributeCDataValue(pos: int, str:String): AttribValue; - def attributeNamespaceDecl(pos: int, uri: String): AttribValue; + //def attributeCDataValue(pos: int, str:String): Attribute; + //def attributeNamespaceDecl(pos: int, uri: String): Attribute; - def attribute(pos: int, uri: String, key: String, value:String): AttribValue = - attributeCDataValue(pos, value); + def attribute(pos: int, uri: String, key: String, value:String) = + Attribute(uri,key,value); /** be careful to copy everything from attrMap1, as it will change * @param pos the position in the sourcefile @@ -75,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],AttribValue], args: mutable.Buffer[A]): Iterable[A]; + def element(pos: int, uri: String, label: String, attrMap1: mutable.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]; diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala index ab62a37dc7..425fa6665e 100644 --- a/sources/scala/xml/parsing/MarkupParser.scala +++ b/sources/scala/xml/parsing/MarkupParser.scala @@ -9,6 +9,7 @@ package scala.xml.parsing; +import scala.xml.Attribute; import scala.collection.{ mutable, Map }; import scala.collection.immutable.ListMap; @@ -39,10 +40,10 @@ abstract class MarkupParser[MarkupType] { /** append Unicode character to name buffer*/ protected def putChar(c: Char) = cbuf.append(c); - protected var aMap: mutable.Map[String,AttribValue] = _; + protected var aMap: mutable.Map[String,Attribute] = _; final val noChildren = new mutable.ListBuffer[MarkupType]; - final val noAttribs = new mutable.HashMap[Pair[String,String], AttribValue]; + final val noAttribs = new mutable.HashMap[Pair[String,String], Attribute]; //var xEmbeddedBlock = false; @@ -132,7 +133,7 @@ abstract class MarkupParser[MarkupType] { } // @todo, iterate over attributes, replace prefix, call handleAttribute. handle.internal_startPrefixMapping; - val aMap1 = new mutable.HashMap[Pair[String,String],AttribValue]; + val aMap1 = new mutable.HashMap[Pair[String,String],Attribute]; val it = aMap.elements; while( it.hasNext ) { val x @ Pair(Pair(pref,key),Pair(pos,value)) = it.next; @@ -169,11 +170,11 @@ abstract class MarkupParser[MarkupType] { * [40] STag ::= '<' Name { S Attribute } [S] * [44] EmptyElemTag ::= '<' Name { S Attribute } [S] */ - protected def xTag: Pair[String, mutable.Map[Pair[String,String],AttribValue]] = { + protected def xTag: Pair[String, mutable.Map[Pair[String,String],Attribute]] = { val elemqName = xName; xSpaceOpt; - val aMap: mutable.Map[Pair[String,String],AttribValue] = + val aMap: mutable.Map[Pair[String,String],Attribute] = if(xml.Parsing.isNameStart( ch )) { xAttributes; } else { |