KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ashkelon > pages > PackagesPage


1 package org.ashkelon.pages;
2
3 import org.ashkelon.*;
4 import org.ashkelon.db.*;
5 import java.sql.*;
6 import java.util.*;
7
8 /**
9  * @author Eitan Suez
10  */

11 public class PackagesPage extends Page
12 {
13     public PackagesPage()
14     {
15         super();
16     }
17
18     public String JavaDoc handleRequest() throws SQLException
19     {
20         // Poor man's cache - how do we do live updates to the database then?
21
if (app.getAttribute("javaPkgs") != null)
22         {
23             return null;
24         }
25
26         List pkgList = getPackageList();
27         HashMap javaPkgs = new HashMap();
28         JPackage pkg = null;
29         for (int i = 0; i < pkgList.size(); i++)
30         {
31             pkg = (JPackage) pkgList.get(i);
32             int index = pkg.getName().indexOf('.');
33             String JavaDoc packageBase = null;
34             if (index < 0)
35             {
36                 packageBase = " ";
37             }
38             else
39             {
40                 packageBase = pkg.getName().substring(0, index);
41             }
42             if (javaPkgs.containsKey(packageBase))
43             {
44                 List list = (List) javaPkgs.get(packageBase);
45                 list.add(pkg);
46             }
47             else
48             {
49                 List list = new ArrayList();
50                 list.add(pkg);
51                 javaPkgs.put(packageBase, list);
52             }
53         }
54         app.setAttribute("javaPkgs", javaPkgs);
55         return null;
56     }
57
58     public List getPackageList() throws SQLException
59     {
60         String JavaDoc sql = DBMgr.getInstance().getStatement("getpackages2");
61
62         Statement stmt = conn.createStatement();
63         ResultSet rset = stmt.executeQuery(sql);
64
65         List pkgList = new ArrayList();
66
67         JPackage pkg;
68         while (rset.next())
69         {
70             pkg = new JPackage(rset.getString(2));
71             pkg.setId(rset.getInt(1));
72             pkg.setDoc(
73                 new DocInfo(
74                     rset.getString(3),
75                     rset.getString(4),
76                     rset.getString(5)));
77             pkgList.add(pkg);
78         }
79
80         rset.close();
81         stmt.close();
82
83         return pkgList;
84     }
85
86 }
87
Popular Tags