Class UrlHelper


  • public final class UrlHelper
    extends Object
    Provides some utility methods for url / path related data
    Author:
    Oliver Wolff
    • Method Detail

      • addTrailingSlashToUrl

        public static String addTrailingSlashToUrl​(String url)
        Parameters:
        url - to be adapted
        Returns:
        the given url if it already suffixed with '/' or null / empty. The given url suffixed with '/' otherwise
      • removeTrailingSlashesFromUrl

        public static String removeTrailingSlashesFromUrl​(String url)
        Parameters:
        url - to be adapted
        Returns:
        the given url if it is not suffixed with '/' or null / empty. The given url '/' removed otherwise. Multiple trailing slashes will be removed as well
      • addPrecedingSlashToPath

        public static String addPrecedingSlashToPath​(String path)
        Parameters:
        path - to be adapted
        Returns:
        the given path if it already prefixed with '/'. The given path prefixed with '/' otherwise. In case of being null or empty it will return "/"
      • removePrecedingSlashFromPath

        public static String removePrecedingSlashFromPath​(String path)
        Parameters:
        path -
        Returns:
        the given path if it is not suffixed with '/' or null / empty. The given path '/' removed otherwise. Multiple preceding slashes will be removed as well
      • splitPath

        public static List<String> splitPath​(String pathString)
        Split the given path String in a unified view with a list of String. The individual path-elements are implicitly trimmed
        Parameters:
        pathString - if it is null or empty an empty List will be returned
        Returns:
        the list view on the path elements. never null but may be empty
      • tryParseUri

        public static Optional<URI> tryParseUri​(String uri)
        Parameters:
        uri - value to be verified if it is a valid URI.
        Returns:
        URI object, if the given value is a valid URI.
      • isValidUri

        public static boolean isValidUri​(String uri)
        Parameters:
        uri - value to be verified if it is a valid URI.
        Returns:
        true, if the given value is a valid URI. False otherwise.