KickJava   Java API By Example, From Geeks To Geeks.

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


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.model.User;
15 import org.jboss.portal.core.modules.ModuleException;
16 import org.jboss.portlet.forums.ForumsModule;
17 import org.jboss.portlet.forums.commands.AbstractCommand;
18 import org.jboss.portlet.forums.commands.ValidationException;
19 import org.jboss.portlet.forums.model.Category;
20 import org.jboss.portlet.forums.model.Forum;
21 import org.jboss.portlet.forums.model.Message;
22 import org.jboss.portlet.forums.model.Poll;
23 import org.jboss.portlet.forums.model.Poster;
24 import org.jboss.portlet.command.ActionCommand;
25 import org.jboss.portlet.JBossActionRequest;
26 import org.jboss.portlet.JBossActionResponse;
27
28 /**
29  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
30  * @author <a HREF="mailto:theute@users.sourceforge.net">Thomas Heute</a>
31  * @version $Revision: 1.3 $
32  */

33 public abstract class ForumCommand
34    extends AbstractCommand
35 {
36
37    protected ForumCommand(JBossActionRequest request, JBossActionResponse response)
38    {
39       super(request, response);
40    }
41
42    /*
43       public Homes homes;
44       public Level level;
45       public boolean isAuth;
46       public boolean isAuthRead;
47       public boolean isAuthDelete;
48       public boolean isAuthSticky;
49       public boolean isAuthAnnounce;
50       public boolean isAuthPollCreate;
51       public boolean isAuthMod;
52       public boolean isAuthAttachments;
53     */

54
55    /** DOCUMENT_ME */
56    public int forumId;
57
58    /** DOCUMENT_ME */
59    public User currentUser;
60
61    /** DOCUMENT_ME */
62    public Forum forum;
63
64    /** DOCUMENT_ME */
65    public Category category;
66
67    /** DOCUMENT_ME */
68    public Poster poster;
69
70    /** DOCUMENT_ME */
71    public Message message;
72
73    /** DOCUMENT_ME */
74    public Poll poll;
75
76    // public Attachment[] attachments;
77

78    /** DOCUMENT_ME */
79    public ForumsModule forumsModule;
80    private String JavaDoc category_title;
81    private String JavaDoc forum_name;
82    private int forum_status;
83
84    /**
85     * DOCUMENT_ME
86     */

87    protected void find()
88    {
89       try
90       {
91          forum = forumsModule.findForumByID(new Integer JavaDoc(forumId));
92       }
93       catch (ModuleException e)
94       {
95          e.printStackTrace();
96       }
97
98       category = forum.getCategory();
99    }
100
101    /**
102     * DOCUMENT_ME
103     *
104     * @throws ValidationException DOCUMENT_ME
105     */

106    protected void prepare()
107    throws ValidationException
108    {
109       find();
110       category_title = category.getTitle();
111       forum_status = forum.getStatus();
112       forum_name = forum.getName();
113
114       // level = module.secGetLevel(category_title + ":" + forum_name + ":", currentUser);
115
// boolean loggedIn = getPoster().getUser() != null;
116

117       /*
118          int[] types = new int[] {
119          authType(),
120          Auth.TYPE_READ,
121          Auth.TYPE_DELETE,
122          Auth.TYPE_STICKY,
123          Auth.TYPE_ANNOUNCE,
124          Auth.TYPE_POLL,
125          Auth.TYPE_ATTACH };
126          boolean[] auths =forum.getAuth().can(types, loggedIn, level);
127          isAuth = auths[0];
128          isAuthRead = auths[1];
129          isAuthDelete = auths[2];
130          isAuthSticky = auths[3];
131          isAuthAnnounce = auths[4];
132          isAuthPollCreate = auths[5];
133          isAuthAttachments = auths[6];
134          isAuthMod = Auth.hasLevel(Auth.LEVEL_MOD, loggedIn, level);
135          //
136          if (forum_status == BBConstants.FORUM_LOCKED && !isAuthMod)
137          {
138          throw new ValidationException(TYPE_FORUM_LOCKED);
139          }
140          //
141          if (!isAuth)
142          {
143          throw new ValidationException(TYPE_NOT_AUTHORIZED);
144          }
145          // Should not be here, maybe the inheritance heirarchy is not good
146          if (attachments != null && attachments.length > 0 && !(isAuthMod || isAuthAttachments))
147          {
148          throw new ValidationException(TYPE_CANNOT_ADD_ATTACHMENT);
149          }
150        */

151    }
152
153    /**
154     * DOCUMENT_ME
155     *
156     * @return DOCUMENT_ME
157     */

158    public Result execute()
159    {
160       try
161       {
162          prepare();
163          return __execute();
164       }
165       catch (ValidationException e)
166       {
167          return e.getResult();
168       }
169    }
170
171    /**
172     * DOCUMENT_ME
173     *
174     * @return DOCUMENT_ME
175     */

176    public abstract int authType();
177
178    /**
179     * DOCUMENT_ME
180     *
181     * @return DOCUMENT_ME
182     */

183    protected abstract Result __execute();
184
185    /**
186     * DOCUMENT_ME
187     *
188     * @return DOCUMENT_ME
189     */

190    public User currentUser()
191    {
192       return currentUser;
193    }
194
195    /**
196     * DOCUMENT_ME
197     *
198     * @param currentUser DOCUMENT_ME
199     */

200    public void setCurrentUser(User currentUser)
201    {
202       this.currentUser = currentUser;
203    }
204
205    /**
206     * DOCUMENT_ME
207     *
208     * @return DOCUMENT_ME
209     */

210    public Poster getPoster()
211    {
212       return poster;
213    }
214
215    /**
216     * DOCUMENT_ME
217     *
218     * @param poster DOCUMENT_ME
219     */

220    public void setPoster(Poster poster)
221    {
222       this.poster = poster;
223    }
224
225    /**
226     * DOCUMENT_ME
227     *
228     * @return DOCUMENT_ME
229     */

230    public ForumsModule getModule()
231    {
232       return forumsModule;
233    }
234
235    /**
236     * DOCUMENT_ME
237     *
238     * @param module DOCUMENT_ME
239     */

240    public void setModule(ForumsModule module)
241    {
242       this.forumsModule = module;
243    }
244 }
Popular Tags