Example usage for com.liferay.portal.kernel.util PrefsPropsUtil getStringArray

List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getStringArray

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PrefsPropsUtil getStringArray.

Prototype

public static String[] getStringArray(PortletPreferences preferences, String name, String delimiter,
            String[] defaultValue) 

Source Link

Usage

From source file:com.evolveum.liferay.usercreatehook.screenname.CustomScreenNameGenerator.java

License:Apache License

public String generate(long companyId, long userId, String emailAddress) throws Exception {

    String screenName = null;//from  www.ja  v  a 2 s.co m

    if (Validator.isNotNull(emailAddress)) {
        // XXX change 1
        // screenName = StringUtil.extractFirst(emailAddress, CharPool.AT).toLowerCase();
        screenName = emailAddress.toLowerCase();

        for (char c : screenName.toCharArray()) {
            // XXX change 2
            // if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.PERIOD))
            // {
            if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH)) {
                // XXX change 3
                // screenName = StringUtil.replace(screenName, c, CharPool.PERIOD);
                screenName = StringUtil.replace(screenName, c, CharPool.DASH);
            }
        }

        if (screenName.equals(DefaultScreenNameValidator.CYRUS)
                || screenName.equals(DefaultScreenNameValidator.POSTFIX)) {

            screenName += StringPool.PERIOD + userId;
        }
    } else {
        screenName = String.valueOf(userId);
    }

    if (!_USERS_SCREEN_NAME_ALLOW_NUMERIC && Validator.isNumber(screenName)) {

        screenName = _NON_NUMERICAL_PREFIX + screenName;
    }

    String[] reservedScreenNames = PrefsPropsUtil.getStringArray(companyId,
            PropsKeys.ADMIN_RESERVED_SCREEN_NAMES, StringPool.NEW_LINE, _ADMIN_RESERVED_SCREEN_NAMES);

    for (String reservedScreenName : reservedScreenNames) {
        if (screenName.equalsIgnoreCase(reservedScreenName)) {
            return getUnusedScreenName(companyId, screenName);
        }
    }

    try {
        UserLocalServiceUtil.getUserByScreenName(companyId, screenName);
    } catch (NoSuchUserException nsue) {
        try {
            GroupLocalServiceUtil.getFriendlyURLGroup(companyId, StringPool.SLASH + screenName);
        } catch (NoSuchGroupException nsge) {
            return screenName;
        }
    }

    return getUnusedScreenName(companyId, screenName);
}