use of com.rometools.rome.feed.synd.SyndEntry 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.SyndEntry in project KaellyBot by Kaysoro.
the class RSS method getRSSFeeds.
public static List<RSS> getRSSFeeds(Language lg) {
List<RSS> rss = new ArrayList<>();
try {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(new URL(Translator.getLabel(lg, "game.url") + Translator.getLabel(lg, "feed.url"))));
for (SyndEntry entry : feed.getEntries()) {
Matcher m = Pattern.compile("<img.+src=\"(.*\\.jpg)\".+>").matcher(entry.getDescription().getValue());
rss.add(new RSS(entry.getTitle(), entry.getLink(), (m.find() ? m.group(1) : null), entry.getPublishedDate().getTime()));
}
} catch (FeedException e) {
Reporter.report(e);
LOG.error("getRSSFeeds", e);
} catch (IOException e) {
ExceptionManager.manageSilentlyIOException(e);
} catch (Exception e) {
ExceptionManager.manageSilentlyException(e);
}
Collections.sort(rss);
return rss;
}
use of com.rometools.rome.feed.synd.SyndEntry in project asterixdb by apache.
the class RSSFeedServlet method getFeed.
protected SyndFeed getFeed(IServletRequest req) throws IOException, FeedException, ParseException {
SyndFeed feed = new SyndFeedImpl();
feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://rome.dev.java.net");
feed.setDescription("This feed has been created using ROME (Java syndication utilities");
List<SyndEntry> entries = new ArrayList<>();
SyndEntry entry;
SyndContent description;
entry = new SyndEntryImpl();
entry.setTitle("AsterixDB 0.8.7");
entry.setLink("http://http://asterixdb.apache.org/docs/0.8.7-incubating/index.html");
entry.setPublishedDate(DATE_PARSER.parse("2012-06-08"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("AsterixDB 0.8.7 Release");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("Couchbase 4.1");
entry.setLink("http://blog.couchbase.com/2015/december/introducing-couchbase-server-4.1");
entry.setPublishedDate(DATE_PARSER.parse("2015-12-09"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Couchbase Server 4.1 Release. Bug fixes, minor API changes and some new features");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("ROME v0.3");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/rome03");
entry.setPublishedDate(DATE_PARSER.parse("2004-07-27"));
description = new SyndContentImpl();
description.setType("text/html");
description.setValue("<p>Bug fixes, API changes, some new features and some Unit testing</p>" + "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#" + "ChangeLog-Changesmadefromv0.3tov0.4\">Changes Log for 0.3</a></p>");
entry.setDescription(description);
entries.add(entry);
entry = new SyndEntryImpl();
entry.setTitle("ROME v0.4");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/rome04");
entry.setPublishedDate(DATE_PARSER.parse("2004-09-24"));
description = new SyndContentImpl();
description.setType("text/html");
description.setValue("<p>Bug fixes, API changes, some new features, Unit testing completed</p>" + "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#" + "ChangeLog-Changesmadefromv0.4tov0.5\">Changes Log for 0.4</a></p>");
entry.setDescription(description);
entries.add(entry);
feed.setEntries(entries);
return feed;
}
use of com.rometools.rome.feed.synd.SyndEntry in project ddf by codice.
the class OpenSearchSource method processResponse.
/**
* @param is
* @param queryRequest
* @return
* @throws ddf.catalog.source.UnsupportedQueryException
*/
private SourceResponseImpl processResponse(InputStream is, QueryRequest queryRequest) throws UnsupportedQueryException {
List<Result> resultQueue = new ArrayList<>();
SyndFeedInput syndFeedInput = new SyndFeedInput();
SyndFeed syndFeed = null;
try {
syndFeed = syndFeedInput.build(new InputStreamReader(is, StandardCharsets.UTF_8));
} catch (FeedException e) {
LOGGER.debug("Unable to read RSS/Atom feed.", e);
}
List<SyndEntry> entries = null;
long totalResults = 0;
if (syndFeed != null) {
entries = syndFeed.getEntries();
for (SyndEntry entry : entries) {
resultQueue.addAll(createResponseFromEntry(entry));
}
totalResults = entries.size();
List<Element> foreignMarkup = syndFeed.getForeignMarkup();
for (Element element : foreignMarkup) {
if (element.getName().equals("totalResults")) {
try {
totalResults = Long.parseLong(element.getContent(0).getValue());
} catch (NumberFormatException | IndexOutOfBoundsException e) {
// totalResults is already initialized to the correct value, so don't change it here.
LOGGER.debug("Received invalid number of results.", e);
}
}
}
}
SourceResponseImpl response = new SourceResponseImpl(queryRequest, resultQueue);
response.setHits(totalResults);
return response;
}
use of com.rometools.rome.feed.synd.SyndEntry in project tika by apache.
the class FeedParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
// set the encoding?
try {
SyndFeed feed = new SyndFeedInput().build(new InputSource(new CloseShieldInputStream(stream)));
String title = stripTags(feed.getTitleEx());
String description = stripTags(feed.getDescriptionEx());
metadata.set(TikaCoreProperties.TITLE, title);
metadata.set(TikaCoreProperties.DESCRIPTION, description);
// store the other fields in the metadata
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
xhtml.element("h1", title);
xhtml.element("p", description);
xhtml.startElement("ul");
for (Object e : feed.getEntries()) {
SyndEntry entry = (SyndEntry) e;
String link = entry.getLink();
if (link != null) {
xhtml.startElement("li");
xhtml.startElement("a", "href", link);
xhtml.characters(stripTags(entry.getTitleEx()));
xhtml.endElement("a");
SyndContent content = entry.getDescription();
if (content != null) {
xhtml.newline();
xhtml.characters(stripTags(content));
}
xhtml.endElement("li");
}
}
xhtml.endElement("ul");
xhtml.endDocument();
} catch (FeedException e) {
throw new TikaException("RSS parse error", e);
}
}
Aggregations