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"));
}
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);
}
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;
}
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(" ", " "));
feed.setLink(feedLink);
feed.setDescription(feedDescription.replaceAll(" ", " "));
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(""", "\"").replaceAll("'", "\'"));
} 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(" ", " ").replaceAll("&quot;", "\"").replaceAll("'", "\'");
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;
}
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();
}
Aggregations