summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-08-30 11:12:42 +0000
committerBurak Emir <emir@epfl.ch>2006-08-30 11:12:42 +0000
commit30ed1a370231b6ad6c339bc7b8cc0dad2700b4c9 (patch)
tree98a6581b3f1ac9c03da74b847f036195ee1b83d4 /src
parent927abec3b0ec9ac2a677876a4d55cebc40c83f88 (diff)
downloadscala-30ed1a370231b6ad6c339bc7b8cc0dad2700b4c9.tar.gz
scala-30ed1a370231b6ad6c339bc7b8cc0dad2700b4c9.tar.bz2
scala-30ed1a370231b6ad6c339bc7b8cc0dad2700b4c9.zip
scala.xml.metadata change
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/xml/MetaData.scala110
-rw-r--r--src/library/scala/xml/NodeSeq.scala2
-rw-r--r--src/library/scala/xml/PrefixedAttribute.scala55
-rw-r--r--src/library/scala/xml/UnprefixedAttribute.scala47
-rw-r--r--src/library/scala/xml/Utility.scala73
-rw-r--r--src/library/scala/xml/parsing/MarkupParser.scala15
6 files changed, 198 insertions, 104 deletions
diff --git a/src/library/scala/xml/MetaData.scala b/src/library/scala/xml/MetaData.scala
index ea930f9ac0..33e8fe2e88 100644
--- a/src/library/scala/xml/MetaData.scala
+++ b/src/library/scala/xml/MetaData.scala
@@ -9,9 +9,9 @@
// $Id$
-package scala.xml;
+package scala.xml
-import scala.runtime.compat.StringBuilder;
+import scala.runtime.compat.StringBuilder
/** Attribute information item, and linked list of attribute information items.
* These are triples consisting of prefix,key,value. To obtain the namespace,
@@ -27,55 +27,55 @@ abstract class MetaData extends Iterable[MetaData] {
/** appends given MetaData items to this MetaData list */
def append(m: MetaData): MetaData =
- next.append(copy(m));
+ next.append(copy(m))
- def apply(s:String) = getValue(s);
+ def apply(s:String) = getValue(s)
- def apply(uri:String, scp:NamespaceBinding, k:String)= getValue(uri, scp, k);
+ def apply(uri:String, scp:NamespaceBinding, k:String)= getValue(uri, scp, k)
def containedIn1(m: MetaData): Boolean =
- m.equals1(this) || containedIn1(m.next);
+ m.equals1(this) || containedIn1(m.next)
/** returns a copy of this MetaData item with next field set to argument */
- def copy(next: MetaData): MetaData;
+ def copy(next: MetaData): MetaData
/** if owner is the element of this metadata item, returns namespace */
- def getNamespace(owner: Node): String;
+ def getNamespace(owner: Node): String
- def hasNext = (Null != next);
+ def hasNext = (Null != next)
- def length: Int = length(0);
+ def length: Int = length(0)
- def length(i: Int): Int = next.length(i + 1);
+ def length(i: Int): Int = next.length(i + 1)
- def isPrefixed: Boolean;
+ def isPrefixed: Boolean
- //def containedIn(m:MetaData): Boolean;
+ //def containedIn(m:MetaData): Boolean
- //def deepCopy: MetaData;
+ //def deepCopy: MetaData
- //def deepCopy(tail:MetaData): MetaData;
+ //def deepCopy(tail:MetaData): MetaData
/** deep equals method */
override def equals(that: Any) = {
that match {
case m: MetaData =>
- var res = (this.length == m.length) && (this.hashCode() == m.hashCode());
- val it = this.elements;
+ var res = (this.length == m.length) && (this.hashCode() == m.hashCode())
+ val it = this.elements
while (res && it.hasNext) { res = it.next.containedIn1(m) }
res
- case _ => false;
+ case _ => false
}
}
/** returns an iterator on attributes */
def elements = new Iterator[MetaData] {
- var x: MetaData = MetaData.this;
- def hasNext = Null != x;
+ var x: MetaData = MetaData.this
+ def hasNext = Null != x
def next = {
- val y = x;
- x = x.next;
+ val y = x
+ x = x.next
y
}
}
@@ -85,78 +85,78 @@ abstract class MetaData extends Iterable[MetaData] {
def nodes = {
class NodeProxy(last:MetaData) extends Node {
override def prefix = last match {
- case p:PrefixedAttribute => p.pre;
+ case p:PrefixedAttribute => p.pre
case _ => null
}
- override def label = "@"+last.key;
- override def child = Text(last.value);
+ override def label = "@"+last.key
+ override def child = Text(last.value)
override def text = last.value
}
- val ns = new Array[Node](this.length);
- var i = 0;
- val it = elements;
+ val ns = new Array[Node](this.length)
+ var i = 0
+ val it = elements
while(it.hasNext) {
- val a = it.next;
- ns(i) = new NodeProxy(a);
- i = i + 1;
+ val a = it.next
+ ns(i) = new NodeProxy(a)
+ i = i + 1
}
- val seq = array2seq(ns);
- NodeSeq.fromSeq(seq);
+ val seq = array2seq(ns)
+ NodeSeq.fromSeq(seq)
}
*/
/** shallow equals method */
- def equals1(that: MetaData): Boolean;
+ def equals1(that: MetaData): Boolean
/** filters this sequence of meta data */
def filter(f: MetaData => Boolean): MetaData = {
- if (f(this)) copy(next filter f) else next filter f;
+ if (f(this)) copy(next filter f) else next filter f
}
/** returns key of this MetaData item */
- def key: String;
+ def key: String
/** returns value of this MetaData item */
- def value: String;
+ def value: Seq[Node]
/** maps this sequence of meta data */
- def map(f: MetaData => Text): List[Text] = f(this)::(next map f);
+ def map(f: MetaData => Text): List[Text] = f(this)::(next map f)
/** returns Null or the next MetaData item */
- def next: MetaData;
+ def next: MetaData
/** gets value of unqualified (unprefixed) attribute with given key */
- def getValue(key: String): String;
+ def getValue(key: String): Seq[Node]
/** gets value of qualified (prefixed) attribute with given key */
- def getValue(namespace: String, owner: Node, key: String): String =
- getValue(namespace, owner.scope, key);
+ def getValue(namespace: String, owner: Node, key: String): Seq[Node] =
+ getValue(namespace, owner.scope, key)
/** gets value of qualified (prefixed) attribute with given key */
- def getValue(namespace: String, scope: NamespaceBinding, key: String): String;
- override def hashCode(): Int;
+ def getValue(namespace: String, scope: NamespaceBinding, key: String): Seq[Node]
+ override def hashCode(): Int
def toString1(): String = {
- val sb = new StringBuilder();
- toString1(sb);
- sb.toString();
+ val sb = new StringBuilder()
+ toString1(sb)
+ sb.toString()
}
//appends string representations of single attribute to StringBuilder
- def toString1(sb:StringBuilder): Unit;
+ def toString1(sb:StringBuilder): Unit
override def toString(): String = {
- val sb = new StringBuilder();
- toString(sb);
- sb.toString();
+ val sb = new StringBuilder()
+ toString(sb)
+ sb.toString()
}
def toString(sb: StringBuilder): Unit = {
- sb.append(' ');
- toString1(sb);
- next.toString(sb);
+ sb.append(' ')
+ toString1(sb)
+ next.toString(sb)
}
- def wellformed(scope: NamespaceBinding): Boolean;
+ def wellformed(scope: NamespaceBinding): Boolean
}
diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala
index a5eeed8251..ee18c5bceb 100644
--- a/src/library/scala/xml/NodeSeq.scala
+++ b/src/library/scala/xml/NodeSeq.scala
@@ -63,7 +63,7 @@ abstract class NodeSeq extends Seq[Node] {
val y = this(0);
val v = y.attribute(k);
if( v != null ) {
- NodeSeq.fromSeq(Seq.single(Text(v):Node));
+ v // NodeSeq.fromSeq(Seq.single(Text(v):Node));
} else
NodeSeq.Empty
diff --git a/src/library/scala/xml/PrefixedAttribute.scala b/src/library/scala/xml/PrefixedAttribute.scala
index 8b587a4d0d..cb8dbb0082 100644
--- a/src/library/scala/xml/PrefixedAttribute.scala
+++ b/src/library/scala/xml/PrefixedAttribute.scala
@@ -9,7 +9,7 @@
// $Id$
-package scala.xml;
+package scala.xml
import scala.runtime.compat.StringBuilder
@@ -17,28 +17,33 @@ import scala.runtime.compat.StringBuilder
*/
class PrefixedAttribute(val pre: String,
val key: String,
- val value: String,
+ val value: Seq[Node],
val next: MetaData) extends MetaData {
- // verify that value is a proper attribute value (references, no &lt;)
+ /** same as this(key, Utility.parseAttributeValue(value), next) */
+ def this(pre: String, key: String, value: String, next: MetaData) =
+ this(pre, key, Utility.parseAttributeValue(value), next)
+
+ /* verify that value is a proper attribute value (references, no &lt)
Utility.checkAttributeValue(value) match {
- case null => ;
- case msg => throw new MalformedAttributeException(msg);
+ case null =>
+ case msg => throw new MalformedAttributeException(msg)
}
+ */
/** Returns a copy of this unprefixed attribute with the given
* next field.
*/
def copy(next: MetaData) =
- new PrefixedAttribute(pre, key, value, next);
+ new PrefixedAttribute(pre, key, value, next)
//** duplicates the MetaData (deep copy), not preserving order */
- //def deepCopy: MetaData = deepCopy(null);
+ //def deepCopy: MetaData = deepCopy(null)
//** duplicates the MetaData (deep copy), prepending it to tail */
/*
def deepCopy(tail: MetaData): MetaData = {
- val md = copy(tail);
+ val md = copy(tail)
if (null == next)
md
else
@@ -49,41 +54,45 @@ class PrefixedAttribute(val pre: String,
def equals1(m: MetaData) =
(m.isPrefixed &&
(m.asInstanceOf[PrefixedAttribute].pre == pre) &&
- (m.key == key) && (m.value == value));
+ (m.key == key) && (m.value sameElements value))
def getNamespace(owner: Node) =
- owner.getNamespace(pre);
+ owner.getNamespace(pre)
- /** forwards the call to next */
- def getValue(key: String): String = next.getValue(key);
+ /** forwards the call to next (because caller looks for unprefixed attribute */
+ def getValue(key: String): Seq[Node] = next.getValue(key)
/** gets attribute value of qualified (prefixed) attribute with given key
*/
- def getValue(namespace: String, scope: NamespaceBinding, key: String): String = {
+ def getValue(namespace: String, scope: NamespaceBinding, key: String): Seq[Node] = {
if (key == this.key && scope.getURI(pre) == namespace)
value
else
- next.getValue(namespace, scope, key);
+ next.getValue(namespace, scope, key)
}
/** returns true */
- final def isPrefixed = true;
+ final def isPrefixed = true
override def hashCode() =
- pre.hashCode() * 41 + key.hashCode() * 7 + value.hashCode() * 3 + next.hashCode();
+ pre.hashCode() * 41 + key.hashCode() * 7 + value.hashCode() * 3 + next.hashCode()
def toString1(sb:StringBuilder): Unit = {
- sb.append(pre);
- sb.append(':');
- sb.append(key);
- sb.append('=');
- Utility.appendQuoted(value, sb);
+ sb.append(pre)
+ sb.append(':')
+ sb.append(key)
+ sb.append('=')
+ val sb2 = new StringBuilder()
+ for (val c <- value) {
+ Utility.toXML(c, TopScope, sb2, true)
+ }
+ Utility.appendQuoted(sb2.toString(), sb)
}
def wellformed(scope: NamespaceBinding): Boolean = {
- (null == next.getValue(scope.getURI(pre), scope, key)
- && next.wellformed(scope));
+ (null == next.getValue(scope.getURI(pre), scope, key) &&
+ next.wellformed(scope))
}
}
diff --git a/src/library/scala/xml/UnprefixedAttribute.scala b/src/library/scala/xml/UnprefixedAttribute.scala
index 02d42507cb..77c43c783d 100644
--- a/src/library/scala/xml/UnprefixedAttribute.scala
+++ b/src/library/scala/xml/UnprefixedAttribute.scala
@@ -9,30 +9,35 @@
// $Id$
-package scala.xml;
+package scala.xml
import scala.runtime.compat.StringBuilder
/** unprefixed attributes have the null namespace
*/
-class UnprefixedAttribute(val key: String, val value: String, val next: MetaData) extends MetaData {
+class UnprefixedAttribute(val key: String, val value: Seq[Node], val next: MetaData) extends MetaData {
- // verify that value is a proper attribute value (references, no &lt;)
+ /** same as this(key, Utility.parseAttributeValue(value), next) */
+ def this(key: String, value: String, next: MetaData) =
+ this(key, Utility.parseAttributeValue(value), next)
+
+ /* verify that value is a proper attribute value (references, no &lt)
Utility.checkAttributeValue(value) match {
- case null => ;
- case msg => throw new MalformedAttributeException(msg);
+ case null =>
+ case msg => throw new MalformedAttributeException(msg)
}
+*/
/** returns a copy of this unprefixed attribute with the given next field*/
def copy(next: MetaData) =
- new UnprefixedAttribute(key, value, next);
+ new UnprefixedAttribute(key, value, next)
def equals1(m:MetaData) =
- !m.isPrefixed && (m.key == key) && (m.value == value);
+ !m.isPrefixed && (m.key == key) && (m.value sameElements value)
/** returns null */
final def getNamespace(owner: Node): String =
- null;
+ null
/**
* Gets value of unqualified (unprefixed) attribute with given key.
@@ -40,34 +45,38 @@ class UnprefixedAttribute(val key: String, val value: String, val next: MetaData
* @param key
* @return ..
*/
- def getValue(key: String): String =
- if (key == this.key) value else next.getValue(key);
+ def getValue(key: String): Seq[Node] =
+ if (key == this.key) value else next.getValue(key)
/**
- * Forwards the call to next.
+ * Forwards the call to next (because caller looks for prefixed attribute).
*
* @param namespace
* @param scope
* @param key
* @return ..
*/
- def getValue(namespace: String, scope: NamespaceBinding, key: String): String =
- next.getValue(namespace, scope, key);
+ def getValue(namespace: String, scope: NamespaceBinding, key: String): Seq[Node] =
+ next.getValue(namespace, scope, key)
override def hashCode() =
- key.hashCode() * 7 + value.hashCode() * 53 + next.hashCode();
+ key.hashCode() * 7 + value.hashCode() * 53 + next.hashCode()
/** returns false */
- final def isPrefixed = false;
+ final def isPrefixed = false
def toString1(sb:StringBuilder): Unit = {
- sb.append(key);
- sb.append('=');
- Utility.appendQuoted(value, sb);
+ sb.append(key)
+ sb.append('=')
+ val sb2 = new StringBuilder()
+ for (val c <- value) {
+ Utility.toXML(c, TopScope, sb2, true)
+ }
+ Utility.appendQuoted(sb2.toString(), sb)
}
def wellformed(scope: NamespaceBinding): Boolean =
- (null == next.getValue(null, scope, key)) && next.wellformed(scope);
+ (null == next.getValue(null, scope, key)) && next.wellformed(scope)
}
diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala
index 19b2c5595b..91e4516b1c 100644
--- a/src/library/scala/xml/Utility.scala
+++ b/src/library/scala/xml/Utility.scala
@@ -241,4 +241,77 @@ object Utility extends AnyRef with parsing.TokenTests {
null
}
+ /** new
+ */
+ def parseAttributeValue(value:String):Seq[Node] = {
+ val zs:Seq[Char] = value
+ val sb = new StringBuilder()
+ val nb = new NodeBuffer()
+ val it = zs.elements
+ while(it.hasNext) {
+ var c = it.next
+ c match {
+ case '&' =>
+ if(sb.length() > 0) {
+ nb += Text(sb.toString())
+ sb.setLength(0)
+ }
+ it.next match {
+ case '#' =>
+ c = it.next
+ val theChar = parseCharRef ({ ()=> c },{ () => c = it.next },{s => throw new RuntimeException(s)})
+ sb.append(theChar)
+
+ case x =>
+ sb.append(x)
+ c = it.next
+ while(c != ';') {
+ sb.append(c)
+ c = it.next
+ }
+ nb += EntityRef(sb.toString())
+ sb.setLength(0)
+ }
+ case x =>
+ sb.append(x)
+ }
+ }
+ if(sb.length() > 0) {
+ val x = Text(sb.toString())
+ if(nb.length == 0)
+ return x
+ else
+ nb += x
+ }
+ return nb
+ }
+
+ /** CharRef ::= "&amp;#" '0'..'9' {'0'..'9'} ";"
+ * | "&amp;#x" '0'..'9'|'A'..'F'|'a'..'f' { hexdigit } ";"
+ *
+ * see [66]
+ */
+ def parseCharRef(ch: () => Char, nextch: () => Unit, reportSyntaxError:(String) => Unit): String = {
+ val hex = (ch() == 'x') && { nextch(); true };
+ val base = if (hex) 16 else 10;
+ var i = 0;
+ while (ch() != ';') {
+ ch() match {
+ case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =>
+ i = i * base + Character.digit( ch(), base );
+ case 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
+ | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' =>
+ if (! hex)
+ reportSyntaxError("hex char not allowed in decimal char ref\n"
+ +"Did you mean to write &#x ?");
+ else
+ i = i * base + Character.digit(ch(), base);
+ case _ =>
+ reportSyntaxError("character '" + ch() + " not allowed in char ref\n");
+ }
+ nextch();
+ }
+ new String(Predef.Array(i.asInstanceOf[char]))
+ }
+
}
diff --git a/src/library/scala/xml/parsing/MarkupParser.scala b/src/library/scala/xml/parsing/MarkupParser.scala
index ceecd6f79e..2de0d1cbf3 100644
--- a/src/library/scala/xml/parsing/MarkupParser.scala
+++ b/src/library/scala/xml/parsing/MarkupParser.scala
@@ -103,13 +103,13 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
m.getValue("version") match {
case null => ;
- case "1.0" => info_ver = Some("1.0"); n = n + 1;
+ case Text("1.0") => info_ver = Some("1.0"); n = n + 1;
case _ => reportSyntaxError("cannot deal with versions != 1.0");
}
m.getValue("encoding") match {
case null => ;
- case enc => if (!isValidIANAEncoding(enc.toString()))
+ case Text(enc) => if (!isValidIANAEncoding(enc.toString()))
reportSyntaxError("\"" + enc + "\" is not a valid encoding");
else {
info_enc = Some(enc.toString());
@@ -118,8 +118,8 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
}
m.getValue("standalone") match {
case null => ;
- case "yes" => info_stdl = Some(true); n = n + 1;
- case "no" => info_stdl = Some(false); n = n + 1;
+ case Text("yes") => info_stdl = Some(true); n = n + 1;
+ case Text("no") => info_stdl = Some(false); n = n + 1;
case _ => reportSyntaxError("either 'yes' or 'no' expected");
}
@@ -141,13 +141,13 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
m.getValue("version") match {
case null => ;
- case "1.0" => info_ver = Some("1.0"); n = n + 1;
+ case Text("1.0") => info_ver = Some("1.0"); n = n + 1;
case _ => reportSyntaxError("cannot deal with versions != 1.0");
}
m.getValue("encoding") match {
case null => ;
- case enc => if (!isValidIANAEncoding(enc.toString()))
+ case Text(enc) => if (!isValidIANAEncoding(enc.toString()))
reportSyntaxError("\"" + enc + "\" is not a valid encoding");
else {
info_enc = Some(enc.toString());
@@ -405,6 +405,8 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
* see [66]
*/
def xCharRef(ch: () => Char, nextch: () => Unit): String = {
+ Utility.parseCharRef(ch, nextch, &reportSyntaxError)
+ /*
val hex = (ch() == 'x') && { nextch(); true };
val base = if (hex) 16 else 10;
var i = 0;
@@ -425,6 +427,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
nextch();
}
new String(Predef.Array(i.asInstanceOf[char]))
+ */
}