Class MediaRangeList

    • Constructor Detail

      • MediaRangeList

        public MediaRangeList​(HttpServletRequest request)
        Constructs a MediaRangeList using information from the supplied HttpServletRequest. if the request contains a PARAM_ACCEPT query parameter, the query parameter value overrides any HEADER_ACCEPT header value. If the request contains no PARAM_ACCEPT parameter, or the parameter value is empty, the value of the HEADER_ACCEPT is used. If both values are missing, it is assumed that the client accepts all media types, as per the RFC. See also MediaRangeList(java.lang.String)
        Parameters:
        request - The HttpServletRequest to extract a MediaRangeList from
      • MediaRangeList

        public MediaRangeList​(String listStr)
        Constructs a MediaRangeList using a list of media ranges specified in a java.lang.String. The string is a comma-separated list of media ranges, as specified by the RFC.
        Examples:
        • text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5
        • text/html;q=0.8, application/json
        Parameters:
        listStr - The list of media range specifications
    • Method Detail

      • contains

        public boolean contains​(String mediaType)
        Determines if this MediaRangeList contains a given media type.
        Parameters:
        mediaType - A string on the form type/subtype. Neither type or subtype should be wildcard (*).
        Returns:
        true if this MediaRangeList contains a media type that matches mediaType, false otherwise
        Throws:
        IllegalArgumentException - if mediaType is not on an accepted form
        NullPointerException - if mediaType is null
      • prefer

        public String prefer​(String... mediaRanges)
        Determines which of the mediaRanges specifications is preferred by this MediaRangeList.
        Parameters:
        mediaRanges - String representations of MediaRanges. The strings must be on the form required by MediaRange(String)
        Returns:
        the toString() representation of the preferred MediaRange, or null if this MediaRangeList does not contain any of the mediaRanges
        See Also:
        prefer(java.util.Set)