本文整理汇总了Java中com.sun.syndication.feed.synd.SyndFeed.getEntries方法的典型用法代码示例。如果您正苦于以下问题:Java SyndFeed.getEntries方法的具体用法?Java SyndFeed.getEntries怎么用?Java SyndFeed.getEntries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.syndication.feed.synd.SyndFeed
的用法示例。
在下文中一共展示了SyndFeed.getEntries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRealFeed
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
Channel channel = new Channel(type);
channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
channel.setEncoding(syndFeed.getEncoding());
channel.setTitle(syndFeed.getTitle());
channel.setLink(syndFeed.getLink());
channel.setDescription(syndFeed.getDescription());
SyndImage sImage = syndFeed.getImage();
if (sImage!=null) {
channel.setImage(createRSSImage(sImage));
}
List sEntries = syndFeed.getEntries();
if (sEntries!=null) {
channel.setItems(createRSSItems(sEntries));
}
return channel;
}
示例2: execute
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("Start FetchAtomWorker job");
EntityManagerFactory emf = (EntityManagerFactory) context.getMergedJobDataMap().get("emf");
DataManager dm = new DataManager (emf);
ServletContext scontext = (ServletContext) context.getMergedJobDataMap().get("scontext");
Iterator it = dm.feeds.entrySet().iterator();
while (it.hasNext()) {
Map.Entry <String, String[]> pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
try {
URL feedUrl = new URL(pair.getValue()[1]);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {
dm.saveNewsItem(entry, pair.getKey());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例3: testCreateNullHeadlineAndLink
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testCreateNullHeadlineAndLink() throws Exception {
String createdFeed = new String(createFeedCreator("feeds/valid_page/index.html")
.createFeed(".headline,.article,.footer", null, null, null)
.setTitle("Title")
.build());
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(createdFeed.getBytes())));
assertEquals("Title", feed.getTitle());
List<SyndEntry> entries = feed.getEntries();
assertEquals(null, entries.get(0).getTitle());
assertEquals(null, entries.get(0).getLink());
assertEquals(EMPTY, entries.get(0).getAuthor());
assertEquals(null, entries.get(1).getTitle());
assertEquals(null, entries.get(1).getLink());
assertEquals(EMPTY, entries.get(1).getAuthor());
}
示例4: gatherLinks
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
private TreeMap gatherLinks(String section) {
TreeMap linkMap = new TreeMap(Collections.reverseOrder());
//for sites that support rss we do rss
SyndFeed feed = getSectionLinksFromRssFeed(section);
if (feed != null) {
for (SyndEntry anEntry : (List<SyndEntry>) feed.getEntries()) {
String aLink = anEntry.getLink();
if (aLink.contains(ampLiteral)) {
aLink = aLink.replace(ampLiteral, "");
}
if (!shoudRemove(anEntry)) {
linkMap.put(aLink, aLink);
}
}
}
//for sites that do not have or do not support
return linkMap;
}
示例5: read
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
public void read() {
try {
URL source = new URL(Defaults.FEEDURL);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(source));
@SuppressWarnings("unchecked")
List<SyndEntry> entries = feed.getEntries();
urls = new ArrayList<String>();
for(SyndEntry entry : entries) {
String sURL = entry.getLink();
urls.add(sURL);
} // for
} catch (IllegalArgumentException | FeedException | IOException e) {
e.printStackTrace();
}
long seed = System.nanoTime();
Collections.shuffle(urls, new Random(seed));
}
示例6: shouldRetrieveGreetings
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@Test
public void shouldRetrieveGreetings() throws Exception {
_testKit.removeService("PrintService");
final MockHandler printService = _testKit.registerInOnlyService("PrintService");
Thread.sleep(10001);
final LinkedBlockingQueue<Exchange> receivedMessages = printService.getMessages();
for (Exchange e : receivedMessages) {
SyndFeed feed = (SyndFeed) e.getMessage().getContent();
@SuppressWarnings("unchecked")
List<SyndEntry> entries = feed.getEntries();
Assert.assertEquals(feed.getEntries().size(), 1);
Iterator<SyndEntry> itEntries = entries.iterator();
while (itEntries.hasNext()) {
SyndEntry entry = (SyndEntry) itEntries.next();
Assert.assertTrue(entry.getTitle().equals(SONG_TITLE));
Assert.assertTrue(entry.getLink().equals(SONG_URL));
Assert.assertTrue(entry.getDescription().getValue().equals(SONG_DESCRIPTION));
}
}
}
示例7: AtomCodeList
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
public AtomCodeList(final String codeSpace, final SyndFeed feed) {
this.codeSpace = codeSpace;
@SuppressWarnings("unchecked")
final List<SyndEntry> entries = (List<SyndEntry>) feed.getEntries();
for (final SyndEntry entry : entries) {
if (entry.getUri().startsWith(feed.getUri())) {
String id = entry.getUri().substring(feed.getUri().length());
if (id.startsWith("/")) {
id = id.substring(1);
}
values.add(id);
} else {
values.add(entry.getTitle());
}
}
}
示例8: getTweets
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
public List<String> getTweets(String username) {
List<String> tweets = new ArrayList<String>();
try {
URL feedSource = new URL("http://api.twitter.com/1/statuses/user_timeline.rss?count=100&screen_name=" + username);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedSource));
for(Object f : feed.getEntries()) {
SyndEntry entry = (SyndEntry) f;
tweets.add(entry.getTitle().substring(username.length() + 2));
}
}catch(Exception e) {
logger.severe(e.getMessage());
}
return tweets;
}
示例9: processFeed2List
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
private List<RSSEntry> processFeed2List(SyndFeed feed) {
List<RSSEntry> lstRC = new ArrayList<RSSEntry>();
for (Object synEntryObject : feed.getEntries()) {
SyndEntry sEntry = (SyndEntry) synEntryObject;
RSSEntry rssEntry = new RSSEntry();
rssEntry.setTitle(sEntry.getTitle());
rssEntry.setLink(sEntry.getLink());
if (sEntry.getDescription() != null) {
rssEntry.setDescription(sEntry.getDescription().getValue());
} else {
rssEntry.setDescription("");
}
rssEntry.setAuthors(buildStringList(sEntry.getAuthors()));
rssEntry.setCategories(buildStringList(sEntry.getCategories()));
rssEntry.setContents(buildStringList(sEntry.getContents()));
rssEntry.setLinks(buildStringList(sEntry.getLinks()));
rssEntry.setCreated(sEntry.getPublishedDate());
rssEntry.setUpdated(sEntry.getUpdatedDate());
lstRC.add(rssEntry);
}
return lstRC;
}
示例10: getAllPostsFromFeed
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
public static List getAllPostsFromFeed(String urlToGet, String source) throws IOException, FeedException {
ArrayList<BlogPost> posts = new ArrayList<BlogPost>();
URL url = new URL(urlToGet);
SyndFeedInput input = new SyndFeedInput();
try {
SyndFeed feed = input.build(new XmlReader(url));
int items = feed.getEntries().size();
if (items > 0) {
log.info("Attempting to parse rss feed: " + urlToGet);
log.info("This Feed has " + items + " items");
List<SyndEntry> entries = feed.getEntries();
for (SyndEntry item : entries) {
if (item.getContents().size() > 0) {
SyndContentImpl contentHolder = (SyndContentImpl) item.getContents().get(0);
String content = contentHolder.getValue();
if (content != null && !content.isEmpty()) {
BlogPost post = new BlogPost(content, null, null, source, item.getLink(), item.getUri(), null);
posts.add(post);
}
}
}
}
return posts;
}
catch(Exception ex){
log.error(ex);
return posts;
}
}
示例11: getFeedEntries
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@Override
public List<FeedEntry> getFeedEntries(String feedUrl)
throws FeedException, IOException {
SyndFeed feed = createFeed(feedUrl);
List entries = feed.getEntries();
List<FeedEntry> result = new ArrayList<>(entries.size());
for (Object o : entries) {
SyndEntry e = (SyndEntry)o;
e.setLink(HttpUtils.cleanFeedUrl(e.getLink()));
result.add(syndEntryToFeedEntry(e));
}
closeUrlConnection();
return result;
}
示例12: testNewFeed
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testNewFeed()
throws Exception
{
List<RssFeedEntry> entries = new ArrayList<>();
RssFeedEntry entry = new RssFeedEntry( "Item 1" );
Date whenGathered = new Date( System.currentTimeMillis() );
entry.setDescription( "RSS 2.0 feed item 1." );
entry.setPublishedDate( whenGathered );
entries.add( entry );
entry = new RssFeedEntry( "Item 2" );
entry.setDescription( "RSS 2.0 feed item 2." );
entry.setPublishedDate( whenGathered );
entries.add( entry );
entry = new RssFeedEntry( "Item 3" );
entry.setDescription( "RSS 2.0 feed item 3." );
entry.setPublishedDate( whenGathered );
entries.add( entry );
SyndFeed feed =
generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries );
assertEquals( "Test Feed", feed.getTitle() );
assertEquals( "The test feed from Archiva.", feed.getDescription() );
assertEquals( "en-us", feed.getLanguage() );
assertEquals( entries.get( 2 ).getPublishedDate(), feed.getPublishedDate() );
List<SyndEntry> syndEntries = feed.getEntries();
assertEquals( 3, syndEntries.size() );
assertEquals( "Item 1", syndEntries.get( 0 ).getTitle() );
assertEquals( "Item 2", syndEntries.get( 1 ).getTitle() );
assertEquals( "Item 3", syndEntries.get( 2 ).getTitle() );
}
示例13: apply
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<SyndEntry> apply(URL url) {
try (XmlReader xmlReader = new XmlReader(url)) {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(xmlReader);
return feed.getEntries();
} catch (Exception e) {
LOG.log(Level.WARNING, "An error during downloading and parsing a given feed: " + url, e);
}
return Collections.emptyList();
}
示例14: testCreateSuccess
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testCreateSuccess() throws Exception {
String createdFeed = new String(createFeedCreator("feeds/valid_page/index.html")
.createFeed(".headline,.article,.footer", ".headline", "a", ".author").build());
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(createdFeed.getBytes())));
List<SyndEntry> entries = feed.getEntries();
assertEquals("headline1", entries.get(0).getTitle());
assertEquals("http://dummy.url", entries.get(0).getLink());
assertEquals("Jon Doe", entries.get(0).getAuthor());
assertEquals("headline2", entries.get(1).getTitle());
assertEquals("http://dummy.url", entries.get(1).getLink());
assertEquals("Anna Smith", entries.get(1).getAuthor());
String content1 = entries.get(0).getDescription().getValue();
assertTrue(content1.contains("headline1"));
assertTrue(content1.contains("text1"));
assertTrue(content1.contains("footer1"));
assertTrue(content1.contains("http://dummy.url"));
String content2 = entries.get(1).getDescription().getValue();
assertTrue(content2.contains("headline2"));
assertTrue(content2.contains("text2"));
assertTrue(content2.contains("footer2"));
assertTrue(content2.contains("http://dummy.url"));
}
示例15: doGet
import com.sun.syndication.feed.synd.SyndFeed; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
resp.setCharacterEncoding("UTF-8");
PrintWriter out = resp.getWriter();
URL feedUrl = new URL("http://localhost");
String category = req.getPathInfo();
if (category.equals("/Bulgaria")) {
feedUrl = new URL("http://www.dnevnik.bg/rssc/?rubrid=1657");
out.printf("<h1>Новини от България</h1><hr>");
} else if (category.equals("/Technology")) {
feedUrl = new URL("http://www.dnevnik.bg/rssc/?rubrid=1660");
out.printf("<h1>Новини от Технологии</h1><hr>");
} else if (category.equals("/Sports")) {
feedUrl = new URL("http://www.dnevnik.bg/rssc/?rubrid=2368");
out.printf("<h1>Новини от Спорт</h1><hr>");
}
HttpURLConnection conn = (HttpURLConnection)feedUrl.openConnection();
try {
SyndFeed feed = new SyndFeedInput().build(new XmlReader(conn));
List entries = feed.getEntries();
Iterator it = entries.iterator();
while (it.hasNext()) {
SyndEntry entry = (SyndEntry) it.next();
out.printf("<a href=\"%s\"><h2>%s</h2></a>", entry.getLink(), entry.getTitle());
out.printf("<h4>%s пише на %s</h4>", entry.getAuthor(), entry.getPublishedDate());
out.printf("<article>%s</article>", entry.getDescription().getValue());
out.printf("<hr/>");
}
} catch (FeedException e) {
e.printStackTrace();
}
}