View Javadoc

1   /**
2    * 
3    */
4   package net.sf.statcvs.pages.xml;
5   
6   import java.util.Iterator;
7   
8   import net.sf.statcvs.output.ReportConfig;
9   import net.sf.statcvs.renderer.XMLRenderer;
10  import net.sf.statcvs.reportmodel.Column;
11  import net.sf.statcvs.reportmodel.Table;
12  import net.sf.statcvs.reports.DevelopersTableReport;
13  import net.sf.statcvs.reports.TableReport;
14  
15  import org.jdom.Element;
16  
17  /**
18   * @author Nilendra Weerasinghe (nilendraw@gmail.com)
19   * @version $Id: AllDevelopersXml.java,v 1.2 2008/04/02 11:22:16 benoitx Exp $
20   * 
21   * This is the class which generates the developer information of the xml report 
22   */
23  public class AllDevelopersXml {
24      private static final int NO_OF_COLS_IN_TABLE = 50;
25      private final XMLRenderer renderer = new XMLRenderer();
26      private final ReportConfig config;
27      private DevelopersTableReport developers;
28      private Table table;
29  
30      /**
31       * @param config Configuration and data for the report suite
32       */
33      public AllDevelopersXml(final ReportConfig config) {
34          this.config = config;
35      }
36  
37      /**
38       * returns jdom element which contains data extracted from DeveloeprsTableReport
39       * 
40       * @returns Element
41       */
42      public Element toFile() {
43          this.developers = new DevelopersTableReport(this.config);
44          final TableReport tr = developers;
45          tr.calculate();
46          this.table = tr.getTable();
47          final Element div = new Element(XmlTags.TAG_DEVELOPERS);
48  
49          final String[] str = new String[NO_OF_COLS_IN_TABLE];
50          for (int j = 0; j < table.getRowCount(); j++) {
51              Element col = null;
52              int i = 0;
53              final Iterator it = table.getColumnIterator();
54              final Iterator itr = table.getColumnIterator();
55              while (it.hasNext()) {
56                  final Column column = (Column) it.next();
57                  column.renderHead(renderer);
58  
59                  str[i] = renderer.getColumnHead();
60                  if (i == 0) {
61                      col = new Element(str[i]);
62                  } else {
63                      col.addContent(new Element(str[i]));
64                  }
65                  i++;
66              }
67              boolean isFirstColumn = true;
68              int k = 0;
69              while (itr.hasNext()) {
70                  final Column column = (Column) itr.next();
71                  column.renderCell(j, renderer);
72                  if (isFirstColumn && table.hasKeysInFirstColumn()) {
73                      col.setAttribute("name", renderer.getRowHead().toLowerCase());
74                      isFirstColumn = false;
75                  } else {
76                      col.getChild(str[k]).setText(renderer.getTableCell());
77                  }
78                  k++;
79              }
80              div.addContent(col);
81          }
82          return div;
83      }
84  }