KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > javanet > ProjectList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.bugs.javanet;
21
22 import org.netbeans.modules.tasklist.bugs.ProjectDesc;
23
24 import java.net.URL JavaDoc;
25 import java.net.URLConnection JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.BufferedInputStream JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 /**
34  * Lists all projects on java.net.
35  *
36  * @author Petr Kuzel
37  */

38 public final class ProjectList {
39
40     public static ProjectDesc[] listProjects() {
41         List JavaDoc components = new ArrayList JavaDoc(23);
42         try {
43             URL JavaDoc list = new URL JavaDoc("http://community.java.net/projects/alpha.csp?only=hosted");
44             URLConnection JavaDoc io = list.openConnection();
45             io.connect();
46             InputStream JavaDoc in = new BufferedInputStream JavaDoc(io.getInputStream());
47             int next = in.read();
48             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
49             while (next != -1) {
50                 sb.append((char) next);
51                 next = in.read();
52             }
53
54             // parse output looking for componet names by MAGIC
55

56             String JavaDoc sample = sb.toString();
57             String JavaDoc MAGIC = "<p><b><a HREF=\"https://"; // NOi18N
58

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); // .dev.java.net
65
if (entry == -1) break;
66                 String JavaDoc 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 JavaDoc e) {
75             return new ProjectDesc[0];
76         } catch (IOException JavaDoc e) {
77             return new ProjectDesc[0];
78         }
79     }
80 }
81
Popular Tags