使用Rome实现网站RSS发布的简单步骤
来源:互联网 发布:linux内核裁剪流程 编辑:程序博客网 时间:2024/05/16 07:08
使用Rome实现网站RSS发布的简单步骤
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="package.inc.jsp"%>
<%@page import="org.jdom.*,com.sun.syndication.feed.synd.*,com.sun.syndication.io.SyndFeedOutput"%>
<%
int maxLength = 500;
out.clearBuffer();
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("Java世纪网,Enjoy Java, Enjoy Everyday");
feed.setLink("http://www.java2000.net");
feed.setDescription("Java世纪网的最新的50个帖子列表");
feed.setEncoding("UTF-8");
/*
Document doc = feed.outputJDom(feed.createWireFeed());
//create the XSL processing instruction
Map xsl = new HashMap();
xsl.put("href", "http://feeds.feedburner.com/~d/styles/rss2full.xsl");
xsl.put("type", "text/xsl");
xsl.put("media", "screen");
ProcessingInstruction pXsl = new ProcessingInstruction("xml-stylesheet", xsl);
doc.addContent(0, pXsl);
//create the CSS processing instruction
Map css = new HashMap();
css.put("href", "http://feeds.feedburner.com/~d/styles/itemcontent.css");
css.put("type", "text/css");
css.put("media", "screen");
ProcessingInstruction pCss = new ProcessingInstruction("xml-stylesheet", css);
doc.addContent(1, pCss);
*/
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry;
SyndContent description;
PostService ps = (PostService) Factory.getBean("PostService");
Collection<Post> pList = ps.findAll(-1, 0, 50);
for (Post p : pList) {
entry = new SyndEntryImpl();
entry.setTitle(p.getUser().getUsername()+"("+p.getUser().getNickName()+")"+(p.getIdParent()==0?"发表了":"回复了")+":"+p.getSubject());
entry.setLink("http://www.java2000.net/viewthread.jsp?tid=" + p.getId() + "");
entry.setPublishedDate(p.getDatetime());
description = new SyndContentImpl();
description.setType("text/html");
if(p.getContent().length()>maxLength){
description.setValue(p.getContent().substring(0,maxLength)+"<br/><br/>【内容太长,只显示了前"+maxLength+"字,更多内容请看全文】");
}else{
description.setValue(p.getContent());
}
entry.setDescription(description);
entries.add(entry);
}
feed.setEntries(entries);
try {
SyndFeedOutput output = new SyndFeedOutput();
out.print(output.outputString(feed));
} catch (Exception ex) {
ex.printStackTrace();
}
<%@include file="package.inc.jsp"%>
<%@page import="org.jdom.*,com.sun.syndication.feed.synd.*,com.sun.syndication.io.SyndFeedOutput"%>
<%
int maxLength = 500;
out.clearBuffer();
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("Java世纪网,Enjoy Java, Enjoy Everyday");
feed.setLink("http://www.java2000.net");
feed.setDescription("Java世纪网的最新的50个帖子列表");
feed.setEncoding("UTF-8");
/*
Document doc = feed.outputJDom(feed.createWireFeed());
//create the XSL processing instruction
Map xsl = new HashMap();
xsl.put("href", "http://feeds.feedburner.com/~d/styles/rss2full.xsl");
xsl.put("type", "text/xsl");
xsl.put("media", "screen");
ProcessingInstruction pXsl = new ProcessingInstruction("xml-stylesheet", xsl);
doc.addContent(0, pXsl);
//create the CSS processing instruction
Map css = new HashMap();
css.put("href", "http://feeds.feedburner.com/~d/styles/itemcontent.css");
css.put("type", "text/css");
css.put("media", "screen");
ProcessingInstruction pCss = new ProcessingInstruction("xml-stylesheet", css);
doc.addContent(1, pCss);
*/
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry;
SyndContent description;
PostService ps = (PostService) Factory.getBean("PostService");
Collection<Post> pList = ps.findAll(-1, 0, 50);
for (Post p : pList) {
entry = new SyndEntryImpl();
entry.setTitle(p.getUser().getUsername()+"("+p.getUser().getNickName()+")"+(p.getIdParent()==0?"发表了":"回复了")+":"+p.getSubject());
entry.setLink("http://www.java2000.net/viewthread.jsp?tid=" + p.getId() + "");
entry.setPublishedDate(p.getDatetime());
description = new SyndContentImpl();
description.setType("text/html");
if(p.getContent().length()>maxLength){
description.setValue(p.getContent().substring(0,maxLength)+"<br/><br/>【内容太长,只显示了前"+maxLength+"字,更多内容请看全文】");
}else{
description.setValue(p.getContent());
}
entry.setDescription(description);
entries.add(entry);
}
feed.setEntries(entries);
try {
SyndFeedOutput output = new SyndFeedOutput();
out.print(output.outputString(feed));
} catch (Exception ex) {
ex.printStackTrace();
}
- 使用Rome实现网站RSS发布的简单步骤
- 使用Rome实现网站RSS发布的简单步骤
- rome实现rss订阅与发布
- rome实现rss订阅与发布
- WEB中使用ROME实现RSS服务
- 使用rome创建RSS格式的xml
- java使用Rome解析Rss的实例
- 使用Rome 生成RSS
- Rome介绍 java的RSS阅读,发布器
- 通过rome实现RSS订阅
- 使用Rome解析RSS Feed
- 使用rome解析rss xml
- 使用Rome解析百度RSS
- 使用rome 解析rss时 碰到的403错误
- JAVA使用ROME读取百度RSS的编码错误问题
- 网站RSS的使用
- rome-rss
- 使用WebWork和Rome轻松暴露RSS
- 开博了
- CUDA VS2005 Wizard
- 在java中如何约束条件限制文本框接受的字符
- Mysql 何去何从
- 使用C#创建Excel文档
- 使用Rome实现网站RSS发布的简单步骤
- 两个下拉菜单的二级联动
- 有史以来批处理最完整人性化教程1
- 使用C#创建Word文档
- swt中限制文本框接受的字符
- SSI--什么是SHTML?
- Concept-第9章翻译
- 使用exchange 和split partition 来将一个非分区表转换为分区表
- 一道IBM笔试题 按季度统计