Class UriUtil

java.lang.Object
org.jhotdraw8.base.net.UriUtil

public class UriUtil extends Object
UriUtil.
Author:
Werner Randelshofer
  • Method Details

    • getName

      public static String getName(@NonNull URI uri)
      Returns the name of an URI for display in the title bar of a window.

      If the URI is a file URI, then displays the file name followed by the path to the file. If the file is inside the user home directory, only the relative path is shown.

      Examples:

           uri = /User/me/Desktop/Hello.txt
           ⊢ title = Hello.txt [~/Desktop]
      
           uri = /User/notme/Desktop/Hello.txt
           ⊢ title = Hello.txt [/User/notme/Desktop]
      
           uri = /Volumes/NetworkDrive/Hello.txt
           ⊢ title = Hello.txt [/Volumes/NetworkDrive]
       
      Parameters:
      uri - the uri
      Returns:
      the name
    • addQuery

      public static URI addQuery(@NonNull URI uri, @Nullable String key, @Nullable String value)
      Adds a query. If a query is already present, adds it after a '&' character. Both, the key, and the value may not include the characters '&' and '='.
      Parameters:
      uri - an uri
      key - the key
      value - the value
      Returns:
      the updated query
    • addQuery

      public static URI addQuery(@NonNull URI uri, @Nullable String query)
      Adds a query. If a query is already present, adds it after a '&' character. The query may not include the characters '&' or '='.
      Parameters:
      uri - an uri
      query - the query
      Returns:
      the updated query
    • setQuery

      public static URI setQuery(URI uri, String query)
      Sets the query on the specified URI. If a query is already present, it is removed.
      Parameters:
      uri - an uri
      query - the query
      Returns:
      the update uri
    • clearQuery

      public static URI clearQuery(URI uri)
    • parseQuery

      public static @NonNull Map<String,String> parseQuery(@NonNull URI uri)
      Parses the query of the URI. Assumes that the query consists of '&'-separated, key '=' value pairs.
      Parameters:
      uri - an URI
      Returns:
      a map
    • relativize

      public static @NonNull URI relativize(@Nullable URI base, @NonNull URI uri)
    • absolutize

      public static @NonNull URI absolutize(@Nullable URI base, @NonNull URI uri)
      Absolutizes an URI.
      Parameters:
      base - the base URI
      uri - an URI that is relative to the base URI
      Returns:
      the absolutized URI
    • getParent

      public static @NonNull URI getParent(@NonNull URI uri)