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 Sourcecast3_0Interface extends ViewCvsInterface { 26 27 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 44 public boolean presetMatch(String rootUrl, String 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 58 public void detect(Document htmlPage) throws MarkerNotFoundException, InvalidVersionException { 59 JXPathContext context = JXPathContext.newContext(htmlPage); 60 context.setLenient(true); 61 62 String keywords = (String ) context.getValue("//META[@name = 'keywords']/@content"); 64 String description = (String ) context.getValue("//META[@name = 'description']/@content"); 65 String version = (String ) context.getValue("//META[@name = 'version']/@content"); 66 if (version == null) { 67 version = (String ) 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 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 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 104 protected String getVersionMarker() { 105 return null; 106 } 107 108 } 109 | Popular Tags |