public class AcceptHeaderDelegate implements HeaderDelegate<Accept> {
private static final SoftConcurrentMap<String, Accept> cache = new SoftConcurrentMap<String, Accept>();
public Accept fromString(String value) throws IllegalArgumentException {
Accept cached = cache.get(value);
if (cached != null) {
return cached;
}
// if there is no Accept header it means that all media types are
// acceptable
if (value == null) {
value = MediaType.WILDCARD;
}
List<MediaType> list = new LinkedList<MediaType>();
String[] mediaTypes = StringUtils.fastSplit(value, ",");
for (String mediaRange : mediaTypes) {
mediaRange = mediaRange.trim();
if (mediaRange.length() == 0) {
continue;
}
list.add(MediaType.valueOf(mediaRange));
}
return cache.put(value, new Accept(list));
}