Package org.ametys.plugins.core.ui.user
Class DefaultProfileImageProvider
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.plugins.core.ui.user.SafeProfileImageProvider
org.ametys.plugins.core.ui.user.DefaultProfileImageProvider
- All Implemented Interfaces:
ProfileImageProvider
,Component
,Contextualizable
,LogEnabled
,Serviceable
public class DefaultProfileImageProvider
extends SafeProfileImageProvider
implements Contextualizable, Component
Helper providing images that are used for user profiles
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Profile image source enumNested classes/interfaces inherited from interface org.ametys.plugins.core.ui.user.ProfileImageProvider
ProfileImageProvider.UserProfileImage
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Name of the avatar directoryThe map of paths to avatar images, keys are idprotected static final String
Name of the initials directoryOrdered list of paths to available backgrounds for 'initials' imagesprotected JSONUtils
JSON Utilsprotected UploadManager
Upload managerprotected UserPreferencesManager
User pref managerstatic final String
The pref context for user profilestatic final String
The profile image user pref idFields inherited from class org.ametys.plugins.core.ui.user.SafeProfileImageProvider
__DEFAULT_FILE_NAME, __USER_PROFILES_DIR_PATH, _sourceResolver, _userManager
Fields inherited from interface org.ametys.plugins.core.ui.user.ProfileImageProvider
ROLE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected InputStream
_addImageBackground
(UserIdentity user, InputStream is) Add a background to an initials image_extractBase64Parameters
(Request request, UserIdentity user) Extracts parameters for a local image_extractLocalImageParameters
(Request request, UserIdentity user) Extracts parameters for a local image_extractSourceParameters
(UserIdentity user, DefaultProfileImageProvider.ProfileImageSource profileImageSource) Provides the necessary parameters to retrieves the image from a given source._extractUploadParameters
(Request request, UserIdentity user) Extracts parameters for an uploaded imageprotected Source
Get the background image for the initials source.protected Source
_getInitialsImageSource
(String initial) Get the source of the initials imageGet the map containing the relative path for each local image.protected Source
_getLocalImageSource
(String localFileId) Get the source of a local imagevoid
contextualize
(Context context) Automatically crop the image to 64x64 pixels.getBase64Image
(UserIdentity user, String data, String filename) Get the image from a base 64 stringgetImage
(UserIdentity user, String imageSource, int size, int maxSize) Get the avatargetImage
(DefaultProfileImageProvider.ProfileImageSource source, UserIdentity user, Map<String, Object> sourceParams) Get the image input streamgetInitialsImage
(UserIdentity userIdentity) Get the image with user initialsgetLocalImage
(UserIdentity user, String localFileId) Get the local imageGet the list of local image identifiersgetProfileImageSource
(String imageSourceStr) Get the profile image source given a source input stringgetUploadedImage
(UserIdentity user, String uploadId) Get the uploaded imagegetUserPrefImage
(UserIdentity user, Map<String, Object> baseSourceParams) Get the image from the user prefboolean
hasInitialsImage
(UserIdentity userIdentity) Test if the initials image is available for a given userboolean
hasLocalImage
(String localFileId) Test if the local image existshasUserPrefImage
(UserIdentity user) Test this user as a profile image set in its user prefvoid
service
(ServiceManager smanager) Methods inherited from class org.ametys.plugins.core.ui.user.SafeProfileImageProvider
getDefaultImage, getGravatarImage, hasGravatarImage
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
USER_PROFILE_PREF_CONTEXT
The pref context for user profile- See Also:
-
USERPREF_PROFILE_IMAGE
The profile image user pref id- See Also:
-
__AVATAR_DIR_NAME
Name of the avatar directory- See Also:
-
__INITIALS_DIR_NAME
Name of the initials directory- See Also:
-
__avatarPaths
The map of paths to avatar images, keys are id -
__initialsBgPaths
Ordered list of paths to available backgrounds for 'initials' images -
_uploadManager
Upload manager -
_userPreferencesManager
User pref manager -
_jsonUtils
JSON Utils
-
-
Constructor Details
-
DefaultProfileImageProvider
public DefaultProfileImageProvider()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classSafeProfileImageProvider
- Throws:
ServiceException
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getImage
public ProfileImageProvider.UserProfileImage getImage(UserIdentity user, String imageSource, int size, int maxSize) throws ProcessingException Description copied from interface:ProfileImageProvider
Get the avatar- Specified by:
getImage
in interfaceProfileImageProvider
- Overrides:
getImage
in classSafeProfileImageProvider
- Parameters:
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.- Returns:
- The image
- Throws:
ProcessingException
- If an error occurred
-
getProfileImageSource
Get the profile image source given a source input string- Parameters:
imageSourceStr
- The input string representing the source- Returns:
- The profile image source.
-
_extractSourceParameters
protected Map<String,Object> _extractSourceParameters(UserIdentity user, DefaultProfileImageProvider.ProfileImageSource profileImageSource) throws ResourceNotFoundException Provides the necessary parameters to retrieves the image from a given source.- Parameters:
user
- The userprofileImageSource
- The image source type- Returns:
- A map of parameters
- Throws:
ResourceNotFoundException
- In case of a unhandled source type or if parameters could not be extracted
-
_extractUploadParameters
Extracts parameters for an uploaded image- Parameters:
request
- The requestuser
- The user- Returns:
- A map containing the uploaded file id (key=id)
-
_extractLocalImageParameters
Extracts parameters for a local image- Parameters:
request
- The requestuser
- The user- Returns:
- A map containing the local image id (key=id)
-
_extractBase64Parameters
Extracts parameters for a local image- Parameters:
request
- The requestuser
- The user- Returns:
- A map containing the local image id (key=id)
-
getImage
public ProfileImageProvider.UserProfileImage getImage(DefaultProfileImageProvider.ProfileImageSource source, UserIdentity user, Map<String, Object> sourceParams) Get the image input stream- Parameters:
source
- The image source typeuser
- The usersourceParams
- The parameters used by the source- Returns:
- The UserProfileImage for the image or null if not found
-
getBase64Image
public ProfileImageProvider.UserProfileImage getBase64Image(UserIdentity user, String data, String filename) Get the image from a base 64 string- Parameters:
user
- The userdata
- The base64 data representing the imagefilename
- The filename or null if not known- Returns:
- The UserProfileImage for the image or null if not set
-
getUserPrefImage
public ProfileImageProvider.UserProfileImage getUserPrefImage(UserIdentity user, Map<String, Object> baseSourceParams) Get the image from the user pref- Parameters:
user
- The userbaseSourceParams
- The base source params to be merge with the params stored in the user pref- Returns:
- The UserProfileImage for the image or null if not set
-
hasUserPrefImage
Test this user as a profile image set in its user pref- Parameters:
user
- The user- Returns:
- The map stored in the user pref
-
getUploadedImage
Get the uploaded image- Parameters:
user
- The useruploadId
- The upload identifier- Returns:
- The UserProfileImage for the image or null if not found
-
cropUploadedImage
Automatically crop the image to 64x64 pixels.- Parameters:
is
- The input stream of the uploaded file- Returns:
- The base64 string
- Throws:
IOException
- If an exception occurs while manipulating streams
-
hasLocalImage
Test if the local image exists- Parameters:
localFileId
- The local file identifier- Returns:
- True if the image exists
-
getLocalImage
Get the local image- Parameters:
user
- The userlocalFileId
- The local file identifier- Returns:
- The UserProfileImage for the image or null if not found
-
_getLocalImageSource
Get the source of a local image- Parameters:
localFileId
- The local file identifier- Returns:
- The source or null
- Throws:
IOException
- If an error occurs while resolving the source uri
-
getLocalImageIds
Get the list of local image identifiers- Returns:
- Ordered list of identifiers
-
_getLocalImagePaths
Get the map containing the relative path for each local image. Create the map if not existing yet.- Returns:
- Map where keys are ids and values are the relative paths
-
hasInitialsImage
Test if the initials image is available for a given user- Parameters:
userIdentity
- The user- Returns:
- True if the image exists
-
getInitialsImage
Get the image with user initials- Parameters:
userIdentity
- The user- Returns:
- The UserProfileImage for the image or null if not found
-
_getInitialsImageSource
Get the source of the initials image- Parameters:
initial
- The initial- Returns:
- The source
- Throws:
IOException
- If an error occurs while resolving the source uri
-
_addImageBackground
Add a background to an initials image- Parameters:
user
- The user used to determine which background will be used (based on a hash representation of the login)is
- The inputstream of the image- Returns:
- The inputstream of the final image with the background
- Throws:
IOException
- If any sort of IO error occurs during the process
-
_getInitialsBackgroundSource
Get the background image for the initials source. The chosen background depend on the user login- Parameters:
user
- The user- Returns:
- The source
- Throws:
IOException
- If an error occurs while resolving the source uri
-