You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GravatarImage.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.panels;
  17. import java.text.MessageFormat;
  18. import org.apache.wicket.behavior.SimpleAttributeModifier;
  19. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  20. import org.apache.wicket.markup.html.link.Link;
  21. import org.apache.wicket.markup.html.panel.Panel;
  22. import org.eclipse.jgit.lib.PersonIdent;
  23. import com.gitblit.GitBlit;
  24. import com.gitblit.Keys;
  25. import com.gitblit.utils.ActivityUtils;
  26. import com.gitblit.utils.StringUtils;
  27. import com.gitblit.wicket.ExternalImage;
  28. import com.gitblit.wicket.WicketUtils;
  29. import com.gitblit.wicket.pages.GravatarProfilePage;
  30. /**
  31. * Represents a Gravatar image and links to the Gravatar profile page.
  32. *
  33. * @author James Moger
  34. *
  35. */
  36. public class GravatarImage extends Panel {
  37. private static final long serialVersionUID = 1L;
  38. public GravatarImage(String id, PersonIdent person) {
  39. this(id, person, 0);
  40. }
  41. public GravatarImage(String id, PersonIdent person, int width) {
  42. super(id);
  43. String email = person.getEmailAddress() == null ? person.getName().toLowerCase() : person.getEmailAddress().toLowerCase();
  44. String hash = StringUtils.getMD5(email);
  45. Link<Void> link = new BookmarkablePageLink<Void>("link", GravatarProfilePage.class,
  46. WicketUtils.newObjectParameter(hash));
  47. link.add(new SimpleAttributeModifier("target", "_blank"));
  48. String url = ActivityUtils.getGravatarThumbnailUrl(email, width);
  49. ExternalImage image = new ExternalImage("image", url);
  50. WicketUtils.setCssClass(image, "gravatar");
  51. link.add(image);
  52. WicketUtils.setHtmlTooltip(link,
  53. MessageFormat.format("View Gravatar profile for {0}", person.getName()));
  54. add(link);
  55. setVisible(GitBlit.getBoolean(Keys.web.allowGravatar, true));
  56. }
  57. }