|
What this is
Other links
The source code
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumWebHandler.java,v 1.24.2.1 2005/06/17 17:34:56 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.24.2.1 $
* $Date: 2005/06/17 17:34:56 $
*
* ====================================================================
*
* Copyright (C) 2002-2005 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.admin;
import java.sql.Timestamp;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.db.*;
import com.mvnforum.search.post.DeletePostIndexTask;
import com.mvnforum.search.post.PostIndexer;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.util.*;
class ForumWebHandler {
private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
ForumWebHandler() {
}
void processAdd(HttpServletRequest request, HttpServletResponse response)
throws BadInputException, CreateException, DatabaseException, DuplicateKeyException,
ForeignKeyNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureCanAddForum();
MyUtil.saveVNTyperMode(request, response);
Timestamp now = DateUtil.getCurrentGMTTimestamp();
int categoryID = ParamUtil.getParameterInt(request, "CategoryID");
String forumName = ParamUtil.getParameterSafe(request, "ForumName", true);
forumName = DisableHtmlTagFilter.filter(forumName);
String forumDesc = ParamUtil.getParameterSafe(request, "ForumDesc", false);
forumDesc = DisableHtmlTagFilter.filter(forumDesc);
int forumType = ParamUtil.getParameterInt(request, "ForumType");
int forumFormatOption = 0;//@todo review and support it later
int forumOption = 0;//@todo review and support it later
int forumStatus = ParamUtil.getParameterInt(request, "ForumStatus");
int forumModerationMode = ParamUtil.getParameterInt(request, "ForumModerationMode");
String forumPassword = "";//@todo review and support it later
// check valid
ForumBean.validateForumType(forumType);
ForumBean.validateForumFormatOption(forumFormatOption);
ForumBean.validateForumOption(forumOption);
ForumBean.validateForumStatus(forumStatus);
ForumBean.validateForumModerationMode(forumModerationMode);
int forumID = DAOFactory.getForumDAO().createForum(categoryID, ""/*lastPostMemberName*/, forumName,
forumDesc, now/*forumCreationDate*/, now/*forumModifiedDate*/,
now/*forumLastPostDate*/, 0/*forumOrder*/, forumType,
forumFormatOption, forumOption, forumStatus,
forumModerationMode, forumPassword, 0/*forumThreadCount*/,
0/*forumPostCount*/);
// Check if the user created forum should be the owner (ForumAdmin) of that forum
// This is used for KG
if (MVNForumConfig.getEnableAutoForumOwner()) {
int memberID = onlineUser.getMemberID();
DAOFactory.getMemberForumDAO().create(memberID, forumID, MVNForumPermission.PERMISSION_FORUM_ADMIN);
onlineUser.reloadPermission();
}
// For Company, we auto add PERMISSION_NORMAL_USER of the relation of forum and group of this company
try {
int companyID = ParamUtil.getParameterInt(request, "companyid");
CompanyBean companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
int groupID = companyBean.getGroupID();
DAOFactory.getGroupForumDAO().create(groupID, forumID, MVNForumPermission.PERMISSION_NORMAL_USER);
} catch (Exception ex) {
// catch all Exception and just ignore
}
request.setAttribute("ForumName", forumName);
}
void prepareDelete(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int forumID = ParamUtil.getParameterInt(request, "forum");
permission.ensureCanDeleteForum(forumID);
ForumBean forumBean = null;
try {
forumBean = DAOFactory.getForumDAO().getForum(forumID);
} catch (ObjectNotFoundException e) {
Locale locale = I18nUtil.getLocaleInRequest(request);
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
throw new ObjectNotFoundException(localizedMessage);
}
int numberOfThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreads_inForum(forumID);
int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);
int numberOfPendingThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inForum(forumID);
request.setAttribute("ForumBean", forumBean);
request.setAttribute("NumberOfThreads", new Integer(numberOfThreads));
request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
request.setAttribute("NumberOfPendingThreads", new Integer(numberOfPendingThreads));
request.setAttribute("NumberOfPendingPosts", new Integer(numberOfPendingPosts));
}
void processDelete(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int forumID = ParamUtil.getParameterInt(request, "forum");
// user must have been authenticated before he can delete
permission.ensureIsAuthenticated();
permission.ensureCanDeleteForum(forumID);
// now check the password
MyUtil.ensureCorrectCurrentPassword(request);
// Delete all attachments in this forum,
// we must call this before any attempt to delete the post/thread/forum
// That is, the order when delete is VERY IMPORTANT
AttachmentWebHandler.deleteAttachments_inForum(forumID);
DAOFactory.getGroupForumDAO().delete_inForum(forumID);
DAOFactory.getMemberForumDAO().delete_inForum(forumID);
DAOFactory.getFavoriteThreadDAO().delete_inForum(forumID);
DAOFactory.getWatchDAO().delete_inForum(forumID);
DAOFactory.getPostDAO().delete_inForum(forumID);
DAOFactory.getThreadDAO().delete_inForum(forumID);
// now delete the forum, note that we delete it after delete all child objects
DAOFactory.getForumDAO().delete(forumID);
// now update the search index
PostIndexer.scheduleDeletePostTask(forumID, DeletePostIndexTask.OBJECT_TYPE_FORUM);
}
void prepareEdit(HttpServletRequest request)
throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int forumID = ParamUtil.getParameterInt(request, "forum");
permission.ensureCanEditForum(forumID);
ForumBean forumBean = null;
Locale locale = I18nUtil.getLocaleInRequest(request);
try {
forumBean = DAOFactory.getForumDAO().getForum(forumID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
throw new ObjectNotFoundException(localizedMessage);
}
request.setAttribute("ForumBean", forumBean);
}
void processUpdate(HttpServletRequest request, HttpServletResponse response)
throws BadInputException, ObjectNotFoundException, DatabaseException, DuplicateKeyException,
ForeignKeyNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
// primary key column(s)
int forumID = ParamUtil.getParameterInt(request, "ForumID");
permission.ensureCanEditForum(forumID);
MyUtil.saveVNTyperMode(request, response);
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Locale locale = I18nUtil.getLocaleInRequest(request);
// column(s) to update
int categoryID = ParamUtil.getParameterInt(request, "CategoryID");
String forumName = ParamUtil.getParameterSafe(request, "ForumName", true);
forumName = DisableHtmlTagFilter.filter(forumName);
String forumDesc = ParamUtil.getParameterSafe(request, "ForumDesc", false);
forumDesc = DisableHtmlTagFilter.filter(forumDesc);
Timestamp forumModifiedDate = now;
int forumOrder = ParamUtil.getParameterUnsignedInt(request, "ForumOrder");
int forumType = ParamUtil.getParameterInt(request, "ForumType");
int forumFormatOption = 0;//ParamUtil.getParameterInt(request, "ForumFormatOption");
int forumOption = 0;//ParamUtil.getParameterInt(request, "ForumOption");
int forumStatus = ParamUtil.getParameterInt(request, "ForumStatus");
int forumModerationMode = ParamUtil.getParameterInt(request, "ForumModerationMode");
// check valid
ForumBean.validateForumType(forumType);
ForumBean.validateForumFormatOption(forumFormatOption);
ForumBean.validateForumOption(forumOption);
ForumBean.validateForumStatus(forumStatus);
ForumBean.validateForumModerationMode(forumModerationMode);
DAOFactory.getForumDAO().update(forumID, // primary key
categoryID, forumName, forumDesc,
forumModifiedDate, forumOrder, forumType,
forumFormatOption, forumOption, forumStatus,
forumModerationMode);
}
/*
* @todo: check permission
*/
void processUpdateForumOrder(HttpServletRequest request)
throws BadInputException, DatabaseException,
ObjectNotFoundException, AuthenticationException, AssertionException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
Locale locale = I18nUtil.getLocaleInRequest(request);
// primary key column(s)
int forumID = ParamUtil.getParameterInt(request, "forum");
permission.ensureCanEditForum(forumID);
Timestamp now = DateUtil.getCurrentGMTTimestamp();
String action = ParamUtil.getParameterSafe(request, "action", true);
if (action.equals("up")) {
DAOFactory.getForumDAO().decreaseForumOrder(forumID, now);
} else if (action.equals("down")) {
DAOFactory.getForumDAO().increaseForumOrder(forumID, now);
} else {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_update_order.unknown_action", new Object[] {action});
throw new BadInputException(localizedMessage);
//throw new BadInputException("Cannot update ForumOrder: unknown action: " + action);
}
}
void prepareForumManagement(HttpServletRequest request)
throws AssertionException, DatabaseException, AuthenticationException {
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
if ((permission.canEditAnyForum() == false) && (permission.canAddForum() == false)) {
permission.ensureCanEditAnyForum(); // is this the correct permission
permission.ensureCanAddForum();
}
}
}
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.