1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.output;
24
25 import java.util.HashSet;
26 import java.util.Set;
27
28 import net.sf.statcvs.model.Directory;
29 import net.sf.statcvs.model.Revision;
30 import net.sf.statcvs.model.VersionedFile;
31
32
33
34
35
36
37
38 public class ChoraIntegration implements WebRepositoryIntegration {
39 private String baseURL;
40 private Set atticFileNames = new HashSet();
41
42
43
44
45 public ChoraIntegration(final String baseURL) {
46 if (baseURL.endsWith("/")) {
47 this.baseURL = baseURL.substring(0, baseURL.length() - 1);
48 } else {
49 this.baseURL = baseURL;
50 }
51 }
52
53
54
55
56 public String getName() {
57 return "Chora";
58 }
59
60
61
62
63 public String getDirectoryUrl(final Directory directory) {
64 return baseURL + "/" + directory.getPath();
65 }
66
67
68
69
70 public String getFileHistoryUrl(final VersionedFile file) {
71 if (isInAttic(file)) {
72 final String path = file.getDirectory().getPath();
73 final String filename = file.getFilename();
74 return baseURL + "/" + path + "Attic/" + filename;
75 }
76 return this.baseURL + "/" + file.getFilenameWithPath();
77 }
78
79
80
81
82 public String getFileViewUrl(final VersionedFile file) {
83 return getFileHistoryUrl(file) + "?r=HEAD";
84 }
85
86
87
88
89 public String getFileViewUrl(final Revision revision) {
90 return getFileHistoryUrl(revision.getFile()) + "?r=" + revision.getRevisionNumber();
91 }
92
93
94
95
96 public String getDiffUrl(final Revision oldRevision, final Revision newRevision) {
97 if (!oldRevision.getFile().equals(newRevision.getFile())) {
98 throw new IllegalArgumentException("revisions must be of the same file");
99 }
100 return getFileHistoryUrl(oldRevision.getFile()) + "?r1=" + oldRevision.getRevisionNumber() + "&r2=" + newRevision.getRevisionNumber();
101 }
102
103
104
105
106 public void setAtticFileNames(final Set atticFileNames) {
107 this.atticFileNames = atticFileNames;
108 }
109
110 private boolean isInAttic(final VersionedFile file) {
111 return atticFileNames.contains(file.getFilenameWithPath());
112 }
113
114 public String getBaseUrl() {
115 return baseURL;
116 }
117 }