Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.avatar; 16 : 17 : import com.google.gerrit.extensions.annotations.ExtensionPoint; 18 : import com.google.gerrit.extensions.restapi.NotImplementedException; 19 : import com.google.gerrit.server.IdentifiedUser; 20 : 21 : /** 22 : * Provide avatar URLs for specified user. 23 : * 24 : * <p>Invoked by Gerrit when Avatar image requests are made. 25 : */ 26 : @ExtensionPoint 27 : public interface AvatarProvider { 28 : 29 : /** 30 : * Get avatar URL. 31 : * 32 : * @param forUser The user for which to load an avatar image 33 : * @param imageSize A requested image size, in pixels. An imageSize of 0 indicates to use whatever 34 : * default size the provider determines. AvatarProviders may ignore the requested image size. 35 : * The web interface will resize any image to match imageSize, so ideally the provider should 36 : * return an image sized correctly. 37 : * @return a URL of an avatar image for the specified user. A return value of {@code null} is 38 : * acceptable, and results in the server responding with a 404. This will hide the avatar 39 : * image in the web UI. 40 : */ 41 : String getUrl(IdentifiedUser forUser, int imageSize); 42 : 43 : /** 44 : * Gets a URL for a user to modify their avatar image. 45 : * 46 : * @param forUser The user wishing to change their avatar image 47 : * @return a URL the user should visit to modify their avatar, or null if modification is not 48 : * possible. 49 : */ 50 : String getChangeAvatarUrl(IdentifiedUser forUser); 51 : 52 : /** 53 : * Set the avatar image URL for specified user and specified size. 54 : * 55 : * <p>It is the default method (not interface method declaration) for back compatibility with old 56 : * code. 57 : * 58 : * @param forUser The user for which need to change the avatar image. 59 : * @param url The avatar image URL for the specified user. 60 : * @param imageSize The avatar image size in pixels. If imageSize have a zero value this indicates 61 : * to set URL for default size that provider determines. 62 : * @throws Exception if an error occurred. 63 : */ 64 : default void setUrl(IdentifiedUser forUser, String url, int imageSize) throws Exception { 65 0 : throw new NotImplementedException(); 66 : } 67 : 68 : /** 69 : * Indicates whether or not the provider allows to set the image URL. 70 : * 71 : * <p>It is the default method (not interface method declaration) for back compatibility with old 72 : * code. 73 : * 74 : * @return 75 : * <ul> 76 : * <li>true - avatar image URL could be set. 77 : * <li>false - avatar image URL could not be set (for example not Implemented). 78 : * </ul> 79 : */ 80 : default boolean canSetUrl() { 81 0 : return false; 82 : } 83 : }