Class MediaRangeList
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<MediaRangeList.MediaRange>,Collection<MediaRangeList.MediaRange>,NavigableSet<MediaRangeList.MediaRange>,Set<MediaRangeList.MediaRange>,SortedSet<MediaRangeList.MediaRange>
Facilitates parsing of the Accept HTTP request header.
See RFC 2616 section 14.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA codeMediaRangerepresents an entry in aMediaRangeList. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMediaRangeList(String listStr) Constructs aMediaRangeListusing a list of media ranges specified in ajava.lang.String.MediaRangeList(javax.servlet.http.HttpServletRequest request) Constructs aMediaRangeListusing information from the suppliedHttpServletRequest. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDetermines if this MediaRangeList contains a given media type.Determines which of themediaRangesspecifications is preferred by thisMediaRangeList.prefer(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, tailSetMethods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
HEADER_ACCEPT
- See Also:
-
PARAM_ACCEPT
- See Also:
-
WILDCARD
- See Also:
-
-
Constructor Details
-
MediaRangeList
public MediaRangeList(javax.servlet.http.HttpServletRequest request) Constructs aMediaRangeListusing information from the suppliedHttpServletRequest. if the request contains aPARAM_ACCEPTquery parameter, the query parameter value overrides anyHEADER_ACCEPTheader value. If the request contains noPARAM_ACCEPTparameter, or the parameter value is empty, the value of theHEADER_ACCEPTis 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- TheHttpServletRequestto extract aMediaRangeListfrom
-
MediaRangeList
Constructs aMediaRangeListusing 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.5text/html;q=0.8, application/json
- Parameters:
listStr- The list of media range specifications
-
-
Method Details
-
contains
Determines if this MediaRangeList contains a given media type.- Parameters:
mediaType- A string on the formtype/subtype. Neithertypeorsubtypeshould be wildcard (*).- Returns:
trueif thisMediaRangeListcontains a media type that matchesmediaType,falseotherwise- Throws:
IllegalArgumentException- ifmediaTypeis not on an accepted formNullPointerException- ifmediaTypeisnull
-
prefer
Given a list of media types, returns the one is preferred by thisMediaRangeList.- Parameters:
mediaRanges- An array of possibleMediaRangeList.MediaRanges- Returns:
- One of the
mediaRangesthat thisMediaRangeListprefers; ornullif thisMediaRangeListdoes not contain any of themediaRanges - Throws:
NullPointerException- ifmediaRangesisnullor contains anullvalue
-
prefer
Determines which of themediaRangesspecifications is preferred by thisMediaRangeList.- Parameters:
mediaRanges- String representations ofMediaRanges. The strings must be on the form required byMediaRange(String)- Returns:
- the
toString()representation of the preferredMediaRange, ornullif thisMediaRangeListdoes not contain any of themediaRanges - See Also:
-