Class MediaRanges

java.lang.Object
org.apache.juneau.MediaRanges

@BeanIgnore public class MediaRanges extends Object
A parsed Accept or similar header value.

The returned media ranges are sorted such that the most acceptable media is available at ordinal position '0', and the least acceptable at position n-1.

The syntax expected to be found in the referenced value complies with the syntax described in RFC2616, Section 14.1, as described below:

Accept = "Accept" ":" #( media-range [ accept-params ] ) media-range = ( "*\/*" | ( type "/" "*" ) | ( type "/" subtype ) ) *( ";" parameter ) accept-params = ";" "q" "=" qvalue *( accept-extension ) accept-extension = ";" token [ "=" ( token | quoted-string ) ]

See Also:
  • Field Details

    • EMPTY

      public static final MediaRanges EMPTY
      Represents an empty media ranges object.
  • Constructor Details

    • MediaRanges

      public MediaRanges(String value)
      Constructor.
      Parameters:
      value - The Accept header value.
    • MediaRanges

      Constructor.
      Parameters:
      e - The parsed header value.
  • Method Details

    • of

      public static MediaRanges of(String value)
      Returns a parsed Accept header value.
      Parameters:
      value - The raw Accept header value.
      Returns:
      A parsed Accept header value.
    • match

      public int match(List<? extends MediaType> mediaTypes)
      Given a list of media types, returns the best match for this Accept header.

      Note that fuzzy matching is allowed on the media types where the Accept header may contain additional subtype parts.
      For example, given identical q-values and an Accept value of "text/json+activity", the media type "text/json" will match if "text/json+activity" or "text/activity+json" isn't found.
      The purpose for this is to allow serializers to match when artifacts such as id properties are present in the header.

      See ActivityPub / Retrieving Objects

      Parameters:
      mediaTypes - The media types to match against.
      Returns:
      The index into the array of the best match, or -1 if no suitable matches could be found.
    • getRange

      public MediaRange getRange(int index)
      Returns the MediaRange at the specified index.
      Parameters:
      index - The index position of the media range.
      Returns:
      The MediaRange at the specified index or null if the index is out of range.
    • hasSubtypePart

      public boolean hasSubtypePart(String part)
      Convenience method for searching through all of the subtypes of all the media ranges in this header for the presence of a subtype fragment.

      For example, given the header "text/json+activity", calling hasSubtypePart("activity") returns true.

      Parameters:
      part - The media type subtype fragment.
      Returns:
      true if subtype fragment exists.
    • toList

      public List<MediaRange> toList()
      Returns the media ranges that make up this object.
      Returns:
      The media ranges that make up this object.
    • forEachRange

      Performs an action on the media ranges that make up this object.
      Parameters:
      action - The action to perform.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object