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

📄 myfriend.java

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

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

/**
 * <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 MyFriend
    extends BaseAction {

  public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse) {
    ActionErrors errors = new ActionErrors();
    FriendForm form = (FriendForm) actionForm;
    UserCheck uc = this.getUserCheck(httpServletRequest, httpServletResponse,
                                     Constant.MESSAGE.getMessage(
                                         httpServletRequest.getLocale(),
                                         "place.friend"));
    if (uc.isGuest()) {
      errors.add("error.pleaselogin", new ActionError("error.pleaselogin"));
      saveErrors(httpServletRequest, errors);
      LoginForm loginForm = new LoginForm();
      loginForm.setTourl(SysUtil.getToURL(httpServletRequest,
                                          "friend" + Constant.FILEPREFIX));
      /*
       loginForm.setTourl(SysUtil.encodeURL("friend" + Constant.FILEPREFIX,
                                           Constant.CHARSET));*/
      httpServletRequest.setAttribute("loginForm", loginForm);

      //return actionMapping.findForward("login");
      return SysUtil.getPassLogin(actionMapping);
    }
    if (form.getAction().equals("list")) {
      List myFriend = getFriendService().findFriends(uc.getId(), (short) 0);
      List black = this.getFriendService().findFriends(uc.getId(), (short) 1);
      httpServletRequest.setAttribute("myFriend", myFriend);
      httpServletRequest.setAttribute("black", black);
      return actionMapping.findForward("friend");
    }
    if (form.getAction().equals("add")) {
      if (this.getFriendService().getMyFriendNum(uc.getId(), (short) 0) >=
          SysInfo.getInstance().getFriendnum()) {
        errors.add("error.friendtoolong", new ActionError("error.friendtoolong"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      UserInfo fui = getUserInfoService().findUserInfoByUserName(form.getFname());
      if (fui == null) {
        errors.add("friendnameno", new ActionError("error.friendnameno"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      Friend f = getFriendService().findMyFriendByName(form.getFname(),
          uc.getId());
      if (f != null) {
        errors.add("friendexist", new ActionError("error.friendexist"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }

      f = FriendFactory.getInstance(uc.getId());
      f.setFid(fui.getId().longValue());
      f.setFname(form.getFname());
      f.setIsBlack( (short) 0);
      f.setUserID(uc.getId());
      f.setUserName(uc.getUsername());
      f.setFcomment(form.getComment());
      if (getFriendService().addFriend(f) == null) {
        errors.add("friendadderror", new ActionError("error.friendadderror"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }

      ActionForward forward = new ActionForward(SysUtil.getResultUrl(
          "succeed.friendadd", "friend" + Constant.FILEPREFIX), true);
      return forward;
    }
    if (form.getAction().equals("addb")) {
      if (this.getFriendService().getMyFriendNum(uc.getId(), (short) 1) >=
          SysInfo.getInstance().getFriendnum()) {
        errors.add("error.friendtoolong", new ActionError("error.friendtoolong"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      UserInfo fui = getUserInfoService().findUserInfoByUserName(form.getFname());
      if (fui == null) {
        errors.add("friendnameno", new ActionError("error.friendnameno"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      Friend f = getFriendService().findMyFriendByName(form.getFname(),
          uc.getId());
      if (f != null) {
        errors.add("friendexist", new ActionError("error.friendexist"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      f = FriendFactory.getInstance(uc.getId());
      f.setFid(fui.getId().longValue());
      f.setFname(form.getFname());
      f.setIsBlack( (short) 1);
      f.setUserID(uc.getId());
      f.setUserName(uc.getUsername());
      f.setFcomment(form.getComment());
      if (getFriendService().saveFriend(f) == null) {
        errors.add("friendadderror", new ActionError("error.friendadderror"));
        saveErrors(httpServletRequest, errors);
        return actionMapping.findForward("error");
      }
      ActionForward forward = new ActionForward(SysUtil.getResultUrl(
          "succeed.blackadd", "friend" + Constant.FILEPREFIX), true);
      return forward;
    }
    if (form.getAction().equals("del")) {
      getFriendService().delFriend(form.getId(), uc.getId());
      ActionForward f = new ActionForward("/friend" + Constant.FILEPREFIX, true);
      return f;
    }
    return actionMapping.findForward("error");
  }
}

⌨️ 快捷键说明

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