KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > Sourcecast1_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 SourceCast 2.0 interfaces to a cvs repository. <p>
18  *
19  * SourceCast 1.x is based apparently on CvsWeb 2.0
20  *
21  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
22  * @version $Revision: 1.6 $ $Date: 2005/06/22 23:38:14 $
23  * @created on 27 dec. 2003
24  */

25 public class Sourcecast1_0Interface extends CvsWeb2_0Interface {
26
27     /**
28      * Constructor for Sourcecast1_0Interface
29      */

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

44     public void detect(Document JavaDoc htmlPage) throws MarkerNotFoundException, InvalidVersionException {
45         JXPathContext context = JXPathContext.newContext(htmlPage);
46         context.setLenient(true);
47         
48         // Check that this is Sourcecast
49
String JavaDoc version = (String JavaDoc) context.getValue("//META[@name = 'SOURCECAST-VERSION']/@content");
50         if (version == null) {
51             throw new MarkerNotFoundException();
52         }
53         if (!version.startsWith("1.")) {
54             throw new InvalidVersionException("Invalid version " + version);
55         }
56         setType("SourceCast " + version);
57     }
58     
59 }
60
Popular Tags