use of com.rometools.rome.feed.synd.SyndEnclosure in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcherTest method convertEnclosures_emptyList.
@Test
public void convertEnclosures_emptyList() {
List<SyndEnclosure> enclosures = new ArrayList<>();
Enclosure enclosure = sut.convertEnclosures(enclosures);
assertThat(enclosure).isNull();
}
use of com.rometools.rome.feed.synd.SyndEnclosure in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcherTest method convertEnclosures_Url_null.
@Test
public void convertEnclosures_Url_null() {
when(syndEnclosureMock.getUrl()).thenReturn(null);
List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
Enclosure enclosure = sut.convertEnclosures(enclosures);
assertThat(enclosure).isNull();
}
use of com.rometools.rome.feed.synd.SyndEnclosure in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcherTest method convertEnclosures.
@Test
public void convertEnclosures() {
Long length = 1l;
when(syndEnclosureMock.getLength()).thenReturn(length);
String type = "type";
when(syndEnclosureMock.getType()).thenReturn(type);
String url = "url";
when(syndEnclosureMock.getUrl()).thenReturn(url);
List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
Enclosure enclosure = sut.convertEnclosures(enclosures);
assertThat(enclosure.getExternalUrl()).isEqualTo(url);
assertThat(enclosure.getLength()).isEqualTo(length);
assertThat(enclosure.getType()).isEqualTo(type);
}
use of com.rometools.rome.feed.synd.SyndEnclosure in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method convertEntry.
/**
* Converts a <code>SyndEntry</code> into an <code>Item</code>
*
* @param entry
* @return
*/
protected Item convertEntry(Feed feed, SyndEntry entry) {
Item item = new ItemImpl(feed);
item.setAuthor(entry.getAuthor());
item.setExternalLink(entry.getLink());
item.setGuid(entry.getUri());
item.setLastModified(entry.getUpdatedDate());
item.setPublishDate(entry.getPublishedDate());
item.setTitle(entry.getTitle());
if (entry.getDescription() != null) {
item.setDescription(entry.getDescription().getValue());
}
List<SyndContent> contents = entry.getContents();
item.setContent(joinContents(contents));
List<SyndEnclosure> enclosures = entry.getEnclosures();
item.setEnclosure(convertEnclosures(enclosures));
return item;
}
use of com.rometools.rome.feed.synd.SyndEnclosure in project rssriver by dadoonet.
the class RssToJson method toJson.
public static XContentBuilder toJson(SyndEntry message, String riverName, String feedname, boolean raw) throws IOException {
XContentBuilder out = jsonBuilder().startObject().field(Rss.FEEDNAME, feedname).field(Rss.TITLE, message.getTitle()).field(Rss.AUTHOR, message.getAuthor()).field(Rss.DESCRIPTION, message.getDescription() != null ? message.getDescription().getValue() : null).field(Rss.LINK, message.getLink()).field(Rss.PUBLISHED_DATE, message.getPublishedDate()).field(Rss.SOURCE, message.getSource());
if (raw) {
if (message.getContents() != null) {
out.startObject(Rss.RAW);
for (Object o : message.getContents()) {
if (o instanceof SyndContentImpl) {
SyndContentImpl content = (SyndContentImpl) o;
out.field(content.getType(), content.getValue());
}
}
out.endObject();
}
}
GeoRSSModule geoRSSModule = GeoRSSUtils.getGeoRSS(message);
if (geoRSSModule != null) {
final Position position = geoRSSModule.getPosition();
if (position != null) {
out.startObject(Rss.LOCATION);
out.field(Rss.Location.LAT, position.getLatitude());
out.field(Rss.Location.LON, position.getLongitude());
out.endObject();
}
}
if (message.getCategories() != null && message.getCategories().size() > 0) {
out.startArray(Rss.CATEGORIES);
for (Object oCategory : message.getCategories()) {
if (oCategory instanceof SyndCategory) {
SyndCategory category = (SyndCategory) oCategory;
out.value(category.getName());
}
}
out.endArray();
}
if (message.getEnclosures() != null && message.getEnclosures().size() > 0) {
out.startArray(Rss.ENCLOSURES);
for (Object oEnclosure : message.getEnclosures()) {
if (oEnclosure instanceof SyndEnclosure) {
out.startObject();
SyndEnclosure enclosure = (SyndEnclosure) oEnclosure;
out.field(Rss.Enclosures.URL, enclosure.getUrl());
out.field(Rss.Enclosures.TYPE, enclosure.getType());
out.field(Rss.Enclosures.LENGTH, enclosure.getLength());
out.endObject();
}
}
out.endArray();
}
MediaEntryModule mediaEntryModule = (MediaEntryModule) message.getModule(MediaEntryModule.URI);
if (mediaEntryModule != null) {
out.startArray(Rss.MEDIAS);
for (MediaContent mediaContent : mediaEntryModule.getMediaContents()) {
out.startObject();
addFieldIfNotNull(out, Rss.Medias.TYPE, mediaContent.getType());
if (mediaContent.getReference() != null) {
URI url = null;
if (mediaContent.getReference() instanceof PlayerReference) {
url = ((PlayerReference) mediaContent.getReference()).getUrl();
}
if (mediaContent.getReference() instanceof UrlReference) {
url = ((UrlReference) mediaContent.getReference()).getUrl();
}
if (url != null) {
addFieldIfNotNull(out, Rss.Medias.REFERENCE, url.toString());
}
}
addFieldIfNotNull(out, Rss.Medias.LANGUAGE, mediaContent.getLanguage());
addFieldIfNotNull(out, Rss.Medias.TITLE, mediaContent.getMetadata().getTitle());
addFieldIfNotNull(out, Rss.Medias.DESCRIPTION, mediaContent.getMetadata().getDescription());
addFieldIfNotNull(out, Rss.Medias.DURATION, mediaContent.getDuration());
addFieldIfNotNull(out, Rss.Medias.WIDTH, mediaContent.getWidth());
addFieldIfNotNull(out, Rss.Medias.HEIGHT, mediaContent.getHeight());
out.endObject();
}
out.endArray();
}
if (riverName != null) {
out.field("river", riverName);
}
return out.endObject();
}
Aggregations