de.bripkens.gravatar
Class Gravatar

java.lang.Object
  extended by de.bripkens.gravatar.Gravatar

public class Gravatar
extends Object

A utility class for the generation of Gravatar URLs. This class supports various settings, e.g. default image, custom default image and avatar ratings that are meant to simplify the URL generation process. A Gravatar instance can be used multiple times and the getUrl(...) method is thread safe. Example:

 String gravatarImageURL = new Gravatar()
               .setSize(50)
               .setHttps(true)
               .setRating(Rating.PARENTAL_GUIDANCE_SUGGESTED)
               .setStandardDefaultImage(DefaultImage.MONSTER)
               .getUrl("foobar@example.com");
 
 

Author:
Ben Ripkens

Field Summary
static Rating DEFAULT_RATING
           
static int DEFAULT_SIZE
           
static String FILE_TYPE_EXTENSION
           
static String HTTPS_URL
           
static String URL
           
 
Constructor Summary
Gravatar()
           
 
Method Summary
 String getUrl(String email)
          Retrieve the gravatar URL for the given email.
 Gravatar setCustomDefaultImage(String customDefaultImage)
          Set the default image which will be retrieved when there is no avatar for the given email, when the avatar can't be shown due to the rating or when you enforce the default avatar.
 Gravatar setCustomDefaultImage(String customDefaultImage, String encoding)
          Set the default image which will be retrieved when there is no avatar for the given email, when the avatar can't be shown due to the rating or when you enforce the default avatar.
 Gravatar setForceDefault(boolean forceDefault)
          Enforce usage of the default image by passing true.
 Gravatar setHttps(boolean https)
          Retrieve an avatar URL which allows retrieval over HTTPS.
 Gravatar setRating(Rating rating)
          Restrict the retrieved avatars to the ones appropriate for the audience.
 Gravatar setSize(int size)
          Set the desired size through the size property.
 Gravatar setStandardDefaultImage(DefaultImage standardDefaultImage)
          Set the default image which will be retrieved when there is no avatar for the given email, when the avatar can't be shown due to the rating or when you enforce the default avatar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL

public static final String URL
See Also:
Constant Field Values

HTTPS_URL

public static final String HTTPS_URL
See Also:
Constant Field Values

FILE_TYPE_EXTENSION

public static final String FILE_TYPE_EXTENSION
See Also:
Constant Field Values

DEFAULT_SIZE

public static final int DEFAULT_SIZE
See Also:
Constant Field Values

DEFAULT_RATING

public static final Rating DEFAULT_RATING
Constructor Detail

Gravatar

public Gravatar()
Method Detail

setSize

public Gravatar setSize(int size)
Set the desired size through the size property. All avatars have a quadratic form, thus only one value is required. The size is expected in pixel

Parameters:
size - The avatar size in pixel.
Returns:
Fluent interface

setHttps

public Gravatar setHttps(boolean https)
Retrieve an avatar URL which allows retrieval over HTTPS.

Parameters:
https - Set to true to retrieve a HTTPS URL.
Returns:
Fluent interface

setForceDefault

public Gravatar setForceDefault(boolean forceDefault)
Enforce usage of the default image by passing true.

Parameters:
forceDefault - True to always retrieve the default image.
Returns:
Fluent interface

setRating

public Gravatar setRating(Rating rating)
Restrict the retrieved avatars to the ones appropriate for the audience. Which ones are appropriate can be set through the rating.

Parameters:
rating - This rating will be allowed.
Returns:
Fluent interface

setStandardDefaultImage

public Gravatar setStandardDefaultImage(DefaultImage standardDefaultImage)
Set the default image which will be retrieved when there is no avatar for the given email, when the avatar can't be shown due to the rating or when you enforce the default avatar.

Parameters:
standardDefaultImage - One of multiple default avatar choices.
Returns:
Fluent interface

setCustomDefaultImage

public Gravatar setCustomDefaultImage(String customDefaultImage)
                               throws UnsupportedEncodingException
Set the default image which will be retrieved when there is no avatar for the given email, when the avatar can't be shown due to the rating or when you enforce the default avatar.

Parameters:
customDefaultImage - Absolute URL to an image. An UTF-8 encoding is expected.
Returns:
Fluent interface
Throws:
UnsupportedEncodingException

setCustomDefaultImage

public Gravatar setCustomDefaultImage(String customDefaultImage,
                                      String encoding)
                               throws UnsupportedEncodingException
Set the default image which will be retrieved when there is no avatar for the given email, when the avatar can't be shown due to the rating or when you enforce the default avatar.

Parameters:
customDefaultImage - Absolute URL to an image.
encoding - customDefaultImage's (first parameter) encoding
Returns:
Fluent interface
Throws:
UnsupportedEncodingException
See Also:
URLEncoder.encode(String, String)

getUrl

public String getUrl(String email)
Retrieve the gravatar URL for the given email.

Parameters:
email - The email for which the avatar URL should be returned.
Returns:
URL to the gravatar.


Copyright © 2011. All Rights Reserved.