Example usage for com.liferay.portal.kernel.theme ThemeDisplay isI18n

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay isI18n

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay isI18n.

Prototype

public boolean isI18n() 

Source Link

Usage

From source file:com.liferay.users.admin.web.internal.portlet.action.EditUserMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    actionRequest = _wrapActionRequest(actionRequest);

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {//www  .j av  a 2 s . c  o m
        User user = null;
        String oldScreenName = StringPool.BLANK;
        boolean updateLanguageId = false;

        if (cmd.equals(Constants.ADD)) {
            user = addUser(actionRequest);
        } else if (cmd.equals(Constants.DEACTIVATE) || cmd.equals(Constants.DELETE)
                || cmd.equals(Constants.RESTORE)) {

            deleteUsers(actionRequest);
        } else if (cmd.equals("deleteRole")) {
            deleteRole(actionRequest);
        } else if (cmd.equals(Constants.UPDATE)) {
            Object[] returnValue = updateUser(actionRequest, actionResponse);

            user = (User) returnValue[0];
            oldScreenName = (String) returnValue[1];
            updateLanguageId = (Boolean) returnValue[2];
        } else if (cmd.equals("unlock")) {
            user = updateLockout(actionRequest);
        }

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        String redirect = ParamUtil.getString(actionRequest, "redirect");

        if (user != null) {
            if (Validator.isNotNull(oldScreenName)) {

                // This will fix the redirect if the user is on his personal
                // my account page and changes his screen name. A redirect
                // that references the old screen name no longer points to a
                // valid screen name and therefore needs to be updated.

                Group group = user.getGroup();

                if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
                    Layout layout = themeDisplay.getLayout();

                    String friendlyURLPath = group.getPathFriendlyURL(layout.isPrivateLayout(), themeDisplay);

                    String oldPath = friendlyURLPath + StringPool.SLASH + oldScreenName;
                    String newPath = friendlyURLPath + StringPool.SLASH + user.getScreenName();

                    redirect = StringUtil.replace(redirect, oldPath, newPath);

                    redirect = StringUtil.replace(redirect, URLCodec.encodeURL(oldPath),
                            URLCodec.encodeURL(newPath));
                }
            }

            if (updateLanguageId && themeDisplay.isI18n()) {
                String i18nLanguageId = user.getLanguageId();

                int pos = i18nLanguageId.indexOf(CharPool.UNDERLINE);

                if (pos != -1) {
                    i18nLanguageId = i18nLanguageId.substring(0, pos);
                }

                String i18nPath = StringPool.SLASH + i18nLanguageId;

                redirect = StringUtil.replace(redirect, themeDisplay.getI18nPath(), i18nPath);
            }

            redirect = http.setParameter(redirect, actionResponse.getNamespace() + "p_u_i_d", user.getUserId());
        }

        Group scopeGroup = themeDisplay.getScopeGroup();

        if (scopeGroup.isUser() && (userLocalService.fetchUserById(scopeGroup.getClassPK()) == null)) {

            redirect = http.setParameter(redirect, "doAsGroupId", 0);
            redirect = http.setParameter(redirect, "refererPlid", 0);
        }

        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
        String mvcPath = "/edit_user.jsp";

        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());

            mvcPath = "/error.jsp";
        } else if (e instanceof AssetCategoryException || e instanceof AssetTagException
                || e instanceof CompanyMaxUsersException || e instanceof ContactBirthdayException
                || e instanceof ContactNameException || e instanceof GroupFriendlyURLException
                || e instanceof MembershipPolicyException || e instanceof NoSuchListTypeException
                || e instanceof RequiredUserException || e instanceof UserEmailAddressException
                || e instanceof UserFieldException || e instanceof UserIdException
                || e instanceof UserReminderQueryException || e instanceof UserScreenNameException) {

            if (e instanceof NoSuchListTypeException) {
                NoSuchListTypeException nslte = (NoSuchListTypeException) e;

                Class<?> clazz = e.getClass();

                SessionErrors.add(actionRequest, clazz.getName() + nslte.getType());
            } else {
                SessionErrors.add(actionRequest, e.getClass(), e);
            }

            if (e instanceof CompanyMaxUsersException || e instanceof RequiredUserException) {

                String redirect = portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

                if (Validator.isNotNull(redirect)) {
                    sendRedirect(actionRequest, actionResponse, redirect);

                    return;
                }
            }
        } else {
            throw e;
        }

        actionResponse.setRenderParameter("mvcPath", mvcPath);
    }
}