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 LogPageGroupMaker {
14 private final ReportConfig config;
15 private final Repository repository;
16
17 public LogPageGroupMaker(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 if (this.repository.getCommits().isEmpty()) {
25 return pages;
26 }
27 final Date start = this.repository.getFirstDate();
28 final Date end = this.repository.getLastDate();
29 final Calendar calendar = new GregorianCalendar();
30 calendar.setTime(end);
31 final Calendar startCal = new GregorianCalendar();
32 startCal.setTime(start);
33 final List results = new ArrayList();
34 while (true) {
35 final int year = calendar.get(Calendar.YEAR);
36 final int month = calendar.get(Calendar.MONTH);
37 final NavigationNode page = new LogPageMaker(this.config, year, month, this.repository.getCommits()).toFile();
38 results.add(page);
39 if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) {
40 break;
41 }
42 calendar.add(Calendar.MONTH, -1);
43 }
44 final Iterator it = results.iterator();
45 while (it.hasNext()) {
46 pages.add((NavigationNode) it.next());
47 }
48 pages.setShowLinkToPreviousSibling(true);
49 return pages;
50 }
51 }