Index: src/main/java/com/xpn/xwiki/plugin/feed/FeedPluginApi.java =================================================================== --- src/main/java/com/xpn/xwiki/plugin/feed/FeedPluginApi.java (revision 11467) +++ src/main/java/com/xpn/xwiki/plugin/feed/FeedPluginApi.java Wed Aug 12 15:25:55 PDT 2009 @@ -41,8 +41,20 @@ public class FeedPluginApi extends Api { + private static final String BLOG_POST_CLASS_NAME = "Blog.BlogPostClass"; + private static final String BLOG_POST_TEMPLATE_NAME = "Blog.BlogPostTemplate"; + + private static final Map BLOG_FIELDS_MAPPING; + public static final String FEED_PLUGIN_EXCEPTION = "FeedPluginException"; + static { + BLOG_FIELDS_MAPPING = new HashMap(); + BLOG_FIELDS_MAPPING.put(SyndEntryDocumentSource.FIELD_TITLE, "Blog.BlogPostClass_title"); + BLOG_FIELDS_MAPPING.put(SyndEntryDocumentSource.FIELD_DESCRIPTION, "Blog.BlogPostClass_content"); + BLOG_FIELDS_MAPPING.put(SyndEntryDocumentSource.FIELD_CATEGORIES, "Blog.BlogPostClass_category"); + BLOG_FIELDS_MAPPING.put(SyndEntryDocumentSource.CONTENT_LENGTH, new Integer(400)); + } private FeedPlugin plugin; public FeedPluginApi(FeedPlugin plugin, XWikiContext context) { @@ -578,17 +590,19 @@ private Map fillBlogFeedMetadata(Map metadata) { - fillDefaultFeedMetadata(metadata); + // Make sure that we don't have an immutable Map + Map result = new HashMap(metadata); + fillDefaultFeedMetadata(result); // these strings should be taken from a resource bundle String title = "Personal Wiki Blog"; String description = title; - if (!keyHasValue(metadata, "title", "")) { - metadata.put("title", title); + if (!keyHasValue(result, "title", "")) { + result.put("title", title); } - if (!keyHasValue(metadata, "description", "")) { - metadata.put("description", description); + if (!keyHasValue(result, "description", "")) { + result.put("description", description); } - return metadata; + return result; } /** @@ -618,7 +632,8 @@ */ public SyndFeed getBlogFeed(List list, Map metadata) { - SyndFeed blogFeed = getArticleFeed(list, fillBlogFeedMetadata(metadata)); + SyndFeed blogFeed = getFeed(list, getSyndEntrySource(SyndEntryDocumentSource.class.getName(), BLOG_FIELDS_MAPPING), Collections.EMPTY_MAP, fillBlogFeedMetadata(metadata)); +// SyndFeed blogFeed = getArticleFeed(list, fillBlogFeedMetadata(metadata)); if (blogFeed != null) { blogFeed.setImage(getDefaultFeedImage()); } @@ -727,14 +742,14 @@ String category = request.getParameter("category"); if (category == null || category.equals("")) { query = - ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.ArticleClass' and obj.name<>'XWiki.ArticleClassTemplate' order by doc.creationDate desc"; + ", BaseObject as obj where obj.name=doc.fullName and obj.className='" + BLOG_POST_CLASS_NAME + "' and obj.name<>'" + BLOG_POST_TEMPLATE_NAME + "' order by doc.creationDate desc"; } else { query = - ", BaseObject as obj, DBStringListProperty as prop join prop.list list where obj.name=doc.fullName and obj.className='XWiki.ArticleClass' and obj.name<>'XWiki.ArticleClassTemplate' and obj.id=prop.id.id and prop.id.name='category' and list = '" + ", BaseObject as obj, DBStringListProperty as prop join prop.list list where obj.name=doc.fullName and obj.className='" + BLOG_POST_CLASS_NAME + "' and obj.name<>'" + BLOG_POST_TEMPLATE_NAME + "' and obj.id=prop.id.id and prop.id.name='category' and list = '" + category + "' order by doc.creationDate desc"; } } - SyndFeed blogFeed = getArticleFeed(query, count, start, fillBlogFeedMetadata(metadata)); + SyndFeed blogFeed = getFeed(query, count, start, getSyndEntrySource(SyndEntryDocumentSource.class.getName(), BLOG_FIELDS_MAPPING), Collections.EMPTY_MAP, fillBlogFeedMetadata(metadata)); if (blogFeed != null) { blogFeed.setImage(getDefaultFeedImage()); } Index: src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryDocumentSource.java =================================================================== --- src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryDocumentSource.java (revision 20510) +++ src/main/java/com/xpn/xwiki/plugin/feed/SyndEntryDocumentSource.java Wed Aug 12 17:20:25 PDT 2009 @@ -44,6 +44,8 @@ import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.feed.synd.SyndContentImpl; import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndCategory; +import com.sun.syndication.feed.synd.SyndCategoryImpl; import com.xpn.xwiki.XWiki; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; @@ -356,7 +358,9 @@ description = parseString(mapping, doc, context); } else { description = getStringValue(mapping, doc, context); - description = context.getDoc().getRenderedContent(description, XWikiDocument.XWIKI10_SYNTAXID, context); + String syntaxId = doc.getSyntaxId(); + syntaxId = syntaxId == null ? XWikiDocument.XWIKI10_SYNTAXID : syntaxId; + description = context.getDoc().getRenderedContent(description, syntaxId, context); } String contentType = (String) params.get(CONTENT_TYPE); int contentLength = ((Number) params.get(CONTENT_LENGTH)).intValue(); @@ -380,14 +384,26 @@ protected List getCategories(Document doc, Map params, XWikiContext context) throws XWikiException { String mapping = (String) params.get(FIELD_CATEGORIES); + List categories = null; if (mapping == null) { - return getDefaultCategories(doc, params, context); + categories = getDefaultCategories(doc, params, context); } else if (isVelocityCode(mapping)) { - return parseList(mapping, doc, context); + categories = parseList(mapping, doc, context); } else { - return getListValue(mapping, doc, context); + categories = getListValue(mapping, doc, context); } + List result = new ArrayList(); + for(Object category: categories) { + if(category instanceof SyndCategory) { + result.add(category); + } else if(category != null) { + SyndCategory scat = new SyndCategoryImpl(); + scat.setName(category.toString()); + result.add(scat); - } + } + } + return result; + } protected Date getDefaultPublishedDate(Document doc, Map params, XWikiContext context) {