| 1 package org.javabb.action.ajax; 2 3 import java.util.HashMap ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 7 import org.javabb.action.infra.ActionSuper; 8 import org.javabb.component.Spy; 9 import org.javabb.component.VelocityTemplate; 10 import org.javabb.infra.JbbConfig; 11 import org.javabb.transaction.TopicTransaction; 12 import org.javabb.vo.FavUserTopic; 13 import org.javabb.vo.FavUserTopicPK; 14 import org.javabb.vo.User; 15 16 import uk.ltd.getahead.dwr.WebContext; 17 import uk.ltd.getahead.dwr.WebContextFactory; 18 19 public class ActionFacade extends ActionSuper { 20 private static final long serialVersionUID = 1L; 21 22 private TopicTransaction topicTransaction; 23 24 public void setTopicTransaction(TopicTransaction topicTransaction) { 25 this.topicTransaction = topicTransaction; 26 } 27 28 public String addFavoriteTopic(Long topicId) { 29 try { 30 WebContext ctx = WebContextFactory.get(); 31 HttpServletRequest req = ctx.getHttpServletRequest(); 32 User user = (User) req.getSession().getAttribute("jbbuser"); 33 34 if (topicId != null && user != null && user.getId() != null) { 35 Long userId = user.getId(); 36 FavUserTopic favUserTopic = new FavUserTopic( 37 new FavUserTopicPK(topicId, userId)); 38 39 topicTransaction.add(favUserTopic); 40 } 41 } catch (Exception e) { 42 log.debug("Error at addFavoriteTopic = " + e.getMessage()); 43 return "addFavoriteTopic=0"; 44 } 45 return "addFavoriteTopic=1"; 46 } 47 48 public String deleteFavoriteTopic(Long topicId) { 49 try { 50 WebContext ctx = WebContextFactory.get(); 51 HttpServletRequest req = ctx.getHttpServletRequest(); 52 User user = (User) req.getSession().getAttribute("jbbuser"); 53 54 if (topicId != null && user != null && user.getId() != null) { 55 Long userId = user.getId(); 56 FavUserTopic favUserTopic = new FavUserTopic( 57 new FavUserTopicPK(topicId, userId)); 58 topicTransaction.delete(favUserTopic); 59 } 60 } catch (Exception e) { 61 log.debug("Error at deleteFavoriteTopic = " + e.getMessage()); 62 return "deleteFavoriteTopic=0"; 63 } 64 return "deleteFavoriteTopic=1"; 65 } 66 67 public String addWatchTopic(Long topicId) { 68 try { 69 WebContext ctx = WebContextFactory.get(); 70 HttpServletRequest req = ctx.getHttpServletRequest(); 71 User user = (User) req.getSession().getAttribute("jbbuser"); 72 73 if (topicId != null && user != null && user.getId() != null) { 74 Long userId = user.getId(); 75 topicTransaction.insertWatchTopicUser(topicId, userId); 76 } 77 } catch (Exception e) { 78 log.debug("Error at addWatchTopic = " + e.getMessage()); 79 return "addWatchTopic=0"; 80 } 81 return "addWatchTopic=1"; 82 } 83 84 85 public String deleteWatchTopic(Long topicId) { 86 try { 87 WebContext ctx = WebContextFactory.get(); 88 HttpServletRequest req = ctx.getHttpServletRequest(); 89 User user = (User) req.getSession().getAttribute("jbbuser"); 90 91 if (topicId != null && user != null && user.getId() != null) { 92 Long userId = user.getId(); 93 topicTransaction.deleteWatchTopicUser(topicId, userId); 94 } 95 } catch (Exception e) { 96 log.debug("Error at deleteWatchTopic = " + e.getMessage()); 97 return "deleteWatchTopic=0"; 98 } 99 return "deleteWatchTopic=1"; 100 } 101 102 103 public String spyTemplate(){ 104 HashMap map = (HashMap ) Spy.getI18NMessages(); 105 map.put("topics", Spy.getSpyTopics()); 106 map.put("theme_name", JbbConfig.getConfig().getForumConfig().getForumName()); 107 108 String template = VelocityTemplate.makeTemplate(map, "spy_table.vm"); 109 return template; 110 } 111 112 } 113 | Popular Tags |