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

📄 rsslistener.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;import biz.tbuy.bbs.bean.BaseBean;import biz.tbuy.bbs.bean.RSS;import biz.tbuy.common.logs.Elog;import biz.tbuy.share.StringFilter;import biz.tbuy.share.XmlOper;import java.util.List;import javax.faces.event.PhaseEvent;import javax.faces.event.PhaseId;import javax.faces.event.PhaseListener;import javax.servlet.http.HttpServletResponse;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Text;/** * @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 RSSListener extends BaseBean implements PhaseListener{    public RSSListener() {}    public void afterPhase(PhaseEvent pe) {        String view = getFacesContext().getViewRoot().getViewId();        if (view.indexOf("/bbs/rss.") != -1 && getBBSApplication().isRss()) {            rss();        }    }    public void beforePhase(PhaseEvent pe) {    }    public PhaseId getPhaseId() {        return PhaseId.RESTORE_VIEW;    }        public void rss() {        List<TopicModel> topics = null;        String rssValue = getParameter("rss");        if (rssValue == null || rssValue.equals("")) return;        if (rssValue.equals(RSS.ALL)) {            topics = ZoneFactory.getTopics(0, RSS.TOTAL);        } else {            int zoneId = Integer.parseInt(rssValue);            ZoneBuilder zBuilder = ZoneFactory.newBuilder(zoneId);            if (zBuilder != null) {                topics = zBuilder.getTopics(0, RSS.TOTAL);            }        }        // 截取topic的主体内容        if (topics != null && !topics.isEmpty()) {            for (TopicModel topic : topics) {                subTopic(topic);            }        }        try {            String serverName = getComApplication().getMySetting().get("webname"); // 获取网站名称            String serverPath = getComApplication().getHttpContextPath();  // 获取网址信息            Document doc = XmlOper.newDocument();            Element rss = doc.createElement("rss");            doc.appendChild(rss);            rss.setAttribute("version", "2.0");            Element channel = doc.createElement("channel");            rss.appendChild(channel);            Element title = doc.createElement("title");            Element link = doc.createElement("link");            Element description = doc.createElement("description");            Text title_text = doc.createTextNode(serverName);            Text link_text = doc.createTextNode(serverPath);            Text description_text = doc.createTextNode("Tbuy");            channel.appendChild(title);            channel.appendChild(link);            channel.appendChild(description);            title.appendChild(title_text);            link.appendChild(link_text);            description.appendChild(description_text);            for (TopicModel topic : topics) {                Element item = doc.createElement("item");                channel.appendChild(item);                Element imTitle = doc.createElement("title");                Element imLink = doc.createElement("link");                Element imDescription = doc.createElement("description");                Element imPubDate = doc.createElement("pubDate");                Element imAuthor = doc.createElement("author");                item.appendChild(imTitle);                item.appendChild(imLink);                item.appendChild(imDescription);                item.appendChild(imPubDate);                item.appendChild(imAuthor);                imTitle.appendChild(doc.createTextNode(topic.getTitle()));                imLink.appendChild(doc.createTextNode(serverPath + "/bbs/topic/" + topic.getNum() + ".faces"));                imDescription.appendChild(doc.createTextNode(topic.getContent()));                imPubDate.appendChild(doc.createTextNode(topic.getDate().toString()));                imAuthor.appendChild(doc.createTextNode(topic.getByUser()));            }            HttpServletResponse response = (HttpServletResponse)                    getFacesContext().getExternalContext().getResponse();            response.setContentType("text/xml;charset=UTF-8");            response.setHeader("Cache-Control", "no-cache");            XmlOper.write(doc, response.getWriter());            getFacesContext().responseComplete();        } catch (Exception e) {            Elog.log("Exception:RSS:rss:" + e.getMessage());        }    }        private void subTopic(TopicModel topic) {        String content = topic.getContent();        content = StringFilter.subString(content, 0, RSS.CONTENT_LENGTH);        content = StringFilter.clearBR(content);        topic.setContent(content + "...");    }}

⌨️ 快捷键说明

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