1 11 package org.jboss.portlet.forums; 12 13 import org.jboss.portal.core.modules.ModuleException; 14 import org.jboss.portlet.JBossActionRequest; 15 import org.jboss.portlet.JBossActionResponse; 16 import org.jboss.portlet.forums.action.*; 17 import org.jboss.portlet.forums.commands.post.*; 18 import org.jboss.portlet.forums.impl.ForumsModuleImpl; 19 import org.jboss.portlet.forums.impl.MessageImpl; 20 import org.jboss.portlet.forums.impl.PollImpl; 21 import org.jboss.portlet.forums.impl.PosterImpl; 22 import org.jboss.portlet.forums.model.Message; 23 import org.jboss.portlet.forums.model.Poll; 24 import org.jboss.portlet.forums.model.Poster; 25 26 import java.util.ArrayList ; 27 import java.util.Date ; 28 import java.util.LinkedList ; 29 30 35 public class Context 36 { 37 39 42 public boolean p_submit; 43 44 47 public boolean p_confirm; 48 49 52 public boolean p_preview; 53 54 58 public boolean p_attach; 59 60 64 public boolean p_attach_box; 65 66 70 public boolean p_posted_attach; 71 72 75 public int p_mode; 76 77 80 public int p_forum_id; 81 82 85 public int p_topic_id; 86 87 90 public int p_post_id; 91 92 95 public int p_topic_type; 96 97 100 public boolean p_cancel; 101 102 105 public boolean p_notify; 106 107 110 public int p_vote_option_id; 111 112 115 public boolean p_poll_delete; 116 117 120 public Poll p_poll; 121 122 125 public Message p_message; 126 127 130 public Poster p_poster; 131 132 135 public ArrayList p_deleted_attachments = new ArrayList (); 136 137 140 public ArrayList p_session_attachments = new ArrayList (); 141 142 145 boolean c_refresh; 146 147 150 ForumsModule forumsModule; 151 152 155 public Context() 156 { 157 forumsModule = new ForumsModuleImpl(); 158 } 159 160 166 public void update(JBossActionRequest req, 167 JBossActionResponse resp) 168 { 169 p_mode = ForumsConstants.ModeDecoder.decodePosting(req.getParameter("mode")); 170 171 p_forum_id = req.getParameters().getInt(ForumsConstants.POST_FORUM_URL, -1); 172 p_topic_id = req.getParameters().getInt(ForumsConstants.POST_TOPIC_URL, -1); 173 p_post_id = req.getParameters().getInt(ForumsConstants.POST_POST_URL, -1); 174 p_topic_type = req.getParameters().getInt("topictype", ForumsConstants.POST_NORMAL); 175 p_notify = req.getParameters().getParameterExists("notify"); 176 p_vote_option_id = req.getParameters().getInt("vote_id", -1); 177 178 p_message = new MessageImpl(); 180 p_message.setSubject(req.getParameters().get("subject", "")); 181 p_message.setText(req.getParameters().get("message", "")); 182 p_message.setHTMLEnabled(!req.getParameters().getParameterExists("disable_html")); 183 p_message.setBBCodeEnabled(!req.getParameters().getParameterExists("disable_bbcode")); 184 p_message.setSmiliesEnabled(!req.getParameters().getParameterExists("disable_smilies")); 185 p_message.setSignatureEnabled(req.getParameters().getParameterExists("attach_sig")); 186 187 Integer userID = req.getUser().getID(); 189 try 190 { 191 p_poster = forumsModule.findPosterByUserID(userID); 192 } 193 catch(ModuleException e) 194 { 195 e.printStackTrace(); 197 } 198 199 if(p_poster == null) 200 { 201 p_poster = new PosterImpl(userID); 202 } 203 204 p_poll = new PollImpl(); 206 p_poll.setTitle(req.getParameters().get("poll_title", "")); 207 p_poll.setLength(Math.max(req.getParameters().getInt("poll_length", 0), 208 0)); 209 p_poll.setOptions(new LinkedList ()); 210 211 String p_add_poll_option_text = req.getParameter("add_poll_option_text"); 212 boolean p_poll_add = req.getParameters().getParameterExists("add_poll_option"); 213 boolean p_poll_edit = req.getParameters().getParameterExists("edit_poll_option"); 214 215 boolean option_deleted = false; 216 for(int index = 0; true; index++) 217 { 218 String param = "poll_option_text[" + index + "]"; 219 String value = req.getParameter(param); 220 boolean deleted = req.getParameter("del_poll_option[" + index + "]") != null; 221 option_deleted |= deleted; 222 if(value != null) 223 { 224 p_poll.getOptions().add(deleted ? null : value); 225 } 226 else 227 { 228 break; 229 } 230 } 231 232 if(p_poll_add) 233 { 234 p_poll.getOptions().add(p_add_poll_option_text); 235 } 236 237 boolean toggle_attach_box = req.getParameters().getParameterExists("add_attachment_box"); 243 boolean toggle_posted_attachments = req.getParameters().getParameterExists("posted_attachments"); 244 245 p_poll_delete = req.getParameters().getParameterExists("poll_delete"); 246 p_cancel = req.getParameters().getParameterExists("cancel"); 247 p_submit = req.getParameters().getParameterExists("post"); 248 p_confirm = req.getParameters().getParameterExists("confirm"); 249 p_preview = req.getParameters().getParameterExists("preview"); 250 p_attach_box = toggle_attach_box | req.getParameters().getParameterExists("add_attachment_box_flag"); 251 p_posted_attach = toggle_posted_attachments ^ req.getParameters().getParameterExists("posted_attachments_flag"); 252 p_attach = req.getParameters().getParameterExists("add_attachment"); 253 254 295 296 boolean c_refresh = p_preview; 298 c_refresh |= p_poll_delete; 299 c_refresh |= p_poll_add; 300 c_refresh |= p_poll_edit; 301 c_refresh |= p_attach; 302 c_refresh |= option_deleted; 303 304 c_refresh |= toggle_attach_box; 306 c_refresh |= toggle_posted_attachments; 307 308 this.c_refresh = c_refresh; 309 310 if(((p_mode == ForumsConstants.PMODE_EDIT_POST) || (p_mode == ForumsConstants.PMODE_NEW_TOPIC) 312 || (p_mode == ForumsConstants.PMODE_REPLY)) 313 && (c_refresh || p_submit)) 314 { 315 } 317 else 318 { 319 p_deleted_attachments.clear(); 320 p_session_attachments.clear(); 321 } 322 } 323 324 331 public Action action(JBossActionRequest req, 332 JBossActionResponse resp) 333 { 334 Action action = null; 335 switch(p_mode) 336 { 337 347 case ForumsConstants.PMODE_REPLY: 348 { 349 if(c_refresh) 350 { 351 ReplyAction rra = new ReplyAction(p_post_id, p_message, p_poster, p_session_attachments); 352 rra.setModule(forumsModule); 353 action = rra; 354 } 355 else if(p_submit) 356 { 357 ReplyCommand rc = new ReplyCommand(req, resp); 358 rc.setPoster(p_poster); 359 rc.postId = p_post_id; 360 rc.message = p_message; 361 rc.current_time = new Date (); 362 rc.setModule(forumsModule); 363 action = new ProcessCommandAction(rc); 365 } 366 else 367 { 368 ReplyAction rra = new ReplyAction(false, p_post_id, p_message, p_poster); 369 rra.setModule(forumsModule); 370 action = rra; 371 } 372 373 break; 374 } 375 376 case ForumsConstants.PMODE_QUOTE: 377 { 378 ReplyAction rra = new ReplyAction(true, p_post_id, p_message, p_poster); 379 rra.setModule(forumsModule); 380 action = rra; 381 break; 382 } 383 384 case ForumsConstants.PMODE_EDIT_POST: 385 { 386 if(c_refresh) 387 { 388 EditPostAction epa = 389 new EditPostAction(p_message, p_poster, p_post_id, p_session_attachments, p_poll); 390 epa.setModule(forumsModule); 391 action = epa; 392 } 393 else if(p_submit) 394 { 395 EditPostCommand epc = new EditPostCommand(req, resp); 396 epc.setPoster(p_poster); 397 epc.postId = p_post_id; 398 epc.message = p_message; 399 epc.poll = p_poll; 400 401 epc.topic_type = p_topic_type; 403 epc.current_time = new Date (); 404 epc.poll_delete = p_poll_delete; 405 epc.notify = p_notify; 406 epc.deletedAttachments = 407 (Integer []) p_deleted_attachments.toArray(new Integer [p_deleted_attachments.size()]); 408 action = new ProcessCommandAction(epc); 409 } 410 else 411 { 412 EditPostAction epa = 413 new EditPostAction(p_message, p_poster, p_post_id, p_session_attachments, p_poll); 414 epa.setModule(forumsModule); 415 action = epa; 416 } 417 418 break; 419 } 420 421 case ForumsConstants.PMODE_DELETE: 422 { 423 DeletePostCommand dpc = new DeletePostCommand(req, resp); 424 dpc.setPoster(p_poster); 425 dpc.postId = p_post_id; 426 dpc.setModule(forumsModule); 427 action = new ProcessCommandAction(dpc); 428 break; 429 } 430 431 case ForumsConstants.PMODE_POLL_DELETE: 432 { 433 DeletePollCommand dpc = new DeletePollCommand(req, resp); 434 dpc.setPoster(p_poster); 435 dpc.postId = p_post_id; 436 action = new ProcessCommandAction(dpc); 437 break; 438 } 439 440 case ForumsConstants.PMODE_NEW_TOPIC: 441 { 442 if(c_refresh) 443 { 444 NewTopicAction nta = 445 new NewTopicAction(p_poster, p_message, p_forum_id, p_session_attachments, p_poll); 446 nta.setModule(forumsModule); 447 action = nta; 448 } 449 else if(p_submit) 450 { 451 NewTopicCommand ntc = new NewTopicCommand(req, resp); 452 ntc.setPoster(p_poster); 453 ntc.forumId = p_forum_id; 454 ntc.message = p_message; 455 ntc.poll = p_poll; 456 457 ntc.topic_type = p_topic_type; 459 ntc.current_time = new Date (); 460 ntc.notify = p_notify; 461 ntc.setModule(forumsModule); 462 action = new ProcessCommandAction(ntc); 463 } 464 else 465 { 466 NewTopicAction nta = new NewTopicAction(p_forum_id); 467 nta.setModule(forumsModule); 468 action = nta; 469 } 470 471 break; 472 } 473 474 case ForumsConstants.PMODE_REPOST: 475 { 476 RepostCommand rc = new RepostCommand(req, resp); 477 rc.setPoster(p_poster); 478 rc.postId = p_post_id; 479 action = new ProcessCommandAction(rc); 480 break; 481 } 482 } 483 484 return action; 485 } 486 } | Popular Tags |