1 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 ; 15 16 25 public class Sourcecast2_0Interface extends ViewCvsInterface { 26 27 30 public Sourcecast2_0Interface(CVSGrab grabber) { 31 super(grabber); 32 33 setWebInterfaceType("browse"); 34 } 35 36 42 public void detect(Document htmlPage) throws MarkerNotFoundException, InvalidVersionException { 43 JXPathContext context = JXPathContext.newContext(htmlPage); 44 context.setLenient(true); 45 46 String keywords = (String ) context.getValue("//META[@name = 'keywords']/@content"); 48 String description = (String ) context.getValue("//META[@name = 'description']/@content"); 49 String version = (String ) context.getValue("//META[@name = 'version']/@content"); 50 if (version == null) { 51 version = (String ) 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 81 protected String getVersionMarker() { 82 return null; 83 } 84 85 } 86 | Popular Tags |