KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > action > TopicAction


1 package org.javabb.action;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
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 /*
24  * Copyright 2004 JavaFree.org
25  *
26  * Licensed under the Apache License, Version 2.0 (the "License");
27  * you may not use this file except in compliance with the License.
28  * You may obtain a copy of the License at
29  *
30  * http://www.apache.org/licenses/LICENSE-2.0
31  *
32  * Unless required by applicable law or agreed to in writing, software
33  * distributed under the License is distributed on an "AS IS" BASIS,
34  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35  * See the License for the specific language governing permissions and
36  * limitations under the License.
37  */

38
39 /**
40  * $Id: TopicAction.java,v 1.35.2.5.2.3.2.6 2006/08/08 18:49:01 daltoncamargo Exp $
41  *
42  * @author Dalton Camargo - <a HREF="mailto:dalton@javabb.org">dalton@javabb.org
43  * </a> <br>
44  * @author Ronald Tetsuo Miura <br>
45  */

46 public class TopicAction extends BaseAction {
47
48     // ####################################################################
49
// Parameters
50
// ####################################################################
51

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 JavaDoc _topics = new ArrayList JavaDoc();
71
72     private Long JavaDoc _moveToForum;
73
74     private List JavaDoc _reversePosts = new ArrayList JavaDoc();
75
76     private List JavaDoc _posts = new ArrayList JavaDoc();
77
78     private List JavaDoc lstCategory = new ArrayList JavaDoc();
79
80     private List JavaDoc _users = new ArrayList JavaDoc();
81
82     private List JavaDoc userRanks = new ArrayList JavaDoc();
83
84     private UserFormatter userFormatter;
85
86     // message used to notify user by mail
87
private String JavaDoc message = "";
88
89     private long _foundItemsTotalCount;
90
91     private int watchTopic;
92     
93     private int favoriteTopic;
94
95     // ####################################################################
96
// Dependencies
97
// ####################################################################
98

99     /**
100      * @param categoryTransaction
101      */

102     public void setCategoryTransaction(CategoryTransaction categoryTransaction) {
103         this._categoryTransaction = categoryTransaction;
104     }
105
106     /**
107      * @param forumTransaction
108      * The forumTransaction to set.
109      */

110     public void setForumTransaction(ForumTransaction forumTransaction) {
111         this._forumTransaction = forumTransaction;
112     }
113
114     /**
115      * @param topicTransaction
116      * the new topicTransaction value
117      */

118     public void setTopicTransaction(TopicTransaction topicTransaction) {
119         this._topicTransaction = topicTransaction;
120     }
121
122     /**
123      * @param postTransaction
124      * the new postTransaction value
125      */

126     public void setPostTransaction(PostTransaction postTransaction) {
127         this._postTransaction = postTransaction;
128     }
129
130     /**
131      * @param postFormatter
132      * the new postFormatter value
133      */

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     // ####################################################################
143
// Actions
144
// ####################################################################
145

146     public void setUserTransaction(UserTransaction transaction) {
147         _userTransaction = transaction;
148     }
149
150     /**
151      * For view where list all topics by id of forum
152      *
153      * @return Action status
154      */

155     public String JavaDoc listaTopics() throws Exception JavaDoc {
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         // Load all categories to populate the combo of foruns
165
lstCategory = _categoryTransaction.listCategory();
166
167         // load user Ranking list
168
userRanks = _userTransaction.getUserRanks();
169
170         return SUCCESS;
171     }
172
173     /**
174      * @return Action status
175      */

176     public String JavaDoc loadTopic() {
177         _topic.setIdTopic(_topicId);
178         _topic = _topicTransaction.loadTopicForVisualization(_topic.getId());
179         return SUCCESS;
180     }
181
182     /**
183      * Get all posts by topic
184      *
185      * @return result
186      */

187     public String JavaDoc 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             // Mark the topis as read
200
UserContext.getContext().setTopicRead(_topicId);
201
202             // Check if user is watching this topic
203
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 JavaDoc 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 JavaDoc e) {
223             log.debug("Message not found:" + e.getMessage());
224             return "no_messages";
225         }
226
227         return SUCCESS;
228     }
229     
230
231
232     /**
233      * @return Action status
234      */

235     public String JavaDoc 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     /**
245      * @return Action status
246      */

247     public String JavaDoc deleteTopic() {
248         _postTransaction.deleteAllPostsByTopic(_topic);
249         _topicTransaction.deleteTopic(_topic.getId());
250         // Atualiza a informaçao dos topicos
251
_forumTransaction.refreshForum(_forum.getId());
252
253         setUrl("../viewforum.jbb?f=" + _forum.getIdForum());
254
255         return SUCCESS;
256     }
257
258     /**
259      * @return result
260      */

261     public String JavaDoc listUnreadTopics() {
262         _topics = _topicTransaction.listUnreadTopics(_page);
263         return SUCCESS;
264     }
265
266     /**
267      * @return result
268      */

269     public String JavaDoc lockTopic() {
270         _topicTransaction.lockTopic(_topic);
271         setUrl("../viewtopic.jbb?t=" + _topic.getIdTopic());
272         return SUCCESS;
273     }
274
275     /**
276      * @return result
277      */

278     public String JavaDoc unlockTopic() {
279         _topicTransaction.unlockTopic(_topic);
280         setUrl("../viewtopic.jbb?t=" + _topic.getIdTopic());
281         return SUCCESS;
282     }
283
284     /**
285      * @return Action status
286      */

287     public String JavaDoc moveTopic() throws Exception JavaDoc {
288         Topic tmp = this.getTopic(); // topicTransaction.loadVO(topic);
289
_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     /**
299      * @return result
300      */

301     public String JavaDoc reviewTopic() {
302         _reversePosts = _postTransaction.listPostsByTopicRev(_topic);
303         return SUCCESS;
304     }
305
306     public String JavaDoc watchTopicByUser() throws Exception JavaDoc {
307         _users = _topicTransaction.watchTopicsByUserId(_userId);
308         return SUCCESS;
309     }
310
311     public String JavaDoc watchTopicsByTopic() throws Exception JavaDoc {
312         _topics = _topicTransaction.watchTopicsByTopic(_topicId);
313         return SUCCESS;
314     }
315
316     
317     public String JavaDoc favoriteTopicByUser() throws Exception JavaDoc {
318         _users = _topicTransaction.favoriteTopicsByUserId(_userId);
319         return SUCCESS;
320     }
321
322     public String JavaDoc favoriteTopicsByTopic() throws Exception JavaDoc {
323         _topics = _topicTransaction.favoriteTopicsByTopic(_topicId);
324         return SUCCESS;
325     }
326     
327     
328     
329     public String JavaDoc findAllLastTopics() throws Exception JavaDoc {
330         _topics = _topicTransaction.findLastTopics();
331         return SUCCESS;
332     }
333     
334     
335     public String JavaDoc findFavoriteTopics() throws Exception JavaDoc {
336         _topics = _topicTransaction.favoriteTopics();
337         return SUCCESS;
338     }
339
340     // ####################################################################
341
// View objects accessors
342
// ####################################################################
343

344     /**
345      * @return Returns the topic.
346      */

347     public Topic getTopic() {
348         return _topic;
349     }
350
351     /**
352      * @return Returns the topics.
353      */

354     public List JavaDoc getTopics() {
355         return _topics;
356     }
357
358     /**
359      * @return Returns the moveToForum.
360      */

361     public Long JavaDoc getMoveToForum() {
362         return _moveToForum;
363     }
364
365     /**
366      * @param moveToForum
367      * The moveToForum to set.
368      */

369     public void setMoveToForum(Long JavaDoc moveToForum) {
370         this._moveToForum = moveToForum;
371     }
372
373     /**
374      * @return Returns the reverseTopics.
375      */

376     public List JavaDoc getReversePosts() {
377         return _reversePosts;
378     }
379
380     /**
381      * @param post
382      * @return formated post
383      */

384     public String JavaDoc formatPost(Post post) {
385         return _postFormatter.formatPost(post);
386     }
387
388     /**
389      * @param text
390      * @return formated post
391      */

392     public String JavaDoc formatEscaped(String JavaDoc text) {
393         return _postFormatter.formatEscaped(text);
394     }
395
396     /**
397      * @return Returns the posts.
398      */

399     public List JavaDoc getPosts() {
400         return _posts;
401     }
402
403     /**
404      * @return Returns the forum.
405      */

406     public Forum getForum() {
407         return _forum;
408     }
409
410     public long getFoundItemsTotalCount() {
411         return _foundItemsTotalCount;
412     }
413
414     /**
415      * @return Returns the lstCategory.
416      */

417     public List JavaDoc getLstCategory() {
418         return lstCategory;
419     }
420
421     /**
422      * @return Returns the message.
423      */

424     public String JavaDoc getMessage() {
425         return message;
426     }
427
428     /**
429      * @param message
430      * The message to set.
431      */

432     public void setMessage(String JavaDoc message) {
433         this.message = message;
434     }
435
436     /**
437      * @return Returns the watchTopic.
438      */

439     public int getWatchTopic() {
440         return watchTopic;
441     }
442
443     /**
444      * @param watchTopic
445      * The watchTopic to set.
446      */

447     public void setWatchTopic(int watchTopic) {
448         this.watchTopic = watchTopic;
449     }
450
451     /**
452      * @return Returns the _users.
453      */

454     public List JavaDoc getUsers() {
455         return _users;
456     }
457
458     /**
459      * @param _users
460      * The _users to set.
461      */

462     public void setUsers(List JavaDoc _users) {
463         this._users = _users;
464     }
465
466     /**
467      * @return Returns the _post.
468      */

469     public Post getPost() {
470         return _post;
471     }
472
473     /**
474      * @param _post
475      * The _post to set.
476      */

477     public void setPost(Post _post) {
478         this._post = _post;
479     }
480
481     public UserFormatter getUserFormatter() {
482         return userFormatter;
483     }
484
485     public List JavaDoc getUserRanks() {
486         return userRanks;
487     }
488
489     public void setUserRanks(List JavaDoc 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