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

📄 threadaction.java

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

import java.util.Date;
import java.util.List;

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

import com.singnet.dwr.INsRoleProxy;

public class ThreadAction extends BaseAction
{
	
	public final static String 		LIST = "list";
	public final static String		FORUM_INFO = "foruminfo";
	
	private NsThread				thread;
	private int						pageNo = 1;
	private PageData				pageList;
	private List					greatList;
	private INsIndexProxy			nsIndexProxy;
	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.isGroupPost(parentForum, user.getUserGroupID().longValue())) {
					//add error msg
					addActionError(getText("group.post.access"));
					System.out.println("group not postable!");
					return ERROR;
				}
			}			
		}
		
		refineThread();
		nsThreadProxy.saveThread(thread);
		addActionMessage(getText("post.success"));
		return SUCCESS;
	}
	
	@Override
	public String doDefault() 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.isGroupPost(parentForum, user.getUserGroupID().longValue())) {
					//add error msg
					addActionError(getText("group.post.access"));
					System.out.println("group not postable!");
					return ERROR;
				}
			}			
		}
		
		return INPUT;
	}
	
	public String loadThreadList() throws Exception
	{
		NsUser user = getCurrentUser();
		loadParentForum();
		//如果用户不是管理员和系统管理员,则判断组权限
		if(user == null) {
			if(nsForumProxy.isVisit(parentForum, NsForum.VISIT_CLOSE)) {
				pageList = null;
				return LIST;
			}
			else if(nsForumProxy.isVisit(parentForum, NsForum.VISIT_LOGIN)) {
				pageList = null;
				return LIST;
			}
		}
		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)) {
				pageList = null;
				return LIST;
			}
			
			if(!nsForumProxy.isGroupVisit(parentForum, user.getUserGroupID().longValue())) {
				//add error msg
				pageList = null;
				return LIST;
			}
		}
		
		pageList = nsThreadProxy.loadPageList(forumID, pageNo);
		if(parentForum.getForumCount().longValue() != pageList.getTotalCount()) {
			parentForum.setForumCount(new Long(pageList.getTotalCount()));
			nsForumProxy.saveOrUpdateForum(parentForum);
		}
		return LIST;
	}
	
	public String loadForumInfo() 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;
			}
		}
		greatList = nsIndexProxy.getHighList(forumID);
		return FORUM_INFO;
	}
	
	private void refineThread() 
	{
		Date date = new Date();
		thread.setPostPid(new Long(forumID));
		thread.setPostCtime(date);
		thread.setPostUtime(date);
		thread.setPostHit(new Long(0));
		thread.setPostReply(new Long(0));
		thread.setPostUser(getSessionFieldValue(Constants.SESSION_UNAME).toString());
		thread.setPostUid(getSessionFieldValue(Constants.SESSION_UID).toString());
		String title = thread.getPostTitle();
		thread.setPostTitle(TextUtils.htmlEncode(title));
	}

	public void setThread(NsThread thread)
	{
		this.thread = thread;
	}

	public NsThread getThread()
	{
		return thread;
	}

	public int getPageNo()
	{
		return pageNo;
	}

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

	public PageData getPageList()
	{
		return pageList;
	}

	public List getGreatList()
	{
		return greatList;
	}

	public void setNsIndexProxy(INsIndexProxy nsIndexProxy)
	{
		this.nsIndexProxy = nsIndexProxy;
	}

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

	
}

⌨️ 快捷键说明

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