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;
}
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 OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method convertEntry.
/**
* Converts a <code>SyndEntry</code> into an <code>Item</code>
*
* @param entry
* @return
*/
protected Item convertEntry(Feed feed, SyndEntry entry) {
Item item = new ItemImpl(feed);
item.setAuthor(entry.getAuthor());
item.setExternalLink(entry.getLink());
item.setGuid(entry.getUri());
item.setLastModified(entry.getUpdatedDate());
item.setPublishDate(entry.getPublishedDate());
item.setTitle(entry.getTitle());
if (entry.getDescription() != null) {
item.setDescription(entry.getDescription().getValue());
}
List<SyndContent> contents = entry.getContents();
item.setContent(joinContents(contents));
List<SyndEnclosure> enclosures = entry.getEnclosures();
item.setEnclosure(convertEnclosures(enclosures));
return item;
}
use of com.rometools.rome.feed.synd.SyndContent in project onebusaway-application-modules by camsys.
the class MonitoringAlertsUpdateAction method execute.
@Override
public String execute() {
_feed = new SyndFeedImpl();
StringBuilder title = new StringBuilder();
title.append("OneBusAway System Monitoring");
HttpServletRequest request = ServletActionContext.getRequest();
StringBuilder b = new StringBuilder();
b.append("http://");
b.append(request.getServerName());
if (request.getServerPort() != 80)
b.append(":").append(request.getServerPort());
if (request.getContextPath() != null)
b.append(request.getContextPath());
String baseUrl = b.toString();
_feed.setTitle(title.toString());
_feed.setLink(baseUrl);
_feed.setDescription("System Monitoring");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
// Add Icinga Alerts
SyndEntry icingaEntry = new SyndEntryImpl();
SyndContent icingaContent = new SyndContentImpl();
StatusGroup icingaGroup = _statusProvider.getIcingaStatus();
StatusGroup icingaProblems = new StatusGroup();
icingaProblems.setTitle(icingaGroup.getTitle());
// Only report items where status is not "OK"
for (StatusItem icingaItem : icingaGroup.getItems()) {
if (icingaItem.getStatus() != StatusItem.Status.OK) {
icingaProblems.addItem(icingaItem);
}
}
if (icingaProblems.getItems().size() == 0) {
icingaEntry = new SyndEntryImpl();
icingaEntry.setTitle("All systems operational");
entries.add(icingaEntry);
} else {
for (StatusItem icingaItem : icingaProblems.getItems()) {
icingaEntry = new SyndEntryImpl();
icingaEntry.setTitle(icingaItem.getTitle());
icingaContent = new SyndContentImpl();
icingaContent.setValue(icingaItem.getStatus() + ": " + icingaItem.getDescription());
icingaEntry.setDescription(icingaContent);
entries.add(icingaEntry);
}
}
_feed.setEntries(entries);
return SUCCESS;
}
use of com.rometools.rome.feed.synd.SyndContent in project onebusaway-application-modules by camsys.
the class ServiceAlertsUpdateAction method execute.
@Override
public String execute() {
_feed = new SyndFeedImpl();
StringBuilder title = new StringBuilder();
title.append("OneBusAway Agency Advisories");
HttpServletRequest request = ServletActionContext.getRequest();
StringBuilder b = new StringBuilder();
b.append("http://");
b.append(request.getServerName());
if (request.getServerPort() != 80)
b.append(":").append(request.getServerPort());
if (request.getContextPath() != null)
b.append(request.getContextPath());
String baseUrl = b.toString();
_feed.setTitle(title.toString());
_feed.setLink(baseUrl);
_feed.setDescription("Service Alerts");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
// Add Service Alerts
SyndEntry serviceAlertEntry = new SyndEntryImpl();
SyndContent saContent = new SyndContentImpl();
StatusGroup saGroup = _statusProvider.getAgencyServiceAlertStatus();
if (saGroup.getItems().size() == 0) {
serviceAlertEntry = new SyndEntryImpl();
serviceAlertEntry.setTitle("All systems operational");
entries.add(serviceAlertEntry);
} else {
for (StatusItem saItem : saGroup.getItems()) {
serviceAlertEntry = new SyndEntryImpl();
serviceAlertEntry.setTitle(saItem.getTitle());
saContent = new SyndContentImpl();
saContent.setValue(saItem.getDescription());
serviceAlertEntry.setDescription(saContent);
entries.add(serviceAlertEntry);
}
}
_feed.setEntries(entries);
return SUCCESS;
}
Aggregations