com.sun.syndication.io.SyndFeedInput Java Examples
The following examples show how to use
com.sun.syndication.io.SyndFeedInput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RSSScraper.java From Babler with Apache License 2.0 | 5 votes |
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; } }
Example #2
Source File: RufusFeed.java From rufus with MIT License | 5 votes |
public static RufusFeed generate(Source source) { SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = null; URL url = source.getUrl(); try { feed = input.build(new XmlReader(url)); } catch (Exception e) { logger.debug("Could not build SyndFeedInput for {}", url, e); } if (CollectionUtils.isEmpty(source.getTags())) { source.setTags(Collections.emptyList()); //never null! } return new RufusFeed(source, feed); }
Example #3
Source File: FeedParser.java From rufus with MIT License | 5 votes |
private static FeedResponse validate(String feedRequestUrl) { try { URL url = new URL(feedRequestUrl); SyndFeedInput input = new SyndFeedInput(); input.build(new XmlReader(url)); //ensure request is a valid rss feed return FeedResponse.valid(feedRequestUrl); } catch (Exception e) { logger.debug("could not parse feed request {}, reason {}", feedRequestUrl, e.getMessage()); return FeedResponse.invalid(e.getMessage(), feedRequestUrl); } }
Example #4
Source File: NewsParser.java From VileBot with MIT License | 5 votes |
protected void printHeadlines( GenericMessageEvent event, LinkedHashMap<String, ImmutablePair<String, URL>> newsFeedsByCategory, String category, Logger logger ) { SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = null; try { feed = input.build( new XmlReader( newsFeedsByCategory.get( category ).getRight() ) ); } catch ( FeedException | IOException e ) { String errorMsg = "Error opening RSS feed"; logger.error( e.getMessage() ); logger.error( errorMsg ); event.respondWith( errorMsg ); } List<SyndEntry> entries = feed.getEntries(); for ( int i = 0; i < NUM_HEADLINES; i++ ) { event.respondWith( Colors.bold( " " + entries.get( i ).getTitle() ) + " -> " + entries.get( i ).getLink() ); } }
Example #5
Source File: RSSWorkItemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void setInput(SyndFeedInput input) { this.input = input; }
Example #6
Source File: RSSScraper.java From Babler with Apache License 2.0 | 4 votes |
public AbstractMap.SimpleEntry<Integer, Integer> fetchAndSave() throws Exception { URL url = new URL(this.url); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new XmlReader(url)); int items = feed.getEntries().size(); if(items > 0){ log.info("Attempting to parse rss feed: "+ this.url ); log.info("This Feed has "+items +" items"); } List <SyndEntry> entries = feed.getEntries(); for (SyndEntry item : entries){ log.info("Title: " + item.getTitle()); log.info("Link: " + item.getLink()); SyndContentImpl contentHolder = (SyndContentImpl) item.getContents().get(0); String content = contentHolder.getValue(); //content might contain html data, let's clean it up Document doc = Jsoup.parse(content); content = doc.text(); try { Result result = ld.detectLanguage(content, language); if (result.languageCode.equals(language) && result.isReliable) { FileSaver file = new FileSaver(content, this.language, "bs", item.getLink(), item.getUri(), String.valueOf(content.hashCode())); String fileName = file.getFileName(); BlogPost post = new BlogPost(content,this.language,null,"bs",item.getLink(),item.getUri(),fileName); if(DAO.saveEntry(post)) { file.save(this.logDb); numOfFiles++; wrongCount = 0; } } else{ log.info("Item " + item.getTitle() + "is in a diff languageCode, skipping this post "+ result.languageCode); wrongCount ++; if(wrongCount > 3){ log.info("Already found 3 posts in the wrong languageCode, skipping this blog"); } break; } } catch(Exception e){ log.error(e); break; } } return new AbstractMap.SimpleEntry<>(numOfFiles,wrongCount); }
Example #7
Source File: RSSRomeExample.java From tutorials with MIT License | 4 votes |
private static SyndFeed readFeed() throws IOException, FeedException { URL feedSource = new URL("http://rssblog.whatisrss.com/feed/"); SyndFeedInput input = new SyndFeedInput(); return input.build(new XmlReader(feedSource)); }
Example #8
Source File: CallbackServlet.java From fuchsia with Apache License 2.0 | 4 votes |
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String hubtopic = null; String hubchallenge = null; MessageStatus stsMessage = MessageStatus.ERROR; ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(SyndFeedInput.class.getClassLoader()); if (request.getContentType().contains(MediaType.APPLICATION_ATOM_XML) || request.getContentType().contains(MediaType.APPLICATION_RSS_XML)) { InputStream in = request.getInputStream(); try { SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new XmlReader(in)); List<SyndLinkImpl> linkList = feed.getLinks(); for (SyndLinkImpl link : linkList) { if ("self".equals(link.getRel())) { hubtopic = link.getHref(); } } if (hubtopic == null) { hubtopic = feed.getUri(); } topicUpdated(hubtopic, feed); } catch (FeedException e) { LOG.error("Failed in creating feed response.", e); } finally { Thread.currentThread().setContextClassLoader(cl); } stsMessage = MessageStatus.OK; } response.setContentType(MediaType.APPLICATION_FORM_URLENCODED); switch (stsMessage) { case OK: response.setStatus(HttpStatus.SC_OK); break; case OK_CHALLENGE: response.setStatus(HttpStatus.SC_OK); response.getWriter().print(hubchallenge); break; default: response.setStatus(HttpStatus.SC_NOT_FOUND); break; } }