Class XMLDocumentIdentifier

All Implemented Interfaces:
Formattable, Serializable, Comparable<XMLDocumentIdentifier>

public class XMLDocumentIdentifier extends Object implements Serializable, Comparable<XMLDocumentIdentifier>, Formattable
Realizes a pair of identifiers ("system" and "public") as often required to identify an XML document.
The "system" part is required, the "public" part is optional.

Some documentation on its role in XML texts (for entity identification) is at
The structure of a "system id" is meant to be an URI.
(The XML standard defines "SystemLiteral" as any character sequence framed by double or single quotes, not containing this kind of quotes.)
The structure of an "public id" is not defined here. TRADITIONALLY it is a "Formal Public Identifier" as defined in SGML (= ISO 8879:1986).
(The XML standard defines "PublicLiteral" similar to SystemLiteral, but with a restricted character set.)

Empty strings are NOT forbidden by the XML spec. They seem sensible only for a system identifier in presence of a public identifier. But the XML spec does not forbid »PUBLIC "" ""«. This code follows that (akward) specification.

See Also:
  • Field Details

    • systemLiteral

      public static final Format systemLiteral
    • publicLiteral

      public static final Format publicLiteral
    • publicIdAlphabet

      public static final Set<Character> publicIdAlphabet
      Contains all characters allowed in public IDs. See definition "PubidChar" in the XML standard
  • Constructor Details

    • XMLDocumentIdentifier

      public XMLDocumentIdentifier(String systemId)
      Create an instance with given systemId and a publicId==null
      IllegalArgumentException - iff systemId is null.
    • XMLDocumentIdentifier

      public XMLDocumentIdentifier(@Opt @Opt String publicId, String systemId)
      Create an instance with given systemId and publicId.
      IllegalArgumentException - iff systemId is null.
    • XMLDocumentIdentifier

      public XMLDocumentIdentifier(@Opt @Opt String publicId, URI systemId)
      Currently for convenience only, executes "systemId.toString()".
    • XMLDocumentIdentifier

      public XMLDocumentIdentifier(@Opt @Opt String publicId, URL systemId)
      Currently for convenience only, executes "systemId.toString()".
  • Method Details

    • getPublicId

      public final String getPublicId()
    • getSystemId

      public final String getSystemId()
    • equals

      public boolean equals(Object o)
      equals in class Object
      true iff
      • the argument "o" is an XMLDocumentIdentifier,
      • at least one publicId is present, and both are equal, or
      • or no publicId is present and the systemIds are equal.
        • IMPORTANT: Other implementations of the XML specification may come to other conclusions; therefore it is possibly not portable to hold a document which is meant to be identical (same public id) at two different file locations (system ids).
          Public Ids need not to be injectiv: A DOI, a URI and another URI can point to the same journal article and thus to the same disk file (system id).
    • equals

      protected boolean equals(XMLDocumentIdentifier x)
      Compares this to another. @see #equals(Object).
    • hashCode

      public int hashCode()
      Is defined according to equality. @see #equals(Object).
      hashCode in class Object
    • toString

      public String toString()
      Create string representation needed for XML headers conformant to the standard. This format is rather awkward:
      (a) if there is NO public Id, then print "SYSTEM <systemId>"
      (b) if there IS a public Id, print "PUBLIC <publicId> <systemId>"
      cf. ATTENTION: both ids may contain EITHER single quote OR double quote, but not both. That will result in an IllegalArgumentException.
      toString in class Object
    • format

      public Format format()
      Create Format representation needed for XML headers.
      Specified by:
      format in interface Formattable
      a format that represents this object in a pretty-printable way
    • compareTo

      public int compareTo(XMLDocumentIdentifier x)
      Auxiliary comparison method, as needed for "sorted Sets" etc. Respects equals(Object). First compare the publicIds and, if equal, then the systemIds. An object with publicId==null is smaller than one with publicId!=null.
      Specified by:
      compareTo in interface Comparable<XMLDocumentIdentifier>
    • isValidSystemId

      public static boolean isValidSystemId(String systemId)
      Check if string is a valid system id. Checks only that not both, single and double quote, are contained. This is not done automatically, e.g. on construction.
    • isValidPublicId

      public static boolean isValidPublicId(@Opt @Opt String publicId)
      Check if string is a valid public id. This is not done automatically, e.g. on construction. Checks only whether all contained characters are allowed. null passes the test.