blob: 880633d860c70e3c1be869d4b6106c4b499dfa3e (
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
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
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala
package xml
package dtd
/** an ExternalIDs - either PublicID or SystemID
*
* @author Burak Emir
*/
sealed abstract class ExternalID extends parsing.TokenTests {
def quoted(s: String) = {
val c = if (s contains '"') '\'' else '"'
c + s + c
}
// public != null: PUBLIC " " publicLiteral " " [systemLiteral]
// public == null: SYSTEM " " systemLiteral
override def toString(): String = {
lazy val quotedSystemLiteral = quoted(systemId)
lazy val quotedPublicLiteral = quoted(publicId)
if (publicId == null) "SYSTEM " + quotedSystemLiteral
else "PUBLIC " + quotedPublicLiteral +
(if (systemId == null) "" else " " + quotedSystemLiteral)
}
def buildString(sb: StringBuilder): StringBuilder =
sb.append(this.toString())
def systemId: String
def publicId: String
}
/** a system identifier
*
* @author Burak Emir
* @param systemId the system identifier literal
*/
case class SystemID(systemId: String) extends ExternalID {
val publicId = null
if (!checkSysID(systemId))
throw new IllegalArgumentException("can't use both \" and ' in systemId")
}
/** a public identifier (see http://www.w3.org/QA/2002/04/valid-dtd-list.html).
*
* @author Burak Emir
* @param publicId the public identifier literal
* @param systemId (can be null for notation pubIDs) the system identifier literal
*/
case class PublicID(publicId: String, systemId: String) extends ExternalID {
if (!checkPubID(publicId))
throw new IllegalArgumentException("publicId must consist of PubidChars")
if (systemId != null && !checkSysID(systemId))
throw new IllegalArgumentException("can't use both \" and ' in systemId")
/** the constant "#PI" */
def label = "#PI"
/** always empty */
def attribute = Node.NoAttributes
/** always empty */
def child = Nil
}
/** A marker used when a `DocType` contains no external id.
*
* @author Michael Bayne
*/
object NoExternalID extends ExternalID {
val publicId = null
val systemId = null
override def toString = ""
}
|