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

📄 note.java

📁 天乙社区6.0是一套基于JAVA技术的网络虚拟社区
💻 JAVA
字号:
package com.laoer.bbscs.web.action;

import com.laoer.bbscs.web.form.*;
import com.laoer.bbscs.web.servlet.*;
import com.laoer.bbscs.sys.*;
import com.laoer.bbscs.bean.*;
import com.laoer.comm.util.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;

/**
 * <p>Title: TianYi BBS</p>
 * <p>Description: TianYi BBS System</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: LAOER.COM/TIANYISOFT.NET</p>
 * @author laoer
 * @version 6.0
 */

public class Note
    extends BaseAction {

  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse) {
    ActionErrors errors = new ActionErrors();
    NoteForm form = (NoteForm) actionForm;

    UserCheck uc = this.getUserCheck(httpServletRequest, httpServletResponse,
                                     Constant.MESSAGE.getMessage(
                                         httpServletRequest.getLocale(),
                                         "place.note"));
    if (uc.isGuest()) {
      errors.add("error.pleaselogin", new ActionError("error.pleaselogin"));
      saveErrors(httpServletRequest, errors);
      LoginForm loginForm = new LoginForm();
      loginForm.setTourl(SysUtil.getToURL(httpServletRequest,
                                          "note" + Constant.FILEPREFIX));
      /*
             loginForm.setTourl(SysUtil.encodeURL("note" + Constant.FILEPREFIX,
                                           Constant.CHARSET));*/
      httpServletRequest.setAttribute("loginForm", loginForm);

      //return actionMapping.findForward("login");
      return SysUtil.getPassLogin(actionMapping);
    }
    httpServletRequest.setAttribute("uc", uc);
    if (form.getAction().equals("list")) {
      form.setAction("dels");
      Pages pages = new Pages(httpServletRequest);
      pages.setPage(form.getPage());
      pages.setPerPageNum(getSysInfo().getNotenumpage());
      //pages.setPerPageNum(2);
      pages.setFileName("note" + Constant.FILEPREFIX);
      pages.setStyle(1);
      if (form.getT() > 0) {
        pages.setTotals(form.getT());
      }

      PageList pl = getGuestBookService().getGuestBookList(uc.getId(), pages);
      httpServletRequest.setAttribute("pl", pl);
      httpServletRequest.setAttribute("noteForm", form);
      return actionMapping.findForward("notelist");
    }
    if (form.getAction().equals("new")) {
      form.setAction("add");
      httpServletRequest.setAttribute("noteForm", form);
      return actionMapping.findForward("note");
    }
    if (form.getAction().equals("add")) {

      UserInfo toUser = getUserInfoService().findUserInfoByUserName(form.
          getFname());
      if (toUser == null) {
        errors.add("error.user.nouser", new ActionError("error.user.nouser"));
        saveErrors(httpServletRequest, errors);
        httpServletRequest.setAttribute("noteForm", form);
        return actionMapping.findForward("note");
      }
      Friend friend = getFriendService().findMyFriendByName(uc.getUsername(),
          toUser.getId().longValue());
      if (friend != null && friend.getIsBlack() == 1) {
        errors.add("error.note.inblack", new ActionError("error.note.inblack"));
        saveErrors(httpServletRequest, errors);
        httpServletRequest.setAttribute("noteForm", form);
        return actionMapping.findForward("note");
      }
      GuestBook gb = GuestBookFactory.getInstance(toUser.getId().longValue());
      //System.out.println(gb);
      gb.setFromID(uc.getId());
      gb.setFromNickName(uc.getNickname());
      gb.setFromUserName(uc.getUsername());
      gb.setIsNew( (short) 0);
      gb.setMtype(form.getMtype());
      gb.setNote(Util.escapeHTMLTags(form.getNote()));
      gb.setStime(Util.getLongTime());
      gb.setToID(toUser.getId().longValue());
      gb.setToNickName(toUser.getNickname());
      gb.setToUserName(toUser.getUsername());
      if (this.getGuestBookService().saveGuestBook(gb) == null) {
        errors.add("error.addnote", new ActionError("error.addnote"));
        saveErrors(httpServletRequest, errors);
        httpServletRequest.setAttribute("noteForm", form);
        return actionMapping.findForward("note");
      }
      ActionForward forward = new ActionForward(SysUtil.getResultUrl(
          "succeed.addnote", "note" + Constant.FILEPREFIX), true);
      return forward;
    }
    if (form.getAction().equals("read")) {
      GuestBook gb = getGuestBookService().getGuestBook(form.getId(), uc.getId());
      if (gb == null) {
        errors.add("error.nonote", new ActionError("error.nonote"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      if (gb.getIsNew() == 0) {
        gb.setIsNew( (short) 1);
        getGuestBookService().saveGuestBook(gb);
      }
      httpServletRequest.setAttribute("gb", gb);
      return actionMapping.findForward("read");
    }
    if (form.getAction().equals("del")) {
      this.getGuestBookService().removeGuestBook(form.getId(), uc.getId());
      ActionForward forward = new ActionForward("/note" + Constant.FILEPREFIX, true);
      return forward;
    }
    if (form.getAction().equals("dels")) {
      for (int i = 0; i < form.getIds().length; i++) {
        this.getGuestBookService().removeGuestBook(form.getIds()[i], uc.getId());
      }
      ActionForward forward = new ActionForward("/note" + Constant.FILEPREFIX, true);
      return forward;
    }
    if (form.getAction().equals("delall")) {
      this.getGuestBookService().removeAllGuestBook(uc.getId());
      ActionForward forward = new ActionForward("/note" + Constant.FILEPREFIX, true);
      return forward;
    }
    return actionMapping.findForward("error");
  }
}

⌨️ 快捷键说明

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