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

📄 replyaction.java

📁 一个成熟的论坛
💻 JAVA
字号:
package com.singnet.web.action;

import java.io.File;
import java.util.Date;

import com.opensymphony.util.TextUtils;
import com.singnet.bean.NsForum;
import com.singnet.bean.NsReply;
import com.singnet.bean.NsRole;
import com.singnet.bean.NsThread;
import com.singnet.bean.NsUser;
import com.singnet.data.Constants;
import com.singnet.dwr.*;
import com.singnet.data.*;

public class ReplyAction extends BaseAction
{
	
	public final static String 		LIST = "list";
	
	private NsReply					reply;
	private INsReplyProxy			nsReplyProxy;	
	private PageData				pageList;	
	private int						pageNo = 1;
	private int						replyPageNo = 1;
	private File					file;
	private String					contentType;
	private String					fileName;
	private INsRoleProxy			nsRoleProxy;

	@Override
	public String execute() throws Exception
	{
		// TODO Auto-generated method stub
		NsUser user = getCurrentUser();
		loadParentForum();
		//如果用户不是管理员和系统管理员,则判断组权限
		if(user == null) {			
			addActionError(getText("user.data.error"));
			System.out.println("user error!");
			return ERROR;
		}
		else {
			if(user != null && !nsRoleProxy.isUserIdentity(user.getUserId(), NsRole.ROLE_SUPERADMIN) && 
					!nsRoleProxy.isUserIdentity(user.getUserId(), NsRole.ROLE_ADMIN)) {
				
				if(nsForumProxy.isVisit(parentForum, NsForum.VISIT_CLOSE)) {
					//add error msg
					addActionError(getText("forum.not.visitable"));
					System.out.println("forum not visistable!");
					return ERROR;
				}
				
				if(nsForumProxy.isWritable(parentForum, NsForum.STATE_READ_ONLY)) {
					addActionError(getText("forum.not.writable"));
					System.out.println("forum not writable!");
					return ERROR;
				}
				if(!nsForumProxy.isGroupVisit(parentForum, user.getUserGroupID().longValue())) {
					//add error msg
					addActionError(getText("group.visit.access"));
					System.out.println("group not visistable!");
					return ERROR;
				}
				if(!nsForumProxy.isGroupReply(parentForum, user.getUserGroupID().longValue())) {
					//add error msg
					addActionError(getText("group.reply.access"));
					System.out.println("group.reply.access!");
					return ERROR;
				}
			}
			
		}
		refineReply();
		nsReplyProxy.saveReply(reply);
		addActionMessage(getText("reply.success"));
		return SUCCESS;
	}
	
	public String loadReplyList() throws Exception
	{
		NsUser user = getCurrentUser();
		loadParentForum();
		//如果用户不是管理员和系统管理员,则判断组权限
		if(user == null) {
			if(nsForumProxy.isVisit(parentForum, NsForum.VISIT_CLOSE)) {
				addActionError(getText("forum.not.visitable"));
				System.out.println("forum not visistable!");
				return ERROR;
			}
			else if(nsForumProxy.isVisit(parentForum, NsForum.VISIT_LOGIN)) {
				addActionError(getText("forum.need.login"));
				System.out.println("forum.need.login!");
				return ERROR;
			}
		}
		else if(user != null && !nsRoleProxy.isUserIdentity(user.getUserId(), NsRole.ROLE_SUPERADMIN) 
				&& !nsRoleProxy.isUserIdentity(user.getUserId(), NsRole.ROLE_ADMIN)) {
			
			if(nsForumProxy.isVisit(parentForum, NsForum.VISIT_CLOSE)) {
				addActionError(getText("forum.not.visitable"));
				System.out.println("forum not visistable!");
				return ERROR;
			}
			
			if(!nsForumProxy.isGroupVisit(parentForum, user.getUserGroupID().longValue())) {
				addActionError(getText("group.visit.access"));
				System.out.println("group not visistable!");
				return ERROR;
			}
		}
		
		if(loadParentThread() != null) {
			pageList = nsReplyProxy.loadPageList(threadID, replyPageNo);
			loadParentForum();
			return LIST;
		}
		
		return SUCCESS;
	}
	
	private void refineReply()
	{
		reply.setPostCtime(new Date());
		reply.setPostPid(new Long(threadID));
		reply.setPostUser(getSessionFieldValue(Constants.SESSION_UNAME).toString());
		reply.setPostUid(getSessionFieldValue(Constants.SESSION_UID).toString());
		String title = reply.getPostTitle();
		reply.setPostTitle(TextUtils.htmlEncode(title));
		NsThread thread = nsThreadProxy.loadThread(threadID);
		if(thread != null) {
			thread.setPostUtime(new Date());
			thread.setPostReply(thread.getPostReply().longValue() + 1);
			nsThreadProxy.saveThread(thread);
		}
	}
	
	public NsReply getReply()
	{
		return reply;
	}

	public void setReply(NsReply reply)
	{
		this.reply = reply;
	}

	public long getThreadID()
	{
		return threadID;
	}

	public void setThreadID(long threadID)
	{
		this.threadID = threadID;
	}

	public void setNsThreadProxy(INsThreadProxy nsThreadProxy)
	{
		this.nsThreadProxy = nsThreadProxy;
	}

	public PageData getPageList()
	{
		return pageList;
	}

	public void setNsReplyProxy(INsReplyProxy nsReplyProxy)
	{
		this.nsReplyProxy = nsReplyProxy;
	}

	public int getPageNo()
	{
		return pageNo;
	}

	public void setPageNo(int pageNo)
	{
		this.pageNo = pageNo;
	}

	public int getReplyPageNo()
	{
		return replyPageNo;
	}

	public void setReplyPageNo(int replyPageNo)
	{
		this.replyPageNo = replyPageNo;
	}

	public void setUploadContentType(String contentType)
	{
		this.contentType = contentType;
	}

	public void setUploadFile(File file)
	{
		this.file = file;
	}

	public void setUploadFileName(String fileName)
	{
		this.fileName = fileName;
	}

	public void setNsRoleProxy(INsRoleProxy nsRoleProxy)
	{
		this.nsRoleProxy = nsRoleProxy;
	}
}

⌨️ 快捷键说明

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