From 8daefa09d99774639a355c0dfa2b989fa1007f5f Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 11 Oct 2012 17:11:18 -0400
Subject: [PATCH] Created static repository close functions for unit testing and fixed Windows sharing violations
---
src/com/gitblit/wicket/WicketUtils.java | 177 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 144 insertions(+), 33 deletions(-)
diff --git a/src/com/gitblit/wicket/WicketUtils.java b/src/com/gitblit/wicket/WicketUtils.java
index a6435d5..e4eb29f 100644
--- a/src/com/gitblit/wicket/WicketUtils.java
+++ b/src/com/gitblit/wicket/WicketUtils.java
@@ -16,6 +16,7 @@
package com.gitblit.wicket;
import java.text.DateFormat;
+import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
@@ -39,13 +40,13 @@
import org.wicketstuff.googlecharts.AbstractChartData;
import org.wicketstuff.googlecharts.IChartData;
+import com.gitblit.Constants;
import com.gitblit.Constants.FederationPullStatus;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
import com.gitblit.models.FederationModel;
import com.gitblit.models.Metric;
import com.gitblit.utils.HttpUtils;
-import com.gitblit.utils.JGitUtils.SearchType;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
@@ -57,6 +58,12 @@
public static void setCssStyle(Component container, String value) {
container.add(new SimpleAttributeModifier("style", value));
+ }
+
+ public static void setCssBackground(Component container, String value) {
+ String background = MessageFormat.format("background-color:{0};",
+ StringUtils.getColor(value));
+ container.add(new SimpleAttributeModifier("style", background));
}
public static void setHtmlTooltip(Component container, String value) {
@@ -88,13 +95,13 @@
public static void setTicketCssClass(Component container, String state) {
String css = null;
if (state.equals("open")) {
- css = "bug_open";
+ css = "label label-important";
} else if (state.equals("hold")) {
- css = "bug_hold";
+ css = "label label-warning";
} else if (state.equals("resolved")) {
- css = "bug_resolved";
+ css = "label label-success";
} else if (state.equals("invalid")) {
- css = "bug_invalid";
+ css = "label";
}
if (css != null) {
setCssClass(container, css);
@@ -102,7 +109,7 @@
}
public static void setAlternatingBackground(Component c, int i) {
- String clazz = i % 2 == 0 ? "dark" : "light";
+ String clazz = i % 2 == 0 ? "light" : "dark";
setCssClass(c, clazz);
}
@@ -115,6 +122,7 @@
public static ContextImage getPullStatusImage(String wicketId, FederationPullStatus status) {
String filename = null;
switch (status) {
+ case MIRRORED:
case PULLED:
filename = "bullet_green.png";
break;
@@ -128,6 +136,7 @@
filename = "bullet_white.png";
break;
case PENDING:
+ case NOCHANGE:
default:
filename = "bullet_black.png";
}
@@ -211,13 +220,26 @@
return img;
}
+ public static Label newIcon(String wicketId, String css) {
+ Label lbl = new Label(wicketId);
+ setCssClass(lbl, css);
+ return lbl;
+ }
+
+ public static Label newBlankIcon(String wicketId) {
+ Label lbl = new Label(wicketId);
+ setCssClass(lbl, "");
+ lbl.setRenderBodyOnly(true);
+ return lbl;
+ }
+
public static ContextRelativeResource getResource(String file) {
return new ContextRelativeResource(file);
}
- public static String getHostURL(Request request) {
+ public static String getGitblitURL(Request request) {
HttpServletRequest req = ((WebRequest) request).getHttpServletRequest();
- return HttpUtils.getHostURL(req);
+ return HttpUtils.getGitblitURL(req);
}
public static HeaderContributor syndicationDiscoveryLink(final String feedTitle,
@@ -228,7 +250,7 @@
public void renderHead(IHeaderResponse response) {
String contentType = "application/rss+xml";
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("<link rel=\"alternate\" ");
buffer.append("type=\"").append(contentType).append("\" ");
buffer.append("title=\"").append(feedTitle).append("\" ");
@@ -237,17 +259,25 @@
}
});
}
-
+
public static PageParameters newTokenParameter(String token) {
return new PageParameters("t=" + token);
}
-
+
public static PageParameters newRegistrationParameter(String url, String name) {
return new PageParameters("u=" + url + ",n=" + name);
}
public static PageParameters newUsernameParameter(String username) {
return new PageParameters("user=" + username);
+ }
+
+ public static PageParameters newTeamnameParameter(String teamname) {
+ return new PageParameters("team=" + teamname);
+ }
+
+ public static PageParameters newProjectParameter(String projectName) {
+ return new PageParameters("p=" + projectName);
}
public static PageParameters newRepositoryParameter(String repositoryName) {
@@ -282,9 +312,9 @@
return newObjectParameter(repositoryName, objectId);
}
if (StringUtils.isEmpty(objectId)) {
- return new PageParameters("r=" + repositoryName + ",page=" + pageNumber);
+ return new PageParameters("r=" + repositoryName + ",pg=" + pageNumber);
}
- return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",page=" + pageNumber);
+ return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",pg=" + pageNumber);
}
public static PageParameters newHistoryPageParameter(String repositoryName, String objectId,
@@ -293,10 +323,10 @@
return newObjectParameter(repositoryName, objectId);
}
if (StringUtils.isEmpty(objectId)) {
- return new PageParameters("r=" + repositoryName + ",f=" + path + ",page=" + pageNumber);
+ return new PageParameters("r=" + repositoryName + ",f=" + path + ",pg=" + pageNumber);
}
- return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path
- + ",page=" + pageNumber);
+ return new PageParameters("r=" + repositoryName + ",h=" + objectId + ",f=" + path + ",pg="
+ + pageNumber);
}
public static PageParameters newBlobDiffParameter(String repositoryName, String baseCommitId,
@@ -309,7 +339,7 @@
}
public static PageParameters newSearchParameter(String repositoryName, String commitId,
- String search, SearchType type) {
+ String search, Constants.SearchType type) {
if (StringUtils.isEmpty(commitId)) {
return new PageParameters("r=" + repositoryName + ",s=" + search + ",st=" + type.name());
}
@@ -318,13 +348,17 @@
}
public static PageParameters newSearchParameter(String repositoryName, String commitId,
- String search, SearchType type, int pageNumber) {
+ String search, Constants.SearchType type, int pageNumber) {
if (StringUtils.isEmpty(commitId)) {
return new PageParameters("r=" + repositoryName + ",s=" + search + ",st=" + type.name()
- + ",page=" + pageNumber);
+ + ",pg=" + pageNumber);
}
return new PageParameters("r=" + repositoryName + ",h=" + commitId + ",s=" + search
- + ",st=" + type.name() + ",page=" + pageNumber);
+ + ",st=" + type.name() + ",pg=" + pageNumber);
+ }
+
+ public static String getProjectName(PageParameters params) {
+ return params.getString("p", "");
}
public static String getRepositoryName(PageParameters params) {
@@ -353,17 +387,37 @@
public static int getPage(PageParameters params) {
// index from 1
- return params.getInt("page", 1);
+ return params.getInt("pg", 1);
+ }
+
+ public static String getRegEx(PageParameters params) {
+ return params.getString("x", "");
+ }
+
+ public static String getSet(PageParameters params) {
+ return params.getString("set", "");
+ }
+
+ public static String getTeam(PageParameters params) {
+ return params.getString("team", "");
+ }
+
+ public static int getDaysBack(PageParameters params) {
+ return params.getInt("db", 14);
}
public static String getUsername(PageParameters params) {
return params.getString("user", "");
}
+ public static String getTeamname(PageParameters params) {
+ return params.getString("team", "");
+ }
+
public static String getToken(PageParameters params) {
return params.getString("t", "");
}
-
+
public static String getUrlParameter(PageParameters params) {
return params.getString("u", "");
}
@@ -372,12 +426,13 @@
return params.getString("n", "");
}
- public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone) {
+ public static Label createDateLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
String format = GitBlit.getString(Keys.web.datestampShortFormat, "MM/dd/yy");
DateFormat df = new SimpleDateFormat(format);
- if (timeZone != null) {
- df.setTimeZone(timeZone);
+ if (timeZone == null) {
+ timeZone = GitBlit.getTimezone();
}
+ df.setTimeZone(timeZone);
String dateString;
if (date.getTime() == 0) {
dateString = "--";
@@ -387,7 +442,7 @@
String title = null;
if (date.getTime() <= System.currentTimeMillis()) {
// past
- title = TimeUtils.timeAgo(date);
+ title = timeUtils.timeAgo(date);
}
if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {
String tmp = dateString;
@@ -395,20 +450,76 @@
title = tmp;
}
Label label = new Label(wicketId, dateString);
- WicketUtils.setCssClass(label, TimeUtils.timeAgoCss(date));
+ WicketUtils.setCssClass(label, timeUtils.timeAgoCss(date));
if (!StringUtils.isEmpty(title)) {
WicketUtils.setHtmlTooltip(label, title);
}
return label;
}
- public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone) {
- String format = GitBlit.getString(Keys.web.datetimestampLongFormat,
- "EEEE, MMMM d, yyyy h:mm a z");
+ public static Label createTimeLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
+ String format = GitBlit.getString(Keys.web.timeFormat, "HH:mm");
DateFormat df = new SimpleDateFormat(format);
- if (timeZone != null) {
- df.setTimeZone(timeZone);
+ if (timeZone == null) {
+ timeZone = GitBlit.getTimezone();
}
+ df.setTimeZone(timeZone);
+ String timeString;
+ if (date.getTime() == 0) {
+ timeString = "--";
+ } else {
+ timeString = df.format(date);
+ }
+ String title = timeUtils.timeAgo(date);
+ Label label = new Label(wicketId, timeString);
+ if (!StringUtils.isEmpty(title)) {
+ WicketUtils.setHtmlTooltip(label, title);
+ }
+ return label;
+ }
+
+ public static Label createDatestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
+ String format = GitBlit.getString(Keys.web.datestampLongFormat, "EEEE, MMMM d, yyyy");
+ DateFormat df = new SimpleDateFormat(format);
+ if (timeZone == null) {
+ timeZone = GitBlit.getTimezone();
+ }
+ df.setTimeZone(timeZone);
+ String dateString;
+ if (date.getTime() == 0) {
+ dateString = "--";
+ } else {
+ dateString = df.format(date);
+ }
+ String title = null;
+ if (TimeUtils.isToday(date)) {
+ title = timeUtils.today();
+ } else if (TimeUtils.isYesterday(date)) {
+ title = timeUtils.yesterday();
+ } else if (date.getTime() <= System.currentTimeMillis()) {
+ // past
+ title = timeUtils.timeAgo(date);
+ }
+ if ((System.currentTimeMillis() - date.getTime()) < 10 * 24 * 60 * 60 * 1000L) {
+ String tmp = dateString;
+ dateString = title;
+ title = tmp;
+ }
+ Label label = new Label(wicketId, dateString);
+ if (!StringUtils.isEmpty(title)) {
+ WicketUtils.setHtmlTooltip(label, title);
+ }
+ return label;
+ }
+
+ public static Label createTimestampLabel(String wicketId, Date date, TimeZone timeZone, TimeUtils timeUtils) {
+ String format = GitBlit.getString(Keys.web.datetimestampLongFormat,
+ "EEEE, MMMM d, yyyy HH:mm Z");
+ DateFormat df = new SimpleDateFormat(format);
+ if (timeZone == null) {
+ timeZone = GitBlit.getTimezone();
+ }
+ df.setTimeZone(timeZone);
String dateString;
if (date.getTime() == 0) {
dateString = "--";
@@ -418,7 +529,7 @@
String title = null;
if (date.getTime() <= System.currentTimeMillis()) {
// past
- title = TimeUtils.timeAgo(date);
+ title = timeUtils.timeAgo(date);
}
Label label = new Label(wicketId, dateString);
if (!StringUtils.isEmpty(title)) {
--
Gitblit v1.9.1