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

📄 threadwebhandler.java

📁 java servlet著名论坛源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // user must have been authenticated before he can view enable threads with pending posts
        permission.ensureIsAuthenticated();

        int forumID = ParamUtil.getParameterInt(request, "forum");
        permission.ensureCanModerateThread(forumID);

        ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();

        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "ThreadLastPostDate";
        if (order.length()== 0) order = "DESC";

        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts_inForum(forumID);
        if (offset > totalThreads) {
            throw new BadInputException("The offset is not allowed to be greater than total rows.");
        }

        Collection threadBeans = DAOFactory.getThreadDAO().getEnableThreadsWithPendingPosts_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);

        request.setAttribute("ThreadBeans", threadBeans);
        request.setAttribute("TotalThreads", new Integer(totalThreads));
    }

    void prepareModerationControlPanel(HttpServletRequest request)
        throws DatabaseException, DatabaseException, AssertionException, DatabaseException, AuthenticationException {

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

        // user must have been authenticated before he can view enable threads with pending posts
        permission.ensureIsAuthenticated();
        permission.ensureCanModerateThreadInAnyForum();

        Collection forumBeans = ForumCache.getInstance().getBeans();
        for (Iterator iter = forumBeans.iterator(); iter.hasNext(); ) {
            ForumBean forumBean = (ForumBean)iter.next();
            int forumID = forumBean.getForumID();

            int pendingThreadCount = 0;
            int threadsWithPendingPostsCount = 0;
            int pendingPostCount = 0;

            if (permission.canModerateThread(forumID) && (forumBean.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED) ) {
                pendingThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableBeans_inForum(forumID);
                threadsWithPendingPostsCount = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts_inForum(forumID);
                pendingPostCount = DAOFactory.getPostDAO().getNumberOfDisablePosts_inForum(forumID);
            }

            // note that if user does not have permission on this forum, then the value is 0
            forumBean.setPendingThreadCount(pendingThreadCount);
            forumBean.setThreadsWithPendingPostsCount(threadsWithPendingPostsCount);
            forumBean.setPendingPostCount(pendingPostCount);
        }

        int pendingThreadCount = DAOFactory.getThreadDAO().getNumberOfDisableBeans();
        int threadsWithPendingPostsCount = DAOFactory.getThreadDAO().getNumberOfEnableThreadsWithPendingPosts();

        // Note that because this forumBeans is a new instance
        // we have to put it in session instead of get it again from the ForumCache
        request.setAttribute("ForumBeans", forumBeans);
        request.setAttribute("PendingThreadCount", new Integer(pendingThreadCount));
        request.setAttribute("ThreadsWithPendingPostsCount", new Integer(threadsWithPendingPostsCount));
    }

    void prepareModeratePendingThreads_inForum_limit(HttpServletRequest request)
        throws AssertionException, DatabaseException, AuthenticationException, BadInputException,
        DatabaseException, ObjectNotFoundException {

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

        // user must have been authenticated before he can view pending/disabled threads
        permission.ensureIsAuthenticated();

        int forumID = ParamUtil.getParameterInt(request, "forum");

        // make sure there is the forum
        // will throw an BadInputException if there is not this forum
        ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
        permission.ensureCanModerateThread(forumID);

        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "ThreadLastPostDate";
        if (order.length()== 0) order = "DESC";

        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalThreads = DAOFactory.getThreadDAO().getNumberOfDisableBeans_inForum(forumID);
        if (offset > totalThreads) {
            throw new BadInputException("The offset is not allowed to be greater than total rows.");
        }

        Collection threadBeans = DAOFactory.getThreadDAO().getDisableBeans_inForum_withSortSupport_limit(forumID, offset, postsPerPage, sort, order);
        Collection firstPostBeans = new ArrayList();

        for (Iterator iterator = threadBeans.iterator(); iterator.hasNext(); ) {
            ThreadBean threadBean = (ThreadBean)iterator.next();
            PostBean postBean = DAOFactory.getPostDAO().getFirstPost_inThread(threadBean.getThreadID());
            firstPostBeans.add(postBean);
            // very slow here
            /** @todo find a better solution */
            MemberBean memberBean = null;
            if (postBean.getMemberID() != 0 && postBean.getMemberID() != MVNForumConstant.MEMBER_ID_OF_GUEST) {
                memberBean = DAOFactory.getMemberDAO().getMember_forPublic(postBean.getMemberID());
            }
            postBean.setMemberBean(memberBean);

            int postAttachCount = postBean.getPostAttachCount();
            if ((postAttachCount > 0) && MVNForumConfig.getEnableAttachment()) {
                int postID = postBean.getPostID();
                Collection attachBeans = DAOFactory.getAttachmentDAO().getBeans_inPost(postID);
                int actualAttachCount = attachBeans.size();

                // now check if the attachCount in talbe Post equals to the actual attachCount in table Attachment
                if (postAttachCount != actualAttachCount) {
                    if (actualAttachCount != DAOFactory.getAttachmentDAO().getNumberOfBeans_inPost(postID)) {
                        throw new AssertionException("AssertionException: Serious error: cannot process Attachment Count in table Attachment");
                    }
                    log.warn("The attachment count in table Post and Attachment are not synchronized. In table Post = " +
                            postAttachCount + " and in table Attachment = " + actualAttachCount + ". Synchronize to " + actualAttachCount);
                    DAOFactory.getPostDAO().updateAttachCount(postID, actualAttachCount);
                }
                if (actualAttachCount > 0) {
                    postBean.setAttachmentBeans(attachBeans);
                }
            }
        }

        request.setAttribute("FirstPostBeans", firstPostBeans);
        request.setAttribute("ThreadBeans", threadBeans);
        request.setAttribute("TotalThreads", new Integer(totalThreads));
    }

    void processModeratePendingThreads(HttpServletRequest request)
        throws AssertionException, DatabaseException, AuthenticationException,
        BadInputException, DatabaseException, ObjectNotFoundException {

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

        // user must have been authenticated before he can moderate pending/disabled threads
        permission.ensureIsAuthenticated();

        // check normal permission, note that we dont check
        // permission on a forumID because we allow moderate posts
        // in multiple forums even if the web interface does not support it
        int forumID = -1;
        try {
            forumID = ParamUtil.getParameterInt(request, "forum");
            ForumCache.getInstance().getBean(forumID);// check valid forumID
            permission.ensureCanModerateThread(forumID);

            ForumCache.getInstance().getBean(forumID).ensureNotDisabledForum();
        } catch (BadInputException ex) {
            // just ignore, in case of use customized client
        }
        permission.ensureCanModerateThreadInAnyForum();

        try {
            String prefix = "modthreadaction_";
            for (Enumeration enum = request.getParameterNames(); enum.hasMoreElements(); ) {
                String param = (String) enum.nextElement();
                if (param.startsWith(prefix)) {
                    String modValue = ParamUtil.getParameter(request, param, true);
                    String strThreadID = param.substring(prefix.length());
                    int threadID = Integer.parseInt(strThreadID);
                    if (modValue.equals("approve")) {
                        ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
                        int currentForumID = threadBean.getForumID();
                        permission.ensureCanModerateThread(currentForumID);
                        DAOFactory.getThreadDAO().update_ThreadStatus(threadID, ThreadBean.THREAD_STATUS_DEFAULT);

                        // now if change from Disable to Enable, update the lastpostdate so
                        // that the Watch will see this thread as a new thread
                        if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED ) {
                            Timestamp now = DateUtil.getCurrentGMTTimestamp();
                            DAOFactory.getThreadDAO().updateLastPostDate(threadID, now);
                        }
                    } else if (modValue.equals("delete")) {
                        ThreadBean threadBean = DAOFactory.getThreadDAO().getBean(threadID);
                        deleteThread(request, threadBean);
                    } else {
                        // it means ignore, do nothing
                    }
                }
            }
        } finally {
            // now update the forum statistics
            if (forumID != -1) {
                StatisticsUtil.updateForumStatistics(forumID);
            }
        }

        request.setAttribute("ForumID", String.valueOf(forumID));
    }

    void prepareList_inFavorite(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException, ObjectNotFoundException {

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

        int memberID = onlineUser.getMemberID();

        Collection threadBeans = DAOFactory.getThreadDAO().getBeans_inFavorite_inMember(memberID);

        //remove threads that current user dont have permission
        for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
            ThreadBean threadBean = (ThreadBean)iter.next();
            int currentForumID = threadBean.getForumID();
            if (permission.canReadPost(currentForumID) == false) {
                iter.remove();
            } else if (threadBean.getThreadStatus() == ThreadBean.THREAD_STATUS_DISABLED) {
                if (permission.canModerateThread(currentForumID) == false) {
                    iter.remove();
                }
            } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
                iter.remove();
            }
        }

        request.setAttribute("ThreadBeans", threadBeans);
    }

    void prepareListRSS(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException,
        AuthenticationException, ObjectNotFoundException {

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

        // for sort and order stuff
        String sort  = ParamUtil.getParameter(request, "sort");
        String order = ParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "ThreadLastPostDate";
        if (order.length()== 0) order = "DESC";

        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        // now find that user want global/category/forum RSS
        int forumID = -1;
        int categoryID = -1;
        try {
            forumID = ParamUtil.getParameterInt(request, "forum");
        } catch (Exception ex) {
            try {
                //categoryID = ParamUtil.getParameterInt(request, "category");
            } catch (Exception ex1) { }
        }

        Collection threadBeans = null;
        if (forumID > 0) {
            int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableBeans_inForum(forumID);
            if (offset > totalThreads) {
                throw new BadInputException("The offset is not allowed to be greater than total rows.");
            }
            if (permission.canReadPost(forumID)) {
                threadBeans = DAOFactory.getThreadDAO().getEnableBeans_inForum_withSortSupport_limit(forumID, offset, MVNForumConfig.getRowsPerRSS(), sort, order);
            } else {
                // dont have permission on this forum, just create empty Collection
                threadBeans = new ArrayList();
            }
        } else if (categoryID > 0) {
            //@todo implement later
        } else {
            int totalThreads = DAOFactory.getThreadDAO().getNumberOfEnableBeans();
            if (offset > totalThreads) {
                throw new BadInputException("The offset is not allowed to be greater than total rows.");
            }
            threadBeans = DAOFactory.getThreadDAO().getEnableBeans_withSortSupport_limit(offset, MVNForumConfig.getRowsPerRSS(), sort, order);

            //remove threads that current user dont have permission
            for (Iterator iter = threadBeans.iterator(); iter.hasNext(); ) {
                ThreadBean threadBean = (ThreadBean)iter.next();
                int currentForumID = threadBean.getForumID();
                if (permission.canReadPost(currentForumID) == false) {
                    iter.remove();
                } else if (ForumCache.getInstance().getBean(currentForumID).getForumStatus() == ForumBean.FORUM_STATUS_DISABLED) {
                    iter.remove();
                }
            }
        }

        request.setAttribute("ThreadBeans", threadBeans);
        request.setAttribute("ForumID", new Integer(forumID));
        request.setAttribute("CategoryID", new Integer(categoryID));
    }

}

⌨️ 快捷键说明

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