1 6 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 26 public class CvsWeb1_0Interface extends ViewCvsInterface { 27 28 private String _root; 29 30 33 public CvsWeb1_0Interface(CVSGrab grabber) { 34 super(grabber); 35 36 setFilesXpath("//TR[TD//IMG/@alt = '[TXT]']"); 37 setDirectoriesXpath("//TR[TD//IMG/@alt = '[DIR]'][TD/A/@name != 'Attic']"); 38 setCheckoutPath("~checkout~/"); 39 setWebInterfaceType("cvsweb"); 40 } 41 42 48 public void detect(Document htmlPage) throws MarkerNotFoundException, InvalidVersionException { 49 JXPathContext context = JXPathContext.newContext(htmlPage); 50 context.setLenient(true); 51 String generator = (String ) context.getValue("//comment()[starts-with(normalize-space(.),'hennerik CVSweb')]"); 53 54 if (generator == null) { 55 throw new MarkerNotFoundException("Not CvsWeb, did not found comment containing 'hennerik CVSweb'"); 56 } 57 58 setType(generator); 59 60 _root = getGrabber().getProjectRoot(); 61 if (_root == null) { 62 String href = (String ) context.getValue("//A/@href[contains(., 'cvsroot=')]"); 63 if (href != null) { 64 _root = href.substring(href.indexOf("cvsroot=") + 8); 65 if (_root.indexOf('#') > 0) { 66 _root = _root.substring(0, _root.indexOf('#')); 67 } 68 if (_root.indexOf('&') > 0) { 69 _root = _root.substring(0, _root.indexOf('&')); 70 } 71 } 72 } 73 74 } 75 76 79 protected String getVersionMarker() { 80 return null; 81 } 82 83 86 public String getBaseUrl() { 87 String url = WebBrowser.forceFinalSlash(getGrabber().getRootUrl()); 88 url += getGrabber().getPackagePath(); 89 url = WebBrowser.addQueryParam(url, getGrabber().getQueryParams()); 90 if (getGrabber().getProjectRoot() != null) { 91 url = WebBrowser.addQueryParam(url, "cvsroot", getGrabber().getProjectRoot()); 92 } 93 return url; 94 } 95 96 99 public String getAltBaseUrl() { 100 String url = WebBrowser.forceFinalSlash(getGrabber().getRootUrl()); 101 url = WebBrowser.addQueryParam(url, getGrabber().getQueryParams()); 102 return url; 103 } 104 105 108 public String getDirectoryUrl(String rootUrl, String directoryName) { 109 try { 110 String url = super.getDirectoryUrl(rootUrl, directoryName); 111 if (_root != null) { 112 url = WebBrowser.addQueryParam(url, "cvsroot", quote(_root)); 113 } 114 url = WebBrowser.addQueryParam(url, getQueryParams()); 115 return url; 116 } catch (URIException ex) { 117 ex.printStackTrace(); 118 throw new RuntimeException ("Cannot create URI"); 119 } 120 } 121 122 public String getDownloadUrl( RemoteFile file) { 123 try { 124 String url = super.getDownloadUrl(file); 126 if (_root != null) { 127 url = WebBrowser.addQueryParam(url, "cvsroot", 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 public String getRoot() { 138 return _root; 139 } 140 141 public void setRoot(String root) { 142 _root = root; 143 } 144 145 } 146 | Popular Tags |