KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CVSGrab
3  * Author: Ludovic Claude (ludovicc@users.sourceforge.net)
4  * Distributable under BSD license.
5  */

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
13 import org.apache.commons.jxpath.JXPathContext;
14 import org.w3c.dom.Document JavaDoc;
15
16 /**
17  * Support for CvsWeb 2.0 interfaces to a cvs repository
18  *
19  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
20  * @version $Revision: 1.8 $ $Date: 2005/06/22 23:38:14 $
21  * @created on 7 dec. 2003
22  */

23 public class CvsWeb2_0Interface extends ViewCvsInterface {
24
25     /**
26      * Constructor for CvsWeb2_0Interface
27      */

28     public CvsWeb2_0Interface(CVSGrab grabber) {
29         super(grabber);
30         
31         setFilesXpath("//TR[TD/A/IMG/@alt = '[TXT]']");
32         setDirectoriesXpath("//TR[TD/A/IMG/@alt = '[DIR]'][TD/A/@name != 'Attic']");
33         setCheckoutPath("~checkout~/");
34         setWebInterfaceType("cvsweb");
35     }
36
37     /**
38      * {@inheritDoc}
39      * @param htmlPage The web page
40      * @throws MarkerNotFoundException if the version marker for the web interface was not found
41      * @throws InvalidVersionException if the version detected is incompatible with the version supported by this web interface.
42      */

43     public void detect(Document JavaDoc htmlPage) throws MarkerNotFoundException, InvalidVersionException {
44         JXPathContext context = JXPathContext.newContext(htmlPage);
45         context.setLenient(true);
46         // Check that this is CvsWeb
47
String JavaDoc generator = (String JavaDoc) context.getValue("//META[@name = 'generator']/@content");
48
49         if (generator == null) {
50             generator = (String JavaDoc) context.getValue("//comment()[starts-with(normalize-space(.),'FreeBSD-cvsweb')]");
51         }
52
53         if (generator == null || generator.toLowerCase().indexOf("cvsweb") < 0) {
54             throw new MarkerNotFoundException("Not CvsWeb, found marker " + generator);
55         }
56         if (generator.indexOf(" 2.") < 0) {
57             throw new InvalidVersionException("Version not supported of CvsWeb: " + generator);
58         }
59
60         setType(generator);
61     }
62
63     /**
64      * {@inheritDoc}
65      * @return
66      */

67     protected String JavaDoc getVersionMarker() {
68         return null;
69     }
70
71 }
72
Popular Tags