001: /*
002: * SelectEPersonTag.java
003: *
004: * Version: $Revision: 1866 $
005: *
006: * Date: $Date: 2007-04-23 09:20:41 -0500 (Mon, 23 Apr 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.jsptag;
041:
042: import java.io.IOException;
043:
044: import javax.servlet.http.HttpServletRequest;
045: import javax.servlet.jsp.JspException;
046: import javax.servlet.jsp.JspWriter;
047: import javax.servlet.jsp.jstl.fmt.LocaleSupport;
048: import javax.servlet.jsp.tagext.TagSupport;
049:
050: import org.dspace.eperson.EPerson;
051:
052: /**
053: * <p>
054: * Tag for producing an e-person select widget in a form. Somewhat analogous to
055: * the HTML SELECT element. An input field is produced with a button which pops
056: * up a window from which e-people can be selected. Selected e-epeople are added
057: * to the field in the form. If the selector is for multiple e-people, a 'remove
058: * selected from list' button is also added.
059: * </p>
060: *
061: * <p>
062: * On any form that has a selecteperson tag (only one allowed per page), you
063: * need to include the following Javascript code on all of the submit buttons,
064: * to ensure that the e-people IDs are posted and that the popup window is
065: * closed:
066: * </p>
067: *
068: * <p>
069: * <code>onclick="javascript:finishEPerson();"</code>
070: * </p>
071: *
072: * @author Robert Tansley
073: * @version $Revision: 1866 $
074: */
075: public class SelectEPersonTag extends TagSupport {
076: /** Multiple e-people? */
077: private boolean multiple;
078:
079: /** Which eperson/epeople are initially in the list? */
080: private EPerson[] epeople;
081:
082: public SelectEPersonTag() {
083: super ();
084: }
085:
086: /**
087: * Setter for multiple attribute
088: *
089: * @param s
090: * attribute from JSP
091: */
092: public void setMultiple(String s) {
093: if ((s != null)
094: && (s.equalsIgnoreCase("yes") || s
095: .equalsIgnoreCase("true"))) {
096: multiple = true;
097: } else {
098: multiple = false;
099: }
100: }
101:
102: /**
103: * Setter for e-people in list
104: *
105: * @param e
106: * attribute from JSP
107: */
108: public void setSelected(Object e) {
109: if (e instanceof EPerson) {
110: epeople = new EPerson[1];
111: epeople[0] = (EPerson) e;
112: } else if (e instanceof EPerson[]) {
113: epeople = (EPerson[]) e;
114: }
115: }
116:
117: public void release() {
118: multiple = false;
119: epeople = null;
120: }
121:
122: public int doStartTag() throws JspException {
123: try {
124: JspWriter out = pageContext.getOut();
125: HttpServletRequest req = (HttpServletRequest) pageContext
126: .getRequest();
127:
128: out
129: .print("<table><tr><td colspan=\"2\" align=\"center\"><select multiple=\"multiple\" name=\"eperson_id\" size=\"");
130: out.print(multiple ? "10" : "1");
131: out.println("\">");
132: // ensure that if no eperson is selected that a blank option is displayed - xhtml compliance
133: if (epeople == null || epeople.length == 0) {
134: out.print("<option value=\"\"> </option>");
135: }
136:
137: if (epeople != null) {
138: for (int i = 0; i < epeople.length; i++) {
139: out.print("<option value=\"" + epeople[i].getID()
140: + "\">");
141: out.print(epeople[i].getFullName() + " ("
142: + epeople[i].getEmail() + ")");
143: out.println("</option>");
144: }
145: }
146: // add blank option value if no person selected to ensure that code is xhtml compliant
147: //out.print("<option/>");
148: out.print("</select></td>");
149:
150: if (multiple) {
151: out
152: .print("</tr><tr><td width=\"50%\" align=\"center\">");
153: } else {
154: out.print("<td>");
155: }
156:
157: String p = (multiple ? LocaleSupport
158: .getLocalizedMessage(pageContext,
159: "org.dspace.app.webui.jsptag.SelectEPersonTag.selectPeople")
160: : LocaleSupport
161: .getLocalizedMessage(pageContext,
162: "org.dspace.app.webui.jsptag.SelectEPersonTag.selectPerson"));
163: out.print("<input type=\"button\" value=\"" + p
164: + "\" onclick=\"javascript:popup_window('"
165: + req.getContextPath()
166: + "/tools/eperson-list?multiple=" + multiple
167: + "', 'eperson_popup');\" />");
168:
169: if (multiple) {
170: out.print("</td><td width=\"50%\" align=\"center\">");
171: out
172: .print("<input type=\"button\" value=\""
173: + LocaleSupport
174: .getLocalizedMessage(
175: pageContext,
176: "org.dspace.app.webui.jsptag.SelectEPersonTag.removeSelected")
177: + "\" onclick=\"javascript:removeSelected(window.document.epersongroup.eperson_id);\"/>");
178: }
179:
180: out.println("</td></tr></table>");
181: } catch (IOException ie) {
182: throw new JspException(ie);
183: }
184:
185: return SKIP_BODY;
186: }
187: }
|