001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsEditUserDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:27 $
004: * Version: $Revision: 1.12 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.accounts;
033:
034: import org.opencms.db.CmsUserSettings;
035: import org.opencms.file.CmsUser;
036: import org.opencms.i18n.CmsLocaleManager;
037: import org.opencms.jsp.CmsJspActionElement;
038: import org.opencms.main.CmsException;
039: import org.opencms.main.OpenCms;
040: import org.opencms.security.CmsOrganizationalUnit;
041: import org.opencms.security.CmsPasswordInfo;
042: import org.opencms.security.CmsRole;
043: import org.opencms.site.CmsSite;
044: import org.opencms.util.CmsStringUtil;
045: import org.opencms.util.CmsUUID;
046: import org.opencms.widgets.CmsCheckboxWidget;
047: import org.opencms.widgets.CmsDisplayWidget;
048: import org.opencms.widgets.CmsGroupWidget;
049: import org.opencms.widgets.CmsInputWidget;
050: import org.opencms.widgets.CmsPasswordWidget;
051: import org.opencms.widgets.CmsSelectWidget;
052: import org.opencms.widgets.CmsSelectWidgetOption;
053: import org.opencms.widgets.CmsTextareaWidget;
054: import org.opencms.workplace.CmsDialog;
055: import org.opencms.workplace.CmsWidgetDialog;
056: import org.opencms.workplace.CmsWidgetDialogParameter;
057: import org.opencms.workplace.CmsWorkplaceSettings;
058: import org.opencms.workplace.tools.CmsToolManager;
059:
060: import java.util.ArrayList;
061: import java.util.HashMap;
062: import java.util.Iterator;
063: import java.util.List;
064: import java.util.Locale;
065: import java.util.Map;
066:
067: import javax.servlet.http.HttpServletRequest;
068:
069: /**
070: * Dialog to edit new or existing user in the administration view.<p>
071: *
072: * @author Michael Moossen
073: *
074: * @version $Revision: 1.12 $
075: *
076: * @since 6.0.0
077: */
078: public abstract class A_CmsEditUserDialog extends CmsWidgetDialog {
079:
080: /** localized messages Keys prefix. */
081: public static final String KEY_PREFIX = "user";
082:
083: /** Defines which pages are valid for this dialog. */
084: public static final String[] PAGES = { "page1" };
085:
086: /** Request parameter name for the user id. */
087: public static final String PARAM_USERID = "userid";
088:
089: /** Session parameter name for the pwd info object. */
090: private static final String PWD_OBJECT = "PWD_INFO";
091:
092: /** Session parameter name for the user object. */
093: private static final String USER_OBJECT = "USER";
094:
095: /** The user object that is edited on this dialog. */
096: protected CmsUser m_user;
097:
098: /** The starting group for the new user. */
099: private String m_group;
100:
101: /** The default language for the new user. */
102: private String m_language;
103:
104: /** Stores the value of the request parameter for the organizational unit fqn. */
105: private String m_paramOufqn;
106:
107: /** Stores the value of the request parameter for the user id. */
108: private String m_paramUserid;
109:
110: /** The password information object. */
111: private CmsPasswordInfo m_pwdInfo;
112:
113: /** The starting site for the new user. */
114: private String m_site;
115:
116: /**
117: * Public constructor with JSP action element.<p>
118: *
119: * @param jsp an initialized JSP action element
120: */
121: public A_CmsEditUserDialog(CmsJspActionElement jsp) {
122:
123: super (jsp);
124: }
125:
126: /**
127: * Commits the edited user to the db.<p>
128: */
129: public void actionCommit() {
130:
131: List errors = new ArrayList();
132:
133: try {
134: // if new create it first
135: if (isNewUser()) {
136: m_pwdInfo.validate();
137: CmsUser newUser = createUser(m_paramOufqn
138: + m_user.getSimpleName(),
139: m_pwdInfo.getNewPwd(), m_user.getDescription(),
140: m_user.getAdditionalInfo());
141: newUser.setFirstname(m_user.getFirstname());
142: newUser.setLastname(m_user.getLastname());
143: newUser.setEmail(m_user.getEmail());
144: newUser.setAddress(m_user.getAddress());
145: m_user = newUser;
146: } else if (CmsStringUtil.isNotEmpty(m_pwdInfo.getNewPwd())) {
147: m_pwdInfo.validate();
148: getCms().setPassword(m_user.getName(),
149: m_pwdInfo.getNewPwd());
150: }
151: // test the group name
152: if (isNewUser()
153: && CmsStringUtil
154: .isNotEmptyOrWhitespaceOnly(getGroup())) {
155: getCms().readGroup(getGroup());
156: }
157: // write the edited user
158: writeUser(m_user);
159: // set starting membership
160: if (isNewUser()) {
161: if (CmsStringUtil
162: .isNotEmptyOrWhitespaceOnly(getGroup())) {
163: getCms().addUserToGroup(m_user.getName(),
164: getGroup());
165: }
166: }
167: // set starting settings
168: CmsUserSettings settings = new CmsUserSettings(m_user);
169: settings.setLocale(CmsLocaleManager
170: .getLocale(getLanguage()));
171: settings.setStartSite(getSite());
172: // set starting project
173: if (isNewUser()) {
174: try {
175: String prj = getCms().readProject(
176: getParamOufqn()
177: + OpenCms.getWorkplaceManager()
178: .getDefaultUserSettings()
179: .getStartProject())
180: .getName();
181: settings.setStartProject(prj);
182: } catch (CmsException e) {
183: // use root ou project, if project not found
184: settings
185: .setStartProject(OpenCms
186: .getWorkplaceManager()
187: .getDefaultUserSettings()
188: .getStartProject());
189: }
190: }
191: settings.save(getCms());
192:
193: // refresh the list
194: Map objects = (Map) getSettings().getListObject();
195: if (objects != null) {
196: objects.remove(getListClass());
197: }
198: } catch (Throwable t) {
199: errors.add(t);
200: }
201:
202: if (errors.isEmpty() && isNewUser()) {
203: if ((getParamCloseLink() != null)
204: && (getParamCloseLink().indexOf(
205: "path=" + getListRootPath()) > -1)) {
206: // set closelink
207: Map argMap = new HashMap();
208: argMap.put(PARAM_USERID, m_user.getId());
209: argMap.put("oufqn", m_paramOufqn);
210: setParamCloseLink(CmsToolManager.linkForToolPath(
211: getJsp(), getListRootPath() + "/edit", argMap));
212: }
213: }
214: // set the list of errors to display when saving failed
215: setCommitErrors(errors);
216: }
217:
218: /**
219: * Returns the description of the parent ou.<p>
220: *
221: * @return the description of the parent ou
222: */
223: public String getAssignedOu() {
224:
225: try {
226: CmsOrganizationalUnit ou = OpenCms.getOrgUnitManager()
227: .readOrganizationalUnit(getCms(), getParamOufqn());
228: return ou.getDisplayName(getLocale());
229: } catch (CmsException e) {
230: return null;
231: }
232: }
233:
234: /**
235: * Returns the localized description of the user if the description is a key.<p>
236: *
237: * @return the localized description of the user if the description is a key
238: */
239: public String getDescription() {
240:
241: return m_user.getDescription(getLocale());
242: }
243:
244: /**
245: * Returns the group.<p>
246: *
247: * @return the group
248: */
249: public String getGroup() {
250:
251: return m_group;
252: }
253:
254: /**
255: * Returns the language.<p>
256: *
257: * @return the language
258: */
259: public String getLanguage() {
260:
261: return m_language;
262: }
263:
264: /**
265: * Returns the simple name of the user object.<p>
266: *
267: * @return the simple name of the user object
268: */
269: public String getName() {
270:
271: if (m_user.getSimpleName().endsWith(
272: CmsOrganizationalUnit.SEPARATOR)) {
273: return "";
274: }
275: return m_user.getSimpleName();
276: }
277:
278: /**
279: * Returns the organizational unit fqn parameter value.<p>
280: *
281: * @return the organizational unit fqn parameter value
282: */
283: public String getParamOufqn() {
284:
285: return m_paramOufqn;
286: }
287:
288: /**
289: * Returns the user id parameter value.<p>
290: *
291: * @return the user id parameter value
292: */
293: public String getParamUserid() {
294:
295: return m_paramUserid;
296: }
297:
298: /**
299: * Returns the password information.<p>
300: *
301: * @return the password information
302: */
303: public CmsPasswordInfo getPwdInfo() {
304:
305: return m_pwdInfo;
306: }
307:
308: /**
309: * Returns the site.<p>
310: *
311: * @return the site
312: */
313: public String getSite() {
314:
315: return m_site;
316: }
317:
318: /**
319: * Returns the selfManagement.<p>
320: *
321: * @return the selfManagement
322: */
323: public boolean isSelfManagement() {
324:
325: return !m_user.isManaged();
326: }
327:
328: /**
329: * This method is only needed for displaying reasons.<p>
330: *
331: * @param assignedOu nothing to do with this parameter
332: */
333: public void setAssignedOu(String assignedOu) {
334:
335: // nothing will be done here, just to avoid warnings
336: assignedOu.length();
337: }
338:
339: /**
340: * Sets the description for the user.<p>
341: *
342: * @param description the description for the user
343: */
344: public void setDescription(String description) {
345:
346: m_user.setDescription(description);
347: }
348:
349: /**
350: * Sets the group.<p>
351: *
352: * @param group the group to set
353: */
354: public void setGroup(String group) {
355:
356: m_group = group;
357: }
358:
359: /**
360: * Sets the language.<p>
361: *
362: * @param language the language to set
363: */
364: public void setLanguage(String language) {
365:
366: m_language = language;
367: }
368:
369: /**
370: * Sets the name of the user object.<p>
371: *
372: * @param name the name of the user object
373: */
374: public void setName(String name) {
375:
376: m_user.setName(getParamOufqn() + name);
377: }
378:
379: /**
380: * Sets the organizational unit fqn parameter value.<p>
381: *
382: * @param ouFqn the organizational unit fqn parameter value
383: */
384: public void setParamOufqn(String ouFqn) {
385:
386: if (ouFqn == null) {
387: ouFqn = "";
388: }
389: m_paramOufqn = ouFqn;
390: }
391:
392: /**
393: * Sets the user id parameter value.<p>
394: *
395: * @param userId the user id parameter value
396: */
397: public void setParamUserid(String userId) {
398:
399: m_paramUserid = userId;
400: }
401:
402: /**
403: * Sets the selfManagement.<p>
404: *
405: * @param selfManagement the selfManagement to set
406: */
407: public void setSelfManagement(boolean selfManagement) {
408:
409: m_user.setManaged(!selfManagement);
410: }
411:
412: /**
413: * Sets the site.<p>
414: *
415: * @param site the site to set
416: */
417: public void setSite(String site) {
418:
419: m_site = site;
420: }
421:
422: /**
423: * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
424: *
425: * This overwrites the method from the super class to create a layout variation for the widgets.<p>
426: *
427: * @param dialog the dialog (page) to get the HTML for
428: * @return the dialog HTML for all defined widgets of the named dialog (page)
429: */
430: protected String createDialogHtml(String dialog) {
431:
432: StringBuffer result = new StringBuffer(1024);
433:
434: result.append(createWidgetTableStart());
435: // show error header once if there were validation errors
436: result.append(createWidgetErrorHeader());
437:
438: if (dialog.equals(PAGES[0])) {
439: boolean webuserOu = false;
440: try {
441: webuserOu = OpenCms.getOrgUnitManager()
442: .readOrganizationalUnit(getCms(),
443: getParamOufqn()).hasFlagWebuser();
444: } catch (CmsException e) {
445: // ignore
446: }
447: // create the widgets for the first dialog page
448: result
449: .append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_IDENTIFICATION_BLOCK_0)));
450: result.append(createWidgetTableStart());
451: result.append(createDialogRowsHtml(0, 5));
452: result.append(createWidgetTableEnd());
453: result.append(dialogBlockEnd());
454: result
455: .append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_ADDRESS_BLOCK_0)));
456: result.append(createWidgetTableStart());
457: result.append(createDialogRowsHtml(6, 9));
458: result.append(createWidgetTableEnd());
459: result.append(dialogBlockEnd());
460: int row = isNewUser() ? 12 : 11;
461: if (!webuserOu) {
462: if (getSites().isEmpty()) {
463: row -= 1;
464: }
465: result
466: .append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_SETTINGS_BLOCK_0)));
467: result.append(createWidgetTableStart());
468: result.append(createDialogRowsHtml(10, row));
469: result.append(createWidgetTableEnd());
470: result.append(dialogBlockEnd());
471: } else {
472: row = 9;
473: }
474: row++;
475: result
476: .append(dialogBlockStart(key(Messages.GUI_USER_EDITOR_LABEL_AUTHENTIFICATION_BLOCK_0)));
477: result.append(createWidgetTableStart());
478: if (isPwdChangeAllowed(m_user)) {
479: result.append(createDialogRowsHtml(row, row + 3));
480: } else {
481: result.append(createDialogRowsHtml(row, row + 1));
482: }
483: result.append(createWidgetTableEnd());
484: result.append(dialogBlockEnd());
485: }
486:
487: result.append(createWidgetTableEnd());
488: return result.toString();
489: }
490:
491: /**
492: * Creates a new user.<p>
493: *
494: * @param name the name
495: * @param pwd the password
496: * @param desc the description
497: * @param info the additional information map
498: *
499: * @return the new user
500: *
501: * @throws CmsException if something goes wrong
502: */
503: protected abstract CmsUser createUser(String name, String pwd,
504: String desc, Map info) throws CmsException;
505:
506: /**
507: * Creates the list of widgets for this dialog.<p>
508: */
509: protected void defineWidgets() {
510:
511: // initialize the user object to use for the dialog
512: initUserObject();
513: boolean webuserOu = false;
514: try {
515: webuserOu = OpenCms.getOrgUnitManager()
516: .readOrganizationalUnit(getCms(), getParamOufqn())
517: .hasFlagWebuser();
518: } catch (CmsException e) {
519: webuserOu = m_user.isWebuser();
520: }
521: setKeyPrefix(KEY_PREFIX);
522:
523: // widgets to display
524: if (isNewUser() && isEditable(m_user)) {
525: addWidget(new CmsWidgetDialogParameter(this , "name",
526: PAGES[0], new CmsInputWidget()));
527: } else {
528: addWidget(new CmsWidgetDialogParameter(this , "name",
529: PAGES[0], new CmsDisplayWidget()));
530: }
531: if (isEditable(m_user)) {
532: addWidget(new CmsWidgetDialogParameter(this , "description",
533: "", PAGES[0], new CmsTextareaWidget(), 0, 1));
534: addWidget(new CmsWidgetDialogParameter(m_user, "lastname",
535: PAGES[0], new CmsInputWidget()));
536: addWidget(new CmsWidgetDialogParameter(m_user, "firstname",
537: PAGES[0], new CmsInputWidget()));
538: addWidget(new CmsWidgetDialogParameter(m_user, "email",
539: PAGES[0], new CmsInputWidget()));
540: addWidget(new CmsWidgetDialogParameter(this , "assignedOu",
541: PAGES[0], new CmsDisplayWidget()));
542: addWidget(new CmsWidgetDialogParameter(m_user, "address",
543: "", PAGES[0], new CmsInputWidget(), 0, 1));
544: addWidget(new CmsWidgetDialogParameter(m_user, "zipcode",
545: "", PAGES[0], new CmsInputWidget(), 0, 1));
546: addWidget(new CmsWidgetDialogParameter(m_user, "city", "",
547: PAGES[0], new CmsInputWidget(), 0, 1));
548: addWidget(new CmsWidgetDialogParameter(m_user, "country",
549: "", PAGES[0], new CmsInputWidget(), 0, 1));
550: if (!webuserOu) {
551: addWidget(new CmsWidgetDialogParameter(this ,
552: "language", PAGES[0], new CmsSelectWidget(
553: getLanguages())));
554: if (!getSites().isEmpty()) {
555: addWidget(new CmsWidgetDialogParameter(this ,
556: "site", PAGES[0], new CmsSelectWidget(
557: getSites())));
558: }
559: if (isNewUser()) {
560: addWidget(new CmsWidgetDialogParameter(this ,
561: "group", PAGES[0], new CmsGroupWidget(null,
562: null, getParamOufqn())));
563: }
564: }
565: } else {
566: addWidget(new CmsWidgetDialogParameter(this , "description",
567: PAGES[0], new CmsDisplayWidget()));
568: addWidget(new CmsWidgetDialogParameter(m_user, "lastname",
569: PAGES[0], new CmsDisplayWidget()));
570: addWidget(new CmsWidgetDialogParameter(m_user, "firstname",
571: PAGES[0], new CmsDisplayWidget()));
572: addWidget(new CmsWidgetDialogParameter(m_user, "email",
573: PAGES[0], new CmsDisplayWidget()));
574: addWidget(new CmsWidgetDialogParameter(this , "assignedOu",
575: PAGES[0], new CmsDisplayWidget()));
576: addWidget(new CmsWidgetDialogParameter(m_user, "address",
577: PAGES[0], new CmsDisplayWidget()));
578: addWidget(new CmsWidgetDialogParameter(m_user, "zipcode",
579: PAGES[0], new CmsDisplayWidget()));
580: addWidget(new CmsWidgetDialogParameter(m_user, "city",
581: PAGES[0], new CmsDisplayWidget()));
582: addWidget(new CmsWidgetDialogParameter(m_user, "country",
583: PAGES[0], new CmsDisplayWidget()));
584: if (!webuserOu) {
585: addWidget(new CmsWidgetDialogParameter(this ,
586: "language", PAGES[0], new CmsDisplayWidget()));
587: if (!getSites().isEmpty()) {
588: addWidget(new CmsWidgetDialogParameter(this ,
589: "site", PAGES[0], new CmsDisplayWidget()));
590: }
591: }
592: }
593: addWidget(new CmsWidgetDialogParameter(m_user, "enabled",
594: PAGES[0], new CmsCheckboxWidget()));
595: addWidget(new CmsWidgetDialogParameter(this , "selfManagement",
596: PAGES[0], new CmsCheckboxWidget()));
597: if (isPwdChangeAllowed(m_user)) {
598: addWidget(new CmsWidgetDialogParameter(m_pwdInfo, "newPwd",
599: PAGES[0], new CmsPasswordWidget()));
600: addWidget(new CmsWidgetDialogParameter(m_pwdInfo,
601: "confirmation", PAGES[0], new CmsPasswordWidget()));
602: }
603: }
604:
605: /**
606: * Returns the dialog class name of the list to refresh.<p>
607: *
608: * @return the list dialog class name
609: */
610: protected abstract String getListClass();
611:
612: /**
613: * Returns the root path for the list tool.<p>
614: *
615: * @return the root path
616: */
617: protected abstract String getListRootPath();
618:
619: /**
620: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
621: */
622: protected String[] getPageArray() {
623:
624: return PAGES;
625: }
626:
627: /**
628: * @see org.opencms.workplace.CmsWorkplace#initMessages()
629: */
630: protected void initMessages() {
631:
632: // add specific dialog resource bundle
633: addMessages(Messages.get().getBundleName());
634: // add default resource bundles
635: super .initMessages();
636: }
637:
638: /**
639: * Initializes the user object to work with depending on the dialog state and request parameters.<p>
640: *
641: * Two initializations of the user object on first dialog call are possible:
642: * <ul>
643: * <li>edit an existing user</li>
644: * <li>create a new user</li>
645: * </ul>
646: */
647: protected void initUserObject() {
648:
649: Object o = null;
650: try {
651: if (CmsStringUtil.isEmpty(getParamAction())
652: || CmsDialog.DIALOG_INITIAL
653: .equals(getParamAction())) {
654: // edit an existing user, get the user object from db
655: m_user = getCms().readUser(
656: new CmsUUID(getParamUserid()));
657: m_pwdInfo = new CmsPasswordInfo();
658: CmsUserSettings settings = new CmsUserSettings(m_user);
659: m_language = settings.getLocale().toString();
660: m_site = settings.getStartSite();
661: return;
662: } else {
663: // this is not the initial call, get the user object from session
664: o = getDialogObject();
665: Map dialogObject = (Map) o;
666: m_user = (CmsUser) dialogObject.get(USER_OBJECT);
667: m_pwdInfo = (CmsPasswordInfo) dialogObject
668: .get(PWD_OBJECT);
669: CmsUserSettings settings = new CmsUserSettings(m_user);
670: m_language = settings.getLocale().toString();
671: m_site = settings.getStartSite();
672: // test
673: m_user.getId();
674: return;
675: }
676: } catch (Exception e) {
677: // noop
678: }
679: // create a new user object
680: m_user = new CmsUser();
681: m_pwdInfo = new CmsPasswordInfo();
682: m_group = "";
683: try {
684: m_group = getCms()
685: .readGroup(
686: getParamOufqn()
687: + OpenCms.getDefaultUsers()
688: .getGroupUsers()).getName();
689: } catch (CmsException e) {
690: // ignore
691: }
692: m_language = CmsLocaleManager.getDefaultLocale().toString();
693: m_site = OpenCms.getSiteManager().getDefaultSite()
694: .getSiteRoot();
695: }
696:
697: /**
698: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
699: */
700: protected void initWorkplaceRequestValues(
701: CmsWorkplaceSettings settings, HttpServletRequest request) {
702:
703: // initialize parameters and dialog actions in super implementation
704: super .initWorkplaceRequestValues(settings, request);
705:
706: // save the current state of the user and pwd (may be changed because of the widget values)
707: Map dialogObject = new HashMap();
708: dialogObject.put(USER_OBJECT, m_user);
709: dialogObject.put(PWD_OBJECT, m_pwdInfo);
710: setDialogObject(dialogObject);
711: }
712:
713: /**
714: * Tests if the given user is editable or not.<p>
715: *
716: * Not editable means that the user can only be activated and deactivated.<p>
717: *
718: * @param user the user to test
719: *
720: * @return the editable flag
721: */
722: protected abstract boolean isEditable(CmsUser user);
723:
724: /**
725: * Checks if the new user dialog has to be displayed.<p>
726: *
727: * @return <code>true</code> if the new user dialog has to be displayed
728: */
729: protected boolean isNewUser() {
730:
731: return getCurrentToolPath().equals(getListRootPath() + "/new");
732: }
733:
734: /**
735: * Indicates if the pwd can be edited or not.<p>
736: *
737: * @param user the edited cms user
738: *
739: * @return <code>true</code> if the pwd can be edited
740: */
741: protected boolean isPwdChangeAllowed(CmsUser user) {
742:
743: return user.isUser(); // always true, just to avoid warning
744: }
745:
746: /**
747: * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
748: */
749: protected void validateParamaters() throws Exception {
750:
751: OpenCms.getRoleManager().checkRole(getCms(),
752: CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
753: if (!isNewUser()) {
754: // test the needed parameters
755: getCms().readUser(new CmsUUID(getParamUserid())).getName();
756: }
757: }
758:
759: /**
760: * Writes a user to the db.<p>
761: *
762: * @param user the user to write
763: *
764: * @throws CmsException if something goes wrong
765: */
766: protected abstract void writeUser(CmsUser user) throws CmsException;
767:
768: /**
769: * Returns a list of options for the locale selector.<p>
770: *
771: * @return a list of options for the locale selector
772: */
773: private List getLanguages() {
774:
775: List locales = new ArrayList();
776:
777: Locale defLocale = null;
778: if ((m_user != null)
779: && CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_user
780: .getName())) {
781: defLocale = new CmsUserSettings(m_user).getLocale();
782: }
783: if (defLocale == null) {
784: defLocale = getCms().getRequestContext().getLocale();
785: }
786:
787: Iterator itLocales = OpenCms.getLocaleManager()
788: .getAvailableLocales().iterator();
789: while (itLocales.hasNext()) {
790: Locale locale = (Locale) itLocales.next();
791: boolean selected = locale.equals(defLocale);
792: locales
793: .add(new CmsSelectWidgetOption(locale.toString(),
794: selected, locale
795: .getDisplayName(getLocale()), null));
796: }
797: return locales;
798: }
799:
800: /**
801: * Returns a list of options for the site selector.<p>
802: *
803: * @return a list of options for the site selector
804: */
805: private List getSites() {
806:
807: List sites = new ArrayList();
808: List sitesList = OpenCms.getSiteManager().getAvailableSites(
809: getCms(), true, getParamOufqn());
810:
811: String defSite = null;
812: if ((m_user != null)
813: && CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_user
814: .getName())) {
815: defSite = new CmsUserSettings(m_user).getStartSite();
816: }
817: if (defSite == null) {
818: defSite = getCms().getRequestContext().getSiteRoot();
819: }
820: if (!defSite.endsWith("/")) {
821: defSite += "/";
822: }
823:
824: Iterator itSites = sitesList.iterator();
825: while (itSites.hasNext()) {
826: CmsSite site = (CmsSite) itSites.next();
827: String siteRoot = site.getSiteRoot();
828: if (CmsStringUtil.isEmptyOrWhitespaceOnly(siteRoot)) {
829: if (sitesList.size() > 1) {
830: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_user
831: .getName())) {
832: if (!OpenCms.getRoleManager().hasRole(getCms(),
833: m_user.getName(), CmsRole.DEVELOPER)) {
834: // skip the root site if not accessible
835: continue;
836: }
837: }
838: }
839: }
840: if (!siteRoot.endsWith("/")) {
841: siteRoot += "/";
842: }
843: boolean selected = defSite.equals(siteRoot);
844: sites.add(new CmsSelectWidgetOption(siteRoot, selected,
845: site.getTitle(), null));
846: }
847: return sites;
848: }
849: }
|