| 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 | 0 | 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 | 0 | return "tag-" + tag.getName(); |
| 33 | |
} |
| 34 | |
|
| 35 | |
public static String getURL(final Date date) { |
| 36 | 0 | final Calendar calendar = new GregorianCalendar(); |
| 37 | 0 | calendar.setTime(date); |
| 38 | 0 | 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 | 0 | return year + "-" + MONTH_TWO_CHARACTERS[month]; |
| 43 | |
} |
| 44 | |
|
| 45 | |
private final Repository repo; |
| 46 | 0 | private final List commits = new ArrayList(); |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | 0 | public RevisedFilesXml(final ReportConfig config) { |
| 57 | 0 | this.repo = config.getRepository(); |
| 58 | 0 | final Iterator it = this.repo.getCommits().iterator(); |
| 59 | 0 | while (it.hasNext()) { |
| 60 | 0 | final Commit commit = (Commit) it.next(); |
| 61 | 0 | this.commits.add(commit); |
| 62 | 0 | } |
| 63 | 0 | Collections.reverse(this.commits); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
public Element toFile() throws NoSuchElementException { |
| 67 | 0 | Set files = null; |
| 68 | 0 | final Hashtable coms = new Hashtable(); |
| 69 | 0 | final Iterator commitIt = this.commits.iterator(); |
| 70 | 0 | Commit nextCommit = commitIt.hasNext() ? (Commit) commitIt.next() : null; |
| 71 | 0 | final ArrayList al = new ArrayList(); |
| 72 | |
|
| 73 | |
|
| 74 | 0 | while (nextCommit != null) { |
| 75 | 0 | files = nextCommit.getAffectedFiles(); |
| 76 | 0 | final Iterator it = files.iterator(); |
| 77 | 0 | final String auth = nextCommit.getAuthor().toString(); |
| 78 | 0 | while (it.hasNext()) { |
| 79 | 0 | final String path = it.next().toString(); |
| 80 | 0 | if (!(coms.containsKey(path))) { |
| 81 | 0 | al.add(path); |
| 82 | 0 | final ArrayList a = new ArrayList(); |
| 83 | 0 | a.add(auth); |
| 84 | 0 | coms.put(path, a); |
| 85 | 0 | } else { |
| 86 | 0 | final ArrayList alist = (ArrayList) coms.get(path); |
| 87 | 0 | final Iterator iter = alist.iterator(); |
| 88 | 0 | final ArrayList l = new ArrayList(); |
| 89 | 0 | for (int i = 0; i < alist.size(); i++) { |
| 90 | 0 | l.add(iter.next().toString()); |
| 91 | |
} |
| 92 | 0 | l.add(auth); |
| 93 | 0 | coms.remove(path); |
| 94 | 0 | coms.put(path, l); |
| 95 | |
} |
| 96 | |
|
| 97 | 0 | } |
| 98 | 0 | nextCommit = commitIt.hasNext() ? (Commit) commitIt.next() : null; |
| 99 | |
|
| 100 | 0 | } |
| 101 | 0 | final Element lg = new Element(XmlTags.TAG_REVISED_FILES); |
| 102 | 0 | final Iterator it = al.iterator(); |
| 103 | 0 | while (it.hasNext()) { |
| 104 | 0 | final Element file = new Element(XmlTags.TAG_FILE); |
| 105 | 0 | final Element path = new Element(XmlTags.TAG_PATH); |
| 106 | 0 | final String str = it.next().toString(); |
| 107 | 0 | path.setText(str); |
| 108 | 0 | final ArrayList a = (ArrayList) coms.get(str); |
| 109 | 0 | final Iterator itr = a.iterator(); |
| 110 | 0 | file.addContent(path); |
| 111 | 0 | while (itr.hasNext()) { |
| 112 | 0 | final String s = itr.next().toString(); |
| 113 | 0 | final Element auth = new Element(XmlTags.TAG_AUTHOR); |
| 114 | 0 | auth.setText(s); |
| 115 | 0 | file.addContent(auth); |
| 116 | 0 | } |
| 117 | 0 | lg.addContent(file); |
| 118 | 0 | } |
| 119 | 0 | return lg; |
| 120 | |
} |
| 121 | |
} |