View Javadoc

1   /*
2    * The contents of this file are subject to the terms 
3    * of the Common Development and Distribution License 
4    * (the "License").  You may not use this file except 
5    * in compliance with the License.
6    * 
7    * You can obtain a copy of the license at 
8    * http://www.sun.com/cddl/cddl.html. 
9    * See the License for the specific language governing 
10   * permissions and limitations under the License.
11   * 
12   * When distributing Covered Code, include this CDDL 
13   * HEADER in each file and include the License file at 
14   * license.txt.  If applicable, add the following below 
15   * this CDDL HEADER, with the fields enclosed by brackets 
16   * "[]" replaced with your own identifying information: 
17   * Portions Copyright [yyyy] [name of copyright owner]
18   * 
19   * Portions Copyright 2004 eBay, Inc.
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