Search in sources :

Example 1 with RequestContext

use of org.moera.node.global.RequestContext in project moera-node by MoeraOrg.

the class TitleBuilder method build.

public CharSequence build(String title) {
    StringBuilder buf = new StringBuilder();
    if (!ObjectUtils.isEmpty(title)) {
        buf.append(title);
        buf.append(' ');
        String name = "";
        try {
            RequestContext rcp = requestContext.getPublic();
            name = rcp.fullName() != null ? rcp.fullName() : rcp.nodeName();
        } catch (Exception e) {
        }
        if (!ObjectUtils.isEmpty(name)) {
            buf.append("@ ");
            buf.append(NodeName.shorten(name));
            buf.append(' ');
        }
    }
    if (buf.length() > 0) {
        buf.append("| ");
    }
    buf.append("Moera");
    return buf;
}
Also used : RequestContext(org.moera.node.global.RequestContext)

Example 2 with RequestContext

use of org.moera.node.global.RequestContext in project moera-node by MoeraOrg.

the class RssController method rss.

@GetMapping("/rss")
@Transactional
@ResponseBody
public SyndFeed rss() {
    RequestContext rcp = requestContext.getPublic();
    PublicPage publicPage = publicPageRepository.findContaining(rcp.nodeId(), Long.MAX_VALUE);
    List<Story> stories = Collections.emptyList();
    if (publicPage != null) {
        stories = storyRepository.findInRange(rcp.nodeId(), Feed.TIMELINE, publicPage.getAfterMoment(), publicPage.getBeforeMoment()).stream().filter(t -> t.getEntry().isMessage()).sorted(Collections.reverseOrder(Comparator.comparingLong(Story::getMoment))).collect(Collectors.toList());
    }
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    String name = rcp.fullName() != null ? rcp.fullName() : rcp.nodeName();
    String title = !ObjectUtils.isEmpty(name) ? name + " - Moera" : "Moera";
    feed.setTitle(title);
    feed.setLink(rcp.getSiteUrl() + "/");
    if (rcp.avatarId() != null) {
        SyndImage image = new SyndImageImpl();
        image.setTitle(title);
        image.setUrl(rcp.getSiteUrl() + "/moera/media/" + new AvatarImage(rcp.getAvatar()).getPath());
        image.setLink(rcp.getSiteUrl() + "/");
        feed.setImage(image);
    }
    feed.setDescription(title);
    feed.setLanguage("en-us");
    feed.setPublishedDate(!stories.isEmpty() ? stories.get(0).getCreatedAt() : Util.now());
    feed.setGenerator("moera-node");
    feed.setWebMaster(buildWebmaster());
    feed.setEntries(stories.stream().map(this::buildEntry).collect(Collectors.toList()));
    return feed;
}
Also used : SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) Util(org.moera.node.util.Util) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) Inject(javax.inject.Inject) Story(org.moera.node.data.Story) StoryRepository(org.moera.node.data.StoryRepository) SyndImage(com.rometools.rome.feed.synd.SyndImage) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) GetMapping(org.springframework.web.bind.annotation.GetMapping) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) Transactional(javax.transaction.Transactional) Feed(org.moera.node.data.Feed) EntryRevision(org.moera.node.data.EntryRevision) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) ObjectUtils(org.springframework.util.ObjectUtils) PublicPageRepository(org.moera.node.data.PublicPageRepository) SyndContent(com.rometools.rome.feed.synd.SyndContent) Entry(org.moera.node.data.Entry) RequestContext(org.moera.node.global.RequestContext) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) AvatarImage(org.moera.node.model.AvatarImage) List(java.util.List) PublicPage(org.moera.node.data.PublicPage) Comparator(java.util.Comparator) Collections(java.util.Collections) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) SyndImage(com.rometools.rome.feed.synd.SyndImage) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) RequestContext(org.moera.node.global.RequestContext) PublicPage(org.moera.node.data.PublicPage) AvatarImage(org.moera.node.model.AvatarImage) Story(org.moera.node.data.Story) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(javax.transaction.Transactional) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RequestContext (org.moera.node.global.RequestContext)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 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)1 SyndImage (com.rometools.rome.feed.synd.SyndImage)1 SyndImageImpl (com.rometools.rome.feed.synd.SyndImageImpl)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Transactional (javax.transaction.Transactional)1 Entry (org.moera.node.data.Entry)1 EntryRevision (org.moera.node.data.EntryRevision)1 Feed (org.moera.node.data.Feed)1 PublicPage (org.moera.node.data.PublicPage)1 PublicPageRepository (org.moera.node.data.PublicPageRepository)1