use of com.rometools.rome.feed.synd.SyndPerson in project xwiki-platform by xwiki.
the class DefaultNotificationRSSRenderer method renderNotification.
@Override
public SyndEntry renderNotification(CompositeEvent eventNotification) throws NotificationException {
SyndEntry entry = new SyndEntryImpl();
SyndContent entryDescription = new SyndContentImpl();
// The users contained in the CompositeEvent are already stored in a Set, they are therefore necessarily unique
List<SyndPerson> eventAuthors = new ArrayList<SyndPerson>();
// Convert every author of the CompositeEvent to a SyndPerson and add it to the new entry
for (DocumentReference author : eventNotification.getUsers()) {
SyndPerson person = new SyndPersonImpl();
person.setName(author.getName());
eventAuthors.add(person);
}
entry.setAuthors(eventAuthors);
// Define the GUID of the event
entry.setUri(String.join("-", eventNotification.getEventIds()));
// Set the entry title
entry.setTitle(this.contextualLocalizationManager.getTranslationPlain(eventNotification.getEvents().get(0).getTitle(), eventNotification.getEvents().get(0).getDocumentTitle()));
// Render the description (the main part) of the feed entry
try {
this.scriptContextManager.getCurrentScriptContext().setAttribute(COMPOSITE_EVENT_BUILDING_NAME, eventNotification, ScriptContext.ENGINE_SCOPE);
// Try to get a template associated with the composite event
Template template = this.templateManager.getTemplate(String.format("notification/rss/%s.vm", eventNotification.getType().replaceAll("\\/", ".")));
// If no template is found, fallback on the default one
if (template == null) {
template = this.templateManager.getTemplate("notification/rss/default.vm");
}
XDOM descriptionXDOM = this.templateManager.execute(template);
WikiPrinter printer = new DefaultWikiPrinter();
blockRenderer.render(descriptionXDOM, printer);
// Add the description to the entry
entryDescription.setType("text/html");
entryDescription.setValue(printer.toString());
entry.setDescription(entryDescription);
} catch (Exception e) {
throw new NotificationException(String.format("Unable to render the description of the event [%s].", eventNotification), e);
} finally {
this.scriptContextManager.getCurrentScriptContext().removeAttribute(COMPOSITE_EVENT_BUILDING_NAME, ScriptContext.ENGINE_SCOPE);
}
// Dates are sorted in descending order in a CompositeEvent, the first date is then the most recent one
entry.setUpdatedDate(eventNotification.getDates().get(0));
return entry;
}
use of com.rometools.rome.feed.synd.SyndPerson in project opencast by opencast.
the class RomeAtomFeed method toRomeAtomPersons.
/**
* Converts a list of persons to a <code>ROME</code> person list.
*
* @param persons
* original persons
* @return <code>ROME</code> person list
*/
private List<SyndPerson> toRomeAtomPersons(List<Person> persons) {
if (persons == null)
return Collections.emptyList();
List<SyndPerson> romePersons = new ArrayList<SyndPerson>(persons.size());
for (Person person : persons) {
com.rometools.rome.feed.atom.Person romePerson = new com.rometools.rome.feed.atom.Person();
romePerson.setEmail(person.getEmail());
romePerson.setName(person.getName());
romePerson.setUri(person.getUri());
romePersons.add(romePerson);
}
return romePersons;
}
use of com.rometools.rome.feed.synd.SyndPerson in project opencast by opencast.
the class RomeRssFeed method toRomePersons.
/**
* Converts a list of persons to a <code>ROME</code> person list.
*
* @param persons
* original persons
* @return <code>ROME</code> person list
*/
private List<SyndPerson> toRomePersons(List<Person> persons) {
if (persons == null)
return Collections.emptyList();
List<SyndPerson> romePersons = new ArrayList<SyndPerson>(persons.size());
for (Person person : persons) {
SyndPersonImpl romePerson = new SyndPersonImpl();
romePerson.setEmail(person.getEmail());
romePerson.setName(person.getName());
romePerson.setUri(person.getUri());
romePersons.add(romePerson);
}
return romePersons;
}
use of com.rometools.rome.feed.synd.SyndPerson in project nutch by apache.
the class FeedParser method addFields.
private void addFields(Metadata parseMeta, Metadata contentMeta, SyndFeed feed, SyndEntry entry) {
List<?> authors = entry.getAuthors(), categories = entry.getCategories();
Date published = entry.getPublishedDate(), updated = entry.getUpdatedDate();
String contentType = null;
if (authors != null) {
for (Object o : authors) {
SyndPerson author = (SyndPerson) o;
String authorName = author.getName();
if (checkString(authorName)) {
parseMeta.add(Feed.FEED_AUTHOR, authorName);
}
}
} else {
// getAuthors may return null if feed is non-atom
// if so, call getAuthor to get Dublin Core module creator.
String authorName = entry.getAuthor();
if (checkString(authorName)) {
parseMeta.set(Feed.FEED_AUTHOR, authorName);
}
}
for (Object i : categories) {
parseMeta.add(Feed.FEED_TAGS, ((SyndCategory) i).getName());
}
if (published != null) {
parseMeta.set(Feed.FEED_PUBLISHED, Long.toString(published.getTime()));
}
if (updated != null) {
parseMeta.set(Feed.FEED_UPDATED, Long.toString(updated.getTime()));
}
SyndContent description = entry.getDescription();
if (description != null) {
contentType = description.getType();
} else {
// TODO: What to do if contents.size() > 1?
List<?> contents = entry.getContents();
if (contents.size() > 0) {
contentType = ((SyndContent) contents.get(0)).getType();
}
}
if (checkString(contentType)) {
// ROME may return content-type as html
if (contentType.equals("html"))
contentType = "text/html";
else if (contentType.equals("xhtml"))
contentType = "text/xhtml";
contentMeta.set(Response.CONTENT_TYPE, contentType + "; " + CHARSET_UTF8);
} else {
contentMeta.set(Response.CONTENT_TYPE, TEXT_PLAIN_CONTENT_TYPE);
}
}
Aggregations