org.eclipse.rdf4j.model.util

## Class URIUtil

- java.lang.Object
- - org.eclipse.rdf4j.model.util.URIUtil

-     public class URIUtil
      extends Object

  Utility functions for working with `URIs`.
  Author:
    Arjohn Kampman

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `URIUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `getLocalNameIndex(String uri)` Finds the index of the first local name character in an (non-relative) URI.
    `static boolean` | `isCorrectURISplit(String namespace, String localName)` Checks whether the URI consisting of the specified namespace and local name has been split correctly according to the URI splitting rules specified in `URI`.
    `static boolean` | `isValidURIReference(String uriRef)` Verifies that the supplied string is a valid RDF (1.0) URI reference, as defined in section 6.4 of the RDF Concepts and Abstract Syntax specification (RDF 1.0 Recommendation of February 10, 2004).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### URIUtil

          public URIUtil()

  - ### Method Detail

    - #### getLocalNameIndex

          public static int getLocalNameIndex(String uri)

      Finds the index of the first local name character in an (non-relative) URI. This index is determined by the following the following steps:
      - Find the first occurrence of the '#' character,
      - If this fails, find the last occurrence of the '/' character,
      - If this fails, find the last occurrence of the ':' character.
      - Add `1`to the found index and return this value.``
      Note that the third step should never fail as every legal (non-relative) URI contains at least one ':' character to seperate the scheme from the rest of the URI. If this fails anyway, the method will throw an `IllegalArgumentException`.
      Parameters:
        `uri` - A URI string.
      Returns:
        The index of the first local name character in the URI string. Note that this index does not reference an actual character if the algorithm determines that there is not local name. In that case, the return index is equal to the length of the URI string.
      Throws:
        `IllegalArgumentException` - If the supplied URI string doesn't contain any of the separator characters. Every legal (non-relative) URI contains at least one ':' character to seperate the scheme from the rest of the URI.

    - #### isCorrectURISplit

          public static boolean isCorrectURISplit(String namespace,
                                                  String localName)

      Checks whether the URI consisting of the specified namespace and local name has been split correctly according to the URI splitting rules specified in `URI`.
      Parameters:
        `namespace` - The URI's namespace, must not be `null`.
        `localName` - The URI's local name, must not be `null`.
      Returns:
        `true` if the specified URI has been correctly split into a namespace and local name, `false` otherwise.
      See Also:
        `URI`, `getLocalNameIndex(String)`

    - #### isValidURIReference

          public static boolean isValidURIReference(String uriRef)

      Verifies that the supplied string is a valid RDF (1.0) URI reference, as defined in section 6.4 of the RDF Concepts and Abstract Syntax specification (RDF 1.0 Recommendation of February 10, 2004).

      An RDF URI reference is valid if it is a Unicode string that:

      - does not contain any control characters ( #x00 - #x1F, #x7F-#x9F)
      - and would produce a valid URI character sequence (per RFC2396 , section 2.1) representing an absolute URI with optional fragment identifier when subjected to the encoding described below
      The encoding consists of:
      1. encoding the Unicode string as UTF-8, giving a sequence of octet values.
      2. %-escaping octets that do not correspond to permitted US-ASCII characters.
      Parameters:
        `uriRef` - a string representing an RDF URI reference.
      Returns:
        `true` iff the supplied string is a syntactically valid RDF URI reference, `false` otherwise.
      See Also:
        section 6.4 of the RDF Concepts and Abstract Syntax specification, RFC 3986, RFC 2396

Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.