Search in sources :

Example 71 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.

the class FeedPluginApi method getBlogFeed.

/**
 * Instantiates the default article feed.
 *
 * @param list a list of articles (as document instances or document names)
 * @param metadata feed meta data (includes the author, description, copyright, encoding, url, title)
 * @return a new feed
 * @see #getArticleFeed(List, Map)
 */
public SyndFeed getBlogFeed(List<Object> list, Map<String, Object> metadata) {
    Map<String, Object> params = Collections.emptyMap();
    SyndFeed blogFeed = getFeed(list, getSyndEntrySource(SyndEntryDocumentSource.class.getName(), BLOG_FIELDS_MAPPING), params, fillBlogFeedMetadata(metadata));
    if (blogFeed != null) {
        blogFeed.setImage(getDefaultFeedImage());
    }
    return blogFeed;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 72 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 list a list of {@link com.xpn.xwiki.api.Document} objects, {@link com.xpn.xwiki.doc.XWikiDocument} objects or document names
 * @param metadata feed meta data (includes the author, description, copyright, encoding, url, title)
 * @return a new feed
 * @see #getDocumentFeed(List, Map)
 */
public SyndFeed getWebFeed(List<Object> list, Map<String, Object> metadata) {
    Map<String, Object> params = Collections.emptyMap();
    SyndFeed webFeed = getDocumentFeed(list, params, fillWebFeedMetadata(metadata));
    if (webFeed != null) {
        webFeed.setImage(getDefaultFeedImage());
    }
    return webFeed;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 73 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.

the class XWikiFeedFetcher method getFeed.

private SyndFeed getFeed(SyndFeedInfo syndFeedInfo, String urlStr, HttpMethod method, int statusCode) throws IOException, FeedException {
    if (statusCode == HttpURLConnection.HTTP_NOT_MODIFIED && syndFeedInfo != null) {
        fireEvent(FetcherEvent.EVENT_TYPE_FEED_UNCHANGED, urlStr);
        return syndFeedInfo.getSyndFeed();
    }
    SyndFeed feed = retrieveFeed(urlStr, method);
    fireEvent(FetcherEvent.EVENT_TYPE_FEED_RETRIEVED, urlStr, feed);
    return feed;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 74 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project xwiki-platform by xwiki.

the class XWikiFeedFetcher method buildSyndFeedInfo.

/**
 * @param feedUrl
 * @param urlStr
 * @param method
 * @param feed
 * @return
 * @throws MalformedURLException
 */
private SyndFeedInfo buildSyndFeedInfo(URL feedUrl, String urlStr, HttpMethod method, SyndFeed feed, int statusCode) throws MalformedURLException {
    SyndFeedInfo syndFeedInfo;
    syndFeedInfo = new SyndFeedInfo();
    // this may be different to feedURL because of 3XX redirects
    syndFeedInfo.setUrl(new URL(urlStr));
    syndFeedInfo.setId(feedUrl.toString());
    Header imHeader = method.getResponseHeader("IM");
    if (imHeader != null && imHeader.getValue().indexOf("feed") >= 0 && isUsingDeltaEncoding()) {
        FeedFetcherCache cache = getFeedInfoCache();
        if (cache != null && statusCode == 226) {
            // client is setup to use http delta encoding and the server supports it and has returned a delta
            // encoded response.
            // This response only includes new items
            SyndFeedInfo cachedInfo = cache.getFeedInfo(feedUrl);
            if (cachedInfo != null) {
                SyndFeed cachedFeed = cachedInfo.getSyndFeed();
                // set the new feed to be the orginal feed plus the new items
                feed = combineFeeds(cachedFeed, feed);
            }
        }
    }
    Header lastModifiedHeader = method.getResponseHeader("Last-Modified");
    if (lastModifiedHeader != null) {
        syndFeedInfo.setLastModified(lastModifiedHeader.getValue());
    }
    Header eTagHeader = method.getResponseHeader("ETag");
    if (eTagHeader != null) {
        syndFeedInfo.setETag(eTagHeader.getValue());
    }
    syndFeedInfo.setSyndFeed(feed);
    return syndFeedInfo;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) Header(org.apache.commons.httpclient.Header) SyndFeedInfo(com.sun.syndication.fetcher.impl.SyndFeedInfo) FeedFetcherCache(com.sun.syndication.fetcher.impl.FeedFetcherCache) URL(java.net.URL)

Example 75 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project liferay-ide by liferay.

the class KBArticleServiceImpl method exportToRSS.

protected String exportToRSS(String rssDisplayStyle, String rssFormat, String name, String description, String feedURL, List<KBArticle> kbArticles, ThemeDisplay themeDisplay) throws SystemException {
    SyndFeed syndFeed = new SyndFeedImpl();
    syndFeed.setDescription(description);
    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
    syndFeed.setEntries(syndEntries);
    for (KBArticle kbArticle : kbArticles) {
        SyndEntry syndEntry = new SyndEntryImpl();
        String author = PortalUtil.getUserName(kbArticle);
        syndEntry.setAuthor(author);
        SyndContent syndContent = new SyndContentImpl();
        syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
        String value = null;
        if (rssDisplayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
            value = HtmlUtil.extractText(kbArticle.getDescription());
            if (Validator.isNull(value)) {
                value = StringUtil.shorten(HtmlUtil.extractText(kbArticle.getContent()), 200);
            }
        } else if (rssDisplayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
            value = StringPool.BLANK;
        } else {
            value = StringUtil.replace(kbArticle.getContent(), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + themeDisplay.getURLPortal() + "/", "src=\"" + themeDisplay.getURLPortal() + "/" });
        }
        syndContent.setValue(value);
        syndEntry.setDescription(syndContent);
        String link = KnowledgeBaseUtil.getKBArticleURL(themeDisplay.getPlid(), kbArticle.getResourcePrimKey(), kbArticle.getStatus(), themeDisplay.getPortalURL(), false);
        syndEntry.setLink(link);
        syndEntry.setPublishedDate(kbArticle.getCreateDate());
        syndEntry.setTitle(kbArticle.getTitle());
        syndEntry.setUpdatedDate(kbArticle.getModifiedDate());
        syndEntry.setUri(syndEntry.getLink());
        syndEntries.add(syndEntry);
    }
    String feedType = RSSUtil.getFeedType(RSSUtil.getFormatType(rssFormat), RSSUtil.getFormatVersion(rssFormat));
    syndFeed.setFeedType(feedType);
    List<SyndLink> syndLinks = new ArrayList<SyndLink>();
    syndFeed.setLinks(syndLinks);
    SyndLink selfSyndLink = new SyndLinkImpl();
    syndLinks.add(selfSyndLink);
    selfSyndLink.setHref(feedURL);
    selfSyndLink.setRel("self");
    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);
    try {
        return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
        throw new SystemException(fe);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndLinkImpl(com.sun.syndication.feed.synd.SyndLinkImpl) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) KBArticle(com.liferay.knowledgebase.model.KBArticle) SyndContent(com.sun.syndication.feed.synd.SyndContent) SystemException(com.liferay.portal.kernel.exception.SystemException) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndLink(com.sun.syndication.feed.synd.SyndLink)

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