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

📄 readhistory.java

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

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

import org.apache.struts.action.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.comm.*;
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.bbscs.service.web.Pages;
import com.laoer.bbscs.service.web.PageList;
import com.laoer.bbscs.exception.*;
import org.apache.struts.util.MessageResources;

public class ReadHistory
    extends BaseAction {

  private BoardService boardService;

  private SysConfig sysConfig;

  private IPSeeker ipSeeker;

  private ForumHistoryService forumHistoryService;

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                               HttpServletResponse response) {

    ReadForm readForm = (ReadForm) form;

    ActionMessages messages = new ActionMessages();

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

    long bid = readForm.getBid();

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

    if (readForm.getAction().equalsIgnoreCase("topic")) {
      Pages pages = new Pages();
      pages.setPage(readForm.getInpages());
      pages.setPerPageNum(this.getUserPostPerNum(uc.getPostPerNum(),
                                                 this.getSysConfig().getPostPerPage()));
      pages.setFileName(BBSCSUtil.getActionMappingURL("/readHistory?action=" + readForm.getAction() +
          "&bid=" + bid + "&id=" + readForm.getId() + "&fcpage=" + readForm.getFcpage() + "&fcaction" +
          readForm.getFcaction(), request));
      PageList pl = this.getForumHistoryService().findForumsTopic(bid, readForm.getId(), pages);
      if (pl.getObjectList().size() == 0) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        return mapping.getInputForward();
      }
      String title = "";
      ForumHistory f = (ForumHistory) pl.getObjectList().get(0);
      if (f.getIsNew() == 1) {
        f.setClick(f.getClick() + 1);
        try {
          this.getForumHistoryService().updateForumHistory(f);
        }
        catch (BbscsException ex) {
          messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
          this.saveErrors(request, messages);
          return mapping.getInputForward();
        }
      }
      else {
        if (readForm.getInpages() == 1) {
          messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
          this.saveErrors(request, messages);
          return mapping.getInputForward();
        }
      }
      title = f.getTitle();
      request.setAttribute("pl", pl);
      request.setAttribute("title", title);
      List pboards = this.getBoardService().findParentBoards(board.getParentIDs());
      request.setAttribute("pboards", pboards);

      request.setAttribute("mainid", readForm.getId());
      request.setAttribute("fcpage", new Integer(readForm.getFcpage()));
      request.setAttribute("inpages", new Integer(readForm.getInpages()));
      request.setAttribute("totalnum", new Integer(pl.getPages().getTotalNum()));

      return mapping.findForward("readHistory");
    }

    if (readForm.getAction().equalsIgnoreCase("summary")) {
      ForumHistory f = this.getForumHistoryService().findForumHistoryByID(readForm.getId(), readForm.getBid());
      if (f == null) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        return mapping.getInputForward();
      }
      request.setAttribute("forum", f);
      return mapping.findForward("postHistorySummary");
    }

    if (readForm.getAction().equalsIgnoreCase("showip")) {
      MessageResources mr = this.getResources(request);
      ForumHistory f = this.getForumHistoryService().findForumHistoryByID(readForm.getId(), readForm.getBid());
      if (f == null) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        return mapping.findForward("htmlError");
      }
      String ipinfo = mr.getMessage(request.getLocale(), "post.showip", f.getIpAddress(),
                                    this.getIpSeeker().getCountry(f.getIpAddress()));

      request.setAttribute("ipinfo", ipinfo);
      request.setAttribute("fid", f.getId());
      return mapping.findForward("postShowIpInfo");
    }

    if (readForm.getAction().equalsIgnoreCase("showupfile")) {

      ForumHistory f = this.getForumHistoryService().findForumHistoryByID(readForm.getId(), readForm.getBid());
      if (f == null) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        return mapping.findForward("htmlError");
      }
      request.setAttribute("f", f);
      return mapping.findForward("showUpFileInPost");
    }

    if (readForm.getAction().equalsIgnoreCase("showvote")) {
      ForumHistory f = this.getForumHistoryService().findForumHistoryByID(readForm.getId(), readForm.getBid());
      if (f == null) {
        messages.add("error.post.getpost", new ActionMessage("error.post.getpost"));
        this.saveErrors(request, messages);
        return mapping.findForward("htmlError");
      }
      request.setAttribute("f", f);
      return mapping.findForward("showVoteInPost");
    }

    return mapping.findForward(this.FORWARD_ERROR);
  }

  private int getUserPostPerNum(int userNum, int sysNum) {
    if (userNum == 0) {
      return sysNum;
    }
    else {
      return userNum;
    }
  }

  public BoardService getBoardService() {
    return boardService;
  }

  public IPSeeker getIpSeeker() {
    return ipSeeker;
  }

  public SysConfig getSysConfig() {
    return sysConfig;
  }

  public ForumHistoryService getForumHistoryService() {
    return forumHistoryService;
  }

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

  public void setIpSeeker(IPSeeker ipSeeker) {
    this.ipSeeker = ipSeeker;
  }

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

  public void setForumHistoryService(ForumHistoryService forumHistoryService) {
    this.forumHistoryService = forumHistoryService;
  }
}

⌨️ 快捷键说明

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