public final class URIUtils extends Object
RFC 3986, sections 3.1 and 3.2.2, says that normalized schemes and
hostnames are normalized to lowercase; unfortunately, Java's URI.normalize()
does not go as far as the RFC says, and leaves the scheme
and host parts of the URI intact.
This class provides methods to fully normalize both schemes and URIs,
and Function
s to perform these normalizations.
It also contains ArgumentChecker
s to detect whether URIs are well
formed given a defined requirement, and static methods calling these
argument checkers as well.
ArgumentChecker
,
Function
,
Registry
Modifier and Type | Method and Description |
---|---|
static void |
checkPathURI(URI uri)
Check whether a URI is a valid path URI
|
static void |
checkSchemaURI(URI uri)
Check that a URI is a valid schema URI
|
static void |
checkScheme(String scheme)
Check whether a given string as an argument is a legal URI scheme
|
static URI |
normalizeSchemaURI(URI uri)
Perform schema URI normalization
|
static String |
normalizeScheme(String scheme)
Normalize a scheme according to RFC 3986, section 3.1
|
static URI |
normalizeURI(URI uri)
Fully normalize a URI as per RFC 3986
|
static ArgumentChecker<URI> |
pathURIChecker()
Argument checker to check whether a URI is a valid path URI
|
static ArgumentChecker<URI> |
schemaURIChecker()
Argument checker for a schema URI
|
static com.google.common.base.Function<URI,URI> |
schemaURINormalizer()
Schema URI normalizer
|
static ArgumentChecker<String> |
schemeChecker()
Return an argument checker to check the correctness of a URI scheme
|
static com.google.common.base.Function<String,String> |
schemeNormalizer()
Return a
Function performing URI scheme normalization, as per RFC
3986, section 3.1 |
static com.google.common.base.Function<URI,URI> |
uriNormalizer()
Full URI normalizer, as per RFC 3986
|
public static com.google.common.base.Function<String,String> schemeNormalizer()
Function
performing URI scheme normalization, as per RFC
3986, section 3.1public static String normalizeScheme(@Nullable String scheme)
scheme
- the schemepublic static com.google.common.base.Function<URI,URI> uriNormalizer()
Function
public static URI normalizeURI(@Nullable URI uri)
uri
- the URIuriNormalizer()
public static com.google.common.base.Function<URI,URI> schemaURINormalizer()
This performs the same normalization as uriNormalizer()
,
except it will also append an empty fragment if no fragment is present.
Function
public static URI normalizeSchemaURI(@Nullable URI uri)
uri
- the URIschemaURINormalizer()
public static ArgumentChecker<String> schemeChecker()
public static void checkScheme(String scheme)
scheme
- the string to checkschemeChecker()
public static ArgumentChecker<URI> pathURIChecker()
A URI is a valid path URI if all the following conditions are met:
/
.public static void checkPathURI(URI uri)
uri
- the URI to checkpathURIChecker()
public static ArgumentChecker<URI> schemaURIChecker()
A URI is a valid schema URI if all of the following conditions are true:
public static void checkSchemaURI(URI uri)
uri
- the URI to checkschemaURIChecker()