controls.add(viewTree);\r
\r
NameRenderer nameRenderer = new NameRenderer();\r
- tableModel = new SyndicatedEntryTableModel();\r
+ tableModel = new SyndicatedEntryTableModel(gitblit);\r
header = new HeaderPanel(Translation.get("gb.timeline"), "feed_16x16.png");\r
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);\r
defaultSorter = new TableRowSorter<SyndicatedEntryTableModel>(tableModel);\r
}\r
\r
private void updateAuthors() {\r
- String repository = repositorySelector.getSelectedItem().toString();\r
+ String repository = ALL;\r
+ if (repositorySelector.getSelectedIndex() > -1) {\r
+ repository = repositorySelector.getSelectedItem().toString();\r
+ }\r
\r
// determine unique repositories and authors\r
Set<String> uniqueAuthors = new HashSet<String>();\r
\r
private static final long serialVersionUID = 1L;\r
\r
+ private static final Date NEVER = new Date(0);\r
+\r
protected final GitblitRegistration reg;\r
\r
public final String url;\r
Set<SyndicatedEntryModel> allEntries = new HashSet<SyndicatedEntryModel>();\r
if (reg.feeds.size() > 0) {\r
for (FeedModel feed : reg.feeds) {\r
- feed.lastRefresh = new Date();\r
+ feed.lastRefreshDate = feed.currentRefreshDate;\r
+ feed.currentRefreshDate = new Date();\r
List<SyndicatedEntryModel> entries = SyndicationUtils.readFeed(url,\r
feed.repository, feed.branch, -1, account, password);\r
allEntries.addAll(entries);\r
}\r
}\r
+ reg.cacheFeeds();\r
syndicatedEntries.clear();\r
syndicatedEntries.addAll(allEntries);\r
Collections.sort(syndicatedEntries);\r
}\r
}\r
\r
+ public Date getLastFeedRefresh(String repository, String branch) {\r
+ FeedModel feed = new FeedModel();\r
+ feed.repository = repository;\r
+ feed.branch = branch;\r
+ if (reg.feeds.contains(feed)) {\r
+ int idx = reg.feeds.indexOf(feed);\r
+ feed = reg.feeds.get(idx);\r
+ return feed.lastRefreshDate;\r
+ }\r
+ return NEVER;\r
+ }\r
+\r
public boolean isSubscribed(RepositoryModel repository) {\r
return subscribedRepositories.contains(repository.name.toLowerCase());\r
}\r
import java.awt.event.KeyEvent;\r
import java.awt.event.WindowAdapter;\r
import java.awt.event.WindowEvent;\r
+import java.io.BufferedReader;\r
import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.FileWriter;\r
import java.io.IOException;\r
import java.net.ConnectException;\r
import java.text.MessageFormat;\r
import java.util.Collections;\r
import java.util.Comparator;\r
import java.util.Date;\r
+import java.util.HashMap;\r
import java.util.LinkedHashMap;\r
import java.util.List;\r
import java.util.Locale;\r
} else {\r
password = new String(Base64.decode(pw)).toCharArray();\r
}\r
- GitblitRegistration reg = new GitblitRegistration(server, url, account, password);\r
+ GitblitRegistration reg = new GitblitRegistration(server, url, account, password) {\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ protected void cacheFeeds() {\r
+ writeFeedCache(this);\r
+ }\r
+ };\r
String[] feeds = config.getStringList(SERVER, server, FEED);\r
if (feeds != null) {\r
// deserialize the field definitions\r
}\r
}\r
reg.lastLogin = lastLogin;\r
+ loadFeedCache(reg);\r
registrations.put(reg.name, reg);\r
}\r
} catch (Throwable t) {\r
return config;\r
}\r
\r
+ private void loadFeedCache(GitblitRegistration reg) {\r
+ File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.url)\r
+ + ".cache");\r
+ if (!feedCache.exists()) {\r
+ // no cache for this registration\r
+ return;\r
+ }\r
+ try {\r
+ BufferedReader reader = new BufferedReader(new FileReader(feedCache));\r
+ Map<String, Date> cache = new HashMap<String, Date>();\r
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");\r
+ String line = null;\r
+ while ((line = reader.readLine()) != null) {\r
+ String[] kvp = line.split("=");\r
+ cache.put(kvp[0], df.parse(kvp[1]));\r
+ }\r
+ reader.close();\r
+ for (FeedModel feed : reg.feeds) {\r
+ String name = feed.toString();\r
+ if (cache.containsKey(name)) {\r
+ feed.currentRefreshDate = cache.get(name);\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ Utils.showException(GitblitManager.this, e);\r
+ }\r
+ }\r
+\r
+ private void writeFeedCache(GitblitRegistration reg) {\r
+ try {\r
+ File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.url)\r
+ + ".cache");\r
+ FileWriter writer = new FileWriter(feedCache);\r
+ for (FeedModel feed : reg.feeds) {\r
+ writer.append(MessageFormat.format("{0}={1,date,yyyy-MM-dd'T'HH:mm:ss}\n",\r
+ feed.toString(), feed.currentRefreshDate));\r
+ }\r
+ writer.close();\r
+ } catch (Exception e) {\r
+ Utils.showException(GitblitManager.this, e);\r
+ }\r
+ }\r
+\r
public static void main(String[] args) {\r
EventQueue.invokeLater(new Runnable() {\r
public void run() {\r
public int compareTo(GitblitRegistration o) {\r
return name.toLowerCase().compareTo(o.name.toLowerCase());\r
}\r
+\r
+ protected void cacheFeeds() {\r
+ }\r
}\r
\r
private static final long serialVersionUID = 1L;\r
\r
+ private final GitblitClient gitblit;\r
+\r
List<SyndicatedEntryModel> entries;\r
\r
enum Columns {\r
- Date, Repository,Author, Message, Branch;\r
+ Date, Repository, Author, Message, Branch;\r
\r
@Override\r
public String toString() {\r
}\r
}\r
\r
- public SyndicatedEntryTableModel() {\r
- this(new ArrayList<SyndicatedEntryModel>());\r
- }\r
-\r
- public SyndicatedEntryTableModel(List<SyndicatedEntryModel> entries) {\r
- setEntries(entries);\r
+ public SyndicatedEntryTableModel(GitblitClient gitblit) {\r
+ this.gitblit = gitblit;\r
+ this.entries = new ArrayList<SyndicatedEntryModel>();\r
}\r
\r
public void setEntries(List<SyndicatedEntryModel> entries) {\r
case Author:\r
return entry.author;\r
case Message:\r
+ Date lastRefresh = gitblit.getLastFeedRefresh(entry.repository, entry.branch);\r
+ if (entry.published.after(lastRefresh)) {\r
+ return "<html><body><b>" + entry.title;\r
+ }\r
return entry.title;\r
}\r
return null;\r
\r
public String repository;\r
public String branch;\r
- public Date lastRefresh;\r
+ public Date lastRefreshDate;\r
+ public Date currentRefreshDate;\r
\r
public boolean subscribed;\r
\r
\r
public FeedModel(String definition) {\r
subscribed = true;\r
- lastRefresh = new Date(0);\r
+ lastRefreshDate = new Date(0);\r
+ currentRefreshDate = new Date(0);\r
\r
String[] fields = definition.split(":");\r
repository = fields[0];\r
\r
@Override\r
public int hashCode() {\r
- return (repository + (StringUtils.isEmpty(branch) ? "" : branch)).toLowerCase().hashCode();\r
+ return toString().toLowerCase().hashCode();\r
}\r
\r
@Override\r