public class DefaultProfileImageProvider extends SafeProfileImageProvider implements Contextualizable, Component
Modifier and Type | Class and Description |
---|---|
static class |
DefaultProfileImageProvider.ProfileImageSource
Profile image source enum
|
ProfileImageProvider.UserProfileImage
Modifier and Type | Field and Description |
---|---|
protected static String |
__AVATAR_DIR_NAME
Name of the avatar directory
|
protected static Map<String,String> |
__avatarPaths
The map of paths to avatar images, keys are id
|
protected static String |
__INITIALS_DIR_NAME
Name of the initials directory
|
protected static List<String> |
__initialsBgPaths
Ordered list of paths to available backgrounds for 'initials' images
|
private Context |
_context |
protected JSONUtils |
_jsonUtils
JSON Utils
|
protected UploadManager |
_uploadManager
Upload manager
|
protected UserPreferencesManager |
_userPreferencesManager
User pref manager
|
static String |
USER_PROFILE_PREF_CONTEXT
The pref context for user profile
|
static String |
USERPREF_PROFILE_IMAGE
The profile image user pref id
|
__DEFAULT_FILE_NAME, __USER_PROFILES_DIR_PATH, _sourceResolver, _userManager
ROLE
Constructor and Description |
---|
DefaultProfileImageProvider() |
Modifier and Type | Method and Description |
---|---|
protected InputStream |
_addImageBackground(UserIdentity user,
InputStream is)
Add a background to an initials image
|
protected Map<String,Object> |
_extractBase64Parameters(Request request,
UserIdentity user)
Extracts parameters for a local image
|
protected Map<String,Object> |
_extractLocalImageParameters(Request request,
UserIdentity user)
Extracts parameters for a local image
|
protected Map<String,Object> |
_extractSourceParameters(UserIdentity user,
DefaultProfileImageProvider.ProfileImageSource profileImageSource)
Provides the necessary parameters to retrieves the image from a given source.
|
protected Map<String,Object> |
_extractUploadParameters(Request request,
UserIdentity user)
Extracts parameters for an uploaded image
|
private Integer |
_getGravatarSize(Map<String,Object> sourceParams)
Extract the gravatar size from the source params if any
|
protected Source |
_getInitialsBackgroundSource(UserIdentity user)
Get the background image for the initials source.
|
protected Source |
_getInitialsImageSource(String initial)
Get the source of the initials image
|
protected Map<String,String> |
_getLocalImagePaths()
Get the map containing the relative path for each local image.
|
protected Source |
_getLocalImageSource(String localFileId)
Get the source of a local image
|
private Map<String,Object> |
_getRawUserPrefImage(UserIdentity user)
Get the profile image user pref
|
private void |
_initializeInitialsBackgroundPaths()
Initializes the list of background paths for initials images
|
private void |
_initializeLocalImagePaths()
Initializes the map of local image paths
|
void |
contextualize(Context context) |
BufferedImage |
cropUploadedImage(InputStream is)
Automatically crop the image to 64x64 pixels.
|
ProfileImageProvider.UserProfileImage |
getBase64Image(UserIdentity user,
String data,
String filename)
Get the image from a base 64 string
|
ProfileImageProvider.UserProfileImage |
getImage(DefaultProfileImageProvider.ProfileImageSource source,
UserIdentity user,
Map<String,Object> sourceParams)
Get the image input stream
|
ProfileImageProvider.UserProfileImage |
getImage(UserIdentity user,
String imageSource,
int size,
int maxSize)
Get the avatar
|
ProfileImageProvider.UserProfileImage |
getInitialsImage(UserIdentity userIdentity)
Get the image with user initials
|
ProfileImageProvider.UserProfileImage |
getLocalImage(UserIdentity user,
String localFileId)
Get the local image
|
List<String> |
getLocalImageIds()
Get the list of local image identifiers
|
DefaultProfileImageProvider.ProfileImageSource |
getProfileImageSource(String imageSourceStr)
Get the profile image source given a source input string
|
ProfileImageProvider.UserProfileImage |
getUploadedImage(UserIdentity user,
String uploadId)
Get the uploaded image
|
ProfileImageProvider.UserProfileImage |
getUserPrefImage(UserIdentity user,
Map<String,Object> baseSourceParams)
Get the image from the user pref
|
boolean |
hasInitialsImage(UserIdentity userIdentity)
Test if the initials image is available for a given user
|
boolean |
hasLocalImage(String localFileId)
Test if the local image exists
|
Map<String,Object> |
hasUserPrefImage(UserIdentity user)
Test this user as a profile image set in its user pref
|
void |
service(ServiceManager smanager) |
getDefaultImage, getGravatarImage, hasGravatarImage
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
public static final String USER_PROFILE_PREF_CONTEXT
public static final String USERPREF_PROFILE_IMAGE
protected static final String __AVATAR_DIR_NAME
protected static final String __INITIALS_DIR_NAME
protected static Map<String,String> __avatarPaths
protected static List<String> __initialsBgPaths
protected UploadManager _uploadManager
protected UserPreferencesManager _userPreferencesManager
protected JSONUtils _jsonUtils
public DefaultProfileImageProvider()
public void service(ServiceManager smanager) throws ServiceException
service
in interface Serviceable
service
in class SafeProfileImageProvider
ServiceException
public void contextualize(Context context) throws ContextException
contextualize
in interface Contextualizable
ContextException
public ProfileImageProvider.UserProfileImage getImage(UserIdentity user, String imageSource, int size, int maxSize) throws ProcessingException
ProfileImageProvider
getImage
in interface ProfileImageProvider
getImage
in class SafeProfileImageProvider
user
- The userimageSource
- The image source. Can be null to get the default onesize
- The size in px. Can be 0.maxSize
- The maxSize in px. Can be 0.ProcessingException
- If an error occurredpublic DefaultProfileImageProvider.ProfileImageSource getProfileImageSource(String imageSourceStr)
imageSourceStr
- The input string representing the sourceprotected Map<String,Object> _extractSourceParameters(UserIdentity user, DefaultProfileImageProvider.ProfileImageSource profileImageSource) throws ResourceNotFoundException
user
- The userprofileImageSource
- The image source typeResourceNotFoundException
- In case of a unhandled source type or if parameters could not be extractedprotected Map<String,Object> _extractUploadParameters(Request request, UserIdentity user)
request
- The requestuser
- The userprotected Map<String,Object> _extractLocalImageParameters(Request request, UserIdentity user)
request
- The requestuser
- The userprotected Map<String,Object> _extractBase64Parameters(Request request, UserIdentity user)
request
- The requestuser
- The userpublic ProfileImageProvider.UserProfileImage getImage(DefaultProfileImageProvider.ProfileImageSource source, UserIdentity user, Map<String,Object> sourceParams)
source
- The image source typeuser
- The usersourceParams
- The parameters used by the sourcepublic ProfileImageProvider.UserProfileImage getBase64Image(UserIdentity user, String data, String filename)
user
- The userdata
- The base64 data representing the imagefilename
- The filename or null if not knownprivate Integer _getGravatarSize(Map<String,Object> sourceParams)
sourceParams
- The source paramspublic ProfileImageProvider.UserProfileImage getUserPrefImage(UserIdentity user, Map<String,Object> baseSourceParams)
user
- The userbaseSourceParams
- The base source params to be merge with the params stored in the user prefpublic Map<String,Object> hasUserPrefImage(UserIdentity user)
user
- The userprivate Map<String,Object> _getRawUserPrefImage(UserIdentity user)
user
- The userpublic ProfileImageProvider.UserProfileImage getUploadedImage(UserIdentity user, String uploadId)
user
- The useruploadId
- The upload identifierpublic BufferedImage cropUploadedImage(InputStream is) throws IOException
is
- The input stream of the uploaded fileIOException
- If an exception occurs while manipulating streamspublic boolean hasLocalImage(String localFileId)
localFileId
- The local file identifierpublic ProfileImageProvider.UserProfileImage getLocalImage(UserIdentity user, String localFileId)
user
- The userlocalFileId
- The local file identifierprotected Source _getLocalImageSource(String localFileId) throws IOException
localFileId
- The local file identifierIOException
- If an error occurs while resolving the source uripublic List<String> getLocalImageIds()
protected Map<String,String> _getLocalImagePaths()
private void _initializeLocalImagePaths()
public boolean hasInitialsImage(UserIdentity userIdentity)
userIdentity
- The userpublic ProfileImageProvider.UserProfileImage getInitialsImage(UserIdentity userIdentity)
userIdentity
- The userprotected Source _getInitialsImageSource(String initial) throws IOException
initial
- The initialIOException
- If an error occurs while resolving the source uriprotected InputStream _addImageBackground(UserIdentity user, InputStream is) throws IOException
user
- The user used to determine which background will be used (based on a hash representation of the login)is
- The inputstream of the imageIOException
- If any sort of IO error occurs during the processprotected Source _getInitialsBackgroundSource(UserIdentity user) throws IOException
user
- The userIOException
- If an error occurs while resolving the source uriprivate void _initializeInitialsBackgroundPaths()