1 22 package com.geinuke.module.survey; 23 24 import javax.servlet.http.Cookie ; 25 26 import com.geinuke.common.UserI; 27 import com.geinuke.util.CookieHandler; 28 import com.geinuke.vo.SurveyAnswerVO; 29 import com.geinuke.vo.SurveyVO; 30 31 32 public class SurveyUtil { 33 34 protected UserI user=null; 35 protected CookieHandler ch=null; 36 37 public SurveyUtil(UserI user,CookieHandler ch){ 38 this.user=user; 39 this.ch=ch; 40 } 41 42 public static SurveyAnswerVO getSurveyAnswerByAID(SurveyVO su,int aid){ 43 SurveyAnswerVO sa=null; 44 int t=-1; 45 boolean flag=false; 46 for(int i=0;i<su.getAnswers().size() && ! flag;i++){ 47 sa=(SurveyAnswerVO)su.getAnswers().get(i); 48 if(sa.getAid()==aid) 49 flag=true; 50 } 51 return sa; 52 } 53 54 55 56 57 public String getKey(SurveyVO su){ 58 String k=null; 59 k="SURVEY"+su.getSid()+"-"+this.user.getId(); 60 return k; 61 } 62 63 public String getAnonymousKey(SurveyVO su){ 64 String k=null; 65 k="SURVEY"+su.getSid()+"-"+UserI.ANONYMOUS_ID; 66 return k; 67 } 68 69 public boolean hasVoted(SurveyVO su){ 70 boolean flag=false; 71 if(this.ch.getReq().getSession(true).getAttribute(this.getAnonymousKey(su))!=null){ 72 return true; 73 } 74 75 Cookie co=ch.getCookie(this.getKey(su)); 76 if(co!=null) 77 flag=true; 78 return flag; 79 } 80 81 public void storeVote(SurveyVO su){ 82 if(this.user.getId()==UserI.ANONYMOUS_ID){ 83 this.ch.getReq().getSession(true).setAttribute(this.getKey(su),System.currentTimeMillis()+""); 84 }else{ 85 this.ch.addCookie(this.getKey(su),System.currentTimeMillis()+""); 86 } 87 } 88 89 } | Popular Tags |