KickJava   Java API By Example, From Geeks To Geeks.

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


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

13 public class PackagePage extends Page
14 {
15    public PackagePage()
16    {
17       super();
18    }
19    
20    public String JavaDoc handleRequest() throws SQLException
21    {
22       int pkgId = 0;
23
24       try
25       {
26          pkgId = Integer.parseInt(ServletUtils.getRequestParam(request, "pkg_id"));
27       }
28       catch (NumberFormatException JavaDoc ex)
29       {
30          String JavaDoc pkgName = ServletUtils.getRequestParam(request, "pkg_name");
31          
32          String JavaDoc sql = DBMgr.getInstance().getStatement("getpkgid");
33          PreparedStatement pstmt = conn.prepareStatement(sql);
34          pstmt.setString(1, pkgName);
35          ResultSet rset = pstmt.executeQuery();
36          log.debug("about to get package id for "+pkgName);
37          if (rset.next())
38          {
39             pkgId = rset.getInt(1);
40             log.debug("pkg id is: "+pkgId);
41          }
42          rset.close();
43          pstmt.close();
44       }
45       
46       Integer JavaDoc pkgId_obj = new Integer JavaDoc(pkgId);
47
48       Object JavaDoc packages_obj = app.getAttribute("packages");
49       Hashtable packages = null;
50       if (packages_obj == null)
51       {
52          packages = new Hashtable();
53       }
54       else
55       {
56          packages = (Hashtable) packages_obj;
57          Object JavaDoc pkg_object = packages.get(pkgId_obj);
58          if (pkg_object !=null)
59          {
60             JPackage pkg = (JPackage) pkg_object;
61             request.setAttribute("pkg", pkg);
62
63             TreeNode tree = pkg.buildTree(conn);
64             request.setAttribute("tree", tree);
65             
66             return null;
67          }
68       }
69        
70       JPackage pkg = JPackage.makePackageFor(conn, pkgId);
71       packages.put(pkgId_obj, pkg);
72       app.setAttribute("packages", packages);
73       request.setAttribute("pkg", pkg);
74
75       TreeNode tree = pkg.buildTree(conn);
76       request.setAttribute("tree", tree);
77       return null;
78    }
79
80 }
81
Popular Tags