0001: /*
0002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/MessageWebHandler.java,v 1.103 2007/11/21 08:01:59 minhnn Exp $
0003: * $Author: minhnn $
0004: * $Revision: 1.103 $
0005: * $Date: 2007/11/21 08:01:59 $
0006: *
0007: * ====================================================================
0008: *
0009: * Copyright (C) 2002-2007 by MyVietnam.net
0010: *
0011: * All copyright notices regarding mvnForum MUST remain
0012: * intact in the scripts and in the outputted HTML.
0013: * The "powered by" text/logo with a link back to
0014: * http://www.mvnForum.com and http://www.MyVietnam.net in
0015: * the footer of the pages MUST remain visible when the pages
0016: * are viewed on the internet or intranet.
0017: *
0018: * This program is free software; you can redistribute it and/or modify
0019: * it under the terms of the GNU General Public License as published by
0020: * the Free Software Foundation; either version 2 of the License, or
0021: * any later version.
0022: *
0023: * This program is distributed in the hope that it will be useful,
0024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0026: * GNU General Public License for more details.
0027: *
0028: * You should have received a copy of the GNU General Public License
0029: * along with this program; if not, write to the Free Software
0030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0031: *
0032: * Support can be obtained from support forums at:
0033: * http://www.mvnForum.com/mvnforum/index
0034: *
0035: * Correspondence and Marketing Questions can be sent to:
0036: * info at MyVietnam net
0037: *
0038: * @author: Minh Nguyen
0039: * @author: Mai Nguyen
0040: */
0041: package com.mvnforum.user;
0042:
0043: import java.sql.Timestamp;
0044: import java.util.*;
0045:
0046: import com.mvnforum.*;
0047: import com.mvnforum.auth.*;
0048: import com.mvnforum.common.PrivateMessageUtil;
0049: import com.mvnforum.db.*;
0050: import net.myvietnam.mvncore.exception.*;
0051: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
0052: import net.myvietnam.mvncore.interceptor.InterceptorService;
0053: import net.myvietnam.mvncore.security.FloodControl;
0054: import net.myvietnam.mvncore.security.SecurityUtil;
0055: import net.myvietnam.mvncore.util.*;
0056: import net.myvietnam.mvncore.web.GenericRequest;
0057: import net.myvietnam.mvncore.web.GenericResponse;
0058: import org.apache.commons.logging.Log;
0059: import org.apache.commons.logging.LogFactory;
0060:
0061: public class MessageWebHandler {
0062:
0063: private static Log log = LogFactory.getLog(MessageWebHandler.class);
0064:
0065: private OnlineUserManager onlineUserManager = OnlineUserManager
0066: .getInstance();
0067:
0068: public MessageWebHandler() {
0069: }
0070:
0071: public void prepareAdd(GenericRequest request,
0072: GenericResponse response) throws DatabaseException,
0073: AuthenticationException, BadInputException,
0074: ObjectNotFoundException {
0075:
0076: Locale locale = I18nUtil.getLocaleInRequest(request);
0077:
0078: if (MVNForumConfig.getEnablePrivateMessage() == false) {
0079: String localizedMessage = MVNForumResourceBundle
0080: .getString(locale,
0081: "java.lang.IllegalStateException.private_message_disabled");
0082: throw new IllegalStateException(localizedMessage);
0083: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
0084: }
0085:
0086: MyUtil.saveVNTyperMode(request, response);
0087:
0088: OnlineUser onlineUser = onlineUserManager
0089: .getOnlineUser(request);
0090: MVNForumPermission permission = onlineUser.getPermission();
0091: permission.ensureIsAuthenticated();
0092: permission.ensureCanUseMessage();
0093:
0094: boolean isPreviewing = GenericParamUtil.getParameterBoolean(
0095: request, "preview");
0096: boolean isForward = GenericParamUtil.getParameterBoolean(
0097: request, "forward");
0098:
0099: int parentMessageID = 0;
0100: try {
0101: parentMessageID = GenericParamUtil.getParameterInt(request,
0102: "parent");
0103: } catch (Exception ex) {
0104: // do nothing
0105: // NOTE: we cannot return here since user can have a parameter parent = 0
0106: }
0107:
0108: if (parentMessageID != 0) { // Reply
0109: MessageBean parentMessageBean = null;
0110: try {
0111: parentMessageBean = DAOFactory.getMessageDAO()
0112: .getMessage(parentMessageID);
0113: } catch (ObjectNotFoundException e) {
0114: String localizedMessage = MVNForumResourceBundle
0115: .getString(
0116: locale,
0117: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
0118: new Object[] { new Integer(
0119: parentMessageID) });
0120: throw new ObjectNotFoundException(localizedMessage);
0121: }
0122: if (parentMessageBean.getMemberID() != onlineUser
0123: .getMemberID()) {
0124: String localizedMessage = MVNForumResourceBundle
0125: .getString(locale,
0126: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
0127: throw new BadInputException(localizedMessage);
0128: //throw new BadInputException("This Private Message does not belong to you");
0129: }
0130: request
0131: .setAttribute("ParentMessageBean",
0132: parentMessageBean);
0133:
0134: // We prepare showing attached files (if any), it's used for Forward Method
0135: if (isForward) {
0136: //MessageBean should have AttachBeans value as default
0137: Collection attachBeans = DAOFactory
0138: .getPmAttachmentDAO()
0139: .getPmAttachments_inMessage(parentMessageID);
0140: request.setAttribute("AttachBeans", attachBeans);
0141: }
0142: }
0143:
0144: if (isPreviewing) {
0145:
0146: boolean sendAll = false;
0147: if (MVNForumConfig.getEnablePublicMessage()
0148: && permission.canAdminSystem()) {
0149: sendAll = GenericParamUtil.getParameterBoolean(request,
0150: "sendall");
0151: }
0152:
0153: int logonMemberID = onlineUser.getMemberID();
0154:
0155: String messageToList = GenericParamUtil.getParameterSafe(
0156: request, "MessageToList", !(sendAll));
0157: messageToList = messageToList.replace(',', ';');
0158: messageToList = DisableHtmlTagFilter.filter(messageToList);// always disable HTML
0159:
0160: String messageCcList = GenericParamUtil.getParameterSafe(
0161: request, "MessageCcList", false);
0162: messageCcList = messageCcList.replace(',', ';');
0163: messageCcList = DisableHtmlTagFilter.filter(messageCcList);// always disable HTML
0164:
0165: String messageBccList = GenericParamUtil.getParameterSafe(
0166: request, "MessageBccList", false);
0167: messageBccList = messageBccList.replace(',', ';');
0168: messageBccList = DisableHtmlTagFilter
0169: .filter(messageBccList);// always disable HTML
0170:
0171: GenericParamUtil
0172: .getParameter(request, "MessageTopic", true);
0173: GenericParamUtil.getParameter(request, "message", true);// use message instead of MessageBody
0174:
0175: MemberBean memberBean = null;
0176: try {
0177: memberBean = MemberCache.getInstance().getMember(
0178: logonMemberID);
0179: } catch (ObjectNotFoundException e) {
0180: String localizedMessage = MVNForumResourceBundle
0181: .getString(
0182: locale,
0183: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0184: new Object[] { new Integer(
0185: logonMemberID) });
0186: throw new ObjectNotFoundException(localizedMessage);
0187: }
0188:
0189: String[] receivedMembers = StringUtil.getStringArrays(
0190: messageToList, messageCcList, messageBccList, ";");
0191:
0192: if (sendAll == false) {
0193: if (receivedMembers.length == 0) {
0194: String localizedMessage = MVNForumResourceBundle
0195: .getString(locale,
0196: "java.lang.AssertionError.cannot_send_message.no_receivers");
0197: throw new AssertionError(localizedMessage);
0198: }
0199: MyUtil.checkMembers(receivedMembers, locale);//check to make sure that members are existed
0200: }
0201:
0202: request.setAttribute("MemberBean", memberBean);
0203: }
0204:
0205: }
0206:
0207: public void processAdd(GenericRequest request,
0208: GenericResponse response) throws ObjectNotFoundException,
0209: DatabaseException, CreateException, BadInputException,
0210: ForeignKeyNotFoundException, AuthenticationException,
0211: InterceptorException, FloodException {
0212:
0213: SecurityUtil.checkHttpPostMethod(request);
0214:
0215: Locale locale = I18nUtil.getLocaleInRequest(request);
0216:
0217: if (MVNForumConfig.getEnablePrivateMessage() == false) {
0218: String localizedMessage = MVNForumResourceBundle
0219: .getString(locale,
0220: "java.lang.IllegalStateException.private_message_disabled");
0221: throw new IllegalStateException(localizedMessage);
0222: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
0223: }
0224:
0225: OnlineUser onlineUser = onlineUserManager
0226: .getOnlineUser(request);
0227: MVNForumPermission permission = onlineUser.getPermission();
0228: permission.ensureIsAuthenticated();
0229: permission.ensureCanUseMessage();
0230:
0231: String currentIP = request.getRemoteAddr();
0232: try {
0233: FloodControl.ensureNotReachMaximum(
0234: MVNForumGlobal.FLOOD_ID_NEW_MESSAGE_PER_IP,
0235: currentIP);
0236: } catch (FloodException fe) {
0237: //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.");
0238: Integer maxMessages = new Integer(
0239: FloodControl
0240: .getActionsPerHour(MVNForumGlobal.FLOOD_ID_NEW_MESSAGE_PER_IP));
0241: String localizedMessage = MVNForumResourceBundle
0242: .getString(
0243: locale,
0244: "mvncore.exception.FloodException.send_message_too_many_times",
0245: new Object[] { maxMessages });
0246: throw new FloodException(localizedMessage);
0247: }
0248:
0249: MyUtil.saveVNTyperMode(request, response);
0250:
0251: int logonMemberID = onlineUser.getMemberID();
0252: String memberName = onlineUser.getMemberName();
0253:
0254: boolean sendAll = false;
0255:
0256: if (MVNForumConfig.getEnablePublicMessage()
0257: && permission.canAdminSystem()) {
0258: sendAll = GenericParamUtil.getParameterBoolean(request,
0259: "sendall");
0260: }
0261:
0262: // if messageToList == null permit null value
0263: String messageToList = GenericParamUtil.getParameterSafe(
0264: request, "MessageToList", !(sendAll));
0265: messageToList = messageToList.replace(',', ';');
0266: messageToList = DisableHtmlTagFilter.filter(messageToList);// always disable HTML
0267:
0268: String messageCcList = GenericParamUtil.getParameterSafe(
0269: request, "MessageCcList", false);
0270: messageCcList = messageCcList.replace(',', ';');
0271: messageCcList = DisableHtmlTagFilter.filter(messageCcList);// always disable HTML
0272:
0273: String messageBccList = GenericParamUtil.getParameterSafe(
0274: request, "MessageBccList", false);
0275: messageBccList = messageBccList.replace(',', ';');
0276: messageBccList = DisableHtmlTagFilter.filter(messageBccList);// always disable HTML
0277:
0278: String messageTopic = GenericParamUtil.getParameter(request,
0279: "MessageTopic", true);
0280: messageTopic = DisableHtmlTagFilter.filter(messageTopic);// always disable HTML
0281: messageTopic = InterceptorService.getInstance()
0282: .validateContent(messageTopic);
0283:
0284: String messageBody = GenericParamUtil.getParameter(request,
0285: "message", true);// use message instead of MessageBody
0286: messageBody = DisableHtmlTagFilter.filter(messageBody);// always disable HTML
0287: messageBody = InterceptorService.getInstance().validateContent(
0288: messageBody);
0289:
0290: String messageIcon = GenericParamUtil.getParameter(request,
0291: "MessageIcon");
0292: messageIcon = DisableHtmlTagFilter.filter(messageIcon);// always disable HTML
0293:
0294: if (sendAll) {
0295: messageToList = onlineUser.getMemberName();
0296: messageBccList = "";
0297: messageCcList = "";
0298: }
0299:
0300: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0301: int messageSenderID = logonMemberID;
0302: String messageSenderName = memberName;
0303: String folderName = MVNForumConstant.MESSAGE_FOLDER_INBOX;
0304: // NOTE: in this step, type = quote is not possible since it needs attachment
0305: int messageType = (sendAll) ? MessageBean.MESSAGE_TYPE_PUBLIC
0306: : MessageBean.MESSAGE_TYPE_DEFAULT;
0307: int messageOption = 0;//GenericParamUtil.getParameterInt(request, "MessageOption");
0308: int messageStatus = 0;//GenericParamUtil.getParameterInt(request, "MessageStatus");
0309: int messageReadStatus = MessageBean.MESSAGE_READ_STATUS_DEFAULT;
0310: int messageNotify = 0;//GenericParamUtil.getParameterInt(request, "MessageNotify");
0311: int messageAttachCount = 0;
0312: String messageIP = currentIP;
0313: Timestamp messageCreateDate = now; // Get Current time
0314:
0315: int parentMessageID = 0;
0316:
0317: boolean isDraft = GenericParamUtil.getParameterBoolean(request,
0318: "draft");
0319: boolean isForward = GenericParamUtil.getParameterBoolean(
0320: request, "forward");
0321: boolean attachMore = GenericParamUtil.getParameterBoolean(
0322: request, "AttachMore");
0323: boolean addToSentFolder = GenericParamUtil.getParameterBoolean(
0324: request, "AddToSentFolder");
0325:
0326: String[] receivedMembers = StringUtil.getStringArrays(
0327: messageToList, messageCcList, messageBccList, ";");
0328: if (sendAll == false) {
0329: if (receivedMembers.length == 0) {
0330: String localizedMessage = MVNForumResourceBundle
0331: .getString(locale,
0332: "java.lang.AssertionError.cannot_send_message.no_receivers");
0333: throw new AssertionError(localizedMessage);
0334: }
0335: }
0336:
0337: Hashtable receivers = MyUtil.checkMembers(receivedMembers,
0338: locale);
0339:
0340: if (isForward) {
0341: parentMessageID = GenericParamUtil.getParameterInt(request,
0342: "parent");
0343: }
0344:
0345: Collection attachBeans = null;
0346: if (isForward) {
0347: MessageBean parentMessageBean = null;
0348: try {
0349: parentMessageBean = DAOFactory.getMessageDAO()
0350: .getMessage(parentMessageID);
0351: } catch (ObjectNotFoundException e) {
0352: String localizedMessage = MVNForumResourceBundle
0353: .getString(
0354: locale,
0355: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
0356: new Object[] { new Integer(
0357: parentMessageID) });
0358: throw new ObjectNotFoundException(localizedMessage);
0359: }
0360:
0361: //actually, the jsp does not allow forward a public message
0362: boolean isPublicMessage = false;
0363: if (MVNForumConfig.getEnablePublicMessage()) {
0364: isPublicMessage = (permission.canAdminSystem() && (parentMessageBean
0365: .getMessageType() == MessageBean.MESSAGE_TYPE_PUBLIC));
0366: }
0367:
0368: if ((parentMessageBean.getMemberID() != logonMemberID)
0369: && !isPublicMessage) {
0370: String localizedMessage = MVNForumResourceBundle
0371: .getString(locale,
0372: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
0373: throw new BadInputException(localizedMessage);
0374: //throw new BadInputException("This Private Message does not belong to you");
0375: }
0376: attachBeans = DAOFactory.getPmAttachmentDAO()
0377: .getPmAttachments_inMessage(parentMessageID);
0378: messageAttachCount = attachBeans.size();// in case forward, the attachcount could > 0 so we call this method
0379: } // end forward
0380:
0381: int maxPrivateMessage = MVNForumConfig.getMaxPrivateMessages();
0382: if (isDraft) { // Click to Draft Button
0383: folderName = MVNForumConstant.MESSAGE_FOLDER_DRAFT;
0384: // We will save message to folder Draft with memberID = SenderID
0385: // @todo: in next version: when user click to draft message we will open
0386: // AddMessage window and display all of its previous data
0387:
0388: int senderMessageCount = DAOFactory.getMessageDAO()
0389: .getNumberOfNonPublicMessages_inMember(
0390: logonMemberID);
0391: if (senderMessageCount >= maxPrivateMessage) {
0392: String localizedMessage = MVNForumResourceBundle
0393: .getString(
0394: locale,
0395: "mvncore.exception.BadInputException.over_private_message_quota",
0396: new Object[] { new Integer(
0397: maxPrivateMessage) });
0398: throw new BadInputException(localizedMessage);
0399: //throw new BadInputException("You cannot push the message into the draft folder. You have already use all your private message quota (" + maxFavorites + ").");
0400: }
0401:
0402: int draftMessageID = DAOFactory.getMessageDAO().create(
0403: folderName, messageSenderID, messageSenderID,
0404: messageSenderName, messageToList, messageCcList,
0405: messageBccList, messageTopic, messageBody,
0406: messageType, messageOption, messageStatus,
0407: messageReadStatus, messageNotify, messageIcon,
0408: messageAttachCount, messageIP, messageCreateDate);
0409: if (isForward) {
0410: // We must move PmAttachment from parent to new Message
0411: for (Iterator attachIter = attachBeans.iterator(); attachIter
0412: .hasNext();) {
0413: PmAttachmentBean pmAttachBean = (PmAttachmentBean) attachIter
0414: .next();
0415: try {
0416: DAOFactory.getPmAttachMessageDAO().create(
0417: draftMessageID,
0418: pmAttachBean.getPmAttachID(),
0419: 0/*type*/, 0/*option*/, 0/*status*/);
0420: } catch (DuplicateKeyException ex) {
0421: // this should never happen
0422: AssertionUtil
0423: .doAssert(false,
0424: "DuplicateKeyException when create PmAttachMessage");
0425: }
0426: }
0427: }// end of isForward
0428:
0429: attachMore = false;
0430: } else { // end draft
0431: // click to Send button
0432: // test the receiver's quota
0433: if (attachMore) {
0434:
0435: int senderMessageCount = DAOFactory.getMessageDAO()
0436: .getNumberOfNonPublicMessages_inMember(
0437: logonMemberID);
0438: if (senderMessageCount >= maxPrivateMessage) {
0439: String localizedMessage = MVNForumResourceBundle
0440: .getString(
0441: locale,
0442: "mvncore.exception.BadInputException.over_private_message_quota",
0443: new Object[] { new Integer(
0444: maxPrivateMessage) });
0445: throw new BadInputException(localizedMessage);
0446: //throw new BadInputException("You cannot push the message into the draft folder. You have already use all your private message quota (" + maxFavorites + ").");
0447: }
0448:
0449: folderName = MVNForumConstant.MESSAGE_FOLDER_DRAFT;// it means sending process is not finished
0450: // Create but save it as temporary message in Draft folder
0451: int messageID = DAOFactory.getMessageDAO().create(
0452: folderName, messageSenderID, messageSenderID,
0453: messageSenderName, messageToList,
0454: messageCcList, messageBccList, messageTopic,
0455: messageBody, messageType, messageOption,
0456: messageStatus, messageReadStatus,
0457: messageNotify, messageIcon, messageAttachCount,
0458: messageIP, messageCreateDate);
0459: if (isForward) {
0460: // We must move PmAttachment from parent to new Message
0461: for (Iterator attachIter = attachBeans.iterator(); attachIter
0462: .hasNext();) {
0463: PmAttachmentBean pmAttachBean = (PmAttachmentBean) attachIter
0464: .next();
0465: try {
0466: DAOFactory
0467: .getPmAttachMessageDAO()
0468: .create(
0469: messageID,
0470: pmAttachBean
0471: .getPmAttachID(),
0472: 0/*type*/, 0/*option*/, 0/*status*/);
0473: } catch (DuplicateKeyException ex) {
0474: // this should never happen
0475: AssertionUtil
0476: .doAssert(false,
0477: "DuplicateKeyException when create PmAttachMessage");
0478: }
0479: }
0480: }// end of isForward
0481:
0482: // When attach more, we must put attribute for MessageID
0483: request.setAttribute("MessageID",
0484: new Integer(messageID));
0485: } else { // NO Attachment
0486: // no attachment means we will send this message now
0487: StringBuffer overQuotaReceivers = new StringBuffer(128);
0488: for (Enumeration enumeration = receivers.keys(); enumeration
0489: .hasMoreElements();) {
0490: int receivedMemberID = ((Integer) enumeration
0491: .nextElement()).intValue();
0492: String receivedMemberName = (String) receivers
0493: .get(new Integer(receivedMemberID));
0494:
0495: int receiverMessageCount = DAOFactory
0496: .getMessageDAO()
0497: .getNumberOfNonPublicMessages_inMember(
0498: receivedMemberID);
0499: if (receiverMessageCount >= maxPrivateMessage) {
0500: if (overQuotaReceivers.length() > 0) {
0501: overQuotaReceivers.append(", ");
0502: }
0503: overQuotaReceivers.append(receivedMemberName);
0504: continue;
0505: }
0506:
0507: // We need to get MessageID for attached page
0508: int eachMessageID = DAOFactory.getMessageDAO()
0509: .create(folderName, receivedMemberID,
0510: messageSenderID, messageSenderName,
0511: messageToList, messageCcList,
0512: messageBccList, messageTopic,
0513: messageBody, messageType,
0514: messageOption, messageStatus,
0515: messageReadStatus, messageNotify,
0516: messageIcon, messageAttachCount,
0517: messageIP, messageCreateDate);
0518:
0519: // Add to statistics
0520: if (messageSenderID != receivedMemberID) {
0521: DAOFactory.getMessageStatisticsDAO().create(
0522: messageSenderID, receivedMemberID,
0523: messageCreateDate, messageAttachCount,
0524: messageType, messageOption,
0525: messageStatus);
0526: }
0527:
0528: if (isForward) {
0529: // We must move PmAttachment from parent to new Message
0530: for (Iterator attachIter = attachBeans
0531: .iterator(); attachIter.hasNext();) {
0532: PmAttachmentBean pmAttachBean = (PmAttachmentBean) attachIter
0533: .next();
0534: try {
0535: DAOFactory
0536: .getPmAttachMessageDAO()
0537: .create(
0538: eachMessageID,
0539: pmAttachBean
0540: .getPmAttachID(),
0541: 0/*type*/,
0542: 0/*option*/, 0/*status*/);
0543: } catch (DuplicateKeyException ex) {
0544: // this should never happen
0545: AssertionUtil
0546: .doAssert(false,
0547: "DuplicateKeyException when create PmAttachMessage");
0548: }
0549: }
0550: }// end of isForward
0551: } // end of for on received members
0552: request.setAttribute("OverQuotaReceivers",
0553: overQuotaReceivers.toString());
0554:
0555: // after that, we create another record to save it in Sent. (if user wants)
0556: if (addToSentFolder) {
0557: int senderMessageCount = DAOFactory.getMessageDAO()
0558: .getNumberOfNonPublicMessages_inMember(
0559: logonMemberID);
0560: if (senderMessageCount < maxPrivateMessage) {
0561: folderName = MVNForumConstant.MESSAGE_FOLDER_SENT;
0562: messageType = MessageBean.MESSAGE_TYPE_DEFAULT;// always a default type in the Sent folder
0563: int sentMessageID = DAOFactory.getMessageDAO()
0564: .create(folderName, messageSenderID,
0565: messageSenderID,
0566: messageSenderName,
0567: messageToList, messageCcList,
0568: messageBccList, messageTopic,
0569: messageBody, messageType,
0570: messageOption, messageStatus,
0571: messageReadStatus,
0572: messageNotify, messageIcon,
0573: messageAttachCount, messageIP,
0574: messageCreateDate);
0575: if (isForward) {
0576: // We must move PmAttachment from parent to new Message
0577: for (Iterator attachIter = attachBeans
0578: .iterator(); attachIter.hasNext();) {
0579: PmAttachmentBean pmAttachBean = (PmAttachmentBean) attachIter
0580: .next();
0581: try {
0582: DAOFactory
0583: .getPmAttachMessageDAO()
0584: .create(
0585: sentMessageID,
0586: pmAttachBean
0587: .getPmAttachID(),
0588: 0/*type*/,
0589: 0/*option*/, 0/*status*/);
0590: } catch (DuplicateKeyException ex) {
0591: // this should never happen
0592: AssertionUtil
0593: .doAssert(false,
0594: "DuplicateKeyException when create PmAttachMessage");
0595: }
0596: }
0597: }// end of isForward
0598: } else {
0599: request.setAttribute("AddSentFolderOverQuota",
0600: Boolean.TRUE);
0601: }
0602: }// end of addToSentFolder
0603: }// else of No Attachment
0604: } // end of click to button Send
0605:
0606: request.setAttribute("AttachMore", new Boolean(attachMore));
0607: request.setAttribute("AddToSentFolder", new Boolean(
0608: addToSentFolder));
0609:
0610: FloodControl.increaseCount(
0611: MVNForumGlobal.FLOOD_ID_NEW_MESSAGE_PER_IP, currentIP);
0612: }
0613:
0614: public void prepareViewMessage(GenericRequest request)
0615: throws ObjectNotFoundException, DatabaseException,
0616: BadInputException, AuthenticationException {
0617:
0618: Locale locale = I18nUtil.getLocaleInRequest(request);
0619:
0620: if (MVNForumConfig.getEnablePrivateMessage() == false) {
0621: String localizedMessage = MVNForumResourceBundle
0622: .getString(locale,
0623: "java.lang.IllegalStateException.private_message_disabled");
0624: throw new IllegalStateException(localizedMessage);
0625: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
0626: }
0627:
0628: OnlineUser onlineUser = onlineUserManager
0629: .getOnlineUser(request);
0630: MVNForumPermission permission = onlineUser.getPermission();
0631: permission.ensureIsAuthenticated();
0632: permission.ensureCanUseMessage();
0633:
0634: int logonMemberID = onlineUser.getMemberID();
0635:
0636: int messageID = GenericParamUtil.getParameterInt(request,
0637: "message");
0638:
0639: MessageBean messageBean = null;
0640: try {
0641: messageBean = DAOFactory.getMessageDAO().getMessage(
0642: messageID);
0643: } catch (ObjectNotFoundException e) {
0644: String localizedMessage = MVNForumResourceBundle
0645: .getString(
0646: locale,
0647: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
0648: new Object[] { new Integer(messageID) });
0649: throw new ObjectNotFoundException(localizedMessage);
0650: }
0651:
0652: // Check if this message doesn't belong to current user
0653: boolean isPublicMessage = ((messageBean.getMessageType() == MessageBean.MESSAGE_TYPE_PUBLIC) && MVNForumConfig
0654: .getEnablePublicMessage());
0655: if ((messageBean.getMemberID() != logonMemberID)
0656: && !isPublicMessage) {
0657: String localizedMessage = MVNForumResourceBundle
0658: .getString(locale,
0659: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
0660: throw new BadInputException(localizedMessage);
0661: //throw new BadInputException("This Private Message does not belong to you");
0662: }
0663:
0664: MemberBean memberSenderBean = null;
0665: int messageSenderID = messageBean.getMessageSenderID();
0666: try {
0667: memberSenderBean = MemberCache.getInstance().getMember(
0668: messageSenderID);
0669: } catch (ObjectNotFoundException e) {
0670: // In this case, member has been deleted but his message is still there, so we just ignore
0671: // Note that currently the viewmessage.jsp accept null value of memberSenderBean
0672: }
0673:
0674: if (isPublicMessage) {
0675: DAOFactory.getMessageDAO().updateMessageReadStatus(
0676: messageID, messageBean.getMemberID(),
0677: MessageBean.MESSAGE_READ_STATUS_READ);
0678: } else {// private message
0679: DAOFactory.getMessageDAO().updateMessageReadStatus(
0680: messageID, logonMemberID,
0681: MessageBean.MESSAGE_READ_STATUS_READ);
0682: }
0683:
0684: // We get attachment of this message
0685: Collection attachBeans = DAOFactory.getPmAttachmentDAO()
0686: .getPmAttachments_inMessage(messageID);
0687: messageBean.setAttachmentBeans(attachBeans);
0688:
0689: // always update the number of new private message count in this case
0690: onlineUser.updateNewMessageCount(true);
0691:
0692: request.setAttribute("MessageBean", messageBean);
0693: request.setAttribute("MemberSenderBean", memberSenderBean);
0694: }
0695:
0696: public void prepareList(GenericRequest request)
0697: throws BadInputException, DatabaseException,
0698: ObjectNotFoundException, AuthenticationException {
0699:
0700: Locale locale = I18nUtil.getLocaleInRequest(request);
0701:
0702: if (MVNForumConfig.getEnablePrivateMessage() == false) {
0703: String localizedMessage = MVNForumResourceBundle
0704: .getString(locale,
0705: "java.lang.IllegalStateException.private_message_disabled");
0706: throw new IllegalStateException(localizedMessage);
0707: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
0708: }
0709:
0710: OnlineUser onlineUser = onlineUserManager
0711: .getOnlineUser(request);
0712: MVNForumPermission permission = onlineUser.getPermission();
0713: permission.ensureIsAuthenticated();
0714: permission.ensureCanUseMessage();
0715:
0716: // always update the number of new private message count in this case
0717: onlineUser.updateNewMessageCount(true);
0718:
0719: // @todo: We must check folder to make a correct list
0720: String folderName = GenericParamUtil.getParameter(request,
0721: "folder");
0722: if (folderName.length() == 0) {
0723: folderName = MVNForumConstant.MESSAGE_FOLDER_INBOX; // Default as Inbox
0724: }
0725: StringUtil.checkGoodName(folderName);
0726:
0727: // for sort and order stuff
0728: String sort = GenericParamUtil.getParameter(request, "sort");
0729: String order = GenericParamUtil.getParameter(request, "order");
0730: if (sort.length() == 0)
0731: sort = "MessageCreationDate";
0732: if (order.length() == 0)
0733: order = "DESC";
0734:
0735: //Process of Show Messages of login member
0736: int messagePerPage = onlineUser.getMessagesPerPage();
0737: int offset = 0;
0738: try {
0739: offset = GenericParamUtil.getParameterUnsignedInt(request,
0740: "offset");
0741: } catch (BadInputException ex) {
0742: // do nothing
0743: }
0744: int logonMemberID = onlineUser.getMemberID();
0745:
0746: try {
0747: DAOFactory.getMessageFolderDAO().findByPrimaryKey(
0748: folderName, logonMemberID);
0749: } catch (ObjectNotFoundException onf) {
0750: String localizedMessage = MVNForumResourceBundle
0751: .getString(
0752: locale,
0753: "mvncore.exception.ObjectNotFoundException.messagefolder_not_exists",
0754: new Object[] { folderName });
0755: throw new ObjectNotFoundException(localizedMessage);
0756: }
0757:
0758: int numberOfMessages = DAOFactory.getMessageDAO()
0759: .getNumberOfNonPublicMessages_inMember_inFolder(
0760: logonMemberID, folderName);
0761: if (offset > numberOfMessages) {
0762: String localizedMessage = MVNForumResourceBundle
0763: .getString(locale,
0764: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
0765: throw new BadInputException(localizedMessage);
0766: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
0767: }
0768:
0769: Collection messageBeans = null;
0770: if (folderName
0771: .equalsIgnoreCase(MVNForumConstant.MESSAGE_FOLDER_DRAFT)) {
0772: // also get the draft public messages
0773: messageBeans = DAOFactory
0774: .getMessageDAO()
0775: .getAllMessages_inMember_inFolder_withSortSupport_limit(
0776: logonMemberID, folderName, offset,
0777: messagePerPage, sort, order);
0778: } else {
0779: messageBeans = DAOFactory
0780: .getMessageDAO()
0781: .getNonPublicMessages_inMember_inFolder_withSortSupport_limit(
0782: logonMemberID, folderName, offset,
0783: messagePerPage, sort, order);
0784: }
0785:
0786: Collection messagePublicBeans = null;
0787: if (MVNForumConfig.getEnablePublicMessage()) {
0788: messagePublicBeans = DAOFactory.getMessageDAO()
0789: .getPublicMessages();
0790: }
0791:
0792: // for folder table
0793: Collection messageFolderBeans = DAOFactory
0794: .getMessageFolderDAO().getMessageFolders_inMember(
0795: logonMemberID);
0796: for (Iterator iter = messageFolderBeans.iterator(); iter
0797: .hasNext();) {
0798: MessageFolderBean messageFolder = (MessageFolderBean) iter
0799: .next();
0800: int messageCount;
0801: int unreadMessageCount;
0802: if (messageFolder.getFolderName().equalsIgnoreCase(
0803: MVNForumConstant.MESSAGE_FOLDER_DRAFT)) {
0804: // also get the draft public messages
0805: messageCount = DAOFactory.getMessageDAO()
0806: .getNumberOfAllMessages_inMember_inFolder(
0807: logonMemberID,
0808: messageFolder.getFolderName());
0809: unreadMessageCount = DAOFactory
0810: .getMessageDAO()
0811: .getNumberOfUnreadAllMessages_inMember_inFolder(
0812: logonMemberID,
0813: messageFolder.getFolderName());
0814: } else {
0815: messageCount = DAOFactory
0816: .getMessageDAO()
0817: .getNumberOfNonPublicMessages_inMember_inFolder(
0818: logonMemberID,
0819: messageFolder.getFolderName());
0820: unreadMessageCount = DAOFactory
0821: .getMessageDAO()
0822: .getNumberOfUnreadNonPublicMessages_inMember_inFolder(
0823: logonMemberID,
0824: messageFolder.getFolderName());
0825: }
0826: messageFolder.setMessageCount(messageCount);
0827: messageFolder.setUnreadMessageCount(unreadMessageCount);
0828: } // end for on folders
0829:
0830: // for the quota bar
0831: int max = MVNForumConfig.getMaxPrivateMessages();
0832: int messageCount = DAOFactory.getMessageDAO()
0833: .getNumberOfNonPublicMessages_inMember(logonMemberID);
0834: double ratio = 0;
0835: if (max == 0) {
0836: ratio = 1.0;
0837: } else {
0838: ratio = (double) messageCount / max;
0839: }
0840: // for the quota bar
0841:
0842: request.setAttribute("QuotaRatio", new Double(ratio * 100));
0843: request.setAttribute("MessagePublicBeans", messagePublicBeans);
0844: request.setAttribute("MessageFolderBeans", messageFolderBeans);
0845: request.setAttribute("MessageBeans", messageBeans);
0846: request.setAttribute("TotalMessages", new Integer(
0847: numberOfMessages));
0848: }
0849:
0850: public void processMessage(GenericRequest request)
0851: throws ObjectNotFoundException, DatabaseException,
0852: BadInputException, AuthenticationException {
0853:
0854: SecurityUtil.checkHttpPostMethod(request);
0855:
0856: Locale locale = I18nUtil.getLocaleInRequest(request);
0857:
0858: if (MVNForumConfig.getEnablePrivateMessage() == false) {
0859: String localizedMessage = MVNForumResourceBundle
0860: .getString(locale,
0861: "java.lang.IllegalStateException.private_message_disabled");
0862: throw new IllegalStateException(localizedMessage);
0863: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
0864: }
0865:
0866: OnlineUser onlineUser = onlineUserManager
0867: .getOnlineUser(request);
0868: MVNForumPermission permission = onlineUser.getPermission();
0869: permission.ensureIsAuthenticated();
0870: permission.ensureCanUseMessage();
0871:
0872: String btnDelete = request.getParameter("btnDelete");
0873: String btnUnreadMark = request.getParameter("btnUnreadMark");
0874: String btnMoveFolder = request.getParameter("btnMoveFolder");
0875:
0876: int logonMemberID = onlineUser.getMemberID();
0877: int action = 0; // it's better than true-false, expand function later
0878: /*
0879: * action = 1; // Delete action
0880: * action = 2; // Mark unread action
0881: * action = 3; // move to another folder
0882: */
0883: if ((btnDelete != null)) {
0884: action = 1;
0885: } else if (btnUnreadMark != null) {
0886: action = 2;
0887: } else if (btnMoveFolder != null) {
0888: action = 3;
0889: } else {
0890: String localizedMessage = MVNForumResourceBundle
0891: .getString(locale,
0892: "mvncore.exception.BadInputException.cannot_specify_action");
0893: throw new BadInputException(localizedMessage);
0894: //throw new BadInputException("Cannot specify the action");
0895: }
0896:
0897: if (action == 1) {// delete
0898: //log.debug("ListDelete Message:" + btnDelete);
0899: String[] deleteList = request
0900: .getParameterValues("selectedmessage");
0901: for (int i = 0; (deleteList != null)
0902: && (i < deleteList.length); i++) {
0903: int messageID = Integer.parseInt(deleteList[i]);
0904:
0905: MessageBean messageBean = null;
0906: try {
0907: messageBean = DAOFactory.getMessageDAO()
0908: .getMessage(messageID);
0909: } catch (ObjectNotFoundException e) {
0910: String localizedMessage = MVNForumResourceBundle
0911: .getString(
0912: locale,
0913: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
0914: new Object[] { new Integer(
0915: messageID) });
0916: throw new ObjectNotFoundException(localizedMessage);
0917: }
0918:
0919: // Check if this message doesn't belong to current user
0920: if (messageBean.getMessageType() == MessageBean.MESSAGE_TYPE_PUBLIC) {
0921: // this is a public message, only Admin can delete it
0922: AssertionUtil.doAssert(permission.canAdminSystem(),
0923: "Only Admin can delete public message.");
0924: PrivateMessageUtil.deleteMessageInDatabase(
0925: messageID, messageBean.getMemberID());
0926: } else {
0927: // not a public message, only the owner can delete it
0928: if (messageBean.getMemberID() != logonMemberID) {
0929: String localizedMessage = MVNForumResourceBundle
0930: .getString(locale,
0931: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
0932: throw new BadInputException(localizedMessage);
0933: //throw new BadInputException("This Private Message does not belong to you");
0934: }
0935: PrivateMessageUtil.deleteMessageInDatabase(
0936: messageID, logonMemberID);
0937: }
0938: }
0939: request.setAttribute("Status", "Delete");
0940: } else if (action == 2) {// mark as unread
0941: //log.debug("Unread Message:" + btnUnreadMark);
0942: String[] unreadList = request
0943: .getParameterValues("selectedmessage");
0944: for (int i = 0; (unreadList != null)
0945: && (i < unreadList.length); i++) {
0946: int messageID = Integer.parseInt(unreadList[i]);
0947: MessageBean messageBean = null;
0948: try {
0949: messageBean = DAOFactory.getMessageDAO()
0950: .getMessage(messageID);
0951: } catch (ObjectNotFoundException e) {
0952: String localizedMessage = MVNForumResourceBundle
0953: .getString(
0954: locale,
0955: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
0956: new Object[] { new Integer(
0957: messageID) });
0958: throw new ObjectNotFoundException(localizedMessage);
0959: }
0960: if (messageBean.getMessageType() != MessageBean.MESSAGE_TYPE_PUBLIC) {
0961: // not a public message, only the owner can mark as unread it
0962: if (messageBean.getMemberID() != logonMemberID) {
0963: String localizedMessage = MVNForumResourceBundle
0964: .getString(locale,
0965: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
0966: throw new BadInputException(localizedMessage);
0967: //throw new BadInputException("This Private Message does not belong to you");
0968: }
0969: //log.debug("Unread MessageID = " + messageID);
0970: DAOFactory.getMessageDAO().updateMessageReadStatus(
0971: messageID, logonMemberID,
0972: MessageBean.MESSAGE_READ_STATUS_DEFAULT);
0973: }
0974: }
0975: request.setAttribute("Status", "Unread");
0976: } else if (action == 3) { // move to another folder
0977: //log.debug("Move Message:" + btnMoveFolder);
0978: String[] movingList = request
0979: .getParameterValues("selectedmessage");
0980: String destinationFolder = GenericParamUtil
0981: .getParameterSafe(request, "DestinationFolder",
0982: true);
0983: StringUtil.checkGoodName(destinationFolder);
0984:
0985: for (int i = 0; (movingList != null)
0986: && (i < movingList.length); i++) {
0987: int messageID = Integer.parseInt(movingList[i]);
0988: MessageBean messageBean = null;
0989: try {
0990: messageBean = DAOFactory.getMessageDAO()
0991: .getMessage(messageID);
0992: } catch (ObjectNotFoundException e) {
0993: String localizedMessage = MVNForumResourceBundle
0994: .getString(
0995: locale,
0996: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
0997: new Object[] { new Integer(
0998: messageID) });
0999: throw new ObjectNotFoundException(localizedMessage);
1000: }
1001: if (messageBean.getMessageType() != MessageBean.MESSAGE_TYPE_PUBLIC) {
1002: // not a public message, only the owner can move it
1003: if (messageBean.getMemberID() != logonMemberID) {
1004: String localizedMessage = MVNForumResourceBundle
1005: .getString(locale,
1006: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
1007: throw new BadInputException(localizedMessage);
1008: //throw new BadInputException("This Private Message does not belong to you");
1009: }
1010: //log.debug("Move MessageID = " + messageID);
1011: DAOFactory.getMessageDAO()
1012: .updateFolderName(messageID, logonMemberID,
1013: destinationFolder);
1014: }
1015: }
1016: request.setAttribute("Status", "MoveFolder");
1017: }
1018: }
1019:
1020: public void processSendMessage(GenericRequest request)
1021: throws ObjectNotFoundException, DatabaseException,
1022: BadInputException, CreateException,
1023: ForeignKeyNotFoundException, AuthenticationException {
1024:
1025: Locale locale = I18nUtil.getLocaleInRequest(request);
1026:
1027: if (MVNForumConfig.getEnablePrivateMessage() == false) {
1028: String localizedMessage = MVNForumResourceBundle
1029: .getString(locale,
1030: "java.lang.IllegalStateException.private_message_disabled");
1031: throw new IllegalStateException(localizedMessage);
1032: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
1033: }
1034:
1035: OnlineUser onlineUser = onlineUserManager
1036: .getOnlineUser(request);
1037: MVNForumPermission permission = onlineUser.getPermission();
1038: permission.ensureIsAuthenticated();
1039: permission.ensureCanUseMessage();
1040:
1041: int logonMemberID = onlineUser.getMemberID();
1042: int messageID = GenericParamUtil.getParameterInt(request,
1043: "message");
1044:
1045: MessageBean messageBean = null;
1046: try {
1047: messageBean = DAOFactory.getMessageDAO().getMessage(
1048: messageID);
1049: } catch (ObjectNotFoundException e) {
1050: String localizedMessage = MVNForumResourceBundle
1051: .getString(
1052: locale,
1053: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
1054: new Object[] { new Integer(messageID) });
1055: throw new ObjectNotFoundException(localizedMessage);
1056: }
1057:
1058: // Check if this message doesn't belong to current user
1059: if (messageBean.getMemberID() != logonMemberID) {
1060: String localizedMessage = MVNForumResourceBundle
1061: .getString(locale,
1062: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
1063: throw new BadInputException(localizedMessage);
1064: //throw new BadInputException("This Private Message does not belong to you");
1065: }
1066:
1067: if (messageBean.getFolderName().equalsIgnoreCase(
1068: MVNForumConstant.MESSAGE_FOLDER_DRAFT) == false) {
1069: String localizedMessage = MVNForumResourceBundle
1070: .getString(
1071: locale,
1072: "mvncore.exception.BadInputException.cannot_add_attachment.pm_does_not_in_folder_draft");
1073: throw new BadInputException(localizedMessage);
1074: //throw new BadInputException("Cannot add attachment because this Private Message does not in the folder Draft");
1075: }
1076:
1077: // Check if the message is from this logon member
1078: AssertionUtil
1079: .doAssert(
1080: messageBean.getMessageSenderID() == logonMemberID,
1081: "Assertion: The MessageSenderID must equals the current logined user.");
1082: AssertionUtil
1083: .doAssert(messageBean.getMessageSenderName().equals(
1084: onlineUser.getMemberName()),
1085: "Assertion: The MessageSenderName must equals the current logined user.");
1086:
1087: Timestamp now = DateUtil.getCurrentGMTTimestamp();
1088: Collection attachBeans = DAOFactory.getPmAttachmentDAO()
1089: .getPmAttachments_inMessage(messageBean.getMessageID()); //messageBean is original message
1090:
1091: int maxPrivateMessage = MVNForumConfig.getMaxPrivateMessages();
1092:
1093: String[] receivedMembers = StringUtil.getStringArrays(
1094: messageBean.getMessageToList(), messageBean
1095: .getMessageCcList(), messageBean
1096: .getMessageBccList(), ";");
1097: Hashtable receivers = MyUtil.checkMembers(receivedMembers,
1098: locale);
1099:
1100: StringBuffer overQuotaReceivers = new StringBuffer(128);
1101: for (Enumeration enumeration = receivers.keys(); enumeration
1102: .hasMoreElements();) {
1103: int receivedMemberID = ((Integer) enumeration.nextElement())
1104: .intValue();
1105: String receivedMemberName = (String) receivers
1106: .get(new Integer(receivedMemberID));
1107:
1108: int receiverMessageCount = DAOFactory.getMessageDAO()
1109: .getNumberOfNonPublicMessages_inMember(
1110: receivedMemberID);
1111: if (receiverMessageCount >= maxPrivateMessage) {
1112: if (overQuotaReceivers.length() > 0) {
1113: overQuotaReceivers.append(", ");
1114: }
1115: overQuotaReceivers.append(receivedMemberName);
1116: continue;
1117: }
1118:
1119: // Create REAL message for receivers when finish. It means we have new messageID for each new receiver
1120: // We need to get MessageID for attached page
1121: int eachMessageID = DAOFactory.getMessageDAO().create(
1122: MVNForumConstant.MESSAGE_FOLDER_INBOX,
1123: receivedMemberID, logonMemberID,
1124: messageBean.getMessageSenderName(),
1125: messageBean.getMessageToList(),
1126: messageBean.getMessageCcList(),
1127: messageBean.getMessageBccList(),
1128: messageBean.getMessageTopic(),
1129: messageBean.getMessageBody(),
1130: messageBean.getMessageType(),
1131: messageBean.getMessageOption(),
1132: messageBean.getMessageStatus(),
1133: MessageBean.MESSAGE_READ_STATUS_DEFAULT,
1134: messageBean.getMessageNotify(),
1135: messageBean.getMessageIcon(),
1136: messageBean.getMessageAttachCount(),
1137: request.getRemoteAddr(), now);
1138:
1139: // Add to statistics
1140: if (logonMemberID != receivedMemberID) {
1141: DAOFactory.getMessageStatisticsDAO().create(
1142: logonMemberID, receivedMemberID, now,
1143: messageBean.getMessageAttachCount(),
1144: messageBean.getMessageType(),
1145: messageBean.getMessageOption(),
1146: messageBean.getMessageStatus());
1147: }
1148:
1149: // We must create a loop to create Attach for many receivers and many attachments
1150: for (Iterator attachIter = attachBeans.iterator(); attachIter
1151: .hasNext();) {
1152: PmAttachmentBean pmAttachBean = (PmAttachmentBean) attachIter
1153: .next();
1154: try {
1155: DAOFactory.getPmAttachMessageDAO().create(
1156: eachMessageID,
1157: pmAttachBean.getPmAttachID(), 0/*type*/,
1158: 0/*option*/, 0/*status*/);
1159: } catch (DuplicateKeyException ex) {
1160: // this should never happen
1161: AssertionUtil
1162: .doAssert(false,
1163: "DuplicateKeyException when create PmAttachMessage");
1164: }
1165: }
1166: } // end of for on receivers
1167: request.setAttribute("OverQuotaReceivers", overQuotaReceivers
1168: .toString());
1169:
1170: // Now delete the message in the draft
1171: PrivateMessageUtil.deleteMessageInDatabase(messageID,
1172: logonMemberID);
1173:
1174: request.setAttribute("MessageID", new Integer(messageID));
1175: request.setAttribute("AttachMore", new Boolean(false));
1176: request.setAttribute("AddToSentFolder", new Boolean(false));
1177: }
1178:
1179: public void processDelete(GenericRequest request)
1180: throws ObjectNotFoundException, DatabaseException,
1181: BadInputException, AuthenticationException {
1182:
1183: Locale locale = I18nUtil.getLocaleInRequest(request);
1184:
1185: if (MVNForumConfig.getEnablePrivateMessage() == false) {
1186: String localizedMessage = MVNForumResourceBundle
1187: .getString(locale,
1188: "java.lang.IllegalStateException.private_message_disabled");
1189: throw new IllegalStateException(localizedMessage);
1190: //throw new IllegalStateException("Cannot operate with private messages. Because the private message feature is disabled");
1191: }
1192:
1193: OnlineUser onlineUser = onlineUserManager
1194: .getOnlineUser(request);
1195: MVNForumPermission permission = onlineUser.getPermission();
1196: permission.ensureIsAuthenticated();
1197: permission.ensureCanUseMessage();
1198:
1199: int logonMemberID = onlineUser.getMemberID();
1200:
1201: int messageID = GenericParamUtil.getParameterInt(request,
1202: "message");
1203:
1204: MessageBean messageBean = null;
1205: try {
1206: messageBean = DAOFactory.getMessageDAO().getMessage(
1207: messageID);
1208: } catch (ObjectNotFoundException e) {
1209: String localizedMessage = MVNForumResourceBundle
1210: .getString(
1211: locale,
1212: "mvncore.exception.ObjectNotFoundException.messageid_not_exists",
1213: new Object[] { new Integer(messageID) });
1214: throw new ObjectNotFoundException(localizedMessage);
1215: }
1216:
1217: // Check if this message doesn't belong to current user
1218: // Please note that we dont allow to delete public in this case
1219: if (messageBean.getMemberID() != logonMemberID) {
1220: String localizedMessage = MVNForumResourceBundle
1221: .getString(locale,
1222: "mvncore.exception.BadInputException.pm_not_belongs_to_you");
1223: throw new BadInputException(localizedMessage);
1224: //throw new BadInputException("This Private Message does not belong to you");
1225: }
1226:
1227: // Now delete the message
1228: PrivateMessageUtil.deleteMessageInDatabase(messageID,
1229: logonMemberID);
1230:
1231: request.setAttribute("FolderName", messageBean.getFolderName());
1232: }
1233:
1234: }
|