Example usage for com.liferay.portal.kernel.model Group getPathFriendlyURL

List of usage examples for com.liferay.portal.kernel.model Group getPathFriendlyURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Group getPathFriendlyURL.

Prototype

public String getPathFriendlyURL(boolean privateLayout,
            com.liferay.portal.kernel.theme.ThemeDisplay themeDisplay);

Source Link

Usage

From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormAdminDisplayContext.java

License:Open Source License

protected String getFormLayoutURL(boolean privateLayout) {
    StringBundler sb = new StringBundler(4);

    ThemeDisplay themeDisplay = _ddlFormAdminRequestHelper.getThemeDisplay();

    Group group = themeDisplay.getSiteGroup();

    sb.append(themeDisplay.getPortalURL());
    sb.append(group.getPathFriendlyURL(privateLayout, themeDisplay));

    sb.append("/forms/shared/-/form/");

    return sb.toString();
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormAdminDisplayContextTest.java

License:Open Source License

protected Group mockGroup() {
    Group group = mock(Group.class);

    when(group.getPathFriendlyURL(Matchers.eq(false), Matchers.any(ThemeDisplay.class)))
            .thenReturn(_PUBLIC_FRIENDLY_URL_PATH);

    when(group.getPathFriendlyURL(Matchers.eq(true), Matchers.any(ThemeDisplay.class)))
            .thenReturn(_PRIVATE_FRIENDLY_URL_PATH);

    return group;
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.instance.lifecycle.AddDefaultSharedFormLayoutPortalInstanceLifecycleListener.java

License:Open Source License

public String getFormLayoutURL(ThemeDisplay themeDisplay, boolean privateLayout) {

    StringBundler sb = new StringBundler(3);

    sb.append(themeDisplay.getPortalURL());

    Group group = themeDisplay.getSiteGroup();

    sb.append(group.getPathFriendlyURL(privateLayout, themeDisplay));

    sb.append("/forms/shared/-/form/");

    return sb.toString();
}

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 ww  w  . ja va  2s.co  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);
    }
}