KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > ForumsPortlet


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;
12
13 import org.jboss.portal.common.command.CommandException;
14 import org.jboss.portal.common.command.filter.CommandFilter;
15 import org.jboss.portal.common.command.filter.CompositeFilter;
16 import org.jboss.portal.common.command.filter.ExecuteFilter;
17 import org.jboss.portal.common.command.result.Result;
18 import org.jboss.portal.common.command.result.ResultType;
19 import org.jboss.portal.common.context.DelegateContext;
20 import org.jboss.portal.common.util.ProxyInfo;
21 import org.jboss.portal.core.model.User;
22 import org.jboss.portal.core.modules.ModuleException;
23 import org.jboss.portal.core.modules.RoleModule;
24 import org.jboss.portal.core.modules.UserModule;
25 import org.jboss.portal.core.servlet.jsp.PortalJsp;
26 import org.jboss.portal.format.render.bbcodehtml.ToHTMLConfig;
27 import org.jboss.portal.format.render.bbcodehtml.ToHTMLRenderer;
28 import org.jboss.portal.format.util.CLLoader;
29 import org.jboss.portlet.forums.commands.CommandConstants;
30 import org.jboss.portlet.forums.commands.admin.OrderCategoryCommand;
31 import org.jboss.portlet.forums.commands.admin.CreateCategoryCommand;
32 import org.jboss.portlet.forums.commands.admin.CreateForumCommand;
33 import org.jboss.portlet.forums.commands.admin.OrderForumCommand;
34 import org.jboss.portlet.forums.commands.admin.DeleteMoveCategoryCommand;
35 import org.jboss.portlet.forums.commands.admin.DeleteForumCommand;
36 import org.jboss.portlet.forums.commands.admin.DeleteMoveForumCommand;
37 import org.jboss.portlet.forums.commands.admin.UpdateCategoryCommand;
38 import org.jboss.portlet.forums.commands.admin.UpdateForumCommand;
39 import org.jboss.portlet.forums.commands.post.EditPostCommand;
40 import org.jboss.portlet.forums.commands.post.ForumCommand;
41 import org.jboss.portlet.forums.commands.post.NewTopicCommand;
42 import org.jboss.portlet.forums.commands.post.ReplyCommand;
43 import org.jboss.portlet.forums.impl.ForumsModuleImpl;
44 import org.jboss.portlet.forums.interceptors.FloodControlInterceptor;
45 import org.jboss.portlet.forums.interceptors.NotificationInterceptor;
46
47 import org.jboss.portlet.forums.properties.TCCLXProperties;
48 import org.jboss.portlet.forums.theme.FolderType;
49 import org.jboss.portlet.forums.theme.ForumsTheme;
50 import org.jboss.portlet.forums.action.Action;
51 import org.jboss.portlet.forums.action.ProcessCommandAction;
52 import org.jboss.portlet.forums.action.ForumAction;
53 import org.jboss.portlet.forums.action.TopicAction;
54 import org.jboss.portlet.forums.action.EditPostAction;
55 import org.jboss.portlet.forums.action.ReplyAction;
56 import org.jboss.portlet.forums.action.NewTopicAction;
57 import org.jboss.portlet.forums.action.PostAction;
58 import org.jboss.portlet.forums.model.Post;
59 import org.jboss.portlet.forums.model.Forum;
60 import org.jboss.portlet.forums.model.Category;
61 import org.jboss.portlet.forums.model.Message;
62 import org.jboss.portlet.forums.model.Poster;
63 import org.jboss.portlet.forums.model.AuthType;
64 import org.jboss.portlet.forums.model.Topic;
65 import org.jboss.portlet.forums.model.ForumWatch;
66 import org.jboss.portlet.forums.model.TopicWatch;
67 import org.jboss.portlet.forums.helper.ForumsTools;
68 import org.jboss.portlet.forums.helper.SimpleDateFormatPool;
69 import org.jboss.portlet.forums.helper.Goto;
70 import org.jboss.portlet.forums.helper.IndexIterator;
71 import org.jboss.portlet.forums.helper.GotoWithOffset;
72 import org.jboss.portlet.JBossPortlet;
73 import org.jboss.portlet.JBossRenderRequest;
74 import org.jboss.portlet.JBossRenderResponse;
75 import org.jboss.portlet.JBossActionRequest;
76 import org.jboss.portlet.JBossActionResponse;
77 import org.jboss.util.collection.CompoundIterator;
78
79 import javax.portlet.PortletException;
80 import javax.portlet.PortletRequestDispatcher;
81 import javax.portlet.PortletURL;
82 import javax.portlet.WindowState;
83 import java.io.IOException JavaDoc;
84 import java.io.PrintWriter JavaDoc;
85 import java.io.StringWriter JavaDoc;
86 import java.util.ResourceBundle JavaDoc;
87 import java.util.Iterator JavaDoc;
88 import java.util.Date JavaDoc;
89 import java.util.List JavaDoc;
90 import java.util.Calendar JavaDoc;
91 import java.util.HashSet JavaDoc;
92 import java.util.Set JavaDoc;
93 import java.util.Collection JavaDoc;
94
95 /**
96  * @author <a HREF="mailto:theute@jboss.org">Thomas Heute</a>
97  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
98  * @version $Revision: 1.22 $
99  */

100 public class ForumsPortlet
101    extends JBossPortlet
102    implements ForumsConstants
103 {
104    private UserModule userModule;
105
106    private RoleModule roleModule;
107
108    private ForumsModule forumsModule;
109
110    private final String JavaDoc OP_MAIN = "main";
111
112    public static final String JavaDoc OP_SHOWFORUM = "showForum";
113
114    private final String JavaDoc OP_POSTING = "showPosting";
115
116    public final static String JavaDoc OP_SHOWTOPIC = "showTopic";
117
118    public static final String JavaDoc OP_SHOWADMINFORUMS = "showAdminForums";
119
120    private final String JavaDoc OP_SHOWADDEDITFORUM = "showAddEditForum";
121
122    private final String JavaDoc OP_SHOWEDITCATEGORY = "showEditCategory";
123
124    private final String JavaDoc OP_SHOWDELETEFORUM = "showDeleteForum";
125
126    private final String JavaDoc OP_CONFIRM = "showConfirm";
127
128    private final String JavaDoc OP_SHOWWATCHEDTOPICS = "showWatchedTopics";
129
130    private final String JavaDoc OP_SHOWWATCHEDFORUMS = "showWatchedForums";
131
132    private ForumsTheme theme;
133
134    // Interceptors
135
private CompositeFilter compositeInterceptor;
136
137    // private final ResourceCacheInvalidatorInterceptor resourceInterceptor;
138
// private final IndexInterceptor indexInterceptor;
139
private NotificationInterceptor notificationInterceptor;
140
141    private FloodControlInterceptor floodControlInterceptor;
142
143    private ExecuteFilter executeInterceptor;
144
145    private CommandFilter chain;
146
147    private ToHTMLRenderer toHTMLRenderer;
148
149    private ProxyInfo proxyInfo;
150
151    /**
152     * Initialization method of the portlet
153     *
154     * @throws PortletException DOCUMENT_ME
155     */

156    public void init() throws PortletException
157    {
158       super.init();
159       forumsModule = new ForumsModuleImpl();
160       getPortletContext().setAttribute("forumsModule", forumsModule);
161
162       // Define the chain of interceptors
163
chain = compositeInterceptor = new CompositeFilter();
164
165       // resourceInterceptor = new ResourceCacheInvalidatorInterceptor();
166
// indexInterceptor = new IndexInterceptor();
167
notificationInterceptor = new NotificationInterceptor(this, forumsModule);
168       notificationInterceptor.setFrom(getPortletConfig().getInitParameter("fromAddress"));
169
170       floodControlInterceptor = new FloodControlInterceptor();
171       String JavaDoc floodInterval = getPortletConfig().getInitParameter("floodInterval");
172       if (floodInterval != null)
173       {
174          int floodIntervalInt = Integer.parseInt(floodInterval);
175          floodControlInterceptor.setFloodInterval(floodIntervalInt);
176       }
177
178       executeInterceptor = new ExecuteFilter();
179
180       // compositeInterceptor.setNext(resourceInterceptor);
181
// resourceInterceptor.setNext(indexInterceptor);
182
// indexInterceptor.setNext(notificationInterceptor);
183
compositeInterceptor.setNext(notificationInterceptor);
184       notificationInterceptor.setNext(floodControlInterceptor);
185       floodControlInterceptor.setNext(executeInterceptor);
186
187       /*
188        try
189        {
190        userModule = (UserModule) new InitialContext()
191        .lookup(ModuleConstants.USERMODULE_JNDINAME);
192        roleModule = (RoleModule) new InitialContext()
193        .lookup(ModuleConstants.ROLEMODULE_JNDINAME);
194        }
195        catch (NamingException e)
196        {
197        throw new PortletException(e);
198        }
199        */

200       // Start the theme
201
theme = new ForumsTheme();
202       try
203       {
204          // start theme
205
theme.setExtendedProperties(new TCCLXProperties(ForumsConstants.THEMENAME, "theme.properties"));
206          theme.start();
207       }
208       catch (IOException JavaDoc e)
209       {
210          throw new PortletException("Cannot start the forums theme, can't read template files", e);
211       }
212       catch (Exception JavaDoc e)
213       {
214          throw new PortletException("Cannot start the forums theme", e);
215       }
216
217       // Create the HTMLRenderer for BBCode
218
String JavaDoc location = "org/jboss/portal/format/template";
219       ToHTMLConfig config = new ToHTMLConfig();
220       config.setLoader(new CLLoader(location));
221       toHTMLRenderer = new ToHTMLRenderer(config);
222
223       // Preferences proxy
224
/*
225        Class proxyClass = Proxy.getProxyClass(Thread.currentThread().getContextClassLoader(), new Class[]{PreferencesProxy.class});
226        try
227        {
228        proxyInfo = new ProxyInfo(proxyClass);
229        }
230        catch (Exception e1)
231        {
232        throw new PortletException();
233        }
234        */

235    }
236
237    public String JavaDoc getDefaultOperation()
238    {
239       return OP_MAIN;
240    }
241
242    /**
243     * doEdit Portlet method
244     *
245     * @param req Portlet render request
246     * @param resp Portlet response request
247     * @throws PortletException For any unexpected exception
248     * @throws IOException If cannot write HTML chunk
249     */

250    protected void doEdit(JBossRenderRequest req, JBossRenderResponse resp)
251       throws PortletException, IOException JavaDoc
252    {
253    }
254
255    /**
256     * doView Portlet method
257     *
258     * @param req Portlet render request
259     * @param resp Portlet response request
260     * @throws PortletException For any unexpected exception
261     * @throws IOException If cannot write HTML chunk
262     */

263    protected void doView(JBossRenderRequest req, JBossRenderResponse resp)
264       throws PortletException, IOException JavaDoc
265    {
266       ResourceBundle JavaDoc bundle = getResourceBundle(req.getLocale());
267
268       resp.setContentType("text/html");
269       PrintWriter JavaDoc writer = resp.getWriter();
270       writer.write("<div class=\"bb\">");
271       String JavaDoc op = req.getParameters().get(getOperationName(),
272          getDefaultOperation());
273       if (req.getWindowState() != WindowState.MAXIMIZED)
274       {
275          writer.write("<table width=\"100%\" cellpadding=\"2\" cellspacing=\"2\"><tr class=\"portlet-section-body\">");
276
277          // Window is is normal mode
278
// Check if the user is an administrator
279
boolean isAdmin = req.hasPermission("Admin");
280          if (isAdmin)
281          {
282             writer.write("<td width=\"50%\" align=\"center\" class=\"portlet-menu-item\">");
283
284             // Create a link to the administration interface
285
PortletURL adminURL = resp.createRenderURL();
286             adminURL.setParameter("op", "" + OP_SHOWADMINFORUMS);
287             adminURL.setWindowState(WindowState.MAXIMIZED);
288             writer.write("<a HREF=\"" + adminURL.toString() + "\">"
289                + "<img border=\"0\" SRC=\"" + req.getContextPath() + "/subSilver/images/icon_forums_admin.gif\"><br>"
290                + bundle.getString("Admin_panel") + "</a>");
291             writer.write("</td>");
292             writer.write("<td width=\"50%\" align=\"center\" class=\"portlet-menu-item\">");
293          }
294          else
295          {
296             writer.write("<td align=\"center\" class=\"portlet-menu-item\">");
297          }
298
299          //Create a link to the forum index
300
PortletURL showForumsURL = resp.createRenderURL();
301          showForumsURL.setWindowState(WindowState.MAXIMIZED);
302          showForumsURL.setParameter("op", "" + OP_MAIN);
303          writer.write("<a HREF=\"" + showForumsURL.toString() + "\">"
304             + "<img border=\"0\" SRC=\"" + req.getContextPath() + "/subSilver/images/icon_forums.gif" + "\"><br>"
305             + bundle.getString("Main_index") + "</a>");
306          writer.write("</td></tr></table>");
307       }
308       else
309       {
310          DelegateContext root = new DelegateContext();
311          if (req.getUser() != null)
312          {
313             root.next("switch_user_logged_in");
314          }
315
316          req.setAttribute(PortalJsp.CTX_REQUEST, root);
317          PortletRequestDispatcher rdisp = getPortletContext()
318             .getRequestDispatcher("/WEB-INF/subSilver/jsp/small_header.jsp");
319          rdisp.include(req, resp);
320
321          if (OP_MAIN.equals(op))
322          {
323             // Forum index
324
resp.setTitle("Forums");
325             req.setAttribute(PortalJsp.CTX_REQUEST, fillShowIndexContext(req,
326                resp, root));
327
328             boolean isAdmin = req.hasPermission("Admin");
329             if (isAdmin)
330             {
331                // Create a link to the administration interface
332
PortletURL adminURL = resp.createRenderURL();
333                adminURL.setParameter("op", "" + OP_SHOWADMINFORUMS);
334                writer.write("<a id=\"adminPanel\" HREF=\"" + adminURL.toString() + "\">"
335                   + bundle.getString("Admin_panel") + "</a><br/>");
336             }
337
338             PortletRequestDispatcher rd = getPortletContext()
339                .getRequestDispatcher("/WEB-INF/subSilver/jsp/index_body.jsp");
340             rd.include(req, resp);
341          }
342          else if (OP_SHOWFORUM.equals(op))
343          {
344             // Display topics of a forums
345
resp.setTitle("Forums");
346             req.setAttribute(PortalJsp.CTX_REQUEST, fillShowForumContext(req,
347                resp, root));
348             PortletRequestDispatcher rd = getPortletContext()
349                .getRequestDispatcher("/WEB-INF/subSilver/jsp/viewforum_body.jsp");
350             rd.include(req, resp);
351          }
352          else if (OP_POSTING.equals(op))
353          {
354             // Display new post form
355
resp.setTitle("Forums");
356             req.setAttribute(PortalJsp.CTX_REQUEST, fillShowNewTopicContext(req, resp, root));
357             PortletRequestDispatcher rd = getPortletContext()
358                .getRequestDispatcher("/WEB-INF/subSilver/jsp/posting_body.jsp");
359             rd.include(req, resp);
360          }
361          else if (OP_SHOWTOPIC.equals(op))
362          {
363             // Display a topic
364
resp.setTitle("Forums");
365             req.setAttribute(PortalJsp.CTX_REQUEST, fillShowTopicContext(req,
366                resp, root));
367             PortletRequestDispatcher rd = getPortletContext()
368                .getRequestDispatcher("/WEB-INF/subSilver/jsp/viewtopic_body.jsp");
369             rd.include(req, resp);
370          }
371          else if (OP_SHOWADMINFORUMS.equals(op))
372          {
373             // Display administration interface
374
resp.setTitle("Forums");
375             boolean auth = req.hasPermission("Admin");
376             if (auth)
377             {
378                req.setAttribute(PortalJsp.CTX_REQUEST,
379                   fillShowAdminForumsContext(req, resp, root));
380                PortletRequestDispatcher rd = getPortletContext()
381                   .getRequestDispatcher("/WEB-INF/subSilver/jsp/admin/forum_admin_body.jsp");
382                rd.include(req, resp);
383             }
384          }
385          else if (OP_SHOWADDEDITFORUM.equals(op))
386          {
387             // Display new or edit a forum form
388
resp.setTitle("Forums");
389             boolean auth = req.hasPermission("Admin");
390             if (auth)
391             {
392                req.setAttribute(PortalJsp.CTX_REQUEST,
393                   fillShowAddEditForumContext(req, resp, root));
394                PortletRequestDispatcher rd = getPortletContext()
395                   .getRequestDispatcher("/WEB-INF/subSilver/jsp/admin/forum_edit_body.jsp");
396                rd.include(req, resp);
397             }
398          }
399          else if (OP_SHOWDELETEFORUM.equals(op))
400          {
401             // Show form to delete an exisiting forum
402
resp.setTitle("Forums");
403             boolean auth = req.hasPermission("Admin");
404             if (auth)
405             {
406                req.setAttribute(PortalJsp.CTX_REQUEST, root);
407                root.put("NAME", req.getParameter("NAME"));
408                root.put("S_SELECT_TO", req.getParameter("S_SELECT_TO"));
409                root.put("S_HIDDEN_FIELDS", req.getParameter("S_HIDDEN_FIELDS"));
410                PortletURL postURL = resp.createActionURL();
411                root.put("POST_URL", postURL.toString());
412                PortletRequestDispatcher rd = getPortletContext()
413                   .getRequestDispatcher("/WEB-INF/subSilver/jsp/admin/forum_delete_body.jsp");
414                rd.include(req, resp);
415             }
416          }
417          else if (OP_SHOWEDITCATEGORY.equals(op))
418          {
419             // Show form to edit or create a category
420
resp.setTitle("Forums");
421             boolean auth = req.hasPermission("Admin");
422             if (auth)
423             {
424                req.setAttribute(PortalJsp.CTX_REQUEST, root);
425                root.put("CAT_TITLE", req.getParameter("CAT_TITLE"));
426                root.put("S_HIDDEN_FIELDS", req.getParameter("S_HIDDEN_FIELDS"));
427                PortletURL postURL = resp.createActionURL();
428                root.put("POST_URL", postURL.toString());
429                PortletRequestDispatcher rd = getPortletContext()
430                   .getRequestDispatcher("/WEB-INF/subSilver/jsp/admin/category_edit_body.jsp");
431                rd.include(req, resp);
432             }
433          }
434          else if (OP_CONFIRM.equals(op))
435          {
436             // Show form to edit or create a category
437
resp.setTitle("Forums");
438             boolean auth = req.hasPermission("Delete");
439             if (auth)
440             {
441                req.setAttribute(PortalJsp.CTX_REQUEST, root);
442                root.put("MESSAGE_TITLE", req.getParameter("MESSAGE_TITLE"));
443                root.put("MESSAGE_TEXT", req.getParameter("MESSAGE_TEXT"));
444                root.put("S_HIDDEN_FIELDS", req.getParameter("S_HIDDEN_FIELDS"));
445                PortletURL postURL = resp.createActionURL();
446                root.put("POST_URL", postURL.toString());
447                PortletRequestDispatcher rd = getPortletContext()
448                   .getRequestDispatcher("/WEB-INF/subSilver/jsp/confirm_body.jsp");
449                rd.include(req, resp);
450             }
451          }
452          else if (OP_SHOWWATCHEDFORUMS.equals(op))
453          {
454             resp.setTitle("Forums");
455             req.setAttribute(PortalJsp.CTX_REQUEST, fillShowWatchedForums(req,
456                resp, root));
457             PortletRequestDispatcher rd = getPortletContext()
458                .getRequestDispatcher("/WEB-INF/subSilver/jsp/watched_forums_body.jsp");
459             rd.include(req, resp);
460          }
461       }
462
463       writer.write("</div>");
464       writer.close();
465    }
466
467    /**
468     * posting operation
469     *
470     * @param request JBoss action request
471     * @param response JBoss action response
472     * @throws CommandException
473     * @throws CommandException DOCUMENT_ME
474     */

475    public void posting(JBossActionRequest request, JBossActionResponse response)
476       throws CommandException
477    {
478       ResourceBundle JavaDoc bundle = getResourceBundle(request.getLocale());
479
480       Context ctx = new Context();
481       ctx.update(request, response);
482
483       /*
484        // Was cancel pressed? If so then redirect to the appropriate page
485        if (ctx.p_cancel)
486        {
487        if (ctx.p_post_id != -1)
488        {
489        response.sendRedirect("index.html?module=bb&op=viewtopic&p="
490        + ctx.p_post_id + "#" + ctx.p_post_id);
491        }
492        else if (ctx.p_topic_id != -1)
493        {
494        response.sendRedirect("index.html?module=bb&op=viewtopic&t="
495        + ctx.p_topic_id);
496        }
497        else if (ctx.p_forum_id != -1)
498        {
499        response.sendRedirect("index.html?module=bb&op=viewforum&f="
500        + ctx.p_forum_id);
501        }
502        else
503        {
504        response.sendRedirect("index.html?module=bb");
505        }
506        return;
507        }
508        */

509
510       // If the variable mode is empty we don't go farther in the process
511
if (ctx.p_mode == PMODE_NO_MODE)
512       {
513          addErrorMessage(response, "posting",
514             "Unexpected error: No mode defined");
515          return;
516       }
517
518       /*
519        // If the mode is set to topic review then output that review
520        switch (ctx.p_mode)
521        {
522        case PMODE_TOPIC_REVIEW:
523        // display(theme.TPL_THEME_POSTING_TOPIC_REVIEW, topicReview(ctx.p_topic_id), page);
524        return;
525        case PMODE_SMILIES:
526        // generate_smilies('window', PAGE_POSTING);
527        // exit;
528        return;
529        }
530        */

531
532       // Output the confirm message in no confirm variable is found when we delete something
533
if ((((ctx.p_mode == PMODE_EDIT_POST) && ctx.p_poll_delete) || (ctx.p_mode == PMODE_DELETE))
534          && !ctx.p_confirm)
535       {
536          response.setRenderParameter("MESSAGE_TITLE", bundle
537             .getString("Information"));
538          response.setRenderParameter("MESSAGE_TEXT",
539             (ctx.p_mode == PMODE_DELETE) ? bundle
540             .getString("Confirm_delete") : bundle
541             .getString("Confirm_delete_poll"));
542          response
543             .setRenderParameter("S_HIDDEN_FIELDS",
544                "<input type=\"hidden\" name=\"p\" value=\""
545             + ctx.p_post_id
546             + "\"/>"
547             + "<input type=\"hidden\" name=\"module\" value=\"bb\"/>"
548             + "<input type=\"hidden\" name=\"op\" value=\"posting\"/>"
549             + ((ctx.p_mode == PMODE_DELETE) ? "<input type=\"hidden\" name=\"mode\" value=\"delete\"/>"
550             : "<input type=\"hidden\" name=\"mode\" value=\"poll_delete\"/>"));
551
552          // display(theme.TPL_THEME_CONFIRM_BODY, temp, page);
553
response.setRenderParameter("op", OP_CONFIRM);
554          return;
555       }
556
557       // Get user informations
558
User currentUser = request.getUser();
559
560       //
561
Action action = ctx.action(request, response);
562
563       if (action instanceof ProcessCommandAction)
564       {
565          // Get the encapsulated command
566
ForumCommand cmd = ((ProcessCommandAction)action).getCommand();
567
568          // Set the current user on it
569
cmd.setCurrentUser(currentUser);
570
571          // Execute it
572
// Finish the command configuration
573
cmd.setModule(forumsModule);
574
575          // Execute the command
576
Result result = chain.filter(cmd);
577
578          // Switch on the result
579
ResultType type = result.getType();
580
581          /*
582           if (type == CommandConstants.TYPE_ALREADY_VOTED)
583           {
584           // Die.exit(GENERAL_MESSAGE,
585           // "${bb.Already_voted}<br/><br/>${bb.Click_view_message_0}<a HREF=\"index.html?module=bb&op=viewtopic&t=" +
586           // ((VoteTopicCommand)cmd).topic.getId() + "\">${bb.Click_view_message_1}</a>${bb.Click_view_message_2}");
587           }
588           else if (type == CommandConstants.TYPE_CANNOT_INSERT_VOTE)
589           {
590           // Die.rollback(GENERAL_ERROR, "Could not insert user_id for poll");
591           }
592           else if (type == CommandConstants.TYPE_CANNOT_OBTAIN_USER_DATA)
593           {
594           // Die.exit(GENERAL_ERROR, "Could not obtain user vote data for this topic");
595           }
596           else if (type == CommandConstants.TYPE_VOTE_CAST)
597           {
598           // Die.exit(GENERAL_MESSAGE,
599           // "${bb.Vote_cast}<br/><br/>${bb.Click_view_message_0}<a HREF=\"index.html?module=bb&op=viewtopic&t=" +
600           // ((VoteTopicCommand)cmd).topic.getId() + "\">${bb.Click_view_message_1}</a>${bb.Click_view_message_2}");
601           }
602           else if (type == CommandConstants.TYPE_NO_VOTE_OPTION)
603           {
604           // Die.exit(GENERAL_MESSAGE,
605           // "${bb.No_vote_option}<br/><br/>${bb.Click_view_message_0}<a HREF=\"index.html?module=bb&op=viewtopic&t=" +
606           // ((VoteTopicCommand)cmd).topic.getId() + "\">${bb.Click_view_message_1}</a>${bb.Click_view_message_2}");
607           }
608           else if (type == CommandConstants.TYPE_COULD_NOT_OBTAIN_VOTE_DATA)
609           {
610           // Die.exit(GENERAL_ERROR, "Could not obtain vote data for this topic");
611           }
612           else if (type == CommandConstants.TYPE_REDIRECT)
613           {
614           response.sendRedirect("index.html?module=bb&op=viewtopic&t=" + ((VoteTopicCommand) cmd).topic.getId());
615           }
616           else
617           */

618          if (type == CommandConstants.TYPE_ERROR_IN_POSTING)
619          {
620             addErrorMessage(response, "postingfailed", "Error in posting");
621             return;
622          }
623          else if ((type == CommandConstants.TYPE_NEW_TOPIC_POSTED)
624             || (type == CommandConstants.TYPE_EDIT_POST_POSTED)
625             || (type == CommandConstants.TYPE_REPLY_POSTED))
626          {
627             Post post = null;
628             if (cmd instanceof NewTopicCommand)
629             {
630                post = ((NewTopicCommand)cmd).post;
631             }
632             else if (cmd instanceof EditPostCommand)
633             {
634                post = ((EditPostCommand)cmd).post;
635             }
636             else
637             {
638                post = ((ReplyCommand)cmd).newPost;
639             }
640
641             addSuccessMessage(response, "posting", "Stored");
642             return;
643          }
644          else if (type == CommandConstants.TYPE_ERROR_IN_DELETING_POST)
645          {
646             addErrorMessage(response, "posting", "Error in deleting post");
647             return;
648          }
649          else if (type == CommandConstants.TYPE_ERROR_IN_DELETING_POLL)
650          {
651             addErrorMessage(response, "posting", "Error in deleting poll");
652             return;
653          }
654          else if ((type == CommandConstants.TYPE_POLL_DELETED)
655             || (type == CommandConstants.TYPE_POST_DELETED))
656          {
657             // Die.exit(GENERAL_MESSAGE,
658
// "<br/><br/>${bb.Click_return_forum_0}<a HREF=\"index.html?module=bb&op=viewforum&f=" +
659
// cmd.forum.getId() + "\">${bb.Click_return_forum_1}</a>" +
660
// "${bb.Click_return_forum_2}");
661
}
662          else if (type == CommandConstants.TYPE_FORUM_LOCKED)
663          {
664             addErrorMessage(response, "postingfailed", "Forum_locked");
665             return;
666          }
667          else if (type == CommandConstants.TYPE_TOPIC_IS_LOCKED)
668          {
669             addErrorMessage(response, "postingfailed", "Topic_locked");
670             return;
671          }
672          else if (type == CommandConstants.TYPE_NOT_AUTHORIZED)
673          {
674             if (currentUser != null)
675             {
676                // Die.exit(GENERAL_MESSAGE, "${bb." + AUTH_TYPE_TO_MESSAGE[cmd.authType()] + "0}" +
677
// "todo" + // $is_auth[$is_auth_type . "_type"]
678
// "${bb." + AUTH_TYPE_TO_MESSAGE[cmd.authType()] + "1}");
679
return;
680             }
681             else
682             {
683                if (cmd instanceof EditPostCommand)
684                {
685                   // redirect after = index.html?module=bb&op=posting&mode=quote& + POST_POST_URL + = post_id
686
}
687                else if (cmd instanceof NewTopicCommand)
688                {
689                   // redirect after = index.html?module=bb&op=posting&mode=newtopic& + POST_FORUM_URL + = forum_id
690
}
691                else if (cmd instanceof ReplyCommand)
692                {
693                   // if (((ReplyCommand)cmd).quote)
694
// {
695
// // redirect after = index.html?module=bb&op=posting&mode=quote& + POST_POST_URL + = post_id
696
// }
697
// else
698
// {
699
// // beware mode=reply switched from topic to topic.lastPost
700
// // redirect after = index.html?module=bb&op=posting&mode=reply& + POST_TOPIC_URL + = topic_id
701
// }
702
}
703                else
704                {
705                }
706
707                // response.sendRedirect("index.html?module=user&op=getlogin");
708
}
709          }
710          else if (type == CommandConstants.TYPE_CANNOT_XXX_OTHER_POST_WHEN_NOT_MODERATOR)
711          {
712             // Die.exit(GENERAL_MESSAGE, (cmd instanceof DeletePollCommand || cmd instanceof DeletePostCommand) ?
713
// "${bb.Delete_own_posts}" : "${bb.Edit_own_posts}" +
714
// "<br/><br/>${bb.Click_return_topic_0}<a HREF=\"index.html?module=bb&op=viewtopic&t=" +
715
// ((TopicCommand)cmd).topic.getId() +
716
// "\">${bb.Click_return_topic_1}</a>${bb.Click_return_topic_2}");
717
}
718          else if (type == CommandConstants.TYPE_CANNOT_DELETE_REPLIED)
719          {
720             addErrorMessage(response, "postingfailed", "Cannot_delete_replied");
721             return;
722          }
723          else if (type == CommandConstants.TYPE_CANNOT_DELETE_POLL)
724          {
725             addErrorMessage(response, "postingfailed", "Cannot_delete_poll");
726             return;
727          }
728          else if (type == CommandConstants.TYPE_NO_SUCH_POST)
729          {
730             addErrorMessage(response, "postingfailed", "No_such_Post");
731             return;
732          }
733          else if (type == CommandConstants.TYPE_NO_SUCH_TOPIC)
734          {
735             addErrorMessage(response, "postingfailed", "No_topic_id");
736             return;
737          }
738          else if (type == CommandConstants.TYPE_NO_SUCH_FORUM)
739          {
740             addErrorMessage(response, "postingfailed", "Forum_not_exist");
741             return;
742          }
743          else if (type == CommandConstants.TYPE_CANNOT_QUERY)
744          {
745             addErrorMessage(response, "postingfailed",
746                "Could not query forum/topic/post information");
747             return;
748          }
749          else if (type == CommandConstants.TYPE_INVALID_POST_SUBJECT)
750          {
751             addErrorMessage(response, "postingfailed", "Empty_subject");
752             return;
753          }
754          else if (type == CommandConstants.TYPE_INVALID_POST_MESSAGE)
755          {
756             addErrorMessage(response, "postingfailed", "Empty_message");
757             return;
758          }
759          else if (type == CommandConstants.TYPE_TOO_MANY_POLL_OPTION)
760          {
761             addErrorMessage(response, "postingfailed", "To_many_poll_options");
762             return;
763          }
764          else if (type == CommandConstants.TYPE_INVALID_POLL_OPTION)
765          {
766             addErrorMessage(response, "postingfailed", "Empty_poll_option");
767             return;
768          }
769          else if (type == CommandConstants.TYPE_INVALID_POLL_TITLE)
770          {
771             addErrorMessage(response, "postingfailed", "Empty_poll_title");
772             return;
773          }
774          else if (type == CommandConstants.TYPE_TOO_FEW_POLL_OPTION)
775          {
776             addErrorMessage(response, "postingfailed", "To_few_poll_options");
777             return;
778          }
779          else if (type == CommandConstants.TYPE_REPOSTED)
780          {
781             addErrorMessage(response, "postingfailed", "Reposted");
782             return;
783
784             // Die.exit(GENERAL_MESSAGE,
785
// "${bb.Reposted}<br/><br/>" +
786
// "${bb.Click_view_message_0}" +
787
// "<a HREF=\"index.html?module=bb&op=viewtopic&t=" +
788
// ((RepostCommand)cmd).topic.getId() + "\">${bb.Click_view_message_1}</a>${bb.Click_view_message_2}");
789
}
790          else if (type == CommandConstants.TYPE_FLOODING_CANNOT_CREATE)
791          {
792             addErrorMessage(response, "postingfailed", "Flood_Error");
793             return;
794          }
795          else if (type == CommandConstants.TYPE_CANNOT_ADD_ATTACHMENT)
796          {
797             addErrorMessage(response, "postingfailed",
798                "You are not authorized to add an