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 com.nabhinc.portal.spi.UserAdminServiceLocator;
030: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
031: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
032: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
033:
034: /**
035: *
036: *
037: * @author Padmanabh Dabke
038: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
039: */
040: public class UserListFetcher extends BaseRequestProcessor implements
041: RenderProcessor {
042:
043: public String process(RenderRequest request,
044: RenderResponse response, RenderConfig renderConfig)
045: throws PortletException, IOException {
046: int numUsers = UserAdminServiceLocator.getUserAdminService()
047: .getUserCount();
048: if (numUsers == 0)
049: return "no-such-record";
050:
051: List userList = null;
052: int pageIndex = 0;
053: int pageSize = 10;
054:
055: String pageIndexStr = request.getParameter("pageindex");
056: if (pageIndexStr != null) {
057: pageIndex = Integer.parseInt(pageIndexStr);
058: }
059:
060: String pageSizeStr = request.getPreferences().getValue(
061: "pagesize", null);
062: if (pageSizeStr != null)
063: pageSize = Integer.parseInt(pageSizeStr);
064:
065: request.setAttribute("user_admin.user_count", new Integer(
066: numUsers));
067: request.setAttribute("user_admin.page_index", new Integer(
068: pageIndex));
069: request.setAttribute("user_admin.page_size", new Integer(
070: pageSize));
071:
072: int offset = pageIndex * pageSize;
073: if (offset >= numUsers)
074: return "page-empty";
075: String descending = request.getParameter("descending");
076: if (descending == null) {
077: descending = (String) request.getPortletSession()
078: .getAttribute("descending");
079: } else {
080: request.getPortletSession().setAttribute("descending",
081: descending);
082: }
083: boolean isDescending = "true".equals(descending);
084:
085: String orderBy = request.getParameter("orderby");
086: if (orderBy == null) {
087: orderBy = (String) request.getPortletSession()
088: .getAttribute("orderby");
089: } else {
090: request.getPortletSession()
091: .setAttribute("orderby", orderBy);
092: }
093: userList = UserAdminServiceLocator.getUserAdminService()
094: .getUsers(offset, pageSize, orderBy, isDescending);
095: if (userList.size() > 0) {
096: request.setAttribute("user_admin.user_list", userList);
097: return "success";
098: } else {
099: return "page-empty";
100: }
101:
102: }
103:
104: }
|