]> source.dussan.org Git - gitblit.git/commitdiff
First draft for a customized avatar image
authorFabrice Bacchella <fbacchella@spamcop.net>
Wed, 3 Jun 2015 15:10:16 +0000 (17:10 +0200)
committerJames Moger <james.moger@gitblit.com>
Mon, 15 Jun 2015 15:55:05 +0000 (11:55 -0400)
23 files changed:
src/main/distrib/data/defaults.properties
src/main/java/com/gitblit/AvatarGenerator.java [new file with mode: 0644]
src/main/java/com/gitblit/GravatarGenerator.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/GitblitWicketApp.java
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
src/main/java/com/gitblit/wicket/pages/CommitPage.java
src/main/java/com/gitblit/wicket/pages/ForksPage.java
src/main/java/com/gitblit/wicket/pages/RootPage.java
src/main/java/com/gitblit/wicket/pages/TagPage.java
src/main/java/com/gitblit/wicket/pages/TicketPage.java
src/main/java/com/gitblit/wicket/panels/ActivityPanel.java
src/main/java/com/gitblit/wicket/panels/AvatarImage.html [new file with mode: 0644]
src/main/java/com/gitblit/wicket/panels/AvatarImage.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java
src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
src/main/java/com/gitblit/wicket/panels/GravatarImage.html [deleted file]
src/main/java/com/gitblit/wicket/panels/GravatarImage.java [deleted file]
src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
src/main/java/com/gitblit/wicket/panels/TicketListPanel.java
src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java
src/test/java/com/gitblit/tests/GravatarTest.java [new file with mode: 0644]

index c17506894554026f6dc18cf544e5730cb88ae83f..aa0d2cfaae891836ba7bce6e55ae5fc5341a692d 100644 (file)
@@ -975,6 +975,13 @@ web.useResponsiveLayout = true
 # SINCE 0.8.0
 web.allowGravatar = true
 
+# Define which class will generate the avatar URL.
+# This class must inherit from com.gitblit.AvatarGenerator
+# It must use a no argument constructor
+#
+# SINCE 1.7.0
+web.avatarClass = com.gitblit.GravatarGenerator
+
 # Allow dynamic zip downloads.
 #
 # SINCE 0.5.0   
diff --git a/src/main/java/com/gitblit/AvatarGenerator.java b/src/main/java/com/gitblit/AvatarGenerator.java
new file mode 100644 (file)
index 0000000..76f189d
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2015 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+public abstract class AvatarGenerator {
+
+       public abstract String getURL(String username, String emailaddress, boolean identicon, int width);
+
+       /**
+        * A method that can extract custom settings for the avatar generator
+        * The default does nothing, it can be overridden
+        *
+        * @param settings
+        */
+       public void configure(IStoredSettings settings) {
+
+       }
+
+}
diff --git a/src/main/java/com/gitblit/GravatarGenerator.java b/src/main/java/com/gitblit/GravatarGenerator.java
new file mode 100644 (file)
index 0000000..796a1a8
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2015 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+import com.gitblit.utils.ActivityUtils;
+
+public class GravatarGenerator extends AvatarGenerator {
+
+       public String getURL(String username, String emailaddress,
+                       boolean identicon, int width) {
+               String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
+               if (identicon) {
+                       return ActivityUtils.getGravatarIdenticonUrl(email, width);
+               } else {
+                       return ActivityUtils.getGravatarThumbnailUrl(email, width);
+               }
+       }
+
+}
index 359040b5376b43fa5d2b67f4cb9a5f74288aacfb..39cdbb41f0c1227fad8c8d71423af416c60ba6c5 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.wicket.protocol.http.WebApplication;
 import ro.fortsoft.pf4j.PluginState;
 import ro.fortsoft.pf4j.PluginWrapper;
 
+import com.gitblit.AvatarGenerator;
 import com.gitblit.IStoredSettings;
 import com.gitblit.Keys;
 import com.gitblit.extensions.GitblitWicketPlugin;
@@ -250,12 +251,15 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp {
                        }
                }
 
-                // customize the Wicket class resolver to load from plugins
+               // customize the Wicket class resolver to load from plugins
                IClassResolver coreResolver = getApplicationSettings().getClassResolver();
-        PluginClassResolver classResolver = new PluginClassResolver(coreResolver, pluginManager);
-        getApplicationSettings().setClassResolver(classResolver);
+               PluginClassResolver classResolver = new PluginClassResolver(coreResolver, pluginManager);
+               getApplicationSettings().setClassResolver(classResolver);
 
                getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
+
+               buildAvatarGenerator();
+
        }
 
        /* (non-Javadoc)
@@ -476,4 +480,30 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp {
        public static GitBlitWebApp get() {
                return (GitBlitWebApp) WebApplication.get();
        }
+
+       AvatarGenerator generator = null;
+       @SuppressWarnings("unchecked")
+       private void buildAvatarGenerator() {
+               Class<AvatarGenerator> clazz;
+               try {
+                       clazz = (Class<AvatarGenerator>) getClass().getClassLoader().loadClass(settings.getString(Keys.web.avatarClass, "com.gitblit.GravatarGenerator"));
+                       generator = clazz.newInstance();
+                       generator.configure(settings);
+               } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException e) {
+                       throw new RuntimeException(e);
+               }
+
+       }
+
+       public String buildAvatarUrl(String username, String emailaddress, String cssClass, int width, boolean identicon) {
+               if (width <= 0) {
+                       width = 50;
+               }
+               if(generator != null) {
+                       return (String) generator.getURL(username, emailaddress, identicon, width);
+               }
+               return null;
+       }
+
+
 }
index 3041c5da01203ed544b06b0dd7acc9fc143bbeaf..b3ca20734a5c34cd60322682e3676a196c22e455 100644 (file)
@@ -75,4 +75,6 @@ public interface GitblitWicketApp {
 
        public abstract TimeZone getTimezone();
 
+       public String buildAvatarUrl(String username, String emailaddress, String cssClass, int width, boolean identicon);
+
 }
\ No newline at end of file
index 3754f3eff0afd4d865d46b49bfe1555e3506645c..b56d721c64209c9ce53b6d8c42f20e572a42642c 100644 (file)
@@ -47,7 +47,7 @@ import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.CommitHeaderPanel;
 import com.gitblit.wicket.panels.CommitLegendPanel;
 import com.gitblit.wicket.panels.DiffStatPanel;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
 import com.gitblit.wicket.panels.LinkPanel;
 import com.gitblit.wicket.panels.RefsPanel;
 
@@ -116,7 +116,7 @@ public class CommitDiffPage extends RepositoryPage {
                                item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
                                item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
                                                Constants.SearchType.AUTHOR));
-                               item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
+                               item.add(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
                                item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
                                                .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
                                item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
index 072bb20032b00a7a45d9c27900b868ff1a2f2fad..0a1a68d46ac69f09c458511ee92221c4b70fefb2 100644 (file)
@@ -44,7 +44,7 @@ import com.gitblit.wicket.panels.CommitHeaderPanel;
 import com.gitblit.wicket.panels.CommitLegendPanel;\r
 import com.gitblit.wicket.panels.CompressedDownloadsPanel;\r
 import com.gitblit.wicket.panels.DiffStatPanel;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
 import com.gitblit.wicket.panels.LinkPanel;\r
 import com.gitblit.wicket.panels.RefsPanel;\r
 \r
@@ -133,7 +133,7 @@ public class CommitPage extends RepositoryPage {
                                item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));\r
                                item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),\r
                                                Constants.SearchType.AUTHOR));\r
-                               item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));\r
+                               item.add(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));\r
                                item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef\r
                                                .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
                                item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,\r
index 9fd7f4db7f36538d53a51fc48503f1559f50353d..93fc9fafd8ad3b648d5aad544229bad907a85023 100644 (file)
@@ -34,7 +34,7 @@ import com.gitblit.models.UserModel;
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
 import com.gitblit.wicket.panels.LinkPanel;\r
 \r
 public class ForksPage extends RepositoryPage {\r
@@ -63,7 +63,7 @@ public class ForksPage extends RepositoryPage {
                                                user = new UserModel(repository.projectPath.substring(1));\r
                                        }\r
                                        PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);\r
-                                       item.add(new GravatarImage("anAvatar", ident, 20));\r
+                                       item.add(new AvatarImage("anAvatar", ident, 20));\r
                                        if (pageRepository.equals(repository)) {\r
                                                // do not link to self\r
                                                item.add(new Label("aProject", user.getDisplayName()));\r
index 37e98702c3ee1a56e835043501b6367bd221978e..6d7ebd8552f01f54d7ed08bc5fe675bfe88f1dee 100644 (file)
@@ -73,7 +73,7 @@ import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.GitBlitWebSession;
 import com.gitblit.wicket.SessionlessForm;
 import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
 import com.gitblit.wicket.panels.LinkPanel;
 import com.gitblit.wicket.panels.NavigationPanel;
 
@@ -612,7 +612,7 @@ public abstract class RootPage extends BasePage {
                        boolean standardLogin = authenticationType.isStandard();
 
                        if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
-                               add(new GravatarImage("username", user, "navbarGravatar", 20, false));
+                               add(new AvatarImage("username", user, "navbarGravatar", 20, false));
                        } else {
                                add(new Label("username", user.getDisplayName()));
                        }
index 9eed27972f2d1856c4419176cafc8665a4e33630..ffeea6f234160ce84b539549b9e72afc6448e7a8 100644 (file)
@@ -31,7 +31,7 @@ import com.gitblit.utils.JGitUtils;
 import com.gitblit.wicket.CacheControl;\r
 import com.gitblit.wicket.CacheControl.LastModified;\r
 import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
 import com.gitblit.wicket.panels.LinkPanel;\r
 import com.gitblit.wicket.panels.RefsPanel;\r
 \r
@@ -77,7 +77,7 @@ public class TagPage extends RepositoryPage {
                        linkClass = CommitPage.class;\r
                        break;\r
                }\r
-               add(new GravatarImage("taggerAvatar", tagRef.getAuthorIdent()));\r
+               add(new AvatarImage("taggerAvatar", tagRef.getAuthorIdent()));\r
 \r
                add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));\r
                add(new Label("tagId", tagRef.getObjectId().getName()));\r
index 254d3c9be0156a746edf7c5bce04fdf76910fa81..1aa89540dd33983d4078907d240d64c1910d1f8e 100644 (file)
@@ -91,7 +91,7 @@ import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.BasePanel.JavascriptTextPrompt;\r
 import com.gitblit.wicket.panels.CommentPanel;\r
 import com.gitblit.wicket.panels.DiffStatPanel;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
 import com.gitblit.wicket.panels.IconAjaxLink;\r
 import com.gitblit.wicket.panels.LinkPanel;\r
 import com.gitblit.wicket.panels.ShockWaveComponent;\r
@@ -312,7 +312,7 @@ public class TicketPage extends RepositoryPage {
                                        if (user == null) {\r
                                                user = new UserModel(username);\r
                                        }\r
-                                       item.add(new GravatarImage("participant", user.getDisplayName(),\r
+                                       item.add(new AvatarImage("participant", user.getDisplayName(),\r
                                                        user.emailAddress, null, 25, true));\r
                                }\r
                        };\r
@@ -736,7 +736,7 @@ public class TicketPage extends RepositoryPage {
                } else {\r
                        // permit user to comment\r
                        Fragment newComment = new Fragment("newComment", "newCommentFragment", this);\r
-                       GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,\r
+                       AvatarImage img = new AvatarImage("newCommentAvatar", user.username, user.emailAddress,\r
                                        "gravatar-round", avatarWidth, true);\r
                        newComment.add(img);\r
                        CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);\r
@@ -816,7 +816,7 @@ public class TicketPage extends RepositoryPage {
                                public void populateItem(final Item<RevCommit> item) {\r
                                        RevCommit commit = item.getModelObject();\r
                                        PersonIdent author = commit.getAuthorIdent();\r
-                                       item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));\r
+                                       item.add(new AvatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));\r
                                        item.add(new Label("author", commit.getAuthorIdent().getName()));\r
                                        item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),\r
                                                        CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));\r
@@ -987,12 +987,12 @@ public class TicketPage extends RepositoryPage {
                UserModel commenter = app().users().getUserModel(entry.author);\r
                if (commenter == null) {\r
                        // unknown user\r
-                       container.add(new GravatarImage("changeAvatar", entry.author,\r
+                       container.add(new AvatarImage("changeAvatar", entry.author,\r
                                        entry.author, null, avatarSize, false).setVisible(avatarSize > 0));\r
                        container.add(new Label("changeAuthor", entry.author.toLowerCase()));\r
                } else {\r
                        // known user\r
-                       container.add(new GravatarImage("changeAvatar", commenter.getDisplayName(),\r
+                       container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(),\r
                                        commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,\r
                                                        avatarSize, true).setVisible(avatarSize > 0));\r
                        container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),\r
index 35513bb392f6daece2f5aee90a48816d1fd6c9c5..062df84e80417b8509401f3ec66e0e308b0df295 100644 (file)
@@ -76,7 +76,7 @@ public class ActivityPanel extends BasePanel {
                                                                .getWhen(), getTimeZone(), getTimeUtils()));\r
 \r
                                                // avatar\r
-                                               commitItem.add(new GravatarImage("avatar", commit.getAuthorIdent(), 40));\r
+                                               commitItem.add(new AvatarImage("avatar", commit.getAuthorIdent(), 40));\r
 \r
                                                // merge icon\r
                                                if (commit.getParentCount() > 1) {\r
diff --git a/src/main/java/com/gitblit/wicket/panels/AvatarImage.html b/src/main/java/com/gitblit/wicket/panels/AvatarImage.html
new file mode 100644 (file)
index 0000000..846a8f1
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en">\r
+<wicket:panel>\r
+<img wicket:id="image"></img>\r
+</wicket:panel>\r
+</html>
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/AvatarImage.java b/src/main/java/com/gitblit/wicket/panels/AvatarImage.java
new file mode 100644 (file)
index 0000000..9901561
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import org.eclipse.jgit.lib.PersonIdent;
+
+import com.gitblit.Keys;
+import com.gitblit.models.UserModel;
+import com.gitblit.wicket.ExternalImage;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * Represents a Gravatar image.
+ *
+ * @author James Moger
+ *
+ */
+public class AvatarImage extends BasePanel {
+
+       private static final long serialVersionUID = 1L;
+
+       public AvatarImage(String id, PersonIdent person) {
+               this(id, person, 0);
+       }
+
+       public AvatarImage(String id, PersonIdent person, int width) {
+               this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
+       }
+
+       public AvatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
+               this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
+       }
+
+       public AvatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
+               this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
+       }
+
+       public AvatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
+               super(id);
+
+               String url = app().buildAvatarUrl(username, emailaddress, cssClass, width, identicon);
+               ExternalImage image = new ExternalImage("image", url);
+               if (cssClass != null) {
+                       WicketUtils.setCssClass(image, cssClass);
+               }
+               add(image);
+               WicketUtils.setHtmlTooltip(image, username);
+               setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
+       }
+
+       public void setTooltip(String tooltip) {
+               WicketUtils.setHtmlTooltip(get("image"), tooltip);
+       }
+}
\ No newline at end of file
index eb757501dbe5c794c392a4feb986d3fa8857703c..249cd4ace70595eefd88e818bc9ae5675b8daea0 100644 (file)
@@ -44,6 +44,6 @@ public class CommitHeaderPanel extends BasePanel {
                add(new Label("commitid", c.getName()));\r
                add(new Label("author", c.getAuthorIdent().getName()));\r
                add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
-               add(new GravatarImage("authorAvatar", c.getAuthorIdent()));\r
+               add(new AvatarImage("authorAvatar", c.getAuthorIdent()));\r
        }\r
 }
\ No newline at end of file
index decfda5052b7da131eae977438a9b1355ce510cb..d901945d40206c47c01034d2ec150932feabfb84 100644 (file)
@@ -216,7 +216,7 @@ public class DigestsPanel extends BasePanel {
                                                final RepositoryCommit commit = commitItem.getModelObject();
 
                                                // author gravatar
-                                               commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+                                               commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
 
                                                // merge icon
                                                if (commit.getParentCount() > 1) {
diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.html b/src/main/java/com/gitblit/wicket/panels/GravatarImage.html
deleted file mode 100644 (file)
index 846a8f1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml"  \r
-      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
-      xml:lang="en"  \r
-      lang="en">\r
-<wicket:panel>\r
-<img wicket:id="image"></img>\r
-</wicket:panel>\r
-</html>
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java b/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
deleted file mode 100644 (file)
index e415757..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2011 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import org.eclipse.jgit.lib.PersonIdent;
-
-import com.gitblit.Keys;
-import com.gitblit.models.UserModel;
-import com.gitblit.utils.ActivityUtils;
-import com.gitblit.wicket.ExternalImage;
-import com.gitblit.wicket.WicketUtils;
-
-/**
- * Represents a Gravatar image.
- *
- * @author James Moger
- *
- */
-public class GravatarImage extends BasePanel {
-
-       private static final long serialVersionUID = 1L;
-
-       public GravatarImage(String id, PersonIdent person) {
-               this(id, person, 0);
-       }
-
-       public GravatarImage(String id, PersonIdent person, int width) {
-               this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
-       }
-
-       public GravatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
-               this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
-       }
-
-       public GravatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
-               this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
-       }
-
-       public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
-               super(id);
-
-               String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
-               String url;
-               if (identicon) {
-                       url = ActivityUtils.getGravatarIdenticonUrl(email, width);
-               } else {
-                       url = ActivityUtils.getGravatarThumbnailUrl(email, width);
-               }
-               ExternalImage image = new ExternalImage("image", url);
-               if (cssClass != null) {
-                       WicketUtils.setCssClass(image, cssClass);
-               }
-               add(image);
-               WicketUtils.setHtmlTooltip(image, username);
-               setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
-       }
-
-       public void setTooltip(String tooltip) {
-               WicketUtils.setHtmlTooltip(get("image"), tooltip);
-       }
-}
\ No newline at end of file
index baefc6bdca23578061caa4fd7a17f58b538b1e9b..2235fd3d1572d4ae2feddd8c91d581ebc3f905eb 100644 (file)
@@ -271,7 +271,7 @@ public class ReflogPanel extends BasePanel {
                                                final RepositoryCommit commit = commitItem.getModelObject();
 
                                                // author gravatar
-                                               commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+                                               commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
 
                                                // merge icon
                                                if (commit.getParentCount() > 1) {
index f37cc2aa00a2e0f8d78eaa2b2086d311003e0bf8..447e17895a6b3da9171bc38d449a3cf6f76d80dd 100644 (file)
@@ -145,7 +145,7 @@ public class RegistrantPermissionsPanel extends BasePanel {
                                        }
 
                                        Fragment userFragment = new Fragment("registrant", "userRegistrant", RegistrantPermissionsPanel.this);
-                                       userFragment.add(new GravatarImage("userAvatar", ident, 20));
+                                       userFragment.add(new AvatarImage("userAvatar", ident, 20));
                                        userFragment.add(new Label("userName", entry.registrant));
                                        item.add(userFragment);
                                } else {
index 2ac33d5327379dd2e8f1456e4837b8ec9d0442a8..1fbe87cd95ddddc5d4fd59ce0c5fb8bc18e63298 100644 (file)
@@ -156,7 +156,7 @@ public class TicketListPanel extends BasePanel {
                                        if (responsible == null) {
                                                responsible = new UserModel(ticket.responsible);
                                        }
-                                       GravatarImage avatar = new GravatarImage("responsible", responsible.getDisplayName(),
+                                       AvatarImage avatar = new AvatarImage("responsible", responsible.getDisplayName(),
                                                        responsible.emailAddress, null, 16, true);
                                        avatar.setTooltip(getString("gb.responsible") + ": " + responsible.getDisplayName());
                                        item.add(avatar);
index 2bf5ee7bbbbe689172b9ee19da437d3e07aead5f..063889b2f913410d1a0aff4fcb9c244a3ddb7da7 100644 (file)
@@ -25,7 +25,7 @@ public class UserTitlePanel extends BasePanel {
 \r
        public UserTitlePanel(String wicketId, UserModel user, String title) {\r
                super(wicketId);\r
-               add(new GravatarImage("userGravatar", user, "gravatar", 36, false));\r
+               add(new AvatarImage("userGravatar", user, "gravatar", 36, false));\r
                add(new Label("userDisplayName", user.getDisplayName()));\r
                add(new Label("userTitle", title));\r
        }\r
diff --git a/src/test/java/com/gitblit/tests/GravatarTest.java b/src/test/java/com/gitblit/tests/GravatarTest.java
new file mode 100644 (file)
index 0000000..1fea843
--- /dev/null
@@ -0,0 +1,77 @@
+package com.gitblit.tests;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.manager.AuthenticationManager;
+import com.gitblit.manager.FederationManager;
+import com.gitblit.manager.GitblitManager;
+import com.gitblit.manager.IAuthenticationManager;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblit;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.IServicesManager;
+import com.gitblit.manager.IUserManager;
+import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
+import com.gitblit.manager.ProjectManager;
+import com.gitblit.manager.RepositoryManager;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.manager.ServicesManager;
+import com.gitblit.manager.UserManager;
+import com.gitblit.tests.mock.MemorySettings;
+import com.gitblit.tickets.FileTicketService;
+import com.gitblit.tickets.ITicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
+import com.gitblit.transport.ssh.MemoryKeyManager;
+import com.gitblit.utils.IdGenerator;
+import com.gitblit.utils.WorkQueue;
+import com.gitblit.utils.XssFilter;
+import com.gitblit.utils.XssFilter.AllowXssFilter;
+import com.gitblit.wicket.GitBlitWebApp;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class GravatarTest extends GitblitUnitTest {
+
+       public static  class SomeModule extends AbstractModule {
+               private final IStoredSettings settings = new MemorySettings();
+               SomeModule() {
+                       settings.overrideSetting(Keys.web.avatarClass, "com.gitblit.GravatarGenerator");
+               }
+               @Override 
+               protected void configure() {
+                       bind(IGitblit.class).to(GitblitManager.class);
+                       bind(IAuthenticationManager.class).to(AuthenticationManager.class);
+                       bind(IFederationManager.class).to(FederationManager.class);
+                       bind(INotificationManager.class).to(NotificationManager.class);
+                       bind(IPluginManager.class).to(PluginManager.class);
+                       bind(IRepositoryManager.class).to(RepositoryManager.class);
+                       bind(IProjectManager.class).to(ProjectManager.class);
+                       bind(IRuntimeManager.class).to(RuntimeManager.class);
+                       bind(IUserManager.class).to(UserManager.class);
+                       bind(ITicketService.class).to(FileTicketService.class);
+                       bind(XssFilter.class).to(AllowXssFilter.class);
+                       bind(IStoredSettings.class).toInstance(settings);
+                       bind(IPublicKeyManager.class).to(MemoryKeyManager.class);
+                       bind(IServicesManager.class).to(ServicesManager.class);
+                       bind(WorkQueue.class).toInstance(new WorkQueue(new IdGenerator(), 0));
+               }
+       }
+
+       @Test
+       public void oneTest() {
+               Injector injector = Guice.createInjector(new SomeModule());
+               GitBlitWebApp webapp = injector.getInstance(GitBlitWebApp.class);
+               webapp.init();
+               Assert.assertNotNull(webapp.buildAvatarUrl("username", "emailaddress", "cssClass", 10, true));
+       }
+       
+}