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

📄 bbsdocaction.java

📁 简易java框架开源论坛系统,简 易java框架开源论坛系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.easyjf.bbs.action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import com.easyjf.bbs.business.ActiveUser;
import com.easyjf.bbs.business.BBSDir;
import com.easyjf.bbs.business.BBSDoc;
import com.easyjf.bbs.business.BBSRights;
import com.easyjf.bbs.business.BBSUtil;
import com.easyjf.bbs.business.UserInfo;
import com.easyjf.bbs.business.Vote;
import com.easyjf.bbs.business.config.BBSConfig;
import com.easyjf.util.CommUtil;
import com.easyjf.util.HtmlUtil;
import com.easyjf.web.ActionContext;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.AbstractCmdAction;
import com.easyjf.web.tools.IPageList;
import com.easyjf.bbs.business.util.*;

/**
 * 
 * <p>
 * Title:BBS栏目处理类
 * </p>
 * <p>
 * Description: BBS目录的列表处理Action,使用EasyJWeb0.5; <br>
 * 通过继承com.easyjf.web.tools.AbstractCmdAction,实现简单的命令式Action处理,去除了复杂烦锁的if else语句
 * </p>
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p>
 * Company: www.easyjf.com
 * </p>
 * 
 * @author 蔡世友
 * @version 1.0
 */
public class BBSDocAction extends AbstractCmdAction {
	/**
	 * 在没有跟任何参数的时候执行,默认显示栏目下的所有帖子信息
	 */
	public Page doInit(WebForm form, Module module) {
		// TODO Auto-generated method stub
		return doQuery(form, module);
	}

	/**
	 * 发表新帖子
	 * 
	 * @param form
	 * @param module
	 * @return 若用户有权限发帖子,则返回发帖页面
	 */
	public Page doNew(WebForm form, Module module) {
		String sn = CommUtil.null2String(form.get("sn"));
		BBSDir dir = BBSDir.readBySN(sn);
		if (getCurrentUser() == null) {
			form.addResult("msg", "您没有登录,不能发表信息!");
			return new Page("login", "/bbs/login.html", "template");
		}
		if (dir != null) {
			form.addResult("dir", dir);
		} else {
			form.addResult("msg", "目录不存在,可能是地址链接错误!");
		}
		return module.findPage("edit");
	}

	/**
	 * 查询帖子
	 * 
	 * @param form
	 * @param module
	 * @return 返回帖子列表
	 */
	public Page doList(WebForm form, Module module) {
		return doQuery(form, module);
	}

	/**
	 * 保存新帖子信息
	 * 
	 * @param form
	 * @param module
	 * @return 返回列表Page或其它
	 */
	public Page doAdd(WebForm form, Module module) {
		BBSDoc obj = new BBSDoc();
		ActiveUser user = getCurrentUser();
		if (user != null) {
			// 在Action中检测权限
			// 以下执行表单对象VO到PO转换的代码,通过使用EasyJWeb验证框架中可以省略
			obj.setTitle(CommUtil.null2String(form.get("title")));
			obj.setDirSn(CommUtil.null2String(form.get("dirSn")));
			if (!BBSRights.checkRights(obj, "add", user))
				return new Page("popedomError", "/bbs/norights.htm", "page");

			obj.setTagPic(CommUtil.null2String(form.get("tagPic")));
			obj.setContent(CommUtil.null2String(form.get("content")));
			obj.setImgs(CommUtil.null2String(form.get("imgs")));
			obj.setFiles(CommUtil.null2String(form.get("files")));
			obj.setParentId(CommUtil.null2String(form.get("parentId")));
			String quotId = CommUtil.null2String(form.get("quotId"));
			if (!quotId.equals(""))// 处理引用回复
			{
				BBSDoc quot = BBSDoc.read(quotId);
				if (quot != null) {
					String QuotoSs = (quot.getContent().length() > 50 ? quot
							.getContent().substring(0, 50)
							+ "..." : quot.getContent());
					String QuotoS = "[QUOTE]" + QuotoSs + "[/QUOTE]";
					obj.setContent(QuotoS + obj.getContent());
				}
			}

			boolean op = obj.getParentId().equals("") ? BBSUtil.publishMessage(
					user, obj) : BBSUtil.replyMessage(user, obj);
			// System.out.println(op);
			if (op) {
				form.addResult("msg", "信息发布成功!");
			} else {
				form.addResult("msg", "信息发布失败");
			}
		} else {
			form.addResult("msg", "您没有登录,不能发表文章!");
			return new Page("login", "/bbsuser.ejf", "template");
		}
		return new Page("bbsList", "/bbsdoc.ejf?easyJWebCommand=show&&cid="
				+ obj.getCid(), "page");
	}

	public Page doTry(WebForm form, Module module) {
		
		form.addResult("hostname", BBSConfig.getInstance().getHost_name());
		form.addResult("list", BBSUtil.getWeekMessages());
		ActionContext.getContext().getResponse().setContentType("text/xml");
		ActionContext.getContext().getResponse().setCharacterEncoding("utf-8");

		try {
			ActionContext.getContext().getResponse().flushBuffer();
		} catch (Exception e) {

		}

		return module.findPage("rss");

	}

	/**
	 * 修改帖子信息
	 * 
	 * @param form
	 * @param module
	 * @return 返回帖子列表Page
	 */
	public Page doUpdate(WebForm form, Module module) {
		String cid = CommUtil.null2String(form.get("cid"));
		ActiveUser user = getCurrentUser();
		BBSDoc obj = BBSDoc.read(cid);
		if (user != null) {
			if (obj != null) {
				// 在Action中检测权限
				// 以下执行表单对象VO到PO转换的代码,通过使用EasyJWeb验证框架中可以省略
				if (!BBSRights.checkRights(obj, "update", user))
					return new Page("popedomError", "/bbs/norights.htm", "page");
				obj.setTitle(CommUtil.null2String(form.get("title")));
				obj.setDirSn(CommUtil.null2String(form.get("dirSn")));
				obj.setTagPic(CommUtil.null2String(form.get("tagPic")));
				obj.setContent(CommUtil.null2String(form.get("content")));
				obj.setImgs(CommUtil.null2String(form.get("imgs")));
				obj.setFiles(CommUtil.null2String(form.get("files")));
				obj.setParentId(CommUtil.null2String(form.get("parentId")));
				obj.setModifyTime(new Date());
				obj.update();
			} else {
				form.addResult("msg", "所要修改的目录不存在!");
			}
		} else {
			form.addResult("msg", "您没有登录,不能发表文章!");
			return new Page("login", "/bbsuser.ejf", "template");
		}
		return new Page("bbsList", "/bbsdoc.ejf?easyJWebCommand=list&&sn="
				+ obj.getDirSn(), "page");
	}

	/**
	 * 显示帖子内容
	 * 
	 * @param form
	 * @param module
	 * @return 返回显示帖子的Page
	 */
	public Page doShow(WebForm form, Module module) {
		String cid = CommUtil.null2String(form.get("cid"));
		int currentPage = CommUtil.null2Int(form.get("page"));
		int pageSize = CommUtil.null2Int(form.get("pageSize"));
		ActiveUser user = getCurrentUser();
		BBSDoc obj = BBSDoc.read(cid);
		if(obj.getHasvote().intValue()==1){
			System.out.println("vote is not null");
			Vote vote=Vote.readByDoc(obj.getCid());
			System.out.println("read by doc");
			List voteitems=VoteUtil.resultById(vote.getCid());
			System.out.println("result by id");
			form.addResult("vote",vote);
			form.addResult("voteitem",voteitems);
		}
		if (obj != null) {
			if (!BBSRights.checkRights(obj, "show", user))
				return new Page("popedomError", "/bbs/norights.htm", "page");
			if (currentPage < 1)
				currentPage = 1;
			if (pageSize < 1)
				pageSize = 15;
			BBSDir dir = BBSDir.readBySN(obj.getDirSn());
			if (dir != null) {
				form.addResult("dir", dir);
			} else {
				form.addResult("msg", "目录不存在,可能是地址链接错误!");
			}
			form.addResult("user", user);
			// 显示并处理主题信息
			// 以下执行表单对象PO到VO转换的代码,大部分在使用EasyJWeb验证框架中可以省略
			form.addResult("cid", obj.getCid());
			form.addResult("title", obj.getTitle());
			form.addResult("content", HtmlUtil
					.getUBB2HTML(replaceEmotTag(HtmlUtil.escapeHTMLTag(obj
							.getContent()))));
			form.addResult("inputUser", obj.getInputTime());
			form.addResult("modifyTime", obj.getModifyTime());
			if (obj.getTagPic() != null && (!obj.getTagPic().equals("")))
				form.addResult("tagPic", obj.getTagPic());
			if (obj.getImgs() != null && (!obj.getImgs().equals("")))
				form.addResult("imgs", obj.getImgs());
			form.addResult("files", obj.getFiles());
			form.addResult("ip", obj.getIp());
			if (user != null) {
				if (BBSRights.checkRights(obj, "setTopMessage", user))// 置顶
					form.addResult("topMessage", "true");
				if (BBSRights.checkRights(obj, "setEliteMessage", user))// 精华
					form.addResult("eliteMessage", "true");
				if (BBSRights.checkRights(obj, "lockMessage", user))// 锁定
					form.addResult("lockMessage", "true");
				if (BBSRights.checkRights(obj, "editMessage", user))// 修改
					form.addResult("editMessage", "true");
				if (BBSRights.checkRights(obj, "delMessage", user))// 删帖
					form.addResult("delMessage", "true");
				if (BBSRights.checkRights(obj, "moveMessage", user))// 移动
					form.addResult("moveMessage", "true");
				if (BBSRights.checkRights(obj, "lockUser", user))// 锁定用户
					form.addResult("lockUser", "true");
			}
			// 取得发帖人的相关信息
			UserInfo inputUser = UserInfo.readByUserName(obj.getInputUser());
			
			if (inputUser != null) {
				form.addResult("userName", inputUser.getUserName());
				form.addResult("userScore", inputUser.getScore());
				form.addResult("userQq", inputUser.getQq());
				form.addResult("userCid", inputUser.getCid());
				form.addResult("userSign", inputUser.getIntro());
				form.addResult("userPhoto", inputUser.getPhoto());
			}
			// 保存点击数
			obj.setReadTimes(new Integer(obj.getReadTimes() != null ? obj
					.getReadTimes().intValue() + 1 : 1));
			obj.update();
			// 处理回复信息
			IPageList pList = BBSUtil.queryReply(obj, pageSize, currentPage);
			List replyList = new ArrayList();
			if (pList != null) {
				List list = pList.getResult();
				if (list != null) {
					for (int i = 0; i < list.size(); i++) {
						Map map = new HashMap();
						BBSDoc reply = (BBSDoc) list.get(i);
						map.put("cid", reply.getCid());
						map.put("title", reply.getTitle());
						map.put("content", HtmlUtil
								.getUBB2HTML(replaceEmotTag(HtmlUtil
										.escapeHTMLTag(reply.getContent()))));
						map.put("inputTime", reply.getInputTime());
						map.put("modifyTime", reply.getModifyTime());
						map.put("ip", reply.getIp());
						map.put("imgs", reply.getImgs() != null ? (reply
								.getImgs().equals("") ? null : reply.getImgs())
								: null);

						map.put("files", reply.getFiles());
						if (reply.getTagPic() != null
								&& (!reply.getTagPic().equals("")))
							map.put("tagPic", reply.getTagPic());
						map.put("floor", new Integer((pageSize
								* (currentPage - 1) + i + 1)));

⌨️ 快捷键说明

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