/** * Creates a content type from an existing content type and an additional parameter as key-value pair. * @param contentType an existing content type * @param parameterName the name of the additional parameter * @param parameterValue the value of the additional parameter * @return a new {@link ContentType} object */ public static ContentType create(final ContentType contentType, final String parameterName, final String parameterValue) throws IllegalArgumentException { TypeUtil.validateParameterNameAndValue(parameterName, parameterValue); ContentType type = new ContentType(contentType.type, contentType.subtype, contentType.parameters); type.parameters.put(parameterName.toLowerCase(Locale.ROOT), parameterValue); return type; }
/** * Creates a content type from an existing content type and an additional parameter as key-value pair. * @param contentType an existing content type * @param parameterName the name of the additional parameter * @param parameterValue the value of the additional parameter * @return a new {@link ContentType} object */ public static ContentType create(final ContentType contentType, final String parameterName, final String parameterValue) throws IllegalArgumentException { TypeUtil.validateParameterNameAndValue(parameterName, parameterValue); ContentType type = new ContentType(contentType.type, contentType.subtype, contentType.parameters); type.parameters.put(parameterName.toLowerCase(Locale.ROOT), parameterValue); return type; }
/** * Valid input is one <code>key=value</code> pair without spaces between key and value. * <p> * See RFC 7231: * The type, subtype, and parameter name tokens are case-insensitive. * Parameter values might or might not be case-sensitive, depending on * the semantics of the parameter name. The presence or absence of a * parameter might be significant to the processing of a media-type, * depending on its definition within the media type registry. * </p> * * @param parameter as <code>key=value</code> pair * @return <code>key</code> as first array value (as lower case) and <code>value</code> as second array value */ static String[] parseParameter(final String parameter) { if (parameter.isEmpty()) { throw new IllegalArgumentException("An empty parameter is not allowed."); } String[] keyValue = parameter.trim().split(PARAMETER_KEY_VALUE_SEPARATOR); if (keyValue.length != 2) { throw new IllegalArgumentException("Parameter '" + parameter + "' must have exactly one '" + PARAMETER_KEY_VALUE_SEPARATOR + "' that separates the name and the value."); } validateParameterNameAndValue(keyValue[0], keyValue[1]); keyValue[0] = keyValue[0].toLowerCase(Locale.ENGLISH); return keyValue; }
/** * Valid input is one <code>key=value</code> pair without spaces between key and value. * <p> * See RFC 7231: * The type, subtype, and parameter name tokens are case-insensitive. * Parameter values might or might not be case-sensitive, depending on * the semantics of the parameter name. The presence or absence of a * parameter might be significant to the processing of a media-type, * depending on its definition within the media type registry. * </p> * * @param parameter as <code>key=value</code> pair * @return <code>key</code> as first array value (as lower case) and <code>value</code> as second array value */ static String[] parseParameter(final String parameter) { if (parameter.isEmpty()) { throw new IllegalArgumentException("An empty parameter is not allowed."); } String[] keyValue = parameter.trim().split(PARAMETER_KEY_VALUE_SEPARATOR); if (keyValue.length != 2) { throw new IllegalArgumentException("Parameter '" + parameter + "' must have exactly one '" + PARAMETER_KEY_VALUE_SEPARATOR + "' that separates the name and the value."); } validateParameterNameAndValue(keyValue[0], keyValue[1]); keyValue[0] = keyValue[0].toLowerCase(Locale.ENGLISH); return keyValue; }