Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryDocumentSource.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryDocumentSource.java (revision 0) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryDocumentSource.java (revision 0) @@ -0,0 +1,114 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.plugin.feed; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; + +/** + * Concrete strategy for computing the field values of a feed entry from any {@link XWikiDocument} + * instance. + */ +public class SyndEntryDocumentSource extends AbstractSyndEntrySource +{ + /** + * @see AbstractSyndEntrySource#getDefaultParams() + */ + public static final Map defaultParams; + + static { + defaultParams = new HashMap(); + defaultParams.put(CONTENT_TYPE, "text/html"); + defaultParams.put(CONTENT_LENGTH, new Integer(250)); + } + + public SyndEntryDocumentSource() + { + this(Collections.EMPTY_MAP); + } + + public SyndEntryDocumentSource(Map params) + { + super(params); + } + + /** + * {@inheritDoc} + * + * @see AbstractSyndEntrySource#getDefaultParams() + */ + protected Map getDefaultParams() + { + return defaultParams; + } + + /** + * {@inheritDoc} + * + * @see SyndEntrySource#source(SyndEntry, Object, Map, XWikiContext) + */ + public void source(SyndEntry entry, Object obj, Map params, XWikiContext context) + throws XWikiException + { + // cast source + XWikiDocument doc = castDocument(obj); + + // test access rights + if (!context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), + context.getDatabase() + ":" + doc.getFullName(), context)) { + throw new XWikiException(); + } + + // prepare parameters (overwrite instance parameters) + Map trueParams = joinParams(params, getParams()); + String contentType = (String) trueParams.get(CONTENT_TYPE); + + // compute field values + XWiki xwiki = context.getWiki(); + + String url = doc.getExternalURL("view", "language=" + doc.getRealLanguage(), context); + String title = doc.getDisplayTitle(context); + String creator = xwiki.getUserName(doc.getCreator(), null, false, context); + String author = xwiki.getUserName(doc.getAuthor(), null, false, context); + String description = + "Version " + doc.getVersion() + " edited by " + author + " on " + doc.getDate(); + List contributors = new ArrayList(); + contributors.add(author); + + // fill the feed entry with computed field values + entry.setUri(url); + entry.setLink(url); + entry.setTitle(title); + entry.setDescription(getSyndContent(contentType, description)); + entry.setPublishedDate(doc.getCreationDate()); + entry.setUpdatedDate(doc.getDate()); + entry.setAuthor(creator); + entry.setContributors(contributors); + } +} Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntrySource.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntrySource.java (revision 0) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntrySource.java (revision 0) @@ -0,0 +1,46 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.plugin.feed; + +import java.util.Map; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; + +/** + * Abstracts a strategy for computing the field values of a feed entry from a generic source. + */ +public interface SyndEntrySource +{ + /** + * Overwrites the current values of the given feed entry with new ones computed from the + * specified source object. + * + * @param entry the feed entry whose fields are going to be overwritten + * @param obj the source for the new values to be set on the fields of the feed entry + * @param params parameters to adjust the computation. Each concrete strategy may define its own + * (key, value) pairs + * @param context the XWiki context + * @throws XWikiException + */ + void source(SyndEntry entry, Object obj, Map params, XWikiContext context) + throws XWikiException; +} Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/FeedPlugin.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/FeedPlugin.java (revision 7925) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/FeedPlugin.java (working copy) @@ -22,17 +22,20 @@ package com.xpn.xwiki.plugin.feed; import java.io.IOException; +import java.io.StringWriter; +import java.lang.reflect.Constructor; import java.net.URL; import java.util.*; import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.SyndFeedOutput; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; -import com.xpn.xwiki.web.XWikiEngineContext; import com.xpn.xwiki.api.Api; import com.xpn.xwiki.cache.api.XWikiCache; import com.xpn.xwiki.cache.api.XWikiCacheNeedsRefreshException; @@ -705,4 +708,116 @@ return null; } + /** + * @see FeedPluginApi#getSyndEntrySource(String, Map) + */ + public SyndEntrySource getSyndEntrySource(String className, Map params, XWikiContext context) + throws XWikiException + { + try { + Class sesc = Class.forName(className).asSubclass(SyndEntrySource.class); + Constructor ctor = null; + if (params != null) { + try { + ctor = sesc.getConstructor(new Class[] {Map.class}); + return (SyndEntrySource) ctor.newInstance(new Object[] {params}); + } catch (Throwable t) { + } + } + ctor = sesc.getConstructor(new Class[] {}); + return (SyndEntrySource) ctor.newInstance(new Object[] {}); + } catch (Throwable t) { + throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, + XWikiException.ERROR_XWIKI_UNKNOWN, + "", + t); + } + } + + /** + * @see FeedPluginApi#getFeedEntry() + */ + public SyndEntry getFeedEntry(XWikiContext context) + { + return new SyndEntryImpl(); + } + + /** + * @see FeedPluginApi#getFeed() + */ + public SyndFeed getFeed(XWikiContext context) + { + return new SyndFeedImpl(); + } + + /** + * @see FeedPluginApi#getFeed(List, SyndEntrySourceApi, Map) + */ + public SyndFeed getFeed(List list, SyndEntrySource source, Map sourceParams, + XWikiContext context) throws XWikiException + { + SyndFeed feed = getFeed(context); + List entries = new ArrayList(); + for (int i = 0; i < list.size(); i++) { + SyndEntry entry = getFeedEntry(context); + try { + source.source(entry, list.get(i), sourceParams, context); + entries.add(entry); + } catch (Throwable t) { + // skip this entry + } + } + feed.setEntries(entries); + return feed; + } + + /** + * @see FeedPluginApi#getFeed(List, SyndEntrySourceApi, Map, String, String, String, String, + * String, String) + */ + public SyndFeed getFeed(List list, SyndEntrySource source, Map sourceParams, String author, + String title, String description, String copyright, String encoding, String url, + XWikiContext context) throws XWikiException + { + SyndFeed feed = getFeed(list, source, sourceParams, context); + feed.setAuthor(author); + feed.setDescription(description); + feed.setCopyright(copyright); + feed.setEncoding(encoding); + feed.setLink(url); + feed.setTitle(title); + return feed; + } + + /** + * @see FeedPluginApi#getFeedOutput(SyndFeed, String) + */ + public String getFeedOutput(SyndFeed feed, String type, XWikiContext context) + { + feed.setFeedType(type); + StringWriter writer = new StringWriter(); + SyndFeedOutput output = new SyndFeedOutput(); + try { + output.output(feed, writer); + writer.close(); + return writer.toString(); + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + /** + * @see FeedPluginApi#getFeedOutput(List, SyndEntrySourceApi, Map, String, String, String, + * String, String, String, String) + */ + public String getFeedOutput(List list, SyndEntrySource source, Map sourceParams, + String author, String title, String description, String copyright, String encoding, + String url, String type, XWikiContext context) throws XWikiException + { + SyndFeed feed = + getFeed(list, source, sourceParams, author, title, description, copyright, encoding, + url, context); + return getFeedOutput(feed, type, context); + } } Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/AbstractSyndEntrySource.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/AbstractSyndEntrySource.java (revision 0) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/AbstractSyndEntrySource.java (revision 0) @@ -0,0 +1,123 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.plugin.feed; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.api.Document; +import com.xpn.xwiki.doc.XWikiDocument; + +/** + * Abstract strategy for computing the field values of a feed entry + */ +public abstract class AbstractSyndEntrySource implements SyndEntrySource +{ + public static final String CONTENT_TYPE = "ContentType"; + + public static final String CONTENT_LENGTH = "ContentLength"; + + /** + * Strategy instance parameters. Each concrete strategy can define its own (paramName, + * paramValue) pairs. These parameters are overwritten by those used when calling + * {@link SyndEntrySource#source(SyndEntry, Object, Map, XWikiContext)} method + */ + private Map params; + + public AbstractSyndEntrySource(Map params) + { + setParams(params); + } + + public Map getParams() + { + return params; + } + + public void setParams(Map params) + { + this.params = joinParams(params, getDefaultParams()); + } + + /** + * Strategy class parameters + */ + protected Map getDefaultParams() + { + return Collections.EMPTY_MAP; + } + + /** + * @return base + (extra - base) + */ + protected Map joinParams(Map base, Map extra) + { + Map params = new HashMap(); + params.putAll(base); + Iterator it = extra.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + if (params.get(entry.getKey()) == null) { + params.put(entry.getKey(), entry.getValue()); + } + } + return params; + } + + protected String getDescription(String content, int contentLength, String url, + XWikiContext context) + { + if (content.length() > contentLength) { + int spaceIndex = content.indexOf(" ", contentLength); + if (spaceIndex < 0) { + spaceIndex = contentLength; + } + if (spaceIndex < 0) { + spaceIndex = 0; + } + content = content.substring(0, spaceIndex); + content = content.concat(" ..."); + } + return context.getDoc().getRenderedContent(content, context); + } + + protected SyndContent getSyndContent(String type, String value) + { + SyndContent content = new SyndContentImpl(); + content.setType(type); + content.setValue(value); + return content; + } + + protected XWikiDocument castDocument(Object obj) + { + if (obj instanceof Document) { + return ((Document) obj).getDocument(); + } else { + return (XWikiDocument) obj; + } + } +} Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryArticleSource.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryArticleSource.java (revision 0) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryArticleSource.java (revision 0) @@ -0,0 +1,120 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.plugin.feed; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.xpn.xwiki.XWiki; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.XWikiDocument; +import com.xpn.xwiki.objects.BaseObject; + +/** + * Concrete strategy for computing the field values of a feed entry from a {@link XWikiDocument} + * instance containing an XWiki.ArticleClass object. + */ +public class SyndEntryArticleSource extends AbstractSyndEntrySource +{ + /** + * @see AbstractSyndEntrySource#getDefaultParams() + */ + public static final Map defaultParams; + + static { + defaultParams = new HashMap(); + defaultParams.put(CONTENT_TYPE, "text/html"); + defaultParams.put(CONTENT_LENGTH, new Integer(400)); + } + + public SyndEntryArticleSource() + { + this(Collections.EMPTY_MAP); + } + + public SyndEntryArticleSource(Map params) + { + super(params); + } + + /** + * {@inheritDoc} + * + * @see AbstractSyndEntrySource#getDefaultParams() + */ + protected Map getDefaultParams() + { + return defaultParams; + } + + /** + * {@inheritDoc} + * + * @see SyndEntrySource#source(SyndEntry, Object, Map, XWikiContext) + */ + public void source(SyndEntry entry, Object obj, Map params, XWikiContext context) + throws XWikiException + { + // cast source + XWikiDocument doc = castDocument(obj); + + // test access rights + if (!context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), + context.getDatabase() + ":" + doc.getFullName(), context)) { + throw new XWikiException(); + } + + // prepare parameters (overwrite instance parameters) + Map trueParams = joinParams(params, getParams()); + String contentType = (String) trueParams.get(CONTENT_TYPE); + int contentLength = ((Number) trueParams.get(CONTENT_LENGTH)).intValue(); + + // compute field values + XWiki xwiki = context.getWiki(); + BaseObject article = doc.getObject("XWiki.ArticleClass"); + + String url = doc.getExternalURL("view", "language=" + doc.getRealLanguage(), context); + String title = doc.display("title", "view", article, context); + String content = doc.display("content", "view", article, context); + String description = getDescription(content, contentLength, url, context); + List categories = + Arrays.asList(doc.display("category", "view", article, context).split(",")); + String creator = xwiki.getUserName(doc.getCreator(), null, false, context); + List contributors = new ArrayList(); + contributors.add(xwiki.getUserName(doc.getAuthor(), null, false, context)); + + // fill the feed entry with computed field values + entry.setUri(url); + entry.setLink(url); + entry.setTitle(title); + entry.setDescription(getSyndContent(contentType, description)); + entry.setCategories(categories); + entry.setPublishedDate(doc.getCreationDate()); + entry.setUpdatedDate(doc.getDate()); + entry.setAuthor(creator); + entry.setContributors(contributors); + } +} Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntrySourceApi.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntrySourceApi.java (revision 0) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/SyndEntrySourceApi.java (revision 0) @@ -0,0 +1,97 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.plugin.feed; + +import java.util.Collections; +import java.util.Map; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.xpn.xwiki.XWikiContext; +import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.api.Api; + +/** + * API for {@link SyndEntrySource} + */ +public class SyndEntrySourceApi extends Api +{ + public static final String SYND_ENTRY_SOURCE_EXCEPTION = "SyndEntrySourceException"; + + private SyndEntrySource source; + + public SyndEntrySourceApi(SyndEntrySource source, XWikiContext context) + { + super(context); + this.source = source; + } + + protected SyndEntrySource getSyndEntrySource() + { + return this.source; + } + + /** + * @see SyndEntrySource#source(SyndEntry, Object, java.util.Map, XWikiContext) + */ + public boolean source(SyndEntry entry, Object obj, Map params) + { + getXWikiContext().remove(SYND_ENTRY_SOURCE_EXCEPTION); + try { + this.source.source(entry, obj, params, getXWikiContext()); + return true; + } catch (XWikiException e) { + getXWikiContext().put(SYND_ENTRY_SOURCE_EXCEPTION, e); + return false; + } + } + + /** + * @see SyndEntrySource#source(SyndEntry, Object, java.util.Map, XWikiContext) + */ + public boolean source(SyndEntry entry, Object obj) + { + return this.source(entry, obj, Collections.EMPTY_MAP); + } + + /** + * @see SyndEntrySource#source(SyndEntry, Object, java.util.Map, XWikiContext) + */ + public SyndEntry source(Object obj, Map params) + { + getXWikiContext().remove(SYND_ENTRY_SOURCE_EXCEPTION); + try { + SyndEntry entry = new SyndEntryImpl(); + this.source.source(entry, obj, params, getXWikiContext()); + return entry; + } catch (XWikiException e) { + getXWikiContext().put(SYND_ENTRY_SOURCE_EXCEPTION, e); + return null; + } + } + + /** + * @see SyndEntrySource#source(SyndEntry, Object, java.util.Map, XWikiContext) + */ + public SyndEntry source(Object obj) + { + return this.source(obj, Collections.EMPTY_MAP); + } +} Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/FeedPluginApi.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/FeedPluginApi.java (revision 7925) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/plugin/feed/FeedPluginApi.java (working copy) @@ -23,13 +23,18 @@ import java.io.IOException; import java.util.Collection; +import java.util.List; +import java.util.Map; +import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.api.Api; public class FeedPluginApi extends Api { + public static final String FEED_PLUGIN_EXCEPTION = "FeedPluginException"; + private FeedPlugin plugin; public FeedPluginApi(FeedPlugin plugin, XWikiContext context) { @@ -168,4 +173,134 @@ return plugin.getActiveUpdateThreads(); } + /** + * Tries to instantiate a class implementing the {@link SyndEntrySource} interface using the + * given parameters + * + * @param className the name of a class implementing {@link SyndEntrySource} interface + * @param params constructor parameters + * @return a new SyndEntrySource instance + */ + public SyndEntrySourceApi getSyndEntrySource(String className, Map params) + { + getXWikiContext().remove(FEED_PLUGIN_EXCEPTION); + try { + SyndEntrySource source = + plugin.getSyndEntrySource(className, params, getXWikiContext()); + return new SyndEntrySourceApi(source, getXWikiContext()); + } catch (XWikiException e) { + getXWikiContext().put(FEED_PLUGIN_EXCEPTION, e); + return null; + } + } + + /** + * @see #getSyndEntrySource(String, Map) + */ + public SyndEntrySourceApi getSyndEntrySource(String className) + { + return this.getSyndEntrySource(className, null); + } + + /** + * Creates an empty feed entry + * + * @return a new feed entry + */ + public SyndEntry getFeedEntry() + { + return plugin.getFeedEntry(getXWikiContext()); + } + + /** + * Creates an empty feed + * + * @return a new feed + */ + public SyndFeed getFeed() + { + return plugin.getFeed(getXWikiContext()); + } + + /** + * Computes a new feed from a list of source items and a corresponding strategy for converting + * them in feed entries + * + * @param list the list of source items + * @param source the strategy to use for computing feed entries from source items + * @param sourceParams strategy parameters + * @return a new feed + */ + public SyndFeed getFeed(List list, SyndEntrySourceApi sourceApi, Map sourceParams) + { + getXWikiContext().remove(FEED_PLUGIN_EXCEPTION); + try { + return plugin.getFeed(list, sourceApi.getSyndEntrySource(), sourceParams, + getXWikiContext()); + } catch (XWikiException e) { + getXWikiContext().put(FEED_PLUGIN_EXCEPTION, e); + return null; + } + } + + /** + * Computes a new feed from a list of source items and a corresponding strategy for converting + * them in feed entries, filling in the feed meta data. + * + * @param list the list of source items + * @param source the strategy to use for computing feed entries from source items + * @param sourceParams strategy parameters + * @param author feed author + * @param title feed title + * @param description feed description + * @param copyright feed copyright + * @param encoding feed encoding + * @param url feed URL + * @return a new feed + */ + public SyndFeed getFeed(List list, SyndEntrySourceApi sourceApi, Map sourceParams, + String author, String title, String description, String copyright, String encoding, + String url) + { + getXWikiContext().remove(FEED_PLUGIN_EXCEPTION); + try { + return plugin.getFeed(list, sourceApi.getSyndEntrySource(), sourceParams, author, + title, description, copyright, encoding, url, getXWikiContext()); + } catch (XWikiException e) { + getXWikiContext().put(FEED_PLUGIN_EXCEPTION, e); + return null; + } + } + + /** + * Converts a feed into its string representation using the specified syntax + * + * @param feed any type of feed, implementing the {@link SyndFeed} interface + * @param type the feed type (syntax) to use, null if none. It can be any version of RSS + * or Atom. Some possible values are "rss_1.0", "rss_2.0" and "atom_1.0" + * @return the string representation of the given feed using the syntax associated with the + * specified feed type + */ + public String getFeedOutput(SyndFeed feed, String type) + { + return plugin.getFeedOutput(feed, type, getXWikiContext()); + } + + /** + * @see #getFeedOutput(SyndFeed, String) + * @see #getFeed(List, SyndEntrySourceApi, String, String, String, String, String, String) + */ + public String getFeedOutput(List list, SyndEntrySourceApi sourceApi, Map sourceParams, + String author, String title, String description, String copyright, String encoding, + String url, String type) + { + getXWikiContext().remove(FEED_PLUGIN_EXCEPTION); + try { + return plugin.getFeedOutput(list, sourceApi.getSyndEntrySource(), sourceParams, + author, title, description, copyright, encoding, url, type, getXWikiContext()); + } catch (XWikiException e) { + getXWikiContext().put(FEED_PLUGIN_EXCEPTION, e); + return null; + } + } }