1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.listeners;
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.log4j.Logger;
30
31 import com.ebay.carad.os.vitalsigns.IDashboardAgent;
32 import com.ebay.carad.os.vitalsigns.ReportContainerIterator;
33 import com.ebay.carad.os.vitalsigns.listeners.outputtemplates.ITemplateProcessor;
34
35 /***
36 * <p>Used for writing any kind of index to the reports that were ran. It stores reports
37 * internally as each is ran, and then when <tt>reportingComplete</tt> is called, it
38 * generates its output based on the Freemarker template provided.</p>
39 *
40 * @author Jeremy Thomerson
41 * @version $Id$
42 */
43 public class IndexWritingListener extends AbstractReportingListener {
44
45 private static final Logger LOGGER = Logger.getLogger(IndexWritingListener.class);
46 private ITemplateProcessor mTemplateProcessor = ITemplateProcessor.DEFAULT_IMPLEMENTATION;
47 private String mRelativeOutputPath = "index.html";
48 private String mTemplatePath = "templates/standard/IndexWritingListener.fml";
49
50 public void reportingComplete(IDashboardAgent agent) {
51 Map context = new HashMap();
52 List reports = new ArrayList();
53 List containers = new ArrayList(agent.getReports());
54
55 for (ReportContainerIterator it = new ReportContainerIterator(containers); it.hasNext(); ) {
56 reports.add(it.next());
57 }
58
59 Collections.sort(reports);
60 Collections.sort(containers);
61
62 context.put("reports", reports);
63 context.put("containers", containers);
64
65 LOGGER.info("IndexWritingListener template context: " + context);
66 mTemplateProcessor.processContext(context, agent, null, mTemplatePath, mRelativeOutputPath);
67 }
68
69 public String getTemplatePath() {
70 return mTemplatePath;
71 }
72
73 /***
74 * @param templatePath The path to the template on the classpath.
75 */
76 public void setTemplatePath(String templatePath) {
77 mTemplatePath = templatePath;
78 }
79
80 public String getRelativeOutputPath() {
81 return mRelativeOutputPath;
82 }
83
84 /***
85 * @param relativeOutputPath The path that the output should be written to, relative to the report agent destination path
86 */
87 public void setRelativeOutputPath(String relativeOutputPath) {
88 mRelativeOutputPath = relativeOutputPath;
89 }
90 }
91