/** * A public method exposing the knowledge of the path extension strategy to * resolve file extensions to a {@link MediaType} in this case for a given * {@link Resource}. The method first looks up any explicitly registered * file extensions first and then falls back on {@link MediaTypeFactory} if available. * @param resource the resource to look up * @return the MediaType for the extension, or {@code null} if none found * @since 4.3 */ @Nullable public MediaType getMediaTypeForResource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); MediaType mediaType = null; String filename = resource.getFilename(); String extension = StringUtils.getFilenameExtension(filename); if (extension != null) { mediaType = lookupMediaType(extension); } if (mediaType == null) { mediaType = MediaTypeFactory.getMediaType(filename).orElse(null); } return mediaType; }
/** * A public method exposing the knowledge of the path extension strategy to * resolve file extensions to a {@link MediaType} in this case for a given * {@link Resource}. The method first looks up any explicitly registered * file extensions first and then falls back on {@link MediaTypeFactory} if available. * @param resource the resource to look up * @return the MediaType for the extension, or {@code null} if none found * @since 4.3 */ @Nullable public MediaType getMediaTypeForResource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); MediaType mediaType = null; String filename = resource.getFilename(); String extension = StringUtils.getFilenameExtension(filename); if (extension != null) { mediaType = lookupMediaType(extension); } if (mediaType == null) { mediaType = MediaTypeFactory.getMediaType(filename).orElse(null); } return mediaType; }
/** * A public method exposing the knowledge of the path extension strategy to * resolve file extensions to a {@link MediaType} in this case for a given * {@link Resource}. The method first looks up any explicitly registered * file extensions first and then falls back on {@link MediaTypeFactory} if available. * @param resource the resource to look up * @return the MediaType for the extension, or {@code null} if none found * @since 4.3 */ @Nullable public MediaType getMediaTypeForResource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); MediaType mediaType = null; String filename = resource.getFilename(); String extension = StringUtils.getFilenameExtension(filename); if (extension != null) { mediaType = lookupMediaType(extension); } if (mediaType == null) { mediaType = MediaTypeFactory.getMediaType(filename).orElse(null); } return mediaType; }
/** * A public method exposing the knowledge of the path extension strategy to * resolve file extensions to a {@link MediaType} in this case for a given * {@link Resource}. The method first looks up any explicitly registered * file extensions first and then falls back on {@link MediaTypeFactory} if available. * @param resource the resource to look up * @return the MediaType for the extension, or {@code null} if none found * @since 4.3 */ @Nullable public MediaType getMediaTypeForResource(Resource resource) { Assert.notNull(resource, "Resource must not be null"); MediaType mediaType = null; String filename = resource.getFilename(); String extension = StringUtils.getFilenameExtension(filename); if (extension != null) { mediaType = lookupMediaType(extension); } if (mediaType == null) { mediaType = MediaTypeFactory.getMediaType(filename).orElse(null); } return mediaType; }