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

The following examples show how to use com.rometools.rome.feed.rss.Description. 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: ArticleFeedView.java    From tutorials with MIT License 6 votes vote down vote up
@Override
protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception {
    List list = new ArrayList<Item>();

    Item item1 = new Item();
    item1.setLink("http://www.baeldung.com/netty-exception-handling");
    item1.setTitle("Exceptions in Netty");
    Description description1 = new Description();
    description1.setValue("In this quick article, we’ll be looking at exception handling in Netty.");
    item1.setDescription(description1);
    item1.setPubDate(new Date());
    item1.setAuthor("Carlos");

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

    list.add(item1);
    list.add(item2);
    return list;
}
 
Example #2
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 #3
Source File: ArticleFeedView.java    From tutorials with MIT License 6 votes vote down vote up
@Override
protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception {
    List list = new ArrayList<Item>();

    Item item1 = new Item();
    item1.setLink("http://www.baeldung.com/netty-exception-handling");
    item1.setTitle("Exceptions in Netty");
    Description description1 = new Description();
    description1.setValue("In this quick article, we’ll be looking at exception handling in Netty.");
    item1.setDescription(description1);
    item1.setPubDate(new Date());
    item1.setAuthor("Carlos");

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

    list.add(item1);
    list.add(item2);
    return list;
}
 
Example #4
Source File: FoundPodcastsRssFeedView.java    From podcastpedia-web with MIT License 6 votes vote down vote up
protected List buildFeedItems(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    	
        List<Podcast> podcasts = (List<Podcast>) model.get("list_of_podcasts");
        List<Item> items = new ArrayList<Item>(podcasts.size());

        for (Podcast podcast : podcasts) {
            Item item = new Item();
//            String date = String.format("%1$tY-%1$tm-%1$td", podcast.getLastEpisode().getPublicationDate());
            item.setTitle(podcast.getTitle());
            item.setPubDate(podcast.getPublicationDate());
            item.setLink(model.get("HOST_AND_PORT_URL") + "/podcasts/" + podcast.getPodcastId() 
            		+ "/" + podcast.getTitleInUrl());
            
            Description podcastDescription = new Description();
            podcastDescription.setValue(podcast.getDescription());
            item.setDescription(podcastDescription);  
                        
            items.add(item);
        }

        return items;
    }
 
Example #5
Source File: RssFeedView.java    From wallride with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected List<Item> buildFeedItems(
		Map<String, Object> model,
		HttpServletRequest request,
		HttpServletResponse response)
throws Exception {
	Set<Article> articles = (Set<Article>)model.get("articles");
	List<Item> items = new ArrayList<>(articles.size());
	for (Article article : articles) {
		Item item = new Item();
		item.setTitle(article.getTitle());
		item.setPubDate(Date.from(article.getDate().atZone(ZoneId.systemDefault()).toInstant()));
		Description description = new Description();
		description.setType("text/html");
		description.setValue(article.getBody());
		item.setDescription(description);
		item.setLink(link(article));
		items.add(item);
	}
	return items;
}
 
Example #6
Source File: RSS091UserlandGenerator.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {

    super.populateItem(item, eItem, index);

    final Description description = item.getDescription();
    if (description != null) {
        eItem.addContent(generateSimpleElement("description", description.getValue()));
    }

    final Namespace contentNamespace = getContentNamespace();
    final Content content = item.getContent();
    if (item.getModule(contentNamespace.getURI()) == null && content != null) {
        final Element elem = new Element("encoded", contentNamespace);
        elem.addContent(content.getValue());
        eItem.addContent(elem);
    }

}
 
Example #7
Source File: RSS10Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {

    super.populateItem(item, eItem, index);

    final String link = item.getLink();
    final String uri = item.getUri();
    if (uri != null) {
        eItem.setAttribute("about", uri, getRDFNamespace());
    } else if (link != null) {
        eItem.setAttribute("about", link, getRDFNamespace());
    }

    final Description description = item.getDescription();
    if (description != null) {
        eItem.addContent(generateSimpleElement("description", description.getValue()));
    }

    if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) {
        final Element elem = new Element("encoded", getContentNamespace());
        elem.addContent(item.getContent().getValue());
        eItem.addContent(elem);
    }

}
 
Example #8
Source File: RssFeedViewTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected List<Item> buildFeedItems(Map<String, Object> model,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Item> items = new ArrayList<>();
	for (String name : model.keySet()) {
		Item item = new Item();
		item.setTitle(name);
		Description description = new Description();
		description.setValue((String) model.get(name));
		item.setDescription(description);
		items.add(item);
	}
	return items;
}
 
Example #9
Source File: RSS090DescriptionParser.java    From commafeed with Apache License 2.0 5 votes vote down vote up
@Override
protected Item parseItem(Element rssRoot, Element eItem, Locale locale) {
	Item item = super.parseItem(rssRoot, eItem, locale);
	Element e = eItem.getChild("description", getRSSNamespace());
	if (e != null) {
		Description desc = new Description();
		desc.setValue(e.getText());
		item.setDescription(desc);
	}

	return item;
}
 
Example #10
Source File: RSS090DescriptionConverter.java    From commafeed with Apache License 2.0 5 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) {
	SyndEntry entry = super.createSyndEntry(item, preserveWireItem);
	Description desc = item.getDescription();
	if (desc != null) {
		SyndContentImpl syndDesc = new SyndContentImpl();
		syndDesc.setValue(desc.getValue());
		entry.setDescription(syndDesc);
	}
	return entry;
}
 
Example #11
Source File: RSS094Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected void populateItem(final Item item, final Element eItem, final int index) {
    super.populateItem(item, eItem, index);

    final Description description = item.getDescription();
    if (description != null && description.getType() != null) {
        final Element eDescription = eItem.getChild("description", getFeedNamespace());
        eDescription.setAttribute(new Attribute("type", description.getType()));
    }
    eItem.removeChild("expirationDate", getFeedNamespace());
}
 
Example #12
Source File: RSS092Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {
    final Description desc = new Description();
    final StringBuilder sb = new StringBuilder();
    final XMLOutputter xmlOut = new XMLOutputter();
    for (final Content c : eDesc.getContent()) {
        switch (c.getCType()) {
            case Text:
            case CDATA:
                sb.append(c.getValue());
                break;
            case EntityRef:
                LOG.debug("Entity: {}", c.getValue());
                sb.append(c.getValue());
                break;
            case Element:
                sb.append(xmlOut.outputString((Element) c));
                break;
            default:
                // ignore
                break;
        }
    }
    desc.setValue(sb.toString());
    String att = eDesc.getAttributeValue("type");
    if (att == null) {
        att = "text/html";
    }
    desc.setType(att);
    return desc;
}
 
Example #13
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

    final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);

    final Description desc = item.getDescription();

    syndEntry.setComments(item.getComments());

    // DublinCoreTest will be failed without this row
    // I don't have better solution
    if (syndEntry.getPublishedDate() == null)
        syndEntry.setPublishedDate(item.getPubDate());

    if (desc != null) {
        final SyndContent descContent = new SyndContentImpl();
        descContent.setType(desc.getType());
        descContent.setValue(desc.getValue());
        syndEntry.setDescription(descContent);
    }

    final Content cont = item.getContent();

    if (cont != null) {
        final SyndContent content = new SyndContentImpl();
        content.setType(cont.getType());
        content.setValue(cont.getValue());

        final List<SyndContent> syndContents = new ArrayList<SyndContent>();
        syndContents.add(content);
        syndEntry.setContents(syndContents);
    }

    return syndEntry;
}
 
Example #14
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

    final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);

    final Description desc = item.getDescription();
    if (desc != null) {
        final SyndContent descContent = new SyndContentImpl();
        descContent.setType(desc.getType());
        descContent.setValue(desc.getValue());
        syndEntry.setDescription(descContent);
    }

    final Content cont = item.getContent();
    if (cont != null) {

        final SyndContent contContent = new SyndContentImpl();
        contContent.setType(cont.getType());
        contContent.setValue(cont.getValue());

        final List<SyndContent> contents = new ArrayList<SyndContent>();
        contents.add(contContent);
        syndEntry.setContents(contents);

    }

    return syndEntry;

}
 
Example #15
Source File: DocumentRssFeedView.java    From jakduk-api with MIT License 5 votes vote down vote up
private Description createDescription(String content) {
	Description description = new Description();
	description.setType(Content.HTML);
	description.setValue(content);

	return description;
}
 
Example #16
Source File: GenericRssFeedView.java    From podcastpedia-web with MIT License 5 votes vote down vote up
protected List buildFeedItems(Map model, HttpServletRequest request, HttpServletResponse response)
    throws Exception {
	
    List<Podcast> podcasts = (List<Podcast>) model.get("list_of_podcasts");
    List<Item> items = new ArrayList<Item>(podcasts.size());

    for (Podcast podcast : podcasts) {
        Episode episode = podcast.getLastEpisode();
        Item item = new Item();
        String date = String.format("%1$tY-%1$tm-%1$td", episode.getPublicationDate());
        item.setTitle(podcast.getTitle()+ " - " + episode.getTitle());
        item.setPubDate(podcast.getPublicationDate());
        item.setLink( model.get("HOST_AND_PORT_URL") + "/podcasts/" + podcast.getPodcastId() 
        		+ "/" + podcast.getTitleInUrl() );
        
        Description episodeDescription = new Description();
        episodeDescription.setValue(episode.getDescription());
        item.setDescription(episodeDescription);  
        
        //set enclosures
        List<Enclosure> enclosures = new ArrayList<Enclosure>();
        Enclosure enclosure = new Enclosure();
        enclosure.setUrl(episode.getMediaUrl());    
        if(episode.getLength() != null) enclosure.setLength(episode.getLength());
        if(episode.getEnclosureType() != null ) enclosure.setType(episode.getEnclosureType());             
        enclosures.add(enclosure);
        item.setEnclosures(enclosures);
        
        items.add(item);
    }

    return items;
}
 
Example #17
Source File: FoundEpisodesRssFeedView.java    From podcastpedia-web with MIT License 5 votes vote down vote up
protected List buildFeedItems(Map model, HttpServletRequest request, HttpServletResponse response)
    throws Exception {
	
    List<Episode> episodes = (List<Episode>) model.get("list_of_episodes");
    List<Item> items = new ArrayList<Item>(episodes.size());

    for (Episode episode : episodes) {
        Item item = new Item();
        String date = String.format("%1$tY-%1$tm-%1$td", episode.getPublicationDate());
        item.setTitle(episode.getTitle());
        item.setPubDate(episode.getPublicationDate());
        item.setLink(model.get("HOST_AND_PORT_URL") + "/podcasts/" + episode.getPodcastId() 
        		+ "/" + episode.getPodcast().getTitleInUrl()+ "/episodes/" + episode.getEpisodeId()
        		+ "/" + episode.getTitleInUrl());
        
        Description episodeDescription = new Description();
        episodeDescription.setValue(episode.getDescription());
        item.setDescription(episodeDescription);  
        
        //set enclosures
        List<Enclosure> enclosures = new ArrayList<Enclosure>();
        Enclosure enclosure = new Enclosure();
        enclosure.setUrl(episode.getMediaUrl());
        if(episode.getLength() != null) enclosure.setLength(episode.getLength());
        if(episode.getEnclosureType() != null ) enclosure.setType(episode.getEnclosureType()); 
        enclosures.add(enclosure);
        item.setEnclosures(enclosures);
        
        items.add(item);
    }

    return items;
}
 
Example #18
Source File: HotArticleRssContentView.java    From kaif with Apache License 2.0 5 votes vote down vote up
private Item convertArticle(Article article) {
  Item entry = new Item();
  Guid guid = new Guid();
  guid.setValue(article.getArticleId().toString());
  entry.setGuid(guid);
  entry.setTitle(cleanXml10Characters(article.getTitle()));
  entry.setPubDate(Date.from(article.getCreateTime()));
  Description summary = new Description();
  summary.setType("html");
  summary.setValue(buildSummary(article));
  entry.setDescription(summary);
  entry.setLink(articleUrl(article));
  return entry;
}
 
Example #19
Source File: RssFeedViewTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	List<Item> items = new ArrayList<Item>();
	for (String name : model.keySet()) {
		Item item = new Item();
		item.setTitle(name);
		Description description = new Description();
		description.setValue((String) model.get(name));
		item.setDescription(description);
		items.add(item);
	}
	return items;
}
 
Example #20
Source File: RssFeedViewTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected List<Item> buildFeedItems(Map<String, Object> model,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Item> items = new ArrayList<>();
	for (String name : model.keySet()) {
		Item item = new Item();
		item.setTitle(name);
		Description description = new Description();
		description.setValue((String) model.get(name));
		item.setDescription(description);
		items.add(item);
	}
	return items;
}
 
Example #21
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Description createItemDescription(final SyndContent sContent) {
    final Description desc = new Description();
    desc.setValue(sContent.getValue());
    desc.setType(sContent.getType());
    return desc;
}
 
Example #22
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Description createItemDescription(final SyndContent sContent) {
    final Description desc = new Description();
    desc.setValue(sContent.getValue());
    desc.setType(sContent.getType());
    return desc;
}
 
Example #23
Source File: RSS10Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {
    final Description desc = new Description();
    desc.setType("text/plain");
    desc.setValue(eDesc.getText());
    return desc;
}
 
Example #24
Source File: RSS20Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
@Override
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {
    final Description desc = super.parseItemDescription(rssRoot, eDesc);
    return desc;
}
 
Example #25
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * This add a particular podcast to the feed.
 * 
 * @param title
 *            The title for this podcast
 * @param mp3link
 *            The URL where the podcast is stored
 * @param date
 *            The publish date for this podcast
 * @param blogContent
 *            The description of this podcast
 * @param cat
 *            The category of entry this is (Podcast)
 * @param author
 *            The author of this podcast
 * 
 * @return 
 * 			 A SyndEntryImpl for this podcast
 */
private Item addPodcast(Map values) 
{
	final Item item = new Item();

	// set title for this podcast
	item.setTitle((String) values.get("title"));

       // Replace all occurrences of pattern (ie, spaces) in input
       // with hex equivalent (%20)
       Pattern pattern = Pattern.compile(" ");
       String url = (String) values.get("url");
       Matcher matcher = pattern.matcher(url);
       url = matcher.replaceAll("%20");
       item.setLink(url);

       // Set Publish date for this podcast/episode
       // NOTE: date has local time, but when feed rendered,
       // converts it to GMT
	item.setPubDate((Date) values.get("date"));

	// Set description for this podcast/episode
	final Description itemDescription = new Description();
	itemDescription.setType(DESCRIPTION_CONTENT_TYPE);
	itemDescription.setValue((String) values.get("description"));
	item.setDescription(itemDescription);

	// Set guid for this podcast/episode
	item.setGuid(new Guid());
	item.getGuid().setValue((String) values.get("guid"));
	item.getGuid().setPermaLink(false);

	// This creates the enclosure so podcatchers (iTunes) can
	// find the podcasts		
	List enclosures = new ArrayList();

	final Enclosure enc = new Enclosure();
	enc.setUrl(url);
	enc.setType((String) values.get("type"));
	enc.setLength((Long) values.get("len"));

	enclosures.add(enc);

	item.setEnclosures(enclosures);

	// Currently uses 2 modules:
	//  iTunes for podcasting
	//  DCmodule since validators want email with author tag, 
	//    so use dc:creator instead
	List modules = new ArrayList();
	
	// Generate the iTunes tags
	final EntryInformation iTunesModule = new EntryInformationImpl();

	iTunesModule.setAuthor(getMessageBundleString(FEED_ITEM_AUTHOR_STRING));
	iTunesModule.setSummary((String) values.get("description"));

	// Set dc:creator tag
	final DCModuleImpl dcModule = new DCModuleImpl();
	
	dcModule.setCreator((String) values.get("author"));
	
	modules.add(iTunesModule);
	modules.add(dcModule);
	
	item.setModules(modules);
	
	return item;
}
 
Example #26
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * This add a particular podcast to the feed.
 * 
 * @param title
 *            The title for this podcast
 * @param mp3link
 *            The URL where the podcast is stored
 * @param date
 *            The publish date for this podcast
 * @param blogContent
 *            The description of this podcast
 * @param cat
 *            The category of entry this is (Podcast)
 * @param author
 *            The author of this podcast
 * 
 * @return 
 * 			 A SyndEntryImpl for this podcast
 */
private Item addPodcast(Map values) 
{
	final Item item = new Item();

	// set title for this podcast
	item.setTitle((String) values.get("title"));

       // Replace all occurrences of pattern (ie, spaces) in input
       // with hex equivalent (%20)
       Pattern pattern = Pattern.compile(" ");
       String url = (String) values.get("url");
       Matcher matcher = pattern.matcher(url);
       url = matcher.replaceAll("%20");
       item.setLink(url);

       // Set Publish date for this podcast/episode
       // NOTE: date has local time, but when feed rendered,
       // converts it to GMT
	item.setPubDate((Date) values.get("date"));

	// Set description for this podcast/episode
	final Description itemDescription = new Description();
	itemDescription.setType(DESCRIPTION_CONTENT_TYPE);
	itemDescription.setValue((String) values.get("description"));
	item.setDescription(itemDescription);

	// Set guid for this podcast/episode
	item.setGuid(new Guid());
	item.getGuid().setValue((String) values.get("guid"));
	item.getGuid().setPermaLink(false);

	// This creates the enclosure so podcatchers (iTunes) can
	// find the podcasts		
	List enclosures = new ArrayList();

	final Enclosure enc = new Enclosure();
	enc.setUrl(url);
	enc.setType((String) values.get("type"));
	enc.setLength((Long) values.get("len"));

	enclosures.add(enc);

	item.setEnclosures(enclosures);

	// Currently uses 2 modules:
	//  iTunes for podcasting
	//  DCmodule since validators want email with author tag, 
	//    so use dc:creator instead
	List modules = new ArrayList();
	
	// Generate the iTunes tags
	final EntryInformation iTunesModule = new EntryInformationImpl();

	iTunesModule.setAuthor(getMessageBundleString(FEED_ITEM_AUTHOR_STRING));
	iTunesModule.setSummary((String) values.get("description"));

	// Set dc:creator tag
	final DCModuleImpl dcModule = new DCModuleImpl();
	
	dcModule.setCreator((String) values.get("author"));
	
	modules.add(iTunesModule);
	modules.add(dcModule);
	
	item.setModules(modules);
	
	return item;
}