spring-framework / org.springframework.web.accept / PathExtensionContentNegotiationStrategy

PathExtensionContentNegotiationStrategy

open class PathExtensionContentNegotiationStrategy : AbstractMappingContentNegotiationStrategy

A ContentNegotiationStrategy that resolves the file extension in the request path to a key to be used to look up a media type.

If the file extension is not found in the explicit registrations provided to the constructor, the MediaTypeFactory is used as a fallback mechanism.

Author
Rossen Stoyanchev

Since
3.2

Constructors

<init>

PathExtensionContentNegotiationStrategy()

Create an instance without any mappings to start with. Mappings may be added later on if any extensions are resolved through the Java Activation framework.

PathExtensionContentNegotiationStrategy(mediaTypes: MutableMap<String, MediaType>)

Create an instance with the given map of file extensions and media types.

Functions

getMediaTypeForResource

open fun getMediaTypeForResource(resource: Resource): MediaType

A public method exposing the knowledge of the path extension strategy to resolve file extensions to a MediaType in this case for a given Resource. The method first looks up any explicitly registered file extensions first and then falls back on MediaTypeFactory if available.

setUrlPathHelper

open fun setUrlPathHelper(urlPathHelper: UrlPathHelper): Unit

Configure a UrlPathHelper to use in #getMediaTypeKey in order to derive the lookup path for a target request URL path.

setUseJaf

open fun setUseJaf(useJaf: Boolean): Unit

Inheritors

ServletPathExtensionContentNegotiationStrategy

open class ServletPathExtensionContentNegotiationStrategy : PathExtensionContentNegotiationStrategy

Extends PathExtensionContentNegotiationStrategy that also uses ServletContext#getMimeType(String) to resolve file extensions.