Class XMLDocumentIdentifier

  • All Implemented Interfaces:
    Formattable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<XMLDocumentIdentifier>

    public class XMLDocumentIdentifier
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable, java.lang.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  http://www.w3.org/TR/xml11/#NT-ExternalID
    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.)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Set<java.lang.Character> publicIdAlphabet
      Contains all characters allowed in public IDs.
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLDocumentIdentifier​(@Opt java.lang.String publicId, java.lang.String systemId)
      Create an instance with given systemId and publicId.
      XMLDocumentIdentifier​(@Opt java.lang.String publicId, java.net.URI systemId)
      Currently for convenience only, executes "systemId.toString()".
      XMLDocumentIdentifier​(@Opt java.lang.String publicId, java.net.URL systemId)
      Currently for convenience only, executes "systemId.toString()".
      XMLDocumentIdentifier​(java.lang.String systemId)
      Create an instance with given systemId and a publicId==null
    • Field Detail

      • publicIdAlphabet

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

      • XMLDocumentIdentifier

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

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

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

        public XMLDocumentIdentifier​(@Opt
                                     @Opt java.lang.String publicId,
                                     java.net.URL systemId)
        Currently for convenience only, executes "systemId.toString()".
    • Method Detail

      • getPublicId

        public final java.lang.String getPublicId()
        Evident
      • getSystemId

        public final java.lang.String getSystemId()
        Evident
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
        Returns:
        true iff
        • the argument "o" is an XMLDocumentIdentifier,
        • at least one publicId is present, and both are equal, or
        • of no public Id 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 ic) at two different file locations (system id).
            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).
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.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.  http://www.w3.org/TR/xml11/#NT-ExternalID ATTENTION: both ids may contain EITHER single quote OR double quote, but not both. That will result in an IllegalArgumentException.
        Overrides:
        toString in class java.lang.Object
      • 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 java.lang.Comparable<XMLDocumentIdentifier>
      • isValidSystemId

        public static boolean isValidSystemId​(java.lang.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 java.lang.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.