001: /*
002: * EPersonListServlet.java
003: *
004: * Version: $Revision: 1947 $
005: *
006: * Date: $Date: 2007-05-18 08:50:29 -0500 (Fri, 18 May 2007) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.webui.servlet.admin;
041:
042: import java.io.IOException;
043: import java.sql.SQLException;
044:
045: import javax.servlet.ServletException;
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048:
049: import org.dspace.app.webui.servlet.DSpaceServlet;
050: import org.dspace.app.webui.util.JSPManager;
051: import org.dspace.app.webui.util.UIUtil;
052: import org.dspace.authorize.AuthorizeException;
053: import org.dspace.core.Context;
054: import org.dspace.eperson.EPerson;
055:
056: /**
057: * Servlet browsing through e-people and selecting them
058: *
059: * @author Robert Tansley
060: * @version $Revision: 1947 $
061: */
062: public class EPersonListServlet extends DSpaceServlet {
063: protected void doDSPost(Context context,
064: HttpServletRequest request, HttpServletResponse response)
065: throws ServletException, IOException, SQLException,
066: AuthorizeException {
067: doDSGet(context, request, response);
068: }
069:
070: protected void doDSGet(Context context, HttpServletRequest request,
071: HttpServletResponse response) throws ServletException,
072: IOException, SQLException, AuthorizeException {
073: // Are we for selecting a single or multiple epeople?
074: boolean multiple = UIUtil.getBoolParameter(request, "multiple");
075:
076: // What are we sorting by. Lastname is default
077: int sortBy = EPerson.LASTNAME;
078:
079: String sbParam = request.getParameter("sortby");
080:
081: if ((sbParam != null) && sbParam.equals("lastname")) {
082: sortBy = EPerson.LASTNAME;
083: } else if ((sbParam != null) && sbParam.equals("email")) {
084: sortBy = EPerson.EMAIL;
085: } else if ((sbParam != null) && sbParam.equals("id")) {
086: sortBy = EPerson.ID;
087: } else if ((sbParam != null) && sbParam.equals("language")) {
088: sortBy = EPerson.LANGUAGE;
089: }
090:
091: // What's the index of the first eperson to show? Default is 0
092: int first = UIUtil.getIntParameter(request, "first");
093: int offset = UIUtil.getIntParameter(request, "offset");
094: if (first == -1) {
095: first = 0;
096: }
097: if (offset == -1) {
098: offset = 0;
099: }
100:
101: EPerson[] epeople;
102: String search = request.getParameter("search");
103: if (search != null && !search.equals("")) {
104: epeople = EPerson.search(context, search);
105: request.setAttribute("offset", new Integer(offset));
106: } else {
107: // Retrieve the e-people in the specified order
108: epeople = EPerson.findAll(context, sortBy);
109: request.setAttribute("offset", new Integer(0));
110: }
111:
112: // Set attributes for JSP
113: request.setAttribute("sortby", new Integer(sortBy));
114: request.setAttribute("first", new Integer(first));
115: request.setAttribute("epeople", epeople);
116: request.setAttribute("search", search);
117:
118: if (multiple) {
119: request.setAttribute("multiple", new Boolean(true));
120: }
121:
122: JSPManager
123: .showJSP(request, response, "/tools/eperson-list.jsp");
124: }
125: }
|