diff options
Diffstat (limited to 'src/main/java/com')
19 files changed, 129 insertions, 40 deletions
diff --git a/src/main/java/com/gitblit/AvatarGenerator.java b/src/main/java/com/gitblit/AvatarGenerator.java new file mode 100644 index 00000000..76f189de --- /dev/null +++ b/src/main/java/com/gitblit/AvatarGenerator.java @@ -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 index 00000000..796a1a88 --- /dev/null +++ b/src/main/java/com/gitblit/GravatarGenerator.java @@ -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); + } + } + +} diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java index 359040b5..39cdbb41 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java @@ -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; + } + + } diff --git a/src/main/java/com/gitblit/wicket/GitblitWicketApp.java b/src/main/java/com/gitblit/wicket/GitblitWicketApp.java index 3041c5da..b3ca2073 100644 --- a/src/main/java/com/gitblit/wicket/GitblitWicketApp.java +++ b/src/main/java/com/gitblit/wicket/GitblitWicketApp.java @@ -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 diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java index 3754f3ef..b56d721c 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java @@ -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, diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java index 072bb200..0a1a68d4 100644 --- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java +++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java @@ -44,7 +44,7 @@ import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.CommitLegendPanel;
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
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;
@@ -133,7 +133,7 @@ public class CommitPage 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,
diff --git a/src/main/java/com/gitblit/wicket/pages/ForksPage.java b/src/main/java/com/gitblit/wicket/pages/ForksPage.java index 9fd7f4db..93fc9faf 100644 --- a/src/main/java/com/gitblit/wicket/pages/ForksPage.java +++ b/src/main/java/com/gitblit/wicket/pages/ForksPage.java @@ -34,7 +34,7 @@ import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
public class ForksPage extends RepositoryPage {
@@ -63,7 +63,7 @@ public class ForksPage extends RepositoryPage { user = new UserModel(repository.projectPath.substring(1));
}
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);
- item.add(new GravatarImage("anAvatar", ident, 20));
+ item.add(new AvatarImage("anAvatar", ident, 20));
if (pageRepository.equals(repository)) {
// do not link to self
item.add(new Label("aProject", user.getDisplayName()));
diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java index 37e98702..6d7ebd85 100644 --- a/src/main/java/com/gitblit/wicket/pages/RootPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java @@ -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())); } diff --git a/src/main/java/com/gitblit/wicket/pages/TagPage.java b/src/main/java/com/gitblit/wicket/pages/TagPage.java index 9eed2797..ffeea6f2 100644 --- a/src/main/java/com/gitblit/wicket/pages/TagPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TagPage.java @@ -31,7 +31,7 @@ import com.gitblit.utils.JGitUtils; import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.CacheControl.LastModified;
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.RefsPanel;
@@ -77,7 +77,7 @@ public class TagPage extends RepositoryPage { linkClass = CommitPage.class;
break;
}
- add(new GravatarImage("taggerAvatar", tagRef.getAuthorIdent()));
+ add(new AvatarImage("taggerAvatar", tagRef.getAuthorIdent()));
add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));
add(new Label("tagId", tagRef.getObjectId().getName()));
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index 254d3c9b..1aa89540 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -91,7 +91,7 @@ import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.BasePanel.JavascriptTextPrompt;
import com.gitblit.wicket.panels.CommentPanel;
import com.gitblit.wicket.panels.DiffStatPanel;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.IconAjaxLink;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.ShockWaveComponent;
@@ -312,7 +312,7 @@ public class TicketPage extends RepositoryPage { if (user == null) {
user = new UserModel(username);
}
- item.add(new GravatarImage("participant", user.getDisplayName(),
+ item.add(new AvatarImage("participant", user.getDisplayName(),
user.emailAddress, null, 25, true));
}
};
@@ -736,7 +736,7 @@ public class TicketPage extends RepositoryPage { } else {
// permit user to comment
Fragment newComment = new Fragment("newComment", "newCommentFragment", this);
- GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,
+ AvatarImage img = new AvatarImage("newCommentAvatar", user.username, user.emailAddress,
"gravatar-round", avatarWidth, true);
newComment.add(img);
CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);
@@ -816,7 +816,7 @@ public class TicketPage extends RepositoryPage { public void populateItem(final Item<RevCommit> item) {
RevCommit commit = item.getModelObject();
PersonIdent author = commit.getAuthorIdent();
- item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
+ item.add(new AvatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
item.add(new Label("author", commit.getAuthorIdent().getName()));
item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),
CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
@@ -987,12 +987,12 @@ public class TicketPage extends RepositoryPage { UserModel commenter = app().users().getUserModel(entry.author);
if (commenter == null) {
// unknown user
- container.add(new GravatarImage("changeAvatar", entry.author,
+ container.add(new AvatarImage("changeAvatar", entry.author,
entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
container.add(new Label("changeAuthor", entry.author.toLowerCase()));
} else {
// known user
- container.add(new GravatarImage("changeAvatar", commenter.getDisplayName(),
+ container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(),
commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,
avatarSize, true).setVisible(avatarSize > 0));
container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),
diff --git a/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java b/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java index 35513bb3..062df84e 100644 --- a/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java @@ -76,7 +76,7 @@ public class ActivityPanel extends BasePanel { .getWhen(), getTimeZone(), getTimeUtils()));
// avatar
- commitItem.add(new GravatarImage("avatar", commit.getAuthorIdent(), 40));
+ commitItem.add(new AvatarImage("avatar", commit.getAuthorIdent(), 40));
// 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/AvatarImage.html index 846a8f1b..846a8f1b 100644 --- a/src/main/java/com/gitblit/wicket/panels/GravatarImage.html +++ b/src/main/java/com/gitblit/wicket/panels/AvatarImage.html diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java b/src/main/java/com/gitblit/wicket/panels/AvatarImage.java index e4157577..99015612 100644 --- a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java +++ b/src/main/java/com/gitblit/wicket/panels/AvatarImage.java @@ -19,7 +19,6 @@ 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; @@ -29,36 +28,30 @@ import com.gitblit.wicket.WicketUtils; * @author James Moger * */ -public class GravatarImage extends BasePanel { +public class AvatarImage extends BasePanel { private static final long serialVersionUID = 1L; - public GravatarImage(String id, PersonIdent person) { + public AvatarImage(String id, PersonIdent person) { this(id, person, 0); } - public GravatarImage(String id, PersonIdent person, int width) { + public AvatarImage(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) { + public AvatarImage(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) { + public AvatarImage(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) { + public AvatarImage(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); - } + String url = app().buildAvatarUrl(username, emailaddress, cssClass, width, identicon); ExternalImage image = new ExternalImage("image", url); if (cssClass != null) { WicketUtils.setCssClass(image, cssClass); diff --git a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java index eb757501..249cd4ac 100644 --- a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java @@ -44,6 +44,6 @@ public class CommitHeaderPanel extends BasePanel { add(new Label("commitid", c.getName()));
add(new Label("author", c.getAuthorIdent().getName()));
add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
- add(new GravatarImage("authorAvatar", c.getAuthorIdent()));
+ add(new AvatarImage("authorAvatar", c.getAuthorIdent()));
}
}
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java b/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java index decfda50..d901945d 100644 --- a/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java @@ -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/ReflogPanel.java b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java index baefc6bd..2235fd3d 100644 --- a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java @@ -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) { diff --git a/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java b/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java index f37cc2aa..447e1789 100644 --- a/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java @@ -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 { diff --git a/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java b/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java index 2ac33d53..1fbe87cd 100644 --- a/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java @@ -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); diff --git a/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java b/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java index 2bf5ee7b..063889b2 100644 --- a/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java +++ b/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java @@ -25,7 +25,7 @@ public class UserTitlePanel extends BasePanel { public UserTitlePanel(String wicketId, UserModel user, String title) {
super(wicketId);
- add(new GravatarImage("userGravatar", user, "gravatar", 36, false));
+ add(new AvatarImage("userGravatar", user, "gravatar", 36, false));
add(new Label("userDisplayName", user.getDisplayName()));
add(new Label("userTitle", title));
}
|