Class IRIx

Direct Known Subclasses:

public abstract class IRIx extends Object
Support for RFC3986 IRIs.

The class IRIx is an abstraction layer; a provider is needed to give an implementation. A provider is selected at start-up and is not expected to change while the system is running.

Use IRIs.reference(java.lang.String) to check a string is suitable for us in RDF.

See Also:
  • Method Details

    • create

      public static IRIx create(String iri) throws IRIException
      Create an IRIx without resolving the iri. This operation may throw an IRIException.

      See IRIs.resolve(String) to create an absolute IRI, resolving against the system base if necessary.

      See IRIs.check(String) to check a string is an absolute URI and is suitable for use in RDF.

      See IRIs.reference(String) when the string is an absolute URI and should not be resolved against local system base (e.g. it was passed in from outside) to create an IRIx that is suitable for use in RDF.

    • createAny

      public static IRIx createAny(String iri)
      Create an IRIx for any string. It returns a IRIx holder and does no checking whatsoever. Whether the IRI "works" is down to care by the application.
    • isAbsolute

      public abstract boolean isAbsolute()
      An absolute URI is one with a URI scheme and without a fragment. The other components, host (authority), path, and query, are optional.

      absolute-URI = scheme ":" hier-part [ "?" query ]

      Beware of the meaning : http:abc is an absolute URI - it has only a schema and a path without a root.

      Note that a URI can be both "not absolute" and "not relative", e.g. http://example/path#fragment.

      Beware that RFC 2396 section 3.1 has a different definition, where the scheme is required but a fragment may be present.

      See isReference() for testing whether a URI is suitable for use in RDF.

    • isRelative

      public abstract boolean isRelative()
      A relative URI is one without a scheme, and maybe without some of the other parts.

      Often it is just the path part.

      See isReference() for testing whether a URI is suitable for use in RDF.

      Note that a URI can be both "not absolute" and "not relative", e.g. http://example/path#fragment.

    • hasScheme

      public abstract boolean hasScheme(String scheme)
      Test whether the IRI has the given scheme name.

      The scheme name should be lowercase.

    • scheme

      public abstract String scheme()
      Return the IRI scheme, if known.

      Returns null for "no scheme" (relative IRI).

    • isReference

      public abstract boolean isReference()
      An RDF Reference is an URI which has scheme. If it is hierarchical, it should have a non-empty host authority. It may have a query component and may have a fragment component. This not a term in RFC 3986 and it is not the same as "absolute URI". This is a change from RFC 2396 where an absolute URI means "has scheme".

      In RDF data it is a useful concept. It is either an absolute URI, but if it is hierarchical, it must have a host.


      • urn:abc:def
      • urn:abc:def#frag
      but not
      • http:abc -- no host authority; HTTP is a hierarchical URI scheme
      • http:// -- the http(s) URI scheme requires the host to be not empty if there is an authority component.

      In practical terms:

      • It has a scheme name.
      • It does not have user info ("user:password@")
      • It can have a fragment.
      • If it is an HTTP URI:
        • It has a host authority, that is, a "//" section
        • It should have a path (starting "/" after the host authority) but this is not required.
      • If it is a URN (RFC8141), which is a "rootless URI" with no "//" part:
    • resolve

      public abstract IRIx resolve(String other)
      Try to resolve a string against this IRI as base. This call is "base.resolver(possibleRelativeIRI)". Throw IRIException if the string does not conform to the IRI grammar.
    • resolve

      public abstract IRIx resolve(IRIx other)
      Try to resolve a string against this IRI as base. Throw IRIException if the string does not conform to the IRI grammar. Return the original IRIx if there is no change.
    • normalize

      public abstract IRIx normalize()
    • relativize

      public abstract IRIx relativize(IRIx other)
      Return (if possible), an IRI that is relative to the base argument. If this IRI is a relative path, this is returned unchanged.

      The base ("this" object) must have a scheme, have no fragment and no query string. Only the path name is made relative.

      If no relative IRI can be found, return null.

    • hasViolations

      public abstract boolean hasViolations()
      Does this IRIx have any warnings and errors that are not syntax errors, for example, from URI scheme checks.
    • handleViolations

      public abstract void handleViolations(BiConsumer<Boolean,String> violation)
      Handle violations by sending a boolean, indicating whether this is an error (true) or a warning (false), and string message to a handler.
    • str

      public String str()
      Return the URI as string. This has a stronger contract than "toString". "Object.toString" is a user readable string (e.g. it might add enclosing "<>" or show the parsed structure of the IRI) whereas asString() is by contract the string that comprises the IRI. The string returned may be the normalized form. It is guaranteed to be usable as string in other API calls that expect a IRI in string form if the original input was a legal IRI by the RFC grammar and any additional scheme-specific rules the IRI provider enforces.
    • getImpl

      public abstract Object getImpl()
      Return the implementation object of the provider. The class of the object depends on the provider.
    • hashCode

      public abstract int hashCode()
      hashCode in class Object
    • equals

      public abstract boolean equals(Object other)
      equals in class Object
    • toString

      public String toString()
      User readable form. Not guaranteed to be usable as a string in other API calls. Use str() to get a string form that represents the IRI in the RFC grammar.
      toString in class Object