Package com.nimbusds.oauth2.sdk.util
Class URIUtils
- java.lang.Object
-
- com.nimbusds.oauth2.sdk.util.URIUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
ensureSchemeIsHTTPS(URI uri)
Ensures the scheme of the specified URI is https.static void
ensureSchemeIsHTTPSorHTTP(URI uri)
Ensures the scheme of the specified URI is https or http.static void
ensureSchemeIsNotProhibited(URI uri, Set<String> prohibitedURISchemes)
Ensures the scheme of the specified URI is not prohibited.static URI
getBaseURI(URI uri)
Gets the base part (schema, host, port and path) of the specified URI.static String
joinPathComponents(String c1, String c2)
Joins two path components.static String
prependLeadingSlashIfMissing(String s)
Prepends a leading slash `/` if missing to the specified string.static URI
prependPath(URI uri, String pathComponent)
Prepends the specified path component to a URI.static URI
removeTrailingSlash(URI uri)
Removes the trailing slash ("/") from the specified URI, if present.static String
stripLeadingSlashIfPresent(String s)
Strips any leading slashes '/' if present from the specified string.static URI
stripQueryString(URI uri)
Strips the query string from the specified URI.static List<String>
toStringList(Collection<URI> uriList)
Returns a string list representation of the specified URI collection.static List<String>
toStringList(Collection<URI> uriList, boolean ignoreNulls)
Returns a string list representation of the specified URI collection.
-
-
-
Method Detail
-
getBaseURI
public static URI getBaseURI(URI uri)
Gets the base part (schema, host, port and path) of the specified URI.- Parameters:
uri
- The URI. May benull
.- Returns:
- The base part of the URI,
null
if the original URI isnull
or doesn't specify a protocol.
-
prependPath
public static URI prependPath(URI uri, String pathComponent)
Prepends the specified path component to a URI. The prepended and any existing path component are always joined with a single slash ('/') between them- Parameters:
uri
- The URI,null
if not specified.pathComponent
- The path component to prepend,null
if not specified.- Returns:
- The URI with prepended path component,
null
if the original URI wasn't specified.
-
prependLeadingSlashIfMissing
public static String prependLeadingSlashIfMissing(String s)
Prepends a leading slash `/` if missing to the specified string.- Parameters:
s
- The string,null
if not specified.- Returns:
- The string with leading slash,
null
if not originally specified.
-
stripLeadingSlashIfPresent
public static String stripLeadingSlashIfPresent(String s)
Strips any leading slashes '/' if present from the specified string.- Parameters:
s
- The string,null
if not specified.- Returns:
- The string with no leading slash,
null
if not originally specified.
-
joinPathComponents
public static String joinPathComponents(String c1, String c2)
Joins two path components. If the two path components are notnull
or empty they are joined so that there is only a single slash ('/') between them.- Parameters:
c1
- The first path component,null
if not specified.c2
- The second path component,null
if not specified.- Returns:
- The joined path components,
null
if both are not specified, or if one isnull
the other unmodified.
-
stripQueryString
public static URI stripQueryString(URI uri)
Strips the query string from the specified URI.- Parameters:
uri
- The URI. May benull
.'- Returns:
- The URI with stripped query string,
null
if the original URI isnull
or doesn't specify a protocol.
-
removeTrailingSlash
public static URI removeTrailingSlash(URI uri)
Removes the trailing slash ("/") from the specified URI, if present.- Parameters:
uri
- The URI. May benull
.- Returns:
- The URI with no trailing slash,
null
if the original URI isnull
.
-
ensureSchemeIsHTTPS
public static void ensureSchemeIsHTTPS(URI uri)
Ensures the scheme of the specified URI is https.- Parameters:
uri
- The URI to check,null
if not specified.- Throws:
IllegalArgumentException
- If the URI is specified and the scheme is not https.
-
ensureSchemeIsHTTPSorHTTP
public static void ensureSchemeIsHTTPSorHTTP(URI uri)
Ensures the scheme of the specified URI is https or http.- Parameters:
uri
- The URI to check,null
if not specified.- Throws:
IllegalArgumentException
- If the URI is specified and the scheme is not https or http.
-
ensureSchemeIsNotProhibited
public static void ensureSchemeIsNotProhibited(URI uri, Set<String> prohibitedURISchemes)
Ensures the scheme of the specified URI is not prohibited.- Parameters:
uri
- The URI to check,null
if not specified.prohibitedURISchemes
- The prohibited URI schemes (should be in lower case), empty ornull
if not specified.- Throws:
IllegalArgumentException
- If the URI is specified and its scheme is prohibited.
-
toStringList
public static List<String> toStringList(Collection<URI> uriList)
Returns a string list representation of the specified URI collection. Collection items that arenull
are not returned.- Parameters:
uriList
- The URI collection,null
if not specified.- Returns:
- The string list,
null
if not specified.
-
toStringList
public static List<String> toStringList(Collection<URI> uriList, boolean ignoreNulls)
Returns a string list representation of the specified URI collection.- Parameters:
uriList
- The URI collection,null
if not specified.ignoreNulls
-true
to not includenull
values.- Returns:
- The string list,
null
if not specified.
-
-