Author: sviluppatorefico
Date: 2008-05-24 13:23:43 -0400 (Sat, 24 May 2008)
New Revision: 10810
Added:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/help.jsp
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource.properties
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource_it.properties
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/oneUser.jsp
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/users.jsp
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/portlet.xml
Log:
I add customization and help page for current users portlet.
See
http://jira.jboss.org/jira/browse/JBPORTAL-2026
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java 2008-05-24
01:39:58 UTC (rev 10809)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java 2008-05-24
17:23:43 UTC (rev 10810)
@@ -22,6 +22,15 @@
package org.jboss.portal.core.samples.users;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Set;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.UnavailableException;
+
import org.apache.log4j.Logger;
import org.jboss.portal.core.identity.UsersActivityStatsService;
import org.jboss.portal.core.servlet.jsp.PortalJsp;
@@ -30,67 +39,74 @@
import org.jboss.portlet.JBossRenderRequest;
import org.jboss.portlet.JBossRenderResponse;
-import javax.portlet.PortletException;
-import javax.portlet.PortletRequestDispatcher;
-import javax.portlet.UnavailableException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Set;
-
/**
* Read the current users online and write them in output.
- *
+ *
* @author <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
*/
-public class CurrentUsersPortlet extends JBossPortlet
-{
+public class CurrentUsersPortlet extends JBossPortlet {
- /** Logger */
- public static Logger log = Logger.getLogger(CurrentUsersPortlet.class);
+ /** Logger */
+ public static Logger log = Logger.getLogger(CurrentUsersPortlet.class);
- protected void doView(JBossRenderRequest rRequest, JBossRenderResponse rResponse)
throws PortletException,
- IOException, UnavailableException
- {
- UsersActivityStatsService uass = (UsersActivityStatsService)
this.getPortletContext().getAttribute(
- "UsersActivityStats");
+ /** Help page */
+ private static final String JSP_HELP = "/WEB-INF/jsp/users/help.jsp";
- rResponse.setContentType("text/html");
- PrintWriter writer = rResponse.getWriter();
+ protected void doHelp(JBossRenderRequest request,
+ JBossRenderResponse response) throws PortletException,
+ PortletSecurityException, IOException {
+ response.setContentType("text/html");
+ PortletRequestDispatcher dispatcher = getPortletContext()
+ .getRequestDispatcher(JSP_HELP);
+ dispatcher.include(request, response);
+ }
- long currentTime = System.currentTimeMillis();
+ protected void doView(JBossRenderRequest rRequest,
+ JBossRenderResponse rResponse) throws PortletException,
+ IOException, UnavailableException {
+
+ String guestNumber =
rRequest.getPreferences().getValue("guestNumber","");
+
+ UsersActivityStatsService uass = (UsersActivityStatsService) this
+ .getPortletContext().getAttribute("UsersActivityStats");
- //TODO: this is wrong - should pass period instead of current time - actually it
works by a coincedence...
- Set users = uass.getActiveUsersNames(currentTime);
+ rResponse.setContentType("text/html");
+ PrintWriter writer = rResponse.getWriter();
- int sessionCount = uass.getActiveSessionCount(currentTime);
+ long currentTime = System.currentTimeMillis();
- int allLoggedSessions = uass.getUsersActivities(currentTime).size();
+ // TODO: this is wrong - should pass period instead of current time -
+ // actually it works by a coincedence...
+ Set users = uass.getActiveUsersNames(currentTime);
- if (sessionCount == 1)
- {
- DelegateContext ctx = new DelegateContext();
- ctx.put("USERS", users.toString());
- ctx.put("USERS_COUNT", Integer.toString(sessionCount));
- rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/oneUser.jsp");
- rd.include(rRequest, rResponse);
- }
- else if (sessionCount > 1)
- {
- DelegateContext ctx = new DelegateContext();
- ctx.put("USERS", users.toString());
- ctx.put("USERS_COUNT", Integer.toString(sessionCount));
- ctx.put("USERS_LOGGED_COUNT", Integer.toString(users.size()));
- rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/users.jsp");
- rd.include(rRequest, rResponse);
- }
- else
- {
- PortletRequestDispatcher rd =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/noUser.jsp");
- rd.include(rRequest, rResponse);
- }
+ int sessionCount = uass.getActiveSessionCount(currentTime);
- writer.close();
- }
+ int allLoggedSessions = uass.getUsersActivities(currentTime).size();
+
+ if (sessionCount == 1 || (guestNumber.equals("false") && users.size()
== 1)) {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("USERS", users.toString());
+ ctx.put("USERS_COUNT", Integer.toString(sessionCount));
+ ctx.put("USERS_LOGGED_COUNT", Integer.toString(users.size()));
+ rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/users/oneUser.jsp");
+ rd.include(rRequest, rResponse);
+ } else if (sessionCount > 1) {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("USERS", users.toString());
+ ctx.put("USERS_COUNT", Integer.toString(sessionCount));
+ ctx.put("USERS_LOGGED_COUNT", Integer.toString(users.size()));
+ rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/users/users.jsp");
+ rd.include(rRequest, rResponse);
+ } else {
+ PortletRequestDispatcher rd = getPortletContext()
+ .getRequestDispatcher("/WEB-INF/jsp/users/noUser.jsp");
+ rd.include(rRequest, rResponse);
+ }
+
+ writer.close();
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource.properties
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource.properties 2008-05-24
01:39:58 UTC (rev 10809)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource.properties 2008-05-24
17:23:43 UTC (rev 10810)
@@ -21,13 +21,15 @@
# 02110-1301 USA, or see the FSF site:
http://www.fsf.org. #
################################################################################
-NO_USERS_ONLINE=No logged-in user
+NO_USERS_ONLINE=No online user
ONE_USER_ONLINE_0=There is <b>
ONE_USER_ONLINE_1=</b> online user
+ONE_USER_LOGGED_1=</b> logged user
ONE_USER_IS_0=<b>
ONE_USER_IS_1=</b>
USERS_ONLINE_0=There are <b>
USERS_ONLINE_1=</b> online users
+USERS_LOGGED_1=</b> logged users
USERS_ARE_0=<b>
USERS_ARE_1=</b>
USERS_WHICH_0=Whose <b>
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource_it.properties
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource_it.properties 2008-05-24
01:39:58 UTC (rev 10809)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/classes/Resource_it.properties 2008-05-24
17:23:43 UTC (rev 10810)
@@ -24,10 +24,12 @@
NO_USERS_ONLINE=Nessun utente \u00e8 online
ONE_USER_ONLINE_0=Al momento c'\u00e8 <b>
ONE_USER_ONLINE_1=</b> utente online
+ONE_USER_LOGGED_1=</b> utente loggato
ONE_USER_IS_0=<b>
ONE_USER_IS_1=</b>
USERS_ONLINE_0=Al momento ci sono <b>
USERS_ONLINE_1=</b> utenti online
+USERS_LOGGED_1=</b> utenti loggati
USERS_ARE_0=<b>
USERS_ARE_1=</b>
USERS_WHICH_0=Di cui <b>
Added:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/help.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/help.jsp
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/help.jsp 2008-05-24
17:23:43 UTC (rev 10810)
@@ -0,0 +1,41 @@
+<%--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2006, Red Hat Middleware, LLC, and individual ~
+ ~ contributors as indicated by the @authors tag. See the ~
+ ~ copyright.txt in the distribution for a full listing of ~
+ ~ individual contributors. ~
+ ~ ~
+ ~ This is free software; you can redistribute it and/or modify it ~
+ ~ under the terms of the GNU Lesser General Public License as ~
+ ~ published by the Free Software Foundation; either version 2.1 of ~
+ ~ the License, or (at your option) any later version. ~
+ ~ ~
+ ~ This software is distributed in the hope that it will be useful, ~
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
+ ~ Lesser General Public License for more details. ~
+ ~ ~
+ ~ You should have received a copy of the GNU Lesser General Public ~
+ ~ License along with this software; if not, write to the Free ~
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--%>
+
+<%@ taglib
uri="http://java.sun.com/portlet"
prefix="portlet"%>
+
+<portlet:defineObjects />
+
+<div class="portlet-font" style="font-size: larger; font-weight:
bold">Current
+Users Portlet Help:</div>
+</div>
+<br />
+<div class="portlet-font">Description: The Current users Portlet
+shows current users actually connected. You can to see both guest and
+logged users number and to see which users are logged.</div>
+<br />
+<div class="portlet-font">You can to manage what to show to users.
+You can to choose paragraphes to show, clicking the checkboxes</div>
+<br />
+<br />
+<div class="portlet-font"><a
+ href="<portlet:renderURL
portletMode='view'/>">Back</a></div>
\ No newline at end of file
Property changes on:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/help.jsp
___________________________________________________________________
Name: svn:executable
+ *
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/oneUser.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/oneUser.jsp 2008-05-24
01:39:58 UTC (rev 10809)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/oneUser.jsp 2008-05-24
17:23:43 UTC (rev 10810)
@@ -32,14 +32,30 @@
<tr>
<td colspan="1">
<span class="portlet-text">
+ <% if (renderRequest.getPreferences().getValue("guestNumber",
"").equals("true")) { %>
${n:i18n("ONE_USER_ONLINE_0")}
${n:out("USERS_COUNT")}
- ${n:i18n("ONE_USER_ONLINE_1")}
- <% java.util.LinkedList linkedStack =
(java.util.LinkedList)contextStack.get();
+ ${n:i18n("ONE_USER_ONLINE_1")}
+ <br/><br/>
+ <% }
+ java.util.LinkedList linkedStack =
(java.util.LinkedList)contextStack.get();
org.jboss.portal.core.servlet.jsp.taglib.context.Context currentContext =
-
((org.jboss.portal.core.servlet.jsp.taglib.context.NamedContext)linkedStack.getLast()).getContext();
- if (!currentContext.get("USERS").equals("[]")) {
%>
+
((org.jboss.portal.core.servlet.jsp.taglib.context.NamedContext)linkedStack.getLast()).getContext();
+ if
(!currentContext.get("USERS_LOGGED_COUNT").equals("0") &&
renderRequest.getPreferences().getValue("loggedNumber",
"").equals("true")) { %>
+
+ <% if
(renderRequest.getPreferences().getValue("guestNumber",
"").equals("true")) { %>
+ ${n:i18n("USERS_WHICH_0")}
+ ${n:out("USERS_LOGGED_COUNT")}
+ ${n:i18n("USERS_WHICH_2")}
+ <% } else { %>
+ ${n:i18n("ONE_USER_ONLINE_0")}
+ ${n:out("USERS_LOGGED_COUNT")}
+ ${n:i18n("ONE_USER_LOGGED_1")}
+ <% } %>
<br/><br/>
+ <% }
+ if (!currentContext.get("USERS").equals("[]")
&& renderRequest.getPreferences().getValue("loggedUsers",
"").equals("true")) { %>
+
${n:i18n("ONE_USER_IS_0")}
${n:out("USERS")}
${n:i18n("ONE_USER_IS_1")}
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/users.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/users.jsp 2008-05-24
01:39:58 UTC (rev 10809)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/jsp/users/users.jsp 2008-05-24
17:23:43 UTC (rev 10810)
@@ -32,24 +32,34 @@
<tr>
<td colspan="1">
<span class="portlet-text">
+ <% if (renderRequest.getPreferences().getValue("guestNumber",
"").equals("true")) { %>
${n:i18n("USERS_ONLINE_0")}
${n:out("USERS_COUNT")}
- ${n:i18n("USERS_ONLINE_1")}
- <% java.util.LinkedList linkedStack =
(java.util.LinkedList)contextStack.get();
+ ${n:i18n("USERS_ONLINE_1")}
+ <br/><br/>
+ <% }
+ java.util.LinkedList linkedStack =
(java.util.LinkedList)contextStack.get();
org.jboss.portal.core.servlet.jsp.taglib.context.Context currentContext =
((org.jboss.portal.core.servlet.jsp.taglib.context.NamedContext)linkedStack.getLast()).getContext();
- if
(!currentContext.get("USERS_LOGGED_COUNT").equals("0")) { %>
+ if
(!currentContext.get("USERS_LOGGED_COUNT").equals("0") &&
renderRequest.getPreferences().getValue("loggedNumber",
"").equals("true")) { %>
+
+ <% if
(renderRequest.getPreferences().getValue("guestNumber",
"").equals("true")) { %>
+ ${n:i18n("USERS_WHICH_0")}
+ ${n:out("USERS_LOGGED_COUNT")}
+ <% if
(!currentContext.get("USERS_LOGGED_COUNT").equals("1")) { %>
+ ${n:i18n("USERS_WHICH_1")}
+ <% } else { %>
+ ${n:i18n("USERS_WHICH_2")}
+ <% } %>
+ <% } else { %>
+ ${n:i18n("USERS_ONLINE_0")}
+ ${n:out("USERS_LOGGED_COUNT")}
+ ${n:i18n("USERS_LOGGED_1")}
+ <% } %>
<br/><br/>
- ${n:i18n("USERS_WHICH_0")}
- ${n:out("USERS_LOGGED_COUNT")}
- <% if
(!currentContext.get("USERS_LOGGED_COUNT").equals("1")) { %>
- ${n:i18n("USERS_WHICH_1")}
- <% } else { %>
- ${n:i18n("USERS_WHICH_2")}
- <% } %>
<% }
- if (!currentContext.get("USERS").equals("[]")) {
%>
- <br/><br/>
+ if (!currentContext.get("USERS").equals("[]")
&& renderRequest.getPreferences().getValue("loggedUsers",
"").equals("true")) { %>
+
${n:i18n("USERS_ARE_0")}
${n:out("USERS")}
${n:i18n("USERS_ARE_1")}
Modified:
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/portlet.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/portlet.xml 2008-05-24
01:39:58 UTC (rev 10809)
+++
branches/JBoss_Portal_Branch_2_6/core-samples/src/resources/portal-users-samples-war/WEB-INF/portlet.xml 2008-05-24
17:23:43 UTC (rev 10810)
@@ -35,6 +35,7 @@
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>HELP</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<supported-locale>it</supported-locale>
@@ -44,5 +45,19 @@
<title>Current users</title>
<keywords>sample,test</keywords>
</portlet-info>
+ <portlet-preferences>
+ <preference>
+ <name>guestNumber</name>
+ <value>true</value>
+ </preference>
+ <preference>
+ <name>loggedNumber</name>
+ <value>true</value>
+ </preference>
+ <preference>
+ <name>loggedUsers</name>
+ <value>true</value>
+ </preference>
+ </portlet-preferences>
</portlet>
</portlet-app>