[jboss-svn-commits] JBL Code SVN: r13183 - in labs/jbossforums/branches/forums101P22: forums/src/main/org/jboss/portlet/forums and 14 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jul 6 15:27:34 EDT 2007


Author: unibrew
Date: 2007-07-06 15:27:34 -0400 (Fri, 06 Jul 2007)
New Revision: 13183

Added:
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
   labs/jbossforums/branches/forums101P22/thirdparty/jdom/
   labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib/
   labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib/jdom.jar
   labs/jbossforums/branches/forums101P22/thirdparty/rome/
   labs/jbossforums/branches/forums101P22/thirdparty/rome/lib/
   labs/jbossforums/branches/forums101P22/thirdparty/rome/lib/rome-0.9.jar
Removed:
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
   labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib/
   labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib/jdom.jar
   labs/jbossforums/branches/forums101P22/thirdparty/rome/lib/
   labs/jbossforums/branches/forums101P22/thirdparty/rome/lib/rome-0.9.jar
Modified:
   labs/jbossforums/branches/forums101P22/forums/build.xml
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
   labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java
   labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-sar/conf/hibernate/setup.txt
   labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/WEB-INF/web.xml
   labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml
   labs/jbossforums/branches/forums101P22/tools/etc/buildfragments/libraries.ent
Log:
[JBFORUMS] Merging feeds to Forums for Portal 2.2.

Modified: labs/jbossforums/branches/forums101P22/forums/build.xml
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/build.xml	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/build.xml	2007-07-06 19:27:34 UTC (rev 13183)
@@ -80,7 +80,8 @@
 			<path refid="apache.myfaces.classpath"/>
 			<path refid="jboss.hibernate.classpath"/>
 			<path refid="jbportal.classpath"/>			
-	        <path refid="facelets.classpath"/>			
+	        <path refid="facelets.classpath"/>		
+		<path refid="rome.classpath"/>	
 		</path>
 
       <!-- Configure modules -->
@@ -206,6 +207,8 @@
       <jar jarfile="${build.lib}/portal-forums.sar">
 		 <fileset dir="${build.resources}/portal-forums-sar" includes="**/*"/>
          <fileset dir="${jakarta.fileupload.root}/lib" includes="commons-fileupload.jar"/>
+      	 <fileset dir="${rome.lib}" includes="rome-0.9.jar" />
+      	 <fileset dir="${jdom.lib}" includes="jdom.jar" />
       </jar>
 
       <!-- portal-forums.ear -->

Modified: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ForumsModule.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -575,6 +575,16 @@
    
    List findTopicWatchedByUser(User user,Date date) throws ModuleException;
    
+   List findPostsFromForumAsc(Forum forum, int limit) throws ModuleException;
+   
+   List findPostsFromForumDesc(Forum forum, int limit) throws ModuleException;
+   
+   List findPostsFromCategoryAsc(Category category, int limit)
+        throws ModuleException;
+   
+   List findPostsFromCategoryDesc(Category category, int limit)
+        throws ModuleException;
+   
    Map findTopicWatches(User user) throws ModuleException;
    
    Attachment findFindAttachmentById(Integer attachID)
@@ -638,5 +648,17 @@
     *
     */
    public void processNotifications (Integer postId, int watchType , String postUrl , String replyUrl );
+   
+   /**
+    * 
+    * @return
+    */
+   public List findPostsDesc(int limit) throws ModuleException;
+   
+   /**
+    * 
+    * @return
+    */
+   public List findPostsAsc(int limit) throws ModuleException;
 
 }
\ No newline at end of file

Copied: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds (from rev 13180, labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds)

Deleted: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java	2007-07-06 18:43:31 UTC (rev 13180)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -1,15 +0,0 @@
-package org.jboss.portlet.forums.feeds;
-
-public class FeedConstants {
-	public final static String CATEGORY = "category";
-	
-	public final static String TOPIC = "topic";
-	
-	public final static String GLOBAL = "global";
-	
-	public final static String FORUM = "forum";
-	
-	public static final String RSS = "rss";
-	
-	public static final String ATOM = "atom";
-}

Copied: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java (from rev 13180, labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java)
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java	                        (rev 0)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -0,0 +1,15 @@
+package org.jboss.portlet.forums.feeds;
+
+public class FeedConstants {
+	public final static String CATEGORY = "category";
+	
+	public final static String TOPIC = "topic";
+	
+	public final static String GLOBAL = "global";
+	
+	public final static String FORUM = "forum";
+	
+	public static final String RSS = "rss";
+	
+	public static final String ATOM = "atom";
+}

Deleted: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java	2007-07-06 18:43:31 UTC (rev 13180)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -1,276 +0,0 @@
-package org.jboss.portlet.forums.feeds;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.transaction.TransactionManager;
-
-import org.apache.log4j.Logger;
-import org.hibernate.TransactionException;
-import org.jboss.portal.common.transaction.TransactionManagerProvider;
-import org.jboss.portal.common.transaction.Transactions;
-import org.jboss.portal.core.modules.ModuleException;
-import org.jboss.portlet.forums.ForumsModule;
-import org.jboss.portlet.forums.model.Category;
-import org.jboss.portlet.forums.model.Forum;
-import org.jboss.portlet.forums.model.Post;
-import org.jboss.portlet.forums.model.Topic;
-import org.jboss.portlet.forums.ui.PortalUtil;
-
-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.SyndEntryImpl;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.feed.synd.SyndFeedImpl;
-import com.sun.syndication.io.SyndFeedOutput;
-
-/**
- * Servlet used for showing RSS entries
- * 
- * @author tomaszszymanski
- * 
- */
-public class FeedsServlet extends HttpServlet {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-
-	private ForumsModule forumsModule;
-
-	private static final Logger log = Logger.getLogger(FeedsServlet.class);
-
-	private static final String WRONG_FEED_TYPE = "Wrong feed type: ";
-
-	private static final String WRONG_FEED_REQ = "Wrong feed request";
-
-	private static final String WRONG_FEED_SHOW_TYPE = "Wrong feed forum type: ";
-
-	private static final int POST_LIMIT = 20;
-
-	private TransactionManager tm;
-
-	public void init() {
-		try {
-			forumsModule = (ForumsModule) new InitialContext()
-					.lookup("java:portal/ForumsModule");
-		} catch (NamingException e) {
-			log.error(e);
-		}
-	}
-
-	protected void doGet(HttpServletRequest request,
-			HttpServletResponse response) throws ServletException, IOException {
-		try {
-			String[] uri = request.getRequestURI().split("/");
-
-			if (uri.length < 5
-					|| (uri[4].equals(FeedConstants.GLOBAL) && uri.length != 5)
-					|| (!uri[4].equals(FeedConstants.GLOBAL) && uri.length != 6)) {
-				response.sendError(HttpServletResponse.SC_BAD_REQUEST,
-						WRONG_FEED_REQ);
-				return;
-			}
-
-			String type = uri[3];
-			String what = uri[4];
-
-			Integer id = null;
-
-			if (!what.equals(FeedConstants.GLOBAL))
-				id = Integer.valueOf(uri[5]);
-
-			SyndFeed feed = new SyndFeedImpl();
-
-			if (!setFeedType(feed, type)) {
-				response.sendError(HttpServletResponse.SC_BAD_REQUEST,
-						WRONG_FEED_TYPE + type);
-				return;
-			}
-
-			if (tm == null) {
-				try {
-					tm = TransactionManagerProvider.JBOSS_PROVIDER
-							.getTransactionManager();
-				} catch (Exception e) {
-					System.out
-							.println("Obtaining TransactionManagerProvider Problem....");
-				}
-			}
-
-			javax.transaction.Transaction oldTx = null;
-			try {
-				oldTx = Transactions
-						.applyBefore(Transactions.TYPE_REQUIRED, tm);
-				try {
-					if (what.equals(FeedConstants.CATEGORY)) {
-						createCategoryFeed(feed, id);
-					} else if (what.equals(FeedConstants.FORUM)) {
-						createForumFeed(feed, id);
-					} else if (what.equals(FeedConstants.TOPIC)) {
-						createTopicFeed(feed, id);
-					} else if (what.equals(FeedConstants.GLOBAL)) {
-						createGlobalFeed(feed, id);
-					} else {
-						response.sendError(HttpServletResponse.SC_BAD_REQUEST,
-								WRONG_FEED_SHOW_TYPE + what);
-						return;
-					}
-				} catch (ModuleException e) {
-					response.sendError(
-							HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e
-									.getMessage());
-					return;
-				}
-
-			} catch (TransactionException e) {
-				System.out.println("JTA problem...");
-			} finally {
-				try {
-					Transactions.applyAfter(Transactions.TYPE_REQUIRED, tm,
-							oldTx);
-
-				} catch (TransactionException e) {
-					// log.error("", e);
-				}
-			}
-			response.setContentType("text/xml");
-
-			Writer writer = response.getWriter();
-
-			SyndFeedOutput output = new SyndFeedOutput();
-			output.output(feed, writer);
-
-			writer.flush();
-
-		} catch (Exception e) {
-			throw new ServletException(e);
-		}
-
-	}
-
-	private void createGlobalFeed(SyndFeed feed, Integer id)
-			throws ModuleException {
-		feed.setTitle("JBoss Forums Global Feed");
-		feed.setLink(PortalUtil.globalLink());
-		feed.setDescription("Messages posted in JBoss Forums");
-
-		List entries = new ArrayList();
-
-		List posts = forumsModule.findPostsDesc(POST_LIMIT);
-
-		for (int i = 0; i < posts.size(); i++) {
-			entries.add(getEntry((Post) posts.get(i)));
-		}
-
-		feed.setEntries(entries);
-	}
-
-	private void createForumFeed(SyndFeed feed, Integer id)
-			throws ModuleException {
-
-		Forum forum = forumsModule.findForumById(id);
-
-		feed.setTitle("JBoss Forums Forum Feed: " + forum.getName());
-		feed.setLink(PortalUtil.categoryLink(id.toString()));
-		feed.setDescription("Messages posted in forum " + forum.getName()
-				+ " in category " + forum.getCategory().getTitle());
-
-		List entries = new ArrayList();
-
-		List posts = forumsModule.findPostsFromForumDesc(forum, POST_LIMIT);
-
-		for (int i = 0; i < posts.size(); i++) {
-			entries.add(getEntry((Post) posts.get(i)));
-		}
-
-		feed.setEntries(entries);
-
-	}
-
-	private void createTopicFeed(SyndFeed feed, Integer id)
-			throws ModuleException {
-
-		Topic topic = forumsModule.findTopicById(id);
-
-		feed.setTitle("JBoss Forums Topic Feed: " + topic.getSubject());
-		feed.setLink(PortalUtil.topicLink(id.toString()));
-		feed.setDescription("Messages posted in topic " + topic.getSubject()
-				+ " in forum " + topic.getForum().getName() + " in category "
-				+ topic.getForum().getCategory().getTitle());
-
-		List entries = new ArrayList();
-
-		List posts = topic.getPosts();
-
-		for (int i = 0; i < posts.size(); i++) {
-			entries.add(getEntry((Post) posts.get(i)));
-		}
-
-		feed.setEntries(entries);
-
-	}
-
-	private boolean setFeedType(SyndFeed feed, String type) {
-		if (type.equals(FeedConstants.RSS)) {
-			feed.setFeedType("rss_2.0");
-		} else if (type.equals(FeedConstants.ATOM)) {
-			feed.setFeedType("atom_0.3");
-		} else {
-			return false;
-		}
-		return true;
-	}
-
-	private void createCategoryFeed(SyndFeed feed, Integer id)
-			throws ModuleException {
-
-		Category category = forumsModule.findCategoryById(id);
-
-		feed.setTitle("JBoss Forums Category Feed: " + category.getTitle());
-		feed.setLink(PortalUtil.categoryLink(id.toString()));
-		feed.setDescription("Messages posted in category "
-				+ category.getTitle());
-
-		List entries = new ArrayList();
-
-		List posts = forumsModule.findPostsFromCategoryDesc(category,
-				POST_LIMIT);
-
-		for (int i = 0; i < posts.size(); i++) {
-			entries.add(getEntry((Post) posts.get(i)));
-		}
-
-		feed.setEntries(entries);
-
-	}
-
-	private SyndEntry getEntry(Post post) {
-		SyndEntry entry;
-		SyndContent description;
-
-		entry = new SyndEntryImpl();
-		entry.setTitle(post.getMessage().getSubject() + " by "
-				+ post.getPoster().getUser().getUserName());
-		entry.setLink(PortalUtil.postLink(post.getId().toString()));
-		entry.setPublishedDate(post.getCreateDate());
-		description = new SyndContentImpl();
-		description.setType("text/html");
-		description.setValue(PortalUtil.formatMessage(post.getMessage()
-				.getText(), post.getMessage().getHTMLEnabled()));
-		entry.setDescription(description);
-
-		return entry;
-	}
-
-}

Copied: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java (from rev 13180, labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java)
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java	                        (rev 0)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -0,0 +1,276 @@
+package org.jboss.portlet.forums.feeds;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.transaction.TransactionManager;
+
+import org.apache.log4j.Logger;
+import org.hibernate.TransactionException;
+import org.jboss.portal.common.transaction.TransactionManagerProvider;
+import org.jboss.portal.common.transaction.Transactions;
+import org.jboss.portal.core.modules.ModuleException;
+import org.jboss.portlet.forums.ForumsModule;
+import org.jboss.portlet.forums.model.Category;
+import org.jboss.portlet.forums.model.Forum;
+import org.jboss.portlet.forums.model.Post;
+import org.jboss.portlet.forums.model.Topic;
+import org.jboss.portlet.forums.ui.PortalUtil;
+
+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.SyndEntryImpl;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
+import com.sun.syndication.io.SyndFeedOutput;
+
+/**
+ * Servlet used for showing RSS entries
+ * 
+ * @author tomaszszymanski
+ * 
+ */
+public class FeedsServlet extends HttpServlet {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private ForumsModule forumsModule;
+
+	private static final Logger log = Logger.getLogger(FeedsServlet.class);
+
+	private static final String WRONG_FEED_TYPE = "Wrong feed type: ";
+
+	private static final String WRONG_FEED_REQ = "Wrong feed request";
+
+	private static final String WRONG_FEED_SHOW_TYPE = "Wrong feed forum type: ";
+
+	private static final int POST_LIMIT = 20;
+
+	private TransactionManager tm;
+
+	public void init() {
+		try {
+			forumsModule = (ForumsModule) new InitialContext()
+					.lookup("java:portal/ForumsModule");
+		} catch (NamingException e) {
+			log.error(e);
+		}
+	}
+
+	protected void doGet(HttpServletRequest request,
+			HttpServletResponse response) throws ServletException, IOException {
+		try {
+			String[] uri = request.getRequestURI().split("/");
+
+			if (uri.length < 5
+					|| (uri[4].equals(FeedConstants.GLOBAL) && uri.length != 5)
+					|| (!uri[4].equals(FeedConstants.GLOBAL) && uri.length != 6)) {
+				response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+						WRONG_FEED_REQ);
+				return;
+			}
+
+			String type = uri[3];
+			String what = uri[4];
+
+			Integer id = null;
+
+			if (!what.equals(FeedConstants.GLOBAL))
+				id = Integer.valueOf(uri[5]);
+
+			SyndFeed feed = new SyndFeedImpl();
+
+			if (!setFeedType(feed, type)) {
+				response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+						WRONG_FEED_TYPE + type);
+				return;
+			}
+
+			if (tm == null) {
+				try {
+					tm = TransactionManagerProvider.JBOSS_PROVIDER
+							.getTransactionManager();
+				} catch (Exception e) {
+					System.out
+							.println("Obtaining TransactionManagerProvider Problem....");
+				}
+			}
+
+			javax.transaction.Transaction oldTx = null;
+			try {
+				oldTx = Transactions
+						.applyBefore(Transactions.TYPE_REQUIRED, tm);
+				try {
+					if (what.equals(FeedConstants.CATEGORY)) {
+						createCategoryFeed(feed, id);
+					} else if (what.equals(FeedConstants.FORUM)) {
+						createForumFeed(feed, id);
+					} else if (what.equals(FeedConstants.TOPIC)) {
+						createTopicFeed(feed, id);
+					} else if (what.equals(FeedConstants.GLOBAL)) {
+						createGlobalFeed(feed, id);
+					} else {
+						response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+								WRONG_FEED_SHOW_TYPE + what);
+						return;
+					}
+				} catch (ModuleException e) {
+					response.sendError(
+							HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e
+									.getMessage());
+					return;
+				}
+
+			} catch (TransactionException e) {
+				System.out.println("JTA problem...");
+			} finally {
+				try {
+					Transactions.applyAfter(Transactions.TYPE_REQUIRED, tm,
+							oldTx);
+
+				} catch (TransactionException e) {
+					// log.error("", e);
+				}
+			}
+			response.setContentType("text/xml");
+
+			Writer writer = response.getWriter();
+
+			SyndFeedOutput output = new SyndFeedOutput();
+			output.output(feed, writer);
+
+			writer.flush();
+
+		} catch (Exception e) {
+			throw new ServletException(e);
+		}
+
+	}
+
+	private void createGlobalFeed(SyndFeed feed, Integer id)
+			throws ModuleException {
+		feed.setTitle("JBoss Forums Global Feed");
+		feed.setLink(PortalUtil.globalLink());
+		feed.setDescription("Messages posted in JBoss Forums");
+
+		List entries = new ArrayList();
+
+		List posts = forumsModule.findPostsDesc(POST_LIMIT);
+
+		for (int i = 0; i < posts.size(); i++) {
+			entries.add(getEntry((Post) posts.get(i)));
+		}
+
+		feed.setEntries(entries);
+	}
+
+	private void createForumFeed(SyndFeed feed, Integer id)
+			throws ModuleException {
+
+		Forum forum = forumsModule.findForumById(id);
+
+		feed.setTitle("JBoss Forums Forum Feed: " + forum.getName());
+		feed.setLink(PortalUtil.categoryLink(id.toString()));
+		feed.setDescription("Messages posted in forum " + forum.getName()
+				+ " in category " + forum.getCategory().getTitle());
+
+		List entries = new ArrayList();
+
+		List posts = forumsModule.findPostsFromForumDesc(forum, POST_LIMIT);
+
+		for (int i = 0; i < posts.size(); i++) {
+			entries.add(getEntry((Post) posts.get(i)));
+		}
+
+		feed.setEntries(entries);
+
+	}
+
+	private void createTopicFeed(SyndFeed feed, Integer id)
+			throws ModuleException {
+
+		Topic topic = forumsModule.findTopicById(id);
+
+		feed.setTitle("JBoss Forums Topic Feed: " + topic.getSubject());
+		feed.setLink(PortalUtil.topicLink(id.toString()));
+		feed.setDescription("Messages posted in topic " + topic.getSubject()
+				+ " in forum " + topic.getForum().getName() + " in category "
+				+ topic.getForum().getCategory().getTitle());
+
+		List entries = new ArrayList();
+
+		List posts = topic.getPosts();
+
+		for (int i = 0; i < posts.size(); i++) {
+			entries.add(getEntry((Post) posts.get(i)));
+		}
+
+		feed.setEntries(entries);
+
+	}
+
+	private boolean setFeedType(SyndFeed feed, String type) {
+		if (type.equals(FeedConstants.RSS)) {
+			feed.setFeedType("rss_2.0");
+		} else if (type.equals(FeedConstants.ATOM)) {
+			feed.setFeedType("atom_0.3");
+		} else {
+			return false;
+		}
+		return true;
+	}
+
+	private void createCategoryFeed(SyndFeed feed, Integer id)
+			throws ModuleException {
+
+		Category category = forumsModule.findCategoryById(id);
+
+		feed.setTitle("JBoss Forums Category Feed: " + category.getTitle());
+		feed.setLink(PortalUtil.categoryLink(id.toString()));
+		feed.setDescription("Messages posted in category "
+				+ category.getTitle());
+
+		List entries = new ArrayList();
+
+		List posts = forumsModule.findPostsFromCategoryDesc(category,
+				POST_LIMIT);
+
+		for (int i = 0; i < posts.size(); i++) {
+			entries.add(getEntry((Post) posts.get(i)));
+		}
+
+		feed.setEntries(entries);
+
+	}
+
+	private SyndEntry getEntry(Post post) {
+		SyndEntry entry;
+		SyndContent description;
+
+		entry = new SyndEntryImpl();
+		entry.setTitle(post.getMessage().getSubject() + " by "
+				+ post.getPoster().getUser().getUserName());
+		entry.setLink(PortalUtil.postLink(post.getId().toString()));
+		entry.setPublishedDate(post.getCreateDate());
+		description = new SyndContentImpl();
+		description.setType("text/html");
+		description.setValue(PortalUtil.formatMessage(post.getMessage()
+				.getText(), post.getMessage().getHTMLEnabled()));
+		entry.setDescription(description);
+
+		return entry;
+	}
+
+}

Modified: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -1585,6 +1585,118 @@
        }
     }
 
+    private List findPostsFromForum(Forum forum, int limit, String order)
+            throws ModuleException
+    {
+        try
+        {
+            Session session = getSession();
+            Query query = session
+            .createQuery("select p from TopicImpl as t join t.posts as p where t.forum.id = :forumId order by p.createDate "
+                    + order);
+
+            query.setString("forumId", forum.getId().toString());
+
+            query.setFirstResult(0);
+
+            if (limit != 0)
+            {
+                query.setMaxResults(limit);
+            }
+            return query.list();
+        } catch (HibernateException e)
+        {
+            String message = "Cannot find posts";
+            log.error(message, e);
+            throw new ModuleException(message, e);
+        }
+    }
+
+    public List findPostsFromForumAsc(Forum forum, int limit)
+            throws ModuleException
+    {
+        return findPostsFromForum(forum, limit, "asc");
+    }
+
+    public List findPostsFromForumDesc(Forum forum, int limit)
+            throws ModuleException
+    {
+        return findPostsFromForum(forum, limit, "desc");
+    }
+
+    private List findPostsFromCategory(Category category, int limit,
+            String order) throws ModuleException
+            {
+        try
+        {
+            Session session = getSession();
+            Query query = session
+            .createQuery("select p from ForumImpl as f join f.topics as t join t.posts as p where f.category.id = :categoryId order by p.createDate "
+                    + order);
+
+            query.setString("categoryId", category.getId().toString());
+
+            query.setFirstResult(0);
+
+            if (limit != 0)
+            {
+                query.setMaxResults(limit);
+            }
+            return query.list();
+        } catch (HibernateException e)
+        {
+            String message = "Cannot find posts";
+            log.error(message, e);
+            throw new ModuleException(message, e);
+        }
+            }
+
+    public List findPostsFromCategoryAsc(Category category, int limit)
+            throws ModuleException
+    {
+        return findPostsFromCategory(category, limit, "asc");
+    }
+
+    public List findPostsFromCategoryDesc(Category category, int limit)
+            throws ModuleException
+    {
+        return findPostsFromCategory(category, limit, "desc");
+    }
+
+    private List findPosts(int limit, String order) throws ModuleException
+    {
+        try
+        {
+            Session session = getSession();
+            Query query = session
+            .createQuery("select p from PostImpl as p order by p.createDate "
+                    + order);
+
+            query.setFirstResult(0);
+
+            if (limit != 0)
+            {
+                query.setMaxResults(limit);
+            }
+            return query.list();
+        } catch (HibernateException e)
+        {
+            String message = "Cannot find posts";
+            log.error(message, e);
+            throw new ModuleException(message, e);
+        }
+    }
+
+    public List findPostsAsc(int limit) throws ModuleException
+    {
+        return findPosts(limit, "asc");
+    }
+
+    public List findPostsDesc(int limit) throws ModuleException
+    {
+        return findPosts(limit, "desc");
+    }
+    
    public List findForumWatchByUser(User user) throws ModuleException
    {
       try
@@ -1920,4 +2032,5 @@
    protected Session getSession () {
        return factory.getCurrentSession();
    }
-}
\ No newline at end of file
+}
+

Modified: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -82,7 +82,7 @@
       }
       finally
       {
-         Tools.safeClose(in);
+         in.close();
       }
    }
 

Modified: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -55,6 +55,7 @@
 import org.jboss.portal.core.model.PropertyMap;
 import org.jboss.portal.core.model.User;
 import org.jboss.portlet.forums.ForumsConstants;
+import org.jboss.portlet.forums.feeds.FeedConstants;
 import org.jboss.portlet.forums.helper.TempFileBinding;
 import org.jboss.portlet.forums.impl.MessageImpl;
 import org.jboss.portlet.forums.impl.PollImpl;
@@ -336,7 +337,70 @@
             return null;
         }
     }
-
+    
+    /**
+     * 
+     */
+    public static String globalLink()
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        BaseController bc = (BaseController) fc.getApplication().
+                                getVariableResolver().
+                                resolveVariable(fc,"shared");
+        return outputLink(bc.getLinks().get("category").toString(),true);
+    }
+    
+    /**
+     * 
+     */
+    public static String categoryLink(String categoryId)
+    {        
+        FacesContext fc = FacesContext.getCurrentInstance();
+        BaseController bc = (BaseController) fc.getApplication().
+                                getVariableResolver().
+                                resolveVariable(fc,"shared");
+        return outputLink(bc.getLinks().get("category").toString(),true) +"&"+ Constants.p_categoryId + "=" + categoryId;
+    }
+    
+    /**
+     * 
+     */
+    public static String forumLink(String forumId)
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        BaseController bc = (BaseController) fc.getApplication().
+                                getVariableResolver().
+                                resolveVariable(fc,"shared");
+        return outputLink(bc.getLinks().get("forum").toString(),true) +"&"+ Constants.p_forumId + "=" + forumId;
+    }
+    
+    /**
+     * 
+     */
+    public static String postLink(String postId)
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        BaseController bc = (BaseController) fc.getApplication().
+                                getVariableResolver().
+                                resolveVariable(fc,"shared");
+        return outputLink(bc.getLinks().get("topic").toString(),true) +"&"+ Constants.p_postId + "=" + postId + "#"+ postId;
+    }
+    
+    /**
+     * 
+     */
+    public static String topicLink(String topicId)
+    {
+        FacesContext fc = FacesContext.getCurrentInstance();
+        BaseController bc = (BaseController) fc.getApplication().
+                                getVariableResolver().
+                                resolveVariable(fc,"shared");
+        return outputLink(bc.getLinks().get("topic").toString(),true) +"&"+ Constants.p_topicId + "=" + topicId;
+    }
+    
+    /**
+     * 
+     */
     public static String postPermlink(String postId)
     {
 
@@ -371,10 +435,40 @@
 
         return url;
     }
-
+    
     /**
+     * Creates feed link.
      * 
+     * @param type
+     *            RSS/Atom. See FeedConstants
+     * @param what
+     *            Kind of the link. See available kinds in FeedConstants
+     * @param id
+     *            Id - for kind FeedCostants.GLOBAL is ignored
+     * @return String with proper address
+     */
+    public static String createFeedLink(String type, String what, Integer id)
+    {
+        Object rreq = FacesContext.getCurrentInstance().getExternalContext()
+                               .getRequest();
+        
+        if (rreq instanceof RenderRequest)
+        {
+            RenderRequest req = (RenderRequest) rreq;
+            return req.getContextPath()
+                   + "/feeds/"
+                   + type
+                   + "/"
+                   + what
+                   + (FeedConstants.GLOBAL.equals(what) ? "" : "/"
+                   + id.toString());
+        }
+        return null;
+    }
+    
+    /**
      * 
+     * 
      */
     public static void executeNotifications()
     {

Modified: labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/main/org/jboss/portlet/forums/ui/view/ViewForum.java	2007-07-06 19:27:34 UTC (rev 13183)
@@ -391,5 +391,18 @@
              }
          }
      }
+     
+     public String getRssFeed()
+     {
+        return PortalUtil.createFeedLink(FeedConstants.RSS,
+                          FeedConstants.FORUM, forum.getId());
+     }
+     
+     public String getAtomFeed()
+     {
+        return PortalUtil.createFeedLink(FeedConstants.ATOM,
+                          FeedConstants.FORUM, forum.getId());
+     }
+     
     //-------------------------------------------------------------------------------------------------------------------------------------    
 }

Modified: labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-sar/conf/hibernate/setup.txt
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-sar/conf/hibernate/setup.txt	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-sar/conf/hibernate/setup.txt	2007-07-06 19:27:34 UTC (rev 13183)
@@ -55,5 +55,5 @@
 }
 finally
 {
-   Tools.safeClose(session);
+   session.close();
 }

Modified: labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/WEB-INF/web.xml
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/WEB-INF/web.xml	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/WEB-INF/web.xml	2007-07-06 19:27:34 UTC (rev 13183)
@@ -176,8 +176,19 @@
    </login-config>
    <security-role>
       <role-name>Authenticated</role-name>
-   </security-role>
-
+   </security-role>
+   
+   <!-- RSS Servlet -->
+	<servlet>
+		<servlet-name>FeedsServlet</servlet-name>
+		<servlet-class>org.jboss.portlet.forums.feeds.FeedsServlet</servlet-class>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	
+	<servlet-mapping>
+		<servlet-name>FeedsServlet</servlet-name>
+		<url-pattern>/feeds/*</url-pattern>
+	</servlet-mapping>
 </web-app>
 
 

Modified: labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml	2007-07-06 19:27:34 UTC (rev 13183)
@@ -108,6 +108,11 @@
         </h4>
     </div>
     
+    <!--  feeds -->
+    
+    <a href="#{forum.rssFeed}">RSS</a>
+    <a href="#{forum.atomFeed}">ATOM</a>
+    
     <!-- PAGINATION -->
     <c:if test="#{forum.pageNavigator.totalPages gt 1}">
     <div class="forumpagination">

Copied: labs/jbossforums/branches/forums101P22/thirdparty/jdom (from rev 13180, labs/jbossforums/branches/forums101P26/thirdparty/jdom)

Copied: labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib (from rev 13180, labs/jbossforums/branches/forums101P26/thirdparty/jdom/lib)

Deleted: labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib/jdom.jar
===================================================================
(Binary files differ)

Copied: labs/jbossforums/branches/forums101P22/thirdparty/jdom/lib/jdom.jar (from rev 13180, labs/jbossforums/branches/forums101P26/thirdparty/jdom/lib/jdom.jar)
===================================================================
(Binary files differ)

Copied: labs/jbossforums/branches/forums101P22/thirdparty/rome (from rev 13180, labs/jbossforums/branches/forums101P26/thirdparty/rome)

Copied: labs/jbossforums/branches/forums101P22/thirdparty/rome/lib (from rev 13180, labs/jbossforums/branches/forums101P26/thirdparty/rome/lib)

Deleted: labs/jbossforums/branches/forums101P22/thirdparty/rome/lib/rome-0.9.jar
===================================================================
(Binary files differ)

Copied: labs/jbossforums/branches/forums101P22/thirdparty/rome/lib/rome-0.9.jar (from rev 13180, labs/jbossforums/branches/forums101P26/thirdparty/rome/lib/rome-0.9.jar)
===================================================================
(Binary files differ)

Modified: labs/jbossforums/branches/forums101P22/tools/etc/buildfragments/libraries.ent
===================================================================
--- labs/jbossforums/branches/forums101P22/tools/etc/buildfragments/libraries.ent	2007-07-06 19:23:21 UTC (rev 13182)
+++ labs/jbossforums/branches/forums101P22/tools/etc/buildfragments/libraries.ent	2007-07-06 19:27:34 UTC (rev 13183)
@@ -166,4 +166,17 @@
     <filelist dir="${jakarta-commons-jexl.lib}" files="commons-jexl-1.0.jar"/>
   </path>
   
+  <!-- Rome -->
+  <property name="rome.root" value="${project.thirdparty}/rome"/>
+  <property name="rome.lib" value="${rome.root}/lib"/>
+  <path id="rome.classpath">
+    <filelist dir="${rome.lib}" files="rome-0.9.jar"/>
+  </path>
+
+  <!-- JDOM -->
+  <property name="jdom.root" value="${project.thirdparty}/jdom"/>
+  <property name="jdom.lib" value="${jdom.root}/lib"/>
+  <path id="jdom.classpath">
+    <filelist dir="${jdom.lib}" files="jdom.jar"/>
+  </path>
 </target>




More information about the jboss-svn-commits mailing list