1 package net.sf.statcvs.pages.xml;
2
3
4
5
6 import java.util.ArrayList;
7 import java.util.Calendar;
8 import java.util.Collection;
9 import java.util.Collections;
10 import java.util.Date;
11 import java.util.GregorianCalendar;
12 import java.util.Iterator;
13 import java.util.List;
14
15 import net.sf.statcvs.model.Commit;
16 import net.sf.statcvs.model.SymbolicName;
17 import net.sf.statcvs.output.ReportConfig;
18
19 import org.jdom.Element;
20
21 public class LogXmlMaker {
22 private final static String[] MONTH_TWO_CHARACTERS = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
23
24 public static String getAnchor(final SymbolicName tag) {
25 return "tag-" + tag.getName();
26 }
27
28 public static String getURL(final Date date) {
29 final Calendar calendar = new GregorianCalendar();
30 calendar.setTime(date);
31 return getFileName(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)) + ".html";
32 }
33
34 private static String getFileName(final int year, final int month) {
35 return year + "-" + MONTH_TWO_CHARACTERS[month];
36 }
37
38 private final ReportConfig config;
39 private final List commits = new ArrayList();
40
41
42
43
44
45
46
47
48
49 public LogXmlMaker(final ReportConfig config, final Collection commits) {
50 this.config = config;
51 final Iterator it = commits.iterator();
52 while (it.hasNext()) {
53 final Commit commit = (Commit) it.next();
54 this.commits.add(commit);
55 }
56 }
57
58 public Element toFile() {
59 Element lg = null;
60 if (!this.commits.isEmpty()) {
61 lg = new CommitListXml(this.commits, getTags(), true).renderCommitList(this.commits);
62 }
63 return lg;
64 }
65
66 private List getTags() {
67 final List tags = new ArrayList();
68 final Calendar calendar = new GregorianCalendar();
69 final Iterator it = this.config.getRepository().getSymbolicNames().iterator();
70 while (it.hasNext()) {
71 final SymbolicName tag = (SymbolicName) it.next();
72 calendar.setTime(tag.getDate());
73 }
74 Collections.reverse(tags);
75 return tags;
76 }
77 }