From b57b9ec3edd2ca7e7e44190f85e3743cea822e3e Mon Sep 17 00:00:00 2001
From: Fabrice Bacchella <fbacchella@spamcop.net>
Date: Mon, 15 Jun 2015 11:55:05 -0400
Subject: [PATCH] First draft for a customized avatar image
---
src/main/java/com/gitblit/wicket/GitBlitWebApp.java | 78 ++++++++++++++++++++++++++++++++------
1 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
index 38dbf57..39cdbb4 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
@@ -32,6 +32,7 @@
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;
@@ -43,6 +44,7 @@
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.tickets.ITicketService;
import com.gitblit.transport.ssh.IPublicKeyManager;
@@ -90,7 +92,11 @@
import com.gitblit.wicket.pages.TreePage;
import com.gitblit.wicket.pages.UserPage;
import com.gitblit.wicket.pages.UsersPage;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+@Singleton
public class GitBlitWebApp extends WebApplication implements GitblitWicketApp {
private final Class<? extends WebPage> homePageClass = MyDashboardPage.class;
@@ -98,6 +104,10 @@
private final Class<? extends WebPage> newRepositoryPageClass = NewRepositoryPage.class;
private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>();
+
+ private final Provider<IPublicKeyManager> publicKeyManagerProvider;
+
+ private final Provider<ITicketService> ticketServiceProvider;
private final IStoredSettings settings;
@@ -113,8 +123,6 @@
private final IAuthenticationManager authenticationManager;
- private final IPublicKeyManager publicKeyManager;
-
private final IRepositoryManager repositoryManager;
private final IProjectManager projectManager;
@@ -123,19 +131,26 @@
private final IGitblit gitblit;
+ private final IServicesManager services;
+
+ @Inject
public GitBlitWebApp(
+ Provider<IPublicKeyManager> publicKeyManagerProvider,
+ Provider<ITicketService> ticketServiceProvider,
IRuntimeManager runtimeManager,
IPluginManager pluginManager,
INotificationManager notificationManager,
IUserManager userManager,
IAuthenticationManager authenticationManager,
- IPublicKeyManager publicKeyManager,
IRepositoryManager repositoryManager,
IProjectManager projectManager,
IFederationManager federationManager,
- IGitblit gitblit) {
+ IGitblit gitblit,
+ IServicesManager services) {
super();
+ this.publicKeyManagerProvider = publicKeyManagerProvider;
+ this.ticketServiceProvider = ticketServiceProvider;
this.settings = runtimeManager.getSettings();
this.xssFilter = runtimeManager.getXssFilter();
this.runtimeManager = runtimeManager;
@@ -143,11 +158,11 @@
this.notificationManager = notificationManager;
this.userManager = userManager;
this.authenticationManager = authenticationManager;
- this.publicKeyManager = publicKeyManager;
this.repositoryManager = repositoryManager;
this.projectManager = projectManager;
this.federationManager = federationManager;
this.gitblit = gitblit;
+ this.services = services;
}
@Override
@@ -175,9 +190,9 @@
// setup the standard gitweb-ish urls
mount("/repositories", RepositoriesPage.class);
- mount("/overview", OverviewPage.class, "r", "h");
+ mount("/overview", OverviewPage.class, "r");
mount("/summary", SummaryPage.class, "r");
- mount("/reflog", ReflogPage.class, "r", "h");
+ mount("/reflog", ReflogPage.class, "r");
mount("/commits", LogPage.class, "r", "h");
mount("/log", LogPage.class, "r", "h");
mount("/tags", TagsPage.class, "r");
@@ -208,7 +223,7 @@
mount("/mytickets", MyTicketsPage.class, "r", "h");
// setup the markup document urls
- mount("/docs", DocsPage.class, "r");
+ mount("/docs", DocsPage.class, "r", "h");
mount("/doc", DocPage.class, "r", "h", "f");
// federation urls
@@ -236,12 +251,15 @@
}
}
- // 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)
@@ -392,7 +410,7 @@
*/
@Override
public IPublicKeyManager keys() {
- return publicKeyManager;
+ return publicKeyManagerProvider.get();
}
/* (non-Javadoc)
@@ -428,11 +446,19 @@
}
/* (non-Javadoc)
+ * @see com.gitblit.wicket.Webapp#services()
+ */
+ @Override
+ public IServicesManager services() {
+ return services;
+ }
+
+ /* (non-Javadoc)
* @see com.gitblit.wicket.Webapp#tickets()
*/
@Override
public ITicketService tickets() {
- return gitblit.getTicketService();
+ return ticketServiceProvider.get();
}
/* (non-Javadoc)
@@ -454,4 +480,30 @@
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;
+ }
+
+
}
--
Gitblit v1.9.1