summaryrefslogtreecommitdiff
path: root/src/library/scala/xml/Group.scala
blob: 8a7cc03da24e0e5af3664d92bd24cc856fd00e4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2006, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.xml

import compat.StringBuilder

/** A hack to group XML nodes in one node for output.
 *
 *  @author  Burak Emir
 *  @version 1.0
 */
[serializable]
case class Group(val nodes: Seq[Node]) extends Node {

  override def theSeq = nodes

  /** structural equality */
  override def equals(x: Any) = x match {
    case z:Node      => (length == 1) && z == apply(0)
    case z:Seq[Node] => sameElements(z)
    case z:String    => text == z
    case _           => false;
  }

  /** always null */
  final def label =
    error("class Group does not support method 'label'")

  /** always empty */
  final override def attributes =
    error("class Group does not support method 'attributes'")

  /** always null */
  final override def namespace =
    error("class Group does not support method 'namespace'")

  /** always empty */
  final override def child =
    error("class Group does not support method 'child'")

  /** returns text, with some characters escaped according to XML spec */
  def toString(sb: StringBuilder) =
    error("class Group does not support method toString(StringBuilder)")

  override def text = { // same impl as NodeSeq
    val sb = new StringBuilder()
    val it = elements
    while (it.hasNext)
      sb.append(it.next.text)
    sb.toString()
  }
}