/** * Negotiate Format - given a list of accepted media types, return the format that's * most suitable * * @param accept comma-seperated list of accepted media types * @param negotiatedFormats list of available formats * @return most suitable format (or null, if none) */ public static String negotiateFormat(String accept, NegotiatedFormat[] negotiatedFormats) { String format = null; float match = 0.0f; String[] acceptTypes = accept.split(","); for (String acceptType : acceptTypes) { MediaType acceptMediaType = new MediaType(acceptType); for (NegotiatedFormat negotiatedFormat : negotiatedFormats) { float negotiatedMatch = negotiatedFormat.getMediaType().compare(acceptMediaType); if (negotiatedMatch > match) { match = negotiatedMatch; format = negotiatedFormat.getFormat(); } } } return format; } }
/** * Negotiate Format - given a list of accepted media types, return the format that's * most suitable * * @param accept comma-seperated list of accepted media types * @param negotiatedFormats list of available formats * @return most suitable format (or null, if none) */ public static String negotiateFormat(String accept, NegotiatedFormat[] negotiatedFormats) { String format = null; float match = 0.0f; String[] acceptTypes = accept.split(","); for (String acceptType : acceptTypes) { MediaType acceptMediaType = new MediaType(acceptType); for (NegotiatedFormat negotiatedFormat : negotiatedFormats) { float negotiatedMatch = negotiatedFormat.getMediaType().compare(acceptMediaType); if (negotiatedMatch > match) { match = negotiatedMatch; format = negotiatedFormat.getFormat(); } } } return format; } }
/** * Negotiate Format - given a list of accepted media types, return the format that's * most suitable * * @param accept comma-seperated list of accepted media types * @param negotiatedFormats list of available formats * @return most suitable format (or null, if none) */ public static String negotiateFormat(String accept, NegotiatedFormat[] negotiatedFormats) { String format = null; float match = 0.0f; String[] acceptTypes = accept.split(","); for (String acceptType : acceptTypes) { MediaType acceptMediaType = new MediaType(acceptType); for (NegotiatedFormat negotiatedFormat : negotiatedFormats) { float negotiatedMatch = negotiatedFormat.getMediaType().compare(acceptMediaType); if (negotiatedMatch > match) { match = negotiatedMatch; format = negotiatedFormat.getFormat(); } } } return format; } }
sb.append(" ").append("accept=\"").append(negotiatedFormat.getMediaType().getType()+"/"+negotiatedFormat.getMediaType().getSubtype()).append("\">"); sb.append(negotiatedFormat.getFormat()).append("</negotiate>").append(AbstractBaseDescriptionDocument.NEW_LINE);
sb.append(" ").append("accept=\"").append(negotiatedFormat.getMediaType().getType()+"/"+negotiatedFormat.getMediaType().getSubtype()).append("\">"); sb.append(negotiatedFormat.getFormat()).append("</negotiate>").append(AbstractBaseDescriptionDocument.NEW_LINE);
sb.append(" ").append("accept=\"").append(negotiatedFormat.getMediaType().getType()+"/"+negotiatedFormat.getMediaType().getSubtype()).append("\">"); sb.append(negotiatedFormat.getFormat()).append("</negotiate>").append(AbstractBaseDescriptionDocument.NEW_LINE);