[jboss-svn-commits] JBL Code SVN: r8535 - in labs/jbossforums/branches/forums26/forums/src: main/org/jboss/portlet/forums/ui main/org/jboss/portlet/forums/ui/view resources/portal-forums-war/WEB-INF resources/portal-forums-war/views/category resources/portal-forums-war/views/forums resources/portal-forums-war/views/topics
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 21 19:47:16 EST 2006
Author: unibrew
Date: 2006-12-21 19:47:10 -0500 (Thu, 21 Dec 2006)
New Revision: 8535
Modified:
labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/Constants.java
labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java
labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml
labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/category/viewcategory_body.xhtml
labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml
labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml
Log:
[JBFORUMS-119] Finally, links to last posts, permament links etc., work
Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/Constants.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-12-22 00:47:10 UTC (rev 8535)
@@ -23,7 +23,7 @@
/**
* @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
- *
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
*/
public interface Constants
{
@@ -56,6 +56,7 @@
public static final String p_results = "results";
public static final String p_page = "page";
public static final String p_watchId = "w";
+ public static final String p_viewId = "v";
//other constants-------------------------------------------------------------------------------------------------------------------------------
public static final String QUOTE = "quote";
public static final String NOTIFY_REPLY_KEY = "notifyreply";
Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-12-22 00:47:10 UTC (rev 8535)
@@ -219,11 +219,13 @@
try
{
+ setPortletRequestFlag(request);
+
if (sessionTimedOut(request)) {
return;
}
- setPortletRequestFlag(request);
+ setPortletRequestFlag(request);
this.setupRenderParameters(request,response);
@@ -405,6 +407,7 @@
String results = ForumUtil.getParameter(request,Constants.p_results);
String page = ForumUtil.getParameter(request,Constants.p_page);
String watchId = ForumUtil.getParameter(request,Constants.p_watchId);
+ String viewId = ForumUtil.getParameter(request,Constants.p_viewId);
if(categoryId!=null && categoryId.trim().length()>0)
{
response.setRenderParameter(Constants.p_categoryId,categoryId);
@@ -457,6 +460,10 @@
{
response.setRenderParameter(Constants.p_watchId,watchId);
}
+ if(viewId!=null && viewId.trim().length()>0)
+ {
+ response.setRenderParameter(Constants.p_viewId,viewId);
+ }
}
/**
Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2006-12-22 00:47:10 UTC (rev 8535)
@@ -250,7 +250,32 @@
return null;
}
}
+
+ public static String postPermlink(String postId) {
+
+ Object response =
+ FacesContext.getCurrentInstance().getExternalContext().getResponse();
+ String url = "";
+
+ if (response instanceof RenderResponse)
+ {
+ RenderResponse renderResponse = (RenderResponse) response;
+ PortletURL portletURL = renderResponse.createActionURL();
+ url = portletURL.toString();
+ if (url.contains("/auth")) {
+ url = url.replaceFirst("/auth","");
+ }
+ url += "&"+Constants.p_viewId+"=t&"+Constants.p_postId+"="+postId+"#"+postId;
+ } else {
+ url = JSFUtil.getContextPath();
+ url += FacesContext.getCurrentInstance().getExternalContext().getRequestServletPath();
+ url += "?"+Constants.p_postId+"="+postId+"#"+postId;
+ }
+
+ return url;
+ }
+
/**
*
* @param preferenceKey
Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/view/ViewTopic.java 2006-12-22 00:47:10 UTC (rev 8535)
@@ -26,9 +26,12 @@
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
+
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.Post;
import org.jboss.portlet.forums.model.Topic;
import org.jboss.portlet.forums.ui.BaseController;
import org.jboss.portlet.forums.ui.Constants;
@@ -188,28 +191,59 @@
private void execute() throws Exception {
//parse input data
int topicId = -1;
+ Integer postId = new Integer(-1);
String t = ForumUtil.getParameter(Constants.p_topicId);
String page = ForumUtil.getParameter(Constants.p_page);
+ String p = ForumUtil.getParameter(Constants.p_postId);
+ String postOrder = this.userPreferences.getPreference(Constants.POST_ORDER_KEY);
+ Integer postsPerPage = Integer.valueOf(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY));
+
if (t != null && t.trim().length() > 0) {
topicId = Integer.parseInt(t);
- }
+ }
+
+ int currentPage = 0;
+ if (page != null && page.trim().length() > 0) {
+ //setup the page data
+ currentPage = Integer.parseInt(page);
+ }
+
+ if (p != null && p.trim().length() > 0) {
+ postId = new Integer(p);
+ Post post = this.getForumsModule().findPostById(postId);
+ topicId = post.getTopic().getId().intValue();
+ this.topic = post.getTopic();
+ List postIds = null;
+ if (postOrder.compareToIgnoreCase("ascending")==0) {
+ postIds = this.getForumsModule().findPostIdsAsc(this.topic.getId(),0,Integer.MAX_VALUE);
+ } else {
+ postIds = this.getForumsModule().findPostIdsDesc(this.topic.getId(),0,Integer.MAX_VALUE);
+ }
+ int counter = 0;
+ Iterator it = postIds.iterator();
+ while (it.hasNext()) {
+ Integer id = (Integer)it.next();
+ if (id.intValue()==postId.intValue()) {
+ break;
+ }
+ counter++;
+ }
+ currentPage = (int)Math.round(Math.floor(counter/postsPerPage.intValue()));
+ }
// ForumsModule is stored as a final variable so that anonymous class could use it.
final ForumsModule fm = BaseController.getForumsModule();
//process the topic information
if (topicId != -1) {
- this.topic = fm.findTopicById(new Integer(topicId));
+ if (this.topic==null) {
+ this.topic = fm.findTopicById(new Integer(topicId));
+ }
topic.setViewCount(topic.getViewCount()+1);
- String postOrder = this.userPreferences.getPreference(Constants.POST_ORDER_KEY);
+
int postCount = topic.getReplies()+1;
-
+
if (postCount > 0) {
- int currentPage = 0;
- if (page != null && page.trim().length() > 0) {
- //setup the page data
- currentPage = Integer.parseInt(page);
- }
//setup the pageNavigator
//total number of entries to be split up into pages
@@ -217,7 +251,7 @@
if (postOrder.compareToIgnoreCase("ascending")==0) {
this.pageNavigator =
new PageNavigator(postCount,
- Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)),
+ postsPerPage.intValue(),
currentPage) {
protected Collection initializePage() {
@@ -251,7 +285,7 @@
this.pageNavigator =
new PageNavigator(postCount,
- Integer.parseInt(this.userPreferences.getPreference(Constants.POSTS_TOPIC_KEY)),
+ postsPerPage.intValue(),
currentPage) {
protected Collection initializePage() {
Modified: labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/WEB-INF/forums.taglib.xml 2006-12-22 00:47:10 UTC (rev 8535)
@@ -10,7 +10,17 @@
<function-name>outputLink</function-name>
<function-class>org.jboss.portlet.forums.ui.PortalUtil</function-class>
<function-signature>java.lang.String outputLink(java.lang.String,boolean)</function-signature>
- </function>
+ </function>
+ <!--
+ function generates a permament link to post in a topic view
+ that works seamlessly within portal and standalone environment
+ to be used for generating "GET" requests that can be bookmarked
+ -->
+ <function>
+ <function-name>postPermlink</function-name>
+ <function-class>org.jboss.portlet.forums.ui.PortalUtil</function-class>
+ <function-signature>java.lang.String postPermlink(java.lang.String)</function-signature>
+ </function>
<!--
function generates String value got from org.jboss.portal.core.CoreConstants
-->
Modified: labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/category/viewcategory_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/category/viewcategory_body.xhtml 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/category/viewcategory_body.xhtml 2006-12-22 00:47:10 UTC (rev 8535)
@@ -104,13 +104,14 @@
<h:outputText value="${category.forumLastPosts[forumrow.id].poster.user.userName}"/>
</h:outputLink>
</c:otherwise>
- </c:choose>
- <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" style="text-decoration: none;">
- <f:param name="t" value="#{category.forumLastPosts[forumrow.id].topic.id}"/>
- <f:verbatim>
- <img border="0" src="#{forums:themeURL('resourceIconLatestReplyURL')}"/>
- </f:verbatim>
- </h:outputLink>
+ </c:choose>
+ <h:outputLink value="#{forums:postPermlink(category.forumLastPosts[forumrow.id].id)}" style="text-decoration: none;">
+ <f:verbatim>
+ <img src="#{forums:themeURL('resourceIconLatestReplyURL')}"
+ alt='${resource.Posts}'
+ title='${resource.Posts}' border="0"/>
+ </f:verbatim>
+ </h:outputLink>
</c:when>
<c:otherwise>
#{resource.No_Posts}
Modified: labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/forums/viewforum_body.xhtml 2006-12-22 00:47:10 UTC (rev 8535)
@@ -248,14 +248,15 @@
</h:outputLink>
</c:otherwise>
</c:choose>
- <!-- link to the last post in the topic -->
- <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" style="text-decoration: none;"
- alt="#{resource.View_latest_post}" title="#{resource.View_latest_post}">
- <f:param name="t" value="#{topicrow.id}"/>
- <f:verbatim>
- <img border="0" src="#{forums:themeURL('resourceIconLatestReplyURL')}"/>
- </f:verbatim>
- </h:outputLink>
+ <!-- link to the last post in the topic -->
+ <h:outputLink value="#{forums:postPermlink(forum.topicLastPosts[topicrow.id].id)}"
+ style="text-decoration: none;"
+ alt="#{resource.View_latest_post}"
+ title="#{resource.View_latest_post}" >
+ <f:verbatim>
+ <img src="#{forums:themeURL('resourceIconLatestReplyURL')}" border="0"/>
+ </f:verbatim>
+ </h:outputLink>
</span>
</td>
</tr>
@@ -349,14 +350,15 @@
</h:outputLink>
</c:otherwise>
</c:choose>
- <!-- link to the last post in the topic -->
- <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" style="text-decoration: none;"
- alt="#{resource.View_latest_post}" title="#{resource.View_latest_post}">
- <f:param name="t" value="#{topicrow.id}"/>
- <f:verbatim>
- <img border="0" src="#{forums:themeURL('resourceIconLatestReplyURL')}"/>
- </f:verbatim>
- </h:outputLink>
+ <!-- link to the last post in the topic -->
+ <h:outputLink value="#{forums:postPermlink(forum.topicLastPosts[topicrow.id].id)}"
+ style="text-decoration: none;"
+ alt="#{resource.View_latest_post}"
+ title="#{resource.View_latest_post}" >
+ <f:verbatim>
+ <img src="#{forums:themeURL('resourceIconLatestReplyURL')}" border="0"/>
+ </f:verbatim>
+ </h:outputLink>
</span>
</td>
</tr>
@@ -449,14 +451,15 @@
</h:outputLink>
</c:otherwise>
</c:choose>
- <!-- link to the last post in the topic -->
- <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}" style="text-decoration: none;"
- alt="#{resource.View_latest_post}" title="#{resource.View_latest_post}">
- <f:param name="t" value="#{topicrow.id}"/>
- <f:verbatim>
- <img border="0" src="#{forums:themeURL('resourceIconLatestReplyURL')}"/>
- </f:verbatim>
- </h:outputLink>
+ <!-- link to the last post in the topic -->
+ <h:outputLink value="#{forums:postPermlink(forum.topicLastPosts[topicrow.id].id)}"
+ style="text-decoration: none;"
+ alt="#{resource.View_latest_post}"
+ title="#{resource.View_latest_post}" >
+ <f:verbatim>
+ <img src="#{forums:themeURL('resourceIconLatestReplyURL')}" border="0"/>
+ </f:verbatim>
+ </h:outputLink>
</span>
</td>
</tr>
Modified: labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2006-12-22 00:46:52 UTC (rev 8534)
+++ labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml 2006-12-22 00:47:10 UTC (rev 8535)
@@ -252,14 +252,14 @@
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
- <h:outputLink value="#{forums:outputLink(shared.links['topic'],true)}#{$posrtrow.id}" style="text-decoration: none;">
- <f:param name="t" value="#{topic.topic.id}"/>
- <f:verbatim>
- <img width="12" height="9"
- src="#{forums:themeURL('resourceIconMinipostURL')}"
- alt='${resource.Posts}'
- title='${resource.Posts}' border="0"/>
- </f:verbatim>
+ <a name="${postrow.id}" />
+ <h:outputLink value="#{forums:postPermlink(postrow.id)}" style="text-decoration: none;">
+ <f:verbatim>
+ <img width="12" height="9"
+ src="#{forums:themeURL('resourceIconMinipostURL')}"
+ alt='${resource.Posts}'
+ title='${resource.Posts}' border="0"/>
+ </f:verbatim>
</h:outputLink>
<span class="postdetails">
${resource.Posted}: 
More information about the jboss-svn-commits
mailing list