001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.core.ui.user; 017 018import java.io.InputStream; 019 020import org.apache.cocoon.ProcessingException; 021 022import org.ametys.core.user.UserIdentity; 023 024/** 025 * Component providing images that are used for user profiles 026 */ 027public interface ProfileImageProvider 028{ 029 /** Avalon role */ 030 public static final String ROLE = ProfileImageProvider.class.getName(); 031 032 /** 033 * Get the avatar 034 * @param user The user 035 * @param imageSource The image source. Can be null to get the default one 036 * @param size The size in px. Can be 0. 037 * @param maxSize The maxSize in px. Can be 0. 038 * @return The image 039 * @throws ProcessingException If an error occurred 040 */ 041 public UserProfileImage getImage(UserIdentity user, String imageSource, int size, int maxSize) throws ProcessingException; 042 043 /** 044 * Basic structure holding necessary data representing an user profile image 045 */ 046 public static class UserProfileImage 047 { 048 private final InputStream _inputstream; 049 private final String _filename; 050 private final Long _length; 051 052 /** 053 * Constructor 054 * @param inputstream The image input stream 055 */ 056 public UserProfileImage(InputStream inputstream) 057 { 058 this(inputstream, null, null); 059 } 060 061 /** 062 * Constructor 063 * @param inputstream The image input stream 064 * @param filename The file name or null if unknown 065 * @param length The file length if known 066 */ 067 public UserProfileImage(InputStream inputstream, String filename, Long length) 068 { 069 _inputstream = inputstream; 070 _filename = filename; 071 _length = length; 072 } 073 074 /** 075 * Retrieves the input stream 076 * @return the input stream 077 */ 078 public InputStream getInputstream() 079 { 080 return _inputstream; 081 } 082 083 /** 084 * Retrieves the filename 085 * @return the filename or null if not defined 086 */ 087 public String getFilename() 088 { 089 return _filename; 090 } 091 092 /** 093 * Retrieves the length 094 * @return the length or null if unknown 095 */ 096 public Long getLength() 097 { 098 return _length; 099 } 100 } 101}