Package com.jcabi.urn

Class URN

  • All Implemented Interfaces:
    Serializable, Comparable<URN>

    @Immutable
    public final class URN
    extends Object
    implements Comparable<URN>, Serializable
    Uniform Resource Name (URN) as in RFC 2141.

    Usage is similar to URI or URL:

     URN urn = new URN("urn:foo:A123,456");
     assert urn.nid().equals("foo");
     assert urn.nss().equals("A123,456");

    NOTICE: the implementation is not fully compliant with RFC 2141. It will become compliant in one of our future versions. Once it becomes fully compliant this notice will be removed.

    Since:
    0.6
    See Also:
    RFC 2141, Serialized Form
    Suppressed Checkstyle violations:
    AbbreviationAsWordInNameCheck (500 lines)
    • Constructor Detail

      • URN

        public URN()
        Public ctor (for JAXB mostly) that creates an "empty" URN.
      • URN

        public URN​(String nid,
                   String nss)
        Public ctor.
        Parameters:
        nid - The namespace ID
        nss - The namespace specific string
    • Method Detail

      • create

        public static URN create​(String text)
        Creates an instance of URN and throws a runtime exception if its syntax is not valid.
        Parameters:
        text - The text of the URN
        Returns:
        The URN created
      • isValid

        public static boolean isValid​(String text)
        Is it a valid URN?
        Parameters:
        text - The text to validate
        Returns:
        Yes of no
      • matches

        public boolean matches​(String pattern)
        Does it match the pattern?
        Parameters:
        pattern - The pattern to match
        Returns:
        Yes of no
      • isEmpty

        public boolean isEmpty()
        Is it empty?
        Returns:
        Yes of no
      • toURI

        public URI toURI()
        Convert it to URI.
        Returns:
        The URI
      • nid

        public String nid()
        Get namespace ID.
        Returns:
        Namespace ID
      • nss

        public String nss()
        Get namespace specific string.
        Returns:
        Namespace specific string
      • params

        public Map<String,​String> params()
        Get all params.
        Returns:
        The params
      • param

        public String param​(String name)
        Get query param by name.
        Parameters:
        name - Name of parameter
        Returns:
        The value of it
      • param

        public URN param​(String name,
                         Object value)
        Add (overwrite) a query param and return a new URN.
        Parameters:
        name - Name of parameter
        value - The value of parameter
        Returns:
        New URN
      • pure

        public URN pure()
        Get just body of URN, without params.
        Returns:
        Clean version of it
      • hasParams

        public boolean hasParams()
        Whether this URN has params?
        Returns:
        Has them?