Search in sources :

Example 26 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project coffeenet-frontpage-plugin-rss by coffeenet.

the class FeedParserTest method parseBlogRss.

@Test
public void parseBlogRss() throws FeedException, IOException {
    SyndContentImpl description = new SyndContentImpl();
    description.setValue("description");
    SyndEntryImpl syndEntry = new SyndEntryImpl();
    syndEntry.setDescription(description);
    syndEntry.setLink("link");
    syndEntry.setAuthor("author");
    syndEntry.setTitle("title");
    syndEntry.setPublishedDate(getDate());
    SyndImage syndImage = new SyndImageImpl();
    syndImage.setUrl("some-url");
    syndImage.setLink("some-link");
    SyndFeed result = new SyndFeedImpl();
    result.setEntries(singletonList(syndEntry));
    result.setImage(syndImage);
    when(feedFactory.build(any(URL.class))).thenReturn(result);
    FeedDto feedDto = sut.parse("http://blog/feed/", 10, 150);
    final List<FeedEntryDto> blogEntries = feedDto.getEntries();
    assertThat(blogEntries, hasSize(1));
    assertThat(blogEntries.get(0).getDescription(), is("description"));
    assertThat(blogEntries.get(0).getLink(), is("link"));
    assertThat(blogEntries.get(0).getUserSeenPublishedDate(), is("3. December 2014"));
    assertThat(blogEntries.get(0).getGregorianPublishedDate(), is("2014-12-03 10:15"));
    assertThat(blogEntries.get(0).getAuthor(), is("author"));
    assertThat(blogEntries.get(0).getTitle(), is("title"));
    final FeedImageDto image = feedDto.getImage();
    assertThat(image.getUrl(), is("some-url"));
    assertThat(image.getLink(), is("some-link"));
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndImage(com.rometools.rome.feed.synd.SyndImage) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) URL(java.net.URL) Test(org.junit.Test)

Example 27 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project quantizr by Clay-Ferguson.

the class RSSFeedService method getRssFeed.

public void getRssFeed(MongoSession ms, String nodeId, Writer writer) {
    SubNode node = read.getNode(ms, nodeId);
    SyndFeed feed = new SyndFeedImpl();
    feed.setEncoding("UTF-8");
    feed.setFeedType("rss_2.0");
    NodeMetaInfo metaInfo = snUtil.getNodeMetaInfo(node);
    feed.setTitle(ok(metaInfo.getTitle()) ? metaInfo.getTitle() : "");
    feed.setLink("");
    feed.setDescription(sanitizeHtml(ok(metaInfo.getDescription()) ? metaInfo.getDescription() : ""));
    List<SyndEntry> entries = new LinkedList<>();
    feed.setEntries(entries);
    if (AclService.isPublic(ms, node)) {
        Iterable<SubNode> iter = read.getChildren(ms, node, Sort.by(Sort.Direction.ASC, SubNode.ORDINAL), null, 0);
        List<SubNode> children = read.iterateToList(iter);
        if (ok(children)) {
            for (SubNode n : children) {
                if (!AclService.isPublic(ms, n))
                    continue;
                metaInfo = snUtil.getNodeMetaInfo(n);
                // handles attachments.
                if (no(metaInfo.getAttachmentUrl())) {
                    metaInfo.setAttachmentUrl(metaInfo.getUrl());
                }
                SyndEntry entry = new SyndEntryImpl();
                entry.setTitle(ok(metaInfo.getTitle()) ? metaInfo.getTitle() : "ID: " + n.getIdStr());
                entry.setLink(ok(metaInfo.getAttachmentUrl()) ? metaInfo.getAttachmentUrl() : prop.getProtocolHostAndPort());
                /*
					 * todo-2: need menu item "Set Create Time", and "Set Modify Time", that prompts with the datetime
					 * GUI, so publishers have more control over this in the feed, or else have an rssTimestamp as an
					 * optional property which can be set on any node to override this.
					 * 
					 * UPDATE: Now that we have 'date' property as a generic feature of nodes (calendar icon on edit
					 * dialog) we can use that as our publish time here, and allow that to be the override for the date
					 * on the node.
					 */
                entry.setPublishedDate(n.getCreateTime());
                SyndContent description = new SyndContentImpl();
                /*
					 * todo-2: NOTE: I tried putting some HTML into 'content' as a test and setting the mime type, but
					 * it doesn't render correctly, so I just need to research how to get HTML in RSS descriptions, but
					 * this is low priority for now so I'm not doing it yet.
					 * 
					 * todo-2: NOTE: when org.owasp.html.Sanitizers capability was added, I forgot to revisit this, so I
					 * need to check what I'm doing here and see if we need "HTML" now here instead.
					 */
                description.setType("text/plain");
                description.setType("text/html");
                description.setValue(sanitizeHtml(ok(metaInfo.getDescription()) ? metaInfo.getDescription() : ""));
                entry.setDescription(description);
                entries.add(entry);
            }
        }
    }
    writeFeed(feed, writer);
}
Also used : NodeMetaInfo(quanta.model.NodeMetaInfo) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SubNode(quanta.mongo.model.SubNode) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) LinkedList(java.util.LinkedList)

Example 28 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project activemq by apache.

the class RssMessageRenderer method createEntryContent.

protected SyndContent createEntryContent(QueueBrowser browser, Message message, HttpServletRequest request) throws JMSException {
    SyndContent description = new SyndContentImpl();
    description.setType(entryContentType);
    if (message instanceof TextMessage) {
        String text = ((TextMessage) message).getText();
        description.setValue(text);
    }
    return description;
}
Also used : SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) TextMessage(javax.jms.TextMessage)

Example 29 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project ecms by exoplatform.

the class RssConnector method generateRSS.

/**
 * Generates RSS.
 *
 * @param context The context.
 * @return the string
 */
private String generateRSS(List<Node> nodes, Map<String, String> context) {
    String rssVersion = context.get(RSS_VERSION);
    String feedTitle = context.get(FEED_TITLE);
    String feedDescription = context.get(DESCRIPTION);
    String feedLink = context.get(LINK);
    String detailPage = context.get(DETAIL_PAGE);
    String detailParam = context.get(DETAIL_PARAM);
    String repository = context.get(REPOSITORY);
    String workspace = context.get(WORKSPACE);
    String contentUrl;
    if (!feedLink.endsWith("/")) {
        contentUrl = feedLink + "/" + detailPage + "?" + detailParam + "=/" + repository + "/" + workspace;
    } else {
        contentUrl = feedLink + detailPage + "?" + detailParam + "=/" + repository + "/" + workspace;
    }
    if (feedTitle == null || feedTitle.length() == 0)
        feedTitle = "";
    try {
        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType(rssVersion);
        feed.setTitle(feedTitle.replaceAll("&nbsp;", " "));
        feed.setLink(feedLink);
        feed.setDescription(feedDescription.replaceAll("&nbsp;", " "));
        feed.setEncoding("UTF-8");
        List<SyndEntry> entries = new ArrayList<SyndEntry>();
        Iterator<Node> iter = nodes.iterator();
        while (iter.hasNext()) {
            Node node = iter.next();
            StringBuilder url = new StringBuilder();
            url.append(contentUrl);
            if (node.isNodeType("nt:frozenNode")) {
                String uuid = node.getProperty("jcr:frozenUuid").getString();
                Node originalNode = node.getSession().getNodeByUUID(uuid);
                url.append(originalNode.getPath());
                url.append("&version=");
                url.append(node.getParent().getName());
            } else {
                url.append(node.getPath());
            }
            SyndEntry entry = new SyndEntryImpl();
            if (node.hasProperty(TITLE)) {
                String nTitle = node.getProperty(TITLE).getString();
                // encoding
                nTitle = Text.unescapeIllegalJcrChars(new String(nTitle.getBytes("UTF-8")));
                entry.setTitle(Text.encodeIllegalXMLCharacters(nTitle).replaceAll("&quot;", "\"").replaceAll("&apos;", "\'"));
            } else
                entry.setTitle("");
            entry.setLink(url.toString());
            SyndContent description = new SyndContentImpl();
            description.setType("text/plain");
            if (node.hasProperty(SUMMARY)) {
                String summary = Text.encodeIllegalXMLCharacters(node.getProperty(SUMMARY).getString()).replaceAll("&nbsp;", " ").replaceAll("&amp;quot;", "\"").replaceAll("&apos;", "\'");
                description.setValue(summary);
            } else
                description.setValue("");
            entry.setDescription(description);
            entries.add(entry);
            entry.getEnclosures();
        }
        feed.setEntries(entries);
        SyndFeedOutput output = new SyndFeedOutput();
        return output.outputString(feed);
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Error when perform generateRSS: ", e);
        }
    }
    return null;
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) SyndFeedOutput(com.rometools.rome.io.SyndFeedOutput) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 30 with SyndContentImpl

use of com.rometools.rome.feed.synd.SyndContentImpl in project haikudepotserver by haiku.

the class CreatedPkgVersionSyndEntrySupplier method generate.

@Override
public List<SyndEntry> generate(final FeedSpecification specification) {
    Preconditions.checkNotNull(specification);
    if (specification.getSupplierTypes().contains(FeedSpecification.SupplierType.CREATEDPKGVERSION)) {
        if (null != specification.getPkgNames() && specification.getPkgNames().isEmpty()) {
            return Collections.emptyList();
        }
        ObjectSelect<PkgVersion> objectSelect = ObjectSelect.query(PkgVersion.class).where(PkgVersion.ACTIVE.isTrue()).and(PkgVersion.PKG.dot(Pkg.ACTIVE).isTrue()).and(ExpressionFactory.or(PkgVersion.PKG.dot(Pkg.NAME).endsWith(PkgService.SUFFIX_PKG_DEBUGINFO), PkgVersion.PKG.dot(Pkg.NAME).endsWith(PkgService.SUFFIX_PKG_DEVELOPMENT), PkgVersion.PKG.dot(Pkg.NAME).endsWith(PkgService.SUFFIX_PKG_SOURCE)).notExp()).orderBy(PkgVersion.CREATE_TIMESTAMP.desc()).limit(specification.getLimit());
        if (null != specification.getPkgNames()) {
            objectSelect.and(PkgVersion.PKG.dot(Pkg.NAME).in(specification.getPkgNames()));
        }
        ObjectContext context = serverRuntime.newContext();
        NaturalLanguage naturalLanguage = deriveNaturalLanguage(context, specification);
        List<PkgVersion> pkgVersions = objectSelect.select(context);
        return pkgVersions.stream().map(pv -> {
            SyndEntry entry = new SyndEntryImpl();
            entry.setPublishedDate(pv.getCreateTimestamp());
            entry.setUpdatedDate(pv.getModifyTimestamp());
            entry.setUri(URI_PREFIX + Hashing.sha1().hashUnencodedChars(String.format("%s_::_%s_::_%s", this.getClass().getCanonicalName(), pv.getPkg().getName(), pv.toVersionCoordinates().toString())).toString());
            {
                UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseUrl).pathSegment("#!", "pkg");
                pv.appendPathSegments(builder);
                entry.setLink(builder.build().toUriString());
            }
            ResolvedPkgVersionLocalization resolvedPkgVersionLocalization = pkgLocalizationService.resolvePkgVersionLocalization(context, pv, null, naturalLanguage);
            entry.setTitle(messageSource.getMessage("feed.createdPkgVersion.atom.title", new Object[] { Optional.ofNullable(resolvedPkgVersionLocalization.getTitle()).orElse(pv.getPkg().getName()), pv.toVersionCoordinates().toString() }, new Locale(naturalLanguage.getCode())));
            {
                SyndContent content = new SyndContentImpl();
                content.setType(MediaType.PLAIN_TEXT_UTF_8.type());
                content.setValue(resolvedPkgVersionLocalization.getSummary());
                entry.setDescription(content);
            }
            return entry;
        }).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : PkgService(org.haiku.haikudepotserver.pkg.model.PkgService) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ObjectContext(org.apache.cayenne.ObjectContext) LoggerFactory(org.slf4j.LoggerFactory) Hashing(com.google.common.hash.Hashing) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) StringUtils(org.apache.commons.lang3.StringUtils) FeedSpecification(org.haiku.haikudepotserver.feed.model.FeedSpecification) Value(org.springframework.beans.factory.annotation.Value) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) Locale(java.util.Locale) ExpressionFactory(org.apache.cayenne.exp.ExpressionFactory) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) MessageSource(org.springframework.context.MessageSource) MediaType(com.google.common.net.MediaType) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) Logger(org.slf4j.Logger) ResolvedPkgVersionLocalization(org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) NaturalLanguage(org.haiku.haikudepotserver.dataobjects.NaturalLanguage) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntrySupplier(org.haiku.haikudepotserver.feed.model.SyndEntrySupplier) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ObjectSelect(org.apache.cayenne.query.ObjectSelect) PkgLocalizationService(org.haiku.haikudepotserver.pkg.model.PkgLocalizationService) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) Collections(java.util.Collections) Locale(java.util.Locale) ResolvedPkgVersionLocalization(org.haiku.haikudepotserver.pkg.model.ResolvedPkgVersionLocalization) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) NaturalLanguage(org.haiku.haikudepotserver.dataobjects.NaturalLanguage) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)33 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)29 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)27 SyndContent (com.rometools.rome.feed.synd.SyndContent)25 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)15 ArrayList (java.util.ArrayList)14 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)13 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)4 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)4 SyndCategory (com.rometools.rome.feed.synd.SyndCategory)3 SyndImageImpl (com.rometools.rome.feed.synd.SyndImageImpl)3 SProject (org.bimserver.interfaces.objects.SProject)3 Preconditions (com.google.common.base.Preconditions)2 Hashing (com.google.common.hash.Hashing)2 MediaType (com.google.common.net.MediaType)2 SyndCategoryImpl (com.rometools.rome.feed.synd.SyndCategoryImpl)2 SyndImage (com.rometools.rome.feed.synd.SyndImage)2 SyndPerson (com.rometools.rome.feed.synd.SyndPerson)2 SyndPersonImpl (com.rometools.rome.feed.synd.SyndPersonImpl)2