KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsAdminUsers


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminUsers.java,v $
3 * Date : $Date: 2006/03/27 14:52:36 $
4 * Version: $Revision: 1.7 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29
30 package com.opencms.workplace;
31
32 import org.opencms.db.CmsUserSettings;
33 import org.opencms.file.CmsGroup;
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsRequestContext;
36 import org.opencms.file.CmsUser;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.OpenCms;
40
41 import com.opencms.core.I_CmsSession;
42 import com.opencms.legacy.CmsLegacyException;
43 import com.opencms.legacy.CmsLegacySecurityException;
44 import com.opencms.legacy.CmsXmlTemplateLoader;
45
46 import java.util.Enumeration JavaDoc;
47 import java.util.Hashtable JavaDoc;
48 import java.util.List JavaDoc;
49 import java.util.Vector JavaDoc;
50
51 /**
52  * Template class for displaying OpenCms workplace admin users screens.
53  * <P>
54  *
55  * @author Mario Stanke
56  * @version $Revision: 1.7 $ $Date: 2006/03/27 14:52:36 $
57  * @see com.opencms.workplace.CmsXmlWpTemplateFile
58  *
59  * @deprecated Will not be supported past the OpenCms 6 release.
60  */

61
62 public class CmsAdminUsers extends CmsWorkplaceDefault {
63
64     /**
65      * change the groups of the user
66      * <P>
67      * the Vector newGroups holds all groups, which theUser will be in afterwards
68      * the amount of database access is kept small with this funcion
69      * @param cms CmsObject Object for accessing system resources.
70      * @param theUser the user whose data will be changed
71      * @param newGroups Vector of Strings with the names of the new groups of theUser
72      * @throws CmsException
73      */

74
75     private void changeGroups(CmsObject cms, CmsUser theUser, Vector JavaDoc newGroups) throws CmsException {
76         String JavaDoc username = theUser.getName();
77         List JavaDoc oldGroups = cms.getGroupsOfUser(username);
78         List JavaDoc oldGroupnames = new Vector JavaDoc();
79
80         cms.writeUser(theUser); // update in the database
81
theUser = cms.readUser(username);
82         if(oldGroups != null) {
83             for(int z = 0;z < oldGroups.size();z++) {
84                 oldGroupnames.add(((CmsGroup)oldGroups.get(z)).getName());
85             }
86
87             // delete the user from the groups which are not in newGroups
88
for(int z = 0;z < oldGroupnames.size();z++) {
89                 String JavaDoc groupname = (String JavaDoc)oldGroupnames.get(z);
90                 if(!newGroups.contains(groupname)) {
91                     try {
92                         cms.removeUserFromGroup(username, groupname);
93                     }catch(CmsException e) {
94                     // can happen when this group has been deleted _indirectly_ before
95
}
96                 }
97             }
98         }
99         if(newGroups != null) {
100
101             // now add the user to the new groups, which he not yet belongs to
102
for(int z = 0;z < newGroups.size();z++) {
103                 String JavaDoc groupname = (String JavaDoc)newGroups.elementAt(z);
104                 if(!cms.userInGroup(username, groupname)) {
105                     cms.addUserToGroup(username, groupname);
106                 }
107             }
108         }
109         cms.writeUser(theUser); // update in the database
110
theUser = cms.readUser(username);
111     }
112
113     /**
114      * Gets the content of a defined section in a given template file and its subtemplates
115      * with the given parameters.
116      *
117      * @see #getContent(CmsObject, String, String, Hashtable, String)
118      * @param cms CmsObject Object for accessing system resources.
119      * @param templateFile Filename of the template file.
120      * @param elementName Element name of this template in our parent template.
121      * @param parameters Hashtable with all template class parameters.
122      * @param templateSelector template section that should be processed.
123      */

124
125     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
126             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
127
128         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
129             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
130             CmsLog.getLog(this).debug("Template file is: " + templateFile);
131             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
132         }
133         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
134         CmsRequestContext reqCont = cms.getRequestContext();
135         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
136         boolean userYetChanged = true;
137         boolean userYetEstablished = true;
138
139         // find out which template (=perspective) should be used
140
String JavaDoc perspective = (String JavaDoc)parameters.get("perspective");
141         if(perspective != null && perspective.equals("user")) {
142             session.removeValue("ERROR");
143             if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("CHANGE") != null) {
144
145                 // change data of selected user
146
perspective = "changeuser";
147                 userYetChanged = false;
148             }else {
149                 if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("DELETE") != null) {
150
151                     // delete the selected user
152
perspective = "deleteuser";
153                 }else {
154                     if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("NEW") != null) {
155
156                         // establish a new user
157
perspective = "newuser";
158                         userYetEstablished = false;
159                     }
160                 }
161             }
162         }
163         if(perspective == null) {
164
165             // display the first template, which lets you chose the action
166
perspective = new String JavaDoc("user");
167         }
168         if(perspective.equals("newuser") || perspective.equals("changeuser")) {
169
170             // first the common part of the two actions:
171
// read the common parameters like first name, description, ...
172
String JavaDoc firstname, desc, street, pwd, pwd2, user, userLastname, town, zipcode,
173                     email, defaultGroup;
174             if(session.getValue("ERROR") == null) {
175                 firstname = (String JavaDoc)parameters.get("USERFIRSTNAME");
176                 desc = (String JavaDoc)parameters.get("USERDESC");
177                 street = (String JavaDoc)parameters.get("USERSTREET");
178                 pwd = (String JavaDoc)parameters.get("PWD");
179                 pwd2 = (String JavaDoc)parameters.get("PWD2");
180                 user = (String JavaDoc)parameters.get("USER");
181                 userLastname = (String JavaDoc)parameters.get("USERNAME");
182                 town = (String JavaDoc)parameters.get("TOWN");
183                 zipcode = (String JavaDoc)parameters.get("ZIP");
184                 email = (String JavaDoc)parameters.get("USEREMAIL");
185                 defaultGroup = (String JavaDoc)parameters.get("DEFAULTGROUP");
186             }else {
187
188                 // an error has occurred before, retrieve the form data from the session
189
firstname = (String JavaDoc)session.getValue("USERFIRSTNAME");
190                 desc = (String JavaDoc)session.getValue("USERDESC");
191                 street = (String JavaDoc)session.getValue("USERSTREET");
192                 pwd = (String JavaDoc)session.getValue("PWD");
193                 pwd2 = (String JavaDoc)session.getValue("PWD2");
194                 user = (String JavaDoc)session.getValue("USER");
195                 userLastname = (String JavaDoc)session.getValue("USERNAME");
196                 town = (String JavaDoc)session.getValue("TOWN");
197                 zipcode = (String JavaDoc)session.getValue("ZIP");
198                 email = (String JavaDoc)session.getValue("USEREMAIL");
199                 defaultGroup = (String JavaDoc)session.getValue("DEFAULTGROUP");
200                 session.removeValue("ERROR");
201             }
202             if(firstname == null) {
203                 firstname = "";
204             }
205             if(desc == null) {
206                 desc = "";
207             }
208             if(street == null) {
209                 street = "";
210             }
211             if(pwd == null) {
212                 pwd = "";
213             }
214             if(pwd2 == null) {
215                 pwd2 = "";
216             }
217             if(user == null) {
218                 user = "";
219             }
220             if(userLastname == null) {
221                 userLastname = "";
222             }
223             if(town == null) {
224                 town = "";
225             }
226             if(zipcode == null) {
227                 zipcode = "";
228             }
229             if(email == null) {
230                 email = "";
231             }
232             if(defaultGroup == null) {
233                 defaultGroup = "";
234             }
235
236             // vectors of Strings that hold the selected and not selected Groups
237
Vector JavaDoc selectedGroups = (Vector JavaDoc)session.getValue("selectedGroups");
238             Vector JavaDoc notSelectedGroups = (Vector JavaDoc)session.getValue("notSelectedGroups");
239             if(perspective.equals("newuser")) {
240
241                 // input is the form for establishing new users
242
templateSelector = "newuser";
243                 if(!userYetEstablished) {
244
245                     // first time the form is visited
246
user = "";
247                     selectedGroups = new Vector JavaDoc();
248                     notSelectedGroups = new Vector JavaDoc();
249                     selectedGroups.addElement(OpenCms.getDefaultUsers().getGroupUsers()); // preselect Users
250
List JavaDoc groups = cms.getGroups();
251                     for(int z = 0;z < groups.size();z++) {
252                         String JavaDoc aName = ((CmsGroup)groups.get(z)).getName();
253                         if(!OpenCms.getDefaultUsers().getGroupUsers().equals(aName)) {
254                             notSelectedGroups.addElement(aName);
255                         }
256                     }
257                     session.putValue("selectedGroups", selectedGroups);
258                     session.putValue("notSelectedGroups", notSelectedGroups);
259                 }
260                 if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("ADD") != null) {
261
262                     // add a new group to selectedGroups
263
String JavaDoc groupname = (String JavaDoc)parameters.get("notselectgroup");
264                     if(groupname != null) {
265                         selectedGroups.addElement(groupname);
266                         notSelectedGroups.removeElement(groupname);
267                     }
268                     session.putValue("selectedGroups", selectedGroups);
269                     session.putValue("notSelectedGroups", notSelectedGroups);
270                 }else {
271                     if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("REMOVE") != null) {
272
273                         // delete a new group from selectedGroups
274
// and move it to notSelectedGroups
275
String JavaDoc groupname = (String JavaDoc)parameters.get("selectgroup");
276                         if(groupname != null) {
277                             notSelectedGroups.addElement(groupname);
278                             selectedGroups.removeElement(groupname);
279                             if(groupname.equals(defaultGroup)) {
280                                 defaultGroup = "";
281                             }
282                         }
283                         session.putValue("selectedGroups", selectedGroups);
284                         session.putValue("notSelectedGroups", notSelectedGroups);
285                     }else {
286                         if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("OK") != null) {
287
288                             // form submitted, try to establish new user
289
try {
290                                 if(email.equals("") || userLastname.equals("")
291                                         || user.equals("")) {
292                                     throw new CmsLegacyException("user data missing",
293                                         CmsLegacyException.C_NO_USER);
294                                 }
295                                 if(!pwd.equals(pwd2)) {
296                                     throw new CmsLegacyException("unequal passwords",
297                                         CmsLegacyException.C_SECURITY_INVALID_PASSWORD);
298                                 }
299                                 // check the password
300
cms.validatePassword(pwd);
301
302                                 Hashtable JavaDoc additionalInfo = new Hashtable JavaDoc();
303
304                                 // additionalInfo.put(C_ADDITIONAL_INFO_ZIPCODE, zipcode);
305
// additionalInfo.put(C_ADDITIONAL_INFO_TOWN, town);
306
CmsUser newUser = cms.createUser(user, pwd, desc, additionalInfo);
307                                 newUser.setEmail(email);
308                                 newUser.setFirstname(firstname);
309                                 newUser.setLastname(userLastname);
310                                 newUser.setAddress(street);
311                                 newUser.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_ZIPCODE, zipcode);
312                                 newUser.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_CITY, town);
313                                 newUser.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DEFAULTGROUP, defaultGroup);
314                                 for(int z = 0;z < selectedGroups.size();z++) {
315                                     String JavaDoc groupname = (String JavaDoc)selectedGroups.elementAt(z);
316                                     cms.addUserToGroup(user, groupname);
317                                 }
318                                 cms.writeUser(newUser); // update in the database
319
session.removeValue("selectedGroups");
320                                 session.removeValue("notSelectedGroups");
321                                 session.removeValue("ERROR");
322                                 templateSelector = ""; //successful
323
}catch(CmsException e) {
324
325                                 // save the form data in the session, so it can be displayed again later
326
session.putValue("ERROR", new String JavaDoc("yes")); // remeber that an error has occurred
327
session.putValue("USERFIRSTNAME", firstname);
328                                 session.putValue("USERDESC", desc);
329                                 session.putValue("USERSTREET", street);
330                                 session.putValue("PWD", pwd);
331                                 session.putValue("PWD2", pwd2);
332                                 session.putValue("USER", user);
333                                 session.putValue("USERNAME", userLastname);
334                                 session.putValue("ZIP", zipcode);
335                                 session.putValue("TOWN", town);
336                                 session.putValue("USEREMAIL", email);
337                                 session.putValue("DEFAULTGROUP", defaultGroup);
338                                 if ((e instanceof CmsLegacySecurityException) && (((CmsLegacySecurityException)e).getType() == CmsLegacySecurityException.C_SECURITY_INVALID_PASSWORD)) {
339                                     if(e.getMessage().equals("unequal passwords")) {
340                                         templateSelector = "passworderror1";
341                                     }else {
342                                         if(e.getMessage().equals("password too short")) {
343                                             templateSelector = "passworderror2";
344                                         }else {
345                                             xmlTemplateDocument.setData("reasonOfError", e.getMessage());
346                                             xmlTemplateDocument.setData("perspective", "newuser");
347                                             templateSelector = "passworderror5";
348                                         }
349                                     }
350                                 }else {
351                                     if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_GROUP)) {
352                                         templateSelector = "errornogroup1";
353                                     }else {
354                                         if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NOT_FOUND && e.getMessage().equals("user data missing"))) {
355                                             templateSelector = "errordatamissing1";
356                                         }else {
357                                             // unknown error
358
xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(e));
359                                             templateSelector = "error";
360                                         }
361                                     }
362                                 }
363                             } // catch block
364
} // OK
365
}
366                 }
367             }else {
368
369                 // input is the form for changing the user data
370
templateSelector = "changeuser";
371                 boolean disabled = false;
372                 if(!userYetChanged) {
373
374                     // form visited for the first time, not yet changed
375
// read the data from the user object
376
CmsUser theUser = cms.readUser(user);
377                     if(theUser == null) {
378                         throw new CmsLegacyException("user does not exist");
379                     }
380                     firstname = theUser.getFirstname();
381                     desc = theUser.getDescription();
382                     street = theUser.getAddress();
383                     userLastname = theUser.getLastname();
384                     email = theUser.getEmail();
385                     disabled = !theUser.isEnabled();
386                     zipcode = (String JavaDoc)theUser.getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_ZIPCODE);
387                     town = (String JavaDoc)theUser.getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_CITY);
388                     defaultGroup = (String JavaDoc)theUser.getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DEFAULTGROUP);
389                     List JavaDoc groups = cms.getDirectGroupsOfUser(user);
390                     if(groups != null) {
391                         selectedGroups = new Vector JavaDoc();
392                         for(int z = 0;z < groups.size();z++) {
393                             selectedGroups.addElement(((CmsGroup)groups.get(z)).getName());
394                         }
395                     }else {
396                         throw new CmsLegacyException(CmsLegacyException.C_NO_GROUP);
397                     }
398                     groups = cms.getGroups();
399                     if(groups != null) {
400                         notSelectedGroups = new Vector JavaDoc();
401                         for(int z = 0;z < groups.size();z++) {
402                             String JavaDoc name = ((CmsGroup)groups.get(z)).getName();
403                             if(!selectedGroups.contains(name)) {
404                                 notSelectedGroups.addElement(name);
405                             }
406                         }
407                     }
408                 }else {
409
410                     // fetch data from the form
411
if((String JavaDoc)parameters.get("LOCK") != null) {
412                         disabled = true;
413                     }
414                     if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("ADD") != null) {
415
416                         // add a new group to selectedGroups
417
String JavaDoc groupname = (String JavaDoc)parameters.get("notselectgroup");
418                         if(groupname != null) {
419                             if(!selectedGroups.contains(groupname)){
420                                 selectedGroups.addElement(groupname);
421                             }
422                             notSelectedGroups.removeElement(groupname);
423                         }
424                     }else {
425                         if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("REMOVE") != null) {
426
427                             // delete a group from selectedGroups
428
// and move it to notSelectedGroups
429
String JavaDoc groupname = (String JavaDoc)parameters.get("selectgroup");
430                             if(groupname != null) {
431                                 if(!notSelectedGroups.contains(groupname)){
432                                     notSelectedGroups.addElement(groupname);
433                                     if(groupname.equals(defaultGroup)) {
434                                         defaultGroup = "";
435                                     }
436                                 }
437                                 selectedGroups.removeElement(groupname);
438                             }
439                         }else {
440                             if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("OK") != null) {
441
442                                 // form submitted, try to change the user data
443
try {
444                                     if(email.equals("") || userLastname.equals("")
445                                             || user.equals("")) {
446                                         throw new CmsLegacyException("user data missing",
447                                             CmsLegacyException.C_NO_USER);
448                                     }
449                                     if(!pwd.equals(pwd2)) {
450                                         throw new CmsLegacySecurityException("unequal passwords",
451                                             CmsLegacySecurityException.C_SECURITY_INVALID_PASSWORD);
452                                     }
453                                     if(!pwd.equals("")) {
454                                         cms.setPassword(user, pwd);
455                                     } // if nothing is entered don't change the password
456
CmsUser theUser = cms.readUser(user);
457                                     theUser.setEmail(email);
458                                     theUser.setDescription(desc);
459                                     theUser.setFirstname(firstname);
460                                     theUser.setLastname(userLastname);
461                                     theUser.setAddress(street);
462                                     theUser.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_ZIPCODE, zipcode);
463                                     theUser.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_CITY, town);
464                                     theUser.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DEFAULTGROUP, defaultGroup);
465                                     if((OpenCms.getDefaultUsers().getUserAdmin().equals(theUser.getName()))
466                                             && (!selectedGroups.contains(OpenCms.getDefaultUsers().getGroupAdministrators()))) {
467                                         throw new CmsLegacyException("cant remove Admin from "
468                                                 + OpenCms.getDefaultUsers().getGroupAdministrators(), CmsLegacyException.C_NOT_ADMIN);
469                                     }
470                                     if(disabled && selectedGroups.contains(OpenCms.getDefaultUsers().getGroupAdministrators())) {
471                                         throw new CmsLegacyException("disabled admin",
472                                             CmsLegacyException.C_NOT_ADMIN);
473                                     }
474                                     theUser.setEnabled(!disabled);
475                                     changeGroups(cms, theUser, selectedGroups);
476                                     session.removeValue("selectedGroups");
477                                     session.removeValue("notSelectedGroups");
478                                     session.removeValue("DEFAULTGROUP");
479                                     session.removeValue("ERROR");
480                                     templateSelector = ""; //successful
481
}catch(CmsException e) {
482                                     session.putValue("ERROR", new String JavaDoc("yes")); // remeber that an error has occurred
483
session.putValue("USERFIRSTNAME", firstname);
484                                     session.putValue("USERDESC", desc);
485                                     session.putValue("USERSTREET", street);
486                                     session.putValue("PWD", pwd);
487                                     session.putValue("PWD2", pwd2);
488                                     session.putValue("USER", user);
489                                     session.putValue("USERNAME", userLastname);
490                                     session.putValue("ZIP", zipcode);
491                                     session.putValue("TOWN", town);
492                                     session.putValue("USEREMAIL", email);
493                                     session.putValue("DEFAULTGROUP", defaultGroup);
494                                     if ((e instanceof CmsLegacySecurityException) && (((CmsLegacySecurityException)e).getType() == CmsLegacyException.C_SECURITY_INVALID_PASSWORD)) {
495                                         if(e.getMessage().equals("unequal passwords")) {
496                                             templateSelector = "passworderror3";
497                                         }else {
498                                             if(e.getMessage().equals("password too short")) {
499                                                 templateSelector = "passworderror4";
500                                             }else {
501                                                 xmlTemplateDocument.setData("reasonOfError", e.getMessage());
502                                                 xmlTemplateDocument.setData("perspective", "changeuser");
503                                                 templateSelector = "passworderror5";
504                                             }
505                                         }
506                                     }else {
507                                         if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_GROUP)) {
508                                             templateSelector = "errornogroup2";
509                                         }else {
510                                             if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_USER && e.getMessage().equals("user data missing"))) {
511                                                 templateSelector = "errordatamissing2";
512                                             }else {
513                                                 if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NOT_ADMIN && e.getMessage().equals("disabled admin"))) {
514                                                     templateSelector = "errordisabledadmin";
515                                                 }else {
516                                                     session.putValue("ERROR", new String JavaDoc("yes"));
517                                                     throw e; // hand the exception down
518
}
519                                             }
520                                         }
521                                     }
522                                 } // catch block
523
} // OK
524
}
525                     }
526                 } // userYetEstablished
527
session.putValue("selectedGroups", selectedGroups);
528                 session.putValue("notSelectedGroups", notSelectedGroups);
529                 session.putValue("DEFAULTGROUP", defaultGroup);
530                 xmlTemplateDocument.setData("DISABLED", disabled ? "checked" : "");
531             }
532
533             // again common part for 'newuser' and 'changeuser':
534
// set the variables for display in the document
535
if(firstname == null) {
536                 firstname = "";
537             }
538             if(desc == null) {
539                 desc = "";
540             }
541             if(street == null) {
542                 street = "";
543             }
544             if(pwd == null) {
545                 pwd = "";
546             }
547             if(pwd2 == null) {
548                 pwd2 = "";
549             }
550             if(user == null) {
551                 user = "";
552             }
553             if(userLastname == null) {
554                 userLastname = "";
555             }
556             if(town == null) {
557                 town = "";
558             }
559             if(zipcode == null) {
560                 zipcode = "";
561             }
562             if(email == null) {
563                 email = "";
564             }
565             xmlTemplateDocument.setData("USERFIRSTNAME", firstname);
566             xmlTemplateDocument.setData("USERDESC", desc);
567             xmlTemplateDocument.setData("USERSTREET", street);
568             xmlTemplateDocument.setData("PWD", pwd);
569             xmlTemplateDocument.setData("PWD2", pwd2);
570             xmlTemplateDocument.setData("USER", user);
571             xmlTemplateDocument.setData("USERNAME", userLastname);
572             xmlTemplateDocument.setData("TOWN", town);
573             xmlTemplateDocument.setData("ZIP", zipcode);
574             xmlTemplateDocument.setData("EMAIL", email);
575         } // belongs to: 'if perspective is newuser or changeuser'
576
else {
577             if(perspective.equals("deleteuser")) {
578                 String JavaDoc user = (String JavaDoc)parameters.get("USER");
579                 xmlTemplateDocument.setData("USER", user);
580                 templateSelector = "RUsureDelete";
581             }else {
582                 if(perspective.equals("reallydeleteuser")) {
583
584                     // deleting a user
585
String JavaDoc user = (String JavaDoc)parameters.get("USER");
586                     try {
587                         cms.deleteUser(user);
588                         templateSelector = "";
589                     }catch(Exception JavaDoc e) {
590
591                         // user == null or delete failed
592
xmlTemplateDocument.setData("DELETEDETAILS", CmsException.getStackTraceAsString(e));
593                         templateSelector = "deleteerror";
594                     }
595                 } // delete user
596
}
597         }
598
599         // Now load the template file and start the processing
600
return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
601                 templateSelector);
602     }
603
604     /**
605      * Gets all groups, that may work for a project.
606      * <P>
607      * The given vectors <code>names</code> and <code>values</code> will
608      * be filled with the appropriate information to be used for building
609      * a select box.
610      *
611      * @param cms CmsObject Object for accessing system resources.
612      * @param names Vector to be filled with the appropriate values in this method.
613      * @param values Vector to be filled with the appropriate values in this method.
614      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
615      * @return Index representing the current value in the vectors.
616      * @throws CmsException
617      */

618
619     public Integer JavaDoc getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
620             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
621
622         // get all groups
623
List JavaDoc groups = cms.getGroups();
624         int retValue = -1;
625
626         // fill the names and values
627
for(int z = 0;z < groups.size();z++) {
628             String JavaDoc name = ((CmsGroup)groups.get(z)).getName();
629             if(OpenCms.getDefaultUsers().getGroupUsers().equals(name)) {
630                 retValue = z;
631             }
632             names.addElement(name);
633             values.addElement(name);
634         }
635         return new Integer JavaDoc(retValue);
636     }
637
638     /**
639      * Gets all groups in which the user is, i.e. the selected ones and the indirect ones
640      * The given vectors <code>names</code> and <code>values</code> will
641      * be filled with the appropriate information to be used for building
642      * a select box.
643      *
644      * @param cms CmsObject Object for accessing system resources.
645      * @param names Vector to be filled with the appropriate values in this method.
646      * @param values Vector to be filled with the appropriate values in this method.
647      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
648      * @return Index representing the default Group of the user
649      * @throws CmsException
650      */

651
652     public Integer JavaDoc getGroupsOfUser(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
653             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
654         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
655         String JavaDoc defaultGroup = (String JavaDoc)session.getValue("DEFAULTGROUP");
656         if(defaultGroup == null) {
657             defaultGroup = "";
658         }
659         getSelectedGroups(cms, lang, names, values, parameters);
660         getIndirectGroups(cms, lang, names, values, parameters);
661         return new Integer JavaDoc(names.indexOf(defaultGroup));
662     }
663
664     /**
665      * Gets all groups in which the user is but not the direct ones
666      * <P>
667      * The given vectors <code>names</code> and <code>values</code> will
668      * be filled with the appropriate information to be used for building
669      * a select box.
670      *
671      * @param cms CmsObject Object for accessing system resources.
672      * @param names Vector to be filled with the appropriate values in this method.
673      * @param values Vector to be filled with the appropriate values in this method.
674      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
675      * @return Index representing the default Group of the user
676      * @throws CmsException
677      */

678
679     public Integer JavaDoc getIndirectGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
680             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
681         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
682         Vector JavaDoc selectedGroups = (Vector JavaDoc)session.getValue("selectedGroups");
683         Vector JavaDoc indirectGroups = new Vector JavaDoc();
684         String JavaDoc groupname, superGroupName;
685         CmsGroup superGroup;
686         if(selectedGroups != null) {
687
688             // get all parents of the groups
689
Enumeration JavaDoc enu = selectedGroups.elements();
690             while(enu.hasMoreElements()) {
691                 groupname = (String JavaDoc)enu.nextElement();
692                 superGroup = cms.getParent(groupname);
693                 while((superGroup != null) && (!indirectGroups.contains(superGroup.getName()))) {
694                     superGroupName = superGroup.getName();
695                     indirectGroups.addElement(superGroupName);
696
697                     // read next super group
698
superGroup = cms.getParent(superGroupName);
699                 }
700             }
701
702             // now remove the direct groups off the list
703
for(int z = 0;z < selectedGroups.size();z++) {
704                 String JavaDoc name = (String JavaDoc)selectedGroups.elementAt(z);
705                 indirectGroups.removeElement(name);
706             }
707         }
708         for(int z = 0;z < indirectGroups.size();z++) {
709             String JavaDoc name = (String JavaDoc)indirectGroups.elementAt(z);
710             names.addElement(name);
711             values.addElement(name);
712         }
713         return new Integer JavaDoc(-1); // none preselected
714
}
715
716     /**
717      * Gets all groups, that have not yet been selected for the user
718      * <P>
719      * The given vectors <code>names</code> and <code>values</code> will
720      * be filled with the appropriate information to be used for building
721      * a select box.
722      *
723      * @param cms CmsObject Object for accessing system resources.
724      * @param names Vector to be filled with the appropriate values in this method.
725      * @param values Vector to be filled with the appropriate values in this method.
726      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
727      * @return Index representing the current value in the vectors.
728      * @throws CmsException
729      */

730
731     public Integer JavaDoc getNotSelectedGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
732             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
733         int retValue = -1;
734         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
735         Vector JavaDoc notSelectedGroups = (Vector JavaDoc)session.getValue("notSelectedGroups");
736         if(notSelectedGroups != null) {
737
738             // fill the names and values
739
for(int z = 0;z < notSelectedGroups.size();z++) {
740                 String JavaDoc name = (String JavaDoc)notSelectedGroups.elementAt(z);
741                 if(OpenCms.getDefaultUsers().getGroupUsers().equals(name)) {
742                     retValue = z;
743                 }
744                 names.addElement(name);
745                 values.addElement(name);
746             }
747         }
748
749         // no current group, set index to -1
750
return new Integer JavaDoc(retValue);
751     }
752
753     /**
754      * Gets all groups that have been selected for the user to be in
755      * <P>
756      * The given vectors <code>names</code> and <code>values</code> will
757      * be filled with the appropriate information to be used for building
758      * a select box.
759      *
760      * @param cms CmsObject Object for accessing system resources.
761      * @param names Vector to be filled with the appropriate values in this method.
762      * @param values Vector to be filled with the appropriate values in this method.
763      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
764      * @return Index representing the default Group of the user
765      * @throws CmsException
766      */

767
768     public Integer JavaDoc getSelectedGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
769             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
770         int retValue = -1;
771         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
772         String JavaDoc defaultGroup = (String JavaDoc)session.getValue("DEFAULTGROUP");
773         if(defaultGroup == null) {
774             defaultGroup = "";
775         }
776         Vector JavaDoc selectedGroups = (Vector JavaDoc)session.getValue("selectedGroups");
777         if(selectedGroups != null) {
778             for(int z = 0;z < selectedGroups.size();z++) {
779                 String JavaDoc name = (String JavaDoc)selectedGroups.elementAt(z);
780                 if(name.equals(defaultGroup)) {
781                     retValue = z;
782                 }
783                 names.addElement(name);
784                 values.addElement(name);
785             }
786         }else {
787             selectedGroups = new Vector JavaDoc();
788         }
789         return new Integer JavaDoc(retValue);
790     }
791
792     /**
793      * Gets all users
794      * <P>
795      * The given vectors <code>names</code> and <code>values</code> will
796      * be filled with the appropriate information to be used for building
797      * a select box.
798      *
799      * @param cms CmsObject Object for accessing system resources.
800      * @param names Vector to be filled with the appropriate values in this method.
801      * @param values Vector to be filled with the appropriate values in this method.
802      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
803      * @return Index representing the current value in the vectors.
804      * @throws CmsException
805      */

806
807     public Integer JavaDoc getUsers(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names,
808             Vector JavaDoc values, Hashtable JavaDoc parameters) throws CmsException {
809
810         // get all users
811
List JavaDoc users = cms.getUsers();
812         int retValue = -1;
813         String JavaDoc firsname;
814         String JavaDoc lastname;
815         String JavaDoc username;
816         String JavaDoc nameToShow;
817
818         // fill the names and values
819
for(int z = 0;z < users.size();z++) {
820             firsname = ((CmsUser)users.get(z)).getFirstname();
821             //Changed by Le (comundus GmbH)
822
lastname = ((CmsUser)users.get(z)).getLastname();
823             username = ((CmsUser)users.get(z)).getName();
824             nameToShow = username + " - " + firsname + " " + lastname;
825             //***
826
names.addElement(nameToShow);
827             values.addElement(username);
828         }
829         if(users.size() > 0) {
830             retValue = 0; // preselect first user
831
}
832         return new Integer JavaDoc(retValue);
833
834
835     }
836     
837     /**
838      * Determines if the user icon is shown in the administration view depending on the property value of the key "workplace.administration.showusergroupicon".<p>
839      *
840      * @param cms the CmsObject
841      * @param lang the workplace language file
842      * @param parameters the parameters
843      * @return Boolean to determine if user icon is shown in the administration view
844      */

845     public Boolean JavaDoc isVisible(CmsObject cms, CmsXmlLanguageFile lang, Hashtable JavaDoc parameters) {
846         return new Boolean JavaDoc(OpenCms.getWorkplaceManager().showUserGroupIcon());
847     }
848
849     /**
850      * Indicates if the results of this class are cacheable.
851      *
852      * @param cms CmsObject Object for accessing system resources
853      * @param templateFile Filename of the template file
854      * @param elementName Element name of this template in our parent template.
855      * @param parameters Hashtable with all template class parameters.
856      * @param templateSelector template section that should be processed.
857      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
858      */

859
860     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
861             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
862         return false;
863     }
864 }
865
Popular Tags