Search in sources :

Example 1 with SyndPerson

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;
}
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 SyndPerson

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

Example 3 with SyndPerson

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;
}
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)

Example 4 with SyndPerson

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);
    }
}
Also used : SyndPerson(com.rometools.rome.feed.synd.SyndPerson) SyndContent(com.rometools.rome.feed.synd.SyndContent) Date(java.util.Date)

Aggregations

SyndPerson (com.rometools.rome.feed.synd.SyndPerson)4 ArrayList (java.util.ArrayList)3 SyndContent (com.rometools.rome.feed.synd.SyndContent)2 SyndPersonImpl (com.rometools.rome.feed.synd.SyndPersonImpl)2 Person (org.opencastproject.feed.api.Person)2 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 Date (java.util.Date)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