Search in sources :

Example 86 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project play-cookbook by spinscale.

the class FeedResult method apply.

public void apply(Request request, Response response) {
    try {
        SyndFeed feed = new SyndFeedImpl();
        feed.setAuthor(Play.configuration.getProperty("rss.author"));
        feed.setTitle(Play.configuration.getProperty("rss.title"));
        feed.setDescription(Play.configuration.getProperty("rss.description"));
        feed.setLink(getFeedLink());
        List<SyndEntry> entries = new ArrayList<SyndEntry>();
        for (Post post : posts) {
            String url = createUrl("Application.showPost", "id", post.id.toString());
            SyndEntry entry = createEntry(post.title, url, post.content, post.createdAt);
            entries.add(entry);
        }
        feed.setEntries(entries);
        feed.setFeedType(getFeedType());
        setContentType(response);
        SyndFeedOutput output = new SyndFeedOutput();
        String rss = output.outputString(feed);
        response.out.write(rss.getBytes("utf-8"));
    } catch (Exception e) {
        throw new UnexpectedException(e);
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) UnexpectedException(play.exceptions.UnexpectedException) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Post(models.Post) ArrayList(java.util.ArrayList) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) UnexpectedException(play.exceptions.UnexpectedException)

Example 87 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project play-cookbook by spinscale.

the class FeedTest method testThatRss10Works.

@Test
public void testThatRss10Works() throws Exception {
    Response response = GET("/feed/posts.rss");
    assertIsOk(response);
    assertContentType("application/rss+xml", response);
    assertCharset("utf-8", response);
    SyndFeed feed = getFeed(response);
    assertEquals("rss_1.0", feed.getFeedType());
}
Also used : Response(play.mvc.Http.Response) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 88 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project OpenClinica by OpenClinica.

the class RssReaderServlet method getFeed.

void getFeed(PrintWriter pw) {
    SyndFeed feed = null;
    String htmlFeed = null;
    try {
        feed = feedFetcher.retrieveFeed(new URL(rssUrl));
        htmlFeed = feedHtml(feed);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        htmlFeed = errorFeedHtml(e.getMessage());
        e.printStackTrace();
    } catch (FeedException e) {
        // TODO Auto-generated catch block
        htmlFeed = errorFeedHtml(e.getMessage());
        e.printStackTrace();
    } catch (FetcherException e) {
        htmlFeed = errorFeedHtml(e.getMessage());
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        htmlFeed = errorFeedHtml(e.getMessage());
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        pw.println(htmlFeed);
        pw.close();
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) FetcherException(com.sun.syndication.fetcher.FetcherException) FeedException(com.sun.syndication.io.FeedException) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) FeedException(com.sun.syndication.io.FeedException) FetcherException(com.sun.syndication.fetcher.FetcherException)

Example 89 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project modules.playframework.org by playframework.

the class FeedCreationActor method createFeed.

private void createFeed(List<HistoricalEvent> historicalEvents, String feedType, File outputDirectory, String classifier) {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(feedType);
    feed.setTitle("Play! Modules");
    feed.setLink("http://modules.playframework.org");
    feed.setUri("http://modules.playframework.org");
    feed.setPublishedDate(new Date());
    feed.setDescription("The Play! Framework's module repository feed");
    List<SyndEntry> entries = new ArrayList<SyndEntry>(historicalEvents.size());
    for (HistoricalEvent historicalEvent : historicalEvents) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(historicalEvent.category);
        entry.setAuthor("Play framework modules");
        entry.setPublishedDate(historicalEvent.creationDate);
        // todo this will be the url of the module
        entry.setLink("http://modules.playframework.org");
        entry.setUri("mpo-he-" + historicalEvent.id);
        SyndContent description = new SyndContentImpl();
        description.setType("text/plain");
        description.setValue(historicalEvent.message);
        entry.setDescription(description);
        entries.add(entry);
    }
    feed.setEntries(entries);
    Writer writer = null;
    try {
        File outputFile = new File(outputDirectory, String.format("mpo.%s.xml", classifier));
        writer = new FileWriter(outputFile);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);
        writer.close();
    } catch (IOException e) {
        Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
    } catch (FeedException e) {
        Logger.error(String.format("A problem occurred when generating the %s feed", classifier), e);
    } finally {
        IOUtils.close(writer);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) HistoricalEvent(models.HistoricalEvent) FileWriter(java.io.FileWriter) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)89 ArrayList (java.util.ArrayList)28 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)25 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)16 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)16 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)16 Test (org.testng.annotations.Test)16 Test (org.junit.Test)11 SkipException (org.testng.SkipException)11 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 URL (java.net.URL)10 FeedException (com.sun.syndication.io.FeedException)9 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)9 IOException (java.io.IOException)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 ConsumerCert (rhsm.data.ConsumerCert)8 XmlReader (com.sun.syndication.io.XmlReader)7 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)6