@Override public List<GmailMessage> getUnreadMessages() { final List<GmailMessage> messages = new ArrayList<GmailMessage>(); HttpGmailConnection c = null; try { // for ROME properties loader Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); c = getGmailConnection(); c.setUrl(gmailFeedUrl); final URLConnection con = c.openConnection(); final SyndFeedInput feedInput = new SyndFeedInput(); final SyndFeed gmail = feedInput.build(new XmlReader(con)); for (final Object entry : gmail.getEntries()) { if (entry instanceof SyndEntry) { messages.add(new RssGmailMessage((SyndEntry) entry)); } } if (log.isDebugEnabled()) { log.debug("Got " + messages.size() + " new messages."); } } catch (final Exception e) { throw new GmailException("Failed getting unread messages", e); } return messages; }
@SuppressWarnings("unchecked") public List<FiddleSyndEntry> getFeeds(URL url, CategoryDetail catDetail) { List<FiddleSyndEntry> feeds = new ArrayList<FiddleSyndEntry>(); XmlReader reader = null; SyndFeed feed = null; try { System.setProperty("http.proxyHost", "proxy-tw.bcbsmn.com"); System.setProperty("http.proxyPort", "9119"); System.setProperty("http.proxyUser", "a0c5zz"); System.setProperty("http.proxyPassword", "test0810"); reader = new XmlReader(url); feed = new SyndFeedInput().build(reader); feeds = feed.getEntries(); } catch (IOException e) { log.error("Exception reading url"); } catch (IllegalArgumentException e) { log.error("Exception reading url"); } catch (FeedException e) { log.error("Exception reading feed"); } finally { if (reader != null) try { reader.close(); } catch (IOException e) { log.error("Unable to close Feed XmlReader"); } } return feeds; }
@SuppressWarnings("unchecked") protected void removeRSSItem(String itemId, Node node, String description) throws Exception { RSS data = new RSS(node); SyndFeed feed = data.read(); List<SyndEntry> entries = feed.getEntries(); Node removeNode = getNodeById(itemId); if (removeNode.isNodeType("exo:topic")) { List<Node> listRemovePosts = getListRemove(removeNode, "exo:post"); removeItem(entries, listRemovePosts); } else if (removeNode.isNodeType("exo:forum")) { List<Node> listRemoveForum = getListRemove(removeNode, "exo:topic"); for (Node n : listRemoveForum) { List<Node> listRemovePosts = getListRemove(n, "exo:post"); removeItem(entries, listRemovePosts); } removeItem(entries, listRemoveForum); } feed.setEntries(entries); String title = new PropertyReader(node).string("exo:name", "Root"); feed.setTitle(title); feed.setDescription(description); data.saveFeed(feed, FORUM_RSS_TYPE); }
public static List<RssUrlBean> getRssUrlBeanListFromPage(int rssCompo_id, String url) { List<RssUrlBean> rubList = new ArrayList<RssUrlBean>(); if (url.equals("")) return rubList; try { URL feedUrl = new URL(url); // SyndFeedInput:从远程读到xml结构的内容转成SyndFeedImpl实例 SyndFeedInput input = new SyndFeedInput(); // rome按SyndFeed类型生成rss和atom的实例, // SyndFeed是rss和atom实现类SyndFeedImpl的接口 SyndFeed syndFeed = input.build(new XmlReader(feedUrl)); List<SyndEntry> entryList = syndFeed.getEntries(); for (SyndEntry entry : entryList) { RssUrlBean rub = new RssUrlBean(); rub.setRssCompo_id(rssCompo_id); rub.setTitle(entry.getTitle()); rub.setLink(entry.getUri()); rub.setPublishedDate(CommonUtil.getStandardDate(entry.getPublishedDate().toLocaleString())); rub.setDescription(entry.getDescription().getValue()); if (entry.getUpdatedDate() != null) rub.setUpdatedDate(CommonUtil.getStandardDate(entry.getUpdatedDate().toLocaleString())); rub.setAuthors(entry.getAuthor()); rubList.add(rub); } } catch (Exception ex) { ex.printStackTrace(); } return rubList; }
@SuppressWarnings("unchecked") public static SyndFeed addOpenSearchModule( SyndFeed feed, int itemsPerPage, int startIdx, int totalResult, String searchDescriptionUrl) { if (feed == null) { throw new NullPointerException("feed is NULL"); } List<Module> mods = null; mods = feed.getModules(); if (mods == null) { mods = new ArrayList<Module>(); } OpenSearchModule osm = new OpenSearchModuleImpl(); osm.setItemsPerPage(itemsPerPage); osm.setStartIndex(startIdx); osm.setTotalResults(totalResult); if (searchDescriptionUrl != null) { Link link = new Link(); link.setHref(searchDescriptionUrl); link.setType("application/opensearchdescription+xml"); osm.setLink(link); } mods.add(osm); feed.setModules(mods); return feed; }
public void serialize( ResultSummary summary, List<DashBoardItem> workItems, String columnsDefinition, List<String> labels, String lang, Response response, HttpServletRequest req) throws ClientException { // TODO labels, lang SyndFeed atomFeed = new SyndFeedImpl(); atomFeed.setFeedType(ATOM_TYPE); // XXX TODO : To be translated atomFeed.setTitle(summary.getTitle()); atomFeed.setLink(summary.getLink()); List<SyndEntry> entries = new ArrayList<SyndEntry>(); for (DashBoardItem item : workItems) { entries.add(adaptDashBoardItem(item, req)); } atomFeed.setEntries(entries); SyndFeedOutput output = new SyndFeedOutput(); // Try to return feed try { response.setEntity(output.outputString(atomFeed), MediaType.TEXT_XML); response.getEntity().setCharacterSet(CharacterSet.UTF_8); } catch (FeedException fe) { } }
/** * Sets the feed type for XML delivery, e.g. "rss_1.0", "atom_1.0" Must match one of ROME's * configured generators, see rome.properties (currently rss_1.0, rss_2.0, atom_1.0, atom_0.3) * * @param feedType feed type */ public void setType(String feedType) { feed.setFeedType(feedType); // XXX FIXME: workaround ROME 1.0 bug, it puts invalid image element in rss1.0 if ("rss_1.0".equals(feedType)) { feed.setImage(null); } }
/** * Adds an entry to the feed * * @param newEntry * @return */ @SuppressWarnings("unchecked") public SyndFeed addEntry(SyndEntry newEntry) { SyndFeed feed = read(); List<SyndEntry> entries = feed.getEntries(); if (newEntry != null) entries.add(0, newEntry); feed.setEntries(entries); return feed; }
/** * Remove one item from RSS feed based on id of object which is changed * * @param itemId id of object * @param node Node content RSS feed * @param feedDescription description about RSS feed * @throws Exception */ protected void removeItemInFeed(String itemId, Node node, String feedDescription) throws Exception { RSS data = new RSS(node); SyndFeed feed = data.removeEntry(itemId); String title = new PropertyReader(node).string("exo:name", "Root"); feed.setTitle(title); feed.setDescription(feedDescription); data.saveFeed(feed, FORUM_RSS_TYPE); }
void parseFeeds( DecoratorRequest request, List<SyndEntry> entries, Map<SyndEntry, SyndFeed> feedMapping, Map<String, String> imgMap, Map<String, String> descriptionNoImage, URL requestURL, String[] urlArray) throws Exception { for (String url : urlArray) { url = url.trim(); SyndFeed tmpFeed = null; URL feedURL = requestURL.relativeURL(url); URL baseURL; try { if (feedURL.getHost().equals(requestURL.getHost())) { baseURL = new URL(requestURL); retrieveLocalResource(feedURL); tmpFeed = this.localFeedFetcher.getFeed(feedURL, request); } else { baseURL = new URL(feedURL); tmpFeed = this.cache.get(url); } } catch (Exception e) { String m = e.getMessage(); if (m == null) { m = e.getClass().getName(); } throw new RuntimeException("Could not read feed url " + url + ": " + m); } if (tmpFeed == null) { throw new RuntimeException("Unable to load feed: " + url); } @SuppressWarnings("unchecked") List<SyndEntry> tmpEntries = tmpFeed.getEntries(); List<SyndEntry> filteredEntries = new ArrayList<SyndEntry>(tmpEntries); boolean filter = !parameterHasValue(PARAMETER_ALLOW_MARKUP, "true", request); for (SyndEntry entry : tmpEntries) { if (entries.contains(entry)) { filteredEntries.remove(entry); } feedMapping.put(entry, tmpFeed); HtmlFragment description = getDescription(entry, baseURL, requestURL, filter); if (description == null) { descriptionNoImage.put(entry.toString(), null); continue; } HtmlElement image = removeImage(description); if (image != null) { imgMap.put(entry.toString(), image.getEnclosedContent()); } descriptionNoImage.put(entry.toString(), description.getStringRepresentation()); } entries.addAll(filteredEntries); } }
public void testReadAtom1() throws FeedException { SyndFeedInput input = new SyndFeedInput(); SyndFeed result = input.build( new InputSource(getClass().getResourceAsStream("/be/hikage/xml/rome/atom_1.0.xml"))); assertEquals("RSS Veille Techno", result.getTitle()); assertEquals("http://svn.cyg.be/", result.getLink()); assertEquals(1, result.getEntries().size()); }
private void removePostFromParentFeeds( Node postNode, Node topicNode, Node forumNode, Node categoryNode) throws Exception { for (Node node : new Node[] {topicNode, forumNode, categoryNode}) { String description = new PropertyReader(node).string("exo:description", " "); RSS data = new RSS(node); SyndFeed feed = data.removeEntry(postNode.getName()); String title = new PropertyReader(node).string("exo:name", "Root"); feed.setTitle(title); feed.setDescription(description); data.saveFeed(feed, FORUM_RSS_TYPE); } }
@SuppressWarnings("unchecked") private void validateLinksInFeeds(SyndFeed feed) { Assert.assertTrue("Feed link is wrong", feed.getLink().startsWith(this.getBaseNexusUrl())); List<SyndEntry> entries = feed.getEntries(); for (SyndEntry syndEntry : entries) { Assert.assertNotNull("Feed item link is empty.", syndEntry.getLink()); Assert.assertTrue( "Feed item link is wrong, is: " + syndEntry.getLink(), syndEntry.getLink().startsWith(this.getBaseNexusUrl())); } }
public List<Note> getEntryData() { List<Note> res = new ArrayList<>(); for (SyndEntryImpl list1 : (List<SyndEntryImpl>) feedContent.getEntries()) { if (list1 == null || list1.equals(last)) break; Note addition = new Note(); // print(addition + " " + last); addition.setTitle(list1.getTitle()); addition.setContent(list1.getLink()); res.add(addition); } last = (SyndEntryImpl) feedContent.getEntries().get(0); return res; }
private SyndFeed createFeed() { SyndFeed feed = new SyndFeedImpl(); SyndPerson auteur = new SyndPersonImpl(); auteur.setName("Gildas Cuisinier"); auteur.setEmail("*****@*****.**"); feed.setTitle("RSS Veille Techno"); feed.setAuthors(Collections.singletonList(auteur)); feed.setDescription("RSS d'exemple !"); feed.setLink("http://svn.cyg.be/"); feed.setPublishedDate(new Date()); feed.setLanguage("fr"); SyndEntry entry = new SyndEntryImpl(); entry.setTitle("Ajout du projet Rome sur le SVN"); entry.setLink("https://rome.dev.java.net/"); SyndContent description = new SyndContentImpl(); description.setValue("Ajout d'un projet Rome sur le SVN afin de voir comment creer un RSS"); description.setType("text"); entry.setDescription(description); entry.setAuthors(Collections.singletonList(auteur)); feed.getEntries().add(entry); return feed; }
/** * Remove an item for the feed * * @param uri * @return * @throws Exception */ @SuppressWarnings("unchecked") public SyndFeed removeEntry(String uri) { SyndFeed feed = read(); List<SyndEntry> entries = feed.getEntries(); if (uri != null && uri.trim().length() > 0) { for (SyndEntry syndEntry : entries) { if (syndEntry.getUri().equals(uri)) { entries.remove(syndEntry); break; } } } feed.setEntries(entries); return feed; }
public static void main(String[] args) { boolean ok = false; if (args.length == 1) { try { URL feedUrl = new URL(args[0]); FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache); FetcherEventListenerImpl listener = new FetcherEventListenerImpl(); fetcher.addFetcherEventListener(listener); System.err.println("Retrieving feed " + feedUrl); // Retrieve the feed. // We will get a Feed Polled Event and then a // Feed Retrieved event (assuming the feed is valid) SyndFeed feed = fetcher.retrieveFeed(feedUrl); System.err.println(feedUrl + " retrieved"); System.err.println( feedUrl + " has a title: " + feed.getTitle() + " and contains " + feed.getEntries().size() + " entries."); // We will now retrieve the feed again. If the feed is unmodified // and the server supports conditional gets, we will get a "Feed // Unchanged" event after the Feed Polled event System.err.println("Polling " + feedUrl + " again to test conditional get support."); SyndFeed feed2 = fetcher.retrieveFeed(feedUrl); System.err.println( "If a \"Feed Unchanged\" event fired then the server supports conditional gets."); ok = true; } catch (Exception ex) { System.out.println("ERROR: " + ex.getMessage()); ex.printStackTrace(); } } if (!ok) { System.out.println(); System.out.println("FeedReader reads and prints any RSS/Atom feed type."); System.out.println("The first parameter must be the URL of the feed to read."); System.out.println(); } }
@SuppressWarnings("unchecked") private boolean findFeedEntry(SyndFeed feed, String title, String[] bodyPortions) { List<SyndEntry> entries = feed.getEntries(); for (SyndEntry entry : entries) { if (entry.getTitle().equals(title)) { if (bodyPortions == null) { return true; } boolean missingPortion = false; SyndContent description = entry.getDescription(); String value = description.getValue(); for (int i = 0; i < bodyPortions.length; i++) { if (!value.contains(bodyPortions[i])) { missingPortion = true; break; } } if (!missingPortion) { return true; } } } return false; }
public void mouseClicked(MouseEvent e) { Point p = e.getPoint(); int row = appWindow.feedItems.rowAtPoint(p); int column = appWindow.feedItems.columnAtPoint(p); ListFeed channel = (ListFeed) appWindow.channelsList.getSelectedValue(); SyndFeed feed = channel.feed; SyndEntry item = (SyndEntry) feed.getEntries().get(row); if (e.getClickCount() == 2) { // open in browser window } else if (e.getClickCount() == 1) { appWindow.itemDetails.setText(item.getDescription().getValue()); } }
public void handle( FeedHandlerRequest handlerRequest, FeedHandlerResponse handlerResponse, FeedHandlerChain handlerChain) throws FeedHandlerException, IOException { handlerChain.chain(handlerRequest, handlerResponse); SyndFeed feed = handlerResponse.getSyndFeed(); if (feed != null) { String toType = handlerRequest.getParameter(namespace("to")); if (toType == null) { toType = toDefault; } feed.setFeedType(toType); } }
private String getFeed( String title, String feedFileName, Collection entries, RSSRequest rssRequest, IWContext iwc) { if (rssFileURIsCacheList.contains(feedFileName)) return PATH_TO_FEED_PARENT_FOLDER + feedFileName; Date now = new Date(); RSSBusiness rss = null; try { rss = IBOLookup.getServiceInstance(iwc, RSSBusiness.class); } catch (IBOLookupException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String serverName = iwc.getServerURL(); serverName = serverName.substring(0, serverName.length() - 1); SyndFeed feed = null; feed = rss.createNewFeed( title, serverName, FEED_DESCRIPTION, "atom_1.0", iwc.getCurrentLocale().toString(), new Timestamp(now.getTime())); if (entries != null) feed.setEntries(getFeedEntries(entries)); try { String feedContent = rss.convertFeedToAtomXMLString(feed); IWSlideService service = this.getIWSlideService(rssRequest); service.uploadFileAndCreateFoldersFromStringAsRoot( PATH_TO_FEED_PARENT_FOLDER, feedFileName, feedContent, RSSAbstractProducer.RSS_CONTENT_TYPE, true); rssFileURIsCacheList.add(feedFileName); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return PATH_TO_FEED_PARENT_FOLDER + feedFileName; }
@Override public Long getLastModified() { Long lastModified = null; final Date date = feed.getPublishedDate(); if (date != null) { lastModified = Long.valueOf(date.getTime()); } return lastModified; }
@Override public void parse(SyndFeed feed) throws Exception { List entries = feed.getEntries(); Iterator itEntries = entries.iterator(); while (itEntries.hasNext()) { SyndEntry entry = (SyndEntry) itEntries.next(); System.out.println("Title : " + entry.getTitle()); } }
@SuppressWarnings("unchecked") public void test() throws Exception { final SyndFeedInput input = new SyndFeedInput(true); final SyndFeed feed = input.build(new File("c:\\temp\\google.xml")); logger.debug("Successfully parsed the RSS feed"); logger.debug("Author = " + feed.getAuthors()); logger.debug("Categories = " + feed.getCategories()); final List<SyndEntry> entries = feed.getEntries(); for (final SyndEntry entry : entries) { logger.debug("Title = " + StringEscapeUtils.unescapeHtml(entry.getTitle())); logger.debug( "Description = " + StringEscapeUtils.unescapeHtml(entry.getDescription().getValue())); logger.debug(entry.getUri()); logger.debug("Updated date = " + entry.getUpdatedDate()); logger.debug("Published date = " + entry.getPublishedDate()); logger.debug("===================================================="); } }
/** Test of parse method, of class com.totsp.xml.syndication.itunes.ITunesParser. */ public void testParse() throws Exception { File feed = new File(this.getTestFile("/test/xml/leshow.xml")); SyndFeedInput input = new SyndFeedInput(); SyndFeed syndfeed = input.build(new XmlReader(feed.toURL())); Module module = syndfeed.getModule(AbstractITunesObject.URI); FeedInformationImpl feedInfo = (FeedInformationImpl) module; assertEquals("owner", "Harry Shearer", feedInfo.getOwnerName()); assertEquals("email", "", feedInfo.getOwnerEmailAddress()); assertEquals( "image", "http://a1.phobos.apple.com/Music/y2005/m06/d26/h21/mcdrrifv.jpg", feedInfo.getImage().toExternalForm()); assertEquals("category", "Comedy", ((Category) feedInfo.getCategories().get(0)).getName()); assertEquals( "summary", "A weekly, hour-long romp through the worlds of media, politics, sports and show business, leavened with an eclectic mix of mysterious music, hosted by Harry Shearer.", feedInfo.getSummary()); List entries = syndfeed.getEntries(); Iterator it = entries.iterator(); while (it.hasNext()) { SyndEntry entry = (SyndEntry) it.next(); EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); System.out.println(entryInfo); } feed = new File(this.getTestFile("/test/xml/rsr.xml")); syndfeed = input.build(new XmlReader(feed.toURL())); entries = syndfeed.getEntries(); it = entries.iterator(); while (it.hasNext()) { SyndEntry entry = (SyndEntry) it.next(); EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI); System.out.println(entryInfo.getDuration()); } }
public static void main(String[] args) throws Exception { URL url = new URL("http://feeds.reuters.com/reuters/businessNews"); XmlReader reader = null; try { reader = new XmlReader(url); SyndFeed feed = new SyndFeedInput().build(reader); System.out.println("Feed Title: " + feed.getAuthor()); for (@SuppressWarnings("unchecked") Iterator<SyndEntry> i = feed.getEntries().iterator(); i.hasNext(); ) { SyndEntry entry = i.next(); System.out.println(entry.getTitle()); } } finally { if (reader != null) reader.close(); } }
@Override protected void createFeed(SyndFeed feed, Map model) { @SuppressWarnings("unchecked") List<PreparedUserEvent> list = (List<PreparedUserEvent>) model.get("topicsList"); String s = "Ответы на комментарии пользователя " + model.get("nick"); feed.setTitle(s); feed.setLink("http://www.linux.org.ru"); feed.setUri("http://www.linux.org.ru"); feed.setAuthor(""); feed.setDescription(s); Date lastModified; if (!list.isEmpty()) { lastModified = list.get(0).getEvent().getEventDate(); } else { lastModified = new Date(); } feed.setPublishedDate(lastModified); List<SyndEntry> entries = new ArrayList<>(); feed.setEntries(entries); for (PreparedUserEvent preparedUserEvent : list) { UserEvent item = preparedUserEvent.getEvent(); SyndEntry feedEntry = new SyndEntryImpl(); feedEntry.setPublishedDate(item.getEventDate()); feedEntry.setTitle(StringEscapeUtils.unescapeHtml4(item.getSubj())); String link; if (item.getCid() != 0) { feedEntry.setAuthor(preparedUserEvent.getAuthor().getNick()); link = String.format( "http://www.linux.org.ru/jump-message.jsp?msgid=%s&cid=%s", String.valueOf(item.getTopicId()), String.valueOf(item.getCid())); } else { link = String.format( "http://www.linux.org.ru/view-message.jsp?msgid=%s", String.valueOf(item.getTopicId())); } feedEntry.setLink(link); feedEntry.setUri(link); if (preparedUserEvent.getMessageText() != null) { SyndContent message = new SyndContentImpl(); message.setValue(StringUtil.removeInvalidXmlChars(preparedUserEvent.getMessageText())); message.setType("text/html"); feedEntry.setDescription(message); } entries.add(feedEntry); } }
/** @see com.elia.rssexample.data.NewsDao */ @SuppressWarnings("unchecked") public List<NewsItem> getNewsList() { // TODO: exception handling log.trace("Enter getNewsList()."); List<NewsItem> newsList = new ArrayList<NewsItem>(); XmlReader reader = null; try { for (String rssUrl : rssUrlList) { reader = new XmlReader(new URL(rssUrl)); SyndFeed feed = new SyndFeedInput().build(reader); for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) { NewsItem item = new NewsItem(); item.setTitle(entry.getTitle()); item.setDescription(entry.getDescription().getValue()); item.setLink(entry.getLink()); item.setPublished(entry.getPublishedDate()); newsList.add(item); } } } catch (Exception e) { log.error("Error reading feed.", e); } finally { try { reader.close(); } catch (IOException e) { log.warn("Unable to close xml reader.", e); } } return newsList; }
public void run() { if (!step && (feed == null || paused)) return; int previous = (itemIndex - 1 < 0) ? feed.getEntries().size() + (itemIndex - 1) : itemIndex - 1; int prevprev = (itemIndex - 2 < 0) ? feed.getEntries().size() + (itemIndex - 2) : itemIndex - 2; form.now2.setText(trim(((SyndEntry) feed.getEntries().get(prevprev)).getTitle())); form.now1.setText(trim(((SyndEntry) feed.getEntries().get(previous)).getTitle())); form.now.setText(trim(((SyndEntry) feed.getEntries().get(itemIndex)).getTitle())); try { Document dom = jTidyParse( new ByteArrayInputStream( ((SyndEntry) feed.getEntries().get(itemIndex)) .getDescription() .getValue() .getBytes()), new ByteArrayOutputStream()); form.display.setDocument(dom); } catch (Exception e) { e.printStackTrace(); } itemIndex++; if (itemIndex >= feed.getEntries().size()) { itemIndex = 0; } }
@Override public List<Article> read(URL url) { try { List<Article> articles = new ArrayList<>(); SyndFeedInput input = new SyndFeedInput(); SyndFeed syndFeed = input.build(new InputStreamReader(url.openStream())); for (Object obj : syndFeed.getEntries()) { if (!(obj instanceof SyndEntry)) { continue; } SyndEntry syndEntry = (SyndEntry) obj; articles.add(mapArticle(syndEntry)); } return articles; } catch (FeedException | IOException e) { throw new RuntimeException("피드를 읽을 수 업습니다. " + e.getMessage(), e); } }