1 package net.sf.statcvs.pages.xml;
2
3
4
5
6
7
8
9
10 import java.util.ArrayList;
11 import java.util.Calendar;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.GregorianCalendar;
15 import java.util.Hashtable;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.NoSuchElementException;
19 import java.util.Set;
20
21 import net.sf.statcvs.model.Commit;
22 import net.sf.statcvs.model.Repository;
23 import net.sf.statcvs.model.SymbolicName;
24 import net.sf.statcvs.output.ReportConfig;
25
26 import org.jdom.Element;
27
28 public class RevisedFilesXml {
29 private final static String[] MONTH_TWO_CHARACTERS = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
30
31 public static String getAnchor(final SymbolicName tag) {
32 return "tag-" + tag.getName();
33 }
34
35 public static String getURL(final Date date) {
36 final Calendar calendar = new GregorianCalendar();
37 calendar.setTime(date);
38 return getFileName(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)) + ".html";
39 }
40
41 private static String getFileName(final int year, final int month) {
42 return year + "-" + MONTH_TWO_CHARACTERS[month];
43 }
44
45 private final Repository repo;
46 private final List commits = new ArrayList();
47
48
49
50
51
52
53
54
55
56 public RevisedFilesXml(final ReportConfig config) {
57 this.repo = config.getRepository();
58 final Iterator it = this.repo.getCommits().iterator();
59 while (it.hasNext()) {
60 final Commit commit = (Commit) it.next();
61 this.commits.add(commit);
62 }
63 Collections.reverse(this.commits);
64 }
65
66 public Element toFile() throws NoSuchElementException {
67 Set files = null;
68 final Hashtable coms = new Hashtable();
69 final Iterator commitIt = this.commits.iterator();
70 Commit nextCommit = commitIt.hasNext() ? (Commit) commitIt.next() : null;
71 final ArrayList al = new ArrayList();
72
73
74 while (nextCommit != null) {
75 files = nextCommit.getAffectedFiles();
76 final Iterator it = files.iterator();
77 final String auth = nextCommit.getAuthor().toString();
78 while (it.hasNext()) {
79 final String path = it.next().toString();
80 if (!(coms.containsKey(path))) {
81 al.add(path);
82 final ArrayList a = new ArrayList();
83 a.add(auth);
84 coms.put(path, a);
85 } else {
86 final ArrayList alist = (ArrayList) coms.get(path);
87 final Iterator iter = alist.iterator();
88 final ArrayList l = new ArrayList();
89 for (int i = 0; i < alist.size(); i++) {
90 l.add(iter.next().toString());
91 }
92 l.add(auth);
93 coms.remove(path);
94 coms.put(path, l);
95 }
96
97 }
98 nextCommit = commitIt.hasNext() ? (Commit) commitIt.next() : null;
99
100 }
101 final Element lg = new Element(XmlTags.TAG_REVISED_FILES);
102 final Iterator it = al.iterator();
103 while (it.hasNext()) {
104 final Element file = new Element(XmlTags.TAG_FILE);
105 final Element path = new Element(XmlTags.TAG_PATH);
106 final String str = it.next().toString();
107 path.setText(str);
108 final ArrayList a = (ArrayList) coms.get(str);
109 final Iterator itr = a.iterator();
110 file.addContent(path);
111 while (itr.hasNext()) {
112 final String s = itr.next().toString();
113 final Element auth = new Element(XmlTags.TAG_AUTHOR);
114 auth.setText(s);
115 file.addContent(auth);
116 }
117 lg.addContent(file);
118 }
119 return lg;
120 }
121 }