KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > module > forum > ForumUtil


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.module.forum;
23
24 import java.util.ArrayList JavaDoc;
25
26 import javax.servlet.http.Cookie JavaDoc;
27
28 import com.geinuke.common.UserI;
29 import com.geinuke.util.CookieHandler;
30 import com.geinuke.vo.ForumVO;
31 import com.geinuke.vo.TopicVO;
32
33 public class ForumUtil {
34     
35     protected UserI user=null;
36     protected CookieHandler ch=null;
37     
38     public ForumUtil(UserI user,CookieHandler ch){
39         this.user=user;
40         this.ch=ch;
41     }
42     
43     public String JavaDoc getCookieKey(ForumVO f,TopicVO t){
44         String JavaDoc res=null;
45         if(t!=null){
46             res="forum-"+f.getFId()+"-"+t.getTId();
47         }else{
48             res="xyzt";
49         }
50         return res;
51     }
52     
53     public void tagForum(ForumVO fo){
54         ArrayList JavaDoc l=new ArrayList JavaDoc();
55         l.add(fo);
56         this.tagForums(l);
57     }
58     
59     public void tagForums(ArrayList JavaDoc forums){
60         ForumVO fo=null;
61         TopicVO to=null;
62         ArrayList JavaDoc topics=null;
63         Cookie JavaDoc coo=null;
64         //if(!user.getRole().getRoleName().equals( UserI.ANONYMOUS) )
65
for(int i=0;i<forums.size();i++){
66             fo=(ForumVO)forums.get(i);
67             fo.setVisited(true);
68             topics=fo.getTopics();
69             for(int j=0;topics!=null && j<topics.size();j++){
70                 to=(TopicVO)topics.get(j);
71                 this.tagTopic(fo,to,false);
72                 
73                 
74             }
75         }
76     }
77     
78     
79     
80     public void tagTopic(ForumVO fo,TopicVO to,boolean toTag){
81     
82         
83         ArrayList JavaDoc topics=null;
84         Cookie JavaDoc coo=null;
85         
86         String JavaDoc key=this.getCookieKey(fo,to);
87         long t=to.getLastModTime();
88         coo=ch.getCookie(key);
89             
90         //if(!user.getRole().getRoleName().equals( UserI.ANONYMOUS) )
91
if(coo==null || Long.parseLong(coo.getValue())<t ){
92             if(toTag)
93                 ch.addCookie(key,System.currentTimeMillis()+"");
94             to.setLastVisit(0);
95             fo.setVisited(false);
96             
97         }
98         else{
99             if(toTag)
100                 ch.addCookie(key,System.currentTimeMillis()+"");
101             to.setLastVisit(System.currentTimeMillis());
102             //fo.setVisited(true);
103
}
104             
105             
106         
107         
108     }
109 }
110
Popular Tags