Search in sources :

Example 31 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project books by aidanwhiteley.

the class FeedsControllerTest method checkRssFeedsHasEntries.

@Test
void checkRssFeedsHasEntries() throws Exception {
    // Find the port the test is running on
    String rootUri = this.testRestTemplate.getRootUri();
    String url = rootUri + "/feeds/rss";
    XmlReader reader = new XmlReader(new URL(url));
    SyndFeed feed = new SyndFeedInput().build(reader);
    assertEquals(booksFeedsTitles, feed.getTitle());
    assertTrue(feed.getEntries().size() > 0);
    for (SyndEntry entry : feed.getEntries()) {
        assertFalse(entry.getContents().get(0).getValue().isEmpty());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) XmlReader(com.rometools.rome.io.XmlReader) URL(java.net.URL) Test(org.junit.jupiter.api.Test) IntegrationTest(com.aidanwhiteley.books.util.IntegrationTest)

Example 32 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project MtgDesktopCompanion by nicho92.

the class RSSNewsProvider method listNews.

@Override
public List<MagicNewsContent> listNews(MagicNews rssBean) throws IOException {
    InputStream is = null;
    SyndFeed feed;
    List<MagicNewsContent> ret = new ArrayList<>();
    try {
        HttpURLConnection openConnection = (HttpURLConnection) new URL(rssBean.getUrl()).openConnection();
        logger.debug("reading " + rssBean.getUrl());
        openConnection.setRequestProperty("User-Agent", MTGConstants.USER_AGENT);
        openConnection.setInstanceFollowRedirects(true);
        is = openConnection.getInputStream();
        InputSource source = new InputSource(is);
        feed = input.build(source);
        String baseURI = feed.getLink();
        for (SyndEntry s : feed.getEntries()) {
            MagicNewsContent content = new MagicNewsContent();
            content.setTitle(s.getTitle());
            content.setAuthor(s.getAuthor());
            content.setDate(s.getPublishedDate());
            URL link;
            if (!s.getLink().startsWith(baseURI))
                link = new URL(baseURI + s.getLink());
            else
                link = new URL(s.getLink());
            content.setLink(link);
            ret.add(content);
        }
        return ret;
    } catch (IllegalArgumentException | FeedException e) {
        throw new IOException(e);
    } finally {
        if (is != null)
            is.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) MagicNewsContent(org.magic.api.beans.MagicNewsContent) FeedException(com.rometools.rome.io.FeedException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) HttpURLConnection(java.net.HttpURLConnection)

Example 33 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project mycore by MyCoRe-Org.

the class MCRRSSFeedImporter method importPublications.

public void importPublications(String projectID) throws Exception {
    LOGGER.info("Getting new publications from {} RSS feed...", sourceSystemID);
    SyndFeed feed = retrieveFeed();
    List<MCRObject> importedObjects = new ArrayList<>();
    for (SyndEntry entry : feed.getEntries()) {
        MCRObject importedObject = handleFeedEntry(entry, projectID);
        if (importedObject != null) {
            importedObjects.add(importedObject);
        }
    }
    int numPublicationsImported = importedObjects.size();
    LOGGER.info("imported {} publications.", numPublicationsImported);
    if ((numPublicationsImported > 0) && (xsl2BuildNotificationMail != null)) {
        sendNotificationMail(importedObjects);
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) MCRObject(org.mycore.datamodel.metadata.MCRObject) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) ArrayList(java.util.ArrayList)

Example 34 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project openolat by klemens.

the class FeedManagerImpl method createFeedFile.

@Override
public MediaResource createFeedFile(OLATResourceable ores, Identity identity, Long courseId, String nodeId) {
    MediaResource media = null;
    Feed feed = loadFeed(ores);
    if (feed != null) {
        SyndFeed rssFeed = new RSSFeed(feed, identity, courseId, nodeId);
        media = new SyndFeedMediaResource(rssFeed);
    }
    return media;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) RSSFeed(org.olat.modules.webFeed.RSSFeed) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) SyndFeedMediaResource(org.olat.modules.webFeed.SyndFeedMediaResource) SyndFeedMediaResource(org.olat.modules.webFeed.SyndFeedMediaResource) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(org.olat.modules.webFeed.Feed) RSSFeed(org.olat.modules.webFeed.RSSFeed)

Example 35 with SyndFeed

use of com.rometools.rome.feed.synd.SyndFeed in project openolat by klemens.

the class RomeFeedFetcher method fetchSyndFeed.

/**
 * Fetches the SyndFeed of an URL.
 * @param feedURL
 * @return
 */
protected SyndFeed fetchSyndFeed(String feedURL) {
    SyndFeed syndFeed = null;
    try (Reader xmlReader = new XmlReader(new URL(feedURL))) {
        syndFeed = syndFeedInput.build(xmlReader);
        log.info("Read external feed: " + feedURL);
    } catch (Exception e) {
        log.warn("Cannot read external feed: : " + feedURL);
    }
    return syndFeed;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Reader(java.io.Reader) XmlReader(com.rometools.rome.io.XmlReader) XmlReader(com.rometools.rome.io.XmlReader) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) ParsingFeedException(com.rometools.rome.io.ParsingFeedException)

Aggregations

SyndFeed (com.rometools.rome.feed.synd.SyndFeed)45 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)22 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)17 XmlReader (com.rometools.rome.io.XmlReader)16 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)15 ArrayList (java.util.ArrayList)14 FeedException (com.rometools.rome.io.FeedException)13 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)12 URL (java.net.URL)11 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)10 SyndContent (com.rometools.rome.feed.synd.SyndContent)9 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)8 IOException (java.io.IOException)7 Test (org.junit.Test)7 Date (java.util.Date)6 ParsingFeedException (com.rometools.rome.io.ParsingFeedException)4 FileNotFoundException (java.io.FileNotFoundException)4 Reader (java.io.Reader)4 Writer (java.io.Writer)4 SQLException (java.sql.SQLException)3