001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portlet.useradmin;
021:
022: import java.io.IOException;
023: import java.util.List;
024:
025: import javax.portlet.PortletException;
026: import javax.portlet.RenderRequest;
027: import javax.portlet.RenderResponse;
028:
029: import org.w3c.dom.Element;
030:
031: import com.nabhinc.portal.core.SessionManager;
032: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
033: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
034: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
035: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
036:
037: /**
038: *
039: *
040: * @author Padmanabh Dabke
041: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
042: */
043: public class OnlineUserFetcher extends BaseRequestProcessor implements
044: RenderProcessor {
045:
046: /**
047: * Caches controller portlet config
048: */
049: public void init(Element arg0, ControllerPortletConfig config)
050: throws PortletException {
051: super .init(arg0, config);
052:
053: }
054:
055: public String process(RenderRequest request,
056: RenderResponse response, RenderConfig renderConfig)
057: throws PortletException, IOException {
058:
059: int numUsers = SessionManager.getNumberOfUsers();
060: if (numUsers == 0)
061: return "no-online-users";
062:
063: List userList = null;
064: int pageIndex = 0;
065: int pageSize = 10;
066:
067: String pageIndexStr = request.getParameter("pageindex");
068: if (pageIndexStr != null) {
069: pageIndex = Integer.parseInt(pageIndexStr);
070: }
071:
072: String pageSizeStr = request.getPreferences().getValue(
073: "pagesize", null);
074: if (pageSizeStr != null)
075: pageSize = Integer.parseInt(pageSizeStr);
076:
077: request.setAttribute("online_users.user_count", new Integer(
078: numUsers));
079: request.setAttribute("online_users.page_index", new Integer(
080: pageIndex));
081: request.setAttribute("online_users.page_size", new Integer(
082: pageSize));
083:
084: int offset = pageIndex * pageSize;
085: String descending = request.getParameter("descending");
086: if (descending == null) {
087: descending = (String) request.getPortletSession()
088: .getAttribute("descending");
089: } else {
090: request.getPortletSession().setAttribute("descending",
091: descending);
092: }
093: boolean isDescending = "true".equals(descending);
094:
095: String orderBy = request.getParameter("orderby");
096: if (orderBy == null) {
097: orderBy = (String) request.getPortletSession()
098: .getAttribute("orderby");
099: } else {
100: request.getPortletSession()
101: .setAttribute("orderby", orderBy);
102: }
103:
104: userList = SessionManager.getOnlineSessions(offset, pageSize,
105: orderBy, isDescending, request);
106: if (userList.size() > 0) {
107: request.setAttribute("user_admin.user_list", userList);
108: }
109: return "success";
110: }
111:
112: }
|