📄 messagewebhandler.java
字号:
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messageid_not_exists", new Object[] {new Integer(messageID)});
throw new ObjectNotFoundException(localizedMessage);
}
// Check if this message doesn't belong to current user
if (messageBean.getMessageType() == MessageBean.MESSAGE_TYPE_PUBLIC) {
// this is a public message, only Admin can delete it
if (permission.canAdminSystem() == false) {
throw new AssertionException("Only Admin can delete public message.");
}
PrivateMessageUtil.deleteMessageInDatabase(messageID, messageBean.getMemberID());
} else {
// not a public message, only the owner can delete it
if (messageBean.getMemberID() != logonMemberID) {
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");
}
PrivateMessageUtil.deleteMessageInDatabase(messageID, logonMemberID);
}
}
request.setAttribute("Status", "Delete");
} else if (action == 2 ) {// mark as unread
//log.debug("Unread Message:" + btnUnreadMark);
String[] unreadList = request.getParameterValues("selectedmessage");
for (int i = 0; (unreadList != null) && (i < unreadList.length); i++) {
int messageID = Integer.parseInt(unreadList[i]);
MessageBean messageBean = null;
try {
messageBean = DAOFactory.getMessageDAO().getMessage(messageID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messageid_not_exists", new Object[] {new Integer(messageID)});
throw new ObjectNotFoundException(localizedMessage);
}
if (messageBean.getMessageType() != MessageBean.MESSAGE_TYPE_PUBLIC) {
// not a public message, only the owner can mark as unread it
if (messageBean.getMemberID() != logonMemberID) {
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");
}
//log.debug("Unread MessageID = " + messageID);
DAOFactory.getMessageDAO().updateMessageReadStatus(messageID, logonMemberID, MessageBean.MESSAGE_READ_STATUS_DEFAULT);
}
}
request.setAttribute("Status", "Unread");
} else if (action == 3) { // move to another folder
//log.debug("Move Message:" + btnMoveFolder);
String[] movingList = request.getParameterValues("selectedmessage");
String destinationFolder = GenericParamUtil.getParameterSafe(request, "DestinationFolder", true);
StringUtil.checkGoodName(destinationFolder);
for (int i = 0; (movingList != null) && (i < movingList.length); i++) {
int messageID = Integer.parseInt(movingList[i]);
MessageBean messageBean = null;
try {
messageBean = DAOFactory.getMessageDAO().getMessage(messageID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messageid_not_exists", new Object[] {new Integer(messageID)});
throw new ObjectNotFoundException(localizedMessage);
}
if (messageBean.getMessageType() != MessageBean.MESSAGE_TYPE_PUBLIC) {
// not a public message, only the owner can move it
if (messageBean.getMemberID() != logonMemberID) {
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");
}
//log.debug("Move MessageID = " + messageID);
DAOFactory.getMessageDAO().updateFolderName(messageID, logonMemberID, destinationFolder);
}
}
request.setAttribute("Status", "MoveFolder");
}
}
public void processSendMessage(GenericRequest request)
throws ObjectNotFoundException, DatabaseException, BadInputException,
CreateException, ForeignKeyNotFoundException, AuthenticationException, AssertionException {
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();
int logonMemberID = onlineUser.getMemberID();
int messageID = GenericParamUtil.getParameterInt(request, "message");
MessageBean messageBean = null;
try {
messageBean = DAOFactory.getMessageDAO().getMessage(messageID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messageid_not_exists", new Object[] {new Integer(messageID)});
throw new ObjectNotFoundException(localizedMessage);
}
// Check if this message doesn't belong to current user
if (messageBean.getMemberID() != logonMemberID ) {
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");
}
if (messageBean.getFolderName().equalsIgnoreCase(MVNForumConstant.MESSAGE_FOLDER_DRAFT) == false) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_add_attachment.pm_does_not_in_folder_draft");
throw new BadInputException(localizedMessage);
//throw new BadInputException("Cannot add attachment because this Private Message does not in the folder Draft");
}
// Check if the message is from this logon member
if (messageBean.getMessageSenderID() != logonMemberID ) {
throw new AssertionException("Assertion: The MessageSenderID must equals the current logined user.");
}
if (messageBean.getMessageSenderName().equals(onlineUser.getMemberName()) == false) {
throw new AssertionException("Assertion: The MessageSenderName must equals the current logined user.");
}
Timestamp now = DateUtil.getCurrentGMTTimestamp();
Collection attachBeans = DAOFactory.getPmAttachmentDAO().getPmAttachments_inMessage(messageBean.getMessageID()); //messageBean is original message
int maxPrivateMessage = MVNForumConfig.getMaxPrivateMessage();
String[] receivedMembers = StringUtil.getStringArrays(messageBean.getMessageToList(), messageBean.getMessageCcList(), messageBean.getMessageBccList(), ";");
Hashtable receivers = MyUtil.checkMembers(receivedMembers, locale);
StringBuffer overQuotaReceivers = new StringBuffer(128);
for (Enumeration enumeration = receivers.keys(); enumeration.hasMoreElements(); ) {
int receivedMemberID = ((Integer)enumeration.nextElement()).intValue();
String receivedMemberName = (String)receivers.get(new Integer(receivedMemberID));
int receiverMessageCount = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember(receivedMemberID);
if (receiverMessageCount >= maxPrivateMessage) {
if (overQuotaReceivers.length() > 0) {
overQuotaReceivers.append(", ");
}
overQuotaReceivers.append(receivedMemberName);
continue;
}
// Create REAL message for receivers when finish. It means we have new messageID for each new receiver
// We need to get MessageID for attached page
int eachMessageID = DAOFactory.getMessageDAO().create(MVNForumConstant.MESSAGE_FOLDER_INBOX, receivedMemberID, logonMemberID,
messageBean.getMessageSenderName(), messageBean.getMessageToList(), messageBean.getMessageCcList(),
messageBean.getMessageBccList(), messageBean.getMessageTopic(), messageBean.getMessageBody(),
messageBean.getMessageType(), messageBean.getMessageOption(), messageBean.getMessageStatus(),
MessageBean.MESSAGE_READ_STATUS_DEFAULT, messageBean.getMessageNotify(), messageBean.getMessageIcon(),
messageBean.getMessageAttachCount(), request.getRemoteAddr(), now);
// Add to statistics
if (logonMemberID != receivedMemberID) {
DAOFactory.getMessageStatisticsDAO().create(logonMemberID, receivedMemberID, now,
messageBean.getMessageAttachCount(), messageBean.getMessageType(),
messageBean.getMessageOption(), messageBean.getMessageStatus());
}
// We must create a loop to create Attach for many receivers and many attachments
for (Iterator attachIter = attachBeans.iterator(); attachIter.hasNext(); ) {
PmAttachmentBean pmAttachBean = (PmAttachmentBean)attachIter.next();
try {
DAOFactory.getPmAttachMessageDAO().create(eachMessageID, pmAttachBean.getPmAttachID(), 0/*type*/, 0/*option*/, 0/*status*/);
} catch (DuplicateKeyException ex) {
// this should never happen
throw new AssertionException("DuplicateKeyException when create PmAttachMessage");
}
}
} // end of for on receivers
request.setAttribute("OverQuotaReceivers", overQuotaReceivers.toString());
// Now delete the message in the draft
PrivateMessageUtil.deleteMessageInDatabase(messageID, logonMemberID);
request.setAttribute("MessageID", new Integer(messageID));
request.setAttribute("AttachMore", new Boolean(false));
request.setAttribute("AddToSentFolder", new Boolean(false));
}
public void processDelete(GenericRequest request)
throws ObjectNotFoundException, DatabaseException, BadInputException,
AuthenticationException, AssertionException {
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();
int logonMemberID = onlineUser.getMemberID();
int messageID = GenericParamUtil.getParameterInt(request, "message");
MessageBean messageBean = null;
try {
messageBean = DAOFactory.getMessageDAO().getMessage(messageID);
} catch (ObjectNotFoundException e) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messageid_not_exists", new Object[] {new Integer(messageID)});
throw new ObjectNotFoundException(localizedMessage);
}
// Check if this message doesn't belong to current user
// Please note that we dont allow to delete public in this case
if (messageBean.getMemberID() != logonMemberID) {
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");
}
// Now delete the message
PrivateMessageUtil.deleteMessageInDatabase(messageID, logonMemberID);
request.setAttribute("FolderName", messageBean.getFolderName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -