Class MediaTypeSupport

java.lang.Object
net.shibboleth.utilities.java.support.net.MediaTypeSupport

public final class MediaTypeSupport
extends Object
Support methods for Guava MediaType.
  • Field Details

  • 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:

      1. If isOneOfStrategy is true, then the MediaType parsed from the content type value is compared to each of the specified valid types via MediaType.is(MediaType). If any pass, the type is considered valid. This allows use of MediaType's support for wildcard and parameter evaluation.
      2. 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 validated
      validTypes - the set of valid media types
      noContentTypeIsValid - flag whether the case of a missing/empty Content-Type header is considered valid
      isOneOfStrategy - flag for the strategy used in the validation (see above for details)
      Returns:
      true if the content type is valid, false if not