📄 replyaction.java
字号:
package com.ntsky.bbs.action;
import java.util.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.log4j.Logger ;
import com.ntsky.bbs.action.Constant;
import com.ntsky.bbs.form.ReplyActionForm;
import com.ntsky.bbs.service.User;
import com.ntsky.bbs.service.*;
import com.ntsky.bbs.service.db.*;
import com.ntsky.bbs.service.ReplyFactory;
/**
* <p>Title: Ntsky OpenSource BBS</p>
* <p>Description: 回复信息</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: WWW.FM880.COM</p>
* @author 姚君林
* @version 1.0
*/
public class ReplyAction extends Action {
private final static Logger logger = Logger.getLogger(ReplyAction.class);
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception{
/**@todo: complete the business logic here, this is just a skeleton.*/
ReplyActionForm replyActionForm = new ReplyActionForm();
HttpSession session = httpServletRequest.getSession();
httpServletRequest.setAttribute(actionMapping.getAttribute(), replyActionForm);
String topicId = httpServletRequest.getParameter("topicId");
String repId = httpServletRequest.getParameter("repId");
String action = httpServletRequest.getParameter("action");
logger.info("数据操作的类型 : " + action);
/**
* 从用户session中获取整个用户信息
*/
BoardFilter boardFilter = BoardFilter.getInstance();
User user = (User)session.getAttribute(Constant.USER_KEY);
if( user == null ){
String uri = httpServletRequest.getRequestURI();
logger.info("uri = " + uri);
if( topicId == null ){
session.setAttribute("uri",
uri + "?action=" + action +"&repId=" + repId);
}
else{
session.setAttribute("uri",
uri + "?action=" + action +"&topicId=" + topicId);
}
}
//检测用户是否登陆
boardFilter.checkUserLogon(httpServletResponse,httpServletRequest,user);
//权限控制
Map userMap = UserFilter.getInstance().filterUser(session,httpServletRequest);
String rightStr = boardFilter.filterBoard(httpServletRequest,httpServletResponse,session);
session.setAttribute("rightStr",rightStr); //该session的值在tiles页面打开时被调用
logger.info("权限判断完毕--------");
replyActionForm.setAction(action);
//添加回复
if((Constant.CREATE).equals(action)){
Topic topic = TopicUtil.listTopic(Integer.parseInt(topicId));
//回复操作前的检测
logger.info("topic = " + topic.getTopicLock());
logger.info("topic.getTopicLock()" + (topic.getTopicLock() == 1));
if(topic.getTopicLock() == 1){
String string_lock = "<script>alert(\"该主题已经被锁定,您不能进行回复操作!\")</script>";
httpServletRequest.setAttribute("action","topicLock");
httpServletRequest.setAttribute("topicLockStr", string_lock);
httpServletRequest.setAttribute("topicId",topicId);
return actionMapping.findForward("success");
}
replyActionForm.setRepTopicId(Integer.parseInt(topicId));
replyActionForm.setRepUsrName(user.getUsrName());
String topicTitle = topic.getTopicTitle();
httpServletRequest.setAttribute("topicTitle",topicTitle.substring(1,topicTitle.length()));
logger.info("进行添加赋值操作.....");
}
if((Constant.EDIT).equals(action)){
int tempRepId = Integer.parseInt(repId);
//修改回复情况
Reply reply = ReplyFactory.getInstance().listReplySin(tempRepId);
if(reply.getRepUsrName().equals(user.getUsrName())){
int tempTopicId = reply.getRepTopicId();
replyActionForm.setRepTopicId(tempTopicId);
String topicTitle = TopicUtil.listTopic(tempTopicId).
getTopicTitle();
httpServletRequest.setAttribute("topicTitle",
topicTitle.
substring(1, topicTitle.length()));
replyActionForm.setRepId(tempRepId);
//replyActionForm.setRepUsrName(user.getUsrName());
replyActionForm.setRepContent(reply.getRepContent());
}
else {
String string =
"<script>alert(\"Sorry!您不能修改信息\\r\\n您不是该回复信息的作者!~~~~\")</script>";
httpServletRequest.setAttribute("action", "upReplyError");
httpServletRequest.setAttribute("topicId",String.valueOf(reply.getRepTopicId()));
httpServletRequest.setAttribute("upReplyError", string);
return actionMapping.findForward("success");
}
logger.info("进行修改操作.....");
}
//删除回复
if((Constant.DELETE).equals(action)){
//本版斑竹,大斑竹,区长可以删除信息
int tempTopicId = ReplyFactory.getInstance().listReplySin(Integer.parseInt(repId)).getRepTopicId();
Topic topic = TopicUtil.listTopic(tempTopicId);
List list = BoardUtil.masterArray(topic.getTopicBoaId());
//如果该用户是管理员,执行删除
logger.info("usrName = " + user.getUsrName());
logger.info("包含用户有 : " + list.contains(user.getUsrName()));
Manager manager = new DBManager();
String usrName = user.getUsrName();
if ( (list.contains(usrName)) ||
(manager.AdminArray().contains(usrName))) {
ReplyFactory.getInstance().delReply(Integer.parseInt(repId));
String string = "<script>alert(\"删除回复成功!\")</script>";
httpServletRequest.setAttribute("action", "delReplyOk");
httpServletRequest.setAttribute("topicId",
String.valueOf(tempTopicId));
httpServletRequest.setAttribute("deleteOk", string);
logger.info("删除成功");
return actionMapping.findForward("success");
}
else {
logger.info("删除失败");
String string = "<script>alert(\"您不是管理员,不能删除该回复信息!\")</script>";
httpServletRequest.setAttribute("action", "delReplyError");
httpServletRequest.setAttribute("deleteError", string);
httpServletRequest.setAttribute("topicId", String.valueOf(tempTopicId));
logger.info("删除不成功返回到页面");
return actionMapping.findForward("success");
}
}
//公共跳转,没有条件的时就是在浏览的时候直接回复
return actionMapping.findForward("continue");
//throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -