@Override
    public void actionCommit() {

        List<Throwable> errors = new ArrayList<Throwable>();

        try {
            // if new create it first
            if (isNewUser()) {
                // test the group name
                CmsGroup group = null;
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getGroup())) {
                    group = getCms().readGroup(getGroup());
                }

                if (group != null) {
                    if (group.getSimpleName().equals(OpenCms.getDefaultUsers().getGroupAdministrators())) {
                        // in case the administrators group is selected, the administrator role must be selected also
                        if (getRole().equals(NO_ROLE)) {
                            throw new CmsIllegalArgumentException(
                                Messages.get().container(Messages.ERR_ADD_TO_ADMINISTRATORS_GROUP_0));
                        }
                        CmsRole role = CmsRole.valueOfRoleName(getRole());
                        if (!CmsRole.ROOT_ADMIN.getRoleName().equals(role.getRoleName())
                            && !CmsRole.ADMINISTRATOR.getRoleName().equals(role.getRoleName())) {
                            throw new CmsIllegalArgumentException(
                                Messages.get().container(Messages.ERR_ADD_TO_ADMINISTRATORS_GROUP_0));
                        }
                    } else if (group.getSimpleName().equals(OpenCms.getDefaultUsers().getGroupUsers())) {
                        // in case the users group is selected, the user should have at least one role
                        if (getRole().equals(NO_ROLE)) {
                            throw new CmsIllegalArgumentException(
                                Messages.get().container(Messages.ERR_ADD_TO_USERS_GROUP_0));
                        }
                    } else if (group.getSimpleName().equals(OpenCms.getDefaultUsers().getGroupGuests())) {
                        // in case the users group is selected, the user should have at least one role
                        if (!getRole().equals(NO_ROLE)) {
                            throw new CmsIllegalArgumentException(
                                Messages.get().container(Messages.ERR_ADD_TO_GUESTS_GROUP_0));
                        }
                    }
                }
                m_pwdInfo.validate();
                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());
                newUser.setManaged(m_user.isManaged());
                newUser.setEnabled(m_user.isEnabled());

                m_user = newUser;
            } else if (CmsStringUtil.isNotEmpty(m_pwdInfo.getNewPwd())) {
                m_pwdInfo.validate();
                getCms().setPassword(m_user.getName(), m_pwdInfo.getNewPwd());
            }

            // write the edited user
            writeUser(m_user);
            // set starting membership
            if (isNewUser()) {
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getGroup())) {
                    getCms().addUserToGroup(m_user.getName(), getGroup());
                }
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getRole()) && !getRole().equals(NO_ROLE)) {
                    OpenCms.getRoleManager().addUserToRole(
                        getCms(),
                        CmsRole.valueOfRoleName(getRole()).forOrgUnit(m_paramOufqn),
                        m_user.getName());
                }
            }
            // set starting settings
            CmsUserSettings settings = new CmsUserSettings(m_user);
            settings.setLocale(CmsLocaleManager.getLocale(getLanguage()));
            settings.setStartSite(getSite());
            // set starting project
            if (isNewUser()) {
                settings.setStartProject(getParamOufqn() + getStartProject());
            } else {
                settings.setStartProject(getStartProject());
            }

            boolean webuserOu = false;
            try {
                webuserOu = OpenCms.getOrgUnitManager().readOrganizationalUnit(
                    getCms(),
                    getParamOufqn()).hasFlagWebuser();
            } catch (CmsException e) {
                // ignore
            }
            // only set the start folder for non web users
            if (!webuserOu) {
                CmsObject tmp = OpenCms.initCmsObject(getCms());
                tmp.getRequestContext().setSiteRoot(getSite());
                String folder = tmp.getRequestContext().removeSiteRoot(getStartFolder());
                try {
                    CmsResource res = tmp.readResource(folder);
                    String siteRoot = OpenCms.getSiteManager().getSiteRoot(res.getRootPath());
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)
                        && CmsStringUtil.isNotEmptyOrWhitespaceOnly(tmp.getRequestContext().getSiteRoot())
                        && !tmp.getRequestContext().getSiteRoot().equals("/")) {
                        folder = res.getRootPath().substring(siteRoot.length());
                    }
                } catch (CmsException e) {
                    throw new CmsIllegalArgumentException(
                        Messages.get().container(Messages.ERR_SELECTED_FOLDER_NOT_IN_SITE_0));
                }
                settings.setStartFolder(folder);
            }
            settings.setStartView(getStartView());
            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<String, String[]> argMap = new HashMap<String, String[]>();
                argMap.put(PARAM_USERID, new String[] {m_user.getId().toString()});
                argMap.put("oufqn", new String[] {m_paramOufqn});
                setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), getListRootPath() + "/edit", argMap));
            }
        }
        // set the list of errors to display when saving failed
        setCommitErrors(errors);
    }
@ Override public void actionCommit ( ) { List < Throwable > errors = new ArrayList < Throwable > ( ) ; try { if ( isNewUser ( ) ) { CmsGroup group = null ; if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( getGroup ( ) ) ) { group = getCms ( ) . readGroup ( getGroup ( ) ) ; } if ( group != null ) { if ( group . getSimpleName ( ) . equals ( OpenCms . getDefaultUsers ( ) . getGroupAdministrators ( ) ) ) { if ( getRole ( ) . equals ( NO_ROLE ) ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_ADD_TO_ADMINISTRATORS_GROUP_0 ) ) ; } CmsRole role = CmsRole . valueOfRoleName ( getRole ( ) ) ; if ( ! CmsRole . ROOT_ADMIN . getRoleName ( ) . equals ( role . getRoleName ( ) ) && ! CmsRole . ADMINISTRATOR . getRoleName ( ) . equals ( role . getRoleName ( ) ) ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_ADD_TO_ADMINISTRATORS_GROUP_0 ) ) ; } } else if ( group . getSimpleName ( ) . equals ( OpenCms . getDefaultUsers ( ) . getGroupUsers ( ) ) ) { if ( getRole ( ) . equals ( NO_ROLE ) ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_ADD_TO_USERS_GROUP_0 ) ) ; } } else if ( group . getSimpleName ( ) . equals ( OpenCms . getDefaultUsers ( ) . getGroupGuests ( ) ) ) { if ( ! getRole ( ) . equals ( NO_ROLE ) ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_ADD_TO_GUESTS_GROUP_0 ) ) ; } } } m_pwdInfo . validate ( ) ; 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 ( ) ) ; newUser . setManaged ( m_user . isManaged ( ) ) ; newUser . setEnabled ( m_user . isEnabled ( ) ) ; m_user = newUser ; } else if ( CmsStringUtil . isNotEmpty ( m_pwdInfo . getNewPwd ( ) ) ) { m_pwdInfo . validate ( ) ; getCms ( ) . setPassword ( m_user . getName ( ) , m_pwdInfo . getNewPwd ( ) ) ; } writeUser ( m_user ) ; if ( isNewUser ( ) ) { if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( getGroup ( ) ) ) { getCms ( ) . addUserToGroup ( m_user . getName ( ) , getGroup ( ) ) ; } if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( getRole ( ) ) && ! getRole ( ) . equals ( NO_ROLE ) ) { OpenCms . getRoleManager ( ) . addUserToRole ( getCms ( ) , CmsRole . valueOfRoleName ( getRole ( ) ) . forOrgUnit ( m_paramOufqn ) , m_user . getName ( ) ) ; } } CmsUserSettings settings = new CmsUserSettings ( m_user ) ; settings . setLocale ( CmsLocaleManager . getLocale ( getLanguage ( ) ) ) ; settings . setStartSite ( getSite ( ) ) ; if ( isNewUser ( ) ) { settings . setStartProject ( getParamOufqn ( ) + getStartProject ( ) ) ; } else { settings . setStartProject ( getStartProject ( ) ) ; } boolean webuserOu = false ; try { webuserOu = OpenCms . getOrgUnitManager ( ) . readOrganizationalUnit ( getCms ( ) , getParamOufqn ( ) ) . hasFlagWebuser ( ) ; } catch ( CmsException e ) { } if ( ! webuserOu ) { CmsObject tmp = OpenCms . initCmsObject ( getCms ( ) ) ; tmp . getRequestContext ( ) . setSiteRoot ( getSite ( ) ) ; String folder = tmp . getRequestContext ( ) . removeSiteRoot ( getStartFolder ( ) ) ; try { CmsResource res = tmp . readResource ( folder ) ; String siteRoot = OpenCms . getSiteManager ( ) . getSiteRoot ( res . getRootPath ( ) ) ; if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( siteRoot ) && CmsStringUtil . isNotEmptyOrWhitespaceOnly ( tmp . getRequestContext ( ) . getSiteRoot ( ) ) && ! tmp . getRequestContext ( ) . getSiteRoot ( ) . equals ( "/" ) ) { folder = res . getRootPath ( ) . substring ( siteRoot . length ( ) ) ; } } catch ( CmsException e ) { throw new CmsIllegalArgumentException ( Messages . get ( ) . container ( Messages . ERR_SELECTED_FOLDER_NOT_IN_SITE_0 ) ) ; } settings . setStartFolder ( folder ) ; } settings . setStartView ( getStartView ( ) ) ; settings . save ( getCms ( ) ) ; 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 ) ) { Map < String , String [ ] > argMap = new HashMap < String , String [ ] > ( ) ; argMap . put ( PARAM_USERID , new String [ ] { m_user . getId ( ) . toString ( ) } ) ; argMap . put ( "oufqn" , new String [ ] { m_paramOufqn } ) ; setParamCloseLink ( CmsToolManager . linkForToolPath ( getJsp ( ) , getListRootPath ( ) + "/edit" , argMap ) ) ; } } setCommitErrors ( errors ) ; }
Commits the edited user to the db.<p>