1 41 package com.mvnforum.user; 42 43 import java.io.IOException ; 44 import java.sql.Timestamp ; 45 import java.util.*; 46 47 import com.mvnforum.*; 48 import com.mvnforum.auth.*; 49 import com.mvnforum.common.StatisticsUtil; 50 import com.mvnforum.db.*; 51 import com.mvnforum.search.post.*; 52 import net.myvietnam.mvncore.exception.*; 53 import net.myvietnam.mvncore.filter.DisableHtmlTagFilter; 54 import net.myvietnam.mvncore.interceptor.InterceptorService; 55 import net.myvietnam.mvncore.security.FloodControl; 56 import net.myvietnam.mvncore.util.*; 57 import net.myvietnam.mvncore.web.GenericRequest; 58 import net.myvietnam.mvncore.web.GenericResponse; 59 import org.apache.commons.logging.Log; 60 import org.apache.commons.logging.LogFactory; 61 62 public class PostWebHandler { 63 64 private static Log log = LogFactory.getLog(PostWebHandler.class); 65 66 private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance(); 67 68 public PostWebHandler() { 69 } 70 71 74 public void prepareAdd(GenericRequest request, GenericResponse response) 75 throws ObjectNotFoundException, DatabaseException, BadInputException, AuthenticationException, AssertionException { 76 77 Locale locale = I18nUtil.getLocaleInRequest(request); 78 79 if (MVNForumConfig.getEnableNewPost() == false) { 80 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_create_new_post.new_post_is_disabled"); 81 throw new AssertionException(localizedMessage); 82 } 84 85 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 86 MVNForumPermission permission = onlineUser.getPermission(); 87 88 if (MVNForumConfig.isGuestUserInDatabase() == false) { 89 permission.ensureIsAuthenticated(); 90 } 91 92 request.setAttribute("action", "addnew"); 94 95 int parentPostID = 0; 96 try { 97 parentPostID = GenericParamUtil.getParameterInt(request, "parent"); 99 } catch (Exception ex) { 100 } 103 104 if (parentPostID == 0) { int forumID = GenericParamUtil.getParameterInt(request, "forum"); 106 107 ForumBean forumBean = null; 108 try { 109 forumBean = ForumCache.getInstance().getBean(forumID); 110 } catch (ObjectNotFoundException e) { 111 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 112 throw new ObjectNotFoundException(localizedMessage); 113 } 114 forumBean.ensureNotDisabledForum(); 115 forumBean.ensureNotClosedForum(); 116 forumBean.ensureNotLockedForum(); 117 118 permission.ensureCanAddThread(forumID); 119 } else { PostBean postBean = null; 122 try { 123 postBean = DAOFactory.getPostDAO().getPost(parentPostID); } catch (ObjectNotFoundException ex) { 125 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (parentPostID)}); 126 throw new ObjectNotFoundException(localizedMessage); 127 } 128 129 int forumID = postBean.getForumID(); 131 132 ForumBean forumBean = null; 133 try { 134 forumBean = ForumCache.getInstance().getBean(forumID); 135 } catch (ObjectNotFoundException e) { 136 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 137 throw new ObjectNotFoundException(localizedMessage); 138 } 139 forumBean.ensureNotDisabledForum(); 140 forumBean.ensureNotClosedForum(); 141 forumBean.ensureNotLockedForum(); 142 143 permission.ensureCanAddPost(forumID); 144 145 int threadID = postBean.getThreadID(); 147 148 ThreadBean threadBean = null; 150 try { 151 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 152 } catch ( ObjectNotFoundException ex ) { 153 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 154 throw new ObjectNotFoundException(localizedMessage); 155 } 156 157 threadBean.ensureStatusCanReply(); 158 159 Collection postBeans = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadID, MVNForumConfig.ROWS_IN_LAST_REPLIES); 160 request.setAttribute("ParentPostBean", postBean); 161 request.setAttribute("PostBeans", postBeans); 162 } 163 164 boolean isPreviewing = GenericParamUtil.getParameterBoolean(request, "preview"); 165 if (isPreviewing) { 166 MyUtil.saveVNTyperMode(request, response); 167 168 GenericParamUtil.getParameter(request, "PostTopic", true); 170 GenericParamUtil.getParameter(request, "message", true); MemberBean memberBean = MemberCache.getInstance().getMember_forPublic(onlineUser.getMemberID()); 172 request.setAttribute("MemberBean", memberBean); 173 } 174 } 175 176 public void processAdd(GenericRequest request, GenericResponse response) 177 throws ObjectNotFoundException, AssertionException, DatabaseException, CreateException, 178 BadInputException, ForeignKeyNotFoundException, AuthenticationException, FloodException, InterceptorException { 179 180 Locale locale = I18nUtil.getLocaleInRequest(request); 181 if (MVNForumConfig.getEnableNewPost() == false) { 182 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_create_new_post.new_post_is_disabled"); 183 throw new AssertionException(localizedMessage); 184 } 186 187 String currentIP = request.getRemoteAddr(); 188 try { 189 FloodControl.ensureNotReachMaximum(MVNForumGlobal.FLOOD_ID_NEW_POST, currentIP); 190 } catch (FloodException fe) { 191 Integer maxPosts = new Integer (FloodControl.getActionsPerHour(MVNForumGlobal.FLOOD_ID_NEW_POST)); 193 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.FloodException.add_post_too_many_times", new Object [] {maxPosts}); 194 throw new FloodException(localizedMessage); 195 } 196 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 197 MVNForumPermission permission = onlineUser.getPermission(); 198 199 MyUtil.saveVNTyperMode(request, response); 200 201 int memberID = onlineUser.getMemberID(); 202 String memberName = onlineUser.getMemberName(); 203 204 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 205 206 int parentPostID = GenericParamUtil.getParameterInt(request, "parent"); 207 208 boolean attachMore = GenericParamUtil.getParameterBoolean(request, "AttachMore"); 209 boolean addFavoriteThread = GenericParamUtil.getParameterBoolean(request, "AddFavoriteParentThread"); 210 boolean addWatchThread = GenericParamUtil.getParameterBoolean(request, "AddWatchParentThread"); 211 212 String postTopic = GenericParamUtil.getParameter(request, "PostTopic", true); 213 postTopic = DisableHtmlTagFilter.filter(postTopic); postTopic = InterceptorService.getInstance().validateContent(postTopic); 215 216 String postBody = GenericParamUtil.getParameter(request, "message", true); postBody = DisableHtmlTagFilter.filter(postBody); postBody = InterceptorService.getInstance().validateContent(postBody); 219 220 String postIcon = GenericParamUtil.getParameter(request, "PostIcon"); 221 postIcon = DisableHtmlTagFilter.filter(postIcon); 223 int forumID = 0; 224 int threadID= 0; 225 boolean isPendingThread = false; 226 boolean isForumModerator = false; 227 if (parentPostID == 0) { 229 forumID = GenericParamUtil.getParameterInt(request, "forum"); 230 ForumBean forumBean = null; 231 try { 232 forumBean = ForumCache.getInstance().getBean(forumID); 233 } catch (ObjectNotFoundException e) { 234 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 235 throw new ObjectNotFoundException(localizedMessage); 236 } 237 forumBean.ensureNotDisabledForum(); 238 forumBean.ensureNotClosedForum(); 239 forumBean.ensureNotLockedForum(); 240 241 isForumModerator = permission.canModerateThread(forumID); 243 permission.ensureCanAddThread(forumID); 244 245 String lastPostMemberName = memberName; 246 247 int threadType = GenericParamUtil.getParameterUnsignedInt(request, "ThreadType", ThreadBean.THREAD_TYPE_DEFAULT); 248 if ( threadType > ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT ) { 249 throw new BadInputException("Not support this thread type"); 251 } 252 253 if (threadType == ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT) { 254 permission.ensureCanAdminSystem(); 255 } else if (threadType != ThreadBean.THREAD_TYPE_DEFAULT ) { 257 permission.ensureCanModerateThread(forumID); 258 } 259 260 int threadOption = 0; int threadStatus = ThreadBean.THREAD_STATUS_DEFAULT; 262 263 if (forumBean.shouldModerateThread() && !isForumModerator) { 265 threadStatus = ThreadBean.THREAD_STATUS_DISABLED; 266 isPendingThread = true; 267 } 268 269 int threadHasPoll = 0; int threadDuration = 0; int threadAttachCount = 0; 272 threadID = DAOFactory.getThreadDAO().createThread(forumID, memberName, lastPostMemberName, 273 postTopic, postBody, 0, 274 0, now, now, 275 threadType, threadOption, threadStatus, 276 threadHasPoll, 0, 0, 277 postIcon, threadDuration, threadAttachCount); 278 } else { PostBean parentPostBean = null; 280 try { 281 parentPostBean = DAOFactory.getPostDAO().getPost(parentPostID); } catch (ObjectNotFoundException ex) { 283 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (parentPostID)}); 284 throw new ObjectNotFoundException(localizedMessage); 285 } 286 forumID = parentPostBean.getForumID(); 287 threadID = parentPostBean.getThreadID(); 288 289 ForumBean forumBean = null; 290 try { 291 forumBean = ForumCache.getInstance().getBean(forumID); 292 } catch (ObjectNotFoundException e) { 293 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 294 throw new ObjectNotFoundException(localizedMessage); 295 } 296 forumBean.ensureNotDisabledForum(); 297 forumBean.ensureNotClosedForum(); 298 forumBean.ensureNotLockedForum(); 299 300 isForumModerator = permission.canModerateThread(forumID); 302 permission.ensureCanAddPost(forumID); 303 304 ThreadBean threadBean = null; 306 try { 307 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 308 } catch (ObjectNotFoundException ex ) { 309 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 310 throw new ObjectNotFoundException(localizedMessage); 311 } 312 threadBean.ensureStatusCanReply(); 313 } 314 315 String postCreationIP = currentIP; 317 String postLastEditIP = ""; int postFormatOption = 0; 319 int postOption = 0; 320 int postStatus = PostBean.POST_STATUS_DEFAULT; 321 322 try { 323 if (ForumCache.getInstance().getBean(forumID).shouldModeratePost() && !isForumModerator) { 325 if (parentPostID != 0) { postStatus = PostBean.POST_STATUS_DISABLED; 328 } 329 } 330 } catch (ObjectNotFoundException e) { 331 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 332 throw new ObjectNotFoundException(localizedMessage); 333 } 334 335 int postAttachCount = 0; 336 337 int postID = DAOFactory.getPostDAO().createPost(parentPostID, forumID, threadID, 338 memberID, memberName, "", 339 postTopic, postBody, now, 340 now, postCreationIP, postLastEditIP, 341 0, postFormatOption, postOption, 342 postStatus, postIcon, postAttachCount); 343 344 StatisticsUtil.updateMemberStatistics(memberID); 345 StatisticsUtil.updateForumStatistics(forumID); 346 StatisticsUtil.updateThreadStatistics(threadID); 347 348 349 350 if (addFavoriteThread) { 352 permission.ensureIsAuthenticated(); 353 int currentFavoriteCount = DAOFactory.getFavoriteThreadDAO().getNumberOfFavoriteThreads_inMember(memberID); 356 int maxFavorites = MVNForumConfig.getMaxFavoriteThread(); 357 if (currentFavoriteCount < maxFavorites) { 358 Timestamp favoriteCreationDate = now; 359 int favoriteType = 0; int favoriteOption = 0; int favoriteStatus = 0; 363 permission.ensureCanReadPost(forumID); 365 366 try { 368 DAOFactory.getFavoriteThreadDAO().create(memberID, threadID, forumID, 369 favoriteCreationDate, favoriteType, favoriteOption, 370 favoriteStatus); 371 } catch (DuplicateKeyException ex) { 372 } 374 } 375 } 376 377 if (addWatchThread) { 379 permission.ensureIsAuthenticated(); 380 permission.ensureIsActivated(); 381 if (MVNForumConfig.getEnableWatch() == false) { 382 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_add_watch.watch_is_disabled"); 384 throw new AssertionException(localizedMessage); 385 } 387 388 int watchType = 0; int watchOption = 0; int watchStatus = 0; Timestamp watchCreationDate = now; 392 Timestamp watchLastSentDate = now; 393 Timestamp watchEndDate = now; 395 try { 396 DAOFactory.getWatchDAO().create(memberID, 0, 0, 397 threadID, watchType, watchOption, 398 watchStatus, watchCreationDate, watchLastSentDate, 399 watchEndDate); 400 } catch (DuplicateKeyException ex) { 401 } 403 } 404 405 406 PostCache.getInstance().clear(); 408 ThreadCache.getInstance().clear(); 409 410 PostBean justAddedPostBean = null; 413 try { 414 justAddedPostBean = DAOFactory.getPostDAO().getPost(postID); 415 } catch(ObjectNotFoundException ex) { 416 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 417 throw new ObjectNotFoundException(localizedMessage); 418 } 419 420 PostIndexer.scheduleAddPostTask(justAddedPostBean); 421 422 request.setAttribute("PostBean", justAddedPostBean); 423 request.setAttribute("ForumID", String.valueOf(forumID)); 424 request.setAttribute("ThreadID", String.valueOf(threadID)); 425 request.setAttribute("PostID", String.valueOf(postID)); 426 request.setAttribute("AttachMore", new Boolean (attachMore)); 427 request.setAttribute("AddFavoriteParentThread", new Boolean (addFavoriteThread)); 428 request.setAttribute("AddWatchParentThread", new Boolean (addWatchThread)); 429 request.setAttribute("IsPendingThread", new Boolean (isPendingThread)); 430 431 433 FloodControl.increaseCount(MVNForumGlobal.FLOOD_ID_NEW_POST, currentIP); 434 } 435 436 public void preparePrintPost(GenericRequest request) 437 throws ObjectNotFoundException, DatabaseException, BadInputException, 438 AuthenticationException, AssertionException { 439 440 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 441 MVNForumPermission permission = onlineUser.getPermission(); 442 443 int postID = GenericParamUtil.getParameterInt(request, "post"); 444 Locale locale = I18nUtil.getLocaleInRequest(request); 445 446 PostBean postBean = null; 447 try { 448 postBean = DAOFactory.getPostDAO().getPost(postID); 449 } catch(ObjectNotFoundException ex) { 450 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 451 throw new ObjectNotFoundException(localizedMessage); 452 } 453 int threadID = postBean.getThreadID(); 454 int forumID = postBean.getForumID(); 455 456 try { 457 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 458 } catch (ObjectNotFoundException e) { 459 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 460 throw new ObjectNotFoundException(localizedMessage); 461 } 462 463 permission.ensureCanReadPost(forumID); 464 465 ThreadBean threadBean = null; 467 try { 468 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 469 } catch ( ObjectNotFoundException ex ) { 470 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 471 throw new ObjectNotFoundException(localizedMessage); 472 } 473 474 MemberBean memberBean = null; 475 if (postBean.getMemberID() > 0) { 476 memberBean = DAOFactory.getMemberDAO().getMember_forPublic(postBean.getMemberID()); 477 } 478 postBean.setMemberBean(memberBean); 479 480 int postAttachCount = postBean.getPostAttachCount(); 481 if ( (postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) { 482 Collection attachBeans = DAOFactory.getAttachmentDAO().getAttachments_inPost(postID); 483 int actualAttachCount = attachBeans.size(); 484 485 if (postAttachCount != actualAttachCount) { 487 if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfAttachments_inPost(postID)) { 488 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.serious_error.cannot_process_attachment_count"); 489 throw new AssertionException(localizedMessage); 490 } 492 log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " + postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount); 493 DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount); 494 } 495 if (actualAttachCount > 0) { 496 postBean.setAttachmentBeans(attachBeans); 497 } 498 } 499 500 request.setAttribute("PostBean", postBean); 501 request.setAttribute("ThreadBean", threadBean); 502 } 503 504 508 public void prepareEdit(GenericRequest request) 509 throws ObjectNotFoundException, DatabaseException, BadInputException, AuthenticationException, AssertionException { 510 511 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 512 MVNForumPermission permission = onlineUser.getPermission(); 513 514 permission.ensureIsAuthenticated(); 516 Locale locale = I18nUtil.getLocaleInRequest(request); 517 518 int postID = GenericParamUtil.getParameterInt(request, "post"); 519 PostBean postBean = null; 520 try { 521 postBean = DAOFactory.getPostDAO().getPost(postID); 522 } catch(ObjectNotFoundException ex) { 523 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 524 throw new ObjectNotFoundException(localizedMessage); 525 } 526 int forumID = postBean.getForumID(); 527 528 ForumBean forumBean = null; 529 try { 530 forumBean = ForumCache.getInstance().getBean(forumID); 531 } catch (ObjectNotFoundException e) { 532 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 533 throw new ObjectNotFoundException(localizedMessage); 534 } 535 forumBean.ensureNotDisabledForum(); 536 forumBean.ensureNotLockedForum(); 537 538 int threadID = postBean.getThreadID(); 540 ThreadBean threadBean = null; 541 try { 542 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 543 } catch ( ObjectNotFoundException ex ) { 544 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 545 throw new ObjectNotFoundException(localizedMessage); 546 } 547 threadBean.ensureStatusCanEdit(); 548 549 int logonMemberID = onlineUser.getMemberID(); 550 int authorID = postBean.getMemberID(); 551 552 if (permission.canEditPost(forumID)) { 554 } else if (logonMemberID == authorID) { permission.ensureCanEditOwnPost(forumID); 558 559 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 561 Timestamp postDate = postBean.getPostCreationDate(); 562 int maxDays = MVNForumConfig.getMaxEditDays(); 563 if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) { 564 565 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_edit.post_is_too_old", new Object [] {new Integer (maxDays)}); 566 throw new BadInputException(localizedMessage); 567 } 569 570 if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) { 572 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_edit_your_post.which_is_disabled"); 573 throw new BadInputException(localizedMessage); 574 } 576 } else { permission.ensureCanEditPost(forumID); } 579 580 request.setAttribute("PostToEdit", postBean); 581 request.setAttribute("action", "update"); 582 583 boolean isPreviewing = GenericParamUtil.getParameterBoolean(request, "preview"); 584 if (isPreviewing) { 585 GenericParamUtil.getParameter(request, "PostTopic", true); 587 GenericParamUtil.getParameter(request, "message", true); 589 MemberBean memberBean = MemberCache.getInstance().getMember_forPublic(onlineUser.getMemberID()); 590 request.setAttribute("MemberBean", memberBean); 591 } 592 } 593 594 601 public void processUpdate(GenericRequest request) 602 throws ObjectNotFoundException, BadInputException, DatabaseException, CreateException, 603 ForeignKeyNotFoundException, AuthenticationException, AssertionException, InterceptorException { 604 605 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 606 MVNForumPermission permission = onlineUser.getPermission(); 607 608 permission.ensureIsAuthenticated(); 610 Locale locale = I18nUtil.getLocaleInRequest(request); 611 612 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 613 614 int postID = GenericParamUtil.getParameterInt(request, "post"); 616 PostBean postBean = null; 618 try { 619 postBean = DAOFactory.getPostDAO().getPost(postID); 620 } catch(ObjectNotFoundException ex) { 621 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 622 throw new ObjectNotFoundException(localizedMessage); 623 } 624 int forumID = postBean.getForumID(); 625 int threadID = postBean.getThreadID(); 626 627 ForumBean forumBean = ForumCache.getInstance().getBean(forumID); 628 forumBean.ensureNotDisabledForum(); 629 forumBean.ensureNotLockedForum(); 630 631 ThreadBean threadBean = null; 634 try { 635 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 636 } catch ( ObjectNotFoundException ex ) { 637 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 638 throw new ObjectNotFoundException(localizedMessage); 639 } 640 threadBean.ensureStatusCanEdit(); 641 642 String postTopic = GenericParamUtil.getParameter(request, "PostTopic", true); 643 postTopic = DisableHtmlTagFilter.filter(postTopic); postTopic = InterceptorService.getInstance().validateContent(postTopic); 645 646 String postBody = GenericParamUtil.getParameter(request, "message", true); postBody = DisableHtmlTagFilter.filter(postBody); postBody = InterceptorService.getInstance().validateContent(postBody); 649 650 int logonMemberID = onlineUser.getMemberID(); 651 String logonMemberName = onlineUser.getMemberName(); 652 int authorID = postBean.getMemberID(); 653 654 if (permission.canEditPost(forumID)) { 656 } else if (logonMemberID == authorID) { permission.ensureCanEditOwnPost(forumID); 660 661 Timestamp postDate = postBean.getPostCreationDate(); 663 int maxDays = MVNForumConfig.getMaxEditDays(); 664 if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) { 665 666 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_edit.post_is_too_old", new Object [] {new Integer (maxDays)}); 667 throw new BadInputException(localizedMessage); 668 } 670 671 if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) { 673 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_edit_your_post.which_is_disabled"); 674 throw new BadInputException(localizedMessage); 675 } 677 } else { permission.ensureCanEditPost(forumID); } 680 681 String postLastEditIP = request.getRemoteAddr(); 682 int postFormatOption = 0; int postOption = 0; int postStatus = postBean.getPostStatus(); String postIcon = GenericParamUtil.getParameter(request, "PostIcon"); 686 postIcon = DisableHtmlTagFilter.filter(postIcon); 688 692 693 DAOFactory.getPostDAO().update(postID, logonMemberName, postTopic, postBody, 695 now, postLastEditIP, postFormatOption, 696 postOption, postStatus, postIcon); 697 DAOFactory.getPostDAO().increaseEditCount(postID); 698 699 if (postBean.getParentPostID() == 0) { String threadIcon = postIcon; 701 DAOFactory.getThreadDAO().updateTopic_Body_Icon(threadID, postTopic, postBody, threadIcon); 702 } 703 704 boolean attachMore = GenericParamUtil.getParameterBoolean(request, "AttachMore"); 705 boolean addFavoriteThread = GenericParamUtil.getParameterBoolean(request, "AddFavoriteParentThread"); 706 boolean addWatchThread = GenericParamUtil.getParameterBoolean(request, "AddWatchParentThread"); 707 if (addFavoriteThread) { 709 permission.ensureIsAuthenticated(); 710 int currentFavoriteCount = DAOFactory.getFavoriteThreadDAO().getNumberOfFavoriteThreads_inMember(logonMemberID); 713 int maxFavorites = MVNForumConfig.getMaxFavoriteThread(); 714 if (currentFavoriteCount < maxFavorites) { 715 Timestamp favoriteCreationDate = now; 716 int favoriteType = 0; int favoriteOption = 0; int favoriteStatus = 0; 720 permission.ensureCanReadPost(forumID); 722 723 try { 725 DAOFactory.getFavoriteThreadDAO().create(logonMemberID, threadID, forumID, 726 favoriteCreationDate, favoriteType, favoriteOption, favoriteStatus); 727 } catch (DuplicateKeyException ex) { 728 } 730 } 731 } 732 733 if (addWatchThread) { 735 permission.ensureIsAuthenticated(); 736 permission.ensureIsActivated(); 737 if (MVNForumConfig.getEnableWatch() == false) { 738 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_add_watch.watch_is_disabled"); 740 throw new AssertionException(localizedMessage); 741 } 743 744 int watchType = 0; int watchOption = 0; int watchStatus = 0; Timestamp watchCreationDate = now; 748 Timestamp watchLastSentDate = now; 749 Timestamp watchEndDate = now; 751 try { 752 DAOFactory.getWatchDAO().create(logonMemberID, 0, 0, 753 threadID, watchType, watchOption, 754 watchStatus, watchCreationDate, watchLastSentDate, 755 watchEndDate); 756 } catch (DuplicateKeyException ex) { 757 } 759 } 760 761 request.setAttribute("PostID", String.valueOf(postID)); 762 request.setAttribute("ForumID", String.valueOf(forumID)); 763 request.setAttribute("ThreadID", String.valueOf(threadID)); 764 request.setAttribute("AttachMore", new Boolean (attachMore)); 765 request.setAttribute("PostBean", postBean); 766 767 PostIndexer.scheduleUpdatePostTask(DAOFactory.getPostDAO().getPost(postID)); 770 771 PostCache.getInstance().clear(); 773 ThreadCache.getInstance().clear(); 774 } 775 776 public void prepareDelete(GenericRequest request) 777 throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException { 778 779 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 780 MVNForumPermission permission = onlineUser.getPermission(); 781 782 permission.ensureIsAuthenticated(); 784 Locale locale = I18nUtil.getLocaleInRequest(request); 785 786 int postID = GenericParamUtil.getParameterInt(request, "post"); 788 789 PostBean postBean = null; 790 try { 791 postBean = DAOFactory.getPostDAO().getPost(postID); 792 } catch(ObjectNotFoundException ex) { 793 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 794 throw new ObjectNotFoundException(localizedMessage); 795 } 796 int forumID = postBean.getForumID(); 797 798 try { 799 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 800 } catch (ObjectNotFoundException e) { 801 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 802 throw new ObjectNotFoundException(localizedMessage); 803 } 804 805 806 if (postBean.getParentPostID() == 0) { 807 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_root_post"); 808 throw new BadInputException(localizedMessage); 809 } 811 812 int logonMemberID = onlineUser.getMemberID(); 814 int authorID = postBean.getMemberID(); 815 if (permission.canDeletePost(forumID)) { 816 } else if (logonMemberID == authorID) { Timestamp now = DateUtil.getCurrentGMTTimestamp(); 820 Timestamp postDate = postBean.getPostCreationDate(); 821 int maxDays = MVNForumConfig.getMaxDeleteDays(); 822 if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) { 823 824 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old"); 825 throw new BadInputException(localizedMessage); 826 } 828 829 int threadID = postBean.getThreadID(); 831 Collection postBeans = DAOFactory.getPostDAO().getEnablePosts_inThread_limit(threadID, 0, 10000); 832 boolean foundReply = false; 833 for (Iterator ite = postBeans.iterator(); ite.hasNext(); ) { 834 PostBean tPostBean = (PostBean) ite.next(); 835 if (tPostBean.getParentPostID() == postBean.getPostID()) { 836 foundReply = true; 837 break; 838 } 839 } 840 if (foundReply) { 841 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_post.post_has_reply"); 842 throw new BadInputException(localizedMessage); 843 } 845 846 if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) { 847 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_your_own_post.post_is_in_pending_status"); 848 throw new BadInputException(localizedMessage); 849 } 851 } else { permission.ensureCanDeletePost(forumID); } 854 855 request.setAttribute("PostBean", postBean); 856 } 857 858 public void processDelete(GenericRequest request) 859 throws BadInputException, DatabaseException, AuthenticationException, AssertionException, ObjectNotFoundException { 860 861 Locale locale = I18nUtil.getLocaleInRequest(request); 862 863 int postID = GenericParamUtil.getParameterInt(request, "post"); 865 PostBean postBean = null; 866 try { 867 postBean = DAOFactory.getPostDAO().getPost(postID); 868 } catch(ObjectNotFoundException ex) { 869 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 870 throw new ObjectNotFoundException(localizedMessage); 871 } 872 873 MyUtil.ensureCorrectCurrentPassword(request); 875 876 ForumCache.getInstance().getBean(postBean.getForumID()).ensureNotDisabledForum(); 877 878 deletePost(request, postBean); 880 881 int threadID = postBean.getThreadID(); 882 int forumID = postBean.getForumID(); 883 884 885 StatisticsUtil.updateForumStatistics(forumID); 887 StatisticsUtil.updateThreadStatistics(threadID); 888 889 PostCache.getInstance().clear(); 891 892 request.setAttribute("ForumID", String.valueOf(forumID)); 893 request.setAttribute("ThreadID", String.valueOf(threadID)); 894 } 895 896 private void deletePost(GenericRequest request, PostBean postBean) 898 throws AssertionException, DatabaseException, AuthenticationException, 899 BadInputException, ObjectNotFoundException { 900 901 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 902 MVNForumPermission permission = onlineUser.getPermission(); 903 904 permission.ensureIsAuthenticated(); 906 907 int parentPostID = postBean.getParentPostID(); 908 909 Locale locale = I18nUtil.getLocaleInRequest(request); 910 911 if (parentPostID == 0) { 912 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_root_post"); 913 throw new BadInputException(localizedMessage); 914 } 916 917 int forumID = postBean.getForumID(); 918 919 int logonMemberID = onlineUser.getMemberID(); 921 int authorID = postBean.getMemberID(); 922 if (permission.canDeletePost(forumID)) { 923 } else if (logonMemberID == authorID) { Timestamp now = DateUtil.getCurrentGMTTimestamp(); 927 Timestamp postDate = postBean.getPostCreationDate(); 928 int maxDays = MVNForumConfig.getMaxDeleteDays(); 929 if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) { 930 931 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.post_is_too_old", new Object [] {new Integer (maxDays)}); 932 throw new BadInputException(localizedMessage); 933 } 935 936 int threadID = postBean.getThreadID(); 938 Collection postBeans = DAOFactory.getPostDAO().getEnablePosts_inThread_limit(threadID, 0, 10000); 939 boolean foundReply = false; 940 for (Iterator ite = postBeans.iterator(); ite.hasNext(); ) { 941 PostBean tPostBean = (PostBean) ite.next(); 942 if (tPostBean.getParentPostID() == postBean.getPostID()) { 943 foundReply = true; 944 break; 945 } 946 } 947 if (foundReply) { 948 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_post.post_has_reply"); 949 throw new BadInputException(localizedMessage); 950 } 952 953 if (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED) { 954 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_your_own_post.post_is_in_pending_status"); 955 throw new BadInputException(localizedMessage); 956 } 958 } else { permission.ensureCanDeletePost(forumID); } 961 962 int postID = postBean.getPostID(); 963 964 AttachmentWebHandler.deleteAttachments_inPost(postID); 967 968 DAOFactory.getPostDAO().delete(postID); 970 971 try { 972 DAOFactory.getPostDAO().updateParentPostID(postID, parentPostID); 973 } catch (ObjectNotFoundException ex) { 974 } 976 977 int memberID = postBean.getMemberID(); 978 StatisticsUtil.updateMemberStatistics(memberID); 979 980 PostIndexer.scheduleDeletePostTask(postID, DeletePostIndexTask.OBJECT_TYPE_POST); 982 } 983 984 public void prepareModeratePendingPosts_limit(GenericRequest request) 985 throws AssertionException, DatabaseException, AuthenticationException, BadInputException, 986 DatabaseException, ObjectNotFoundException { 987 988 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 989 MVNForumPermission permission = onlineUser.getPermission(); 990 991 Locale locale = I18nUtil.getLocaleInRequest(request); 992 993 int threadID = GenericParamUtil.getParameterInt(request, "thread"); 994 ThreadBean threadBean = null; 995 try { 996 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 997 } catch ( ObjectNotFoundException ex ) { 998 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 999 throw new ObjectNotFoundException(localizedMessage); 1000 } 1001 int forumID = threadBean.getForumID(); 1002 1003 try { 1004 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 1005 } catch (ObjectNotFoundException e) { 1006 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 1007 throw new ObjectNotFoundException(localizedMessage); 1008 } 1009 1010 int numberOfPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID); 1011 1012 permission.ensureIsAuthenticated(); 1014 1015 permission.ensureCanModerateThread(forumID); 1017 1018 int postsPerPage = 10000; 1019 int offset = 0; 1020 1021 Collection postBeans = DAOFactory.getPostDAO().getDisablePosts_inThread_limit(threadID, offset, postsPerPage); 1022 1023 Iterator iterator = postBeans.iterator(); 1024 while (iterator.hasNext()) { 1025 PostBean postBean = (PostBean) iterator.next(); 1026 1028 MemberBean memberBean = null; 1029 if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) { 1030 memberBean = MemberCache.getInstance().getMember_forPublic(postBean.getMemberID()); 1031 } 1032 postBean.setMemberBean(memberBean); 1033 1034 int postAttachCount = postBean.getPostAttachCount(); 1035 if ((postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) { 1036 int postID = postBean.getPostID(); 1037 Collection attachBeans = DAOFactory.getAttachmentDAO().getAttachments_inPost(postID); 1038 int actualAttachCount = attachBeans.size(); 1039 1040 if (postAttachCount != actualAttachCount) { 1042 if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfAttachments_inPost(postID)) { 1043 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.serious_error.cannot_process_attachment_count"); 1044 throw new AssertionException(localizedMessage); 1045 } 1047 log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " + 1048 postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount); 1049 DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount); 1050 } 1051 if (actualAttachCount > 0) { 1052 postBean.setAttachmentBeans(attachBeans); 1053 } 1054 } 1055 } 1056 1057 PostBean firstPostBean = DAOFactory.getPostDAO().getFirstPost_inThread(threadID); 1058 if (firstPostBean.getMemberID() != 0 && firstPostBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) { 1059 MemberBean memberBean = MemberCache.getInstance().getMember_forPublic(firstPostBean.getMemberID()); 1060 firstPostBean.setMemberBean(memberBean); 1061 } 1062 1063 1064 request.setAttribute("ThreadBean", threadBean); 1065 request.setAttribute("FirstPostBean", firstPostBean); 1066 request.setAttribute("PostBeans", postBeans); 1067 request.setAttribute("NumberOfPosts", new Integer (numberOfPosts)); 1068 } 1069 1070 public void processModeratePendingPosts(GenericRequest request) 1071 throws AssertionException, DatabaseException, AuthenticationException, 1072 BadInputException, DatabaseException, ObjectNotFoundException { 1073 1074 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 1075 MVNForumPermission permission = onlineUser.getPermission(); 1076 Locale locale = I18nUtil.getLocaleInRequest(request); 1077 1078 permission.ensureIsAuthenticated(); 1080 1081 int threadID = -1; 1085 int forumID = -1; 1086 try { 1087 threadID = GenericParamUtil.getParameterInt(request, "thread"); 1088 ThreadBean threadBean = null; 1089 try { 1090 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 1091 } catch ( ObjectNotFoundException ex ) { 1092 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 1093 throw new ObjectNotFoundException(localizedMessage); 1094 } 1095 forumID = threadBean.getForumID(); 1096 permission.ensureCanModerateThread(forumID); 1097 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 1098 } catch (BadInputException ex) { 1099 } 1101 permission.ensureCanModerateThreadInAnyForum(); 1102 1103 try { 1104 String prefix = "modpostaction_"; 1105 for (Enumeration enumeration = request.getParameterNames(); enumeration.hasMoreElements(); ) { 1106 String param = (String ) enumeration.nextElement(); 1107 if (param.startsWith(prefix)) { 1108 String modValue = GenericParamUtil.getParameter(request, param, true); 1109 String strPostID = param.substring(prefix.length()); 1110 int postID = Integer.parseInt(strPostID); 1111 if (modValue.equals("approve")) { 1112 PostBean postBean = null; 1113 try { 1114 postBean = DAOFactory.getPostDAO().getPost(postID); 1115 } catch(ObjectNotFoundException ex) { 1116 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 1117 throw new ObjectNotFoundException(localizedMessage); 1118 } 1119 int currentForumID = postBean.getForumID(); 1120 permission.ensureCanModerateThread(currentForumID); 1121 DAOFactory.getPostDAO().updateStatus(postID, PostBean.POST_STATUS_DEFAULT); 1122 } else if (modValue.equals("delete")) { 1123 PostBean postBean = null; 1124 try { 1125 postBean = DAOFactory.getPostDAO().getPost(postID); 1126 } catch(ObjectNotFoundException ex) { 1127 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object [] {new Integer (postID)}); 1128 throw new ObjectNotFoundException(localizedMessage); 1129 } 1130 deletePost(request, postBean); 1131 } else { 1132 } 1134 } 1135 } 1136 } finally { 1137 if (forumID != -1) { 1139 StatisticsUtil.updateForumStatistics(forumID); 1140 } 1141 1142 if (threadID != -1) { 1144 StatisticsUtil.updateThreadStatistics(threadID); 1145 } 1146 } 1147 1148 PostCache.getInstance().clear(); 1150 ThreadCache.getInstance().clear(); 1151 1152 request.setAttribute("ForumID", String.valueOf(forumID)); 1153 request.setAttribute("ThreadID", String.valueOf(threadID)); 1154 } 1155 1156 1159 public void prepareViewThread(GenericRequest request) 1160 throws DatabaseException, ObjectNotFoundException, BadInputException, AuthenticationException, AssertionException { 1161 1162 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 1163 MVNForumPermission permission = onlineUser.getPermission(); 1164 1165 Locale locale = I18nUtil.getLocaleInRequest(request); 1166 1167 int threadID = GenericParamUtil.getParameterInt(request, "thread"); 1168 boolean printAll = GenericParamUtil.getParameterBoolean(request, "printall"); 1169 ThreadBean threadBean = null; 1170 try { 1171 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 1172 } catch ( ObjectNotFoundException ex ) { 1173 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 1174 throw new ObjectNotFoundException(localizedMessage); 1175 } 1176 int forumID = threadBean.getForumID(); 1177 int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID); 1178 1179 permission.ensureCanReadPost(forumID); 1181 1182 try { 1184 ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum(); 1185 } catch (ObjectNotFoundException e) { 1186 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object [] {new Integer (forumID)}); 1187 throw new ObjectNotFoundException(localizedMessage); 1188 } 1189 1190 if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) { 1192 permission.ensureCanModerateThread(forumID); 1193 } 1194 1195 int postsPerPage = onlineUser.getPostsPerPage(); 1196 int offset = 0; 1197 boolean lastPage = GenericParamUtil.getParameterBoolean(request, "lastpage"); 1198 if (lastPage) { 1199 int pageCount = numberOfPosts / postsPerPage; 1201 int odd = numberOfPosts % postsPerPage; 1202 if (odd > 0) { 1203 pageCount++; 1204 } 1205 if (pageCount < 1) { 1206 pageCount = 1; } 1208 offset = (pageCount-1) * postsPerPage; 1209 } else { 1210 try { 1211 offset = GenericParamUtil.getParameterInt(request, "offset"); 1212 } catch (BadInputException e) { 1213 } 1215 } 1216 if (printAll) { 1217 postsPerPage = 10000; offset = 0; 1219 } 1220 1221 Collection postBeans = PostCache.getInstance().getEnablePosts_inThread_limit(threadID, offset, postsPerPage); 1222 1223 Iterator iterator = postBeans.iterator(); 1224 while(iterator.hasNext()) { 1225 PostBean postBean = (PostBean)iterator.next(); 1226 MemberBean memberBean = null; 1227 if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) { 1228 memberBean = MemberCache.getInstance().getMember_forPublic(postBean.getMemberID()); 1230 } 1231 postBean.setMemberBean(memberBean); 1232 1233 int postAttachCount = postBean.getPostAttachCount(); 1234 if ( (postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) { 1235 int postID = postBean.getPostID(); 1236 Collection attachBeans = DAOFactory.getAttachmentDAO().getAttachments_inPost(postID); 1237 int actualAttachCount = attachBeans.size(); 1238 1239 if (postAttachCount != actualAttachCount) { 1241 if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfAttachments_inPost(postID)) { 1242 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.serious_error.cannot_process_attachment_count"); 1243 throw new AssertionException(localizedMessage); 1244 } 1246 log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " + postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount); 1247 DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount); 1248 } 1249 if (actualAttachCount > 0) { 1250 postBean.setAttachmentBeans(attachBeans); 1251 } 1252 } 1253 } 1254 1255 int previousTopic = ThreadCache.getInstance().getPreviousEnableThread(forumID, threadID); int nextTopic = ThreadCache.getInstance().getNextEnableThread(forumID, threadID); 1260 int pendingPostCount = 0; 1261 if (permission.canModerateThread(forumID)) { 1262 pendingPostCount = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID); 1263 } 1264 1265 DAOFactory.getThreadDAO().increaseViewCount(threadID); 1266 1267 request.setAttribute("ThreadBean", threadBean); 1268 request.setAttribute("PostBeans", postBeans); 1269 request.setAttribute("NumberOfPosts", new Integer (numberOfPosts)); 1270 request.setAttribute("PreviousTopic", new Integer (previousTopic)); 1271 request.setAttribute("NextTopic", new Integer (nextTopic)); 1272 request.setAttribute("PendingPostCount", new Integer (pendingPostCount)); 1273 } 1274 1275 public void prepareSearch(GenericRequest request) 1276 throws AssertionException { 1277 1278 if (!MVNForumConfig.getEnableSearch()) { 1279 Locale locale = I18nUtil.getLocaleInRequest(request); 1280 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.search_disabled"); 1281 throw new AssertionException(localizedMessage); 1282 } 1283 } 1284 1285 public void processSearch(GenericRequest request, GenericResponse response) 1286 throws BadInputException, IOException , DatabaseException, 1287 ObjectNotFoundException, AuthenticationException, AssertionException { 1288 1289 OnlineUser onlineUser = onlineUserManager.getOnlineUser(request); 1290 MVNForumPermission permission = onlineUser.getPermission(); 1291 1292 Locale locale = I18nUtil.getLocaleInRequest(request); 1293 1294 if (!MVNForumConfig.getEnableSearch()) { 1295 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.search_disabled"); 1296 throw new AssertionException(localizedMessage); 1297 } 1298 1299 MyUtil.saveVNTyperMode(request, response); 1300 1301 String memberName = GenericParamUtil.getParameter(request, "member"); 1302 StringUtil.checkGoodName(memberName); 1303 1304 int minAttachmentCount = GenericParamUtil.getParameterInt(request, "minattach", 0); 1305 1306 boolean requireKey = ((memberName.length() == 0) && (minAttachmentCount == 0)); 1308 String key = GenericParamUtil.getParameter(request, "key", requireKey); 1309 1310 int forumID = GenericParamUtil.getParameterInt(request, "forum", 0); int offset = GenericParamUtil.getParameterUnsignedInt(request, "offset", 0); 1312 int rows = GenericParamUtil.getParameterUnsignedInt(request, "rows", 20); 1313 if (rows == 0) { 1314 rows = 20; } 1316 1317 offset = (offset / rows) * rows; 1319 1320 PostSearchQuery query = new PostSearchQuery(); 1321 1322 if (key.length() > 0) { 1323 query.setSearchString(key); 1324 int scopeInPost = GenericParamUtil.getParameterInt(request, "scopeinpost", PostSearchQuery.SEARCH_ONLY_BODY|PostSearchQuery.SEARCH_ONLY_TITLE); 1325 query.setScopeInPost(scopeInPost); 1326 } 1327 1328 if (memberName.length() > 0) { 1329 try { 1330 int memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName); 1331 query.setMemberId(memberID); 1332 } catch(ObjectNotFoundException ex) { 1333 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object [] {memberName}); 1334 throw new ObjectNotFoundException(localizedMessage); 1335 } 1336 } 1337 1338 if (minAttachmentCount > 0) { 1339 query.setMinAttachmentCount(minAttachmentCount); 1340 } 1341 1342 int searchDate = GenericParamUtil.getParameterUnsignedInt(request, "date", PostSearchQuery.SEARCH_ANY_DATE); 1343 int searchBeforeAfter = GenericParamUtil.getParameterInt(request, "beforeafter", PostSearchQuery.SEARCH_NEWER); 1344 1345 if ((searchDate != PostSearchQuery.SEARCH_ANY_DATE) && (searchDate < 365 * 10)) { long deltaTime = DateUtil.DAY * searchDate; 1347 1348 Timestamp now = DateUtil.getCurrentGMTTimestamp(); 1349 Timestamp from = null; 1350 Timestamp to = null; 1351 1352 long currentTime = now.getTime(); 1353 1354 if (searchBeforeAfter == PostSearchQuery.SEARCH_NEWER) { 1355 from = new Timestamp (currentTime - deltaTime); 1356 } else { to = new Timestamp (currentTime - deltaTime); 1358 } 1359 1360 query.setFromDate(from); 1361 query.setToDate(to); 1362 } 1363 1364 if (forumID > 0) { 1365 query.setForumId(forumID); 1366 } else if (forumID < 0) { 1367 query.setForumId(forumID); 1369 } else { 1370 } 1373 1374 query.searchDocuments(offset, rows, permission); 1375 int hitCount = query.getHitCount(); 1376 Collection result = query.getPostResult(); 1377 1378 for (Iterator iter = result.iterator(); iter.hasNext(); ) { 1384 PostBean postBean = (PostBean)iter.next(); 1385 int currentForumID = postBean.getForumID(); 1386 if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) { 1387 iter.remove(); 1388 } else if ( (permission.canReadPost(currentForumID) == false) || 1389 (postBean.getPostStatus() == PostBean.POST_STATUS_DISABLED)) { 1390 iter.remove(); 1391 } 1392 else if (postBean.getParentPostID() == 0) { if (permission.canModerateThread(currentForumID) == false) { 1397 int threadID = postBean.getThreadID(); 1398 ThreadBean threadBean = null; 1399 try { 1400 threadBean = DAOFactory.getThreadDAO().getThread(threadID); 1401 } catch ( ObjectNotFoundException ex ) { 1402 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object [] {new Integer (threadID)}); 1403 throw new ObjectNotFoundException(localizedMessage); 1404 } 1405 if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) { 1406 iter.remove(); 1407 } 1408 } 1409 } 1410 } 1411 1412 if (offset > hitCount) { 1413 String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows"); 1414 throw new BadInputException(localizedMessage); 1415 } 1417 1418 request.setAttribute("rows", new Integer (rows)); 1424 request.setAttribute("TotalPosts", new Integer (hitCount)); 1425 request.setAttribute("PostBeans", result); 1426 request.setAttribute("SearchQuery", query); 1427 } 1428 1429} 1430 | Popular Tags |