com.rometools.rome.feed.synd.SyndEnclosure Java Examples

The following examples show how to use com.rometools.rome.feed.synd.SyndEnclosure. 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: ConverterForRSS092.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item createRSSItem(final SyndEntry sEntry) {

    final Item item = super.createRSSItem(sEntry);

    final List<SyndCategory> sCats = sEntry.getCategories(); // c
    if (!sCats.isEmpty()) {
        item.setCategories(createRSSCategories(sCats));
    }

    final List<SyndEnclosure> sEnclosures = sEntry.getEnclosures();
    if (!sEnclosures.isEmpty()) {
        item.setEnclosures(createEnclosures(sEnclosures));
    }

    return item;

}
 
Example #2
Source File: Entry.java    From commafeed with Apache License 2.0 6 votes vote down vote up
public SyndEntry asRss() {
	SyndEntry entry = new SyndEntryImpl();

	entry.setUri(getGuid());
	entry.setTitle(getTitle());
	entry.setAuthor(getAuthor());

	SyndContentImpl content = new SyndContentImpl();
	content.setValue(getContent());
	entry.setContents(Arrays.<SyndContent> asList(content));

	if (getEnclosureUrl() != null) {
		SyndEnclosureImpl enclosure = new SyndEnclosureImpl();
		enclosure.setType(getEnclosureType());
		enclosure.setUrl(getEnclosureUrl());
		entry.setEnclosures(Arrays.<SyndEnclosure> asList(enclosure));
	}

	entry.setLink(getUrl());
	entry.setPublishedDate(getDate());
	return entry;
}
 
Example #3
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public SyndEnclosure createSyndEnclosure(final Feed feed, final Entry entry, final Link link) {
    final SyndEnclosure syndEncl = new SyndEnclosureImpl();
    syndEncl.setUrl(link.getHrefResolved());
    syndEncl.setType(link.getType());
    syndEncl.setLength(link.getLength());
    return syndEncl;
}
 
Example #4
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public Link createAtomEnclosure(final SyndEnclosure syndEnclosure) {
    final Link link = new Link();
    link.setRel("enclosure");
    link.setType(syndEnclosure.getType());
    link.setHref(syndEnclosure.getUrl());
    link.setLength(syndEnclosure.getLength());
    return link;
}
 
Example #5
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
public SyndEnclosure createSyndEnclosure(final Entry entry, final Link link) {
    final SyndEnclosure syndEncl = new SyndEnclosureImpl();
    syndEncl.setUrl(link.getHrefResolved());
    syndEncl.setType(link.getType());
    syndEncl.setLength(link.getLength());
    return syndEncl;
}
 
Example #6
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
public Link createAtomEnclosure(final SyndEnclosure syndEnclosure) {
    final Link link = new Link();
    link.setRel("enclosure");
    link.setType(syndEnclosure.getType());
    link.setHref(syndEnclosure.getUrl());
    link.setLength(syndEnclosure.getLength());
    return link;
}
 
Example #7
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 #8
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 #9
Source File: TestSyndFeedRSS092.java    From rome with Apache License 2.0 5 votes vote down vote up
protected void testEnclosures(final List<SyndEnclosure> encs, final String prefix) throws Exception {
    final Set<String> s1 = new HashSet<String>();
    final Set<String> s2 = new HashSet<String>();
    for (int i = 0; i < encs.size(); i++) {
        final SyndEnclosure enc = encs.get(i);
        s1.add(enc.getUrl() + " " + enc.getType() + " " + enc.getLength());
        s2.add(getPrefix() + "." + prefix + ".enclousure[" + i + "]^url" + " " + getPrefix() + "." + prefix + ".enclousure[" + i + "]^type" + " " + "100");
    }
    assertTrue(s1.equals(s2));
}
 
Example #10
Source File: TestSyndFeedRSS092Alt.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected void testEnclosures(final List<SyndEnclosure> encs, final String prefix) throws Exception {
    final Set<String> s1 = new HashSet<String>();
    final Set<String> s2 = new HashSet<String>();
    for (int i = 0; i < encs.size(); i++) {
        final SyndEnclosure enc = encs.get(i);
        s1.add(enc.getUrl() + " " + enc.getType() + " " + enc.getLength());
        s2.add(getPrefix() + "." + prefix + ".enclousure[" + i + "]^url" + " " + getPrefix() + "." + prefix + ".enclousure[" + i + "]^type" + " " + "0");
    }
    assertTrue(s1.equals(s2));
}
 
Example #11
Source File: FeedParser.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: FeedParser.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * 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;
}