/** * Get the content type based on <code>contentType</code> parameter. If this content type is not * compatible to the expected ContentType a BatchDeserializerException is thrown. * * @param contentType content type string which is parsed * @param expected content type to which the parsed must be compatible * @param line parsed line * @return the parsed content type or if not compatible or parseable an exception is thrown (never * returns null) * @throws BatchDeserializerException */ public static ContentType parseContentType( final String contentType, final ContentType expected, final int line) throws BatchDeserializerException { ContentType type; try { type = ContentType.create(contentType); } catch (final IllegalArgumentException e) { if (contentType == null) { throw new BatchDeserializerException( "Missing content type", e, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, Integer.toString(line)); } else { throw new BatchDeserializerException( "Invalid content type.", e, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, Integer.toString(line)); } } if (type.isCompatible(expected)) { return type; } else { throw new BatchDeserializerException( "Content type is not the expected content type", BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE, Integer.toString(line), expected.toContentTypeString(), type.toContentTypeString()); } }
public static boolean isODataMetadataNone(final ContentType contentType) { return contentType.isCompatible(ContentType.APPLICATION_JSON) && ContentType.VALUE_ODATA_METADATA_NONE.equals( contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA)); }