View Javadoc

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