Class MediaTypeSupport
java.lang.Object
net.shibboleth.utilities.java.support.net.MediaTypeSupport
public final class MediaTypeSupport extends Object
Support methods for Guava
MediaType
.-
Field Summary
Fields Modifier and Type Field Description private static Function<MediaType,MediaType>
STRIP_PARAMS
Function to strip MediaType parameters. -
Constructor Summary
Constructors Modifier Constructor Description private
MediaTypeSupport()
Constructor. -
Method Summary
Modifier and Type Method Description static boolean
validateContentType(String contentType, Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy)
Validate the specified Content-Type.
-
Field Details
-
STRIP_PARAMS
Function to strip MediaType parameters.
-
-
Constructor Details
-
MediaTypeSupport
private MediaTypeSupport()Constructor.
-
-
Method Details
-
validateContentType
public static boolean validateContentType(String contentType, Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy)Validate the specified Content-Type.Two strategies are supported for evaluating a content type:
-
If isOneOfStrategy is true, then the
MediaType
parsed from the content type value is compared to each of the specified valid types viaMediaType.is(MediaType)
. If any pass, the type is considered valid. This allows use of MediaType's support for wildcard and parameter evaluation. -
If isOneOfStrategy is false, then the
MediaType
parsed from the value is stripped of its parameters, as is each of the valid types. Then a simple evaluation is done that the specified content type is equal to one of the passed types. In this case, only literal types and subtypes should be passed as valid types; wildcards should not be used.
- Parameters:
contentType
- the contentType to be validatedvalidTypes
- the set of valid media typesnoContentTypeIsValid
- flag whether the case of a missing/empty Content-Type header is considered validisOneOfStrategy
- flag for the strategy used in the validation (see above for details)- Returns:
- true if the content type is valid, false if not
-
If isOneOfStrategy is true, then the
-