📄 messagewebhandler.java
字号:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/MessageWebHandler.java,v 1.91 2006/04/14 17:05:27 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.91 $
* $Date: 2006/04/14 17:05:27 $
*
* ====================================================================
*
* Copyright (C) 2002-2006 by MyVietnam.net
*
* 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 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.
*
* 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 at MyVietnam net
*
* @author: Minh Nguyen
* @author: Mai Nguyen
*/
package com.mvnforum.user;
import java.sql.Timestamp;
import java.util.*;
import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.common.PrivateMessageUtil;
import com.mvnforum.db.*;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.interceptor.InterceptorService;
import net.myvietnam.mvncore.security.FloodControl;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.GenericRequest;
import net.myvietnam.mvncore.web.GenericResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MessageWebHandler {
private static Log log = LogFactory.getLog(MessageWebHandler.class);
private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
public MessageWebHandler() {
}
public void prepareAdd(GenericRequest request, GenericResponse response)
throws AssertionException, DatabaseException, AuthenticationException,
BadInputException, ObjectNotFoundException {
Locale locale = I18nUtil.getLocaleInRequest(request);
if (MVNForumConfig.getEnablePrivateMessage() == false) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.private_message_disabled");
throw new AssertionException(localizedMessage);
//throw new AssertionException("Cannot operate with private messages. Because the private message feature is disabled");
}
MyUtil.saveVNTyperMode(request, response);
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureIsAuthenticated();
permission.ensureCanUseMessage();
boolean isPreviewing = GenericParamUtil.getParameterBoolean(request, "preview");
boolean isForward = GenericParamUtil.getParameterBoolean(request, "forward");
int parentMessageID = 0;
try {
parentMessageID = GenericParamUtil.getParameterInt(request, "parent");
} catch (Exception ex) {
// do nothing
// NOTE: we cannot return here since user can have a parameter parent = 0
}
if (parentMessageID != 0) { // Reply
MessageBean parentMessageBean = null;
try {
parentMessageBean = DAOFactory.getMessageDAO().getMessage(parentMessageID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messageid_not_exists", new Object[] {new Integer(parentMessageID)});
throw new ObjectNotFoundException(localizedMessage);
}
if (parentMessageBean.getMemberID() != onlineUser.getMemberID()) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.pm_not_belongs_to_you");
throw new BadInputException(localizedMessage);
//throw new BadInputException("This Private Message does not belong to you");
}
request.setAttribute("ParentMessageBean", parentMessageBean);
// We prepare showing attached files (if any), it's used for Forward Method
if (isForward) {
//MessageBean should have AttachBeans value as default
Collection attachBeans = DAOFactory.getPmAttachmentDAO().getPmAttachments_inMessage(parentMessageID);
request.setAttribute("AttachBeans", attachBeans);
}
}
if (isPreviewing) {
boolean sendAll = false;
if (MVNForumConfig.getEnablePublicMessage() && permission.canAdminSystem()) {
sendAll = GenericParamUtil.getParameterBoolean(request, "sendall");
}
int logonMemberID = onlineUser.getMemberID();
String messageToList = GenericParamUtil.getParameterSafe(request, "MessageToList", !(sendAll));
messageToList = messageToList.replace(',', ';');
messageToList = DisableHtmlTagFilter.filter(messageToList);// always disable HTML
String messageCcList = GenericParamUtil.getParameterSafe(request, "MessageCcList", false);
messageCcList = messageCcList.replace(',', ';');
messageCcList = DisableHtmlTagFilter.filter(messageCcList);// always disable HTML
String messageBccList = GenericParamUtil.getParameterSafe(request, "MessageBccList", false);
messageBccList = messageBccList.replace(',', ';');
messageBccList = DisableHtmlTagFilter.filter(messageBccList);// always disable HTML
GenericParamUtil.getParameter(request, "MessageTopic", true);
GenericParamUtil.getParameter(request, "message", true);// use message instead of MessageBody
MemberBean memberBean = null;
try {
memberBean = MemberCache.getInstance().getMember_forPublic(logonMemberID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(logonMemberID)});
throw new ObjectNotFoundException(localizedMessage);
}
String[] receivedMembers = StringUtil.getStringArrays(messageToList, messageCcList, messageBccList, ";");
if (sendAll == false) {
if (receivedMembers.length == 0) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_send_message.no_receivers");
throw new AssertionException(localizedMessage);
}
MyUtil.checkMembers(receivedMembers, locale);//check to make sure that members are existed
}
request.setAttribute("MemberBean", memberBean);
}
//Get MemberTutor (only for Netmama's), it uses to check permision for send message
// First, we will check if LoginID is a tutor or Admin
boolean isTutorAdmin = true;
try {
if (MVNForumConfig.getEnableCompany()) {
DAOFactory.getMemberGroupDAO().isTutor(onlineUser.getMemberID());
}
} catch (ObjectNotFoundException ex) {
isTutorAdmin = false;
}
if (permission.canAdminSystem()) { /*This member is an admin*/
isTutorAdmin = true;
}
if ((isTutorAdmin == false) && MVNForumConfig.getEnableCompany()) {
MemberTutorBean memberTutorBean = null;
try {
memberTutorBean = DAOFactory.getMemberTutorDAO().getBean(onlineUser.getMemberID());
} catch (ObjectNotFoundException ex) {
// it means memberTutorBean is null and this user doesn't have tutor
}
request.setAttribute("MemberTutorBean", memberTutorBean);
}
request.setAttribute("IsTutorAdmin", new Boolean(isTutorAdmin));
}
public void processAdd(GenericRequest request, GenericResponse response)
throws ObjectNotFoundException, AssertionException, DatabaseException, CreateException,
BadInputException, ForeignKeyNotFoundException, AuthenticationException, InterceptorException, FloodException {
Locale locale = I18nUtil.getLocaleInRequest(request);
if (MVNForumConfig.getEnablePrivateMessage() == false) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.private_message_disabled");
throw new AssertionException(localizedMessage);
//throw new AssertionException("Cannot operate with private messages. Because the private message feature is disabled");
}
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
MVNForumPermission permission = onlineUser.getPermission();
permission.ensureIsAuthenticated();
permission.ensureCanUseMessage();
String currentIP = request.getRemoteAddr();
try {
FloodControl.ensureNotReachMaximum(MVNForumGlobal.FLOOD_ID_NEW_MESSAGE, currentIP);
} catch (FloodException fe) {
//throw new FloodException("You have reached the maximum number of the private message adding actions for this page. Please try this page later. This is to prevent forum from being flooded.");
Integer maxMessages = new Integer(FloodControl.getActionsPerHour(MVNForumGlobal.FLOOD_ID_NEW_MESSAGE));
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.FloodException.send_message_too_many_times", new Object[] {maxMessages});
throw new FloodException(localizedMessage);
}
MyUtil.saveVNTyperMode(request, response);
int logonMemberID = onlineUser.getMemberID();
String memberName = onlineUser.getMemberName();
boolean sendAll = false;
if (MVNForumConfig.getEnablePublicMessage() && permission.canAdminSystem()) {
sendAll = GenericParamUtil.getParameterBoolean(request, "sendall");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -