1 package net.sf.statcvs.pages.xml;
2
3
4
5
6
7
8
9
10 import java.util.Iterator;
11 import java.util.SortedSet;
12 import java.util.Stack;
13
14 import net.sf.statcvs.model.Directory;
15 import net.sf.statcvs.model.Repository;
16 import net.sf.statcvs.output.ReportConfig;
17
18 import org.jdom.Element;
19
20 public class DirectoriesXml {
21 private final SortedSet directory;
22 private final Repository repository;
23
24
25
26
27 public DirectoriesXml(final ReportConfig config) {
28 this.repository = config.getRepository();
29 directory = this.repository.getDirectories();
30 }
31
32
33
34
35
36
37 public Element toFile() {
38 final Element dir = new Element(XmlTags.TAG_DIRECTORIES);
39 final Iterator it = this.directory.iterator();
40
41
42 final Element parent = dir;
43 final Stack stack = new Stack();
44 stack.add(dir);
45 while (it.hasNext()) {
46 final Directory direc = (Directory) it.next();
47 final Element item = format(direc, 0);
48
49
50
51
52
53
54
55
56
57
58
59 parent.addContent(item);
60
61
62
63
64
65 }
66
67 return dir;
68 }
69
70
71
72
73
74
75
76 private Element format(final Directory dir, final int currentDepth) {
77 final Element element = new Element(XmlTags.TAG_DIRECTORY);
78 final Element path = new Element(XmlTags.TAG_PATH);
79
80 path.setText(dir.getPath());
81 if (dir.isEmpty()) {
82 element.setAttribute("status", "deleted");
83 }
84 final Element child1 = new Element(XmlTags.TAG_FILES);
85 final String str = Integer.toString(dir.getCurrentFileCount());
86 child1.setText(str);
87 final Element child2 = new Element(XmlTags.TAG_LINES_CHANGED);
88 final String str2 = Integer.toString(dir.getCurrentLOC());
89 child2.setText(str2);
90 element.addContent(path);
91 element.addContent(child1);
92 element.addContent(child2);
93 return element;
94 }
95 }