001: /*
002: * AddEPersonForm.java
003: *
004: * Version: $Revision: 1.0 $
005: *
006: * Date: $Date: 2006/07/13 23:20:54 $
007: *
008: * Copyright (c) 2002, 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.xmlui.aspect.administrative.eperson;
041:
042: import java.sql.SQLException;
043: import java.util.ArrayList;
044:
045: import org.apache.cocoon.environment.ObjectModelHelper;
046: import org.apache.cocoon.environment.Request;
047:
048: import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
049: import org.dspace.app.xmlui.wing.Message;
050: import org.dspace.app.xmlui.wing.WingException;
051: import org.dspace.app.xmlui.wing.element.Body;
052: import org.dspace.app.xmlui.wing.element.CheckBox;
053: import org.dspace.app.xmlui.wing.element.Division;
054: import org.dspace.app.xmlui.wing.element.Item;
055: import org.dspace.app.xmlui.wing.element.List;
056: import org.dspace.app.xmlui.wing.element.PageMeta;
057: import org.dspace.app.xmlui.wing.element.Para;
058: import org.dspace.app.xmlui.wing.element.Text;
059: import org.dspace.authorize.AuthorizeException;
060:
061: /**
062: * Present the user with all the eperson metadata fields so that they
063: * can describe the new eperson before being created. If the user's
064: * input is incorrect in someway then they may be returning here with
065: * some fields in error. In particular there is a special case for the
066: * condition when the email-adress entered is allready in use by
067: * another user.
068: *
069: * @author Alexey Maslov
070: */
071: public class AddEPersonForm extends AbstractDSpaceTransformer {
072: /** Language Strings */
073: private static final Message T_dspace_home = message("xmlui.general.dspace_home");
074:
075: private static final Message T_eperson_trail = message("xmlui.administrative.eperson.general.epeople_trail");
076:
077: private static final Message T_title = message("xmlui.administrative.eperson.AddEPersonForm.title");
078:
079: private static final Message T_trail = message("xmlui.administrative.eperson.AddEPersonForm.trail");
080:
081: private static final Message T_head1 = message("xmlui.administrative.eperson.AddEPersonForm.head1");
082:
083: private static final Message T_email_taken = message("xmlui.administrative.eperson.AddEPersonForm.email_taken");
084:
085: private static final Message T_head2 = message("xmlui.administrative.eperson.AddEPersonForm.head2");
086:
087: private static final Message T_error_email_unique = message("xmlui.administrative.eperson.AddEPersonForm.error_email_unique");
088:
089: private static final Message T_error_email = message("xmlui.administrative.eperson.AddEPersonForm.error_email");
090:
091: private static final Message T_error_fname = message("xmlui.administrative.eperson.AddEPersonForm.error_fname");
092:
093: private static final Message T_error_lname = message("xmlui.administrative.eperson.AddEPersonForm.error_lname");
094:
095: private static final Message T_req_certs = message("xmlui.administrative.eperson.AddEPersonForm.req_certs");
096:
097: private static final Message T_can_log_in = message("xmlui.administrative.eperson.AddEPersonForm.can_log_in");
098:
099: private static final Message T_submit_create = message("xmlui.administrative.eperson.AddEPersonForm.submit_create");
100:
101: private static final Message T_submit_cancel = message("xmlui.general.cancel");
102:
103: /** Language string used from other aspects: */
104:
105: private static final Message T_email_address = message("xmlui.EPerson.EditProfile.email_address");
106:
107: private static final Message T_first_name = message("xmlui.EPerson.EditProfile.first_name");
108:
109: private static final Message T_last_name = message("xmlui.EPerson.EditProfile.last_name");
110:
111: private static final Message T_telephone = message("xmlui.EPerson.EditProfile.telephone");
112:
113: public void addPageMeta(PageMeta pageMeta) throws WingException {
114: pageMeta.addMetadata("title").addContent(T_title);
115: pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
116: pageMeta.addTrailLink(contextPath + "/admin/epeople",
117: T_eperson_trail);
118: pageMeta.addTrail().addContent(T_trail);
119: }
120:
121: public void addBody(Body body) throws WingException, SQLException,
122: AuthorizeException {
123: // Get all our parameters
124: Request request = ObjectModelHelper.getRequest(objectModel);
125:
126: String errorString = parameters.getParameter("errors", null);
127: ArrayList<String> errors = new ArrayList<String>();
128: if (errorString != null) {
129: for (String error : errorString.split(","))
130: errors.add(error);
131: }
132:
133: String emailValue = request.getParameter("email_address");
134: String firstValue = request.getParameter("first_name");
135: String lastValue = request.getParameter("last_name");
136: String phoneValue = request.getParameter("phone");
137: boolean canLogInValue = (request.getParameter("can_log_in") == null) ? false
138: : true;
139: boolean certificateValue = (request.getParameter("certificate") == null) ? false
140: : true;
141:
142: // DIVISION: eperson-add
143: Division add = body.addInteractiveDivision("eperson-add",
144: contextPath + "/admin/epeople", Division.METHOD_POST,
145: "primary administrative eperson");
146:
147: add.setHead(T_head1);
148:
149: if (errors.contains("eperson_email_key")) {
150: Para problem = add.addPara();
151: problem.addHighlight("bold").addContent(T_email_taken);
152: }
153:
154: List identity = add.addList("identity", List.TYPE_FORM);
155: identity.setHead(T_head2);
156:
157: Text email = identity.addItem().addText("email_address");
158: email.setRequired();
159: email.setLabel(T_email_address);
160: email.setValue(emailValue);
161: if (errors.contains("eperson_email_key")) {
162: email.addError(T_error_email_unique);
163: } else if (errors.contains("email_address")) {
164: email.addError(T_error_email);
165: }
166:
167: Text firstName = identity.addItem().addText("first_name");
168: firstName.setRequired();
169: firstName.setLabel(T_first_name);
170: firstName.setValue(firstValue);
171: if (errors.contains("first_name")) {
172: firstName.addError(T_error_fname);
173: }
174:
175: Text lastName = identity.addItem().addText("last_name");
176: lastName.setRequired();
177: lastName.setLabel(T_last_name);
178: lastName.setValue(lastValue);
179: if (errors.contains("last_name")) {
180: lastName.addError(T_error_lname);
181: }
182:
183: Text phone = identity.addItem().addText("phone");
184: phone.setLabel(T_telephone);
185: phone.setValue(phoneValue);
186:
187: CheckBox canLogIn = identity.addItem()
188: .addCheckBox("can_log_in");
189: canLogIn.setLabel(T_can_log_in);
190: canLogIn.addOption(canLogInValue, "yes");
191:
192: CheckBox certificate = identity.addItem().addCheckBox(
193: "certificate");
194: certificate.setLabel(T_req_certs);
195: certificate.addOption(certificateValue, "yes");
196:
197: Item buttons = identity.addItem();
198: buttons.addButton("submit_save").setValue(T_submit_create);
199: buttons.addButton("submit_cancel").setValue(T_submit_cancel);
200:
201: add.addHidden("administrative-continue").setValue(knot.getId());
202: }
203:
204: }
|