KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > action > EditPostAction


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.action;
12
13 import org.jboss.portal.core.modules.ModuleException;
14 import org.jboss.portlet.forums.impl.PollImpl;
15 import org.jboss.portlet.forums.model.*;
16
17 import java.util.Collections JavaDoc;
18 import java.util.List JavaDoc;
19
20 /**
21  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
22  * @version $Revision: 1.4 $
23  */

24 public class EditPostAction
25       extends PostAction
26 {
27    private Message message;
28    private Poster poster;
29    private int postID;
30    private List JavaDoc attachments;
31    private Post post;
32    private Topic topic;
33    private Poll poll;
34    private boolean firstPost;
35
36    // /** An optional delete attachment command. */
37
// protected DeleteAttachmentCommand dac;
38
public EditPostAction(Message message,
39                          Poster poster,
40                          int postID,
41                          List JavaDoc attachments,
42                          Poll poll)
43    {
44       super(ForumAction.REFRESH);
45       this.message = message;
46       this.poster = poster;
47       this.postID = postID;
48       this.attachments = attachments;
49       this.poll = poll;
50    }
51
52    /**
53     * Creates a new {@link EditPostAction} object.
54     *
55     * @param postID DOCUMENT_ME
56     */

57    public EditPostAction(int postID)
58    {
59       super(ForumAction.INIT);
60       this.message = null;
61       this.poster = null;
62       this.postID = postID;
63       this.poll = new PollImpl();
64       this.attachments = Collections.EMPTY_LIST;
65    }
66
67    /**
68     * DOCUMENT_ME
69     *
70     * @return DOCUMENT_ME
71     */

72    public Post getPost()
73    {
74       return post;
75    }
76
77    /**
78     * DOCUMENT_ME
79     *
80     * @return DOCUMENT_ME
81     */

82    public Topic getTopic()
83    {
84       return topic;
85    }
86
87    /**
88     * DOCUMENT_ME
89     *
90     * @return DOCUMENT_ME
91     */

92    public Forum getForum()
93    {
94       return getTopic().getForum();
95    }
96
97    /**
98     * DOCUMENT_ME
99     *
100     * @return DOCUMENT_ME
101     */

102    public Poster getPoster()
103    {
104       // return getMode() == ForumAction.INIT ? getPost().getPoster() : poster;
105
return null;
106    }
107
108    /**
109     * DOCUMENT_ME
110     *
111     * @return DOCUMENT_ME
112     */

113    public Message getMessage()
114    {
115       return (getMode() == ForumAction.INIT) ? getPost().getMessage() : message;
116    }
117
118    /**
119     * DOCUMENT_ME
120     *
121     * @return DOCUMENT_ME
122     */

123    public List JavaDoc getAttachments()
124    {
125       return attachments;
126    }
127
128    /**
129     * DOCUMENT_ME
130     */

131    public void init()
132    {
133       System.out.println("EditPostAction.init()");
134       try
135       {
136          post = module.findPostByID(new Integer JavaDoc(postID));
137          topic = post.getTopic();
138          if(topic.getFirstPost().getID().equals(post.getID()))
139          {
140             firstPost = true;
141          }
142
143          Topic topic = post.getTopic();
144          message.setSubject(topic.getSubject());
145       }
146       catch(ModuleException e)
147       {
148          e.printStackTrace();
149       }
150       /*
151          try
152          {
153             post = homes.post.findByPrimaryKey(new Integer(postID));
154             topic = post.getTopic();
155             firstPost = EJB.areIdentical(post, topic.getFirstPost());
156             if (getMode() == INIT)
157             {
158                message = post.getMessage();
159                if (firstPost)
160                {
161                   message.setSubject(topic.getTitle());
162                }
163                PollEJBLocal poll = topic.getPoll();
164                if (poll != null)
165                {
166                   this.poll.setTitle(poll.getText());
167                   this.poll.setLength(poll.getLength());
168                   // try
169                   // {
170                   for (Iterator i = homes.option.findByPoll(poll).iterator();i.hasNext();)
171                   {
172                      OptionEJBLocal option = (OptionEJBLocal)i.next();
173                      this.poll.getOptions().add(option.getText());
174                   }
175                   // }
176                   // catch(FinderException e)
177                   // {
178                   // throw new ValidationException(TYPE_COULD_NOT_OBTAIN_VOTE_DATA);
179                   // }
180                }
181                else
182                {
183                   this.poll.setTitle("");
184                   this.poll.setLength(0);
185                   this.poll.setOptions(Collections.EMPTY_LIST);
186                }
187             }
188          }
189          catch (FinderException e)
190          {
191             throw new RuntimeException(e);
192          }
193        */

194    }
195
196    /**
197     * DOCUMENT_ME
198     *
199     * @return DOCUMENT_ME
200     */

201    public Poll getPoll()
202    {
203       return poll;
204    }
205
206    /**
207     * DOCUMENT_ME
208     *
209     * @return DOCUMENT_ME
210     */

211    public boolean isFirstPost()
212    {
213       return firstPost;
214    }
215 }
Popular Tags