/** * Return the content type represented by the given string. If the string does not have a "/", * assume it's "text/{format}". For example, if format is "xml", the returned media type will be * "text/xml". * * @param format * @return the content type represented by the given string */ public static MediaType getContentType(String format) { if (format == null) { format = "text/html"; } else if (format.indexOf('/') <= 0) { format = "text/" + format; } return HttpHelper.getContentType(format); }
public static Variant selectVariant(ContainerRequest r, List<Variant> variants) { LinkedList<VariantHolder> vhs = getVariantHolderList(variants); Set<String> vary = new HashSet<String>(); vhs = selectVariants(vhs, HttpHelper.getAccept(r), MEDIA_TYPE_DC, vary); vhs = selectVariants(vhs, HttpHelper.getAcceptLanguage(r), LANGUAGE_TAG_DC, vary); vhs = selectVariants(vhs, HttpHelper.getAcceptCharset(r), CHARSET_DC, vary); vhs = selectVariants(vhs, HttpHelper.getAcceptEncoding(r), ENCODING_DC, vary); if (vhs.isEmpty()) { return null; } else { StringBuilder varyHeader = new StringBuilder(); for (String v : vary) { if (varyHeader.length() > 0) { varyHeader.append(','); } varyHeader.append(v); } r.getProperties().put(ContainerRequest.VARY_HEADER, varyHeader.toString()); return vhs.iterator().next().v; } }