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

📄 forumaction.java

📁 在线读书交流平台
💻 JAVA
字号:
package com.olr.control.club;

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

import org.apache.log4j.Logger;

import com.olr.BO.ClubBO;
import com.olr.beans.Forum;
import com.olr.beans.Topic;
import com.olr.control.common.PageAction;
import com.olr.util.Constants;
import com.olr.util.Pager;

public  class ForumAction extends PageAction{
	private ClubBO clubBO;
	//论坛相关字段
	private Integer forumId;
	private String forumName;
	private String masterName;
	private String description;
	private Integer topicCount;
	//帖子相关字段
	private Integer topicId;
	private Integer parentId=-1;
	private String topicName;
	private String content;
	private String username;
	private Date postdate;
	private Integer replies;
	
	
	private Pager forumPager;
	private Pager parentTopicPager;
	
	
	private Forum forum;
	private Topic topic;
	private List<Topic> childList;
	private List<Forum> hotClubList;
	private List<Forum> newClubList;
	//初始化论坛首页,获取最热门的讨论区列表
	Logger log = Logger.getLogger(this.getClass());
	
	public void validate(){
		this.clearErrorsAndMessages();
	}
	
	public  String clubIndex() {
		log.info("进入论坛首页");
		username=this.getLoginUsername();
		if(hotClubList==null||newClubList==null){
			hotClubList=this.getClubBO().getHotClubs();
			newClubList=this.getClubBO().getNewClubs();
		}
		//this.setSession("hotClubList", hotClubList);
		//this.setSession("newClubList",newClubList);
		return "clubIndex";
	}
	
	public String initForum(){
		log.info("初始化论坛列表");
		this.clearErrorsAndMessages();
		super.pageSize=Constants.pageSize;
		super.pageNo=Constants.pageNo;
		super.pager=this.getClubBO().getForumPager(pageSize, pageNo);
		forumPager=super.pager;
		//this.setSession("forumPager", super.pager);
		return "forumList";
	}
	
	public String listForum(){
		log.info("翻页论坛列表");
		this.clearErrorsAndMessages();
		super.pager=this.getClubBO().getForumPager(pageSize, pageNo);
		forumPager=super.pager;
		//this.setSession("forumPager", super.pager);
		return "forumList";
	}
	
	
	public String newForum(){
		if(!this.isLogin()){
			this.addFieldError("forumError", "只有注册用户才能执行此操作");
			return this.clubIndex();
		}else if(!this.getClubBO().check(this.getLoginUsername())){			
			this.addFieldError("forumError","只有等级为10以上的用户才能执行此操作");
			return this.clubIndex();
		}
		log.info("新建板块");
		this.setForumName("");
		this.setDescription("");
		return "forumAdd";
	}
	
	public String addForum(){
		Forum forum=new Forum();
		forum.setForumName(forumName);
		forum.setDescription(description);
		forum.setMasterName(this.getLoginUsername());
		forum.setTopicCount(0);
		this.getClubBO().addForum(forum);
		log.info("添加板块成功");
		newClubList=this.getClubBO().getNewClubs();
		return this.clubIndex();
	}
	
	public String deleteForum(){
		if(!this.isLogin()){
			this.addFieldError("forumError", "只有注册用户才能执行此操作");
			return this.clubIndex();
		}else if(!this.getClubBO().check(this.getLoginUsername())){			
			this.addFieldError("forumError","只有等级为10以上的用户才能执行此操作");
			return this.clubIndex();
		}
		this.getClubBO().deleteForum(forumId);
		log.info("删除板块成功");
		hotClubList=this.getClubBO().getHotClubs();
		newClubList=this.getClubBO().getNewClubs();
		return this.clubIndex();
		
	}
	
	public String editForum(){
		if(!this.isLogin()){
			this.addFieldError("forumError", "只有注册用户才能执行此操作");
			return this.clubIndex();
		}else if(!this.getClubBO().check(this.getLoginUsername())){			
			this.addFieldError("forumError","只有等级为10以上的用户才能执行此操作");
			return this.clubIndex();
		}
		forum=this.getClubBO().getForum(forumId);		
		return "forumEdit";
	}
	
	public String updateForum(){
		Forum forum1=new Forum();
		forum1.setForumId(forumId);
		forum1.setForumName(forumName);
		forum1.setDescription(description);
		forum1.setMasterName(this.getForum().getMasterName());
		this.getClubBO().updateForum(forum1);
		return this.clubIndex();
	}
	
	public String initTopic(){
		this.clearErrorsAndMessages();
		super.pageSize=Constants.pageSize;
		super.pageNo=Constants.pageNo;
		super.pager=this.getClubBO().getParentTopicPager(forumId, pageNo, pageSize);
		forum = this.getClubBO().getForum(forumId);
		forumName=forum.getForumName();
		masterName=forum.getMasterName();
		parentTopicPager=super.pager;
		//this.setSession("parentTopicPager", super.pager);
		return "forum";
	}
	
	public String listTopic(){

		this.setForum(this.getClubBO().getForum(forumId));
		super.pager=this.getClubBO().getParentTopicPager(forumId, pageNo, pageSize);
		parentTopicPager=super.pager;
		//this.setSession("parentTopicPager", super.pager);
		return "forum";
	}
	
	public String newTopic(){
		if(!this.isLogin()){
			this.addFieldError("topicError","只有注册用户才能执行此操作");
			return this.listTopic();
		}
		this.setParentId(-1);
		this.setTopicName("");
		this.setContent("");
		return "topicAdd";
	}
	
	public String showTopic(){
		
		topic=this.getClubBO().getTopic(topicId);
		topic.setContent(topic.getContent().replaceAll("\r\n","<br/>"));
		this.setTopic(topic);
		//parentId=topic.getParentId();
		this.setChildList(this.getClubBO().getChildList(topic.getTopicId()));
		this.setParentId(topic.getTopicId());
		return "topic";
		
	}
	
	public String addTopic(){
		if(!this.isLogin()){
			this.addFieldError("topicError","只有注册用户才能执行此操作");
			return "login";
		}
		if(parentId==-1){//新建帖子
			Topic topic1 =new Topic();
			topic1.setForumId(forumId);
			topic1.setTopicName(topicName);
			topic1.setPostdate(new Date());
			topic1.setParentId(0);
			topic1.setUsername(this.getLoginUsername());
			topic1.setContent(content);
			topic1.setReplies(0);
			this.getClubBO().addTopic(topic1);
			this.setTopicId(topic1.getTopicId());
			this.setParentId(topicId);
			this.setTopic(topic1);
		}else{//回复帖子
			Topic topic2=new Topic();
			topic2.setUsername(this.getLoginUsername());
			topic2.setPostdate(new Date());
			topic2.setParentId(topicId);
			topic2.setContent(content);
			topic2.setForumId(forumId);
			this.getClubBO().addTopic(topic2);
		}
		//this.setChildList(this.getClubBO().getChildList(topic.getTopicId()));
		return this.showTopic();
		
	
	}
	
	public String deleteTopic(){
		this.getClubBO().deleteTopic(topicId);
		return this.listTopic();
	}
	
	
	
	
	public ClubBO getClubBO() {
		return clubBO;
	}
	public void setClubBO(ClubBO clubBO) {
		this.clubBO = clubBO;
	}
	public Integer getForumId() {
		return forumId;
	}
	public void setForumId(Integer forumId) {
		this.forumId = forumId;
	}
	public String getForumName() {
		return forumName;
	}
	public void setForumName(String forumName) {
		this.forumName = forumName;
	}
	public String getMasterName() {
		return masterName;
	}
	public void setMasterName(String masterName) {
		this.masterName = masterName;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Integer getTopicCount() {
		return topicCount;
	}
	public void setTopicCount(Integer topicCount) {
		this.topicCount = topicCount;
	}

	public Integer getTopicId() {
		return topicId;
	}

	public void setTopicId(Integer topicId) {
		this.topicId = topicId;
	}

	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public String getTopicName() {
		return topicName;
	}

	public void setTopicName(String topicName) {
		this.topicName = topicName;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Date getPostdate() {
		return postdate;
	}

	public void setPostdate(Date postdate) {
		this.postdate = postdate;
	}

	public Integer getReplies() {
		return replies;
	}

	public void setReplies(Integer replies) {
		this.replies = replies;
	}

	public Forum getForum() {
		return forum;
	}

	public void setForum(Forum forum) {
		this.forum = forum;
	}

	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	public List<Topic> getChildList() {
		return childList;
	}

	public void setChildList(List<Topic> childList) {
		this.childList = childList;
	}

	public Pager getForumPager() {
		return forumPager;
	}

	public void setForumPager(Pager forumPager) {
		this.forumPager = forumPager;
	}

	public Pager getParentTopicPager() {
		return parentTopicPager;
	}

	public void setParentTopicPager(Pager parentTopicPager) {
		this.parentTopicPager = parentTopicPager;
	}

	public List<Forum> getHotClubList() {
		return hotClubList;
	}

	public void setHotClubList(List<Forum> hotClubList) {
		this.hotClubList = hotClubList;
	}

	public List<Forum> getNewClubList() {
		return newClubList;
	}

	public void setNewClubList(List<Forum> newClubList) {
		this.newClubList = newClubList;
	}
	
	

}

⌨️ 快捷键说明

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