View Javadoc

1   package net.sf.statcvs.pages;
2   
3   import java.util.Calendar;
4   import java.util.Iterator;
5   
6   import net.sf.statcvs.Messages;
7   import net.sf.statcvs.charts.ChartImage;
8   import net.sf.statcvs.charts.LOCChartMaker.MainLOCChartMaker;
9   import net.sf.statcvs.model.Repository;
10  import net.sf.statcvs.model.Revision;
11  import net.sf.statcvs.model.VersionedFile;
12  import net.sf.statcvs.output.ReportConfig;
13  import net.sf.statcvs.reports.TagReport;
14  import net.sf.statcvs.reports.TopDevelopersTableReport;
15  
16  /**
17   * @author anja
18   * @author Richard Cyganiak (richard@cyganiak.de)
19   * @version $Id: IndexPageMaker.java,v 1.7 2008/04/03 17:38:14 benoitx Exp $
20   */
21  public class IndexPageMaker {
22      private final ReportConfig config;
23      private final Repository repository;
24      private final String notesHTML;
25      private final PageGroup reports;
26  
27      /**
28       * Creates a new report index page.
29       * @param config Report configuration to use
30       * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt>
31       * @param reports A list of {@link NavigationNode}s that constitute the page's main menu
32       */
33      public IndexPageMaker(final ReportConfig config, final String notesHTML, final PageGroup reports) {
34          this.config = config;
35          this.repository = config.getRepository();
36          this.notesHTML = notesHTML;
37          this.reports = reports;
38      }
39  
40      public Page toFile() {
41          final ChartImage chart = new MainLOCChartMaker(this.config, "loc_small.png", this.config.getSmallChartSize()).toFile();
42  
43          final TopDevelopersTableReport topDevelopers = new TopDevelopersTableReport(this.config);
44  
45          final String title = Messages.getString("INDEX_TITLE") + " " + this.config.getProjectName();
46          final Page page = this.config.createPage("index", title, title);
47          page.addAttribute("Generated", Calendar.getInstance().getTime());
48          final String headRevisionNumber = getHeadRevisionNumber();
49          // Quick and dirty-ish trick: a revision for CVS contains "." and it does not make sense to
50          // display a "head revision" for CVS.
51          if (headRevisionNumber != null && headRevisionNumber.indexOf('.') < 0) {
52              page.addAttribute("Head revision", headRevisionNumber);
53          }
54          page.addRawAttribute("Report Period", getReportPeriod());
55          page.addAttribute("Total Files", getCurrentFileCount());
56          page.addAttribute("Total Lines of Code", this.repository.getCurrentLOC());
57          page.addAttribute("Developers", topDevelopers.getDeveloperCount());
58          if (this.notesHTML != null) {
59              page.addRawContent(this.notesHTML);
60          }
61          page.add(this.reports);
62          if (chart != null) {
63              page.addSection(Messages.getString("LOC_TITLE"));
64              page.add(chart, "loc.html");
65          }
66          if (topDevelopers.getDeveloperCount() > 1) {
67              if (topDevelopers.getDeveloperCount() > 10) {
68                  page.addSection(Messages.getString("SECTION_TOP_AUTHORS"));
69              } else {
70                  page.addSection("Developers");
71              }
72              page.add(topDevelopers);
73              page.addRawContent(HTML.getLink("developers.html", Messages.getString("NAVIGATION_MORE")));
74          }
75          if (!this.repository.getSymbolicNames().isEmpty()) {
76              page.addSection("Repository Tags");
77              page.add(new TagReport(this.config));
78          }
79          page.addSection("Directories");
80          page.add(this.repository.getRoot(), false);
81          return page;
82      }
83  
84      private String getReportPeriod() {
85          return HTML.getDate(this.repository.getFirstDate()) + " to " + HTML.getDate(this.repository.getLastDate());
86      }
87  
88      private int getCurrentFileCount() {
89          int result = 0;
90          final Iterator it = this.repository.getFiles().iterator();
91          while (it.hasNext()) {
92              final VersionedFile file = (VersionedFile) it.next();
93              if (!file.isDead()) {
94                  result++;
95              }
96          }
97          return result;
98      }
99  
100     private String getHeadRevisionNumber() {
101         final Revision headRevision = (Revision) (this.repository.getRevisions().last());
102 
103         if (headRevision != null) {
104             return headRevision.getRevisionNumber();
105         } else {
106             return null;
107         }
108     }
109 }