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

The following examples show how to use com.rometools.rome.feed.rss.Enclosure. 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: RSS092Generator.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 Source source = item.getSource();
    if (source != null) {
        eItem.addContent(generateSourceElement(source));
    }

    final List<Enclosure> enclosures = item.getEnclosures();
    for (int i = 0; i < getNumberOfEnclosures(enclosures); i++) {
        eItem.addContent(generateEnclosure(enclosures.get(i)));
    }

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

}
 
Example #2
Source File: RSS092Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
protected Element generateEnclosure(final Enclosure enclosure) {

        final Element enclosureElement = new Element("enclosure", getFeedNamespace());

        final String url = enclosure.getUrl();
        if (url != null) {
            enclosureElement.setAttribute("url", url);
        }

        final long length = enclosure.getLength();
        if (length != 0) {
            enclosureElement.setAttribute("length", String.valueOf(length));
        }

        final String type = enclosure.getType();
        if (type != null) {
            enclosureElement.setAttribute("type", type);
        }

        return enclosureElement;
    }
 
Example #3
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 #4
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 #5
Source File: ConverterForRSS092.java    From rome with Apache License 2.0 5 votes vote down vote up
protected List<SyndEnclosure> createSyndEnclosures(final List<Enclosure> enclosures) {
    final List<SyndEnclosure> sEnclosures = new ArrayList<SyndEnclosure>();
    for (final Enclosure enc : enclosures) {
        final SyndEnclosure sEnc = new SyndEnclosureImpl();
        sEnc.setUrl(enc.getUrl());
        sEnc.setType(enc.getType());
        sEnc.setLength(enc.getLength());
        sEnclosures.add(sEnc);
    }
    return sEnclosures;
}
 
Example #6
Source File: ConverterForRSS092.java    From rome with Apache License 2.0 5 votes vote down vote up
protected List<Enclosure> createEnclosures(final List<SyndEnclosure> sEnclosures) {
    final List<Enclosure> enclosures = new ArrayList<Enclosure>();
    for (final SyndEnclosure sEnc : sEnclosures) {
        final Enclosure enc = new Enclosure();
        enc.setUrl(sEnc.getUrl());
        enc.setType(sEnc.getType());
        enc.setLength(sEnc.getLength());
        enclosures.add(enc);
    }
    return enclosures;
}
 
Example #7
Source File: RSS092Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
protected int getNumberOfEnclosures(final List<Enclosure> enclosures) {
    if (!enclosures.isEmpty()) {
        return 1;
    } else {
        return 0;
    }
}
 
Example #8
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 #9
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 #10
Source File: RSS093Generator.java    From rome with Apache License 2.0 4 votes vote down vote up
@Override
protected int getNumberOfEnclosures(final List<Enclosure> enclosures) {
    return enclosures.size();
}
 
Example #11
Source File: ConverterForRSS092.java    From rome with Apache License 2.0 3 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

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

    final List<Category> cats = item.getCategories();

    if (!cats.isEmpty()) {

        // using a set to remove duplicates and use a LinkedHashSet to try to retain the
        // document order
        final Set<SyndCategory> s = new LinkedHashSet<SyndCategory>();

        // feed native categories (as syndcat)
        s.addAll(createSyndCategories(cats));

        // DC subjects (as syndcat)
        s.addAll(syndEntry.getCategories());

        syndEntry.setCategories(new ArrayList<SyndCategory>(s)); // c
    }

    final List<Enclosure> enclosures = item.getEnclosures();
    if (!enclosures.isEmpty()) {
        syndEntry.setEnclosures(createSyndEnclosures(enclosures));
    }

    return syndEntry;

}