| 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 | 200 | private Set atticFileNames = new HashSet(); |
| 41 | |
private String postfix; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 200 | public CvswebIntegration(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 | |
|
| 62 | |
|
| 63 | |
public String getName() { |
| 64 | 8 | return "cvsweb"; |
| 65 | |
} |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
public String getDirectoryUrl(final Directory directory) { |
| 71 | 16 | return baseURL + "/" + directory.getPath(); |
| 72 | |
} |
| 73 | |
|
| 74 | |
private 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 | |
|
| 93 | |
|
| 94 | |
public String getFileHistoryUrl(final VersionedFile file) { |
| 95 | 32 | return getFileUrl(file, ""); |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 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 | |
|
| 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 | |
|
| 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() + "&f=h"); |
| 120 | |
} |
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
public void setAtticFileNames(final Set atticFileNames) { |
| 126 | 8 | this.atticFileNames = atticFileNames; |
| 127 | 8 | } |
| 128 | |
|
| 129 | |
private boolean isInAttic(final VersionedFile file) { |
| 130 | 72 | return atticFileNames.contains(file.getFilenameWithPath()); |
| 131 | |
} |
| 132 | |
|
| 133 | |
public String getBaseUrl() { |
| 134 | 0 | return baseURL; |
| 135 | |
} |
| 136 | |
} |