KickJava   Java API By Example, From Geeks To Geeks.

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


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 IndexPage extends Page
14 {
15    private static int PAGE_SIZE = 21;
16    
17    public IndexPage()
18    {
19       super();
20    }
21    
22    public String JavaDoc handleRequest() throws SQLException
23    {
24       String JavaDoc startFrom = ServletUtils.getRequestParam(request, "start");
25       String JavaDoc cmd = ServletUtils.getCommand(request);
26       
27       if (StringUtils.isBlank(startFrom))
28          return null;
29       
30       String JavaDoc[] parts = StringUtils.split(cmd, ".");
31       String JavaDoc browseType = parts[1];
32       List results = null;
33       
34       if (browseType.equals("package"))
35       {
36          results = getPackages(startFrom);
37          if (results.size()>=PAGE_SIZE)
38          {
39             JPackage next = (JPackage) results.remove(results.size()-1);
40             request.setAttribute("next", next.getName());
41          }
42       }
43       else if (browseType.equals("class"))
44       {
45          results = getClasses(startFrom);
46          if (results.size()>=PAGE_SIZE)
47          {
48             ClassType next = (ClassType) results.remove(results.size()-1);
49             request.setAttribute("next", next.getName());
50          }
51       }
52       else if (browseType.equals("member"))
53       {
54          results = getMembers(startFrom);
55          if (results.size()>=PAGE_SIZE)
56          {
57             Member next = (Member) results.remove(results.size()-1);
58             request.setAttribute("next", next.getName());
59          }
60       }
61       else if (browseType.equals("author"))
62       {
63          results = getAuthors(startFrom);
64          if (results.size()>=PAGE_SIZE)
65          {
66             Author next = (Author) results.remove(results.size()-1);
67             request.setAttribute("next", next.getName());
68          }
69       }
70       
71       request.setAttribute("results", results);
72       if (results.isEmpty())
73          request.setAttribute("next", "");
74       
75       request.setAttribute("display_results", new Boolean JavaDoc(true));
76       return null;
77    }
78    
79    
80    public List getPackages(String JavaDoc startFrom) throws SQLException
81    {
82       startFrom = startFrom.toLowerCase();
83
84       String JavaDoc sql = DBMgr.getInstance().getStatement("getpackages");
85       
86       PreparedStatement p = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
87       p.setFetchSize(PAGE_SIZE);
88       p.setFetchDirection(ResultSet.FETCH_FORWARD);
89       p.setString(1, startFrom);
90       ResultSet rset = p.executeQuery();
91
92       List results = new ArrayList();
93       JPackage pkg;
94       
95       int rownum = 0;
96       while (rset.next() && rownum < PAGE_SIZE)
97       {
98         pkg = new JPackage(rset.getString(2));
99         pkg.setId(rset.getInt(1));
100         pkg.setDoc(new DocInfo(rset.getString(3), rset.getString(4), rset.getString(5)));
101         results.add(pkg);
102          
103         rownum++;
104       }
105       rset.close();
106       p.close();
107       
108       return results;
109    }
110    
111    public List getClasses(String JavaDoc startFrom) throws SQLException
112    {
113       startFrom = startFrom.toLowerCase();
114
115       String JavaDoc sql = DBMgr.getInstance().getStatement("getclasses");
116
117       PreparedStatement p = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
118       p.setFetchSize(PAGE_SIZE);
119       p.setFetchDirection(ResultSet.FETCH_FORWARD);
120       p.setMaxRows(PAGE_SIZE);
121       
122       p.setString(1, startFrom);
123       ResultSet rset = p.executeQuery();
124       
125       List results = new ArrayList();
126       ClassType c;
127       
128       int rownum = 0;
129       while (rset.next() && rownum < PAGE_SIZE)
130       {
131         c = new ClassType(rset.getString(2));
132         c.setId(rset.getInt(1));
133         c.setClassType(rset.getInt(3));
134         c.setStatic(rset.getBoolean(4));
135         c.setFinal(rset.getBoolean(5));
136         c.setAbstract(rset.getBoolean(6));
137         c.setAccessibility(rset.getInt(7));
138         c.setModifiers(rset.getString(8));
139         c.setDoc(new DocInfo(rset.getString(9), rset.getString(10), rset.getString(11)));
140         results.add(c);
141         rownum++;
142       }
143
144       rset.close();
145       p.close();
146       
147       return results;
148    }
149    
150    
151    
152    public List getMembers(String JavaDoc startFrom) throws SQLException
153    {
154       startFrom = startFrom.toLowerCase();
155
156       String JavaDoc sql = DBMgr.getInstance().getStatement("getmembers");
157       
158       PreparedStatement p = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
159       p.setFetchSize(PAGE_SIZE);
160       p.setFetchDirection(ResultSet.FETCH_FORWARD);
161       p.setMaxRows(PAGE_SIZE);
162       
163       p.setString(1, startFrom);
164       ResultSet rset = p.executeQuery();
165
166       List results = new ArrayList();
167       Member m;
168
169       int rownum = 0;
170       while (rownum<PAGE_SIZE && rset.next())
171       {
172         m = new Member(rset.getString(2), rset.getInt(3));
173         m.setId(rset.getInt(1));
174         m.setDoc(new DocInfo(rset.getString(13), rset.getString(14), rset.getString(15)));
175         m.setStatic(rset.getBoolean(4));
176         m.setFinal(rset.getBoolean(5));
177         m.setAccessibility(rset.getInt(6));
178         m.setModifiers(rset.getString(7));
179         String JavaDoc signature = rset.getString(12);
180         if (!StringUtils.isBlank(signature))
181         {
182            ExecMember em = new ExecMember(m, signature);
183            String JavaDoc returntypename = rset.getString(10);
184            if (!StringUtils.isBlank(returntypename))
185            {
186                MethodMember method = new MethodMember(m, signature);
187                method.setAbstract(rset.getBoolean(8));
188                method.setReturnTypeName(returntypename);
189                method.setReturnTypeDimension(rset.getInt(11));
190                int returntypeid = rset.getInt(9);
191                if (returntypeid > 0)
192                {
193                   method.setReturnType(new ClassType(returntypename));
194                   method.getReturnType().setId(returntypeid);
195                }
196                
197                results.add(method);
198            }
199            else
200            {
201               results.add(em);
202            }
203         }
204         else
205         {
206            results.add(m);
207         }
208          
209         rownum++;
210       }
211       rset.close();
212       p.close();
213       
214       return results;
215    }
216
217
218
219    public List getAuthors(String JavaDoc startFrom) throws SQLException
220    {
221       startFrom = startFrom.toLowerCase();
222
223       String JavaDoc sql = DBMgr.getInstance().getStatement("getauthors");
224
225       PreparedStatement p = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
226       p.setFetchSize(PAGE_SIZE);
227       p.setFetchDirection(ResultSet.FETCH_FORWARD);
228       p.setMaxRows(PAGE_SIZE);
229       
230       p.setString(1, startFrom);
231       ResultSet rset = p.executeQuery();
232       
233       List results = new ArrayList();
234       
235       int rownum = 0;
236       Author author = null;
237       while (rset.next() && rownum < PAGE_SIZE)
238       {
239         author = new Author(rset.getString(2));
240         author.setId(rset.getInt(1));
241         results.add(author);
242         rownum++;
243       }
244
245       rset.close();
246       p.close();
247       
248       return results;
249    }
250 }
251
252
253
254
Popular Tags