1 2 3 24 package com.geinuke.bizlogic; 25 26 import java.sql.SQLException ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import com.geinuke.dao.WikiDAO; 31 import com.geinuke.middle.IWikiBL; 32 import com.geinuke.util.TextUtil; 33 import com.geinuke.util.collection.MagicCollections; 34 import com.geinuke.util.collection.WikiArticleVOComparator; 35 import com.geinuke.vo.WikiArticleVO; 36 import com.geinuke.vo.WikiFileVO; 37 import com.geinuke.vo.WikiMenuVO; 38 39 public class WikiBL implements IWikiBL { 40 protected static IWikiBL instance=null; 41 42 public WikiBL(){ 43 44 } 45 46 47 public WikiArticleVO getWikiArticleByName(String name)throws BLException{ 48 WikiArticleVO wa=null; 49 50 try{ 51 WikiDAO dao=new WikiDAO(); 52 wa=dao.getWikiArticleByName(name); 53 if(wa!=null) 54 wa.setFileList(this.getWikiFilesByWAID(wa.getWAId())); 55 }catch(SQLException sqle){ 56 throw new DBException(sqle.getMessage()); 57 }catch(Throwable t){ 58 throw new BLException(t.getMessage()); 59 } 60 return wa; 61 } 62 63 public ArrayList getWikiFilesByWAID(int fid) throws BLException{ 64 ArrayList ll=null; 65 try{ 66 WikiDAO dao=new WikiDAO(); 67 List list=dao.getWikiFilesByWAID(fid); 68 69 ll=new ArrayList (list); 70 71 }catch(SQLException sqle){ 72 throw new DBException(sqle.getMessage()); 73 }catch(Throwable t){ 74 throw new BLException(t.getMessage()); 75 } 76 return ll; 77 } 78 79 public ArrayList getAllWikiArticles() throws BLException{ 80 ArrayList ll=null; 81 try{ 82 WikiDAO dao=new WikiDAO(); 83 ll=dao.getAllWikiArticles(); 84 85 }catch(SQLException sqle){ 86 throw new DBException(sqle.getMessage()); 87 }catch(Throwable t){ 88 throw new BLException(t.getMessage()); 89 } 90 return ll; 91 } 92 93 public WikiFileVO getWikiFileByWFID(int fid) throws BLException{ 94 WikiFileVO ll=null; 95 try{ 96 WikiDAO dao=new WikiDAO(); 97 ll=dao.getWikiFileByWFID(fid); 98 99 100 101 }catch(SQLException sqle){ 102 throw new DBException(sqle.getMessage()); 103 }catch(Throwable t){ 104 throw new BLException(t.getMessage()); 105 } 106 return ll; 107 } 108 109 public void deleteWikiFileByWFID(int fid) throws BLException{ 110 111 try{ 112 WikiDAO dao=new WikiDAO(); 113 dao.deleteWikiFileByWFID(fid); 114 115 }catch(SQLException sqle){ 116 throw new DBException(sqle.getMessage()); 117 }catch(Throwable t){ 118 throw new BLException(t.getMessage()); 119 } 120 121 } 122 123 public void deleteWikiArticleByWAID(int aid) throws BLException{ 124 125 try{ 126 WikiDAO dao=new WikiDAO(); 127 dao.deleteWikiArticleByWAID(aid); 128 129 }catch(SQLException sqle){ 130 throw new DBException(sqle.getMessage()); 131 }catch(Throwable t){ 132 throw new BLException(t.getMessage()); 133 } 134 135 } 136 137 public WikiArticleVO getWikiArticleById(int id)throws BLException{ 138 WikiArticleVO wa=null; 139 140 try{ 141 WikiDAO dao=new WikiDAO(); 142 wa=dao.getWikiArticleById(id); 143 if(wa!=null) 144 wa.setFileList(this.getWikiFilesByWAID(wa.getWAId())); 145 }catch(SQLException sqle){ 146 throw new DBException(sqle.getMessage()); 147 }catch(Throwable t){ 148 throw new BLException(t.getMessage()); 149 } 150 return wa; 151 } 152 153 public WikiMenuVO getWikiMenu()throws BLException{ 154 WikiMenuVO wm=null; 155 156 try{ 157 WikiDAO dao=new WikiDAO(); 158 wm=dao.getWikiMenu(); 159 }catch(SQLException sqle){ 160 throw new DBException(sqle.getMessage()); 161 }catch(Throwable t){ 162 throw new BLException(t.getMessage()); 163 } 164 return wm; 165 } 166 167 public void insWikiArticle(WikiArticleVO wa)throws BLException{ 168 169 try{ 170 WikiDAO dao=new WikiDAO(); 171 dao.insertWikiArticle(wa); 172 173 }catch(SQLException sqle){ 174 throw new DBException(sqle.getMessage()); 175 }catch(Throwable t){ 176 throw new BLException(t.getMessage()); 177 } 178 179 } 180 181 public void insWikiFile(WikiFileVO wf)throws BLException{ 182 183 try{ 184 WikiDAO dao=new WikiDAO(); 185 dao.insertWikiFile(wf); 186 187 }catch(SQLException sqle){ 188 throw new DBException(sqle.getMessage()); 189 }catch(Throwable t){ 190 throw new BLException(t.getMessage()); 191 } 192 193 } 194 195 public void updateWikiArticle(WikiArticleVO wa)throws BLException{ 196 197 try{ 198 WikiDAO dao=new WikiDAO(); 199 dao.updateWikiArticle(wa); 200 }catch(SQLException sqle){ 201 throw new DBException(sqle.getMessage()); 202 }catch(Throwable t){ 203 throw new BLException(t.getMessage()); 204 } 205 206 } 207 208 public void updateWikiMenu(WikiMenuVO wm)throws BLException{ 209 210 try{ 211 WikiDAO dao=new WikiDAO(); 212 dao.updateWikiMenu(wm); 213 }catch(SQLException sqle){ 214 throw new DBException(sqle.getMessage()); 215 }catch(Throwable t){ 216 throw new BLException(t.getMessage()); 217 } 218 219 } 220 221 222 public ArrayList getWikiArticlesByNameOrText(String words) throws BLException { 223 ArrayList list=null,aux=null; 224 String [] wordsA=TextUtil.tokenize(words,",-;. "); 225 list=new ArrayList (); 226 227 try{ 228 WikiDAO dao=new WikiDAO(); 229 for(int i=0;i<wordsA.length;i++){ 230 aux=dao.getWikiArticlesByNameOrText(wordsA[i]); 231 list.addAll(aux); 232 } 233 list=MagicCollections.semplifyAndSort(list,new WikiArticleVOComparator()); 234 }catch(SQLException sqle){ 236 throw new DBException(sqle.getMessage()); 237 }catch(Throwable t){ 238 throw new BLException(t.getMessage()); 239 } 240 return list; 241 } 242 243 public ArrayList getWikiArticlesByText(String words) throws BLException { 244 ArrayList list=null,aux=null; 245 String [] wordsA=TextUtil.tokenize(words,",-;. "); 246 list=new ArrayList (); 247 248 try{ 249 WikiDAO dao=new WikiDAO(); 250 for(int i=0;i<wordsA.length;i++){ 251 aux=dao.getWikiArticlesByText(wordsA[i]); 252 list.addAll(aux); 253 } 254 list=MagicCollections.semplifyAndSort(list,new WikiArticleVOComparator()); 255 }catch(SQLException sqle){ 257 throw new DBException(sqle.getMessage()); 258 }catch(Throwable t){ 259 throw new BLException(t.getMessage()); 260 } 261 return list; 262 } 263 264 265 public ArrayList getWikiArticlesByName(String words) throws BLException { 266 ArrayList list=null,aux=null; 267 String [] wordsA=TextUtil.tokenize(words,",-;. "); 268 list=new ArrayList (); 269 270 try{ 271 WikiDAO dao=new WikiDAO(); 272 for(int i=0;i<wordsA.length;i++){ 273 aux=dao.getWikiArticlesByName(wordsA[i]); 274 list.addAll(aux); 275 } 276 list=MagicCollections.semplifyAndSort(list,new WikiArticleVOComparator()); 277 }catch(SQLException sqle){ 279 throw new DBException(sqle.getMessage()); 280 }catch(Throwable t){ 281 throw new BLException(t.getMessage()); 282 } 283 return list; 284 } 285 } 286 | Popular Tags |