Class ContentTypeUtil
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.utils.http.ContentTypeUtil
-
public class ContentTypeUtil extends Object
A utility for selecting content types, in the context of the Accept header. ------------------- This does not support matching against content types with extensions, like "level=1", as illustrated in RFC-2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 However, as long as we don't offer such extensions on our available types, the use of extensions in the Accept header is moot.
-
-
Constructor Summary
Constructors Constructor Description ContentTypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbestContentType(String acceptHeader, Collection<String> availableTypeNames)Given an Accept header value and a list of available type names, decide which type is the best fit.static Set<edu.cornell.mannlib.vitro.webapp.utils.http.ContentTypeUtil.AcceptableType>parseAcceptHeader(String acceptHeader)The order of items in the Accept header is not important.
-
-
-
Method Detail
-
bestContentType
public static String bestContentType(String acceptHeader, Collection<String> availableTypeNames) throws AcceptHeaderParsingException, NotAcceptableException
Given an Accept header value and a list of available type names, decide which type is the best fit. If there is no fit, throw a NotAcceptableException The only thing to do is to match all available against all acceptable, and pick the best match. Try to do as little work as possible inside the nested loop.
-
parseAcceptHeader
public static Set<edu.cornell.mannlib.vitro.webapp.utils.http.ContentTypeUtil.AcceptableType> parseAcceptHeader(String acceptHeader) throws AcceptHeaderParsingException
The order of items in the Accept header is not important. We rely on the specificity of the match and the "q" factor, in that order. Since q ranges between 1.0 and 0.001, we add a specificity offset of 2, 3 or 4. That way, matches with equal specificity are decided by q factor.- Throws:
AcceptHeaderParsingException
-
-