Class UriUtils

java.lang.Object
dev.metaschema.core.util.UriUtils

public final class UriUtils extends Object
A collection of methods for manipulating uniform resource identifiers (URIs), providing functionality for URI resolution, relativization, and path manipulation.

This utility class supports both local file paths and remote URIs.

  • Method Details

    • toUri

      @NonNull public static URI toUri(@NonNull String location, @NonNull URI baseUri) throws URISyntaxException
      Process a string to a local file path or remote location. If the location is convertible to a URI, return the URI. Normalize the resulting URI with the base URI, if provided.
      Parameters:
      location - a string defining a remote or local file-based location
      baseUri - the base URI to use for URI normalization
      Returns:
      a new URI
      Throws:
      URISyntaxException - if the location string is not convertible to URI
    • relativize

      @NonNull public static URI relativize(URI base, URI other, boolean prepend) throws URISyntaxException
      This function extends the functionality of URI.relativize(URI) by supporting relative reference pathing (e.g., ..), when the prepend parameter is set to true.
      Parameters:
      base - the URI to relativize against
      other - the URI to make relative
      prepend - if true, then prepend relative pathing
      Returns:
      a new relative URI
      Throws:
      URISyntaxException - if any of the URIs are malformed
    • prependRelativePath

      public static String prependRelativePath(String base, String target)
      Get the path of the provided target relative to the path of the provided base.
      Parameters:
      base - the base path to resolve against
      target - the URI to relativize against the base
      Returns:
      the relativized URI