Author: ludovic
Date: 2008-02-12 00:02:08 +0100 (Tue, 12 Feb 2008)
New Revision: 7531

Modified:
   xwiki-products/curriki/trunk/plugins/activitystream/pom.xml
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityEvent.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
Log:
CURRIKI-1575 Activity Stream RSS Feed

Modified: xwiki-products/curriki/trunk/plugins/activitystream/pom.xml
===================================================================
--- xwiki-products/curriki/trunk/plugins/activitystream/pom.xml 2008-02-11 
21:38:34 UTC (rev 7530)
+++ xwiki-products/curriki/trunk/plugins/activitystream/pom.xml 2008-02-11 
23:02:08 UTC (rev 7531)
@@ -40,7 +40,7 @@
     <dependency>
       <groupId>com.xpn.xwiki.platform</groupId>
       <artifactId>xwiki-core</artifactId>
-      <version>1.2-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>jmock</groupId>

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
    2008-02-11 21:38:34 UTC (rev 7530)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
    2008-02-11 23:02:08 UTC (rev 7531)
@@ -275,4 +275,5 @@
      * @param params
      */
     void setParams(List params);
+
 }

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
   2008-02-11 21:38:34 UTC (rev 7530)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
   2008-02-11 23:02:08 UTC (rev 7531)
@@ -24,6 +24,8 @@
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiDocument;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
 
 /**
  * Manages the activity stream
@@ -91,4 +93,15 @@
 
     List getEventsForUser(String streamName, String user, boolean filter, int 
nb, int start,
         XWikiContext context) throws ActivityStreamException;
+
+    SyndEntry getFeedEntry(ActivityEvent event, XWikiContext context);
+
+    SyndFeed getFeed(List events, XWikiContext context);
+
+    SyndFeed getFeed(List events, String author, String title, String 
description, String copyright, String encoding, String url, XWikiContext 
context);
+
+    String getFeedOutput(List events, String author, String title, String 
description, String copyright, String encoding, String url, String type, 
XWikiContext context);
+
+    String getFeedOutput(SyndFeed feed, String type);
+     
 }

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
      2008-02-11 21:38:34 UTC (rev 7530)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
      2008-02-11 23:02:08 UTC (rev 7531)
@@ -21,6 +21,10 @@
 
 import java.util.List;
 import java.util.ArrayList;
+import java.io.StringWriter;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
 
 import org.apache.commons.lang.RandomStringUtils;
 import org.hibernate.Session;
@@ -37,6 +41,12 @@
 import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
 import com.xpn.xwiki.notify.XWikiNotificationRule;
 import com.xpn.xwiki.store.XWikiHibernateStore;
+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.sun.syndication.io.FeedException;
 
 public class ActivityStreamImpl implements ActivityStream, 
XWikiDocChangeNotificationInterface
 {
@@ -281,9 +291,65 @@
         }
     }
 
-    /*
+
     public SyndEntry getFeedEntry(ActivityEvent event, XWikiContext context) {
-        return null;
-    } */
+        SyndEntry entry = new SyndEntryImpl();
+        String user = event.getUser();
+        String displayUser = context.getWiki().getUserName(user, null, false, 
context);
+        entry.setAuthor(displayUser);
+        entry.setTitle(event.getDisplayTitle(context));
+        // entry.setDescription(event.getDisplayBody(context));
+        String url;
+        try {
+            url = (new URL(context.getURL(), event.getUrl())).toString();
+        } catch (MalformedURLException e) {
+            url = event.getUrl();
+        }
+        entry.setLink(url);
+        entry.setPublishedDate(event.getDate());
+        entry.setUpdatedDate(event.getDate());
+        return entry;
+    }
 
+    public SyndFeed getFeed(List events, XWikiContext context) {
+        SyndFeed feed = new SyndFeedImpl();
+        List entries = new ArrayList();
+        for (int i=0;i<events.size();i++) {
+           ActivityEvent event = (ActivityEvent) events.get(i);
+           SyndEntry entry = getFeedEntry(event, context);
+           entries.add(entry);
+        }
+        feed.setEntries(entries);
+        return feed;
+    }
+
+    public SyndFeed getFeed(List events, String author, String title, String 
description, String copyright, String encoding, String url, XWikiContext 
context) {
+        SyndFeed feed = getFeed(events, context);
+        feed.setAuthor(author);
+        feed.setDescription(description);
+        feed.setCopyright(copyright);
+        feed.setEncoding(encoding);
+        feed.setLink(url);
+        feed.setTitle(title);
+        return feed;
+    }
+
+    public String getFeedOutput(List events, String author, String title, 
String description, String copyright, String encoding, String url, String type, 
XWikiContext context) {
+        SyndFeed feed = getFeed(events, author, title, description, copyright, 
encoding, url, context);
+        return getFeedOutput(feed, type);
+    }
+
+    public String getFeedOutput(SyndFeed feed, String type) {
+        feed.setFeedType(type);
+        StringWriter writer = new StringWriter();
+        SyndFeedOutput output = new SyndFeedOutput();
+        try {
+            output.output(feed,writer);
+            writer.close();
+            return writer.toString();
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
 }

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityEvent.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityEvent.java
 2008-02-11 21:38:34 UTC (rev 7530)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityEvent.java
 2008-02-11 23:02:08 UTC (rev 7531)
@@ -201,4 +201,7 @@
         return event.getDisplayUser(context);
     }
 
+    protected org.xwiki.plugin.activitystream.api.ActivityEvent getEvent() {
+        return event;
+    }
 }

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
       2008-02-11 21:38:34 UTC (rev 7530)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
       2008-02-11 23:02:08 UTC (rev 7531)
@@ -19,13 +19,16 @@
  */
 package org.xwiki.plugin.activitystream.plugin;
 
-import org.xwiki.plugin.activitystream.api.ActivityStream;
-import org.xwiki.plugin.activitystream.api.ActivityStreamException;
+import org.xwiki.plugin.activitystream.api.*;
+import org.xwiki.plugin.activitystream.api.ActivityEvent;
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.api.Document;
 import com.xpn.xwiki.plugin.PluginApi;
 import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
 
 import java.util.List;
 import java.util.ArrayList;
@@ -162,4 +165,40 @@
         }
         return result;
     }
+
+    protected List unwrapEvents(List events) {
+            List result = new ArrayList();
+            if (events != null) {
+                for (Iterator iter = events.iterator(); iter.hasNext();) {
+                    Object obj = iter.next();
+                    org.xwiki.plugin.activitystream.plugin.ActivityEvent event 
= (org.xwiki.plugin.activitystream.plugin.ActivityEvent) obj;
+                    org.xwiki.plugin.activitystream.api.ActivityEvent 
unwrappedEvent = event.getEvent();
+                    result.add(unwrappedEvent);
+                }
+            }
+            return result;
+        }
+
+
+    public SyndEntry 
getFeedEntry(org.xwiki.plugin.activitystream.plugin.ActivityEvent event) {
+        return getActivityStream().getFeedEntry(event.getEvent(), context);
+    }
+
+    public SyndFeed getFeed(List events) {
+        return getActivityStream().getFeed(unwrapEvents(events), context);
+    }
+
+
+    public SyndFeed getFeed(List events, String author, String title, String 
description, String copyright, String encoding, String url) {
+        return getActivityStream().getFeed(unwrapEvents(events), author, 
title, description, copyright, encoding, url, context);
+    }
+
+    public String getFeedOutput(List events, String author, String title, 
String description, String copyright, String encoding, String url, String type) 
{
+        return getActivityStream().getFeedOutput(unwrapEvents(events), author, 
title, description, copyright, encoding, url, type, context);
+    }
+
+    public String getFeedOutput(SyndFeed feed, String type) {
+        return getActivityStream().getFeedOutput(feed, type);
+    }
+
 }

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to