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 CvswebIntegration implements WebRepositoryIntegration {
39      private String baseURL;
40      private Set atticFileNames = new HashSet();
41      private String postfix;
42  
43      
44  
45  
46      public CvswebIntegration(String baseURL) {
47          final int i = baseURL.indexOf("?");
48          if (i != -1) {
49              this.postfix = baseURL.substring(i + 1);
50              baseURL = baseURL.substring(0, i);
51          }
52  
53          if (baseURL.endsWith("/")) {
54              this.baseURL = baseURL.substring(0, baseURL.length() - 1);
55          } else {
56              this.baseURL = baseURL;
57          }
58      }
59  
60      
61  
62  
63      public String getName() {
64          return "cvsweb";
65      }
66  
67      
68  
69  
70      public String getDirectoryUrl(final Directory directory) {
71          return baseURL + "/" + directory.getPath();
72      }
73  
74      private String getFileUrl(final VersionedFile file, final String parameter) {
75          String filename;
76          if (isInAttic(file)) {
77              final String path = file.getDirectory().getPath();
78              filename = "/" + path + "Attic/" + file.getFilename();
79  
80          } else {
81              filename = "/" + file.getFilenameWithPath();
82          }
83  
84          String append = parameter;
85          if (this.postfix != null) {
86              append += (append.length() > 0) ? "&" + this.postfix : "?" + this.postfix;
87          }
88          return this.baseURL + filename + append;
89      }
90  
91      
92  
93  
94      public String getFileHistoryUrl(final VersionedFile file) {
95          return getFileUrl(file, "");
96      }
97  
98      
99  
100 
101     public String getFileViewUrl(final VersionedFile file) {
102         return getFileUrl(file, "?rev=HEAD&content-type=text/vnd.viewcvs-markup");
103     }
104 
105     
106 
107 
108     public String getFileViewUrl(final Revision revision) {
109         return getFileUrl(revision.getFile(), "?rev=" + revision.getRevisionNumber() + "&content-type=text/vnd.viewcvs-markup");
110     }
111 
112     
113 
114 
115     public String getDiffUrl(final Revision oldRevision, final Revision newRevision) {
116         if (!oldRevision.getFile().equals(newRevision.getFile())) {
117             throw new IllegalArgumentException("revisions must be of the same file");
118         }
119         return getFileUrl(oldRevision.getFile(), ".diff?r1=" + oldRevision.getRevisionNumber() + "&r2=" + newRevision.getRevisionNumber() + "&f=h");
120     }
121 
122     
123 
124 
125     public void setAtticFileNames(final Set atticFileNames) {
126         this.atticFileNames = atticFileNames;
127     }
128 
129     private boolean isInAttic(final VersionedFile file) {
130         return atticFileNames.contains(file.getFilenameWithPath());
131     }
132 
133     public String getBaseUrl() {
134         return baseURL;
135     }
136 }