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 * TODO: Clean up 19 * 20 * @author Anja Jentzsch 21 * @author Benoit Xhenseval (OutputRenderer and ExtraReportRegister interfaces) 22 * @version $Id: ReportSuiteMaker.java,v 1.7 2009/04/22 08:20:42 benoitx Exp $ 23 */ 24 public class ReportSuiteMaker { 25 26 /** 27 * Path to web distribution files inside the distribution JAR, relative to 28 * the {@link net.sf.statcvs.Main} class 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 * @param config Configuration and data for the report suite 46 * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt> 47 */ 48 public ReportSuiteMaker(final ReportConfig config, final String notesHTML) { 49 this(config, notesHTML, Collections.EMPTY_LIST); 50 } 51 52 /** 53 * @param config Configuration and data for the report suite 54 * @param notesHTML A note to be inserted on top of the page; might be <tt>null</tt> 55 * @param additionalPages A list of {@link Page}s for inclusion in the index page's main menu 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 * this method will move away from the ordinary routine taken by 65 * statSVn and will invoke some new classes that are written to generate the xml's 66 * 67 */ 68 public void toXml() { 69 new GenerateXml(this.config).generate(); 70 } 71 72 /** 73 * TODO: Don't throw exception 74 * @throws IOException on error while writing the files 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 mainMenu.add(new CloudCommitPageMaker(this.config).toFile()); 96 Iterator it = this.extraPages.iterator(); 97 while (it.hasNext()) { 98 mainMenu.add((Page) it.next()); 99 } 100 final Page indexPage = new IndexPageMaker(this.config, this.notesHTML, mainMenu).toFile(); 101 102 final PageGroup directoryPages = new PageGroup("Directories", false); 103 it = this.config.getRepository().getDirectories().iterator(); 104 while (it.hasNext()) { 105 directoryPages.add(new DirectoryPageMaker(this.config, (Directory) it.next()).toFile()); 106 } 107 indexPage.addChild(directoryPages); 108 return indexPage; 109 } 110 111 private void createIcon(final String iconFilename) throws IOException { 112 this.config.copyFileIntoReport(Main.class.getResource(WEB_FILE_PATH + iconFilename), iconFilename); 113 } 114 115 private Page createEmptyRepositoryPage() { 116 String projectName = this.config.getProjectName(); 117 if (projectName == null) { 118 projectName = "empty repository"; 119 } 120 final String title = "Development statistics for " + projectName; 121 final Page page = this.config.createPage("index", title, title); 122 page.addAttribute("Generated", Calendar.getInstance().getTime()); 123 page.addRawContent("<p>No matching files in repository.</p>"); 124 return page; 125 } 126 }