org.apache.any23.servlet.conneg
Class ContentTypeNegotiator

java.lang.Object
  extended by 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
protected  class ContentTypeNegotiator.VariantSpec
           
 
Constructor Summary
protected ContentTypeNegotiator()
           
 
Method Summary
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 -
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 -
userAgent -
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 "* / *".


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-2012 The Apache Software Foundation. All Rights Reserved.