use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.
the class DefaultRomeFeedFactory method createFeed.
@Override
public SyndFeed createFeed(RssMacroParameters parameters) throws MacroExecutionException {
if (StringUtils.isEmpty(parameters.getFeed())) {
throw new MacroExecutionException("The required 'feed' parameter is missing");
}
SyndFeedInput syndFeedInput = new SyndFeedInput();
SyndFeed feed;
try {
if (StringUtils.startsWith(parameters.getFeed().toLowerCase(), "https")) {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) parameters.getFeedURL().openConnection();
httpsURLConnection.setConnectTimeout(TIMEOUT_MILLISECONDS);
httpsURLConnection.setRequestProperty(USER_AGENT_HEADER, USER_AGENT);
feed = syndFeedInput.build(new XmlReader(httpsURLConnection.getInputStream(), true, parameters.getEncoding()));
} else {
URLConnection httpURLConnection = parameters.getFeedURL().openConnection();
httpURLConnection.setConnectTimeout(TIMEOUT_MILLISECONDS);
httpURLConnection.setRequestProperty(USER_AGENT_HEADER, USER_AGENT);
feed = syndFeedInput.build(new XmlReader(httpURLConnection.getInputStream(), true, parameters.getEncoding()));
}
} catch (SocketTimeoutException ex) {
throw new MacroExecutionException(MessageFormat.format("Connection timeout when trying to reach [{0}]", parameters.getFeedURL()));
} catch (Exception ex) {
throw new MacroExecutionException(MessageFormat.format("Error processing [{0}] : {1}", parameters.getFeedURL(), ex.getMessage()), ex);
}
if (feed == null) {
throw new MacroExecutionException(MessageFormat.format("No feed found at [{0}]", parameters.getFeedURL()));
}
return feed;
}
use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.
the class RssMacro method execute.
@Override
public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
List<Block> result;
SyndFeed feed = this.romeFeedFactory.createFeed(parameters);
if (parameters.isDecoration()) {
BoxMacroParameters boxParameters = new BoxMacroParameters();
boolean hasImage = parameters.isImage() && (feed.getImage() != null);
boxParameters.setCssClass(FEED_CLASS_VALUE);
if (StringUtils.isNotEmpty(parameters.getWidth())) {
boxParameters.setWidth(parameters.getWidth());
}
boxParameters.setBlockTitle(generateBoxTitle("rsschanneltitle", feed));
if (hasImage) {
boxParameters.setImage(new ResourceReference(feed.getImage().getUrl(), ResourceType.URL));
}
result = this.boxMacro.execute(boxParameters, content == null ? StringUtils.EMPTY : content, context);
} else {
result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE)));
}
generateEntries(result.get(0), feed, parameters);
return result;
}
use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.
the class FeedPlugin method getFeedForce.
public SyndFeed getFeedForce(String sfeed, boolean ignoreInvalidFeeds, XWikiContext context) throws IOException {
try {
URL feedURL = new URL(sfeed);
XWikiFeedFetcher feedFetcher = new XWikiFeedFetcher();
feedFetcher.setUserAgent(context.getWiki().Param("xwiki.plugins.feed.useragent", context.getWiki().getHttpUserAgent(context)));
SyndFeed feed = feedFetcher.retrieveFeed(feedURL, (int) context.getWiki().ParamAsLong("xwiki.plugins.feed.timeout", context.getWiki().getHttpTimeout(context)));
return feed;
} catch (Exception ex) {
if (ignoreInvalidFeeds) {
@SuppressWarnings("unchecked") Map<String, Exception> map = (Map<String, Exception>) context.get("invalidFeeds");
if (map == null) {
map = new HashMap<String, Exception>();
context.put("invalidFeeds", map);
}
map.put(sfeed, ex);
return null;
}
throw new java.io.IOException("Error processing " + sfeed + ": " + ex.getMessage());
}
}
use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.
the class FeedPlugin method getFeed.
public SyndFeed getFeed(String sfeed, boolean ignoreInvalidFeeds, boolean force, XWikiContext context) throws IOException {
SyndFeed feed = null;
prepareCache(context);
if (!force) {
feed = this.feedCache.get(sfeed);
}
if (feed == null) {
feed = getFeedForce(sfeed, ignoreInvalidFeeds, context);
}
if (feed != null) {
this.feedCache.set(sfeed, feed);
}
return feed;
}
use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.
the class FeedPluginApi method getWebFeed.
/**
* Instantiates the default document feed.
*
* @param query the HQL query used for retrieving the documents
* @param count the maximum number of documents to retrieve
* @param start the start index
* @param metadata feed meta data (includes the author, description, copyright, encoding, url, title)
* @return a new feed
* @see #getDocumentFeed(String, int, int, Map)
*/
public SyndFeed getWebFeed(String query, int count, int start, Map<String, Object> metadata) {
if (query == null) {
query = "where 1=1 order by doc.date desc";
}
Map<String, Object> params = new HashMap<String, Object>();
SyndFeed webFeed = getDocumentFeed(query, count, start, params, fillWebFeedMetadata(metadata));
if (webFeed != null) {
webFeed.setImage(getDefaultFeedImage());
}
return webFeed;
}
Aggregations