Java Code Examples for com.sun.syndication.feed.synd.SyndEntry#getEnclosures()

The following examples show how to use com.sun.syndication.feed.synd.SyndEntry#getEnclosures() . 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: FeedManagerImpl.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a <code>SyndEntry</code> into an <code>Item</code>
 * 
 * @param entry
 *            The SyndEntry
 * @return The Item
 */
private Item convertToItem(final SyndEntry entry) {
    // A SyncEntry can potentially have many attributes like title, description,
    // guid, link, enclosure or content. In OLAT, however, items are limited
    // to the attributes, title, description and one media file (called
    // enclosure in RSS) for simplicity.
    final Item e = new Item();
    e.setTitle(entry.getTitle());
    e.setDescription(entry.getDescription() != null ? entry.getDescription().getValue() : null);
    // Extract content objects from syndication item
    final StringBuffer sb = new StringBuffer();
    for (final SyndContent content : (List<SyndContent>) entry.getContents()) {
        // we don't check for type, assume it is html or txt
        if (sb.length() > 0) {
            sb.append("<p />");
        }
        sb.append(content.getValue());
    }
    // Set aggregated content from syndication item as our content
    if (sb.length() > 0) {
        e.setContent(sb.toString());
    }
    e.setGuid(entry.getUri());
    e.setExternalLink(entry.getLink());
    e.setLastModified(entry.getUpdatedDate());
    e.setPublishDate(entry.getPublishedDate());

    for (final Object enclosure : entry.getEnclosures()) {
        if (enclosure instanceof SyndEnclosure) {
            final SyndEnclosure syndEnclosure = (SyndEnclosure) enclosure;
            final Enclosure media = new Enclosure();
            media.setExternalUrl(syndEnclosure.getUrl());
            media.setType(syndEnclosure.getType());
            media.setLength(syndEnclosure.getLength());
            e.setEnclosure(media);
        }
        // Break after one cycle because only one media file is supported
        break;
    }
    return e;
}
 
Example 2
Source File: FeedManagerImpl.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a <code>SyndEntry</code> into an <code>Item</code>
 * 
 * @param entry
 *            The SyndEntry
 * @return The Item
 */
private Item convertToItem(final SyndEntry entry) {
    // A SyncEntry can potentially have many attributes like title, description,
    // guid, link, enclosure or content. In OLAT, however, items are limited
    // to the attributes, title, description and one media file (called
    // enclosure in RSS) for simplicity.
    final Item e = new Item();
    e.setTitle(entry.getTitle());
    e.setDescription(entry.getDescription() != null ? entry.getDescription().getValue() : null);
    // Extract content objects from syndication item
    final StringBuffer sb = new StringBuffer();
    for (final SyndContent content : (List<SyndContent>) entry.getContents()) {
        // we don't check for type, assume it is html or txt
        if (sb.length() > 0) {
            sb.append("<p />");
        }
        sb.append(content.getValue());
    }
    // Set aggregated content from syndication item as our content
    if (sb.length() > 0) {
        e.setContent(sb.toString());
    }
    e.setGuid(entry.getUri());
    e.setExternalLink(entry.getLink());
    e.setLastModified(entry.getUpdatedDate());
    e.setPublishDate(entry.getPublishedDate());

    for (final Object enclosure : entry.getEnclosures()) {
        if (enclosure instanceof SyndEnclosure) {
            final SyndEnclosure syndEnclosure = (SyndEnclosure) enclosure;
            final Enclosure media = new Enclosure();
            media.setExternalUrl(syndEnclosure.getUrl());
            media.setType(syndEnclosure.getType());
            media.setLength(syndEnclosure.getLength());
            e.setEnclosure(media);
        }
        // Break after one cycle because only one media file is supported
        break;
    }
    return e;
}