rss阅读器 java_RSS阅读器
[java]代码库package com.ruanko.service;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import com.ruanko.dao.impl.FileDaoImpl;
import com.ruanko.model.Channel;
import com.ruanko.model.News;
import com.runko.dao.NewsDao;
public class RSSService
{
private ArrayList channelList;
private List newsList;
private NewsDao rssDao;
public RSSService()
{
rssDao = new FileDaoImpl();
}
public List getChannelList()
{
if(channelList == null)
{
channelList = new ArrayList();
//创建“腾讯新闻”频道
Channel channel1 = new Channel();
channel1.setName("新浪国际新闻");
channel1.setFilePath("NewsFiles/sina.xml");
channel1.setUrl("http://rss.sina.com.cn/news/world/focus15.xml");
//创建“腾讯-国内新闻”频道
Channel channel2 = new Channel();
channel2.setName("腾讯国内新闻");
channel2.setFilePath("NewsFiles/rss_newsgn.xml");
channel2.setUrl("http://news.qq.com/newsgn/rss_newsgn.xml");
//创建“新浪网-国内要闻”频道
Channel channel3 = new Channel();
channel3.setName("新浪体育新闻");
channel3.setFilePath("NewsFiles/sports.xml");
channel3.setUrl("http://rss.sina.com.cn/roll/sports/hot_roll.xml");
//创建“新浪网-国际要闻”频道
Channel channel4 = new Channel();
channel4.setName("新浪社会新闻");
channel4.setFilePath("NewsFiles/socials.xml");
channel4.setUrl("http://rss.sina.com.cn/news/society/focus15.xml");
channelList.add(channel1);
channelList.add(channel2);
channelList.add(channel3);
channelList.add(channel4);
}
return channelList;
}
public List getNewsList(String filePath)
{
Document doc = load(filePath);
newsList = parse(doc);
return newsList;
}
private Document load(String filePath)
{
Document doc = null;
SAXBuilder sb = new SAXBuilder(false);
File fXml = new File(filePath);
if(fXml.exists() && fXml.isFile())
{
try
{
doc = sb.build(fXml);
}catch (JDOMException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
return doc;
}
private News itemToNews(Element item)
{
News news = new News();
//获得节点内容
String title = item.getChildText("title").trim();
String link = item.getChildText("link");
String author = item.getChildText("author");
String guid = item.getChildText("guid");
String pubDate = item.getChildText("pubDate");
String category = item.getChildText("category");
String description = item.getChildText("description").trim();
//设置节点内容
news.setTitle(title);
news.setLink(link);
news.setAuthor(author);
news.setGuid(guid);
news.setPubDate(pubDate);
news.setCategory(category);
news.setDescription(description);
return news;
}
private List parse(Document doc)
{
List newsList = new ArrayList();
News news = null;
Element root = doc.getRootElement();
//获得item标签
Element eChannel = root.getChild("channel");
List itemList = eChannel.getChildren("item");
//生成news对象列表
for(int i = 0; i < itemList.size(); i++)
{
Element item = itemList.get(i);
news = itemToNews(item);
newsList.add(news);
}
return newsList;
}
public String newsToString(News news)
{
String content = "";
content = "标题:"
+ news.getTitle() + "\r\n"
+ "链接:"
+ news.getLink() + "\r\n"
+ "作者:"
+ news.getAuthor() + "\r\n"
+ "发布时间:"
+ news.getPubDate() + "\r\n"
+ "-------------------------------------------------------------\n"
+ news.getDescription() + "\r\n" + "\r\n" + "\r\n";
return content;
}
public boolean save()
{
boolean flag = false;
if(rssDao.save(newsList))
{
flag = true;
}
return flag;
}
}
rss阅读器 java_RSS阅读器相关推荐
- 细胞亚器文献阅读之酵母液泡与线粒体的动态互作A Dynamic Interface between Vacuoles and Mitochondria in Yeast
细胞亚器文献阅读之酵母液泡与线粒体的动态互作A Dynamic Interface between Vacuoles and Mitochondria in Yeast 本文和前一篇阅读的文献之间的关 ...
- 动物电子耳标阅读器|识读器|读卡器L8600系列Modbus RTU通讯协议与二次开发说明
动物电子耳标阅读器|识读器|读卡器L8600系列Modbus RTU通讯协议与二次开发说明适用于L8600-S-02.L8600-R-02,更多MODBUS TCP协议资料欢迎交流! 出厂默认配置: ...
- 细胞亚器文献阅读二~An ER-Mitochondria Tethering Complex Revealed by a Synthetic Biology Screen
细胞亚器文献阅读二~An ER-Mitochondria Tethering Complex Revealed by a Synthetic Biology Screen 通过合成生物学筛选ER和Mi ...
- 细胞亚器文章阅读ER-to-Plasma Membrane Tethering Proteins Regulate Cell Signaling and ER Morphology
细胞亚器文章阅读ER-to-Plasma Membrane Tethering Proteins Regulate Cell Signaling and ER Morphology 本文采用蛋白质谱的 ...
- 电子护照阅读器|证件阅读机MEPR100+与MEPR100性能分析与差异化对比
电子护照阅读器|证件阅读机MEPR系列是一款外形轻巧美观的证件识读设备,配备高清300万像素成像系统,采用OCR技术或RFID感应识别技术,可识别多种护照证件.可识读符合国际民航组织ICAO DOC ...
- 安卓pdf阅读器_BOOX阅读器:不仅阅读效果逆天,PDF阅读和手写体验更出色!
当下电子阅读逐渐流行,但多限于纯文字类网文小说阅读.市面上主流的电子书阅读器多为8英寸以下的小屏产品,很多都不能很好地解决大版面的PDF文件阅读舒适度的问题,更没法满足读者批注写笔记的需求. 一直走大 ...
- 低频工业读写器|读卡器|阅读器CK-LR03-A01与FX1N三菱PLC联机应用手册
低频工业读写器|读卡器|阅读器CK-LR03-A01是一款基于射频识别技术的低频RFID标签读卡器.RFID 工作频率为134K 支持对FDX-B和EMID标准协议格式标签的读取,以及对FDX-B标准 ...
- 你以为福昕阅读器只是阅读器吗
PDF文档不管是在日常办公还是在平时的学习都非常常见.但是有时候一些PDF阅读器只有阅读功能,并不能添加注释或者修改.作为国产PDF阅读器的小清新-福昕阅读器,不仅可以快捷阅读PDF文档,而且还提供很 ...
- 全三轨磁条卡读卡器|阅读机|刷卡器MRS100串口通信协议 Communication Protocol
全三轨磁条卡读卡器|阅读机|刷卡器MRS100串口通信协议 Communication Protocol 1.Command Command name Command code Comm ...
最新文章
- 转录组背景、环境设置(目录管理)
- mysql重连,连接丢失:The last packet successfully received from the server--转载
- 程序员的职业素养-读书笔记
- SQL Server XML性能优化(Best Practices)
- Google Nexus5在linux下刷原生安卓 android6.0
- Oracle的10046事件
- 如何将网易云ncm格式转换为mp3格式
- 零基础如何学习计算机语言
- 云原生 - 自建数据库与云数据库RDS性能优势分析,值不值得购买?
- 2、Terraform-安装
- 第69天-内网安全-域横向 CobaltStrikeSPNRDP
- SpringCloud Getway服务网关
- 2019年内大892数据结构部分参考答案
- 孕妇电子计算机房辐射,孕妇在机房辐射大吗
- 十大盗版软件你用了几个?
- Logo(图片)作为报表水印的解决方法
- C Primer Plus (第六版)编程练习参考答案
- 所以拱桥的承重力要比平桥多得多,盖超
- Java 百度、高德、84坐标系经纬度的相互转换
- ZOJ 2547 Tri Tiling 脑筋急转弯
热门文章
- centos php 绑定域名,centos如何绑定域名?
- C++之指针探究(十三):函数指针数组
- 信息服务器 iis 7.0,iis7.0的技术参数汇总
- matplotlib 散点图_python之matplotlib 折线图和散点图
- 湖南师大计算机学信网,湖南师范大学有计算机专业硕士吗?
- 计算方法c语言上机作业,考研复试-----C语言上机操作(三)
- linux实现内存共享,Linux共享内存实现
- linux启动日志服务命令,linux命令:syslog日志服务-系统缩减之增加日志服务功能...
- linux的文件权限前面的东西,linux 文件权限解析
- 2021温州市高考成绩查询,温州2021高考成绩排名榜单,温州各高中高考成绩喜报