use of com.rometools.rome.feed.synd.SyndContent in project BIMserver by opensourceBIM.
the class SyndicationServlet method writeCheckoutsFeed.
private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, PublicInterfaceNotFoundException {
long poid = Long.parseLong(request.getParameter("poid"));
SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(FEED_TYPE);
feed.setTitle("BIMserver.org checkouts feed for project '" + sProject.getName() + "'");
feed.setLink(request.getContextPath());
feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try {
List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
for (SCheckout sCheckout : allCheckoutsOfProject) {
SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
entry.setPublishedDate(sCheckout.getDate());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
entry.setDescription(description);
entries.add(entry);
}
} catch (UserException e) {
LOGGER.error("", e);
}
feed.setEntries(entries);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
}
use of com.rometools.rome.feed.synd.SyndContent in project BIMserver by opensourceBIM.
the class SyndicationServlet method writeProjectsFeed.
private void writeProjectsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws UserException, IOException, FeedException, PublicInterfaceNotFoundException {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(FEED_TYPE);
feed.setTitle("BIMserver.org projects feed");
feed.setLink(request.getContextPath());
feed.setDescription("This feed represents all your available projects within this BIMserver");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try {
List<SProject> allProjects = serviceMap.getServiceInterface().getAllProjects(false, true);
for (SProject sProject : allProjects) {
SyndEntry entry = new SyndEntryImpl();
entry.setAuthor(serviceMap.getServiceInterface().getUserByUoid(sProject.getCreatedById()).getName());
entry.setTitle(sProject.getName());
entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
entry.setPublishedDate(sProject.getCreatedDate());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue(sProject.getDescription());
entry.setDescription(description);
entries.add(entry);
}
if (allProjects.size() == 0) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("No projects found");
entry.setLink(request.getContextPath() + "/main.jsp");
entry.setPublishedDate(new Date());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("No projects found");
entry.setDescription(description);
entries.add(entry);
}
} catch (ServiceException e) {
LOGGER.error("", e);
}
feed.setEntries(entries);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
}
use of com.rometools.rome.feed.synd.SyndContent in project ddf by codice.
the class OpenSearchSource method createResponseFromEntry.
/**
* Creates a single response from input parameters. Performs XPath operations on the document to
* retrieve data not passed in.
*
* @param entry a single Atom entry
* @return single response
* @throws ddf.catalog.source.UnsupportedQueryException
*/
private List<Result> createResponseFromEntry(SyndEntry entry) throws UnsupportedQueryException {
String id = entry.getUri();
if (id != null && !id.isEmpty()) {
id = id.substring(id.lastIndexOf(':') + 1);
}
List<SyndContent> contents = entry.getContents();
List<SyndCategory> categories = entry.getCategories();
List<Metacard> metacards = new ArrayList<>();
List<Element> foreignMarkup = entry.getForeignMarkup();
String relevance = "";
String source = "";
for (Element element : foreignMarkup) {
if (element.getName().equals("score")) {
relevance = element.getContent(0).getValue();
}
}
//we currently do not support downloading content via an RSS enclosure, this support can be added at a later date if we decide to include it
for (SyndContent content : contents) {
MetacardImpl metacard = getMetacardImpl(parseContent(content.getValue(), id));
metacard.setSourceId(this.shortname);
String title = metacard.getTitle();
if (StringUtils.isEmpty(title)) {
metacard.setTitle(entry.getTitle());
}
if (!source.isEmpty()) {
metacard.setSourceId(source);
}
metacards.add(metacard);
}
for (int i = 0; i < categories.size() && i < metacards.size(); i++) {
SyndCategory category = categories.get(i);
Metacard metacard = metacards.get(i);
if (StringUtils.isBlank(metacard.getContentTypeName())) {
((MetacardImpl) metacard).setContentTypeName(category.getName());
}
}
List<Result> results = new ArrayList<>();
for (Metacard metacard : metacards) {
ResultImpl result = new ResultImpl(metacard);
if (relevance == null || relevance.isEmpty()) {
LOGGER.debug("couldn't find valid relevance. Setting relevance to 0");
relevance = "0";
}
result.setRelevanceScore(new Double(relevance));
results.add(result);
}
return results;
}
use of com.rometools.rome.feed.synd.SyndContent in project nutch by apache.
the class FeedParser method addToMap.
private void addToMap(ParseResult parseResult, SyndFeed feed, String feedLink, SyndEntry entry, Content content) {
String link = entry.getLink(), text = null, title = null;
Metadata parseMeta = new Metadata(), contentMeta = content.getMetadata();
Parse parse = null;
SyndContent description = entry.getDescription();
try {
link = normalizers.normalize(link, URLNormalizers.SCOPE_OUTLINK);
if (link != null)
link = filters.filter(link);
} catch (Exception e) {
e.printStackTrace();
return;
}
if (link == null)
return;
title = stripTags(entry.getTitleEx());
if (feedLink != null)
parseMeta.set("feed", feedLink);
addFields(parseMeta, contentMeta, feed, entry);
// some item descriptions contain markup text in them,
// so we temporarily set their content-type to parse them
// with another plugin
String contentType = contentMeta.get(Response.CONTENT_TYPE);
if (description != null)
text = description.getValue();
if (text == null) {
List<?> contents = entry.getContents();
StringBuilder buf = new StringBuilder();
for (Object syndContent : contents) {
buf.append(((SyndContent) syndContent).getValue());
}
text = buf.toString();
}
try {
Parser parser = parserFactory.getParsers(contentType, link)[0];
parse = parser.getParse(new Content(link, link, text.getBytes(), contentType, contentMeta, conf)).get(link);
} catch (ParserNotFound e) {
/* ignore */
}
if (parse != null) {
ParseData data = parse.getData();
data.getContentMeta().remove(Response.CONTENT_TYPE);
mergeMetadata(data.getParseMeta(), parseMeta);
parseResult.put(link, new ParseText(parse.getText()), new ParseData(ParseStatus.STATUS_SUCCESS, title, data.getOutlinks(), data.getContentMeta(), data.getParseMeta()));
} else {
contentMeta.remove(Response.CONTENT_TYPE);
parseResult.put(link, new ParseText(text), new ParseData(ParseStatus.STATUS_FAILURE, title, new Outlink[0], contentMeta, parseMeta));
}
}
use of com.rometools.rome.feed.synd.SyndContent in project blogwt by billy1380.
the class FeedServlet method getFeed.
protected SyndFeed getFeed(HttpServletRequest request) throws IOException, FeedException {
SyndFeed feed = new SyndFeedImpl();
String url = ServletHelper.constructBaseUrl(request);
feed.setTitle(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.TITLE).value);
feed.setLink(url + "/feed");
feed.setDescription(PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.EXTENDED_TITLE).value);
List<Post> posts;
Pager pager = PagerHelper.createDefaultPager();
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry;
SyndContent description;
MarkdownProcessor processor = new MarkdownProcessor();
do {
posts = PostServiceProvider.provide().getPosts(Boolean.FALSE, Boolean.FALSE, pager.start, pager.count, PostSortType.PostSortTypePublished, SortDirectionType.SortDirectionTypeDescending);
if (posts != null) {
PagerHelper.moveForward(pager);
for (Post post : posts) {
entry = new SyndEntryImpl();
entry.setTitle(post.title);
entry.setLink(url + "/#" + PageType.PostDetailPageType.asTargetHistoryToken(post.slug));
entry.setPublishedDate(post.published);
description = new SyndContentImpl();
description.setType("text/HTML");
description.setValue(processor.process(post.summary));
entry.setDescription(description);
entries.add(entry);
}
}
} while (posts != null && posts.size() >= pager.count.intValue());
feed.setEntries(entries);
return feed;
}
Aggregations