1 22 package com.geinuke.module.forum; 23 24 import java.util.ArrayList ; 25 26 import javax.servlet.http.Cookie ; 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 getCookieKey(ForumVO f,TopicVO t){ 44 String 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 l=new ArrayList (); 55 l.add(fo); 56 this.tagForums(l); 57 } 58 59 public void tagForums(ArrayList forums){ 60 ForumVO fo=null; 61 TopicVO to=null; 62 ArrayList topics=null; 63 Cookie coo=null; 64 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 topics=null; 84 Cookie coo=null; 85 86 String key=this.getCookieKey(fo,to); 87 long t=to.getLastModTime(); 88 coo=ch.getCookie(key); 89 90 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 } 104 105 106 107 108 } 109 } 110 | Popular Tags |