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

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

Introduction

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

Prototype

public String getI18nPath() 

Source Link

Document

Returns the path element for the current internationalization language.

Usage

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

private static void _populateTokens(Map<String, String> tokens, long articleGroupId, ThemeDisplay themeDisplay)
        throws PortalException {

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    LayoutSet layoutSet = layout.getLayoutSet();

    String friendlyUrlCurrent = null;

    if (layout.isPublicLayout()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPublic();
    } else if (group.isUserGroup()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateUser();
    } else {/*from  ww  w .j  ava  2  s  .c o m*/
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateGroup();
    }

    String layoutSetFriendlyUrl = themeDisplay.getI18nPath();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplay.getServerName())) {

        layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL();
    }

    tokens.put("article_group_id", String.valueOf(articleGroupId));
    tokens.put("cdn_host", themeDisplay.getCDNHost());
    tokens.put("company_id", String.valueOf(themeDisplay.getCompanyId()));
    tokens.put("friendly_url_current", friendlyUrlCurrent);
    tokens.put("friendly_url_private_group", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("friendly_url_private_user", themeDisplay.getPathFriendlyURLPrivateUser());
    tokens.put("friendly_url_public", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("group_friendly_url", group.getFriendlyURL());
    tokens.put("image_path", themeDisplay.getPathImage());
    tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl);
    tokens.put("main_path", themeDisplay.getPathMain());
    tokens.put("portal_ctx", themeDisplay.getPathContext());
    tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplay.getURLPortal()));
    tokens.put("protocol", HttpUtil.getProtocol(themeDisplay.getURLPortal()));
    tokens.put("root_path", themeDisplay.getPathContext());
    tokens.put("scope_group_id", String.valueOf(themeDisplay.getScopeGroupId()));
    tokens.put("site_group_id", String.valueOf(themeDisplay.getSiteGroupId()));
    tokens.put("theme_image_path", themeDisplay.getPathThemeImages());

    _populateCustomTokens(tokens, themeDisplay.getCompanyId());

    // Deprecated tokens

    tokens.put("friendly_url", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("friendly_url_private", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("group_id", String.valueOf(articleGroupId));
    tokens.put("page_url", themeDisplay.getPathFriendlyURLPublic());
}

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 {//from  www .  j  a v  a 2 s . c om
        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);
    }
}