Search in sources :

Example 1 with SyndPersonImpl

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;
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) NotificationException(org.xwiki.notifications.NotificationException) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) NotificationException(org.xwiki.notifications.NotificationException) Template(org.xwiki.template.Template) SyndPerson(com.rometools.rome.feed.synd.SyndPerson) SyndPersonImpl(com.rometools.rome.feed.synd.SyndPersonImpl) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with SyndPersonImpl

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;
}
Also used : SyndPerson(com.rometools.rome.feed.synd.SyndPerson) SyndPersonImpl(com.rometools.rome.feed.synd.SyndPersonImpl) ArrayList(java.util.ArrayList) Person(org.opencastproject.feed.api.Person) SyndPerson(com.rometools.rome.feed.synd.SyndPerson)

Aggregations

SyndPerson (com.rometools.rome.feed.synd.SyndPerson)2 SyndPersonImpl (com.rometools.rome.feed.synd.SyndPersonImpl)2 ArrayList (java.util.ArrayList)2 SyndContent (com.rometools.rome.feed.synd.SyndContent)1 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 Person (org.opencastproject.feed.api.Person)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 NotificationException (org.xwiki.notifications.NotificationException)1 XDOM (org.xwiki.rendering.block.XDOM)1 DefaultWikiPrinter (org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)1 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)1 Template (org.xwiki.template.Template)1