Class UriNormalizationUtil


  • public class UriNormalizationUtil
    extends Object
    Common URI path resolution
    • Method Detail

      • toURI

        public static URI toURI​(String path,
                                boolean trailingSlash)
        Create a URI path from a string. The specified path can not contain relative .. segments or % characters.

        Examples:

        • toUri("/", true) will return a URI with path /
        • toUri("/", false) will return a URI with an empty path /
        • toUri("./", true) will return a URI with path /
        • toUri("./", false) will return a URI with an empty path /
        • toUri("foo/", true) will return a URI with path foo/
        • toUri("foo/", false) will return a URI with an empty path foo
        Parameters:
        path - String to convert into a URI
        trailingSlash - true if resulting URI must end with a '/'
        Throws:
        IllegalArgumentException - if the path contains invalid characters or path segments.
      • normalizeWithBase

        public static URI normalizeWithBase​(URI base,
                                            String segment,
                                            boolean trailingSlash)
        Resolve a string path against a URI base. The specified path can not contain relative .. segments or % characters. Relative paths will be resolved against the specified base URI. Absolute paths will be normalized and returned.

        Examples:

        • normalizeWithBase(new URI("/"), "example", true) will return a URI with path /example/
        • normalizeWithBase(new URI("/"), "example", false) will return a URI with an empty path /example
        • normalizeWithBase(new URI("/"), "/example", true) will return a URI with path /example/
        • normalizeWithBase(new URI("/"), "/example", false) will return a URI with an empty {@literal /example
        • {@code normalizeWithBase(new URI("/prefix/"), "example", true)} will return a URI with path {@literal /prefix/example/}
        • {@code normalizeWithBase(new URI("/prefix/"), "example", false)} will return a URI with an empty path {@literal /prefix/example}
        • {@code normalizeWithBase(new URI("/prefix/"), "/example", true)} will return a URI with path {@literal /example/}
        • {@code normalizeWithBase(new URI("/prefix/"), "/example", false)} will return a URI with an empty path {@literal /example}
        • {@code normalizeWithBase(new URI("foo/"), "example", true)} will return a URI with path {@literal foo/example/}
        • {@code normalizeWithBase(new URI("foo/"), "example", false)} will return a URI with an empty path {@literal foo/example}
        • {@code normalizeWithBase(new URI("foo/"), "/example", true)} will return a URI with path {@literal /example/}
        • {@code normalizeWithBase(new URI("foo/"), "/example", false)} will return a URI with an empty path {@literal /example}
        Parameters:
        base - URI to resolve relative paths. Use toURI(String, boolean) to construct this parameter.
        segment - Relative or absolute path
        trailingSlash - true if resulting URI must end with a '/'
        Throws:
        IllegalArgumentException - if the path contains invalid characters or path segments.