當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。