1 package net.sf.statcvs.pages;
2
3 import java.util.ArrayList;
4 import java.util.Calendar;
5 import java.util.Date;
6 import java.util.GregorianCalendar;
7 import java.util.Iterator;
8 import java.util.List;
9
10 import net.sf.statcvs.model.Repository;
11 import net.sf.statcvs.output.ReportConfig;
12
13 public class CommitLogPageGroupMaker {
14 private final ReportConfig config;
15 private final Repository repository;
16
17 public CommitLogPageGroupMaker(final ReportConfig config) {
18 this.config = config;
19 this.repository = config.getRepository();
20 }
21
22 public PageGroup getPages() {
23 final PageGroup pages = new PageGroup("Commit Logs");
24 List commits = this.repository.getCommits();
25 if (commits == null || commits.isEmpty()) {
26 return null;
27 }
28 final Date start = this.repository.getFirstDate();
29 final Date end = this.repository.getLastDate();
30 final Calendar calendar = new GregorianCalendar();
31 calendar.setTime(end);
32 final Calendar startCal = new GregorianCalendar();
33 startCal.setTime(start);
34 final List results = new ArrayList();
35 boolean firstPage = true;
36 while (true) {
37 final int year = calendar.get(Calendar.YEAR);
38 final int month = calendar.get(Calendar.MONTH);
39
40 final NavigationNode page = new CommitLogPageMaker(this.config, year, month, commits, firstPage).toFile();
41 results.add(page);
42 if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) {
43 break;
44 }
45 firstPage = false;
46 calendar.add(Calendar.MONTH, -1);
47 }
48 final Iterator it = results.iterator();
49 while (it.hasNext()) {
50 pages.add((NavigationNode) it.next());
51 }
52 pages.setShowLinkToPreviousSibling(true);
53 return pages;
54 }
55 }