KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > bizlogic > WikiBL


1
2
3  /*
4  -- GeiNuke --
5 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
6  http://www.hostingjava.it/-geinuke/
7
8 This file is part of GeiNuke.
9
10     GeiNuke is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     GeiNuke is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with GeiNuke; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */

24 package com.geinuke.bizlogic;
25
26 import java.sql.SQLException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
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 JavaDoc 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 JavaDoc sqle){
56             throw new DBException(sqle.getMessage());
57         }catch(Throwable JavaDoc t){
58             throw new BLException(t.getMessage());
59         }
60         return wa;
61     }
62     
63     public ArrayList JavaDoc getWikiFilesByWAID(int fid) throws BLException{
64         ArrayList JavaDoc ll=null;
65         try{
66             WikiDAO dao=new WikiDAO();
67             List JavaDoc list=dao.getWikiFilesByWAID(fid);
68             
69             ll=new ArrayList JavaDoc(list);
70             
71         }catch(SQLException JavaDoc sqle){
72             throw new DBException(sqle.getMessage());
73         }catch(Throwable JavaDoc t){
74             throw new BLException(t.getMessage());
75         }
76         return ll;
77     }
78     
79     public ArrayList JavaDoc getAllWikiArticles() throws BLException{
80         ArrayList JavaDoc ll=null;
81         try{
82             WikiDAO dao=new WikiDAO();
83             ll=dao.getAllWikiArticles();
84             
85         }catch(SQLException JavaDoc sqle){
86             throw new DBException(sqle.getMessage());
87         }catch(Throwable JavaDoc 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 JavaDoc sqle){
102             throw new DBException(sqle.getMessage());
103         }catch(Throwable JavaDoc 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 JavaDoc sqle){
116             throw new DBException(sqle.getMessage());
117         }catch(Throwable JavaDoc 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 JavaDoc sqle){
130             throw new DBException(sqle.getMessage());
131         }catch(Throwable JavaDoc 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 JavaDoc sqle){
146             throw new DBException(sqle.getMessage());
147         }catch(Throwable JavaDoc 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 JavaDoc sqle){
160             throw new DBException(sqle.getMessage());
161         }catch(Throwable JavaDoc 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 JavaDoc sqle){
174             throw new DBException(sqle.getMessage());
175         }catch(Throwable JavaDoc 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 JavaDoc sqle){
188             throw new DBException(sqle.getMessage());
189         }catch(Throwable JavaDoc 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 JavaDoc sqle){
201             throw new DBException(sqle.getMessage());
202         }catch(Throwable JavaDoc 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 JavaDoc sqle){
214             throw new DBException(sqle.getMessage());
215         }catch(Throwable JavaDoc t){
216             throw new BLException(t.getMessage());
217         }
218         
219     }
220
221
222     public ArrayList JavaDoc getWikiArticlesByNameOrText(String JavaDoc words) throws BLException {
223         ArrayList JavaDoc list=null,aux=null;
224         String JavaDoc [] wordsA=TextUtil.tokenize(words,",-;. ");
225         list=new ArrayList JavaDoc();
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             //this.fillBlogPosts(list);
235
}catch(SQLException JavaDoc sqle){
236             throw new DBException(sqle.getMessage());
237         }catch(Throwable JavaDoc t){
238             throw new BLException(t.getMessage());
239         }
240         return list;
241     }
242
243     public ArrayList JavaDoc getWikiArticlesByText(String JavaDoc words) throws BLException {
244         ArrayList JavaDoc list=null,aux=null;
245         String JavaDoc [] wordsA=TextUtil.tokenize(words,",-;. ");
246         list=new ArrayList JavaDoc();
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             //this.fillBlogPosts(list);
256
}catch(SQLException JavaDoc sqle){
257             throw new DBException(sqle.getMessage());
258         }catch(Throwable JavaDoc t){
259             throw new BLException(t.getMessage());
260         }
261         return list;
262     }
263
264
265     public ArrayList JavaDoc getWikiArticlesByName(String JavaDoc words) throws BLException {
266         ArrayList JavaDoc list=null,aux=null;
267         String JavaDoc [] wordsA=TextUtil.tokenize(words,",-;. ");
268         list=new ArrayList JavaDoc();
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             //this.fillBlogPosts(list);
278
}catch(SQLException JavaDoc sqle){
279             throw new DBException(sqle.getMessage());
280         }catch(Throwable JavaDoc t){
281             throw new BLException(t.getMessage());
282         }
283         return list;
284     }
285 }
286
Popular Tags