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

📄 votepost.java

📁 一个jsp写的bbs
💻 JAVA
字号:
package com.laoer.bbscs.web.action;

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

import org.apache.commons.lang.*;
import org.apache.struts.action.*;
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 com.laoer.comm.util.*;
import org.apache.struts.util.LabelValueBean;

public class VotePost
    extends BaseAction {

  private ForumService forumService;

  private BoardService boardService;

  private SysConfig sysConfig;

  private UserService userService;

  private VoteService voteService;

  private VoteItemService voteItemService;

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

    ActionMessages messages = new ActionMessages();

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

    long bid = votePostForm.getBid();
    Board board = (Board) request.getAttribute(Constant.BOARD_REQUEST_KEY);
    if (board == null) {
      board = this.getBoardService().getBoardByID(bid);
      request.setAttribute("board", board);
    }
    String tagId = votePostForm.getTagId();
    if (StringUtils.isBlank(tagId)) {
      tagId = "0";
    }

    request.setAttribute("yearValues", Constant.NYEAR);
    request.setAttribute("monthValues", Constant.MONTH);
    request.setAttribute("dayValues", Constant.DAY);


    if (votePostForm.getAction().equalsIgnoreCase("new")) {
      votePostForm.setAction("add");
      votePostForm.setDeadLineYear(Util.getYear());
      votePostForm.setDeadLineMon(Util.getMonth());
      this.setTagsAttribute(request, board);
      return mapping.findForward("votePost");
    }

    if (votePostForm.getAction().equalsIgnoreCase("add")) {
      String title = StringUtils.trimToEmpty(votePostForm.getTitle());
      String detail = StringUtils.trimToEmpty(votePostForm.getDetail());
      if (StringUtils.isBlank(title) || BBSCSUtil.getSysCharsetStrLength(title) > 90) {
        messages.add("error.post.titletoolong", new ActionMessage("error.post.titletoolong"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
      title = this.getSysConfig().bestrowScreen(title);
      if (StringUtils.isBlank(detail)) {
        messages.add("error.post.nodetail", new ActionMessage("error.post.nodetail"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
      detail = this.getSysConfig().bestrowScreen(detail);

      String[] details = detail.split("\n");
      if (this.getSysConfig().getVoteItemNum() > 0) {
        if (details.length > this.getSysConfig().getVoteItemNum()) {
          messages.add("error.vote.itemnum",
                       new ActionMessage("error.vote.itemnum",
                                         String.valueOf(this.getSysConfig().getVoteItemNum())));
          this.saveErrors(request, messages);
          this.setTagsAttribute(request, board);
          return mapping.getInputForward();
        }
      }
      int voteItemLength = this.getSysConfig().getVoteItemLength();
      if (voteItemLength > 255) {
        voteItemLength = 255;
      }
      for (int i = 0; i < details.length; i++) {
        if (details[i].length() == 0 || BBSCSUtil.getSysCharsetStrLength(details[i]) > voteItemLength) {
          messages.add("error.vote.itemlength",
                       new ActionMessage("error.vote.itemlength", String.valueOf(voteItemLength)));
          this.saveErrors(request, messages);
          this.setTagsAttribute(request, board);
          return mapping.getInputForward();
        }
      }

      if (Util.Date2Long(votePostForm.getDeadLineYear(), votePostForm.getDeadLineMon(),
                         votePostForm.getDeadLineDay()) <= Util.getLongTime()) {
        messages.add("error.vote.deadline", new ActionMessage("error.vote.deadline"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();

      }

      long nowtime = System.currentTimeMillis();
      Forum f = new Forum();
      f.setAgree(0);
      f.setAmend("");
      f.setArtSize(0);
      f.setAttachFileName(new ArrayList());
      f.setAuditing(board.getAuditPost());
      f.setAuditingAttachFile(board.getAuditAttach());
      f.setBeAgainst(0);
      f.setBoardID(bid);
      f.setBoardName(board.getBoardName());
      f.setCanNotDel(0);
      f.setCanNotRe(0);
      f.setClick(0);
      f.setCommend(0);
      f.setDelIP("");
      f.setDelSign(0);
      f.setDelTime(0);
      f.setDelUserID("");
      f.setDelUserName("");
      f.setDetail(detail);
      f.setDoEliteName("");
      f.setDoEliteTime(0);
      f.setEditType(0);
      f.setElite(0);
      f.setEliteID(0);
      f.setFace(99);
      f.setHaveAttachFile(0);
      f.setIpAddress(request.getRemoteAddr());
      f.setIsHidden(0);
      f.setIsHiddenValue(0);
      f.setIsLock(0);
      f.setIsNew(1);
      f.setIsTop(0);
      f.setIsVote(1);
      f.setLastPostNickName("---");
      f.setLastPostTitle("");
      f.setLastPostUserName("---");
      f.setLastTime(nowtime);
      f.setMainID("");
      f.setNickName(us.getNickName());
      f.setParentID("");
      f.setPostTime(nowtime);
      f.setPostType(0);
      f.setQuoteText("");
      f.setReNum(0);
      f.setSign("");
      f.setTitle(title);
      f.setTitleColor(0);
      f.setUserID(us.getId());
      f.setUserName(us.getUserName());
      f.setEmailInform(0);
      f.setMsgInform(0);

      f.setTagID(tagId);
      if (tagId.equals("0")) {
        f.setTagName("");
      }
      else {
        f.setTagName(board.getBoardTagById(tagId).getTagName());
      }


      Vote vote = new Vote();
      vote.setDeadLine(Util.Date2Long(votePostForm.getDeadLineYear(), votePostForm.getDeadLineMon(),
                                      votePostForm.getDeadLineDay()));
      vote.setIsM(votePostForm.getIsM());
      vote.setTitle(votePostForm.getTitle());

      UserInfo ui = this.getUserService().findUserInfoById(us.getId());
      if (ui == null) {
        messages.add("error.post.guest", new ActionMessage("error.post.guest"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }

      try {
        this.getForumService().createVoteForum(f, board, vote, ui);
        uc.addLastPostTime();
        if (board.getAuditPost() == 0) {
          //return new ActionForward(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + bid), true);
          if (Constant.USE_URL_REWRITE) {
            return new ActionForward("/forum-index-" + bid + "-" + tagId + "-1-0.html", true);
          }
          else {
            return new ActionForward(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + bid +
                "&tagId=" + tagId), true);
          }
        }
        else {
          return new ActionForward(BBSCSUtil.getActionMappingURL("/postWaitAudit?bid=" + bid), true);
        }

      }
      catch (BbscsException ex) {
        messages.add("error.vote.addvote", new ActionMessage("error.vote.addvote"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
    }

    if (votePostForm.getAction().equalsIgnoreCase("edit")) {
      if (this.getSysConfig().getVoteChange() == 0) {
        messages.add("error.post.notchange", new ActionMessage("error.post.notchange"));
        this.saveErrors(request, messages);
        return mapping.findForward(this.FORWARD_ERROR);
      }

      votePostForm.setAction("editdo");
      Forum f = this.getForumService().findForumByID(votePostForm.getId(), votePostForm.getBid());
      if (f == null) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        return mapping.findForward(this.FORWARD_ERROR);
      }
      Vote vote = this.getVoteService().findVoteByID(f.getVoteID());
      votePostForm.setIsM(vote.getIsM());
      votePostForm.setTitle(vote.getTitle());
      votePostForm.setDeadLineDay(Util.getDay(vote.getDeadLine()));
      votePostForm.setDeadLineMon(Util.getMonth(vote.getDeadLine()));
      votePostForm.setDeadLineYear(Util.getYear(vote.getDeadLine()));

      List l = this.getVoteItemService().findVoteItemsByVoteID(f.getVoteID());
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < l.size(); i++) {
        VoteItem vi = (VoteItem) l.get(i);
        sb.append(vi.getItem());
        sb.append("\n");
      }
      votePostForm.setDetail(sb.toString());
      this.setTagsAttribute(request, board);
      return mapping.findForward("votePost");
    }

    if (votePostForm.getAction().equalsIgnoreCase("editdo")) {
      String title = StringUtils.trimToEmpty(votePostForm.getTitle());

      if (StringUtils.isBlank(title) || BBSCSUtil.getSysCharsetStrLength(title) > 90) {
        messages.add("error.post.titletoolong", new ActionMessage("error.post.titletoolong"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
      title = this.getSysConfig().bestrowScreen(title);
      if (Util.Date2Long(votePostForm.getDeadLineYear(), votePostForm.getDeadLineMon(),
                         votePostForm.getDeadLineDay()) <= Util.getLongTime()) {
        messages.add("error.vote.deadline", new ActionMessage("error.vote.deadline"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
      Forum f = this.getForumService().findForumByID(votePostForm.getId(), votePostForm.getBid());
      if (f == null) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
      Vote vote = this.getVoteService().findVoteByID(f.getVoteID());
      vote.setDeadLine(Util.Date2Long(votePostForm.getDeadLineYear(), votePostForm.getDeadLineMon(),
                                      votePostForm.getDeadLineDay()));
      vote.setIsM(votePostForm.getIsM());
      vote.setTitle(votePostForm.getTitle());

      f.setTitle(votePostForm.getTitle());

      try {
        this.getForumService().saveForum(f);
        this.getVoteService().saveVote(vote);
        return new ActionForward(BBSCSUtil.getActionMappingURL("/forum?action=index&bid=" + bid), true);
      }
      catch (BbscsException ex1) {
        messages.add("error.post.vote.edit.error", new ActionMessage("error.post.vote.edit.error"));
        this.saveErrors(request, messages);
        this.setTagsAttribute(request, board);
        return mapping.getInputForward();
      }
    }

    return mapping.getInputForward();
  }

  private void setTagsAttribute(HttpServletRequest request, Board b) {
    Vector v = new Vector();
    v.add(new LabelValueBean(b.getBoardName(), "0"));
    Iterator it = b.getBoardTag().iterator();
    BoardTag bt = null;
    while (it.hasNext()) {
      bt = (BoardTag) it.next();
      v.add(new LabelValueBean(bt.getTagName(), bt.getId()));
    }
    request.setAttribute("tagValues", v);
  }

  public BoardService getBoardService() {
    return boardService;
  }

  public ForumService getForumService() {
    return forumService;
  }

  public SysConfig getSysConfig() {
    return sysConfig;
  }

  public UserService getUserService() {
    return userService;
  }

  public VoteService getVoteService() {
    return voteService;
  }

  public VoteItemService getVoteItemService() {
    return voteItemService;
  }

  public void setBoardService(BoardService boardService) {
    this.boardService = boardService;
  }

  public void setForumService(ForumService forumService) {
    this.forumService = forumService;
  }

  public void setSysConfig(SysConfig sysConfig) {
    this.sysConfig = sysConfig;
  }

  public void setUserService(UserService userService) {
    this.userService = userService;
  }

  public void setVoteService(VoteService voteService) {
    this.voteService = voteService;
  }

  public void setVoteItemService(VoteItemService voteItemService) {
    this.voteItemService = voteItemService;
  }

}

⌨️ 快捷键说明

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