Search in sources :

Example 1 with FeedViewInterceptor

use of org.shredzone.cilla.view.interceptor.FeedViewInterceptor in project cilla by shred.

the class FeedView method createEntry.

/**
 * Creates a {@link SyndEntry} from the given {@link Page}.
 *
 * @param page
 *            {@link Page} to create a {@link SyndEntry} for
 * @param uriPrefix
 *            URI prefix for this website
 * @return {@link SyndEntry} that was created
 */
private SyndEntry createEntry(Page page, String uriPrefix) {
    String pageUrl = linkService.linkTo().page(page).absolute().toString();
    String body = textFormatter.format(page.getTeaser(), () -> linkService.linkTo().page(page)).toString();
    for (FeedViewInterceptor it : interceptors) {
        body = it.filterDescription(page, body);
    }
    SyndEntry entry = new SyndEntryImpl();
    entry.setTitle(page.getTitle());
    entry.setLink(pageUrl);
    entry.setUri(buildTaxonomyUri(uriPrefix, "page", page.getId()));
    entry.setPublishedDate(page.getPublication());
    entry.setUpdatedDate(page.getModification());
    // Add a donation link if set
    if (page.isDonatable() && page.getDonateUrl() != null) {
        SyndLink link = new SyndLinkImpl();
        link.setRel("payment");
        link.setHref(page.getDonateUrl());
        entry.getLinks().add(link);
    }
    SyndContent description = new SyndContentImpl();
    description.setType("text/html");
    description.setValue(body);
    entry.setDescription(description);
    entry.getCategories().addAll(page.getCategories().stream().map(cat -> {
        SyndCategory category = new SyndCategoryImpl();
        category.setName(cat.getName());
        category.setTaxonomyUri(buildTaxonomyUri(uriPrefix, "category", cat.getId()));
        return category;
    }).collect(toList()));
    entry.getCategories().addAll(page.getTags().stream().map(tag -> {
        SyndCategory category = new SyndCategoryImpl();
        category.setName(tag.getName());
        category.setTaxonomyUri(buildTaxonomyUri(uriPrefix, "tag", tag.getName()));
        return category;
    }).collect(toList()));
    List<SyndPerson> authorList = new ArrayList<>();
    User creator = page.getCreator();
    SyndPerson author = new SyndPersonImpl();
    author.setName(creator.getName());
    author.setUri(buildTaxonomyUri(uriPrefix, "author", creator.getId()));
    authorList.add(author);
    entry.setAuthors(authorList);
    interceptors.forEach(it -> it.postProcessEntry(page, entry));
    return entry;
}
Also used : SyndCategory(com.rometools.rome.feed.synd.SyndCategory) User(org.shredzone.cilla.core.model.User) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndLinkImpl(com.rometools.rome.feed.synd.SyndLinkImpl) ArrayList(java.util.ArrayList) FeedViewInterceptor(org.shredzone.cilla.view.interceptor.FeedViewInterceptor) SyndPerson(com.rometools.rome.feed.synd.SyndPerson) SyndPersonImpl(com.rometools.rome.feed.synd.SyndPersonImpl) SyndCategoryImpl(com.rometools.rome.feed.synd.SyndCategoryImpl) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndLink(com.rometools.rome.feed.synd.SyndLink)

Aggregations

SyndCategory (com.rometools.rome.feed.synd.SyndCategory)1 SyndCategoryImpl (com.rometools.rome.feed.synd.SyndCategoryImpl)1 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 SyndLink (com.rometools.rome.feed.synd.SyndLink)1 SyndLinkImpl (com.rometools.rome.feed.synd.SyndLinkImpl)1 SyndPerson (com.rometools.rome.feed.synd.SyndPerson)1 SyndPersonImpl (com.rometools.rome.feed.synd.SyndPersonImpl)1 ArrayList (java.util.ArrayList)1 User (org.shredzone.cilla.core.model.User)1 FeedViewInterceptor (org.shredzone.cilla.view.interceptor.FeedViewInterceptor)1