org.apache.any23.servlet.conneg

## Class ContentTypeNegotiator

- java.lang.Object
- - org.apache.any23.servlet.conneg.ContentTypeNegotiator

-     public class ContentTypeNegotiator
      extends Object

  This class defines a negotiator for content types based on scoring.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ContentTypeNegotiator.VariantSpec`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ContentTypeNegotiator()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addUserAgentOverride(Pattern userAgentString, String originalAcceptHeader, String newAcceptHeader)` Overrides the Accept header for certain user agents.
    `protected ContentTypeNegotiator.VariantSpec` | `addVariant(String mediaType)`
    `MediaRangeSpec` | `getBestMatch(String accept)` Returns the `MediaRangeSpec` associated to the given accept type.
    `MediaRangeSpec` | `getBestMatch(String accept, String userAgent)` Returns the `MediaRangeSpec` associated to the given accept type and userAgent.
    `protected void` | `setDefaultAccept(String accept)` Sets an Accept header to be used as the default if a client does not send an Accept header, or if the Accept header cannot be parsed.

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

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

- - ### Constructor Detail

    - #### ContentTypeNegotiator

          protected ContentTypeNegotiator()

  - ### Method Detail

    - #### getBestMatch

          public MediaRangeSpec getBestMatch(String accept)

      Returns the `MediaRangeSpec` associated to the given accept type.
      Parameters:
        `accept` - a provided accept type
      Returns:
        a `MediaRangeSpec` associated to the accept parameter

    - #### getBestMatch

          public MediaRangeSpec getBestMatch(String accept,
                                             String userAgent)

      Returns the `MediaRangeSpec` associated to the given accept type and userAgent.
      Parameters:
        `accept` - a provided accept type
        `userAgent` - use agent associated with the request
      Returns:
        the `MediaRangeSpec` associated to the given accept type and userAgent.

    - #### addVariant

          protected ContentTypeNegotiator.VariantSpec addVariant(String mediaType)

    - #### setDefaultAccept

          protected void setDefaultAccept(String accept)

      Sets an Accept header to be used as the default if a client does not send an Accept header, or if the Accept header cannot be parsed. Defaults to "* / *".
      Parameters:
        `accept` - a default accept type

    - #### addUserAgentOverride

          protected void addUserAgentOverride(Pattern userAgentString,
                                              String originalAcceptHeader,
                                              String newAcceptHeader)

      Overrides the Accept header for certain user agents. This can be used to implement special-case handling for user agents that send faulty Accept headers.
      Parameters:
        `userAgentString` - A pattern to be matched against the User-Agent header; `null` means regardless of User-Agent
        `originalAcceptHeader` - Only override the Accept header if the user agent sends this header; `null` means always override
        `newAcceptHeader` - The Accept header to be used instead

Copyright © 2010–2019 The Apache Software Foundation. All rights reserved.