📄 messagewebhandler.java
字号:
request.setAttribute("AddSentFolderOverQuota", Boolean.TRUE);
}
}// end of addToSentFolder
}// else of No Attachment
} // end of click to button Send
request.setAttribute("AttachMore", new Boolean(attachMore));
request.setAttribute("AddToSentFolder", new Boolean(addToSentFolder));
FloodControl.increaseCount(MVNForumGlobal.FLOOD_ID_NEW_MESSAGE, currentIP);
}
public void prepareViewMessage(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
boolean isPublicMessage = ((messageBean.getMessageType() == MessageBean.MESSAGE_TYPE_PUBLIC) && MVNForumConfig.getEnablePublicMessage());
if ((messageBean.getMemberID() != logonMemberID) && !isPublicMessage) {
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");
}
MemberBean memberSenderBean = null;
int messageSenderID = messageBean.getMessageSenderID();
try {
memberSenderBean = MemberCache.getInstance().getMember_forPublic(messageSenderID);
} catch (ObjectNotFoundException e) {
// In this case, member has been deleted but his message is still there, so we just ignore
// Note that currently the viewmessage.jsp accept null value of memberSenderBean
}
if (isPublicMessage) {
DAOFactory.getMessageDAO().updateMessageReadStatus(messageID, messageBean.getMemberID(), MessageBean.MESSAGE_READ_STATUS_READ);
} else {// private message
DAOFactory.getMessageDAO().updateMessageReadStatus(messageID, logonMemberID, MessageBean.MESSAGE_READ_STATUS_READ);
}
// We get attachment of this message
Collection attachBeans = DAOFactory.getPmAttachmentDAO().getPmAttachments_inMessage(messageID);
messageBean.setAttachmentBeans(attachBeans);
// always update the number of new private message count in this case
onlineUser.updateNewMessageCount(true);
request.setAttribute("MessageBean", messageBean);
request.setAttribute("MemberSenderBean", memberSenderBean);
}
public void prepareList(GenericRequest request)
throws BadInputException, DatabaseException, ObjectNotFoundException,
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();
// always update the number of new private message count in this case
onlineUser.updateNewMessageCount(true);
// @todo: We must check folder to make a correct list
String folderName = GenericParamUtil.getParameter(request, "folder");
if (folderName.length() == 0) {
folderName = MVNForumConstant.MESSAGE_FOLDER_INBOX; // Default as Inbox
}
StringUtil.checkGoodName(folderName);
// for sort and order stuff
String sort = GenericParamUtil.getParameter(request, "sort");
String order = GenericParamUtil.getParameter(request, "order");
if (sort.length() == 0) sort = "MessageCreationDate";
if (order.length()== 0) order = "DESC";
//Process of Show Messages of login member
int messagePerPage = onlineUser.getMessagesPerPage();
int offset = 0;
try {
offset = GenericParamUtil.getParameterInt(request, "offset");
} catch (BadInputException ex) {
// do nothing
}
int logonMemberID = onlineUser.getMemberID();
try {
DAOFactory.getMessageFolderDAO().findByPrimaryKey(folderName, logonMemberID);
} catch (ObjectNotFoundException onf) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.messagefolder_not_exists", new Object[] {folderName});
throw new ObjectNotFoundException(localizedMessage);
}
int numberOfMessages = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember_inFolder(logonMemberID, folderName);
if (offset > numberOfMessages) {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
throw new BadInputException(localizedMessage);
//throw new BadInputException("The offset is not allowed to be greater than total rows.");
}
Collection messageBeans = null;
if (folderName.equalsIgnoreCase(MVNForumConstant.MESSAGE_FOLDER_DRAFT)) {
// also get the draft public messages
messageBeans = DAOFactory.getMessageDAO().getAllMessages_inMember_inFolder_withSortSupport_limit(logonMemberID, folderName, offset, messagePerPage, sort, order);
} else {
messageBeans = DAOFactory.getMessageDAO().getNonPublicMessages_inMember_inFolder_withSortSupport_limit(logonMemberID, folderName, offset, messagePerPage, sort, order);
}
Collection messagePublicBeans = null;
if (MVNForumConfig.getEnablePublicMessage()) {
messagePublicBeans = DAOFactory.getMessageDAO().getPublicMessages();
}
// for folder table
Collection messageFolderBeans = DAOFactory.getMessageFolderDAO().getMessageFolders_inMember(logonMemberID);
for (Iterator iter = messageFolderBeans.iterator(); iter.hasNext(); ) {
MessageFolderBean messageFolder = (MessageFolderBean) iter.next();
int messageCount;
int unreadMessageCount;
if (messageFolder.getFolderName().equalsIgnoreCase(MVNForumConstant.MESSAGE_FOLDER_DRAFT)) {
// also get the draft public messages
messageCount = DAOFactory.getMessageDAO().getNumberOfAllMessages_inMember_inFolder(logonMemberID, messageFolder.getFolderName());
unreadMessageCount = DAOFactory.getMessageDAO().getNumberOfUnreadAllMessages_inMember_inFolder(logonMemberID, messageFolder.getFolderName());
} else {
messageCount = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember_inFolder(logonMemberID, messageFolder.getFolderName());
unreadMessageCount = DAOFactory.getMessageDAO().getNumberOfUnreadNonPublicMessages_inMember_inFolder(logonMemberID, messageFolder.getFolderName());
}
messageFolder.setMessageCount(messageCount);
messageFolder.setUnreadMessageCount(unreadMessageCount);
} // end for on folders
// for the quota bar
int max = MVNForumConfig.getMaxPrivateMessage();
int messageCount = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember(logonMemberID);
double ratio = 0;
if (max == 0) {
ratio = 1.0;
} else {
ratio = (double)messageCount / max;
}
// for the quota bar
request.setAttribute("QuotaRatio", new Double(ratio*100));
request.setAttribute("MessagePublicBeans", messagePublicBeans);
request.setAttribute("MessageFolderBeans", messageFolderBeans);
request.setAttribute("MessageBeans", messageBeans);
request.setAttribute("TotalMessages", new Integer(numberOfMessages));
}
public void processMessage(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();
String btnDelete = request.getParameter("btnDelete");
String btnUnreadMark = request.getParameter("btnUnreadMark");
String btnMoveFolder = request.getParameter("btnMoveFolder");
int logonMemberID = onlineUser.getMemberID();
int action = 0; // it's better than true-false, expand function later
/*
* action = 1; // Delete action
* action = 2; // Mark unread action
* action = 3; // move to another folder
*/
if ((btnDelete != null)) {
action = 1;
} else if (btnUnreadMark != null) {
action = 2;
} else if (btnMoveFolder != null) {
action = 3;
} else {
String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_specify_action");
throw new BadInputException(localizedMessage);
//throw new BadInputException("Cannot specify the action");
}
if (action == 1) {// delete
//log.debug("ListDelete Message:" + btnDelete);
String[] deleteList = request.getParameterValues("selectedmessage");
for (int i = 0; (deleteList != null) && (i < deleteList.length); i++) {
int messageID = Integer.parseInt(deleteList[i]);
MessageBean messageBean = null;
try {
messageBean = DAOFactory.getMessageDAO().getMessage(messageID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -