use of com.rometools.rome.feed.synd.SyndPersonImpl 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.SyndPersonImpl 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;
}
Aggregations