View Javadoc

1   /*
2   	StatCvs - CVS statistics generation 
3   	Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4   	http://statcvs.sf.net/
5       
6   	This library is free software; you can redistribute it and/or
7   	modify it under the terms of the GNU Lesser General Public
8   	License as published by the Free Software Foundation; either
9   	version 2.1 of the License, or (at your option) any later version.
10  
11  	This library is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  	Lesser General Public License for more details.
15  
16  	You should have received a copy of the GNU Lesser General Public
17  	License along with this library; if not, write to the Free Software
18  	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19      
20  	$RCSfile: CvswebIntegration.java,v $
21  	$Date: 2008/04/02 11:22:15 $ 
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   * Integration of cvsweb
34   *
35   * @author Richard Cyganiak
36   * @version $Id: CvswebIntegration.java,v 1.13 2008/04/02 11:22:15 benoitx Exp $
37   */
38  public class CvswebIntegration implements WebRepositoryIntegration {
39      private String baseURL;
40      private Set atticFileNames = new HashSet();
41      private String postfix;
42  
43      /**
44       * @param baseURL base URL of the cvsweb installation
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       * @see net.sf.statcvs.output.WebRepositoryIntegration#getName
62       */
63      public String getName() {
64          return "cvsweb";
65      }
66  
67      /**
68       * @see net.sf.statcvs.output.WebRepositoryIntegration#getDirectoryUrl
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       * @see net.sf.statcvs.output.WebRepositoryIntegration#getFileHistoryUrl
93       */
94      public String getFileHistoryUrl(final VersionedFile file) {
95          return getFileUrl(file, "");
96      }
97  
98      /**
99       * @see net.sf.statcvs.output.WebRepositoryIntegration#getFileViewUrl(VersionedFile)
100      */
101     public String getFileViewUrl(final VersionedFile file) {
102         return getFileUrl(file, "?rev=HEAD&content-type=text/vnd.viewcvs-markup");
103     }
104 
105     /**
106      * @see net.sf.statcvs.output.WebRepositoryIntegration#getFileViewUrl(VersionedFile)
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      * @see net.sf.statcvs.output.WebRepositoryIntegration#getDiffUrl
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      * @see net.sf.statcvs.output.WebRepositoryIntegration#setAtticFileNames(java.util.Set)
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 }