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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.xml.dtd ;
import scala.collection.Map ;
abstract class Decl ;
abstract class MarkupDecl extends Decl ;
/** an element declaration
*/
case class ElemDecl(name: String, contentModel: ContentModel.RegExp, attList: AttListDecl) extends MarkupDecl {
//def mixed = ; // to do
def setAttList(nAttList:AttListDecl) =
ElemDecl(name, contentModel, nAttList);
} // ElemDecl
case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl;
/** an attribute declaration. at this point, the tpe is a string. Future
* versions might provide a way to access the attribute types more
* directly.
*/
case class AttrDecl( name:String, tpe:String, default:DefaultDecl ) {
final override def toString() = {
val sb = new StringBuffer("AttrDecl(");
sb.append('"');
sb.append( name );
sb.append('"');
sb.append(',');
sb.append('"');
sb.append( tpe );
sb.append('"');
sb.append(',');
sb.append(default.toString());
sb.append(')');
sb.toString();
}
}
class EntityDecl extends MarkupDecl;
/** an entity declaration */
case class ParsedEntityDecl( name:String, entdef:EntityDef )
extends EntityDecl;
case class ParameterEntityDecl(name: String, entdef: EntityDef)
extends EntityDecl;
class EntityDef;
case class IntDef(value:String) extends EntityDef {
private def validateValue(): Unit = {
var tmp = value;
var ix = tmp.indexOf('%');
while( ix != -1) {
val iz = tmp.indexOf(';', ix);
if(iz == -1 && iz == ix + 1)
error("no % allowed in entity value, except for parameter-entity-references");
else {
val n = tmp.substring(ix, iz);
if( !Utility.isName( n ))
throw new IllegalArgumentException("ent must be an XML Name");
tmp = tmp.substring(iz+1, tmp.length());
ix = tmp.indexOf('%');
}
}
}
validateValue();
}
case class ExtDef(extID:ExternalID) extends EntityDef;
/** an entity declaration */
case class UnparsedEntityDecl( name:String, extID:ExternalID, notation:String ) extends EntityDecl;
/** a notation declaration */
case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl;
/** a parsed entity reference */
case class PEReference(ent:String) extends MarkupDecl {
if( !Utility.isName( ent ))
throw new IllegalArgumentException("ent must be an XML Name");
final override def toString() = "%"+ent+";"
}
// default declarations for attributes
class DefaultDecl ;
case object REQUIRED extends DefaultDecl {
final override def toString() = "REQUIRED";
}
case object IMPLIED extends DefaultDecl {
final override def toString() = "IMPLIED";
}
case class DEFAULT(fixed:boolean, attValue:String) extends DefaultDecl {
final override def toString() = {
val sb = new StringBuffer("DEFAULT(");
sb.append( fixed );
sb.append(',');
Utility.appendEscapedQuoted( attValue, sb );
sb.append(')');
sb.toString()
}
}
|