postopt.java

来自「一个jsp写的bbs」· Java 代码 · 共 797 行 · 第 1/3 页

JAVA
797
字号
package com.laoer.bbscs.web.action;

import java.util.*;
import java.io.*;
import javax.servlet.http.*;

import org.apache.commons.lang.*;
import org.apache.commons.mail.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.comm.*;
import com.laoer.bbscs.exception.*;
import com.laoer.bbscs.service.*;
import com.laoer.bbscs.service.config.*;
import com.laoer.bbscs.web.form.*;
import com.laoer.bbscs.web.servlet.*;
import freemarker.template.*;

public class PostOpt
    extends BaseAction {

  private ForumService forumService;

  private BoardService boardService;

  private SysConfig sysConfig;

  private UserService userService;

  private AjaxMessagesXML ajaxMessagesXML;

  private AgreeAgainstService agreeAgainstService;

  private SubscibeFactory subscibeFactory;

  private SubscibeService subscibeService;

  private HtmlEmail htmlEmail;

  private Configuration tempConfiguration;

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                               HttpServletResponse response) {
    ReadForm optForm = (ReadForm) form;

    UserSession us = this.getUserSession(request);
    UserCookie uc = this.getUserCookie(request, response, this.getSysConfig());
    long bid = optForm.getBid();

    Board board = (Board) request.getAttribute(Constant.BOARD_REQUEST_KEY);
    if (board == null) {
      board = this.getBoardService().getBoardByID(bid);
      //request.setAttribute("board", board);
    }

    MessageResources mr = this.getResources(request);
    Locale locale = this.getLocale(request);

    if (optForm.getAction().equalsIgnoreCase("votyes") ||
        optForm.getAction().equalsIgnoreCase("votno")) {
      Forum f = this.getForumService().findForumByID(optForm.getId(), bid);
      if (f == null) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_NOT_EXIST,
                                             mr.getMessage(locale, "error.post.getpost"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      if (this.getSysConfig().getPostVoteRec() == 0) { //不记录投票结果
        if (optForm.getAction().equalsIgnoreCase("votyes")) {
          f.setAgree(f.getAgree() + 1);
        }
        if (optForm.getAction().equalsIgnoreCase("votno")) {
          f.setBeAgainst(f.getBeAgainst() + 1);
        }
        try {
          f = this.getForumService().saveForum(f);
          if (optForm.getAction().equalsIgnoreCase("votyes")) {
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                                 mr.getMessage(locale, "post.agreeagainst.ok"),
                                                 String.valueOf(f.getAgree()));
          }
          if (optForm.getAction().equalsIgnoreCase("votno")) {
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                                 mr.getMessage(locale, "post.agreeagainst.ok"),
                                                 String.valueOf(f.getBeAgainst()));
          }
        }
        catch (BbscsException ex) {
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_AGREEAGAINST_ERROR,
                                               mr.getMessage(locale,
              "error.post.agreeagainst.error"));
        }
      }
      else {
        AgreeAgainst agreeAgainst = this.getAgreeAgainstService().findAgreeAgainstByUidPidBid(us.
            getId(), optForm.getId(), bid);
        if (agreeAgainst == null) {
          if (optForm.getAction().equalsIgnoreCase("votyes")) {
            f.setAgree(f.getAgree() + 1);
          }
          if (optForm.getAction().equalsIgnoreCase("votno")) {
            f.setBeAgainst(f.getBeAgainst() + 1);
          }
          try {
            f = this.getForumService().saveForum(f);
            agreeAgainst = new AgreeAgainst();
            agreeAgainst.setBoardID(f.getBoardID());
            agreeAgainst.setCreateTime(System.currentTimeMillis());
            agreeAgainst.setPostID(f.getId());
            agreeAgainst.setUserID(us.getId());
            if (optForm.getAction().equalsIgnoreCase("votyes")) {
              agreeAgainst.setVoteType(0);
            }
            if (optForm.getAction().equalsIgnoreCase("votno")) {
              agreeAgainst.setVoteType(1);
            }
            this.getAgreeAgainstService().saveAgreeAgainst(agreeAgainst);
            if (optForm.getAction().equalsIgnoreCase("votyes")) {
              this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                  mr.getMessage(locale, "post.agreeagainst.ok"),
                  String.valueOf(f.getAgree()));
            }
            if (optForm.getAction().equalsIgnoreCase("votno")) {
              this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                  mr.getMessage(locale, "post.agreeagainst.ok"),
                  String.valueOf(f.getBeAgainst()));
            }
          }
          catch (BbscsException ex) {
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_AGREEAGAINST_ERROR,
                                                 mr.getMessage(locale,
                "error.post.agreeagainst.error"));
          }
        }
        else {
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_AGREEAGAINST_REPEAT,
                                               mr.getMessage(locale,
              "error.post.agreeagainst.repeat"));
        }
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward(this.FORWARD_AJAX);
    }

    if (optForm.getAction().equalsIgnoreCase("dela")) {
      Forum f = this.getForumService().findForumByID(optForm.getId(), bid);
      if (f == null) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_NOT_EXIST,
                                             mr.getMessage(locale, "error.post.getpost"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      if ( (f.getCanNotRe() == 0 && f.getUserID().equals(us.getId())) ||
          us.isHaveBoardSpecialPermission(Constant.SPERMISSION_CAN_DELPOST)) {
        f.setDelIP(request.getRemoteAddr());
        f.setDelSign(1);
        f.setDelTime(System.currentTimeMillis());
        f.setDelUserID(us.getId());
        f.setDelUserName(us.getUserName());
        if (f.getIndexStatus() == Constant.INDEX_STATUS_NO_INDEX) {
          f.setIndexStatus(Constant.INDEX_STATUS_NO_INDEX_TO_DEL);
        }
        else {
          f.setIndexStatus(Constant.INDEX_STATUS_NEED_DEL);
        }
        /**
        else if (f.getIndexStatus() == Constant.INDEX_STATUS_INDEXED) {
          f.setIndexStatus(Constant.INDEX_STATUS_NEED_DEL);
        }
        else if (f.getIndexStatus() == Constant.INDEX_STATUS_NEED_UPDTAE) {
          f.setIndexStatus(Constant.INDEX_STATUS_UPDATE_TO_DEL);
        }*/
        //UserInfo ui = this.getUserService().findUserInfoById(us.getId());

        UserInfo ui = this.getUserService().findUserInfoById(f.getUserID());
        try {
          this.getForumService().delaPost(f, board, ui);
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                               mr.getMessage(locale, "post.del.ok"));

        }
        catch (BbscsException ex1) {
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_DEL_ERROR,
                                               mr.getMessage(locale, "error.post.del1"));
        }
      }
      else {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_NO_PERMISSION,
                                             mr.getMessage(locale, "error.noPermission"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward(this.FORWARD_AJAX);
    }

    if (optForm.getAction().equalsIgnoreCase("subs")) {
      Forum f = this.getForumService().findForumByID(optForm.getId(), bid);
      if (f == null) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_NOT_EXIST,
                                             mr.getMessage(locale, "error.post.getpost"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      if (this.getSubscibeService().findSubscibeByPostID(optForm.getId(), us.getId(), bid) == null) {
        UserInfo ui = this.getUserService().findUserInfoById(us.getId());
        if (ui != null) {
          Subscibe subs = this.getSubscibeFactory().getInstance(bid);
          subs.setBoardID(bid);
          subs.setCreateTime(new Date());
          subs.setEmailinform(1);
          subs.setMsginform(1);
          subs.setNickName(us.getNickName());
          subs.setPostID(optForm.getId());
          subs.setPostTitle(f.getTitle());
          subs.setUserEmail(ui.getEmail());
          subs.setUserID(us.getId());
          subs.setUserName(us.getUserName());
          subs.setUserLocale(ui.getUserLocale());
          try {
            this.getSubscibeService().saveSubscibe(subs);
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                                 mr.getMessage(locale, "post.subs.ok"));
          }
          catch (BbscsException ex2) {
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_SUBS_ERROR,
                                                 mr.getMessage(locale, "error.post.subs.error"));
          }
        }
      }
      else {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_SUBS_EXIST,
                                             mr.getMessage(locale, "error.post.subs.exist"));
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward(this.FORWARD_AJAX);
    }

    if (optForm.getAction().equalsIgnoreCase("top") || optForm.getAction().equalsIgnoreCase("untop")) {
      Forum f = this.getForumService().findForumByID(optForm.getId(), bid);
      if (f == null) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_NOT_EXIST,
                                             mr.getMessage(locale, "error.post.getpost"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      if (optForm.getAction().equalsIgnoreCase("top")) {
        if (f.getIsTop() == 0) {
          f.setIsTop(1);
          try {
            this.getForumService().saveForum(f);
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK, mr.getMessage(locale, "post.top.set.ok"));
          }
          catch (BbscsException ex3) {
            this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_TOP_SET_ERROR,
                                                 mr.getMessage(locale, "error.post.top.seterror"));
          }
        }
        else {
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_TOP_EXIST,
                                               mr.getMessage(locale, "error.post.top.exist"));
        }
      }
      if (optForm.getAction().equalsIgnoreCase("untop")) {
        if (f.getIsTop() != 0) {

⌨️ 快捷键说明

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