use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.
the class FeedImplTest method setterGetterTest.
@Test
public void setterGetterTest() {
instance.setTitle("text");
logger.info(instance.getTitle().getValue());
Assert.assertEquals(instance.getTitle().getValue(), "text");
instance.setLink("http://localhost:8080/feeds/rss/2.0/test");
Assert.assertEquals(instance.getLink(), "http://localhost:8080/feeds/rss/2.0/test");
instance.setCopyright("text");
Assert.assertEquals(instance.getCopyright(), "text");
List<Person> person = new ArrayList<Person>();
instance.setAuthors(person);
Assert.assertEquals(instance.getAuthors(), person);
instance.setContributors(person);
Assert.assertEquals(instance.getContributors(), person);
instance.setUri("http://testuri/");
Assert.assertEquals(instance.getUri(), "http://testuri/");
List<Category> category = new ArrayList<Category>();
instance.setCategories(category);
Assert.assertEquals(instance.getCategories(), category);
instance.setDescription("description");
Assert.assertEquals(instance.getDescription().getValue(), "description");
Content content = new ContentImpl("desciption");
instance.setDescription(content);
Assert.assertEquals(instance.getDescription(), content);
instance.setEncoding("encode");
Assert.assertEquals(instance.getEncoding(), "encode");
List<FeedEntry> feed = new ArrayList<FeedEntry>();
instance.setEntries(feed);
Assert.assertEquals(instance.getEntries(), feed);
Image image = new ImageImpl("http://picture/");
instance.setImage(image);
Assert.assertEquals(instance.getImage(), image);
instance.setLanguage("English");
Assert.assertEquals(instance.getLanguage(), "English");
List<Link> link = new ArrayList<Link>();
instance.setLinks(link);
Assert.assertEquals(instance.getLinks(), link);
List<FeedExtension> feedExtension = new ArrayList<FeedExtension>();
instance.setModules(feedExtension);
Assert.assertEquals(instance.getModules(), feedExtension);
Date date = new Date(21091981);
instance.setPublishedDate(date);
Assert.assertEquals(instance.getPublishedDate(), date);
instance.setUpdatedDate(date);
Assert.assertEquals(instance.getUpdatedDate(), date);
instance.setTitle(content);
Assert.assertEquals(instance.getTitle(), content);
}
use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.
the class FeedImplTest method testFeedImpl.
@Test
public void testFeedImpl() {
try {
Content title = new PlainTextContent("Test Feed");
Content description = new HtmlContent("generated by <b>unit test</b>", Mode.Escaped);
FeedImpl feed = new FeedImpl(Type.RSS, "http://localhost:8080/feeds/rss/2.0/test", title, description, "http://localhost:8080/feeds/rss/2.0/test");
feed.addAuthor(new PersonImpl("Test User", "testuser@example.com", "http://www.example.com/testuser"));
feed.addContributor(new PersonImpl("test university"));
FeedEntry entry = new FeedEntryImpl(feed, "test entry", new LinkImpl("http://localhost:8080/feeds/rss/2.0/test/testentry"), "http://localhost:8080/feeds/rss/2.0/test/testentry");
entry.addEnclosure(new EnclosureImpl("http://www.example.com/video.mp4", "video/mp4", "presenter/delivery", 12));
feed.addEntry(entry);
ITunesFeedExtension itunesmodule = new ITunesFeedExtension();
itunesmodule.addKeyword("test");
List<String> categories = new LinkedList<String>();
categories.add("Higher Education");
itunesmodule.setCategories(categories);
feed.addModule(itunesmodule);
DublinCoreExtension dcModule = new DublinCoreExtension();
feed.addModule(dcModule);
Assert.assertEquals(feed.getAuthors().get(0).getName(), "Test User");
Assert.assertEquals(feed.getAuthors().get(0).getEmail(), "testuser@example.com");
Assert.assertEquals(feed.getContributors().get(0).getName(), "test university");
Assert.assertEquals(feed.getTitle().getValue(), "Test Feed");
Assert.assertEquals(feed.getDescription().getType(), "text/html");
Assert.assertEquals(feed.getType(), Type.RSS);
Assert.assertEquals(feed.getLink(), "http://localhost:8080/feeds/rss/2.0/test");
} catch (Exception e) {
Assert.fail();
}
// Todo test Services... but this cannot be done outside OSGI and the servlet Container, so this has to be done by
// an integration test.
}
use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.
the class RomeRssFeed method init.
/**
* Converts the replay feed to a rome feed, that can then be written to the reponse.
*
* @param originalFeed
* the original feed
* @param feedInfo
* the feed info
*/
private void init(Feed originalFeed, FeedInfo feedInfo) {
if (originalFeed == null)
throw new IllegalArgumentException("Feed is null");
// Create SyndFeed
setEncoding(originalFeed.getEncoding());
setFeedType(feedInfo.toROMEVersion());
// Convert fields
setModules(toRomeModules(originalFeed.getModules()));
setAuthors(toRomePersons(originalFeed.getAuthors()));
setCategories(toRomeCategories(originalFeed.getCategories()));
setContributors(toRomePersons(originalFeed.getContributors()));
setDescriptionEx(toRomeContent(originalFeed.getDescription()));
setImage(toRomeImage(originalFeed.getImage()));
setLanguage(originalFeed.getLanguage());
setLinks(toRomeLinks(originalFeed.getLinks()));
setPublishedDate(originalFeed.getPublishedDate());
setTitleEx(toRomeContent(originalFeed.getTitle()));
setCopyright(originalFeed.getCopyright());
setUri(originalFeed.getUri());
setLink(originalFeed.getLink());
// Add SyndFeedEntries
if (originalFeed.getEntries() != null) {
List<SyndEntry> romeEntries = new ArrayList<SyndEntry>();
for (FeedEntry entry : originalFeed.getEntries()) {
SyndEntryImpl e = new SyndEntryImpl();
e.setModules(toRomeModules(entry.getModules()));
e.setAuthors(toRomePersons(entry.getAuthors()));
e.setCategories(toRomeCategories(entry.getCategories()));
e.setContents(toRomeContents(entry.getContents()));
e.setContributors(toRomePersons(entry.getContributors()));
e.setDescription(toRomeContent(entry.getDescription()));
e.setEnclosures(toRomeEnclosures(entry.getEnclosures()));
e.setPublishedDate(entry.getPublishedDate());
e.setTitleEx(toRomeContent(entry.getTitle()));
e.setUpdatedDate(entry.getUpdatedDate());
e.setUri(entry.getUri());
List<SyndLink> links = toRomeLinks(entry.getLinks());
e.setLinks(links);
// todo this strategy seems to work but is unproven
if (links.size() > 0)
e.setLink(links.get(0).getHref());
romeEntries.add(e);
}
setEntries(romeEntries);
}
}
use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.
the class AbstractFeedGenerator method addEpisode.
/**
* Adds episode information to the feed.
*
* @param feed
* the feed
* @param query
* the query that results in the feed
* @param resultItem
* the episodes item
* @param organization
* the organization
* @return the feed
*/
protected Feed addEpisode(Feed feed, String[] query, SearchResultItem resultItem, Organization organization) {
String link = getLinkForEntry(feed, resultItem, organization);
String title = resultItem.getDcTitle();
// Get the media enclosures
List<MediaPackageElement> enclosures = getEnclosures(feed, resultItem);
if (enclosures.size() == 0) {
logger.debug("No media formats found for feed entry: {}", title);
return feed;
}
String entryUri = null;
// For RSS feeds, create multiple entries (one per enclosure). For Atom, add all enclosures to the same item
switch(feed.getType()) {
case RSS:
entryUri = resultItem.getId();
for (MediaPackageElement e : enclosures) {
List<MediaPackageElement> enclosure = new ArrayList<MediaPackageElement>(1);
enclosure.add(e);
FeedEntry entry = createEntry(feed, title, link, entryUri);
entry = populateFeedEntry(entry, resultItem, enclosure);
entry.setUri(entry.getUri() + "/" + e.getIdentifier());
feed.addEntry(entry);
}
break;
case Atom:
entryUri = generateEntryUri(resultItem.getId());
FeedEntry entry = createEntry(feed, title, link, entryUri);
entry = populateFeedEntry(entry, resultItem, enclosures);
if (getLinkSelf(organization) != null) {
LinkImpl self = new LinkImpl(getSelfLinkForEntry(feed, resultItem, organization));
self.setRel("self");
entry.addLink(self);
}
feed.addEntry(entry);
if (feed.getUpdatedDate() == null)
feed.setUpdatedDate(entry.getUpdatedDate());
else if (entry.getUpdatedDate().before(feed.getUpdatedDate()))
feed.setUpdatedDate(entry.getUpdatedDate());
break;
default:
throw new IllegalStateException("Unsupported feed type " + feed.getType());
}
return feed;
}
use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.
the class RomeAtomFeed method init.
/**
* Converts the replay feed to a rome feed, that can then be written to the reponse.
*
* @param originalFeed
* the original feed
* @param feedInfo
* the feed info
*/
private void init(Feed originalFeed, FeedInfo feedInfo) {
if (originalFeed == null)
throw new IllegalArgumentException("Feed is null");
// Create SyndFeed
setEncoding(originalFeed.getEncoding());
setFeedType(feedInfo.toROMEVersion());
// Convert fields
setModules(toRomeModules(originalFeed.getModules()));
setAuthors(toRomeAtomPersons(originalFeed.getAuthors()));
setCategories(toRomeAtomCategories(originalFeed.getCategories()));
setContributors(toRomeAtomPersons(originalFeed.getContributors()));
setInfo(toRomeAtomContent(originalFeed.getDescription()));
setLanguage(originalFeed.getLanguage());
setAlternateLinks(toRomeAtomLinks(originalFeed.getLinks()));
setUpdated(originalFeed.getUpdatedDate());
setTitleEx(toRomeAtomContent(originalFeed.getTitle()));
setId(originalFeed.getUri());
setCopyright(originalFeed.getCopyright());
List<Link> otherLinks = new ArrayList<Link>();
otherLinks.add(new LinkImpl(originalFeed.getLink()));
setOtherLinks(toRomeAtomLinks(otherLinks));
// Add SyndFeedEntries
if (originalFeed.getEntries() != null) {
List<Entry> romeEntries = new ArrayList<Entry>();
for (FeedEntry entry : originalFeed.getEntries()) {
Entry e = new Entry();
e.setModules(toRomeModules(entry.getModules()));
e.setAuthors(toRomeAtomPersons(entry.getAuthors()));
e.setCategories(toRomeAtomCategories(entry.getCategories()));
e.setContents(toRomeAtomContents(entry.getContents()));
e.setContributors(toRomeAtomPersons(entry.getContributors()));
e.setSummary(toRomeAtomContent(entry.getDescription()));
e.setPublished(entry.getPublishedDate());
e.setTitleEx(toRomeAtomContent(entry.getTitle()));
e.setUpdated(entry.getUpdatedDate());
e.setId(entry.getUri());
List<com.rometools.rome.feed.atom.Link> links = toRomeAtomLinks(entry.getLinks());
links.addAll(toRomeAtomEnclosures(entry.getEnclosures()));
e.setOtherLinks(links);
// todo this strategy seems to work but is unproven
// if (links.size() > 0)
// e.setLink(links.get(0).getHref());
romeEntries.add(e);
}
setEntries(romeEntries);
}
}
Aggregations