KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > Sourcecast3_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 3.0 interfaces to a cvs repository. <p>
18  *
19  * Sourcecast 3.0 uses internally ViewCVS 0.9
20  *
21  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
22  * @version $Revision: 1.4 $ $Date: 2005/06/25 19:51:33 $
23  * @created on 12 oct. 2003
24  */

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

30     public Sourcecast3_0Interface(CVSGrab grabber) {
31         super(grabber);
32         
33         setFilesXpath("//TABLE[@class = 'filebrowse']//TD/DIV[@class = 'leaf']");
34         setFileNameXpath("@id");
35         setFileVersionXpath("../following::node()/text()");
36         setDirectoriesXpath("//TABLE[@class = 'filebrowse']//TD/DIV[@class = 'leafnode'][@id != 'Attic']");
37         setDirectoryXpath("@id");
38         setWebInterfaceType("browse");
39     }
40
41     /**
42      * {@inheritDoc}
43      */

44     public boolean presetMatch(String JavaDoc rootUrl, String JavaDoc packagePath) {
45         if (rootUrl.indexOf("dev.java.net") > 0) {
46             setType("SourceCast 3.0 on dev.java.net");
47             return true;
48         }
49         return false;
50     }
51
52     /**
53      * {@inheritDoc}
54      * @param htmlPage The web page
55      * @throws MarkerNotFoundException if the version marker for the web interface was not found
56      * @throws InvalidVersionException if the version detected is incompatible with the version supported by this web interface.
57      */

58     public void detect(Document JavaDoc htmlPage) throws MarkerNotFoundException, InvalidVersionException {
59         JXPathContext context = JXPathContext.newContext(htmlPage);
60         context.setLenient(true);
61
62         // Check that this is Sourcecast/CollabNet
63
String JavaDoc keywords = (String JavaDoc) context.getValue("//META[@name = 'keywords']/@content");
64         String JavaDoc description = (String JavaDoc) context.getValue("//META[@name = 'description']/@content");
65         String JavaDoc version = (String JavaDoc) context.getValue("//META[@name = 'version']/@content");
66         if (version == null) {
67             version = (String JavaDoc) context.getValue("//META[@name = 'SourceCastVersion']/@content");
68         }
69
70         boolean sourcecastKeyword = false;
71         boolean collabnetKeyword = false;
72         boolean poweredByCollabnet = false;
73         if (keywords != null) {
74             sourcecastKeyword = (keywords.toLowerCase().indexOf("sourcecast") >= 0);
75             collabnetKeyword = (keywords.toLowerCase().indexOf("collabnet") >= 0);
76         }
77         if (description != null) {
78             sourcecastKeyword |= (description.toLowerCase().indexOf("sourcecast") >= 0);
79             collabnetKeyword |= (description.toLowerCase().indexOf("collabnet") >= 0);
80         }
81         if (!sourcecastKeyword && !collabnetKeyword && version != null) {
82             // Try to scan the Powered by buttons
83
poweredByCollabnet = context.getValue("//A[contains(@href, 'www.collab.net')][IMG/@id='poweredby']") != null;
84         }
85         if (!sourcecastKeyword && !collabnetKeyword && !poweredByCollabnet) {
86             throw new MarkerNotFoundException("Not SourceCast/CollabNet, meta keywords was '" + keywords + "', description was '" + description + "'");
87         }
88         if (version != null && version.startsWith("2.")) {
89             // Only 2.6+ generated an html similar to version 3.0
90
int minorVersion = Integer.parseInt(version.substring(2, version.indexOf('.', 2)));
91             if (minorVersion < 6) {
92                 throw new InvalidVersionException("Version 2.5 and earlier are not supported");
93             }
94         } else if (version == null || !version.startsWith("3.")) {
95             throw new InvalidVersionException("Invalid version " + version);
96         }
97         setType("SourceCast " + version);
98     }
99
100     /**
101      * {@inheritDoc}
102      * @return
103      */

104     protected String JavaDoc getVersionMarker() {
105         return null;
106     }
107
108 }
109
Popular Tags