1 package org.javabb.action; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.javabb.action.infra.BaseAction; 7 import org.javabb.component.PostFormatter; 8 import org.javabb.component.Spy; 9 import org.javabb.component.UserFormatter; 10 import org.javabb.infra.UserContext; 11 import org.javabb.transaction.CategoryTransaction; 12 import org.javabb.transaction.ForumTransaction; 13 import org.javabb.transaction.PostTransaction; 14 import org.javabb.transaction.TopicTransaction; 15 import org.javabb.transaction.UserTransaction; 16 import org.javabb.vo.Forum; 17 import org.javabb.vo.Post; 18 import org.javabb.vo.PostText; 19 import org.javabb.vo.Topic; 20 21 import com.opensymphony.webwork.ServletActionContext; 22 23 38 39 46 public class TopicAction extends BaseAction { 47 48 52 private TopicTransaction _topicTransaction; 53 54 private ForumTransaction _forumTransaction; 55 56 private PostTransaction _postTransaction; 57 58 private PostFormatter _postFormatter; 59 60 private CategoryTransaction _categoryTransaction; 61 62 private UserTransaction _userTransaction; 63 64 private Topic _topic = new Topic(); 65 66 private Post _post = new Post(); 67 68 private Forum _forum = new Forum(); 69 70 private List _topics = new ArrayList (); 71 72 private Long _moveToForum; 73 74 private List _reversePosts = new ArrayList (); 75 76 private List _posts = new ArrayList (); 77 78 private List lstCategory = new ArrayList (); 79 80 private List _users = new ArrayList (); 81 82 private List userRanks = new ArrayList (); 83 84 private UserFormatter userFormatter; 85 86 private String message = ""; 88 89 private long _foundItemsTotalCount; 90 91 private int watchTopic; 92 93 private int favoriteTopic; 94 95 99 102 public void setCategoryTransaction(CategoryTransaction categoryTransaction) { 103 this._categoryTransaction = categoryTransaction; 104 } 105 106 110 public void setForumTransaction(ForumTransaction forumTransaction) { 111 this._forumTransaction = forumTransaction; 112 } 113 114 118 public void setTopicTransaction(TopicTransaction topicTransaction) { 119 this._topicTransaction = topicTransaction; 120 } 121 122 126 public void setPostTransaction(PostTransaction postTransaction) { 127 this._postTransaction = postTransaction; 128 } 129 130 134 public void setPostFormatter(PostFormatter postFormatter) { 135 this._postFormatter = postFormatter; 136 } 137 138 public void setUserFormatter(UserFormatter userFormatter) { 139 this.userFormatter = userFormatter; 140 } 141 142 146 public void setUserTransaction(UserTransaction transaction) { 147 _userTransaction = transaction; 148 } 149 150 155 public String listaTopics() throws Exception { 156 157 if (_forum.getIdForum() != null) { 158 _forumId = _forum.getIdForum(); 159 } 160 _topics = _topicTransaction.getLastTopicsByLastPosts(_forumId, _page); 161 _forum.setIdForum(_forumId); 162 _forum = _forumTransaction.loadForum(_forumId); 163 164 lstCategory = _categoryTransaction.listCategory(); 166 167 userRanks = _userTransaction.getUserRanks(); 169 170 return SUCCESS; 171 } 172 173 176 public String loadTopic() { 177 _topic.setIdTopic(_topicId); 178 _topic = _topicTransaction.loadTopicForVisualization(_topic.getId()); 179 return SUCCESS; 180 } 181 182 187 public String showTopic() { 188 try { 189 if (_postId != null) { 190 Post p = new Post(); 191 p.setIdPost(_postId); 192 p = _postTransaction.loadPost(_postId); 193 _topicId = p.getTopic().getIdTopic(); 194 } 195 196 _topic = _topicTransaction.loadTopicForVisualization(_topicId); 197 _posts = _postTransaction.findByTopic(_topicId, _page); 198 199 UserContext.getContext().setTopicRead(_topicId); 201 202 if (UserContext.getContext().isAuthenticated()) { 204 watchTopic = _topicTransaction.isWatchTopic(_topicId, 205 UserContext.getContext().getUser().getIdUser()); 206 207 favoriteTopic = _topicTransaction.isFavoriteTopic(_topicId, 208 UserContext.getContext().getUser().getIdUser()); 209 } 210 211 if (UserContext.getContext().isAuthenticated()) { 212 String userName = UserContext.getContext().getUser().getUser(); 213 log.debug("User " + userName + " into of topic " 214 + _topic.getTitleTopic()); 215 } else { 216 log.debug("Anonymous ip[" 217 + ServletActionContext.getRequest().getRemoteAddr() 218 + "] user into of topic " + _topic.getTitleTopic()); 219 } 220 221 Spy.addSpyTopic(_topic); 222 } catch (Exception e) { 223 log.debug("Message not found:" + e.getMessage()); 224 return "no_messages"; 225 } 226 227 return SUCCESS; 228 } 229 230 231 232 235 public String loadTopicNoSumView() { 236 if (_post.getIdPost() != null) { 237 _postId = _post.getIdPost(); 238 } 239 _post = (PostText) _postTransaction.loadPost(_postId); 240 _topic = _topicTransaction.loadTopic(_topic.getId()); 241 return SUCCESS; 242 } 243 244 247 public String deleteTopic() { 248 _postTransaction.deleteAllPostsByTopic(_topic); 249 _topicTransaction.deleteTopic(_topic.getId()); 250 _forumTransaction.refreshForum(_forum.getId()); 252 253 setUrl("../viewforum.jbb?f=" + _forum.getIdForum()); 254 255 return SUCCESS; 256 } 257 258 261 public String listUnreadTopics() { 262 _topics = _topicTransaction.listUnreadTopics(_page); 263 return SUCCESS; 264 } 265 266 269 public String lockTopic() { 270 _topicTransaction.lockTopic(_topic); 271 setUrl("../viewtopic.jbb?t=" + _topic.getIdTopic()); 272 return SUCCESS; 273 } 274 275 278 public String unlockTopic() { 279 _topicTransaction.unlockTopic(_topic); 280 setUrl("../viewtopic.jbb?t=" + _topic.getIdTopic()); 281 return SUCCESS; 282 } 283 284 287 public String moveTopic() throws Exception { 288 Topic tmp = this.getTopic(); _topicTransaction.moveTopic(tmp, getMoveToForum(), message, 290 getText("forum_topic_moved_from"), 291 getText("forum_topic_moved_to"), getText("topic")); 292 293 setUrl("../viewtopic.jbb?t=" + _topic.getIdTopic()); 294 295 return SUCCESS; 296 } 297 298 301 public String reviewTopic() { 302 _reversePosts = _postTransaction.listPostsByTopicRev(_topic); 303 return SUCCESS; 304 } 305 306 public String watchTopicByUser() throws Exception { 307 _users = _topicTransaction.watchTopicsByUserId(_userId); 308 return SUCCESS; 309 } 310 311 public String watchTopicsByTopic() throws Exception { 312 _topics = _topicTransaction.watchTopicsByTopic(_topicId); 313 return SUCCESS; 314 } 315 316 317 public String favoriteTopicByUser() throws Exception { 318 _users = _topicTransaction.favoriteTopicsByUserId(_userId); 319 return SUCCESS; 320 } 321 322 public String favoriteTopicsByTopic() throws Exception { 323 _topics = _topicTransaction.favoriteTopicsByTopic(_topicId); 324 return SUCCESS; 325 } 326 327 328 329 public String findAllLastTopics() throws Exception { 330 _topics = _topicTransaction.findLastTopics(); 331 return SUCCESS; 332 } 333 334 335 public String findFavoriteTopics() throws Exception { 336 _topics = _topicTransaction.favoriteTopics(); 337 return SUCCESS; 338 } 339 340 344 347 public Topic getTopic() { 348 return _topic; 349 } 350 351 354 public List getTopics() { 355 return _topics; 356 } 357 358 361 public Long getMoveToForum() { 362 return _moveToForum; 363 } 364 365 369 public void setMoveToForum(Long moveToForum) { 370 this._moveToForum = moveToForum; 371 } 372 373 376 public List getReversePosts() { 377 return _reversePosts; 378 } 379 380 384 public String formatPost(Post post) { 385 return _postFormatter.formatPost(post); 386 } 387 388 392 public String formatEscaped(String text) { 393 return _postFormatter.formatEscaped(text); 394 } 395 396 399 public List getPosts() { 400 return _posts; 401 } 402 403 406 public Forum getForum() { 407 return _forum; 408 } 409 410 public long getFoundItemsTotalCount() { 411 return _foundItemsTotalCount; 412 } 413 414 417 public List getLstCategory() { 418 return lstCategory; 419 } 420 421 424 public String getMessage() { 425 return message; 426 } 427 428 432 public void setMessage(String message) { 433 this.message = message; 434 } 435 436 439 public int getWatchTopic() { 440 return watchTopic; 441 } 442 443 447 public void setWatchTopic(int watchTopic) { 448 this.watchTopic = watchTopic; 449 } 450 451 454 public List getUsers() { 455 return _users; 456 } 457 458 462 public void setUsers(List _users) { 463 this._users = _users; 464 } 465 466 469 public Post getPost() { 470 return _post; 471 } 472 473 477 public void setPost(Post _post) { 478 this._post = _post; 479 } 480 481 public UserFormatter getUserFormatter() { 482 return userFormatter; 483 } 484 485 public List getUserRanks() { 486 return userRanks; 487 } 488 489 public void setUserRanks(List userRanks) { 490 this.userRanks = userRanks; 491 } 492 493 public int getFavoriteTopic() { 494 return favoriteTopic; 495 } 496 497 public void setFavoriteTopic(int favoriteTopic) { 498 this.favoriteTopic = favoriteTopic; 499 } 500 501 } | Popular Tags |