KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > commands > post > NewTopicCommand


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under GPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portlet.forums.commands.post;
12
13 import org.jboss.portal.common.command.result.Result;
14 import org.jboss.portal.core.modules.ModuleException;
15 import org.jboss.portlet.JBossActionRequest;
16 import org.jboss.portlet.JBossActionResponse;
17 import org.jboss.portlet.forums.ForumsConstants;
18 import org.jboss.portlet.forums.commands.ValidationException;
19 import org.jboss.portlet.forums.model.Post;
20
21 import java.util.Date JavaDoc;
22
23 /**
24  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
25  * @author <a HREF="mailto:theute@users.sourceforge.net">Thomas Heute</a>
26  * @version $Revision: 1.7 $
27  */

28 public final class NewTopicCommand
29       extends ForumCommand
30 {
31    /**
32     * DOCUMENT_ME
33     */

34    public Date JavaDoc current_time;
35
36    /**
37     * DOCUMENT_ME
38     */

39    public int topic_type;
40
41    /**
42     * Notification when someone replies
43     */

44    public boolean notify;
45
46    /**
47     * DOCUMENT_ME
48     */

49    public Post post;
50
51    public NewTopicCommand(JBossActionRequest request, JBossActionResponse response)
52    {
53       super(request, response);
54    }
55
56    /**
57     * DOCUMENT_ME
58     *
59     * @return DOCUMENT_ME
60     */

61    public int authType()
62    {
63       return ForumsConstants.TOPIC_TYPE_TO_AUTH_TYPE[topic_type];
64    }
65
66    /**
67     * DOCUMENT_ME
68     *
69     * @throws ValidationException DOCUMENT_ME
70     */

71    protected void prepare()
72          throws ValidationException
73    {
74       super.prepare();
75       PostTools.validate(message);
76
77       // PostTools.validate(poll);
78
}
79
80    /**
81     * DOCUMENT_ME
82     *
83     * @return DOCUMENT_ME
84     */

85    protected Result __execute()
86    {
87       try
88       {
89          post = forumsModule.createTopic(forum,
90                                          message,
91                                          new Date JavaDoc(),
92                                          poster,
93                                          topic_type);
94          forumsModule.createWatch(poster, post.getTopic());
95          poster.incrementPostCount();
96       }
97       catch(ModuleException e)
98       {
99          // TODO Auto-generated catch block
100
e.printStackTrace();
101       }
102
103       /*
104          boolean topic_vote = poll.getTitle() != null && poll.getOptions().size() >= 2;
105          TopicEJBLocal topicEJB = null;
106          try
107          {
108             topicEJB = homes.topic.create(message.getSubject(),
109                   getPoster().getUser(),
110                   current_time,
111                   forum,
112                   BBConstants.TOPIC_UNLOCKED,
113                   topic_type,
114                   topic_vote);
115             forum.setTopicSize(forum.getTopicSize() + 1);
116             post = homes.post.create(topicEJB, forum, getPoster(), message, current_time);
117             topicEJB.setFirstPost(post);
118             topicEJB.setLastPost(post);
119             topicEJB.setLastPostDate(current_time);
120             forum.setLastPost(post);
121            forum.setPostSize(forum.getPostSize() + 1);
122             for (int i = 0;i < attachments.length;i++)
123             {
124                Attachment attachment = attachments[i];
125                homes.attachment.create(post,
126                      attachment.getFile().getName(),
127                      attachment.getFile().getContent(),
128                      attachment.getComment(),
129                      attachment.getFile().getContentType(),
130                      attachment.getFile().getSize(),
131                      current_time);
132             }
133             if (topic_vote)
134             {
135                PollEJBLocal pollEJB = homes.poll.create(topicEJB, poll.getTitle(), current_time, poll.getLength());
136                for (int i = 0;i < poll.getOptions().size();i++)
137                {
138                   String text = (String)poll.getOptions().get(i);
139                   homes.option.create(pollEJB, text);
140                }
141             }
142             if (notify)
143             {
144                homes.topicWatch.create(getPoster().getUser(), topicEJB);
145             }
146          }
147          catch (CreateException e)
148          {
149             log.error("Cannot insert topic", e);
150             return TYPE_ERROR_IN_POSTING;
151          }
152        */

153       return TYPE_NEW_TOPIC_POSTED;
154    }
155 }
Popular Tags