summaryrefslogtreecommitdiff
path: root/src/library/scala/xml/dtd/DocType.scala
blob: d1110e5ad7e37c489b2c05d1c9e2cf234f7374e6 (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
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2006, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id$


package scala.xml.dtd;

import scala.runtime.compat.StringBuilder

/** an XML node for document type declaration
 *
 * @author Burak Emir
 * @param  target name of this DOCTYPE
 * @param  extID  None, or Some(external ID of this doctype)
 * @param  intSubset sequence of internal subset declarations
**/

case class DocType( name:String, extID:ExternalID, intSubset:Seq[dtd.Decl]) {

  if( !Utility.isName( name ) )
    throw new IllegalArgumentException(name+" must be an XML Name");

  /** hashcode for this processing instruction */
  final override def hashCode() = name.hashCode() + 7 * extID.hashCode() + 41*intSubset.toList.hashCode();

  /** returns "<!DOCTYPE + name + extID? + ("["+intSubSet+"]")? >" */
  final override def toString() = {
    val sb = new StringBuilder().append("<!DOCTYPE ");
    sb.append( name );
    sb.append(' ');
    sb.append(extID.toString());
    if( intSubset.length > 0 ) {
      sb.append('[');
      for( val d <- intSubset ) {
        sb.append( d.toString() );
      }
      sb.append(']');
    }
    sb.append('>');
    sb.toString();
  }
}