⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagewebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

        // if messageToList == null permit null value
        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

        String messageTopic = GenericParamUtil.getParameter(request, "MessageTopic", true);
        messageTopic = DisableHtmlTagFilter.filter(messageTopic);// always disable HTML
        messageTopic = InterceptorService.getInstance().validateContent(messageTopic);

        String messageBody  = GenericParamUtil.getParameter(request, "message", true);// use message instead of MessageBody
        messageBody = DisableHtmlTagFilter.filter(messageBody);// always disable HTML
        messageBody = InterceptorService.getInstance().validateContent(messageBody);

        String messageIcon = GenericParamUtil.getParameter(request, "MessageIcon");
        messageIcon = DisableHtmlTagFilter.filter(messageIcon);// always disable HTML

        if (sendAll) {
            messageToList  = onlineUser.getMemberName();
            messageBccList = "";
            messageCcList  = "";
        }

        Timestamp now               = DateUtil.getCurrentGMTTimestamp();
        int messageSenderID         = logonMemberID;
        String messageSenderName    = memberName;
        String folderName           = MVNForumConstant.MESSAGE_FOLDER_INBOX;
        // NOTE: in this step, type = quote is not possible since it needs attachment
        int messageType             = (sendAll) ? MessageBean.MESSAGE_TYPE_PUBLIC : MessageBean.MESSAGE_TYPE_DEFAULT;
        int messageOption           = 0;//GenericParamUtil.getParameterInt(request, "MessageOption");
        int messageStatus           = 0;//GenericParamUtil.getParameterInt(request, "MessageStatus");
        int messageReadStatus       = MessageBean.MESSAGE_READ_STATUS_DEFAULT;
        int messageNotify           = 0;//GenericParamUtil.getParameterInt(request, "MessageNotify");
        int messageAttachCount      = 0;
        String messageIP            = currentIP;
        Timestamp messageCreateDate = now; // Get Current time

        int parentMessageID = 0;

        boolean isDraft         = GenericParamUtil.getParameterBoolean(request, "draft");
        boolean isForward       = GenericParamUtil.getParameterBoolean(request, "forward");
        boolean attachMore      = GenericParamUtil.getParameterBoolean(request, "AttachMore");
        boolean addToSentFolder = GenericParamUtil.getParameterBoolean(request, "AddToSentFolder");

        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);
            }
        }

        Hashtable receivers = MyUtil.checkMembers(receivedMembers, locale);

        if (isForward) {
            parentMessageID = GenericParamUtil.getParameterInt(request, "parent");
        }

        Collection attachBeans = null;
        if (isForward) {
            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);
            }

            //actually, the jsp does not allow forward a public message
            boolean isPublicMessage = false;
            if (MVNForumConfig.getEnablePublicMessage()) {
                isPublicMessage = (permission.canAdminSystem() && (parentMessageBean.getMessageType() == MessageBean.MESSAGE_TYPE_PUBLIC));
            }

            if ((parentMessageBean.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");
            }
            attachBeans = DAOFactory.getPmAttachmentDAO().getPmAttachments_inMessage(parentMessageID);
            messageAttachCount = attachBeans.size();// in case forward, the attachcount could > 0 so we call this method
        } // end forward

        int maxPrivateMessage = MVNForumConfig.getMaxPrivateMessage();
        if (isDraft) { // Click to Draft Button
            folderName = MVNForumConstant.MESSAGE_FOLDER_DRAFT;
            // We will save message to folder Draft with memberID = SenderID
            // @todo: in next version:  when user click to draft message we will open
            //        AddMessage window and display all of its previous data

            int senderMessageCount = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember(logonMemberID);
            if (senderMessageCount >= maxPrivateMessage) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.over_private_message_quota", new Object[] {new Integer(maxPrivateMessage)});
                throw new BadInputException(localizedMessage);
                //throw new BadInputException("You cannot push the message into the draft folder. You have already use all your private message quota (" + maxFavorites + ").");
            }

            int draftMessageID = DAOFactory.getMessageDAO().create(folderName, messageSenderID, messageSenderID,
                                                messageSenderName, messageToList, messageCcList,
                                                messageBccList, messageTopic, messageBody,
                                                messageType, messageOption, messageStatus,
                                                messageReadStatus, messageNotify, messageIcon,
                                                messageAttachCount, messageIP, messageCreateDate);
            if (isForward) {
                // We must move PmAttachment from parent to new Message
                for (Iterator attachIter = attachBeans.iterator(); attachIter.hasNext(); ) {
                    PmAttachmentBean pmAttachBean = (PmAttachmentBean)attachIter.next();
                    try {
                        DAOFactory.getPmAttachMessageDAO().create(draftMessageID, pmAttachBean.getPmAttachID(), 0/*type*/, 0/*option*/, 0/*status*/);
                    } catch (DuplicateKeyException ex) {
                        // this should never happen
                        throw new AssertionException("DuplicateKeyException when create PmAttachMessage");
                    }
                }
            }// end of isForward

            attachMore = false;
        } else { // end draft
            // click to Send button
            // test the receiver's quota
            if (attachMore) {

                int senderMessageCount = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember(logonMemberID);
                if (senderMessageCount >= maxPrivateMessage) {
                    String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.over_private_message_quota", new Object[] {new Integer(maxPrivateMessage)});
                    throw new BadInputException(localizedMessage);
                    //throw new BadInputException("You cannot push the message into the draft folder. You have already use all your private message quota (" + maxFavorites + ").");
                }

                folderName = MVNForumConstant.MESSAGE_FOLDER_DRAFT;// it means sending process is not finished
                // Create but save it as temporary message in Draft folder
                int messageID = DAOFactory.getMessageDAO().create(folderName, messageSenderID, messageSenderID,
                                                messageSenderName, messageToList, messageCcList,
                                                messageBccList, messageTopic, messageBody,
                                                messageType, messageOption, messageStatus,
                                                messageReadStatus, messageNotify, messageIcon,
                                                messageAttachCount, messageIP, messageCreateDate);
                if (isForward) {
                    // We must move PmAttachment from parent to new Message
                    for (Iterator attachIter = attachBeans.iterator(); attachIter.hasNext(); ) {
                        PmAttachmentBean pmAttachBean = (PmAttachmentBean)attachIter.next();
                        try {
                            DAOFactory.getPmAttachMessageDAO().create(messageID, pmAttachBean.getPmAttachID(), 0/*type*/, 0/*option*/, 0/*status*/);
                        } catch (DuplicateKeyException ex) {
                            // this should never happen
                            throw new AssertionException("DuplicateKeyException when create PmAttachMessage");
                        }
                    }
                }// end of isForward

                // When attach more, we must put attribute for MessageID
                request.setAttribute("MessageID", new Integer(messageID));
            } else { // NO Attachment
                // no attachment means we will send this message now
                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;
                    }

                    // We need to get MessageID for attached page
                    int eachMessageID = DAOFactory.getMessageDAO().create(folderName, receivedMemberID, messageSenderID,
                                                        messageSenderName, messageToList, messageCcList,
                                                        messageBccList, messageTopic, messageBody,
                                                        messageType, messageOption, messageStatus,
                                                        messageReadStatus, messageNotify, messageIcon,
                                                        messageAttachCount, messageIP, messageCreateDate);

                    // Add to statistics
                    if (messageSenderID != receivedMemberID) {
                        DAOFactory.getMessageStatisticsDAO().create(messageSenderID, receivedMemberID, messageCreateDate,
                                                                    messageAttachCount, messageType, messageOption, messageStatus);
                    }

                    if (isForward) {
                        // We must move PmAttachment from parent to new Message
                        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 isForward
                } // end of for on received members
                request.setAttribute("OverQuotaReceivers", overQuotaReceivers.toString());

                // after that, we create another record to save it in Sent. (if user wants)
                if (addToSentFolder) {
                    int senderMessageCount = DAOFactory.getMessageDAO().getNumberOfNonPublicMessages_inMember(logonMemberID);
                    if (senderMessageCount < maxPrivateMessage) {
                        folderName = MVNForumConstant.MESSAGE_FOLDER_SENT;
                        messageType = MessageBean.MESSAGE_TYPE_DEFAULT;// always a default type in the Sent folder
                        int sentMessageID = DAOFactory.getMessageDAO().create(folderName, messageSenderID, messageSenderID,
                                messageSenderName, messageToList, messageCcList,
                                messageBccList, messageTopic, messageBody,
                                messageType, messageOption, messageStatus,
                                messageReadStatus, messageNotify, messageIcon,
                                messageAttachCount, messageIP, messageCreateDate);
                        if (isForward) {
                            // We must move PmAttachment from parent to new Message
                            for (Iterator attachIter = attachBeans.iterator(); attachIter.hasNext(); ) {
                                PmAttachmentBean pmAttachBean = (PmAttachmentBean)attachIter.next();
                                try {
                                    DAOFactory.getPmAttachMessageDAO().create(sentMessageID, pmAttachBean.getPmAttachID(), 0/*type*/, 0/*option*/, 0/*status*/);
                                } catch (DuplicateKeyException ex) {
                                    // this should never happen
                                    throw new AssertionException("DuplicateKeyException when create PmAttachMessage");
                                }
                            }
                        }// end of isForward
                    } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -