ParameterContentNegotiationStrategy (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.web.accept

## Class ParameterContentNegotiationStrategy

- java.lang.Object
- - org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
  - - org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
    - - org.springframework.web.accept.ParameterContentNegotiationStrategy

- All Implemented Interfaces:
    ContentNegotiationStrategy, MediaTypeFileExtensionResolver

      public class ParameterContentNegotiationStrategy
      extends AbstractMappingContentNegotiationStrategy

  A ContentNegotiationStrategy that uses a request parameter to determine what media types are requested. The default parameter name is `format`. Its value is used to look up the media type in the map given to the constructor.
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)` Create an instance with the given extension-to-MediaType lookup.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `getMediaTypeKey(NativeWebRequest webRequest)` Sub-classes must extract the key to use to look up a media type.
    `protected void` | `handleMatch(String mediaTypeKey, MediaType mediaType)` Invoked when a matching media type is found in the lookup map.
    `void` | `setParameterName(String parameterName)` Set the parameter name that can be used to determine the requested media type.

    - ### Methods inherited from class org.springframework.web.accept.AbstractMappingContentNegotiationStrategy

      `handleNoMatch, resolveMediaTypes`

    - ### Methods inherited from class org.springframework.web.accept.MappingMediaTypeFileExtensionResolver

      `addMapping, getAllFileExtensions, lookupMediaType, resolveFileExtensions`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.web.accept.MediaTypeFileExtensionResolver

      `getAllFileExtensions, resolveFileExtensions`

- - ### Constructor Detail

    - #### ParameterContentNegotiationStrategy

          public ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)

      Create an instance with the given extension-to-MediaType lookup.
      Throws:
        `IllegalArgumentException` - if a media type string cannot be parsed

  - ### Method Detail

    - #### setParameterName

          public void setParameterName(String parameterName)

      Set the parameter name that can be used to determine the requested media type.

      The default parameter name is `format`.

    - #### getMediaTypeKey

          protected String getMediaTypeKey(NativeWebRequest webRequest)

      Description copied from class: `AbstractMappingContentNegotiationStrategy`
      Sub-classes must extract the key to use to look up a media type.
      Specified by:
        `getMediaTypeKey` in class `AbstractMappingContentNegotiationStrategy`
      Returns:
        the lookup key or `null` if the key cannot be derived

    - #### handleMatch

          protected void handleMatch(String mediaTypeKey,
                         MediaType mediaType)

      Description copied from class: `AbstractMappingContentNegotiationStrategy`
      Invoked when a matching media type is found in the lookup map.
      Overrides:
        `handleMatch` in class `AbstractMappingContentNegotiationStrategy`