com.rometools.rome.feed.synd.SyndFeedImpl Java Examples

The following examples show how to use com.rometools.rome.feed.synd.SyndFeedImpl. 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: RssFeedGenerator.java    From archiva with Apache License 2.0 6 votes vote down vote up
public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries )
{
    if( dataEntries.size() ==  0 )
    {
        log.debug( "No updates found, feed not generated." );
        return null;
    }
    
    SyndFeed feed = new SyndFeedImpl();
    feed.setTitle( title );        
    feed.setDescription( description );
    feed.setLanguage( DEFAULT_LANGUAGE );
    feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() );
    feed.setFeedType( DEFAULT_FEEDTYPE );
    feed.setEntries( getEntries( dataEntries ) );

    log.debug( "Finished generating the feed \'{}\'.", title );
    
    return feed;
}
 
Example #2
Source File: RSSFeedServlet.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("WildFly-Camel Test RSS Feed");
    feed.setLink("http://localhost:8080/rss-tests");
    feed.setDescription("Test RSS feed for the camel-rss component");

    List<SyndEntry> entries = new ArrayList<>();
    for (int i = 1; i <= 5; i++) {
        entries.add(createFeedEntry("Test entry: ", "Test content: ", i));
    }
    feed.setEntries(entries);

    SyndFeedOutput output = new SyndFeedOutput();
    try {
        output.output(feed, response.getWriter());
    } catch (FeedException e) {
        throw new IllegalStateException("Error generating RSS feed", e);
    }
}
 
Example #3
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testImageTakesPrecedenceOverImageUri() throws Exception {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("title");
    feed.setDescription("description");
    feed.setLink("https://example.org");

    FeedInformation itunesFeed = new FeedInformationImpl();
    itunesFeed.setImage(new URL("https://example.org/test1.png"));
    itunesFeed.setImageUri(new java.net.URI("https://example.org/test2.png"));
    feed.getModules().add(itunesFeed);

    String xml = new SyndFeedOutput().outputString(feed);

    AbstractITunesObject parsedItunesFeed =
            (AbstractITunesObject) new SyndFeedInput()
                    .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8"))))
                    .getModule(AbstractITunesObject.URI);
    assertEquals(new URL("https://example.org/test1.png"), parsedItunesFeed.getImage());
    assertEquals(new java.net.URI("https://example.org/test1.png"),
            parsedItunesFeed.getImageUri());
}
 
Example #4
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testImageUri() throws Exception {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("title");
    feed.setDescription("description");
    feed.setLink("https://example.org");

    FeedInformation itunesFeed = new FeedInformationImpl();
    itunesFeed.setImageUri(new java.net.URI("https://example.org/test.png"));
    feed.getModules().add(itunesFeed);

    String xml = new SyndFeedOutput().outputString(feed);

    AbstractITunesObject parsedItunesFeed =
            (AbstractITunesObject) new SyndFeedInput()
                    .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8"))))
                    .getModule(AbstractITunesObject.URI);
    assertEquals(new java.net.URI("https://example.org/test.png"),
            parsedItunesFeed.getImageUri());
    assertEquals(new URL("https://example.org/test.png"),
            parsedItunesFeed.getImage());
}
 
Example #5
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testImage() throws Exception {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("title");
    feed.setDescription("description");
    feed.setLink("https://example.org");

    FeedInformation itunesFeed = new FeedInformationImpl();
    itunesFeed.setImage(new URL("https://example.org/test.png"));
    feed.getModules().add(itunesFeed);

    String xml = new SyndFeedOutput().outputString(feed);

    AbstractITunesObject parsedItunesFeed =
            (AbstractITunesObject) new SyndFeedInput()
                    .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8"))))
                    .getModule(AbstractITunesObject.URI);
    assertEquals(new URL("https://example.org/test.png"), parsedItunesFeed.getImage());
    assertEquals(new java.net.URI("https://example.org/test.png"),
            parsedItunesFeed.getImageUri());
}
 
Example #6
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testCreate() throws Exception {

        final SyndFeed feed = new SyndFeedImpl();
        final String feedType = "rss_2.0";
        feed.setFeedType(feedType);
        feed.setLanguage("en-us");
        feed.setTitle("sales.com on the Radio!");
        feed.setDescription("sales.com radio shows in MP3 format");
        feed.setLink("http://foo/rss/podcasts.rss");

        final FeedInformation fi = new FeedInformationImpl();
        fi.setOwnerName("sales.com");
        fi.getCategories().add(new Category("Shopping"));
        fi.setOwnerEmailAddress("[email protected]");
        fi.setType("serial");
        feed.getModules().add(fi);

        final SyndFeedOutput output = new SyndFeedOutput();
        final StringWriter writer = new StringWriter();
        output.output(feed, writer);
        LOG.debug("{}", writer);
    }
 
Example #7
Source File: SyndicationServlet.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, PublicInterfaceNotFoundException {
	long poid = Long.parseLong(request.getParameter("poid"));
	SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);

	SyndFeed feed = new SyndFeedImpl();
	feed.setFeedType(FEED_TYPE);

	feed.setTitle("BIMserver.org checkouts feed for project '" + sProject.getName() + "'");
	feed.setLink(request.getContextPath());
	feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");

	List<SyndEntry> entries = new ArrayList<SyndEntry>();
	try {
		List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
		for (SCheckout sCheckout : allCheckoutsOfProject) {
			SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
			SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
			SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
			SyndEntry entry = new SyndEntryImpl();
			entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
			entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
			entry.setPublishedDate(sCheckout.getDate());
			SyndContent description = new SyndContentImpl();
			description.setType("text/plain");
			description
					.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
			entry.setDescription(description);
			entries.add(entry);
		}
	} catch (UserException e) {
		LOGGER.error("", e);
	}
	feed.setEntries(entries);
	SyndFeedOutput output = new SyndFeedOutput();
	output.output(feed, response.getWriter());
}
 
Example #8
Source File: SyndicationServlet.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeRevisionsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws IOException, FeedException, ServiceException, PublicInterfaceNotFoundException {
	long poid = Long.parseLong(request.getParameter("poid"));
	SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);

	SyndFeed feed = new SyndFeedImpl();
	feed.setFeedType(FEED_TYPE);

	feed.setTitle("BIMserver.org revisions feed for project '" + sProject.getName() + "'");
	feed.setLink(request.getContextPath());
	feed.setDescription("This feed represents all the revisions of project '" + sProject.getName() + "'");

	List<SyndEntry> entries = new ArrayList<SyndEntry>();
	try {
		List<SRevision> allRevisionsOfProject = serviceMap.getServiceInterface().getAllRevisionsOfProject(poid);
		Collections.sort(allRevisionsOfProject, new SRevisionIdComparator(false));
		for (SRevision sVirtualRevision : allRevisionsOfProject) {
			SUser user = serviceMap.getServiceInterface().getUserByUoid(sVirtualRevision.getUserId());
			SyndEntry entry = new SyndEntryImpl();
			entry.setTitle("Revision " + sVirtualRevision.getOid());
			entry.setLink(request.getContextPath() + "/revision.jsp?poid=" + sVirtualRevision.getOid() + "&roid=" + sVirtualRevision.getOid());
			entry.setPublishedDate(sVirtualRevision.getDate());
			SyndContent description = new SyndContentImpl();
			description.setType("text/html");
			description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Comment</td><td>" + sVirtualRevision.getComment()
					+ "</td></tr></table>");
			entry.setDescription(description);
			entries.add(entry);
		}
	} catch (ServiceException e) {
		LOGGER.error("", e);
	}
	feed.setEntries(entries);
	SyndFeedOutput output = new SyndFeedOutput();
	output.output(feed, response.getWriter());
}
 
Example #9
Source File: TestOpsOPML20.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
    PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/3"));
    w.println(sFeed1.toString());
    w.close();
    w = new PrintWriter(new FileOutputStream("target/test-reports/4"));
    w.println(sFeed2.toString());
    w.close();
    assertEquals(sFeed1, sFeed2);
}
 
Example #10
Source File: TestOpsOPML10links.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testTemp() throws Exception {
    final WireFeedInput input = new WireFeedInput();
    final WireFeed wf = input.build(TestUtil.loadFile("/opml_1.0_links.xml"));
    final WireFeedOutput output = new WireFeedOutput();

    final SyndFeedImpl sf = new SyndFeedImpl(wf);
    sf.setFeedType("rss_2.0");
    sf.setDescription("");
    sf.setLink("http://foo.com");
    sf.setFeedType("opml_1.0");
    output.output(sf.createWireFeed(), new NullWriter());
}
 
Example #11
Source File: TestOpsOPML10links.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
    PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1"));
    w.println(sFeed1.toString());
    w.close();
    w = new PrintWriter(new FileOutputStream("target/test-reports/2"));
    w.println(sFeed2.toString());
    w.close();

    assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed());
}
 
Example #12
Source File: FeedOpsTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);

    assertEquals(sFeed1, sFeed2);
}
 
Example #13
Source File: FeedOpsTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = this.getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);

    assertTrue(sFeed1.equals(sFeed2));
}
 
Example #14
Source File: TestOpsOPML10.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
    PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1"));
    w.println(sFeed1.toString());
    w.close();
    w = new PrintWriter(new FileOutputStream("target/test-reports/2"));
    w.println(sFeed2.toString());
    w.close();

    assertEquals(sFeed1, sFeed2);
}
 
Example #15
Source File: BlogRssServices.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
public static Map<String, Object> generateBlogRssFeed(DispatchContext dctx, Map<String, ? extends Object> context) {
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    String contentId = (String) context.get("blogContentId");
    String entryLink = (String) context.get("entryLink");
    String feedType = (String) context.get("feedType");
    Locale locale = (Locale) context.get("locale");

    // create the main link
    String mainLink = (String) context.get("mainLink");
    mainLink = mainLink + "?blogContentId=" + contentId;

    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();

    // get the main blog content
    GenericValue content = null;
    try {
        content = EntityQuery.use(delegator).from("Content").where("contentId", contentId).queryOne();
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }

    if (content == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource,
                "ContentCannotGenerateBlogRssFeed",
                UtilMisc.toMap("contentId", contentId), locale));
    }

    // create the feed
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType(feedType);
    feed.setLink(mainLink);

    feed.setTitle(content.getString("contentName"));
    feed.setDescription(content.getString("description"));
    feed.setEntries(generateEntryList(dispatcher, delegator, contentId, entryLink, locale, userLogin));

    Map<String, Object> resp = ServiceUtil.returnSuccess();
    resp.put("wireFeed", feed.createWireFeed());
    return resp;
}
 
Example #16
Source File: FeedAggregator.java    From rome with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) {

        boolean ok = false;

        if (args.length >= 2) {

            try {

                final String outputType = args[0];

                final SyndFeed feed = new SyndFeedImpl();
                feed.setFeedType(outputType);

                feed.setTitle("Aggregated Feed");
                feed.setDescription("Anonymous Aggregated Feed");
                feed.setAuthor("anonymous");
                feed.setLink("http://www.anonymous.com");

                final List<SyndEntry> entries = new ArrayList<SyndEntry>();
                feed.setEntries(entries);

                final FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
                final FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);

                for (int i = 1; i < args.length; i++) {
                    final URL inputUrl = new URL(args[i]);
                    final SyndFeed inFeed = feedFetcher.retrieveFeed(inputUrl);
                    entries.addAll(inFeed.getEntries());
                }

                final SyndFeedOutput output = new SyndFeedOutput();
                output.output(feed, new PrintWriter(System.out));

                ok = true;

            } catch (final Exception ex) {
                System.out.println("ERROR: " + ex.getMessage());
                ex.printStackTrace();
            }

        }

        if (!ok) {
            System.out.println();
            System.out.println("FeedAggregator aggregates different feeds into a single one.");
            System.out.println("The first parameter must be the feed type for the aggregated feed.");
            System.out.println(" [valid values are: rss_0.9, rss_0.91, rss_0.92, rss_0.93, ]");
            System.out.println(" [                  rss_0.94, rss_1.0, rss_2.0 & atom_0.3  ]");
            System.out.println("The second to last parameters are the URLs of feeds to aggregate.");
            System.out.println();
        }
    }
 
Example #17
Source File: Issue131Test.java    From rome with Apache License 2.0 4 votes vote down vote up
public void testCopiedFeedCategories() throws Exception {
    final SyndFeed copiedFeed = new SyndFeedImpl();
    copiedFeed.copyFrom(getCachedSyndFeed());
    checkFeed(copiedFeed);
}
 
Example #18
Source File: SyndFeedInput.java    From rome with Apache License 2.0 2 votes vote down vote up
/**
 * Builds SyndFeedImpl from an JDOM document.
 * <p>
 *
 * @param document JDOM document to read to create the SyndFeedImpl.
 * @return the SyndFeedImpl read from the JDOM document.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the
 *             underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public SyndFeed build(final Document document) throws IllegalArgumentException, FeedException {
    return new SyndFeedImpl(feedInput.build(document), preserveWireFeed);
}
 
Example #19
Source File: SyndFeedInput.java    From rome with Apache License 2.0 2 votes vote down vote up
/**
 * Builds SyndFeedImpl from an W3C DOM document.
 * <p>
 *
 * @param document W3C DOM document to read to create the SyndFeedImpl.
 * @return the SyndFeedImpl read from the W3C DOM document.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the
 *             underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public SyndFeed build(final org.w3c.dom.Document document) throws IllegalArgumentException, FeedException {
    return new SyndFeedImpl(feedInput.build(document), preserveWireFeed);
}
 
Example #20
Source File: SyndFeedInput.java    From rome with Apache License 2.0 2 votes vote down vote up
/**
 * Builds SyndFeedImpl from an W3C SAX InputSource.
 * <p>
 *
 * @param is W3C SAX InputSource to read to create the SyndFeedImpl.
 * @return the SyndFeedImpl read from the W3C SAX InputSource.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the
 *             underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public SyndFeed build(final InputSource is) throws IllegalArgumentException, FeedException {
    return new SyndFeedImpl(feedInput.build(is), preserveWireFeed);
}
 
Example #21
Source File: SyndFeedInput.java    From rome with Apache License 2.0 2 votes vote down vote up
/**
 * Builds SyndFeedImpl from an Reader.
 * <p>
 *
 * @param reader Reader to read to create the SyndFeedImpl.
 * @return the SyndFeedImpl read from the Reader.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the
 *             underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public SyndFeed build(final Reader reader) throws IllegalArgumentException, FeedException {
    return new SyndFeedImpl(feedInput.build(reader), preserveWireFeed);
}
 
Example #22
Source File: SyndFeedInput.java    From rome with Apache License 2.0 2 votes vote down vote up
/**
 * Builds SyndFeedImpl from a file.
 * <p>
 *
 * @param file file to read to create the SyndFeedImpl.
 * @return the SyndFeedImpl read from the file.
 * @throws FileNotFoundException thrown if the file could not be found.
 * @throws IOException thrown if there is problem reading the file.
 * @throws IllegalArgumentException thrown if feed type could not be understood by any of the
 *             underlying parsers.
 * @throws FeedException if the feed could not be parsed
 *
 */
public SyndFeed build(final File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException {
    return new SyndFeedImpl(feedInput.build(file), preserveWireFeed);
}