?? threadwebhandler.java
字號:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ThreadWebHandler.java,v 1.23 2004/05/19 19:11:59 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.23 $
* $Date: 2004/05/19 19:11:59 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 by MyVietnam.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* All copyright notices regarding mvnForum MUST remain intact
* in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in the
* footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
* @author: Mai Nguyen mai.nh@MyVietnam.net
*/
package com.mvnforum.user;
import java.sql.Timestamp;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.common.StatisticsUtil;
import com.mvnforum.db.*;
import com.mvnforum.search.DeletePostIndexTask;
import com.mvnforum.search.PostIndexer;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.util.ParamUtil;
import net.myvietnam.mvncore.exception.ObjectNotFoundException;
import net.myvietnam.mvncore.exception.DatabaseException;
public class ThreadWebHandler {
private static Log log = LogFactory.getLog(ThreadWebHandler.class);
private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
public ThreadWebHandler() {
}
void prepareDelete(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException,
AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int threadID = ParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
// check constraint
int forumID = threadBean.getForumID();
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
int logonMemberID = onlineUser.getMemberID();
String authorName = threadBean.getMemberName();
int authorID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(authorName);
if (permission.canDeletePost(forumID)) {
// have permission, just do nothing, that is dont check the max day contraint
} else if (logonMemberID == authorID) {// same author
// check date here, usually must not older than 7 days
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Timestamp postDate = threadBean.getThreadCreationDate();
int maxDays = MVNForumConfig.getMaxDeleteDays();
if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) {
/** @todo choose a better Exception here */
throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
}
//Check to make sure that "no reply" for this post
if (numberOfPosts > 1) {
throw new BadInputException("Cannot delete a thread that has reply!");
}
/** @todo check status of this thread */
/*
if (postBean.getPostStatus() == ?) {
throw new BadInputException("Cannot delete message which is disable.");
}*/
} else {//not an author, so this user must have Edit Permission
permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
}
int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
request.setAttribute("ThreadBean", threadBean);
request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
request.setAttribute("NumberOfPendingPosts", new Integer(numberOfPendingPosts));
}
void processDelete(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException,
AuthenticationException, AssertionException {
// primary key column(s)
int threadID = ParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
// now check the password
MyUtil.ensureCorrectCurrentPassword(request);
deleteThread(request, threadBean);
//now, update the statistics in the forum and member
int forumID = threadBean.getForumID();
StatisticsUtil.updateForumStatistics(forumID);
request.setAttribute("ForumID", String.valueOf(forumID));
}
// Note that this method does not update the forum statistics
// The caller must call method to update the forum statistics
void deleteThread(HttpServletRequest request, ThreadBean threadBean)
throws BadInputException, ObjectNotFoundException, DatabaseException,
AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// user must have been authenticated before he can delete
permission.ensureIsAuthenticated();
// primary key column(s)
int threadID = threadBean.getThreadID();
// now, check the permission
int forumID = threadBean.getForumID();
int logonMemberID = onlineUser.getMemberID();
String authorName = threadBean.getMemberName();
int authorID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(authorName);
if (permission.canDeletePost(forumID)) {
// have permission, just do nothing, that is dont check the max day contraint
} else if (logonMemberID == authorID) {// same author
// check date here, usually must not older than 7 days
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Timestamp postDate = threadBean.getThreadCreationDate();
int maxDays = MVNForumConfig.getMaxDeleteDays();
if ( (now.getTime() - postDate.getTime()) > (DateUtil.DAY * maxDays) ) {
/** @todo choose a better Exception here */
throw new BadInputException("You cannot delete a post which is older than " + maxDays + " days.");
}
//Check to make sure that "no reply" for this post
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
if (numberOfPosts > 1) {
throw new BadInputException("Cannot delete a thread that has reply!");
}
if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
throw new BadInputException("Cannot delete your own disabled thread.");
}
} else {//not an author, so this user must have Edit Permission
permission.ensureCanDeletePost(forumID);// this method ALWAYS throws AuthenticationException
}
// Delete all attachments in this thread,
// we must call this before any attempt to delete the thread
// That is, the order when delete is VERY IMPORTANT
AttachmentWebHandler.deleteAttachments_inThread(threadID);
DAOFactory.getFavoriteThreadDAO().delete_inThread(threadID);
DAOFactory.getWatchDAO().delete_inThread(threadID);
DAOFactory.getPostDAO().delete_inThread(threadID);
// now delete the thread, note that we delete it after delete all child objects
DAOFactory.getThreadDAO().delete(threadID);
// now update the search index
// @todo : what if the above methods throw exception, then no thread is deleted from index ???
PostIndexer.scheduleDeletePostTask(threadID, DeletePostIndexTask.OBJECT_TYPE_THREAD);
//now, update the statistics in the member
StatisticsUtil.updateMemberStatistics(authorID);
}
void prepareMoveThread(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException,
AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int threadID = ParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
// now, check the permission
// @todo: is it the correct permission ???
permission.ensureCanDeletePost(threadBean.getForumID());
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
request.setAttribute("ThreadBean", threadBean);
request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
}
void processMoveThread(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException,
ForeignKeyNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// user must have been authenticated before he can delete
permission.ensureIsAuthenticated();
// primary key column(s)
int threadID = ParamUtil.getParameterInt(request, "thread");
// now, check the permission
ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
int forumID = threadBean.getForumID();
permission.ensureCanDeletePost(forumID);
ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
// now check the password
MyUtil.ensureCorrectCurrentPassword(request);
int destForumID = ParamUtil.getParameterInt(request, "destforum");
// make sure that we dont move to the same forum (meaningless)
if (destForumID == forumID) {
throw new AssertionException("Cannot move thread to the same forum.");
}
// now make sure that the dest forum is existed
ForumCache.getInstance().getBean(destForumID);
DAOFactory.getThreadDAO().update_ForumID(threadID, destForumID);
DAOFactory.getPostDAO().update_ForumID_inThread(threadID, destForumID);
DAOFactory.getFavoriteThreadDAO().update_ForumID_inThread(threadID, destForumID);
//now, update the statistics in the source forum and dest forum
StatisticsUtil.updateForumStatistics(forumID);
StatisticsUtil.updateForumStatistics(destForumID);
// now update the search index
// @todo : what if the above methods throw exception, then no thread is deleted from index ???
PostIndexer.scheduleUpdateThreadTask(threadID);
request.setAttribute("ForumID", String.valueOf(forumID));
}
void prepareEditThreadStatus(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException,
AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int threadID = ParamUtil.getParameterInt(request, "thread");
ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
ForumCache.getInstance().getBean(threadBean.getForumID()).ensureNotDisabledForum();
// now, check the permission
permission.ensureCanModerateThread(threadBean.getForumID());
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inThread(threadID);
int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inThread(threadID);
request.setAttribute("ThreadBean", threadBean);
request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
request.setAttribute("NumberOfPendingPosts", new Integer(numberOfPendingPosts));
}
void processEditThreadStatus(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException,
ForeignKeyNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -