| 1 | |
package net.sf.statcvs.pages.xml; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
import java.text.DecimalFormat; |
| 9 | |
import java.text.NumberFormat; |
| 10 | |
import java.util.Iterator; |
| 11 | |
|
| 12 | |
import net.sf.statcvs.model.Repository; |
| 13 | |
import net.sf.statcvs.model.VersionedFile; |
| 14 | |
import net.sf.statcvs.output.ReportConfig; |
| 15 | |
import net.sf.statcvs.renderer.XMLRenderer; |
| 16 | |
import net.sf.statcvs.reportmodel.Column; |
| 17 | |
import net.sf.statcvs.reportmodel.Table; |
| 18 | |
import net.sf.statcvs.reports.FileTypeReport; |
| 19 | |
import net.sf.statcvs.reports.FilesWithMostRevisionsTableReport; |
| 20 | |
import net.sf.statcvs.reports.LargestFilesTableReport; |
| 21 | |
import net.sf.statcvs.reports.TableReport; |
| 22 | |
|
| 23 | |
import org.jdom.Element; |
| 24 | |
|
| 25 | |
public class FilesXml { |
| 26 | 0 | private final static NumberFormat[] DOUBLE_FORMATS = { new DecimalFormat("0"), new DecimalFormat("0.0"), new DecimalFormat("0.00"), |
| 27 | |
new DecimalFormat("0.000"), new DecimalFormat("0.0000") }; |
| 28 | |
private static final int NO_OF_COLS_IN_EXT_TABLE = 4; |
| 29 | |
private static final int NO_OF_COLS_IN_LARG_TABLE = 4; |
| 30 | |
private static final int MAX_LARGEST_FILES = 40; |
| 31 | |
private Table table; |
| 32 | 0 | private final XMLRenderer renderer = new XMLRenderer(); |
| 33 | |
|
| 34 | |
private final ReportConfig config; |
| 35 | |
private final Repository repository; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public FilesXml(final ReportConfig config) { |
| 41 | 0 | this.config = config; |
| 42 | 0 | this.repository = config.getRepository(); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public Element toFile() { |
| 51 | 0 | final Element fileStats = new Element("FileStats"); |
| 52 | 0 | final Element summ = new Element(XmlTags.TAG_SUMMARY); |
| 53 | 0 | summ.addContent(new Element(XmlTags.TAG_TOTAL_FILES).setText(Integer.toString(getCurrentFileCount()))); |
| 54 | 0 | summ.addContent(new Element(XmlTags.TAG_AVG_FILE_SIZE).setText(DOUBLE_FORMATS[1].format(getCurrentAverageFileSize()) + " lines")); |
| 55 | 0 | summ.addContent(new Element(XmlTags.TAG_AVG_REVISIONS_PER_FILE).setText(Double.toString(getCurrentAverageRevisionCount()))); |
| 56 | 0 | fileStats.addContent(summ); |
| 57 | 0 | fileStats.addContent(fileExts()); |
| 58 | 0 | fileStats.addContent(largestFiles()); |
| 59 | 0 | fileStats.addContent(mostRevs()); |
| 60 | |
|
| 61 | 0 | return fileStats; |
| 62 | |
} |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
private Element fileExts() { |
| 70 | 0 | final Element ele = new Element(XmlTags.TAG_EXTENSIONS); |
| 71 | 0 | final TableReport tr = new FileTypeReport(this.config); |
| 72 | 0 | tr.calculate(); |
| 73 | 0 | this.table = tr.getTable(); |
| 74 | 0 | final String[] str = new String[NO_OF_COLS_IN_EXT_TABLE]; |
| 75 | 0 | for (int j = 0; j < table.getRowCount(); j++) { |
| 76 | 0 | Element col = null; |
| 77 | 0 | int i = 0; |
| 78 | 0 | final Iterator it = table.getColumnIterator(); |
| 79 | 0 | final Iterator itr = table.getColumnIterator(); |
| 80 | 0 | while (it.hasNext()) { |
| 81 | 0 | final Column column = (Column) it.next(); |
| 82 | 0 | column.renderHead(renderer); |
| 83 | 0 | str[i] = renderer.getColumnHead(); |
| 84 | 0 | if (i == 0) { |
| 85 | 0 | col = new Element(str[i]); |
| 86 | 0 | } else { |
| 87 | 0 | col.addContent(new Element(str[i])); |
| 88 | 0 | } |
| 89 | 0 | i++; |
| 90 | 0 | } |
| 91 | 0 | boolean isFirstColumn = true; |
| 92 | 0 | int k = 0; |
| 93 | 0 | while (itr.hasNext()) { |
| 94 | 0 | final Column column = (Column) itr.next(); |
| 95 | 0 | column.renderCell(j, renderer); |
| 96 | 0 | if (isFirstColumn && table.hasKeysInFirstColumn()) { |
| 97 | 0 | col.setAttribute("ext", renderer.getRowHead().toLowerCase()); |
| 98 | 0 | isFirstColumn = false; |
| 99 | 0 | } else { |
| 100 | 0 | col.getChild(str[k]).setText(renderer.getTableCell()); |
| 101 | 0 | } |
| 102 | 0 | k++; |
| 103 | 0 | } |
| 104 | 0 | ele.addContent(col); |
| 105 | 0 | } |
| 106 | 0 | return ele; |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
public Element largestFiles() { |
| 115 | 0 | final Element larg = new Element(XmlTags.TAG_LARGEST_FILES); |
| 116 | 0 | final TableReport largestFilesTable = new LargestFilesTableReport(this.config, this.repository.getFiles(), MAX_LARGEST_FILES); |
| 117 | 0 | largestFilesTable.calculate(); |
| 118 | 0 | this.table = largestFilesTable.getTable(); |
| 119 | 0 | final String[] str = new String[NO_OF_COLS_IN_LARG_TABLE]; |
| 120 | 0 | for (int j = 0; j < table.getRowCount(); j++) { |
| 121 | 0 | Element col = null; |
| 122 | 0 | int i = 0; |
| 123 | 0 | final Iterator it = table.getColumnIterator(); |
| 124 | 0 | final Iterator itr = table.getColumnIterator(); |
| 125 | 0 | while (it.hasNext()) { |
| 126 | 0 | final Column column = (Column) it.next(); |
| 127 | 0 | column.renderHead(renderer); |
| 128 | 0 | str[i] = renderer.getColumnHead(); |
| 129 | 0 | if (i == 0) { |
| 130 | 0 | col = new Element(str[i]); |
| 131 | 0 | } else { |
| 132 | 0 | str[i] = renderer.getColumnHead().replaceAll(" ", "_"); |
| 133 | 0 | |
| 134 | |
} |
| 135 | 0 | i++; |
| 136 | 0 | } |
| 137 | 0 | |
| 138 | 0 | boolean isFirstColumn = true; |
| 139 | 0 | int k = 0; |
| 140 | 0 | while (itr.hasNext()) { |
| 141 | 0 | final Column column = (Column) itr.next(); |
| 142 | 0 | column.renderCell(j, renderer); |
| 143 | 0 | if (isFirstColumn && table.hasKeysInFirstColumn()) { |
| 144 | 0 | col.setText(renderer.getRowHead()); |
| 145 | 0 | isFirstColumn = false; |
| 146 | 0 | } else { |
| 147 | 0 | col.setAttribute(str[k].toLowerCase(), renderer.getTableCell()); |
| 148 | 0 | } |
| 149 | 0 | k++; |
| 150 | 0 | } |
| 151 | 0 | larg.addContent(col); |
| 152 | 0 | } |
| 153 | 0 | return larg; |
| 154 | 0 | } |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
public Element mostRevs() { |
| 162 | 0 | final Element revs = new Element(XmlTags.TAG_MOST_REVISIONS); |
| 163 | 0 | final TableReport mostRevs = new FilesWithMostRevisionsTableReport(this.config, this.repository.getFiles(), MAX_LARGEST_FILES); |
| 164 | 0 | mostRevs.calculate(); |
| 165 | 0 | this.table = mostRevs.getTable(); |
| 166 | 0 | final String[] str = new String[NO_OF_COLS_IN_LARG_TABLE]; |
| 167 | 0 | for (int j = 0; j < table.getRowCount(); j++) { |
| 168 | 0 | Element col = null; |
| 169 | 0 | int i = 0; |
| 170 | 0 | final Iterator it = table.getColumnIterator(); |
| 171 | 0 | final Iterator itr = table.getColumnIterator(); |
| 172 | 0 | while (it.hasNext()) { |
| 173 | 0 | final Column column = (Column) it.next(); |
| 174 | 0 | column.renderHead(renderer); |
| 175 | 0 | if (i == 0) { |
| 176 | 0 | str[i] = renderer.getColumnHead(); |
| 177 | 0 | col = new Element(str[i]); |
| 178 | 0 | } else { |
| 179 | 0 | str[i] = renderer.getColumnHead().replaceAll(" ", "_"); |
| 180 | 0 | |
| 181 | |
} |
| 182 | 0 | i++; |
| 183 | 0 | } |
| 184 | 0 | |
| 185 | 0 | boolean isFirstColumn = true; |
| 186 | 0 | int k = 0; |
| 187 | 0 | while (itr.hasNext()) { |
| 188 | 0 | final Column column = (Column) itr.next(); |
| 189 | 0 | column.renderCell(j, renderer); |
| 190 | 0 | if (isFirstColumn && table.hasKeysInFirstColumn()) { |
| 191 | 0 | col.setText(renderer.getRowHead()); |
| 192 | 0 | isFirstColumn = false; |
| 193 | 0 | } else { |
| 194 | 0 | col.setAttribute(str[k].toLowerCase(), renderer.getTableCell()); |
| 195 | 0 | } |
| 196 | 0 | k++; |
| 197 | 0 | } |
| 198 | 0 | revs.addContent(col); |
| 199 | 0 | } |
| 200 | 0 | return revs; |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
private int getCurrentFileCount() { |
| 209 | 0 | int result = 0; |
| 210 | 0 | final Iterator it = this.repository.getFiles().iterator(); |
| 211 | 0 | while (it.hasNext()) { |
| 212 | 0 | final VersionedFile file = (VersionedFile) it.next(); |
| 213 | 0 | if (!file.isDead()) { |
| 214 | 0 | result++; |
| 215 | 0 | } |
| 216 | 0 | } |
| 217 | 0 | return result; |
| 218 | 0 | } |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
private double getCurrentAverageFileSize() { |
| 226 | 0 | return ((double) this.repository.getCurrentLOC()) / getCurrentFileCount(); |
| 227 | 0 | } |
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
private double getCurrentAverageRevisionCount() { |
| 235 | 0 | int revisions = 0; |
| 236 | 0 | final Iterator it = this.repository.getFiles().iterator(); |
| 237 | 0 | while (it.hasNext()) { |
| 238 | 0 | final VersionedFile file = (VersionedFile) it.next(); |
| 239 | 0 | if (!file.isDead()) { |
| 240 | 0 | revisions += file.getRevisions().size(); |
| 241 | 0 | } |
| 242 | 0 | } |
| 243 | 0 | return ((double) revisions) / getCurrentFileCount(); |
| 244 | 0 | } |
| 245 | |
} |