KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > CvsWeb3_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 3.0 interfaces to a cvs repository
18  *
19  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
20  * @version $Revision: 1.4 $ $Date: 2005/06/24 00:04:46 $
21  * @created on 7 dec. 2003
22  */

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

28     public CvsWeb3_0Interface(CVSGrab grabber) {
29         super(grabber);
30         
31         setFilesXpath("//TR/TD[@class = 'file']");
32         setFileNameXpath("A[2]/text()");
33         setFileVersionXpath("./following::node()/A/text()");
34         setDirectoriesXpath("//TR/TD[@class = 'dir'][A/@name][A/@name != 'Attic' and A/@href !='../']");
35         setDirectoryXpath("A/@name");
36         setCheckoutPath("~checkout~/");
37         setWebInterfaceType("cvsweb");
38     }
39
40     /**
41      * {@inheritDoc}
42      * @param htmlPage The web page
43      * @throws MarkerNotFoundException if the version marker for the web interface was not found
44      * @throws InvalidVersionException if the version detected is incompatible with the version supported by this web interface.
45      */

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

70     protected String JavaDoc getVersionMarker() {
71         return null;
72     }
73
74 }
75
Popular Tags