1 7 package net.sourceforge.cvsgrab.web; 8 9 import net.sourceforge.cvsgrab.CVSGrab; 10 import net.sourceforge.cvsgrab.InvalidVersionException; 11 import net.sourceforge.cvsgrab.MarkerNotFoundException; 12 import net.sourceforge.cvsgrab.RemoteFile; 13 import net.sourceforge.cvsgrab.WebBrowser; 14 15 import org.apache.commons.httpclient.URIException; 16 import org.apache.commons.jxpath.JXPathContext; 17 import org.w3c.dom.Document ; 18 19 20 27 public class ViewCvs1_0Interface extends ViewCvsInterface { 28 29 private String _root; 30 31 34 public ViewCvs1_0Interface(CVSGrab grabber) { 35 super(grabber); 36 setFileVersionXpath("TD/A/B"); 37 setFilesXpath("//TR[TD/A/IMG/@alt = '(file)' or contains(TD/A/IMG/@src, 'text')]"); 38 setDirectoriesXpath("//TR[TD/A/IMG/@alt = '(dir)' or contains(TD/A/IMG/@src, 'dir')][TD/A/@name != 'Attic']"); 40 41 } 42 43 49 public void detect(Document htmlPage) throws MarkerNotFoundException, InvalidVersionException { 50 super.detect(htmlPage); 51 _root = getGrabber().getProjectRoot(); 52 53 if (_root == null) { 54 JXPathContext context = JXPathContext.newContext(htmlPage); 55 context.setLenient(true); 56 String href = (String ) context.getValue("//A/@href[contains(., 'root=')]"); 57 if (href == null) { 58 CVSGrab.getLog().warn("CVS Root not found, there may be issues if ViewCvs is used with multiple repositories"); 59 CVSGrab.getLog().warn("Use the parameter -cvsRoot <root> to remove this warning"); 60 } else { 61 _root = href.substring(href.indexOf("root=")+ 5); 62 if (_root.indexOf('#') > 0) { 63 _root = _root.substring(0, _root.indexOf('#')); 64 } 65 if (_root.indexOf('&') > 0) { 66 _root = _root.substring(0, _root.indexOf('&')); 67 } 68 } 69 } 70 71 if (getGrabber().getRootUrl() != null && getGrabber().getRootUrl().startsWith("http://cvs.apache.org/viewcvs.cgi/") && _root != null && _root.indexOf("SVN") >= 0) { 73 throw new InvalidVersionException("CVSGrab cannot be used on projects hosted in a SVN repository"); 74 } 75 } 76 77 80 public String getBaseUrl() { 81 String url = WebBrowser.forceFinalSlash(getGrabber().getRootUrl()); 82 url += getGrabber().getPackagePath(); 83 url = WebBrowser.addQueryParam(url, getGrabber().getQueryParams()); 84 if (getGrabber().getProjectRoot() != null) { 85 url = WebBrowser.addQueryParam(url, "root", getGrabber().getProjectRoot()); 86 } 87 return url; 88 } 89 90 93 public String getAltBaseUrl() { 94 String url = WebBrowser.forceFinalSlash(getGrabber().getRootUrl()); 95 url = WebBrowser.addQueryParam(url, getGrabber().getQueryParams()); 96 return url; 97 } 98 99 104 public String getDirectoryUrl(String rootUrl, String directoryName) { 105 try { 106 String url = super.getDirectoryUrl(rootUrl, directoryName); 107 if (_root != null) { 108 url = WebBrowser.addQueryParam(url, "root", quote(_root)); 109 } 110 url = WebBrowser.addQueryParam(url, getQueryParams()); 111 return url; 112 } catch (URIException ex) { 113 ex.printStackTrace(); 114 throw new RuntimeException ("Cannot create URI"); 115 } 116 } 117 118 122 public String getDownloadUrl( RemoteFile file) { 123 try { 124 String url = super.getDownloadUrl(file); 126 if (_root != null) { 127 url = WebBrowser.addQueryParam(url, "root", quote(_root)); 128 } 129 url = WebBrowser.addQueryParam(url, getQueryParams()); 130 return url; 131 } catch (URIException ex) { 132 ex.printStackTrace(); 133 throw new RuntimeException ("Cannot create URI"); 134 } 135 } 136 137 140 public String getRoot() { 141 return _root; 142 } 143 144 147 public void setRoot(String root) { 148 _root = root; 149 } 150 151 protected String getVersionMarker() { 152 return "ViewCVS 1.0"; 153 } 154 155 protected void adjustFile(RemoteFile file, JXPathContext nodeContext) { 156 super.adjustFile(file, nodeContext); 157 String href = (String ) nodeContext.getValue("TD[1]/A/@href"); 158 if (href.indexOf("/Attic/" + file.getName()) >= 0) { 159 file.setInAttic(true); 160 } 161 } 162 163 } 164 | Popular Tags |