KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > util > SearchLinkConverter


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

22 package com.geinuke.util;
23
24 import java.util.ArrayList JavaDoc;
25
26 import com.geinuke.vo.BlogPostVO;
27 import com.geinuke.vo.CategoryVO;
28 import com.geinuke.vo.NewsVO;
29 import com.geinuke.vo.SearchLinkVO;
30 import com.geinuke.vo.TopicVO;
31
32 public class SearchLinkConverter {
33     protected static int MAX=180;
34     
35     public static ArrayList JavaDoc getLinksFromBlogs(ArrayList JavaDoc source){
36         ArrayList JavaDoc res=null;
37         if(source!=null){
38             res=new ArrayList JavaDoc();
39             BlogPostVO blo=null;
40             SearchLinkVO link=null;
41             
42             for(int i=0;i<source.size();i++){
43                 link=new SearchLinkVO();
44                 blo=(BlogPostVO)source.get(i);
45                 link.setId(blo.getBid());
46                 link.setCategory(CategoryVO.CAT_BLOG);
47                 link.setTitle(blo.getBlogTitle());
48                 
49                 String JavaDoc aux=TextUtil.removeHTML(blo.getBlogText());
50                 aux=TextUtil.trunc(aux,MAX)+"...";
51                 link.setShortBody(aux);
52                 
53                 link.setPath("BlogViewer.jhtm?op=showBP&bid="+link.getId());
54                 res.add(link);
55             }
56         }
57         return res;
58     }
59     
60     public static ArrayList JavaDoc getLinksFromNews(ArrayList JavaDoc source){
61         ArrayList JavaDoc res=null;
62         if(source!=null){
63             res=new ArrayList JavaDoc();
64             NewsVO nn=null;
65             SearchLinkVO link=null;
66             
67             for(int i=0;i<source.size();i++){
68                 link=new SearchLinkVO();
69                 nn=(NewsVO)source.get(i);
70                 link.setId(nn.getNId());
71                 link.setCategory(CategoryVO.CAT_NEWS);
72                 link.setTitle( nn.getTitle());
73                 
74                 String JavaDoc aux=TextUtil.removeHTML(nn.getBodyText());
75                 aux=TextUtil.trunc(aux,MAX)+"...";
76                 link.setShortBody(aux);
77                 
78                 link.setPath("News.jhtm?op=showN&id="+link.getId());
79                 res.add(link);
80             }
81         }
82         return res;
83     }
84     
85     public static ArrayList JavaDoc getLinksFromForumTopics(ArrayList JavaDoc source){
86         ArrayList JavaDoc res=null;
87         if(source!=null){
88             res=new ArrayList JavaDoc();
89             TopicVO tt=null;
90             SearchLinkVO link=null;
91             
92             for(int i=0;i<source.size();i++){
93                 link=new SearchLinkVO();
94                 tt=(TopicVO)source.get(i);
95                 link.setId(tt.getTId());
96                 link.setCategory(CategoryVO.CAT_FORUMS);
97                 link.setTitle( tt.getName());
98                 String JavaDoc aux=TextUtil.removeHTML(tt.getText());
99                 aux=TextUtil.trunc(aux,MAX)+"...";
100                 link.setShortBody(aux);
101                 link.setPath("Forum.jhtm?op=showST&tid="+link.getId());
102                 res.add(link);
103             }
104         }
105         return res;
106     }
107 }
108
Popular Tags