Class MediaRangeList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- java.util.TreeSet<MediaRangeList.MediaRange>
-
- org.apache.sling.api.request.header.MediaRangeList
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<MediaRangeList.MediaRange>
,java.util.Collection<MediaRangeList.MediaRange>
,java.util.NavigableSet<MediaRangeList.MediaRange>
,java.util.Set<MediaRangeList.MediaRange>
,java.util.SortedSet<MediaRangeList.MediaRange>
@ConsumerType public class MediaRangeList extends java.util.TreeSet<MediaRangeList.MediaRange>
Facilitates parsing of the Accept HTTP request header. See RFC 2616 section 14.1- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MediaRangeList.MediaRange
A codeMediaRange
represents an entry in aMediaRangeList
.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
HEADER_ACCEPT
static java.lang.String
PARAM_ACCEPT
static java.lang.String
WILDCARD
-
Constructor Summary
Constructors Constructor Description MediaRangeList(java.lang.String listStr)
Constructs aMediaRangeList
using a list of media ranges specified in ajava.lang.String
.MediaRangeList(HttpServletRequest request)
Constructs aMediaRangeList
using information from the suppliedHttpServletRequest
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(java.lang.String mediaType)
Determines if this MediaRangeList contains a given media type.java.lang.String
prefer(java.lang.String... mediaRanges)
Determines which of themediaRanges
specifications is preferred by thisMediaRangeList
.MediaRangeList.MediaRange
prefer(java.util.Set<MediaRangeList.MediaRange> mediaRanges)
Given a list of media types, returns the one is preferred by thisMediaRangeList
.-
Methods inherited from class java.util.TreeSet
add, addAll, ceiling, clear, clone, comparator, contains, descendingIterator, descendingSet, first, floor, headSet, headSet, higher, isEmpty, iterator, last, lower, pollFirst, pollLast, remove, size, spliterator, subSet, subSet, tailSet, tailSet
-
-
-
-
Field Detail
-
HEADER_ACCEPT
public static final java.lang.String HEADER_ACCEPT
- See Also:
- Constant Field Values
-
PARAM_ACCEPT
public static final java.lang.String PARAM_ACCEPT
- See Also:
- Constant Field Values
-
WILDCARD
public static final java.lang.String WILDCARD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MediaRangeList
public MediaRangeList(HttpServletRequest request)
Constructs aMediaRangeList
using information from the suppliedHttpServletRequest
. if the request contains aPARAM_ACCEPT
query parameter, the query parameter value overrides anyHEADER_ACCEPT
header value. If the request contains noPARAM_ACCEPT
parameter, or the parameter value is empty, the value of theHEADER_ACCEPT
is used. If both values are missing, it is assumed that the client accepts all media types, as per the RFC. See alsoMediaRangeList(java.lang.String)
- Parameters:
request
- TheHttpServletRequest
to extract aMediaRangeList
from
-
MediaRangeList
public MediaRangeList(java.lang.String listStr)
Constructs aMediaRangeList
using a list of media ranges specified in ajava.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(java.lang.String mediaType)
Determines if this MediaRangeList contains a given media type.- Parameters:
mediaType
- A string on the formtype/subtype
. Neithertype
orsubtype
should be wildcard (*
).- Returns:
true
if thisMediaRangeList
contains a media type that matchesmediaType
,false
otherwise- Throws:
java.lang.IllegalArgumentException
- ifmediaType
is not on an accepted formjava.lang.NullPointerException
- ifmediaType
isnull
-
prefer
public MediaRangeList.MediaRange prefer(java.util.Set<MediaRangeList.MediaRange> mediaRanges)
Given a list of media types, returns the one is preferred by thisMediaRangeList
.- Parameters:
mediaRanges
- An array of possibleMediaRangeList.MediaRange
s- Returns:
- One of the
mediaRanges
that thisMediaRangeList
prefers; ornull
if thisMediaRangeList
does not contain any of themediaRanges
- Throws:
java.lang.NullPointerException
- ifmediaRanges
isnull
or contains anull
value
-
prefer
public java.lang.String prefer(java.lang.String... mediaRanges)
Determines which of themediaRanges
specifications is preferred by thisMediaRangeList
.- Parameters:
mediaRanges
- String representations ofMediaRange
s. The strings must be on the form required byMediaRange(String)
- Returns:
- the
toString()
representation of the preferredMediaRange
, ornull
if thisMediaRangeList
does not contain any of themediaRanges
- See Also:
prefer(java.util.Set)
-
-