View Javadoc

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          boolean firstPage = true;
35          while (true) {
36              final int year = calendar.get(Calendar.YEAR);
37              final int month = calendar.get(Calendar.MONTH);
38  
39              final NavigationNode page = new LogPageMaker(this.config, year, month, this.repository.getCommits(), firstPage).toFile();
40              results.add(page);
41              if (calendar.get(Calendar.YEAR) == startCal.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == startCal.get(Calendar.MONTH)) {
42                  break;
43              }
44              firstPage = false;
45              calendar.add(Calendar.MONTH, -1);
46          }
47          final Iterator it = results.iterator();
48          while (it.hasNext()) {
49              pages.add((NavigationNode) it.next());
50          }
51          pages.setShowLinkToPreviousSibling(true);
52          return pages;
53      }
54  }