Source Code Cross Referenced for EditEPersonForm.java in  » Content-Management-System » dspace » org » dspace » app » xmlui » aspect » administrative » eperson » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » dspace » org.dspace.app.xmlui.aspect.administrative.eperson 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * EditEPersonForm.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:        import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
048:        import org.dspace.app.xmlui.utils.UIException;
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:        import org.dspace.authorize.AuthorizeManager;
061:        import org.dspace.eperson.EPerson;
062:        import org.dspace.eperson.Group;
063:
064:        /**
065:         * Edit an existing EPerson, display all the eperson's metadata 
066:         * along with two special options two reset the eperson's 
067:         * password and delete this user. 
068:         *
069:         * @author Alexey Maslov
070:         */
071:        public class EditEPersonForm 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_submit_save = message("xmlui.general.save");
076:
077:            private static final Message T_submit_cancel = message("xmlui.general.cancel");
078:
079:            private static final Message T_title = message("xmlui.administrative.eperson.EditEPersonForm.title");
080:
081:            private static final Message T_eperson_trail = message("xmlui.administrative.eperson.general.epeople_trail");
082:
083:            private static final Message T_trail = message("xmlui.administrative.eperson.EditEPersonForm.trail");
084:
085:            private static final Message T_head1 = message("xmlui.administrative.eperson.EditEPersonForm.head1");
086:
087:            private static final Message T_email_taken = message("xmlui.administrative.eperson.EditEPersonForm.email_taken");
088:
089:            private static final Message T_head2 = message("xmlui.administrative.eperson.EditEPersonForm.head2");
090:
091:            private static final Message T_error_email_unique = message("xmlui.administrative.eperson.EditEPersonForm.error_email_unique");
092:
093:            private static final Message T_error_email = message("xmlui.administrative.eperson.EditEPersonForm.error_email");
094:
095:            private static final Message T_error_fname = message("xmlui.administrative.eperson.EditEPersonForm.error_fname");
096:
097:            private static final Message T_error_lname = message("xmlui.administrative.eperson.EditEPersonForm.error_lname");
098:
099:            private static final Message T_req_certs = message("xmlui.administrative.eperson.EditEPersonForm.req_certs");
100:
101:            private static final Message T_can_log_in = message("xmlui.administrative.eperson.EditEPersonForm.can_log_in");
102:
103:            private static final Message T_submit_reset_password = message("xmlui.administrative.eperson.EditEPersonForm.submit_reset_password");
104:
105:            private static final Message T_special_help = message("xmlui.administrative.eperson.EditEPersonForm.special_help");
106:
107:            private static final Message T_submit_delete = message("xmlui.administrative.eperson.EditEPersonForm.submit_delete");
108:
109:            private static final Message T_member_head = message("xmlui.administrative.eperson.EditEPersonForm.member_head");
110:
111:            private static final Message T_indirect_member = message("xmlui.administrative.eperson.EditEPersonForm.indirect_member");
112:
113:            private static final Message T_member_none = message("xmlui.administrative.eperson.EditEPersonForm.member_none");
114:
115:            /** Language string used: */
116:
117:            private static final Message T_email_address = message("xmlui.EPerson.EditProfile.email_address");
118:
119:            private static final Message T_first_name = message("xmlui.EPerson.EditProfile.first_name");
120:
121:            private static final Message T_last_name = message("xmlui.EPerson.EditProfile.last_name");
122:
123:            private static final Message T_telephone = message("xmlui.EPerson.EditProfile.telephone");
124:
125:            public void addPageMeta(PageMeta pageMeta) throws WingException {
126:                pageMeta.addMetadata("title").addContent(T_title);
127:                pageMeta.addTrailLink(contextPath + "/", T_dspace_home);
128:                pageMeta.addTrailLink(contextPath + "/admin/epeople",
129:                        T_eperson_trail);
130:                pageMeta.addTrail().addContent(T_trail);
131:            }
132:
133:            public void addBody(Body body) throws WingException, SQLException,
134:                    AuthorizeException {
135:                // Get all our parameters
136:                boolean admin = AuthorizeManager.isAdmin(context);
137:
138:                Request request = ObjectModelHelper.getRequest(objectModel);
139:
140:                // Get our parameters;
141:                int epersonID = parameters.getParameterAsInteger("epersonID",
142:                        -1);
143:                String errorString = parameters.getParameter("errors", null);
144:                ArrayList<String> errors = new ArrayList<String>();
145:                if (errorString != null) {
146:                    for (String error : errorString.split(","))
147:                        errors.add(error);
148:                }
149:
150:                // Grab the person in question 
151:                EPerson eperson = EPerson.find(context, epersonID);
152:
153:                if (eperson == null)
154:                    throw new UIException("Unable to find eperson for id:"
155:                            + epersonID);
156:
157:                String emailValue = eperson.getEmail();
158:                String firstValue = eperson.getFirstName();
159:                String lastValue = eperson.getLastName();
160:                String phoneValue = eperson.getMetadata("phone");
161:                boolean canLogInValue = eperson.canLogIn();
162:                boolean certificatValue = eperson.getRequireCertificate();
163:
164:                if (request.getParameter("email_address") != null)
165:                    emailValue = request.getParameter("email_address");
166:                if (request.getParameter("first_name") != null)
167:                    firstValue = request.getParameter("first_name");
168:                if (request.getParameter("last_name") != null)
169:                    lastValue = request.getParameter("last_name");
170:                if (request.getParameter("phone") != null)
171:                    phoneValue = request.getParameter("phone");
172:
173:                // DIVISION: eperson-edit
174:                Division edit = body.addInteractiveDivision("eperson-edit",
175:                        contextPath + "/admin/epeople", Division.METHOD_POST,
176:                        "primary administrative eperson");
177:                edit.setHead(T_head1);
178:
179:                if (errors.contains("eperson_email_key")) {
180:                    Para problem = edit.addPara();
181:                    problem.addHighlight("bold").addContent(T_email_taken);
182:                }
183:
184:                List identity = edit.addList("form", List.TYPE_FORM);
185:                identity.setHead(T_head2.parameterize(eperson.getFullName()));
186:
187:                if (admin) {
188:                    Text email = identity.addItem().addText("email_address");
189:                    email.setRequired();
190:                    email.setLabel(T_email_address);
191:                    email.setValue(emailValue);
192:                    if (errors.contains("eperson_email_key"))
193:                        email.addError(T_error_email_unique);
194:                    else if (errors.contains("email_address"))
195:                        email.addError(T_error_email);
196:                } else {
197:                    identity.addLabel(T_email_address);
198:                    identity.addItem(emailValue);
199:                }
200:
201:                if (admin) {
202:                    Text firstName = identity.addItem().addText("first_name");
203:                    firstName.setRequired();
204:                    firstName.setLabel(T_first_name);
205:                    firstName.setValue(firstValue);
206:                    if (errors.contains("first_name"))
207:                        firstName.addError(T_error_fname);
208:                } else {
209:                    identity.addLabel(T_first_name);
210:                    identity.addItem(firstValue);
211:                }
212:
213:                if (admin) {
214:                    Text lastName = identity.addItem().addText("last_name");
215:                    lastName.setRequired();
216:                    lastName.setLabel(T_last_name);
217:                    lastName.setValue(lastValue);
218:                    if (errors.contains("last_name"))
219:                        lastName.addError(T_error_lname);
220:                } else {
221:                    identity.addLabel(T_last_name);
222:                    identity.addItem(lastValue);
223:                }
224:
225:                if (admin) {
226:                    Text phone = identity.addItem().addText("phone");
227:                    phone.setLabel(T_telephone);
228:                    phone.setValue(phoneValue);
229:                } else {
230:                    identity.addLabel(T_telephone);
231:                    identity.addItem(phoneValue);
232:                }
233:
234:                if (admin) {
235:                    // Administrative options:
236:
237:                    CheckBox canLogInField = identity.addItem().addCheckBox(
238:                            "can_log_in");
239:                    canLogInField.setLabel(T_can_log_in);
240:                    canLogInField.addOption(canLogInValue, "true");
241:
242:                    CheckBox certificateField = identity.addItem().addCheckBox(
243:                            "certificate");
244:                    certificateField.setLabel(T_req_certs);
245:                    certificateField.addOption(certificatValue, "true");
246:
247:                    identity.addItem().addHighlight("italic").addContent(
248:                            T_special_help);
249:                    Item special = identity.addItem();
250:                    special.addButton("submit_reset_password").setValue(
251:                            T_submit_reset_password);
252:                    special.addButton("submit_delete")
253:                            .setValue(T_submit_delete);
254:                }
255:
256:                Item buttons = identity.addItem();
257:                if (admin)
258:                    buttons.addButton("submit_save").setValue(T_submit_save);
259:                buttons.addButton("submit_cancel").setValue(T_submit_cancel);
260:
261:                if (admin) {
262:                    List member = edit.addList("eperson-member-of");
263:                    member.setHead(T_member_head);
264:
265:                    Group[] groups = Group.allMemberGroups(context, eperson);
266:                    for (Group group : groups) {
267:                        String url = contextPath
268:                                + "/admin/groups?administrative-continue="
269:                                + knot.getId() + "&submit_edit_group&groupID="
270:                                + group.getID();
271:
272:                        Item item = member.addItem();
273:                        item.addXref(url, group.getName());
274:
275:                        // Check if this membership is via another group or not, if so then add a note.
276:                        Group via = findViaGroup(eperson, group);
277:                        if (via != null)
278:                            item.addHighlight("fade").addContent(
279:                                    T_indirect_member.parameterize(via
280:                                            .getName()));
281:
282:                    }
283:
284:                    if (groups.length <= 0)
285:                        member.addItem().addHighlight("italic").addContent(
286:                                T_member_none);
287:
288:                }
289:
290:                edit.addHidden("administrative-continue")
291:                        .setValue(knot.getId());
292:            }
293:
294:            /**
295:             * Determine if the given eperson is a direct member of this group if
296:             * they are not the return the group that membership is implied
297:             * through (the via group!). This will only find one possible relation 
298:             * path, there may be multiple.
299:             * 
300:             * 
301:             * @param eperson The source group to search from
302:             * @param group The target group to search for.
303:             * @return The group this member is related through or null if none found.
304:             */
305:            private Group findViaGroup(EPerson eperson, Group group)
306:                    throws SQLException {
307:                // First check if this eperson is a direct member of the group.
308:                for (EPerson direct : group.getMembers()) {
309:                    if (direct.getID() == eperson.getID())
310:                        // Direct membership
311:                        return null;
312:                }
313:
314:                // Otherwise check what group this eperson is a member through
315:                Group[] targets = group.getMemberGroups();
316:
317:                Group[] groups = Group.allMemberGroups(context, eperson);
318:                for (Group member : groups) {
319:                    for (Group target : targets) {
320:                        if (member.getID() == target.getID())
321:                            return member;
322:                    }
323:                }
324:
325:                // This should never happen, but let's just say we couldn't find the relationship.
326:                return null;
327:            }
328:
329:        }
w_w_w__._j__a__va_2___s___.__co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.