[jboss-svn-commits] JBL Code SVN: r11199 - labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Apr 21 18:39:59 EDT 2007
Author: dejp
Date: 2007-04-21 18:39:58 -0400 (Sat, 21 Apr 2007)
New Revision: 11199
Modified:
labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/Constants.java
labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/DevForumEntriesPortlet.java
labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumEntriesPortlet.java
labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumsTools.java
labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/UserForumEntriesPortlet.java
Log:
JBLAB-848
Modified: labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/Constants.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/Constants.java 2007-04-21 22:36:10 UTC (rev 11198)
+++ labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/Constants.java 2007-04-21 22:39:58 UTC (rev 11199)
@@ -14,4 +14,10 @@
public static final String PROJECT_ID_NOT_SELECTED = "notSelected";
+ public static final String FORUMS_PAGE_NAME = "forums";
+
+ public static final String DATE_PATTERN = "EEEEE, MMM d, yyyy 'at' hh:mm aaa";
+
+ public static final String DATE_PATTERN2 = "EEE, MMM d, yyyy hh:mm aaa";
+
}
Modified: labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/DevForumEntriesPortlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/DevForumEntriesPortlet.java 2007-04-21 22:36:10 UTC (rev 11198)
+++ labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/DevForumEntriesPortlet.java 2007-04-21 22:39:58 UTC (rev 11199)
@@ -22,16 +22,20 @@
response.setContentType("text/html");
String portalName = ForgeHelper.getPortalName(request);
- //String serverAdress = ForgeHelper.getBaseServerAddress(request);
String jspPath = ForumsTools.getDevForumsEntriesJspCmPath();
+ String projectId = ProjectsHelper.getSelectedProjectId(request);
+
+ DelegateContext context = null;
+
Object forumIdObj = request.getPreferences().getValue("forumId", null);
- String forumId = (String) forumIdObj;
-
- String projectId = ProjectsHelper.getSelectedProjectId(request);
-
- DelegateContext context = ForumsTools.getLatestDevForumPostsCtx(forumId, projectId, response);
+ if (forumIdObj != null) {
+ String forumId = (String) forumIdObj;
+ context = ForumsTools.getLatestDevForumPostsCtx(forumId, projectId);
+ } else {
+ context = ForumsTools.getLatestDevForumPostsCtx();
+ }
request.setAttribute(PortalJsp.CTX_REQUEST, context);
Modified: labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumEntriesPortlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumEntriesPortlet.java 2007-04-21 22:36:10 UTC (rev 11198)
+++ labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumEntriesPortlet.java 2007-04-21 22:39:58 UTC (rev 11199)
@@ -31,9 +31,9 @@
DelegateContext context = null;
if (projectId == null || projectId.equals(Constants.PROJECT_ID_NOT_SELECTED)) {
- context = ForumsTools.getLatestForumPostsCtx(response);
+ context = ForumsTools.getLatestForumPostsCtx();
} else {
- context = ForumsTools.getProjectLatestForumPostsCtx(projectId, response);
+ context = ForumsTools.getProjectLatestForumPostsCtx(projectId);
}
request.setAttribute(PortalJsp.CTX_REQUEST, context);
Modified: labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumsTools.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumsTools.java 2007-04-21 22:36:10 UTC (rev 11198)
+++ labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/ForumsTools.java 2007-04-21 22:39:58 UTC (rev 11199)
@@ -5,21 +5,18 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
-
+import java.util.Random;
import javax.naming.InitialContext;
-
import org.jboss.forge.common.ejb3.LabsServices;
import org.jboss.forge.common.ejb3.ProjectsService;
import org.jboss.forge.common.projects.project.Project;
import org.jboss.logging.Logger;
+import org.jboss.portal.core.modules.ModuleException;
import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
import org.jboss.portal.identity.User;
-import org.jboss.portlet.JBossRenderResponse;
import org.jboss.portlet.forums.ForumsModule;
import org.jboss.portlet.forums.model.Forum;
import org.jboss.portlet.forums.model.Message;
@@ -43,47 +40,9 @@
return Constants.FORUMS_DIR + File.separator + Constants.USER_FORUM_ENTRIES_JSP;
}
- private static final String DATE_PATTERN = "EEEEE, MMM d, yyyy 'at' hh:mm aaa";
- private static final String DATE_PATTERN2 = "EEE, MMM d, yyyy hh:mm aaa";
-
private static final int NUMBER_OF_DISPLAYED_POSTS = 3;
- public static final String ERROR_PARAMETER_NAME = "error";
-
- private static ForumsModule getForumModule() {
- ForumsModule forumsModule = null;
- try {
- InitialContext initialContext = new InitialContext();
-
- Object obj = initialContext.lookup("java:portal/ForumsModule");
-
- forumsModule = (ForumsModule) obj;
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return forumsModule;
- }
-
- public static List<Project> getProjects() {
- List<Project> projectsList = new ArrayList<Project>();
-
- try {
- ProjectsService projectsService = LabsServices.getProjectsService();
- Collection<? extends Project> projects = projectsService.getProjects();
- for (Project project : projects) {
- if (!project.getId().equals("default")) {
- projectsList.add(project);
- }
- }
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- }
-
- return projectsList;
- }
-
- public static DelegateContext getLatestForumPostsCtx(JBossRenderResponse response) {
+ public static DelegateContext getLatestForumPostsCtx() {
DelegateContext ctx = new DelegateContext();
DelegateContext projectsCtx = ctx.next("projects");
@@ -97,54 +56,41 @@
DelegateContext postsCtx = ctx.next("posts");
try {
- Map lastForumPosts = forumsModule.findLastPostsOfForums();
+ Map lastestForumPostsMap = forumsModule.findLastPostsOfForums();
- if (lastForumPosts.isEmpty()) {
- postsCtx.put("message", "There are not any entries.");
- }
-
- int counter = 0;
- for (Object topic : lastForumPosts.keySet()) {
+ if (!lastestForumPostsMap.isEmpty()) {
+ List<Post> latestPosts = new ArrayList<Post>();
- if (counter == NUMBER_OF_DISPLAYED_POSTS) {
- break;
+ for (Object postObj : lastestForumPostsMap.values()) {
+ Post post = (Post) postObj;
+ latestPosts.add(post);
}
- Post post = (Post) lastForumPosts.get(topic);
+ int postsNumber = 0;
+ Random random = new Random();
- if (post != null) {
+ while (postsNumber++ < NUMBER_OF_DISPLAYED_POSTS && latestPosts.size() > 0) {
+ int item = (int)(latestPosts.size() * random.nextFloat());
+
+ Post post = latestPosts.remove(item);
+
DelegateContext postCtx = postsCtx.next("post");
- Message message = post.getMessage();
- if (message != null) {
- postCtx.put("subject", message.getSubject());
-
- postCtx.put("address", prepareForumPostLink(forumsModule.findTopicById((Integer) topic), post));
-
- SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN2, Locale.US);
- postCtx.put("date", getPostCreateDate(post, formatter));
-
- Poster poster = post.getPoster();
- if (poster != null) {
- User user = poster.getUser();
- postCtx.put("userId", user.getUserName());
- }
- }
-
- counter++;
+ preparePostCtx(post, postCtx, Constants.DATE_PATTERN2);
}
-
+ } else {
+ postsCtx.put("message", "There are not any entries.");
}
+
} catch (Exception e) {
logger.error(e.getMessage(), e);
postsCtx.put("error", "Cannot display latest forum entries.");
}
-
+
return ctx;
}
- public static DelegateContext getProjectLatestForumPostsCtx(String projectId,
- JBossRenderResponse response) {
+ public static DelegateContext getProjectLatestForumPostsCtx(String projectId) {
DelegateContext ctx = new DelegateContext();
DelegateContext projectsCtx = ctx.next("projects");
@@ -167,16 +113,17 @@
Project project = projectsService.getProjectById(projectId);
if (project != null) {
- Integer devForumId = getForumIdFromLink(project.getDevForum());
- Integer userForumId = getForumIdFromLink(project.getUserForum());
+ Integer devForumId = retrieveForumIdFromLink(project.getDevForum());
+ Integer userForumId = retrieveForumIdFromLink(project.getUserForum());
- Set<Topic> topics = new HashSet<Topic>();
+ List<Topic> topics = new ArrayList<Topic>();
if (devForumId != null) {
Forum devForum = forumsModule.findForumById(devForumId);
if (devForum != null) {
- topics.addAll(devForum.getTopics());
+ for (Object topicObj : devForum.getTopics())
+ topics.add((Topic) topicObj);
}
}
@@ -184,49 +131,40 @@
Forum userForum = forumsModule.findForumById(userForumId);
if (userForum != null) {
- topics.addAll(userForum.getTopics());
+ for (Object topicObj : userForum.getTopics())
+ topics.add((Topic) topicObj);
}
}
-
- Map latestForumPosts = forumsModule.findLastPostsOfTopics(topics);
-
-
- if (latestForumPosts.isEmpty()) {
- postsCtx.put("message", "There are not any entries.");
- }
-
- int counter = 0;
- for (Object topic : latestForumPosts.keySet()) {
- if (counter == NUMBER_OF_DISPLAYED_POSTS) {
- break;
+ Map latestForumPostsMap = null;
+ if (!topics.isEmpty()) {
+ latestForumPostsMap = forumsModule.findLastPostsOfTopics(topics);
+
+ List<Post> latestPosts = new ArrayList<Post>();
+
+ for (Object postObj : latestForumPostsMap.values()) {
+ Post post = (Post) postObj;
+ latestPosts.add(post);
}
- Post post = (Post) latestForumPosts.get(topic);
+ int postsNumber = 0;
+ Random random = new Random();
- if (post != null) {
+ while (postsNumber++ < NUMBER_OF_DISPLAYED_POSTS && latestPosts.size() > 0) {
+ int item = (int)(latestPosts.size() * random.nextFloat());
+
+ Post post = latestPosts.remove(item);
+
DelegateContext postCtx = postsCtx.next("post");
- Message message = post.getMessage();
- if (message != null) {
- postCtx.put("subject", message.getSubject());
- postCtx.put("address", prepareForumPostLink(forumsModule.findTopicById((Integer) topic), post));
-
- SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN2, Locale.US);
- postCtx.put("date", getPostCreateDate(post, formatter));
-
- Poster poster = post.getPoster();
- if (poster != null) {
- User user = poster.getUser();
- postCtx.put("userId", user.getUserName());
- }
- }
-
- counter++;
+ preparePostCtx(post, postCtx, Constants.DATE_PATTERN2);
}
+ } else {
+ postsCtx.put("message", "There are not any entries.");
}
}
}
+
} catch (Exception e) {
e.printStackTrace();
postsCtx.put("error", "Cannot display latest forum entries.");
@@ -235,72 +173,46 @@
return ctx;
}
- public static DelegateContext getLatestUserForumPostsCtx(String forumId, String projectId,
- JBossRenderResponse response) {
+ public static DelegateContext getLatestUserForumPostsCtx(String forumId, String projectId) {
DelegateContext ctx = new DelegateContext();
DelegateContext postsCtx = ctx.next("posts");
+
+ preparePostsCtx(forumId, postsCtx);
+
try {
- ForumsModule forumsModule = getForumModule();
+ ProjectsService projectsService = LabsServices.getProjectsService();
+ Project project = projectsService.getProjectById(projectId);
- if (forumId != null) {
- Forum forum = forumsModule.findForumById(new Integer((String) forumId));
-
- Map latestForumPosts = null;
- if (forum != null) {
- latestForumPosts = forumsModule.findLastPostsOfTopics(forum.getTopics());
- }
-
- if (latestForumPosts != null) {
- if (latestForumPosts.isEmpty()) {
- postsCtx.put("message", "There are not any entries.");
- }
-
- int counter = 0;
- for (Object topic : latestForumPosts.keySet()) {
- if (counter == NUMBER_OF_DISPLAYED_POSTS) {
- break;
- }
-
- Post post = (Post) latestForumPosts.get(topic);
-
- if (post != null) {
- DelegateContext postCtx = postsCtx.next("post");
-
- Message message = post.getMessage();
- if (message != null) {
- postCtx.put("subject", message.getSubject());
- postCtx.put("address", prepareForumPostLink(forumId, post.getId()));
-
- SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN, Locale.US);
- postCtx.put("date", getPostCreateDate(post, formatter));
-
- Poster poster = post.getPoster();
- if (poster != null) {
- User user = poster.getUser();
- postCtx.put("userId", user.getUserName());
- }
- }
-
- counter++;
- }
- }
-
- } else {
- postsCtx.put("message", "There are not any entries.");
- }
+ if (project != null) {
+ String userForum = project.getUserForum();
+ if (userForum != null && userForum.length() > 0) {
+ postsCtx.put("userForumsAddress", project.getUserForum());
+ }
}
-
} catch (Exception e) {
logger.error(e.getMessage(), e);
- postsCtx.put("error", "Cannot display latest forum entries.");
}
+ return ctx;
+ }
+
+ public static DelegateContext getLatestDevForumPostsCtx(String forumId, String projectId) {
+ DelegateContext ctx = new DelegateContext();
+
+ DelegateContext postsCtx = ctx.next("posts");
+
+ preparePostsCtx(forumId, postsCtx);
+
try {
ProjectsService projectsService = LabsServices.getProjectsService();
Project project = projectsService.getProjectById(projectId);
+
if (project != null) {
- postsCtx.put("userForumsAddress", project.getUserForum());
+ String devForum = project.getDevForum();
+ if (devForum != null && devForum.length() > 0) {
+ postsCtx.put("devForumsAddress", project.getDevForum());
+ }
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
@@ -308,81 +220,208 @@
return ctx;
}
-
- public static DelegateContext getLatestDevForumPostsCtx(String forumId, String projectId,
- JBossRenderResponse response) {
+
+ public static DelegateContext getLatestUserForumPostsCtx() {
DelegateContext ctx = new DelegateContext();
DelegateContext postsCtx = ctx.next("posts");
try {
ForumsModule forumsModule = getForumModule();
+
+ List<Post> latestPosts = new ArrayList<Post>();
- if (forumId != null) {
- Forum forum = forumsModule.findForumById(new Integer((String) forumId));
-
- Map latestForumPosts = null;
- if (forum != null) {
- latestForumPosts = forumsModule.findLastPostsOfTopics(forum.getTopics());
- }
-
- if (latestForumPosts != null) {
- if (latestForumPosts.isEmpty()) {
- postsCtx.put("message", "There are not any entries.");
+ List<Project> projects = getProjects();
+ for (Project project : projects) {
+ Integer forumId = retrieveForumIdFromLink(project.getUserForum());
+ if (forumId != null) {
+ Forum forum = null;
+ try {
+ forum = forumsModule.findForumById(forumId);
+ } catch (ModuleException e) {
+ logger.error(e.getMessage(), e);
+ }
+ if (forum != null) {
+ Post post = forumsModule.findLastPost(forum);
+ if (post != null)
+ latestPosts.add(post);
}
+ }
+ }
+
+ if (!latestPosts.isEmpty()) {
+ int postsNumber = 0;
+ Random random = new Random();
+
+ while (postsNumber++ < NUMBER_OF_DISPLAYED_POSTS && latestPosts.size() > 0) {
+ int item = (int)(latestPosts.size() * random.nextFloat());
- int counter = 0;
- for (Object topic : latestForumPosts.keySet()) {
- if (counter == NUMBER_OF_DISPLAYED_POSTS) {
- break;
- }
+ Post post = latestPosts.remove(item);
+ DelegateContext postCtx = postsCtx.next("post");
- Post post = (Post) latestForumPosts.get(topic);
+ preparePostCtx(post, postCtx, Constants.DATE_PATTERN);
+ }
+ } else {
+ postsCtx.put("message", "There are not any entries.");
+ }
- if (post != null) {
- DelegateContext postCtx = postsCtx.next("post");
-
- Message message = post.getMessage();
- if (message != null) {
- postCtx.put("subject", message.getSubject());
- postCtx.put("address", prepareForumPostLink(forumId, post.getId()));
-
- SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN, Locale.US);
- postCtx.put("date", getPostCreateDate(post, formatter));
-
- Poster poster = post.getPoster();
- if (poster != null) {
- User user = poster.getUser();
- postCtx.put("userId", user.getUserName());
- }
- }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ postsCtx.put("error", "Cannot display latest forum entries.");
+ }
- counter++;
- }
+ postsCtx.put("userForumsAddress", "/" + Constants.FORUMS_PAGE_NAME);
+
+ return ctx;
+ }
+
+ public static DelegateContext getLatestDevForumPostsCtx() {
+ DelegateContext ctx = new DelegateContext();
+
+ DelegateContext postsCtx = ctx.next("posts");
+ try {
+ ForumsModule forumsModule = getForumModule();
+
+ List<Post> latestPosts = new ArrayList<Post>();
+
+ List<Project> projects = getProjects();
+ for (Project project : projects) {
+ Integer forumId = retrieveForumIdFromLink(project.getDevForum());
+ if (forumId != null) {
+ Forum forum = null;
+
+ try {
+ forum = forumsModule.findForumById(forumId);
+ } catch (ModuleException e) {
+ logger.error(e.getMessage(), e);
+ }
+ if (forum != null) {
+ Post post = forumsModule.findLastPost(forum);
+ if (post != null)
+ latestPosts.add(post);
}
+ }
+ }
+
+ if (!latestPosts.isEmpty()) {
+ int postsNumber = 0;
+ Random random = new Random();
+
+ while (postsNumber++ < NUMBER_OF_DISPLAYED_POSTS && latestPosts.size() > 0) {
+ int item = (int)(latestPosts.size() * random.nextFloat());
- } else {
- postsCtx.put("message", "There are not any entries.");
+ Post post = latestPosts.remove(item);
+ DelegateContext postCtx = postsCtx.next("post");
+
+ preparePostCtx(post, postCtx, Constants.DATE_PATTERN);
}
- }
+ } else {
+ postsCtx.put("message", "There are not any entries.");
+ }
+
} catch (Exception e) {
logger.error(e.getMessage(), e);
postsCtx.put("error", "Cannot display latest forum entries.");
}
+ postsCtx.put("devForumsAddress", "/" + Constants.FORUMS_PAGE_NAME);
+
+ return ctx;
+ }
+
+ private static void preparePostsCtx(String forumId, DelegateContext postsCtx) {
try {
- ProjectsService projectsService = LabsServices.getProjectsService();
- Project project = projectsService.getProjectById(projectId);
+ ForumsModule forumsModule = getForumModule();
+
+ Forum forum = forumsModule.findForumById(new Integer((String) forumId));
- if (project != null) {
- postsCtx.put("devForumsAddress", project.getDevForum());
+ Map latestForumPostsMap = null;
+ if (forum != null) {
+ latestForumPostsMap = forumsModule.findLastPostsOfTopics(forum.getTopics());
}
+
+ if (!latestForumPostsMap.isEmpty()) {
+ List<Post> latestPosts = new ArrayList<Post>();
+
+ for (Object postObj : latestForumPostsMap.values()) {
+ Post post = (Post) postObj;
+ latestPosts.add(post);
+ }
+
+ int postsNumber = 0;
+ Random random = new Random();
+
+ while (postsNumber++ < NUMBER_OF_DISPLAYED_POSTS && latestPosts.size() > 0) {
+ int item = (int)(latestPosts.size() * random.nextFloat());
+
+ Post post = (Post) latestPosts.remove(item);
+ DelegateContext postCtx = postsCtx.next("post");
+
+ preparePostCtx(post, postCtx, Constants.DATE_PATTERN);
+ }
+ } else {
+ postsCtx.put("message", "There are not any entries.");
+ }
+
} catch (Exception e) {
logger.error(e.getMessage(), e);
+ postsCtx.put("error", "Cannot display latest forum entries.");
+ }
+ }
+
+ private static void preparePostCtx(Post post, DelegateContext postCtx, String datePattern) {
+ Message message = post.getMessage();
+ if (message != null) {
+ postCtx.put("subject", message.getSubject());
+
+ Topic topic = post.getTopic();
+ if (topic != null) {
+ postCtx.put("address", prepareForumPostLink(post.getId(), topic.getId()));
+ }
+
+ SimpleDateFormat formatter = new SimpleDateFormat(datePattern, Locale.US);
+ postCtx.put("date", getPostCreateDate(post, formatter));
+
+ Poster poster = post.getPoster();
+ if (poster != null) {
+ User user = poster.getUser();
+ postCtx.put("userId", user.getUserName());
+ }
+ }
+ }
+
+ private static ForumsModule getForumModule() {
+ ForumsModule forumsModule = null;
+ try {
+ InitialContext initialContext = new InitialContext();
+
+ Object obj = initialContext.lookup("java:portal/ForumsModule");
+
+ forumsModule = (ForumsModule) obj;
+ } catch (Exception e) {
+ e.printStackTrace();
}
- return ctx;
+ return forumsModule;
}
+ public static List<Project> getProjects() {
+ List<Project> projectsList = new ArrayList<Project>();
+
+ try {
+ ProjectsService projectsService = LabsServices.getProjectsService();
+ Collection<? extends Project> projects = projectsService.getProjects();
+ for (Project project : projects) {
+ if (!project.getId().equals("default")) {
+ projectsList.add(project);
+ }
+ }
+ } catch (Exception e) {
+ logger.warn(e.getMessage(), e);
+ }
+
+ return projectsList;
+ }
+
private static String getPostCreateDate(Post post, SimpleDateFormat formatter) {
Date date = post.getCreateDate();
@@ -393,33 +432,35 @@
return formatter.format(date);
}
- private static Integer getForumIdFromLink(String forumLink) {
+ private static Integer retrieveForumIdFromLink(String forumLink) {
Integer forumId = null;
if (forumLink != null) {
- String[] tokens = forumLink.split("/");
- try {
- if (tokens.length > 0) {
- forumId = new Integer(tokens[tokens.length - 1]);
- }
- } catch (NumberFormatException e) {}
+ if (forumLink.contains("&f=")) {
+ if (forumId == null) {
+ for (String s : forumLink.split("&")) {
+ if (s.matches("f=[0-9]+?")) {
+ forumId = new Integer(s.substring(s.indexOf("=") + 1));
+ }
+ }
+ }
+ } else {
+ String[] tokens = forumLink.split("/");
+
+ if (tokens.length > 0) {
+ String s = tokens[tokens.length - 1];
+ if (s.matches("[0-9]+?")) {
+ forumId = new Integer(s);
+ }
+ }
+ }
}
return forumId;
}
- private static String prepareForumPostLink(Topic topic, Post post) {
- Forum forum = topic.getForum();
-
- if (forum == null) {
- return null;
- }
-
- return "/forums/" + forum.getId() + "/" + post.getId();
+ private static String prepareForumPostLink(Integer postId, Integer topicId) {
+ return "/" + Constants.FORUMS_PAGE_NAME + "/" + topicId + "/" + postId;
}
- private static String prepareForumPostLink(String forumId, Integer postId) {
- return "/forums/" + forumId + "/" + postId;
- }
-
}
Modified: labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/UserForumEntriesPortlet.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/UserForumEntriesPortlet.java 2007-04-21 22:36:10 UTC (rev 11198)
+++ labs/jbosslabs/trunk/portal-extensions/jboss-forums/forums-portlets/src/java/org/jboss/forge/forums/UserForumEntriesPortlet.java 2007-04-21 22:39:58 UTC (rev 11199)
@@ -22,17 +22,21 @@
response.setContentType("text/html");
String portalName = ForgeHelper.getPortalName(request);
- //String serverAdress = ForgeHelper.getBaseServerAddress(request);
String jspPath = ForumsTools.getUserForumsEntriesJspCmPath();
+ String projectId = ProjectsHelper.getSelectedProjectId(request);
+
+ DelegateContext context = null;
+
Object forumIdObj = request.getPreferences().getValue("forumId", null);
- String forumId = (String) forumIdObj;
+ if (forumIdObj != null) {
+ String forumId = (String) forumIdObj;
+ context = ForumsTools.getLatestUserForumPostsCtx(forumId, projectId);
+ } else {
+ context = ForumsTools.getLatestUserForumPostsCtx();
+ }
- String projectId = ProjectsHelper.getSelectedProjectId(request);
-
- DelegateContext context = ForumsTools.getLatestUserForumPostsCtx(forumId, projectId, response);
-
request.setAttribute(PortalJsp.CTX_REQUEST, context);
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(
More information about the jboss-svn-commits
mailing list