a_cmsedituserdialog.java
来自「找了很久才找到到源代码」· Java 代码 · 共 734 行 · 第 1/2 页
JAVA
734 行
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsEditUserDialog.java,v $
* Date : $Date: 2007-08-29 13:30:26 $
* Version: $Revision: 1.8 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.workplace.tools.accounts;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsUser;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.security.CmsPasswordInfo;
import org.opencms.security.CmsRole;
import org.opencms.site.CmsSite;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import org.opencms.widgets.CmsCheckboxWidget;
import org.opencms.widgets.CmsDisplayWidget;
import org.opencms.widgets.CmsGroupWidget;
import org.opencms.widgets.CmsInputWidget;
import org.opencms.widgets.CmsPasswordWidget;
import org.opencms.widgets.CmsSelectWidget;
import org.opencms.widgets.CmsSelectWidgetOption;
import org.opencms.widgets.CmsTextareaWidget;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWidgetDialog;
import org.opencms.workplace.CmsWidgetDialogParameter;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.tools.CmsToolManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
/**
* Dialog to edit new or existing user in the administration view.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.8 $
*
* @since 6.0.0
*/
public abstract class A_CmsEditUserDialog extends CmsWidgetDialog {
/** localized messages Keys prefix. */
public static final String KEY_PREFIX = "user";
/** Defines which pages are valid for this dialog. */
public static final String[] PAGES = {"page1"};
/** Request parameter name for the user id. */
public static final String PARAM_USERID = "userid";
/** Session parameter name for the pwd info object. */
private static final String PWD_OBJECT = "PWD_INFO";
/** Session parameter name for the user object. */
private static final String USER_OBJECT = "USER";
/** The user object that is edited on this dialog. */
protected CmsUser m_user;
/** The starting group for the new user. */
private String m_group;
/** The default language for the new user. */
private String m_language;
/** Stores the value of the request parameter for the organizational unit fqn. */
private String m_paramOufqn;
/** Stores the value of the request parameter for the user id. */
private String m_paramUserid;
/** The password information object. */
private CmsPasswordInfo m_pwdInfo;
/** The starting site for the new user. */
private String m_site;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public A_CmsEditUserDialog(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Commits the edited user to the db.<p>
*/
public void actionCommit() {
List errors = new ArrayList();
try {
// in the case the confirmation widget has not be enabled
if (CmsStringUtil.isNotEmpty(m_pwdInfo.getNewPwd())) {
m_pwdInfo.setConfirmation(m_pwdInfo.getConfirmation());
}
// if new create it first
if (isNewUser()) {
CmsUser newUser = createUser(
m_paramOufqn + m_user.getSimpleName(),
m_pwdInfo.getNewPwd(),
m_user.getDescription(),
m_user.getAdditionalInfo());
newUser.setFirstname(m_user.getFirstname());
newUser.setLastname(m_user.getLastname());
newUser.setEmail(m_user.getEmail());
newUser.setAddress(m_user.getAddress());
m_user = newUser;
} else if (CmsStringUtil.isNotEmpty(m_pwdInfo.getNewPwd())) {
if (!m_pwdInfo.getNewPwd().equals(m_pwdInfo.getConfirmation())) {
m_pwdInfo.setConfirmation(null);
}
getCms().setPassword(m_user.getName(), m_pwdInfo.getNewPwd());
}
// test the group name
if (isNewUser() && CmsStringUtil.isNotEmptyOrWhitespaceOnly(getGroup())) {
getCms().readGroup(getGroup());
}
// write the edited user
writeUser(m_user);
// set starting membership
if (isNewUser()) {
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getGroup())) {
getCms().addUserToGroup(m_user.getName(), getGroup());
}
}
// set starting settings
CmsUserSettings settings = new CmsUserSettings(m_user);
settings.setLocale(CmsLocaleManager.getLocale(getLanguage()));
settings.setStartSite(getSite());
// set starting project
if (isNewUser()) {
try {
String prj = getCms().readProject(
getParamOufqn() + OpenCms.getWorkplaceManager().getDefaultUserSettings().getStartProject()).getName();
settings.setStartProject(prj);
} catch (CmsException e) {
// use root ou project, if project not found
settings.setStartProject(OpenCms.getWorkplaceManager().getDefaultUserSettings().getStartProject());
}
}
settings.save(getCms());
// refresh the list
Map objects = (Map)getSettings().getListObject();
if (objects != null) {
objects.remove(getListClass());
}
} catch (Throwable t) {
errors.add(t);
}
if (errors.isEmpty() && isNewUser()) {
if ((getParamCloseLink() != null) && (getParamCloseLink().indexOf("path=" + getListRootPath()) > -1)) {
// set closelink
Map argMap = new HashMap();
argMap.put(PARAM_USERID, m_user.getId());
argMap.put("oufqn", m_paramOufqn);
setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), getListRootPath() + "/edit", argMap));
}
}
// set the list of errors to display when saving failed
setCommitErrors(errors);
}
/**
* Returns the description of the parent ou.<p>
*
* @return the description of the parent ou
*/
public String getAssignedOu() {
try {
CmsOrganizationalUnit ou = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), getParamOufqn());
return ou.getDisplayName(getLocale());
} catch (CmsException e) {
return null;
}
}
/**
* Returns the localized description of the user if the description is a key.<p>
*
* @return the localized description of the user if the description is a key
*/
public String getDescription() {
return m_user.getDescription(getLocale());
}
/**
* Returns the group.<p>
*
* @return the group
*/
public String getGroup() {
return m_group;
}
/**
* Returns the language.<p>
*
* @return the language
*/
public String getLanguage() {
return m_language;
}
/**
* Returns the simple name of the user object.<p>
*
* @return the simple name of the user object
*/
public String getName() {
if (m_user.getSimpleName().endsWith(CmsOrganizationalUnit.SEPARATOR)) {
return "";
}
return m_user.getSimpleName();
}
/**
* Returns the organizational unit fqn parameter value.<p>
*
* @return the organizational unit fqn parameter value
*/
public String getParamOufqn() {
return m_paramOufqn;
}
/**
* Returns the user id parameter value.<p>
*
* @return the user id parameter value
*/
public String getParamUserid() {
return m_paramUserid;
}
/**
* Returns the site.<p>
*
* @return the site
*/
public String getSite() {
return m_site;
}
/**
* Returns the selfManagement.<p>
*
* @return the selfManagement
*/
public boolean isSelfManagement() {
return !m_user.isManaged();
}
/**
* This method is only needed for displaying reasons.<p>
*
* @param assignedOu nothing to do with this parameter
*/
public void setAssignedOu(String assignedOu) {
// nothing will be done here, just to avoid warnings
assignedOu.length();
}
/**
* Sets the description for the user.<p>
*
* @param description the description for the user
*/
public void setDescription(String description) {
m_user.setDescription(description);
}
/**
* Sets the group.<p>
*
* @param group the group to set
*/
public void setGroup(String group) {
m_group = group;
}
/**
* Sets the language.<p>
*
* @param language the language to set
*/
public void setLanguage(String language) {
m_language = language;
}
/**
* Sets the name of the user object.<p>
*
* @param name the name of the user object
*/
public void setName(String name) {
m_user.setName(getParamOufqn() + name);
}
/**
* Sets the organizational unit fqn parameter value.<p>
*
* @param ouFqn the organizational unit fqn parameter value
*/
public void setParamOufqn(String ouFqn) {
if (ouFqn == null) {
ouFqn = "";
}
m_paramOufqn = ouFqn;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?