Coverage Report - net.sf.statcvs.output.ViewCvsIntegration
 
Classes in this File Line Coverage Branch Coverage Complexity
ViewCvsIntegration
88%
28/32
92%
11/12
1.5
 
 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: ViewCvsIntegration.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 ViewCVS
 34  
  *
 35  
  * @author Richard Cyganiak
 36  
  * @version $Id: ViewCvsIntegration.java,v 1.14 2008/04/02 11:22:15 benoitx Exp $
 37  
  */
 38  
 public class ViewCvsIntegration implements WebRepositoryIntegration {
 39  
     private String baseURL;
 40  200
     private Set atticFileNames = new HashSet();
 41  
     private String postfix;
 42  
 
 43  
     /**
 44  
      * @param baseURL base URL of the ViewCVS installation 
 45  
      */
 46  200
     public ViewCvsIntegration(String baseURL) {
 47  200
         final int i = baseURL.indexOf("?");
 48  200
         if (i != -1) {
 49  16
             this.postfix = baseURL.substring(i + 1);
 50  16
             baseURL = baseURL.substring(0, i);
 51  
         }
 52  
 
 53  200
         if (baseURL.endsWith("/")) {
 54  176
             this.baseURL = baseURL.substring(0, baseURL.length() - 1);
 55  
         } else {
 56  24
             this.baseURL = baseURL;
 57  
         }
 58  200
     }
 59  
 
 60  
     /**
 61  
      * @see net.sf.statcvs.output.WebRepositoryIntegration#getName
 62  
      */
 63  
     public String getName() {
 64  8
         return "ViewCVS";
 65  
     }
 66  
 
 67  
     /**
 68  
      * @see net.sf.statcvs.output.WebRepositoryIntegration#getDirectoryUrl
 69  
      */
 70  
     public String getDirectoryUrl(final Directory directory) {
 71  32
         return baseURL + "/" + directory.getPath();
 72  
     }
 73  
 
 74  
     protected String getFileUrl(final VersionedFile file, final String parameter) {
 75  
         String filename;
 76  72
         if (isInAttic(file)) {
 77  16
             final String path = file.getDirectory().getPath();
 78  16
             filename = "/" + path + "Attic/" + file.getFilename();
 79  
 
 80  14
         } else {
 81  56
             filename = "/" + file.getFilenameWithPath();
 82  
         }
 83  
 
 84  72
         String append = parameter;
 85  72
         if (this.postfix != null) {
 86  24
             append += (append.length() > 0) ? "&" + this.postfix : "?" + this.postfix;
 87  
         }
 88  72
         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  32
         return getFileUrl(file, "");
 96  
     }
 97  
 
 98  
     /**
 99  
      * @see net.sf.statcvs.output.WebRepositoryIntegration#getFileViewUrl(VersionedFile)
 100  
      */
 101  
     public String getFileViewUrl(final VersionedFile file) {
 102  24
         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  0
         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  16
         if (!oldRevision.getFile().equals(newRevision.getFile())) {
 117  0
             throw new IllegalArgumentException("revisions must be of the same file");
 118  
         }
 119  16
         return getFileUrl(oldRevision.getFile(), ".diff?r1=" + oldRevision.getRevisionNumber() + "&r2=" + newRevision.getRevisionNumber());
 120  
     }
 121  
 
 122  
     /**
 123  
      * @see net.sf.statcvs.output.WebRepositoryIntegration#setAtticFileNames(java.util.Set)
 124  
      */
 125  
     public void setAtticFileNames(final Set atticFileNames) {
 126  8
         this.atticFileNames = atticFileNames;
 127  8
     }
 128  
 
 129  
     protected boolean isInAttic(final VersionedFile file) {
 130  72
         return atticFileNames.contains(file.getFilenameWithPath());
 131  
     }
 132  
 
 133  
     protected String getPostfix() {
 134  0
         return postfix;
 135  
     }
 136  
 
 137  
     public String getBaseUrl() {
 138  0
         return baseURL;
 139  
     }
 140  
 }