org.restlet.engine.util
Class Conneg

java.lang.Object
  extended by org.restlet.engine.util.Conneg

public class Conneg
extends Object

Content negotiation algorithm.

Author:
Jerome Louvel

Constructor Summary
Conneg(ClientInfo clientInfo, MetadataService metadataService)
          Constructor.
 
Method Summary
protected  List<Preference<CharacterSet>> getCharacterSetPrefs()
          Returns the enriched list of character set preferences.
protected  ClientInfo getClientInfo()
          Returns the client preferences.
protected  List<Preference<Encoding>> getEncodingPrefs()
          Returns the enriched list of encoding preferences.
protected
<T extends Metadata>
List<Preference<T>>
getEnrichedPreferences(List<Preference<T>> userPreferences, T defaultValue, T allValue)
          Returns an enriched list of preferences.
protected  List<Preference<Language>> getLanguagePrefs()
          Returns the enriched list of language preferences.
protected  List<Preference<MediaType>> getMediaTypePrefs()
          Returns the enriched list of media type preferences.
protected  MetadataService getMetadataService()
          Returns the metadata service.
 Variant getPreferredVariant(List<? extends Variant> variants)
          Returns the best variant representation for a given resource according the the client preferences.
A default language is provided in case the variants don't match the client preferences.
 float scoreCharacterSet(CharacterSet characterSet)
          Scores a character set relatively to enriched client preferences.
 float scoreEncodings(List<Encoding> encodings)
          Scores encodings relatively to enriched client preferences.
 float scoreLanguages(List<Language> languages)
          Scores languages relatively to enriched client preferences.
 float scoreMediaType(MediaType mediaType)
          Scores a media type relatively to enriched client preferences.
 float scoreVariant(Variant variant)
          Scores a variant relatively to enriched client preferences.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Conneg

public Conneg(ClientInfo clientInfo,
              MetadataService metadataService)
Constructor.

Parameters:
clientInfo -
metadataService -
Method Detail

getCharacterSetPrefs

protected List<Preference<CharacterSet>> getCharacterSetPrefs()
Returns the enriched list of character set preferences.

Returns:
The enriched list of character set preferences.

getClientInfo

protected ClientInfo getClientInfo()
Returns the client preferences.

Returns:
The client preferences.

getEncodingPrefs

protected List<Preference<Encoding>> getEncodingPrefs()
Returns the enriched list of encoding preferences.

Returns:
The enriched list of encoding preferences.

getEnrichedPreferences

protected <T extends Metadata> List<Preference<T>> getEnrichedPreferences(List<Preference<T>> userPreferences,
                                                                          T defaultValue,
                                                                          T allValue)
Returns an enriched list of preferences. Contains the user preferences, implied user parent preferences (quality between 0.005 and 0.006), default preference (quality of 0.003), default parent preference (quality of 0.002), all preference (quality of 0.001).

This necessary to compensate the misconfiguration of many browsers which don't expose all the metadata actually understood by end users.

Type Parameters:
T -
Parameters:
userPreferences - The user preferences to enrich.
defaultValue - The default value.
allValue - The ALL value.
Returns:
The enriched user preferences.

getLanguagePrefs

protected List<Preference<Language>> getLanguagePrefs()
Returns the enriched list of language preferences.

Returns:
The enriched list of language preferences.

getMediaTypePrefs

protected List<Preference<MediaType>> getMediaTypePrefs()
Returns the enriched list of media type preferences.

Returns:
The enriched list of media type preferences.

getMetadataService

protected MetadataService getMetadataService()
Returns the metadata service.

Returns:
The metadata service.

getPreferredVariant

public Variant getPreferredVariant(List<? extends Variant> variants)
Returns the best variant representation for a given resource according the the client preferences.
A default language is provided in case the variants don't match the client preferences.

Parameters:
variants - The list of variants to compare.
Returns:
The preferred variant.
See Also:
Apache content negotiation algorithm

scoreCharacterSet

public float scoreCharacterSet(CharacterSet characterSet)
Scores a character set relatively to enriched client preferences.

Parameters:
characterSet - The character set to score.
Returns:
The score.

scoreEncodings

public float scoreEncodings(List<Encoding> encodings)
Scores encodings relatively to enriched client preferences.

Parameters:
encodings - The encodings to score.
Returns:
The score.

scoreLanguages

public float scoreLanguages(List<Language> languages)
Scores languages relatively to enriched client preferences.

Parameters:
languages - The languages to score.
Returns:
The score.

scoreMediaType

public float scoreMediaType(MediaType mediaType)
Scores a media type relatively to enriched client preferences.

Parameters:
mediaType - The media type to score.
Returns:
The score.

scoreVariant

public float scoreVariant(Variant variant)
Scores a variant relatively to enriched client preferences.

Parameters:
variant - The variant to score.
Returns:
The enriched client preferences.


Copyright © 2005-2011 Noelios Technologies.