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

📄 topic.java

📁 tbuy1.1.5是在netbeans环境下用JSF技术编写的一个论坛tbuy1.1.5是在netbeans环境下用JSF技术编写的一个论坛
💻 JAVA
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! */package biz.tbuy.bbs.bean;import biz.tbuy.bbs.CommonAction;import biz.tbuy.bbs.FileModel;import biz.tbuy.bbs.MusicModel;import biz.tbuy.bbs.ReplyBuilder;import biz.tbuy.bbs.ReplyFactory;import biz.tbuy.bbs.ReplyModel;import biz.tbuy.bbs.StorageAction;import biz.tbuy.bbs.StorageModel;import biz.tbuy.bbs.TopicAction;import biz.tbuy.bbs.TopicBuilder;import biz.tbuy.bbs.TopicFactory;import biz.tbuy.bbs.TopicModel;import biz.tbuy.bbs.UserinfoModel;import biz.tbuy.common.Constants;import biz.tbuy.common.Utils;import biz.tbuy.common.page.DataPage;import biz.tbuy.common.page.PagedListDataModel;import biz.tbuy.share.StringFilter;import java.util.List;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;import javax.el.ELContext;import javax.el.ValueExpression;import javax.faces.component.UIData;import javax.faces.event.ActionEvent;import javax.servlet.http.HttpServletRequest;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class Topic extends BaseBean{    private TopicModel _topic;      // 发表的主题    private UserinfoModel _userinfo;// 发表主题的作者信息    private List<FileModel> _files; // 包含该主题相关联的上传文件    private MusicModel _music;      // 该主题所关联的music信息    private List<String> _masters;  // 该主题所对应的讨论区版主信息        private PagedListDataModel _replys;      // 包含所有该主题的回复信息    private UIData _uiReplys;        // 绑定于回复信息    private int _pageSize = 12;      // 默认的每页显示记录        /** Creates a new instance of TopicBean */    @SuppressWarnings("unchecked")    public Topic() {        String view;        _topic = new TopicModel();        _userinfo = new UserinfoModel();        _files = new ArrayList<FileModel>();        try {            view = getFacesContext().getViewRoot().getViewId();        } catch (Exception e) {            HttpServletRequest request = (HttpServletRequest)                 getFacesContext().getExternalContext().getRequest();            view = request.getRequestURL().toString();        }        try {            int start = view.lastIndexOf("/");            int end = view.lastIndexOf(".");            int id = Integer.parseInt(view.substring(start + 1, end));            Map<String, Object> topicObj = new HashMap<String, Object>();            topicObj = CommonAction.getTopicOfObject(id);            _topic = (TopicModel)topicObj.get("topic");            if (_topic == null) {                Utils.addErrorMessage(getBundle(), "主题不存在或已经删除");            } else {                TopicBuilder tBuilder = TopicFactory.newBuilder(_topic);                if (!tBuilder.isViewTopic()) {// 如果用户无权浏览该主题 或者转到出错页面                    _topic = null;                }            }            _userinfo = (UserinfoModel)topicObj.get("userinfo");            _files = (ArrayList<FileModel>)topicObj.get("files");            _music = (MusicModel)topicObj.get("music");            if (_music != null &&                     !_music.getLrc().trim().toLowerCase().startsWith("http://")) {                _music.setLrc("/bbs/images/upload/lrc/" + _music.getLrc());            }            // 获取masters列表            _masters = getBBSApplication().getMasters().get(_topic.getByForum());            // topic浏览量信息,将topic的浏览量累加1            updateTopic(_topic);        } catch (Exception e) {            //out("Exception:Topic:" + e.getCause());        }    }        /**     * set the topic which will be visit     */     public void setTopic(TopicModel topic) {        _topic = topic;    }        /**     * get the topic which will be visit     */     public TopicModel getTopic() {        return _topic;    }        /**     * set userinfo of the topic     * @param userinfo     */    public void setUserinfo(UserinfoModel userinfo) {        _userinfo = userinfo;    }        /**     * get userinfo of the topic     * @return UserInfoModel     */     public UserinfoModel getUserinfo() {        return _userinfo;    }        public void setFiles(List<FileModel> files) {        _files = files;    }        /**     * 获取所有上传文件     */     public List<FileModel> getFiles() {        return _files;    }        public void setMusic(MusicModel music) {        _music = music;    }        public MusicModel getMusic() {        return _music;    }        public List<String> getMasters() {        return _masters;    }        public void setReplys(PagedListDataModel replys) {        _replys = replys;    }        public PagedListDataModel getReplys() {        if (_replys == null && _topic != null) {            _replys = new LocalDataModel(_pageSize);        }        return _replys;    }        public void setUiReplys(UIData uiReplys) {        _uiReplys = uiReplys;    }        public UIData getUiReplys() {        return _uiReplys;    }        public void setPageSize(int pageSize) {        _pageSize = pageSize;    }        public int getPageSize() {        return _pageSize;    }    /** page about ************************************************************/    private  DataPage getDataPage(int startRow, int pageSize) {        int total;        List<Map> dataList = new ArrayList<Map>();        total = CommonAction.getTotalRepliesByTopic(_topic);        dataList = CommonAction.getRepliesByTopic(_topic, startRow, pageSize);        return new DataPage(total, startRow, dataList);    }        private class LocalDataModel extends PagedListDataModel {        public  LocalDataModel(int pageSize) {             super (pageSize);        }        public DataPage fetchPage(int startRow,int pageSize) {             // call enclosing managed bean method to fetch the data              return getDataPage(startRow, pageSize);        }    }        // -----------------------------------------------------------action        /**     * 更新topic浏览量信息,将topic的浏览量累加1     * 如果是作者自已查看主题,则不增加浏览量     */     private void updateTopic(TopicModel tTopic) {        if (getVisitor().isLogin() &&                 getVisitor().getUser().getId().equals(tTopic.getByUser())) {            return;        }        tTopic.setTotalView(tTopic.getTotalView() + 1);        TopicAction.updateTopic(tTopic);    }        // -----------------------------------------------------------关于快速回复    private String quickReplyContent;        public void setQuickReplyContent(String quickReplyContent) {        this.quickReplyContent = quickReplyContent;    }        public String getQuickReplyContent() {        return quickReplyContent;    }        /**     * 快速回复     * @return "success" if reply success, else return "failure";     */    public String quickReply() throws Exception {        String newContent = StringFilter.filter(quickReplyContent);        Reply reply = new Reply();        reply.setTopic(_topic);        reply.setContent(newContent);        if (reply.reply().equals(Constants.OUT_SUCCESS)) {            quickReplyContent = ""; // 回复成功后清空回复内容            return Constants.OUT_SUCCESS;        } else {            Utils.addErrorMessage(getBundle(), "回复主题时遇到问题!");            return Constants.OUT_FAILURE;        }    }        // -----------------------------------------------------------详细回复    public String toReply() {        return Constants.OUT_SUCCESS;    }        /**      * 带引用主题内容的回复     * 先绑定Bean,然后设置Bean的相关信息     */     public String toReplyByQuoteTopic() {        ELContext elc = getELContext();        ValueExpression ve =getValueExpression("bbs_reply", "requestScope");        String replyContent = getQuoteContent(_topic.getContent());                        Reply reply = new Reply();        reply.setTopic(_topic);  // 设置被回复的主题        reply.setContent(replyContent); // 设置引用的内容        ve.setValue(elc, reply);        return Constants.OUT_SUCCESS;    }        /**     * 带引用回复内容的回复     */     public String toReplyByQuoteReply() {        ELContext elc = getELContext();        ValueExpression ve =getValueExpression("bbs_reply", "requestScope");        Map mReply = (Map)_uiReplys.getRowData();    // 被引用的回复信息        ReplyModel qReply = (ReplyModel)mReply.get("reply");        String replyContent = getQuoteContent(qReply.getContent());                        Reply reply = new Reply();        reply.setTopic(_topic);  // 设置被回复的主题        reply.setContent(replyContent); // 设置引用的内容        ve.setValue(elc, reply);        return Constants.OUT_SUCCESS;    }        /**     * 将需要“引用”的内容进行格式化,并返回     * 格式化后的内容.     * @param content 被引用的内容     * @return newContent 经过样式格式化的内容     */     private String getQuoteContent(String content) {        String newContent =                 "<div style='" +                "background: #FFFFFF;" +                "border: 1px solid gray;" +                "padding: 3px'>" +                    "<span style='" +                    "font-weight: bold;" +                    "font-size: 12px;'>引用:" +                    "</span><br>" + content +                 "</div><p>.";        return newContent;    }        // -----------------------------------------------------------topicTools.jsp        /**     * 该方法首先判断当前用户是否有权限修改该文章。     * 如果没有权限则发出警告信息,否则转到主题工具页面     * 进行主题工具页面topicTools.jsp     */     public String toShowToolsTopic() {        TopicBuilder tBuilder = TopicFactory.newBuilder(_topic);        return tBuilder.isDisplay() ? Constants.OUT_SUCCESS : Constants.OUT_FAILURE;    }        // -----------------------------------------------------------replyTools.jsp        /**     * 该方法用于转到ReplyTools.jsp,即回复信息的工具页面     * 进行reply回复信息的编辑操作     */    public String toShowToolsReply() {        Map mReply = (Map)_uiReplys.getRowData();    // 被引用的回复信息        ReplyModel reply = (ReplyModel)mReply.get("reply");                ReplyBuilder rBuilder = ReplyFactory.newBuilder(_topic, reply);        if (!rBuilder.isUpdate()) {            Utils.addErrorMessage(getBundle(), "对不起,你没有权限编辑该文件");            return Constants.OUT_FAILURE;        }        return Constants.OUT_SUCCESS;     }        // -----------------------------------------------------------关于用户短消息的发送        /**     * 给用户发送短消息,数据绑定已经在页面中进行,这里只是简单返回     * success;     */     public String toMessage() {        return Constants.OUT_SUCCESS;    }        // -----------------------------------------------------------关于主题的收藏        /**     * 收藏当前的主题     * 1.检查用户登录情况     * 2.检查该主题是否已被收藏     * 3.开始收藏主题文章     */    public String storeTopic() {        // 1        if (!getVisitor().isLogin()) {            Utils.addErrorMessage(getBundle(), "对不起,你需要先登录才能收藏!");            return Constants.OUT_FAILURE;        }        // 2        String userId = getVisitor().getUser().getId();        StorageModel storage = new StorageModel();        if (StorageAction.isExistStorage(_topic.getNum(), userId)) {            Utils.addErrorMessage(getBundle(), "该文章已经存在于你的收藏列表中!");            return Constants.OUT_FAILURE;        }        // 3        storage.setBeRevoke(false);        storage.setByTopic(_topic.getNum());        storage.setByUser(userId);        storage.setTitle(_topic.getTitle());        if (StorageAction.addStorage(storage)) {            Utils.addInfoMessage(getBundle(), "文章已经添加到我的收藏列表中!");            return Constants.OUT_SUCCESS;        }        return Constants.OUT_FAILURE;    }        // -----------------------------------------------------------页面跳转    private int _jumpTo;        public void setJumpTo(int jumpTo) {        _jumpTo = jumpTo;    }        public int getJumpTo() {        return _jumpTo;    }        /**     * 关于页面的跳转     */    public void jump(ActionEvent e) {        double totalPage = Math.ceil((double)_uiReplys.getRowCount() / _pageSize);        if (_jumpTo > 0 && _jumpTo <= totalPage) {            int first = (_jumpTo - 1) * _pageSize;            _uiReplys.setFirst(first);        }    }}

⌨️ 快捷键说明

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