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

📄 postaction.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.laoer.bbscs.bbs.action;

import org.apache.struts.action.*;
import org.apache.struts.upload.*;
import javax.servlet.http.*;
import com.laoer.bbscs.bbs.actionform.*;
import com.laoer.bbscs.bbs.business.*;
import com.laoer.bbscs.sysinfo.*;
import com.laoer.bbscs.util.*;
import com.laoer.bbscs.servlet.*;
import com.laoer.bbscs.db.*;
import org.apache.struts.util.*;
import java.util.*;
import java.io.*;
import org.apache.log4j.*;

public class PostAction
    extends Action {

  static Logger logger = Logger.getLogger(PostAction.class.getName());

  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse) {

    ActionErrors errors = new ActionErrors();
    PostActionForm form = (PostActionForm) actionForm;
    UserSessionCheck myUserSessionCheck = new UserSessionCheck(form.getSid(),
        httpServletRequest);
    if (!myUserSessionCheck.checkSession(form.getBid())) {
      errors.add("error.timeout", new ActionError("error.timeout"));
      saveErrors(httpServletRequest, errors);
      return actionMapping.findForward("error");
    }
    if (myUserSessionCheck.isGuest()) {
      errors.add("noguest", new ActionError("error.user.noguest"));
      saveErrors(httpServletRequest, errors);
      return actionMapping.findForward("error");
    }
    if (myUserSessionCheck.getBuAtBoards()) {
      errors.add("error.blackuser1",
                 new ActionError("error.blackuser1",
                                 myUserSessionCheck.getBuOutTime()));
      saveErrors(httpServletRequest, errors);
      return actionMapping.findForward("error");
    }
    httpServletRequest.setAttribute("myUserSessionCheck", myUserSessionCheck);
    httpServletRequest.setAttribute("sid", form.getSid());
    httpServletRequest.setAttribute("bid", form.getBid());

    if (form.getAction().equals("new")) {
      MessageResources messages = getResources(httpServletRequest);
      Locale locale = getLocale(httpServletRequest);
      String headadv = ShowMsg.getHeadAdv(messages, locale, form.getSid(),
                                          myUserSessionCheck);
      httpServletRequest.setAttribute("action", form.getAction());
      httpServletRequest.setAttribute("headadv", headadv);
      httpServletRequest.setAttribute("theBoards",
                                      myUserSessionCheck.getTheBoards());
      if (form.getUseedit().equals("no")) {
        httpServletRequest.setAttribute("useedit", "no");
        //return actionMapping.findForward("newpost");
      }
      else {
        httpServletRequest.setAttribute("useedit", "yes");
        //return actionMapping.findForward("newpostedit");
      }
      errors = null;
      form = null;
      myUserSessionCheck = null;
      messages = null;
      locale = null;
      headadv = null;
      return actionMapping.findForward("newpost");
    }
    if (form.getAction().equals("re")) {
      MessageResources messages = getResources(httpServletRequest);
      Locale locale = getLocale(httpServletRequest);
      String headadv = ShowMsg.getHeadAdv(messages, locale, form.getSid(),
                                          myUserSessionCheck);
      httpServletRequest.setAttribute("headadv", headadv);
      httpServletRequest.setAttribute("theBoards",
                                      myUserSessionCheck.getTheBoards());
      if (form.getUseedit().equals("no")) {
        httpServletRequest.setAttribute("useedit", "no");
        //return actionMapping.findForward("newpost");
      }
      else {
        httpServletRequest.setAttribute("useedit", "yes");
        //return actionMapping.findForward("newpostedit");
      }
      httpServletRequest.setAttribute("action", form.getAction());
      httpServletRequest.setAttribute("recid", form.getRecid());
      httpServletRequest.setAttribute("mainid", form.getMainid());
      httpServletRequest.setAttribute("pages", form.getPages());
      httpServletRequest.setAttribute("totalnum", form.getTotalnum());
      ForumInfo aForumInfo = new ForumInfo();
      aForumInfo.setBoardID(Long.parseLong(form.getBid()));
      aForumInfo.setID(Long.parseLong(form.getRecid()));
      String title = "";
      Forum aForum = ForumFactory.getInstance();
      aForum.setForumInfo(aForumInfo);
      if (aForum.getPost(null, "ID", true) != Sys.RESULT_RIGHT) {
        errors.add("getpost", new ActionError("error.post.getpost"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      title = aForum.getForumInfo().getTitle();
      aForum = null;
      aForumInfo = null;
      httpServletRequest.setAttribute("title", title);
      errors = null;
      form = null;
      myUserSessionCheck = null;
      messages = null;
      locale = null;
      title = null;
      return actionMapping.findForward("newpost");
    }
    if (form.getAction().equals("add")) {
      UserInfo myUserInfo = myUserSessionCheck.getUser().getUserInfo();
      BoardsInfo theBoards = myUserSessionCheck.getTheBoards();
      String IP = httpServletRequest.getRemoteAddr();
      int artSize = 0;
      try {
        artSize = form.getDetail().getBytes(Sys.SYSINFO.CHARSET).length;
      }
      catch (Exception e) {
        System.out.println(e);
      }

      int mypower = 0; //气力值
      mypower = myUserInfo.getPower();
      if (mypower <= 0 &&
          ! (myUserSessionCheck.isSuperAdmin() ||
             myUserSessionCheck.isBMaster() ||
             myUserSessionCheck.isMainMaster() ||
             myUserSessionCheck.isAssiMaster() ||
             myUserSessionCheck.isHideMaster())) {
        errors.add("nopower", new ActionError("error.post.nopower"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      String sign_detail = "";
      if (form.getSign().equals("0")) {
        sign_detail = "";
      }
      else {
        sign_detail = Util.addSlashes(myUserInfo.getSing_Detail(Integer.
            parseInt(form.getSign())));
      }
      ForumInfo aForumInfo = new ForumInfo();
      long postTime = Util.getaLongTime();
      long aID = TableID.nextID(4);
      aForumInfo.setID(aID);
      aForumInfo.setID1(0);
      aForumInfo.setID2(aID);
      aForumInfo.setBoardID(theBoards.getID());
      aForumInfo.setBoardName(theBoards.getBoardsName());
      aForumInfo.setFace(Integer.parseInt(form.getBq()));
      aForumInfo.setUserID(myUserInfo.getID());
      aForumInfo.setUserName(myUserInfo.getUserName());
      aForumInfo.setTitle(form.getTitle());
      aForumInfo.setDetail(form.getDetail());
      aForumInfo.setSign(sign_detail);
      aForumInfo.setArtSize(artSize);
      aForumInfo.setEmail_Inform(Integer.parseInt(form.getEmail_inform()));
      aForumInfo.setMsg_Inform(Integer.parseInt(form.getMsg_inform()));
      aForumInfo.setPostTime(postTime);
      aForumInfo.setLastTime(postTime);
      aForumInfo.setIPAddress(IP);
      aForumInfo.setIsNew(1);
      aForumInfo.setNickName(myUserInfo.getNickName());
      FormFile file = form.getForm_data();
      boolean isHavePic = false;

      if (file != null && file.getFileName() != null &&
          file.getFileName().length() > 0) {
        if (Util.isAllowFile("pic", file.getFileName()) &&
            file.getFileSize() > 0 &&
            file.getFileSize() <= (Sys.SYSINFO.UPIMGSIZE * 1024)) {
          String imgFileName = "img_" + aID + "_" + postTime +
              Util.getFileExt(file.getFileName());
          aForumInfo.setHavePic(1);
          aForumInfo.setPicName(imgFileName);
          isHavePic = true;
        }
        else {
          errors.add("upnotice",
                     new ActionError("post.upnotice",
                                     String.valueOf(Sys.SYSINFO.UPIMGSIZE)));
          saveErrors(httpServletRequest, errors);
          return actionMapping.findForward("error");
        }
      }
      Forum aForum = ForumFactory.getInstance();
      aForum.setUserInfo(myUserInfo);
      aForum.setForumInfo(aForumInfo);
      aForum.setUserSessionCheck(myUserSessionCheck);

      int result = 0;
      if (isHavePic) {
        result = aForum.createPost(null, "new", file);
      }
      else {
        result = aForum.createPost(null, "new");
      }
      if (result != Sys.RESULT_RIGHT) {
        errors.add("posterror", new ActionError("error.posterror"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      User myUser = myUserSessionCheck.getUser();
      myUser.setUserInfo(aForum.getUserInfo());
      UserSession myUserSession = ServerSession.getSession(form.getSid(),
          httpServletRequest);
      myUserSession.setAttribute("user", myUser);
      ServerSession.upSession(myUserSession);

      errors = null;
      //form = null;
      myUserSessionCheck = null;
      myUserInfo = null;
      theBoards = null;
      IP = null;
      sign_detail = null;
      aForumInfo = null;
      file = null;
      aForum = null;
      myUser = null;
      myUserSession = null;
      /*
             httpServletRequest.setAttribute("aForwardInfo",
                                      new ForwardInfo("",
          Sys.getURL() + "rightAction.do?sid=" + form.getSid() +
          "&bid=" + form.getBid() + "&pages=1"));
             return actionMapping.findForward("forwards");*/

      ActionForward f = new ActionForward("/rightAction.do?sid=" +
                                          form.getSid() +
                                          "&bid=" + form.getBid() + "&pages=1", true);

⌨️ 快捷键说明

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