KickJava   Java API By Example, From Geeks To Geeks.

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


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
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 2.0 uses internally ViewCVS 0.9
20  *
21  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
22  * @version $Revision: 1.12 $ $Date: 2005/06/25 13:23:40 $
23  * @created on 12 oct. 2003
24  */

25 public class Sourcecast2_0Interface extends ViewCvsInterface {
26
27     /**
28      * Constructor for Sourcecast2_0Interface
29      */

30     public Sourcecast2_0Interface(CVSGrab grabber) {
31         super(grabber);
32         
33         setWebInterfaceType("browse");
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         JXPathContext context = JXPathContext.newContext(htmlPage);
44         context.setLenient(true);
45
46         // Check that this is Sourcecast/CollabNet
47
String JavaDoc keywords = (String JavaDoc) context.getValue("//META[@name = 'keywords']/@content");
48         String JavaDoc description = (String JavaDoc) context.getValue("//META[@name = 'description']/@content");
49         String JavaDoc version = (String JavaDoc) context.getValue("//META[@name = 'version']/@content");
50         if (version == null) {
51             version = (String JavaDoc) context.getValue("//META[@name = 'SourceCastVersion']/@content");
52         }
53
54         boolean sourcecastKeyword = false;
55         boolean collabnetKeyword = false;
56         if (keywords != null) {
57             sourcecastKeyword = (keywords.toLowerCase().indexOf("sourcecast") >= 0);
58             collabnetKeyword = (keywords.toLowerCase().indexOf("collabnet") >= 0);
59         }
60         if (description != null) {
61             sourcecastKeyword |= (description.toLowerCase().indexOf("sourcecast") >= 0);
62             collabnetKeyword |= (description.toLowerCase().indexOf("collabnet") >= 0);
63         }
64         if (!sourcecastKeyword && !collabnetKeyword) {
65             throw new MarkerNotFoundException("Not SourceCast/CollabNet, meta keywords was '" + keywords + "', description was '" + description + "'");
66         }
67         if (version == null || !version.startsWith("2.")) {
68             throw new InvalidVersionException("Invalid version " + version);
69         }
70         int minorVersion = Integer.parseInt(version.substring(2, version.indexOf('.', 2)));
71         if (minorVersion >= 6) {
72             throw new InvalidVersionException("Version 2.6 and later are not supported, as they are similar to version 3.0");
73         }
74         setType("SourceCast " + version);
75     }
76
77     /**
78      * {@inheritDoc}
79      * @return
80      */

81     protected String JavaDoc getVersionMarker() {
82         return null;
83     }
84
85 }
86
Popular Tags