1 package org.ashkelon.pages; 2 3 import org.ashkelon.*; 4 import org.ashkelon.util.*; 5 import org.ashkelon.db.*; 6 import java.util.*; 7 import java.sql.*; 8 9 import org.apache.oro.text.perl.*; 10 11 14 public class ClassesPage extends Page 15 { 16 public ClassesPage() throws SQLException 17 { 18 super(); 19 } 20 21 public String handleRequest() throws SQLException 22 { 23 boolean simpleSearch = (Boolean.valueOf((String ) ServletUtils.getRequestParam(request, "simple"))).booleanValue(); 24 25 List found = null; 26 27 if (simpleSearch) 28 { 29 String searchField = ServletUtils.getRequestParam(request, "searchField"); 30 if (StringUtils.isBlank(searchField)) 31 return null; 32 33 found = getSimpleClasses(searchField); 34 } 35 else 36 { 37 found = getComplexClasses(); 38 } 39 40 if (found.size()==1) 41 { 42 int id = ((ClassType)found.get(0)).getId(null); 43 request.setAttribute("cls_id", ""+id); return "cls.main"; 45 } 46 47 request.setAttribute("cls_list", found); 48 return null; 49 50 } 51 52 public List getComplexClasses() throws SQLException 53 { 54 String selectors[] = request.getParameterValues("selector"); 55 if (selectors == null || selectors.length == 0) 56 return null; 57 58 Map filters = new HashMap(10); 59 String value; 60 for (int i=0; i<selectors.length; i++) 61 { 62 if ("author".equals(selectors[i]) || "package_name".equals(selectors[i]) 63 || "searchField".equals(selectors[i])) 64 { 65 value = ServletUtils.getRequestParam(request, selectors[i]); 66 value = value.replace('*', '%').toLowerCase(); 67 filters.put(selectors[i], value); 68 } 69 else 70 { 71 filters.put(selectors[i], new Integer (ServletUtils.getIntParam(request, selectors[i]))); 72 } 73 } 74 75 String sql = " select " + 76 " c.id, c.qualifiedname, c.type, c.isstatic, c.isfinal, c.isabstract, " + 77 " c.accessibility, c.modifier, d.summarydescription, d.since, d.deprecated " + 78 " from "; 79 80 List fromClause = new ArrayList(10); 81 fromClause.add("CLASSTYPE c, DOC d"); 82 if (filters.get("author")!=null) 83 fromClause.add("CLASS_AUTHOR ca, AUTHOR a"); 84 if (filters.get("package_name")!=null) 85 fromClause.add("PACKAGE p"); 86 87 sql += StringUtils.join(fromClause.toArray(), ",") + 88 " where "; 89 90 List whereClause = new ArrayList(10); 91 if (filters.get("searchField")!=null) 92 { 93 String selectby = "c.qualifiedname"; 94 if (!JDocUtil.isQualified((String ) filters.get("searchField"))) 95 selectby = "c.name"; 96 whereClause.add("lower("+selectby+") like ?"); 97 } 98 if (filters.get("class_type")!=null) 99 whereClause.add("c.type=?"); 100 if (filters.get("abstract")!=null) 101 whereClause.add("c.isabstract=?"); 102 if (filters.get("author")!=null) 103 whereClause.add("c.id=ca.classid and ca.authorid=a.id and lower(a.name) like ?"); 104 if (filters.get("package_name")!=null) 105 whereClause.add("c.packageid=p.id and lower(p.name) like ?"); 106 whereClause.add("c.docid=d.id"); 107 if (filters.get("deprecated")!=null) 108 { 109 if ( ((Integer )filters.get("deprecated")).intValue() == 1) 110 whereClause.add("d.deprecated != ''"); 111 else 112 whereClause.add("d.deprecated = ''"); 113 } 114 115 sql += StringUtils.join(whereClause.toArray(), " and ") + 116 " order by c.qualifiedname, c.type "; 117 118 PreparedStatement pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, 119 ResultSet.CONCUR_READ_ONLY); 120 pstmt.setFetchSize(FETCH_SIZE); 121 122 int i=1; 123 if (filters.get("searchField")!=null) 124 pstmt.setString(i++, (String ) filters.get("searchField")); 125 if (filters.get("class_type")!=null) 126 pstmt.setInt(i++, ((Integer ) filters.get("class_type")).intValue()); 127 if (filters.get("abstract")!=null) 128 pstmt.setInt(i++, ((Integer ) filters.get("abstract")).intValue()); 129 if (filters.get("author")!=null) 130 pstmt.setString(i++, (String ) filters.get("author")); 131 if (filters.get("package_name")!=null) 132 pstmt.setString(i++, (String ) filters.get("package_name")); 133 134 Logger.getInstance().debug("advanced search sql query:\n\t"+sql); 135 136 ResultSet rset = pstmt.executeQuery(); 137 int position = position(rset); 138 139 List found = new ArrayList(); 140 ClassType c; 141 142 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 143 { 144 c = new ClassType(rset.getString(2)); 145 c.setId(rset.getInt(1)); 146 c.setClassType(rset.getInt(3)); 147 c.setStatic(rset.getBoolean(4)); 148 c.setFinal(rset.getBoolean(5)); 149 c.setAbstract(rset.getBoolean(6)); 150 c.setAccessibility(rset.getInt(7)); 151 c.setModifiers(rset.getString(8)); 152 c.setDoc(new DocInfo(rset.getString(9), rset.getString(10), rset.getString(11))); 153 found.add(c); 154 } 155 156 rset.close(); 157 return found; 158 } 159 160 161 public List getSimpleClasses(String searchField) throws SQLException 162 { 163 searchField = searchField.toLowerCase(); 164 String selectby = "c.qualifiedname"; 165 if (!JDocUtil.isQualified(searchField)) 166 { 167 selectby = "c.name"; 168 } 169 170 Perl5Util util = new Perl5Util(); 171 String pattern = "s/\\*/%/g"; 172 searchField = util.substitute(pattern, searchField); 173 175 String sql = 176 " select c.id, c.qualifiedname, c.type, " + 177 " c.isstatic, c.isfinal, c.isabstract, c.accessibility, c.modifier, " + 178 " d.summarydescription, d.since, d.deprecated " + 179 " from CLASSTYPE c, DOC d " + 180 " where lower("+selectby+") like ? " + 181 " and c.docid=d.id " + 182 " order by c.qualifiedname, c.type "; 183 184 if (DBMgr.getInstance().isOracle()) 185 { 186 sql = 187 " select c.id, c.qualifiedname, c.type, " + 188 " c.isstatic, c.isfinal, c.isabstract, c.accessibility, c.modifier, " + 189 " d.summarydescription, d.since, d.deprecated " + 190 " from CLASSTYPE c, DOC d " + 191 " where lower("+selectby+") like ? " + 192 " and c.docid=d.id " + 193 " order by c.qualifiedname, c.type"; 194 } 195 196 PreparedStatement pstmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, 197 ResultSet.CONCUR_READ_ONLY); 198 pstmt.setFetchSize(FETCH_SIZE); 199 200 pstmt.setString(1, searchField); 201 ResultSet rset = pstmt.executeQuery(); 202 int position = position(rset); 203 204 List found = new ArrayList(); 205 ClassType c; 206 207 while (rset.next() && rset.getRow() <= (position + FETCH_SIZE)) 208 { 209 c = new ClassType(rset.getString(2)); 210 c.setId(rset.getInt(1)); 211 c.setClassType(rset.getInt(3)); 212 c.setStatic(rset.getBoolean(4)); 213 c.setFinal(rset.getBoolean(5)); 214 c.setAbstract(rset.getBoolean(6)); 215 c.setAccessibility(rset.getInt(7)); 216 c.setModifiers(rset.getString(8)); 217 c.setDoc(new DocInfo(rset.getString(9), rset.getString(10), rset.getString(11))); 218 found.add(c); 219 } 220 221 rset.close(); 222 return found; 223 } 224 225 226 } 227 | Popular Tags |