Top Description Fields Constructors Methods
org.springframework.web.accept

public Class PathExtensionContentNegotiationStrategy

extends AbstractMappingContentNegotiationStrategy
Class Inheritance
Known Direct Subclasses
org.springframework.web.accept.ServletPathExtensionContentNegotiationStrategy
Annotations
@Deprecated
Imports
java.util.Locale, .Map, jakarta.servlet.http.HttpServletRequest, org.springframework.core.io.Resource, org.springframework.http.MediaType, .MediaTypeFactory, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.util.UriUtils, .UrlPathHelper

Deprecated

as of 5.2.4. See class-level note in ContentNegotiationManagerFactoryBean on the deprecation of path extension config options.

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

Field Summary

Modifier and TypeField and Description
private UrlPathHelper
Inherited from org.springframework.web.accept.AbstractMappingContentNegotiationStrategy:
logger

Constructor Summary

AccessConstructor and Description
public
PathExtensionContentNegotiationStrategy()

Create an instance without any mappings to start with.

public
PathExtensionContentNegotiationStrategy(Map<String, MediaType> mediaTypes)

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

Method Summary

Modifier and TypeMethod and Description
public MediaType

Returns:

the MediaType for the extension, or null if none found
getMediaTypeForResource
(Resource
the resource to look up
resource
)

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.

protected String
getMediaTypeKey(NativeWebRequest webRequest)

Implements abstract org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.getMediaTypeKey.

Extract a key from the request to use to look up media types.
public void
setUrlPathHelper(UrlPathHelper urlPathHelper)

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

public void
setUseJaf(boolean useJaf)

Deprecated as of 5.0, in favor of setUseRegisteredExtensionsOnly(boolean).
Indicate whether to use the Java Activation Framework as a fallback option to map from file extensions to media types.
Inherited from org.springframework.web.accept.AbstractMappingContentNegotiationStrategy:
handleMatchhandleNoMatchisIgnoreUnknownExtensionsisUseRegisteredExtensionsOnlyresolveMediaTypeKeyresolveMediaTypessetIgnoreUnknownExtensionssetUseRegisteredExtensionsOnly

Field Detail

urlPathHelperback to summary
private UrlPathHelper urlPathHelper

Constructor Detail

PathExtensionContentNegotiationStrategyback to summary
public 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.

PathExtensionContentNegotiationStrategyback to summary
public PathExtensionContentNegotiationStrategy(Map<String, MediaType> mediaTypes)

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

Method Detail

getMediaTypeForResourceback to summary
public MediaType getMediaTypeForResource(Resource resource)

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.

Parameters
resource:Resource

the resource to look up

Returns:MediaType

the MediaType for the extension, or null if none found

Annotations
@Nullable
Since
4.3
getMediaTypeKeyback to summary
protected String getMediaTypeKey(NativeWebRequest webRequest)

Implements abstract org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.getMediaTypeKey.

Doc from org.springframework.web.accept.AbstractMappingContentNegotiationStrategy.getMediaTypeKey.

Extract a key from the request to use to look up media types.

Returns:String

the lookup key, or null if none

Annotations
@Override
@Nullable
setUrlPathHelperback to summary
public void setUrlPathHelper(UrlPathHelper urlPathHelper)

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

Since
4.2.8
setUseJafback to summary
public void setUseJaf(boolean useJaf)

Deprecated

as of 5.0, in favor of setUseRegisteredExtensionsOnly(boolean).

Indicate whether to use the Java Activation Framework as a fallback option to map from file extensions to media types.

Annotations
@Deprecated