com.github.fge.jsonschema.core.util
Class URIUtils

java.lang.Object
  extended by com.github.fge.jsonschema.core.util.URIUtils

public final class URIUtils
extends Object

Utility class for URI normalization

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 Functions to perform these normalizations.

It also contains ArgumentCheckers to detect whether URIs are well formed given a defined requirement, and static methods calling these argument checkers as well.

See Also:
ArgumentChecker, Function, Registry

Method Summary
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 Function<URI,URI> schemaURINormalizer()
          Schema URI normalizer
static ArgumentChecker<String> schemeChecker()
          Return an argument checker to check the correctness of a URI scheme
static Function<String,String> schemeNormalizer()
          Return a Function performing URI scheme normalization, as per RFC 3986, section 3.1
static Function<URI,URI> uriNormalizer()
          Full URI normalizer, as per RFC 3986
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

schemeNormalizer

public static Function<String,String> schemeNormalizer()
Return a Function performing URI scheme normalization, as per RFC 3986, section 3.1

Returns:
a function

normalizeScheme

public static String normalizeScheme(@Nullable
                                     String scheme)
Normalize a scheme according to RFC 3986, section 3.1

Parameters:
scheme - the scheme
Returns:
the normalized scheme

uriNormalizer

public static Function<URI,URI> uriNormalizer()
Full URI normalizer, as per RFC 3986

Returns:
a full URI normalizer as a Function

normalizeURI

public static URI normalizeURI(@Nullable
                               URI uri)
Fully normalize a URI as per RFC 3986

Parameters:
uri - the URI
Returns:
the fully normalized URI
See Also:
uriNormalizer()

schemaURINormalizer

public static Function<URI,URI> schemaURINormalizer()
Schema URI normalizer

This performs the same normalization as uriNormalizer(), except it will also append an empty fragment if no fragment is present.

Returns:
a schema URI normalizer as a Function

normalizeSchemaURI

public static URI normalizeSchemaURI(@Nullable
                                     URI uri)
Perform schema URI normalization

Parameters:
uri - the URI
Returns:
the normalized schema URI
See Also:
schemaURINormalizer()

schemeChecker

public static ArgumentChecker<String> schemeChecker()
Return an argument checker to check the correctness of a URI scheme

Returns:
an argument checker

checkScheme

public static void checkScheme(String scheme)
Check whether a given string as an argument is a legal URI scheme

Parameters:
scheme - the string to check
See Also:
schemeChecker()

pathURIChecker

public static ArgumentChecker<URI> pathURIChecker()
Argument checker to check whether a URI is a valid path URI

A URI is a valid path URI if all the following conditions are met:

Returns:
an argument checker

checkPathURI

public static void checkPathURI(URI uri)
Check whether a URI is a valid path URI

Parameters:
uri - the URI to check
See Also:
pathURIChecker()

schemaURIChecker

public static ArgumentChecker<URI> schemaURIChecker()
Argument checker for a schema URI

A URI is a valid schema URI if all of the following conditions are true:

Returns:
an argument checker

checkSchemaURI

public static void checkSchemaURI(URI uri)
Check that a URI is a valid schema URI

Parameters:
uri - the URI to check
See Also:
schemaURIChecker()