1 package com.stateofflow.eclipse.metrics.export.html;
2
3 import java.io.IOException;
4
5 import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
6 import com.stateofflow.eclipse.metrics.collator.MetricsCollatorSet;
7 import com.stateofflow.eclipse.metrics.configuration.MetricPresentations;
8 import com.stateofflow.eclipse.metrics.metric.MetricId;
9
10 final class DashboardWriter {
11 private final HtmlExportFactory factory;
12
13 public DashboardWriter(final HtmlExportFactory factory) {
14 this.factory = factory;
15 }
16
17 public void write(final MetricsCollatorSet collatorSet) throws IOException {
18 final HtmlPageBuilder pageBuilder = openPage();
19 write(pageBuilder, collatorSet.getMethodMetrics());
20 write(pageBuilder, collatorSet.getTypeMetrics());
21 pageBuilder.closePage();
22 }
23
24 private HtmlPageBuilder openPage() throws IOException {
25 return factory.createHtmlPageBuilder().openPage(HtmlExporter.DASHBOARD_FILE_NAME, "Dashboard").openElement("P").printIndexLink().closeElementAndNewline("P").openElement("P").closeElementAndNewline("P");
26 }
27
28 private void write(final HtmlPageBuilder pageBuilder, final MetricsCollator collator) {
29 final MetricId[] ids = collator.getSortedMetricIds();
30 final MetricPresentations presentations = factory.getPresentations();
31 for (final MetricId id : ids) {
32 pageBuilder.createElement("H2", pageBuilder.getLink(presentations.getDescriptionUrl(id), presentations.getPresentationName(id)));
33 pageBuilder.createImageFileLink(factory.getImageFilePath(id));
34 }
35 }
36 }
37