当前位置: 首页>>代码示例>>Java>>正文


Java SyndEntry.getEnclosures方法代码示例

本文整理汇总了Java中com.sun.syndication.feed.synd.SyndEntry.getEnclosures方法的典型用法代码示例。如果您正苦于以下问题:Java SyndEntry.getEnclosures方法的具体用法?Java SyndEntry.getEnclosures怎么用?Java SyndEntry.getEnclosures使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.syndication.feed.synd.SyndEntry的用法示例。


在下文中一共展示了SyndEntry.getEnclosures方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRSSItem

import com.sun.syndication.feed.synd.SyndEntry; //导入方法依赖的package包/类
@Override
protected Item createRSSItem(SyndEntry sEntry) {
    Item item = super.createRSSItem(sEntry);

    List sCats =  sEntry.getCategories();    //c
    if (sCats.size()>0) {
        item.setCategories(createRSSCategories(sCats));
    }
    List sEnclosures = sEntry.getEnclosures();
    if (sEnclosures.size()>0) {
        item.setEnclosures(createEnclosures(sEnclosures));
    }
    return item;
}
 
开发者ID:4thline,项目名称:feeds,代码行数:15,代码来源:ConverterForRSS092.java

示例2: parse

import com.sun.syndication.feed.synd.SyndEntry; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void parse() throws Exception {
	SyndFeedInput input = new SyndFeedInput();
	byte b[] = downloadAndSendBinary(url);
	if (b != null) {
		SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(b)));
		name = feed.getTitle();
		if (feed.getCategories() != null && feed.getCategories().size() > 0) {
			SyndCategory category = (SyndCategory) feed.getCategories().get(0);
			tempCategory = category.getName();
		}
		List<SyndEntry> entries = feed.getEntries();
		for (SyndEntry entry : entries) {
			tempItemTitle = entry.getTitle();
			tempItemLink = entry.getLink();
			tempFeedLink = entry.getUri();
			tempItemThumbURL = null;

			ArrayList<Element> elements = (ArrayList<Element>) entry.getForeignMarkup();
			for (Element elt : elements) {
				if ("group".equals(elt.getName()) && "media".equals(elt.getNamespacePrefix())) {
					List<Content> subElts = elt.getContent();
					for (Content subelt : subElts) {
						if (subelt instanceof Element) {
							parseElement((Element) subelt, false);
						}
					}
				}
				parseElement(elt, true);
			}
			List<SyndEnclosure> enclosures = entry.getEnclosures();
			for (SyndEnclosure enc : enclosures) {
				if (StringUtils.isNotBlank(enc.getUrl())) {
					tempItemLink = enc.getUrl();
				}
			}
			manageItem();
		}
	}
	setLastModified(System.currentTimeMillis());
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:42,代码来源:Feed.java

示例3: parseFeedEnclosures

import com.sun.syndication.feed.synd.SyndEntry; //导入方法依赖的package包/类
/**
 * Parses the entries contained in an RSS feed, extracts the enclosures, converts them to an {@link Attachment}
 * adds them to the map with the entry uri as key.
 * <p>The RSS spec says there is only one enclosure per item so this is what we work with. We don't actually check this so it's possible
 * that if you have more than one enclosure attached to an item that only the latest one will be presented in the end.
 *
 * @param feed
 * @return
 */
public static Map<String, Attachment> parseFeedEnclosures(SyndFeed feed) {
	
	Map<String,Attachment> attachments = new HashMap<String,Attachment>();
	
	// image mime types that are ok to be rendered as an image
	List<String> imageTypes = new ArrayList<String>();
	imageTypes.add("image/jpeg");
	imageTypes.add("image/gif");
	imageTypes.add("image/png");
	imageTypes.add("image/jpg");
	
	List<SyndEntry> entries = feed.getEntries();
	for(SyndEntry entry: entries) {
		
		//get entry uri, but it could be blank so if so, skip this item
		if(StringUtils.isBlank(entry.getUri())) {
			continue;
		}
		
		//for each enclosure attached to an entry get the first one and use that.			
		List<SyndEnclosure> enclosures = entry.getEnclosures();
		for(SyndEnclosure e: enclosures) {
			
			//convert to an Attachment
			Attachment a = new Attachment();
			a.setUrl(e.getUrl());
			a.setDisplayLength(formatLength(e.getLength()));
			a.setType(e.getType());
			
			//process the url into a displayname (get just the filename from the full URL)
			String displayName = StringUtils.substringAfterLast(e.getUrl(), "/");
			if(StringUtils.isNotBlank(displayName)){
				a.setDisplayName(displayName);
			} else {
				a.setDisplayName(Messages.getString("view.attachment.default"));
			}
			
			//check if its an iamge we are able to display as the thumbnail for the entry
			if(imageTypes.contains(e.getType())){
				a.setImage(true);
			} 
			
			attachments.put(entry.getUri(), a);
		}
	}
	
	return attachments;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:58,代码来源:FeedParser.java

示例4: convertToItem

import com.sun.syndication.feed.synd.SyndEntry; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:huihoo,项目名称:olat,代码行数:48,代码来源:FeedManagerImpl.java

示例5: purgeFeed

import com.sun.syndication.feed.synd.SyndEntry; //导入方法依赖的package包/类
/**
 * @param seriesId
 * @param transcodingProfileId
 * @param feed
 */
@SuppressWarnings("rawtypes")
public void purgeFeed(String seriesId, String transcodingProfileId, SyndFeed feed) {
  final File encodingDirectory = new File(feedFilePath, transcodingProfileId);

  // delete feed
  final File feedFile = new File(encodingDirectory, seriesId + feedFileExtension);
  if (feedFile.canWrite()) {
    feedFile.delete();
  }

  // delete feed thumbnail
  final File feedThumbnail = new File(encodingDirectory, seriesId + PNG_EXTENSION);
  if (feedThumbnail.canWrite()) {
    feedThumbnail.delete();
  }

  // delete feed transformation
  final File feedTransformationFile =
      new File(encodingDirectory, seriesId + feedTransformationOutputFileExtension);
  if (feedTransformationFile.canWrite()) {
    feedTransformationFile.delete();
  }

  if (feed != null) {
    final Iterator it = feed.getEntries().iterator();
    while (it.hasNext()) {
      SyndEntry entry = (SyndEntry) it.next();
      final List enclosures = entry.getEnclosures();
      if (enclosures.size() > 0) {
        Iterator enclosureIterator = enclosures.iterator();
        while (enclosureIterator.hasNext()) {
          SyndEnclosure enclosure = (SyndEnclosure) enclosureIterator.next();
          String encUrl = enclosure.getUrl();
          encUrl = encUrl.substring(encUrl.lastIndexOf('/') + 1);

          final TranscodingProfile profile =
              transcodingProfilesDao.findAllProfiles().get(transcodingProfileId);
          if (profile != null) {
            profile.deleteEncoding(this.feedFilePath, enclosure.getUrl(), entry.getUri());
          } else {
            // fabricate a profile for the purpose of deleting the encoding output
            final TranscodingProfile fakeProfile = new TranscodingProfile();
            fakeProfile.setId(transcodingProfileId);
            if (enclosure.getUrl().endsWith(".m3u8")) {
              fakeProfile.setMode(TranscoderType.ONE_PASS_HTTP_SEGMENTED_VOD);
            } else {
              fakeProfile.setMode(TranscoderType.ONE_PASS);
            }

            fakeProfile.deleteEncoding(this.feedFilePath, enclosure.getUrl(), entry.getUri());
          }
        }
      } else {
        LOGGER.debug("No enclosures specified in the entry, continuing");
        continue;
      }
    }
  }

  // delete the encoding profile directory if it is empty following the purge
  if (encodingDirectory.list().length == 0) {
    LOGGER.info("Deleting empty encoding profile directory: "
        + encodingDirectory.getAbsolutePath());
    encodingDirectory.delete();
  }
}
 
开发者ID:skidder,项目名称:mythpodcaster,代码行数:72,代码来源:FeedFileAccessorImpl.java


注:本文中的com.sun.syndication.feed.synd.SyndEntry.getEnclosures方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。