package scala.xml
package dtd
abstract class ExternalID extends parsing.TokenTests
{
  def quoted(s: String) = {
    val c = if (s contains '"') '\'' else '"'
    c + s + c
  }
  
  
  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
}
case class SystemID(systemId: String) extends ExternalID {
  val publicId = null
  if (!checkSysID(systemId))
    throw new IllegalArgumentException("can't use both \" and ' in systemId")
}
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")
  
  def label = "#PI"
  
  def attribute = Node.NoAttributes
  
  def child = Nil
}