com.rometools.rome.feed.rss.Channel Java Examples

The following examples show how to use com.rometools.rome.feed.rss.Channel. 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: RSS20Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {

    super.populateChannel(channel, eChannel);

    final String generator = channel.getGenerator();
    if (generator != null) {
        eChannel.addContent(generateSimpleElement("generator", generator));
    }

    final int ttl = channel.getTtl();
    if (ttl > -1) {
        eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl)));
    }

    final List<Category> categories = channel.getCategories();
    for (final Category category : categories) {
        eChannel.addContent(generateCategoryElement(category));
    }

    generateForeignMarkup(eChannel, channel.getForeignMarkup());

}
 
Example #2
Source File: RSS10Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {

    super.populateChannel(channel, eChannel);

    final String channelUri = channel.getUri();
    if (channelUri != null) {
        eChannel.setAttribute("about", channelUri, getRDFNamespace());
    }

    final List<Item> items = channel.getItems();
    if (!items.isEmpty()) {
        final Element eItems = new Element("items", getFeedNamespace());
        final Element eSeq = new Element("Seq", getRDFNamespace());
        for (final Item item : items) {
            final Element lis = new Element("li", getRDFNamespace());
            final String uri = item.getUri();
            if (uri != null) {
                lis.setAttribute("resource", uri, getRDFNamespace());
            }
            eSeq.addContent(lis);
        }
        eItems.addContent(eSeq);
        eChannel.addContent(eItems);
    }
}
 
Example #3
Source File: RSS094Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    final List<Element> categories = eChannel.getChildren("category", getRSSNamespace());
    channel.setCategories(parseCategories(categories));

    final Element ttl = eChannel.getChild("ttl", getRSSNamespace());
    if (ttl != null && ttl.getText() != null) {
        final Integer ttlValue = NumberParser.parseInt(ttl.getText());
        if (ttlValue != null) {
            channel.setTtl(ttlValue);
        }
    }

    return channel;
}
 
Example #4
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);
    channel.setLanguage(syndFeed.getLanguage()); // c
    channel.setCopyright(syndFeed.getCopyright()); // c
    channel.setPubDate(syndFeed.getPublishedDate()); // c
    channel.setDocs(syndFeed.getDocs());
    channel.setManagingEditor(syndFeed.getManagingEditor());
    channel.setWebMaster(syndFeed.getWebMaster());
    channel.setGenerator(syndFeed.getGenerator());

    final List<SyndPerson> authors = syndFeed.getAuthors();
    if (Lists.isNotEmpty(authors)) {
        final SyndPerson author = authors.get(0);
        channel.setManagingEditor(author.getName());
    }

    return channel;
}
 
Example #5
Source File: RssChannelHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void writeOtherCharset() throws IOException, SAXException {
	Channel channel = new Channel("rss_2.0");
	channel.setTitle("title");
	channel.setLink("http://example.com");
	channel.setDescription("description");

	String encoding = "ISO-8859-1";
	channel.setEncoding(encoding);

	Item item1 = new Item();
	item1.setTitle("title1");

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(channel, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)),
			outputMessage.getHeaders().getContentType());
}
 
Example #6
Source File: RssChannelHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws IOException {
	InputStream is = getClass().getResourceAsStream("rss.xml");
	MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
	inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", utf8));
	Channel result = converter.read(Channel.class, inputMessage);
	assertEquals("title", result.getTitle());
	assertEquals("http://example.com", result.getLink());
	assertEquals("description", result.getDescription());

	List<?> items = result.getItems();
	assertEquals(2, items.size());

	Item item1 = (Item) items.get(0);
	assertEquals("title1", item1.getTitle());

	Item item2 = (Item) items.get(1);
	assertEquals("title2", item2.getTitle());
}
 
Example #7
Source File: RssChannelHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void read() throws IOException {
	InputStream is = getClass().getResourceAsStream("rss.xml");
	MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
	inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", StandardCharsets.UTF_8));
	Channel result = converter.read(Channel.class, inputMessage);
	assertEquals("title", result.getTitle());
	assertEquals("http://example.com", result.getLink());
	assertEquals("description", result.getDescription());

	List<?> items = result.getItems();
	assertEquals(2, items.size());

	Item item1 = (Item) items.get(0);
	assertEquals("title1", item1.getTitle());

	Item item2 = (Item) items.get(1);
	assertEquals("title2", item2.getTitle());
}
 
Example #8
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {

    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);

    final String uri = syndFeed.getUri();
    if (uri != null) {
        channel.setUri(uri);
    } else {
        // if URI is not set use the value for link
        final String link = syndFeed.getLink();
        channel.setUri(link);
    }

    return channel;
}
 
Example #9
Source File: RssChannelHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void writeOtherCharset() throws IOException, SAXException {
	Channel channel = new Channel("rss_2.0");
	channel.setTitle("title");
	channel.setLink("http://example.com");
	channel.setDescription("description");

	String encoding = "ISO-8859-1";
	channel.setEncoding(encoding);

	Item item1 = new Item();
	item1.setTitle("title1");

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(channel, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)),
			outputMessage.getHeaders().getContentType());
}
 
Example #10
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {

    final Channel channel = (Channel) feed;

    super.copyInto(channel, syndFeed);

    final String uri = channel.getUri();
    if (uri != null) {
        syndFeed.setUri(uri);
    } else {
        // if URI is not set use the value for link
        final String link = channel.getLink();
        syndFeed.setUri(link);
    }
}
 
Example #11
Source File: RssChannelHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void writeOtherCharset() throws IOException, SAXException {
	Channel channel = new Channel("rss_2.0");
	channel.setTitle("title");
	channel.setLink("https://example.com");
	channel.setDescription("description");

	String encoding = "ISO-8859-1";
	channel.setEncoding(encoding);

	Item item1 = new Item();
	item1.setTitle("title1");

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(channel, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)),
			outputMessage.getHeaders().getContentType());
}
 
Example #12
Source File: HotArticleRssContentView.java    From kaif with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildFeedMetadata(Map<String, Object> model,
    Channel feed,
    HttpServletRequest request) {
  ZoneInfo zoneInfo = (ZoneInfo) model.get("zoneInfo");
  @SuppressWarnings("unchecked")
  List<Article> articles = (List<Article>) model.get("articles");
  if (zoneInfo != null) {
    feed.setTitle(zoneInfo.getName() + " kaif.io");
    feed.setLink(zoneUrl(zoneInfo.getZone()));
    feed.setDescription(zoneInfo.getAliasName() + " 熱門");
    feed.setPubDate(buildFeedUpdateTime(articles, zoneInfo.getCreateTime()));
  } else {
    feed.setTitle("熱門 kaif.io");
    feed.setLink(SCHEME_AND_HOST);
    feed.setDescription("綜合熱門");
    feed.setPubDate(buildFeedUpdateTime(articles, DEFAULT_INSTANT));
  }
}
 
Example #13
Source File: RssChannelHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void read() throws IOException {
	InputStream is = getClass().getResourceAsStream("rss.xml");
	MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
	inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", StandardCharsets.UTF_8));
	Channel result = converter.read(Channel.class, inputMessage);
	assertEquals("title", result.getTitle());
	assertEquals("https://example.com", result.getLink());
	assertEquals("description", result.getDescription());

	List<?> items = result.getItems();
	assertEquals(2, items.size());

	Item item1 = (Item) items.get(0);
	assertEquals("title1", item1.getTitle());

	Item item2 = (Item) items.get(1);
	assertEquals("title2", item2.getTitle());
}
 
Example #14
Source File: ArticleRssController.java    From tutorials with MIT License 6 votes vote down vote up
@GetMapping(value = "/rss2", produces = {"application/rss+xml", "application/rss+json"})
@ResponseBody
public Channel articleHttpFeed() {
    List<Article> items = new ArrayList<>();
    Article item1 = new Article();
    item1.setLink("http://www.baeldung.com/netty-exception-handling");
    item1.setTitle("Exceptions in Netty");
    item1.setDescription("In this quick article, we’ll be looking at exception handling in Netty.");
    item1.setPublishedDate(new Date());
    item1.setAuthor("Carlos");

    Article item2 = new Article();
    item2.setLink("http://www.baeldung.com/cockroachdb-java");
    item2.setTitle("Guide to CockroachDB in Java");
    item2.setDescription("This tutorial is an introductory guide to using CockroachDB with Java.");
    item2.setPublishedDate(new Date());
    item2.setAuthor("Baeldung");

    items.add(item1);
    items.add(item2);
    Channel channelData = buildChannel(items);

    return channelData;
}
 
Example #15
Source File: ArticleRssController.java    From tutorials with MIT License 6 votes vote down vote up
private Channel buildChannel(List<Article> articles){
    Channel channel = new Channel("rss_2.0");
    channel.setLink("http://localhost:8080/spring-mvc-simple/rss");
    channel.setTitle("Article Feed");
    channel.setDescription("Article Feed Description");
    channel.setPubDate(new Date());

    List<Item> items = new ArrayList<>();
    for (Article article : articles) {
        Item item = new Item();
        item.setLink(article.getLink());
        item.setTitle(article.getTitle());
        Description description1 = new Description();
        description1.setValue(article.getDescription());
        item.setDescription(description1);
        item.setPubDate(article.getPublishedDate());
        item.setAuthor(article.getAuthor());
        items.add(item);
    }

    channel.setItems(items);
    return channel;
}
 
Example #16
Source File: RSS092Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateChannel(final Channel channel, final Element eChannel) {

    super.populateChannel(channel, eChannel);

    final Cloud cloud = channel.getCloud();
    if (cloud != null) {
        eChannel.addContent(generateCloud(cloud));
    }

}
 
Example #17
Source File: RSS090Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
protected void addItems(final Channel channel, final Element parent) throws FeedException {
    final List<Item> items = channel.getItems();
    for (int i = 0; i < items.size(); i++) {
        addItem(items.get(i), parent, i);
    }
    checkItemsConstraints(parent);
}
 
Example #18
Source File: TestSyndFeedRSS20.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testPreserveWireFeedComments() throws Exception {
    final WireFeed wf = this.getCachedSyndFeed(true).originalWireFeed();
    assertNotNull(wf);
    assertTrue(wf instanceof Channel);
    if (wf instanceof Channel) {
        final Channel channel = (Channel) wf;
        assertEquals("rss_2.0.channel.item[0].comments", channel.getItems().get(0).getComments());
        assertEquals("rss_2.0.channel.item[1].comments", channel.getItems().get(1).getComments());
    }
}
 
Example #19
Source File: JsonChannelHttpMessageConverter.java    From tutorials with MIT License 5 votes vote down vote up
@Override
protected void writeInternal(Channel wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    WireFeedOutput feedOutput = new WireFeedOutput();

    try {
        String xmlStr = feedOutput.outputString(wireFeed, true);
        JSONObject xmlJSONObj = XML.toJSONObject(xmlStr);
        String jsonPrettyPrintString = xmlJSONObj.toString(4);

        outputMessage.getBody().write(jsonPrettyPrintString.getBytes());
    } catch (JSONException | FeedException e) {
        e.printStackTrace();
    }
}
 
Example #20
Source File: RSS091UserlandGenerator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected Element createRootElement(final Channel channel) {
    final Element root = new Element("rss", getFeedNamespace());
    final Attribute version = new Attribute("version", getVersion());
    root.setAttribute(version);
    root.addNamespaceDeclaration(getContentNamespace());
    generateModuleNamespaceDefs(root);
    return root;
}
 
Example #21
Source File: Issue162Test.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeed() throws Exception {
    final Channel channel = (Channel) getCachedWireFeed();
    assertProperty(channel.getDocs(), "channel.docs");
    assertProperty(channel.getGenerator(), "channel.generator");
    assertProperty(channel.getManagingEditor(), "channel.managingEditor");
    assertProperty(channel.getWebMaster(), "channel.webMaster");
}
 
Example #22
Source File: ArticleFeedView.java    From tutorials with MIT License 5 votes vote down vote up
protected Channel newFeed() {
    Channel channel = new Channel("rss_2.0");
    channel.setLink("http://localhost:8080/rss");
    channel.setTitle("Article Feed");
    channel.setDescription("Article Feed Description");
    channel.setPubDate(new Date());
    return channel;
}
 
Example #23
Source File: RSS090Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
protected void addChannel(final Channel channel, final Element parent) throws FeedException {
    final Element eChannel = new Element("channel", getFeedNamespace());
    populateChannel(channel, eChannel);
    checkChannelConstraints(eChannel);
    parent.addContent(eChannel);
    generateFeedModules(channel.getModules(), eChannel);
}
 
Example #24
Source File: RSS10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
    final String uri = eChannel.getAttributeValue("about", getRDFNamespace());
    if (uri != null) {
        channel.setUri(uri);
    }

    return channel;
}
 
Example #25
Source File: ConverterForRSS094.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);
    final List<SyndCategory> cats = syndFeed.getCategories(); // c
    if (!cats.isEmpty()) {
        channel.setCategories(createRSSCategories(cats));
    }
    return channel;
}
 
Example #26
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = new Channel(type);
    channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
    channel.setStyleSheet(syndFeed.getStyleSheet());
    channel.setEncoding(syndFeed.getEncoding());

    channel.setTitle(syndFeed.getTitle());
    final String link = syndFeed.getLink();
    final List<SyndLink> links = syndFeed.getLinks();
    if (link != null) {
        channel.setLink(link);
    } else if (!links.isEmpty()) {
        channel.setLink(links.get(0).getHref());
    }

    channel.setDescription(syndFeed.getDescription());

    final SyndImage sImage = syndFeed.getImage();
    if (sImage != null) {
        channel.setImage(createRSSImage(sImage));
    }

    final List<SyndEntry> sEntries = syndFeed.getEntries();
    if (sEntries != null) {
        channel.setItems(createRSSItems(sEntries));
    }

    final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
    if (!foreignMarkup.isEmpty()) {
        channel.setForeignMarkup(foreignMarkup);
    }

    return channel;
}
 
Example #27
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {

    syndFeed.setModules(ModuleUtils.cloneModules(feed.getModules()));

    final List<Element> foreignMarkup = feed.getForeignMarkup();
    if (!foreignMarkup.isEmpty()) {
        syndFeed.setForeignMarkup(foreignMarkup);
    }

    syndFeed.setStyleSheet(feed.getStyleSheet());

    syndFeed.setEncoding(feed.getEncoding());

    final Channel channel = (Channel) feed;

    syndFeed.setTitle(channel.getTitle());
    syndFeed.setLink(channel.getLink());
    syndFeed.setDescription(channel.getDescription());

    final Image image = channel.getImage();
    if (image != null) {
        syndFeed.setImage(createSyndImage(image));
    }

    final List<Item> items = channel.getItems();
    if (items != null) {
        syndFeed.setEntries(createSyndEntries(items, syndFeed.isPreservingWireFeed()));
    }
}
 
Example #28
Source File: DocumentRssFeedView.java    From jakduk-api with MIT License 5 votes vote down vote up
/**
 * Create a new Channel instance to hold the entries.
 * <p>By default returns an RSS 2.0 channel, but the subclass can specify any channel.
 */
@Override protected Channel newFeed() {
	Channel channel = new Channel("rss_2.0");
	channel.setLink(String.format("%s/%s", jakdukProperties.getWebServerUrl(), "/rss"));
	channel.setTitle(JakdukUtils.getMessageSource("common.jakduk"));
	channel.setDescription(JakdukUtils.getMessageSource("common.jakduk.rss.description"));

	return channel;
}
 
Example #29
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * This puts the pieces together to generate the actual feed.
 * 
 * @param title
 *            The global title for the podcast
 * @param link
 *            The URL for the feed
 * @param description_loc
 *            Global description of the feed
 * @param copyright
 *            Copyright information
 * @param entries
 *            The list of individual podcasts
 * @param feedTyle
 * 			 The output feed type (for potential future development). Set to rss_2.0
 * @param pubDate
 * 			 The date to set the publish date for this feed
 * 
 * @eturn SyndFeed
 * 			The entire podcast stuffed into a SyndFeed object
 */
private Channel doSyndication(Map feedInfo, List entries,
		String feedType, Date pubDate, Date lastBuildDate) {

	final Channel channel = new Channel();

	// FUTURE: How to determine what podcatcher supports and feed that to them
	channel.setFeedType(feedType);
	channel.setTitle((String) feedInfo.get("title"));
	channel.setLanguage(LANGUAGE);

	channel.setPubDate(pubDate);
	channel.setLastBuildDate(lastBuildDate);

	channel.setLink((String) feedInfo.get("url"));
	channel.setDescription((String) feedInfo.get("desc"));		
	channel.setCopyright((String) feedInfo.get("copyright"));
	channel.setGenerator((String) feedInfo.get("gen"));

	channel.setItems(entries);

	// Used to remove the dc: tags from the channel level info
	List modules = new ArrayList();
	
	channel.setModules(modules);

	return channel;
}
 
Example #30
Source File: RssFeedView.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Override
protected void buildFeedMetadata(
		Map<String, Object> model, 
		Channel feed,
		HttpServletRequest request) {
	Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
	String language = LocaleContextHolder.getLocale().getLanguage();

	feed.setTitle(blog.getTitle(language));
	feed.setDescription(blog.getTitle(language));

	UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
	feed.setLink(builder.buildAndExpand().toUriString());
}