1 19 20 package org.netbeans.modules.tasklist.bugs.javanet; 21 22 import org.netbeans.modules.tasklist.bugs.ProjectDesc; 23 24 import java.net.URL ; 25 import java.net.URLConnection ; 26 import java.net.MalformedURLException ; 27 import java.util.List ; 28 import java.util.ArrayList ; 29 import java.io.InputStream ; 30 import java.io.BufferedInputStream ; 31 import java.io.IOException ; 32 33 38 public final class ProjectList { 39 40 public static ProjectDesc[] listProjects() { 41 List components = new ArrayList (23); 42 try { 43 URL list = new URL ("http://community.java.net/projects/alpha.csp?only=hosted"); 44 URLConnection io = list.openConnection(); 45 io.connect(); 46 InputStream in = new BufferedInputStream (io.getInputStream()); 47 int next = in.read(); 48 StringBuffer sb = new StringBuffer (); 49 while (next != -1) { 50 sb.append((char) next); 51 next = in.read(); 52 } 53 54 56 String sample = sb.toString(); 57 String MAGIC = "<p><b><a HREF=\"https://"; 59 int entry = 0; 60 int end = -1; 61 while (true) { 62 entry = sample.indexOf(MAGIC, entry); 63 if (entry == -1) break; 64 end = sample.indexOf(".", entry); if (entry == -1) break; 66 String component = sample.substring(entry + MAGIC.length(), end); 67 entry = end; 68 ProjectDesc desc = new ProjectDesc(); 69 desc.name = component; 70 components.add(desc); 71 } 72 return (ProjectDesc[]) components.toArray(new ProjectDesc[components.size()]); 73 74 } catch (MalformedURLException e) { 75 return new ProjectDesc[0]; 76 } catch (IOException e) { 77 return new ProjectDesc[0]; 78 } 79 } 80 } 81 | Popular Tags |