1 package net.sf.statcvs.pages;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.Calendar;
6 import java.util.Collections;
7 import java.util.Iterator;
8 import java.util.List;
9
10 import net.sf.statcvs.Main;
11 import net.sf.statcvs.model.Directory;
12 import net.sf.statcvs.output.ChurnPageMaker;
13 import net.sf.statcvs.output.RepoMapPageMaker;
14 import net.sf.statcvs.output.ReportConfig;
15 import net.sf.statcvs.pages.xml.GenerateXml;
16
17
18
19
20
21
22
23
24 public class ReportSuiteMaker {
25
26
27
28
29
30 public static final String WEB_FILE_PATH = "web-files/";
31
32 public static final String DIRECTORY_ICON = "folder.png";
33 public static final String BUG_ICON = "bug.png";
34 public static final String DELETED_DIRECTORY_ICON = "folder-deleted.png";
35 public static final String FILE_ICON = "file.png";
36 public static final String DELETED_FILE_ICON = "file-deleted.png";
37 public static final int ICON_WIDTH = 15;
38 public static final int ICON_HEIGHT = 13;
39
40 private final ReportConfig config;
41 private final String notesHTML;
42 private List extraPages = new ArrayList();
43
44
45
46
47
48 public ReportSuiteMaker(final ReportConfig config, final String notesHTML) {
49 this(config, notesHTML, Collections.EMPTY_LIST);
50 }
51
52
53
54
55
56
57 public ReportSuiteMaker(final ReportConfig config, final String notesHTML, final List additionalPages) {
58 this.config = config;
59 this.notesHTML = notesHTML;
60 this.extraPages = additionalPages;
61 }
62
63
64
65
66
67
68 public void toXml() {
69 new GenerateXml(this.config).generate();
70 }
71
72
73
74
75
76 public Page toFile() throws IOException {
77 this.config.getCssHandler().createOutputFiles();
78 if (this.config.getRepository().isEmpty()) {
79 return createEmptyRepositoryPage();
80 }
81 createIcon(BUG_ICON);
82 createIcon(DIRECTORY_ICON);
83 createIcon(DELETED_DIRECTORY_ICON);
84 createIcon(FILE_ICON);
85 createIcon(DELETED_FILE_ICON);
86
87 final PageGroup mainMenu = new PageGroup("Reports", false);
88 mainMenu.add(new AllDevelopersPageMaker(this.config).toFile());
89 mainMenu.add(new LogPageGroupMaker(this.config).getPages());
90 mainMenu.add(new LOCPageMaker(this.config).toFile());
91 mainMenu.add(new FileSizesPageMaker(this.config).toFile());
92 mainMenu.add(new DirectorySizesPageMaker(this.config).toFile());
93 mainMenu.add(new RepoMapPageMaker(config).toFile());
94 mainMenu.add(new ChurnPageMaker(config).toFile());
95 Iterator it = this.extraPages.iterator();
96 while (it.hasNext()) {
97 mainMenu.add((Page) it.next());
98 }
99 final Page indexPage = new IndexPageMaker(this.config, this.notesHTML, mainMenu).toFile();
100
101 final PageGroup directoryPages = new PageGroup("Directories", false);
102 it = this.config.getRepository().getDirectories().iterator();
103 while (it.hasNext()) {
104 directoryPages.add(new DirectoryPageMaker(this.config, (Directory) it.next()).toFile());
105 }
106 indexPage.addChild(directoryPages);
107 return indexPage;
108 }
109
110 private void createIcon(final String iconFilename) throws IOException {
111 this.config.copyFileIntoReport(Main.class.getResource(WEB_FILE_PATH + iconFilename), iconFilename);
112 }
113
114 private Page createEmptyRepositoryPage() {
115 String projectName = this.config.getProjectName();
116 if (projectName == null) {
117 projectName = "empty repository";
118 }
119 final String title = "Development statistics for " + projectName;
120 final Page page = this.config.createPage("index", title, title);
121 page.addAttribute("Generated", Calendar.getInstance().getTime());
122 page.addRawContent("<p>No matching files in repository.</p>");
123 return page;
124 }
125 }