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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jun 26 18:11:54 EDT 2007


Author: szimano
Date: 2007-06-26 18:11:54 -0400 (Tue, 26 Jun 2007)
New Revision: 12874

Added:
   labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/
   labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java
   labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
   labs/jbossforums/branches/forums101P26/thirdparty/jdom/
   labs/jbossforums/branches/forums101P26/thirdparty/jdom/lib/
   labs/jbossforums/branches/forums101P26/thirdparty/jdom/lib/jdom.jar
   labs/jbossforums/branches/forums101P26/thirdparty/rome/
   labs/jbossforums/branches/forums101P26/thirdparty/rome/lib/
   labs/jbossforums/branches/forums101P26/thirdparty/rome/lib/rome-0.9.jar
Modified:
   labs/jbossforums/branches/forums101P26/forums/build.xml
   labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java
   labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/WEB-INF/web.xml
   labs/jbossforums/branches/forums101P26/tools/etc/buildfragments/libraries.ent
Log:
feeds prototype

Modified: labs/jbossforums/branches/forums101P26/forums/build.xml
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/build.xml	2007-06-26 22:08:42 UTC (rev 12873)
+++ labs/jbossforums/branches/forums101P26/forums/build.xml	2007-06-26 22:11:54 UTC (rev 12874)
@@ -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 -->
@@ -205,6 +206,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 -->

Added: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java	                        (rev 0)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedConstants.java	2007-06-26 22:11:54 UTC (rev 12874)
@@ -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";
+}

Added: labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java	                        (rev 0)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/feeds/FeedsServlet.java	2007-06-26 22:11:54 UTC (rev 12874)
@@ -0,0 +1,271 @@
+package org.jboss.portlet.forums.feeds;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+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 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 != 6) {
+				response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+						WRONG_FEED_REQ);
+				return;
+			}
+
+			String type = uri[3];
+			String what = uri[4];
+			Integer id = Integer.valueOf(uri[5]);
+
+			log.info("Type = " + type + "  what = " + what + " id = " + id);
+
+			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)) {
+
+					} else {
+						response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+								WRONG_FEED_SHOW_TYPE + what);
+						return;
+					}
+				} catch (ModuleException e) {
+					e.printStackTrace();
+				}
+
+			} 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 createForumFeed(SyndFeed feed, Integer id)
+			throws ModuleException {
+
+		Forum forum = forumsModule.findForumById(id);
+
+		feed.setTitle("JBoss Forums Forum Feed: " + forum.getName());
+		feed.setLink("http://rome.dev.java.net");
+		feed.setDescription("Messages posted in forum " + forum.getName()
+				+ " in category " + forum.getCategory().getTitle());
+
+		List entries = new ArrayList();
+
+		List posts = new ArrayList();
+
+		for (int i = 0; i < forum.getTopics().size(); i++) {
+			Topic topic = (Topic) forum.getTopics().get(i);
+
+			posts.addAll(topic.getPosts());
+
+		}
+
+		sortPostList(posts);
+
+		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("http://rome.dev.java.net");
+		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();
+
+		sortPostList(posts);
+
+		for (int i = 0; i < posts.size(); i++) {
+			entries.add(getEntry((Post) posts.get(i)));
+		}
+
+		feed.setEntries(entries);
+
+	}
+
+	private void sortPostList(List posts) {
+		Collections.sort(posts, new Comparator() {
+
+			public int compare(Object o1, Object o2) {
+				Post p1 = (Post) o1;
+				Post p2 = (Post) o2;
+
+				return p1.getCreateDate().compareTo(p2.getCreateDate());
+			}
+
+		});
+	}
+
+	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");
+		feed.setLink("http://rome.dev.java.net");
+		feed
+				.setDescription("This feed has been created using ROME (Java syndication utilities");
+
+		List entries = new ArrayList();
+
+		feed.setEntries(entries);
+
+	}
+
+	private SyndEntry getEntry(Post post) {
+		SyndEntry entry;
+		SyndContent description;
+
+		entry = new SyndEntryImpl();
+		entry.setTitle(post.getMessage().getSubject() + " by "
+				+ post.getPoster().getUserId());
+		entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
+		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/forums101P26/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java	2007-06-26 22:08:42 UTC (rev 12873)
+++ labs/jbossforums/branches/forums101P26/forums/src/main/org/jboss/portlet/forums/properties/TCCLXProperties.java	2007-06-26 22:11:54 UTC (rev 12874)
@@ -82,7 +82,7 @@
       }
       finally
       {
-         Tools.safeClose(in);
+         in.close();
       }
    }
 

Modified: labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/WEB-INF/web.xml
===================================================================
--- labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/WEB-INF/web.xml	2007-06-26 22:08:42 UTC (rev 12873)
+++ labs/jbossforums/branches/forums101P26/forums/src/resources/portal-forums-war/WEB-INF/web.xml	2007-06-26 22:11:54 UTC (rev 12874)
@@ -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>
 
 

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


Property changes on: labs/jbossforums/branches/forums101P26/thirdparty/jdom/lib/jdom.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

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


Property changes on: labs/jbossforums/branches/forums101P26/thirdparty/rome/lib/rome-0.9.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossforums/branches/forums101P26/tools/etc/buildfragments/libraries.ent
===================================================================
--- labs/jbossforums/branches/forums101P26/tools/etc/buildfragments/libraries.ent	2007-06-26 22:08:42 UTC (rev 12873)
+++ labs/jbossforums/branches/forums101P26/tools/etc/buildfragments/libraries.ent	2007-06-26 22:11:54 UTC (rev 12874)
@@ -170,4 +170,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