Search in sources :

Example 66 with SyndFeed

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SocketTimeoutException(java.net.SocketTimeoutException) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) XmlReader(com.sun.syndication.io.XmlReader) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) URLConnection(java.net.URLConnection) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 67 with SyndFeed

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) GroupBlock(org.xwiki.rendering.block.GroupBlock) LinkBlock(org.xwiki.rendering.block.LinkBlock) Block(org.xwiki.rendering.block.Block) ImageBlock(org.xwiki.rendering.block.ImageBlock) RawBlock(org.xwiki.rendering.block.RawBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) GroupBlock(org.xwiki.rendering.block.GroupBlock) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) BoxMacroParameters(org.xwiki.rendering.macro.box.BoxMacroParameters)

Example 68 with SyndFeed

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());
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) HashMap(java.util.HashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) XWikiException(com.xpn.xwiki.XWikiException) ConversionException(org.xwiki.rendering.converter.ConversionException) IOException(java.io.IOException) CacheException(org.xwiki.cache.CacheException)

Example 69 with SyndFeed

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 70 with SyndFeed

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;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) HashMap(java.util.HashMap)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)89 ArrayList (java.util.ArrayList)28 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)25 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)16 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)16 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)16 Test (org.testng.annotations.Test)16 Test (org.junit.Test)11 SkipException (org.testng.SkipException)11 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 URL (java.net.URL)10 FeedException (com.sun.syndication.io.FeedException)9 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)9 IOException (java.io.IOException)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 ConsumerCert (rhsm.data.ConsumerCert)8 XmlReader (com.sun.syndication.io.XmlReader)7 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)6