KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > ViewCvs0_9Interface


1 /*
2  * CVSGrab
3  * Author: Ludovic Claude (ludovicc@users.sourceforge.net)
4  * Distributable under BSD license.
5  * See terms of license at gnu.org.
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.WebBrowser;
13
14 import org.apache.commons.jxpath.JXPathContext;
15 import org.w3c.dom.Document JavaDoc;
16
17
18 /**
19  * Support for ViewCvs 0.9 interfaces to a cvs repository
20  *
21  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
22  * @version $Revision: 1.7 $ $Date: 2005/06/22 23:38:14 $
23  * @created on 11 oct. 2003
24  */

25 public class ViewCvs0_9Interface extends ViewCvsInterface {
26
27     private String JavaDoc _root;
28     
29     /**
30      * Constructor for ViewCvs0_9Interface
31      */

32     public ViewCvs0_9Interface(CVSGrab grabber) {
33         super(grabber);
34     }
35
36     /**
37      * {@inheritDoc}
38      * @param htmlPage The web page
39      * @throws MarkerNotFoundException if the version marker for the web interface was not found
40      * @throws InvalidVersionException if the version detected is incompatible with the version supported by this web interface.
41      */

42     public void detect(Document JavaDoc htmlPage) throws MarkerNotFoundException, InvalidVersionException {
43         super.detect(htmlPage);
44         
45         _root = getGrabber().getProjectRoot();
46         if (_root == null) {
47             JXPathContext context = JXPathContext.newContext(htmlPage);
48             context.setLenient(true);
49             String JavaDoc href = (String JavaDoc) context.getValue("//A/@href[contains(., 'cvsroot=')]");
50             if (href != null) {
51                 _root = href.substring(href.indexOf("cvsroot=") + 8);
52                 if (_root.indexOf('#') > 0) {
53                     _root = _root.substring(0, _root.indexOf('#'));
54                 }
55                 if (_root.indexOf('&') > 0) {
56                     _root = _root.substring(0, _root.indexOf('&'));
57                 }
58             }
59             getGrabber().getWebOptions().setProjectRoot(_root);
60         }
61     }
62
63     protected String JavaDoc getVersionMarker() {
64         return "ViewCVS 0.9";
65     }
66
67     /**
68      * @return the alternate base url to use when trying to auto-detect this type of web interface
69      */

70     public String JavaDoc getAltBaseUrl() {
71         String JavaDoc url = WebBrowser.forceFinalSlash(getGrabber().getRootUrl());
72         url = WebBrowser.addQueryParam(getCvsrootParam(), getProjectRoot());
73         url = WebBrowser.addQueryParam(url, getGrabber().getQueryParams());
74         return url;
75     }
76
77     /**
78      * @return
79      */

80     public String JavaDoc getProjectRoot() {
81         if (_root == null) {
82             _root = getGrabber().getProjectRoot();
83         }
84         return _root;
85     }
86
87     /**
88      * @param root
89      */

90     public void setProjectRoot(String JavaDoc root) {
91         _root = root;
92     }
93
94 }
95
Popular Tags