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

📄 watchwebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (watchMail.haveAtLeastOneNewThread()) {
            // send mail now
            String from = MVNForumConfig.getWebMasterEmail(); //use the default MailFrom value
            String to = receiver.getMemberEmail();
            String subject = watchMail.getWatchSubject();
            String content = watchMail.getMailContent();
            //log.debug("Send message from websmater to ~ " + to + "~");
            try {
                MailUtil.sendMail(from, to, "" /*cc*/, "" /*bcc*/, subject, content);
            } catch (UnsupportedEncodingException e) {
                log.error("Cannot support encoding", e);
            }

            // finally, update the lastsent
            DAOFactory.getWatchDAO().updateLastSentDate_forMember(memberID, now);
        } else {
            log.debug("No new thread for MemberID = " + memberID);
        }
    }

    public void prepareList(GenericRequest request)
        throws DatabaseException, AuthenticationException, AssertionException, ObjectNotFoundException {

        OnlineUser onlineUser = userManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureIsAuthenticated();

        int memberID = onlineUser.getMemberID();
        Locale locale = I18nUtil.getLocaleInRequest(request);

        Collection watchBeans = DAOFactory.getWatchDAO().getWatches_forMember(memberID);

        Collection globalWatchBeans = WatchUtil.getGlobalWatchs(watchBeans);
        Collection categoryWatchBeans = WatchUtil.getCategoryWatchs(watchBeans);
        Collection forumWatchBeans = WatchUtil.getForumWatchs(watchBeans);
        Collection threadWatchBeans = WatchUtil.getThreadWatchs(watchBeans);

        // @todo Improve the performance of the below code
        for (Iterator iter = threadWatchBeans.iterator(); iter.hasNext(); ) {
            WatchBean threadWatchBean = (WatchBean)iter.next();
            int threadID = threadWatchBean.getThreadID();

            ThreadBean threadBean = null;
            try {
                threadBean = DAOFactory.getThreadDAO().getThread(threadID);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
                throw new ObjectNotFoundException(localizedMessage);
            }
            threadWatchBean.setThreadBean(threadBean);
        }

        request.setAttribute("WatchBeans", watchBeans);
        request.setAttribute("GlobalWatchBeans", globalWatchBeans);
        request.setAttribute("CategoryWatchBeans", categoryWatchBeans);
        request.setAttribute("ForumWatchBeans", forumWatchBeans);
        request.setAttribute("ThreadWatchBeans", threadWatchBeans);
    }

    public void prepareAdd(GenericRequest request)
        throws DatabaseException, AuthenticationException, AssertionException {

        Locale locale = I18nUtil.getLocaleInRequest(request);

        if (MVNForumConfig.getEnableWatch() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_add_watch.watch_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot add Watch because Watch feature is disabled by administrator.");
        }

        OnlineUser onlineUser = userManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureIsAuthenticated();
        if (MVNForumConfig.getEnableCompany() == false) {
            permission.ensureIsActivated();
        }
    }

    public void processAdd(GenericRequest request)
        throws BadInputException, CreateException, DatabaseException, ObjectNotFoundException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException {

        Locale locale = I18nUtil.getLocaleInRequest(request);

        if (MVNForumConfig.getEnableWatch() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_add_watch.watch_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot add Watch because Watch feature is disabled by administrator.");
        }

        OnlineUser onlineUser = userManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureIsAuthenticated();
        if (MVNForumConfig.getEnableCompany() == false) {
            permission.ensureIsActivated();
        }

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        int memberID = onlineUser.getMemberID();
        int categoryID              = 0;
        int forumID                 = 0;
        int threadID                = 0;
        int watchType               = 0;//GenericParamUtil.getParameterInt(request, "WatchType");
        int watchOption             = WatchBean.WATCH_OPTION_DEFAULT;//GenericParamUtil.getParameterInt(request, "WatchOption");
        int watchStatus             = 0;//GenericParamUtil.getParameterInt(request, "WatchStatus");
        Timestamp watchCreationDate = now;
        Timestamp watchLastSentDate = now;
        Timestamp watchEndDate      = now;// @todo: check it !!!

        int watchSelector = GenericParamUtil.getParameterInt(request, "WatchSelector");
        switch (watchSelector) {
            case 0:
                break;
            case 1:
                categoryID = GenericParamUtil.getParameterInt(request, "category");
                break;
            case 2:
                forumID = GenericParamUtil.getParameterInt(request, "forum");
                ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
                break;
            case 3:
                threadID = GenericParamUtil.getParameterInt(request, "thread");
                DAOFactory.getThreadDAO().findByPrimaryKey(threadID);
                break;
            default:
                // please do not localize this
                throw new AssertionException("Cannot process WatchSelector = " + watchSelector);
        }

        try {
            DAOFactory.getWatchDAO().create(memberID, categoryID, forumID,
                                       threadID, watchType, watchOption,
                                       watchStatus, watchCreationDate, watchLastSentDate,
                                       watchEndDate);
        } catch (DuplicateKeyException ex) {
            // User try to create a duplicate watch, just ignore
        }
    }

    public void processDelete(GenericRequest request)
        throws BadInputException, DatabaseException, AuthenticationException,
        AssertionException, ObjectNotFoundException {

        OnlineUser onlineUser = userManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureIsAuthenticated();

        int memberID = onlineUser.getMemberID();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int watchID = GenericParamUtil.getParameterInt(request, "watch");

        WatchBean watchBean = DAOFactory.getWatchDAO().getWatch(watchID);

        // check if the watch is owned by the current member
        if (watchBean.getMemberID() != memberID) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete.watch_is_not_owned_by_current_member");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete watch: this watch is not owned by the current member.");
        }

        //now delete the watch
        DAOFactory.getWatchDAO().delete(watchID);
    }
}

⌨️ 快捷键说明

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