Example usage for com.liferay.portal.kernel.util URLCodec encodeURL

List of usage examples for com.liferay.portal.kernel.util URLCodec encodeURL

Introduction

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

Prototype

public static String encodeURL(String rawURLString) 

Source Link

Usage

From source file:com.liferay.login.web.internal.portlet.action.LoginMVCActionCommand.java

License:Open Source License

protected void login(ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    HttpServletRequest request = _portal
            .getOriginalServletRequest(_portal.getHttpServletRequest(actionRequest));
    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    if (!themeDisplay.isSignedIn()) {
        String portletId = _portal.getPortletId(actionRequest);

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
                .getStrictPortletSetup(themeDisplay.getLayout(), portletId);

        String authType = portletPreferences.getValue("authType", null);

        _authenticatedSessionManager.login(request, response, login, password, rememberMe, authType);
    }//from   w  w w  .  j av  a 2 s .c om

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

    if (Validator.isNotNull(redirect)) {
        redirect = _portal.escapeRedirect(redirect);

        if (Validator.isNotNull(redirect) && !redirect.startsWith(Http.HTTP)) {

            redirect = getCompleteRedirectURL(request, redirect);
        }
    }

    String mainPath = themeDisplay.getPathMain();

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        if (Validator.isNotNull(redirect)) {
            redirect = mainPath.concat("/portal/protected?redirect=").concat(URLCodec.encodeURL(redirect));
        } else {
            redirect = mainPath.concat("/portal/protected");
        }

        actionResponse.sendRedirect(redirect);
    } else {
        if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
        } else {
            boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

            if (doActionAfterLogin) {
                return;
            } else {
                actionResponse.sendRedirect(mainPath);
            }
        }
    }
}

From source file:com.liferay.screens.service.impl.ScreensAssetEntryServiceImpl.java

License:Open Source License

protected String getFileEntryPreviewURL(FileEntry fileEntry) {
    StringBundler sb = new StringBundler(9);

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);//  ww  w .ja  va2  s .c o  m
    sb.append(fileEntry.getFolderId());
    sb.append(StringPool.SLASH);
    sb.append(URLCodec.encodeURL(HtmlUtil.unescape(fileEntry.getTitle())));
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getUuid());

    return sb.toString();
}

From source file:com.liferay.social.activity.customizer.interpreter.CustomWikiActivityInterpreter.java

License:Open Source License

protected String getAttachmentTitle(SocialActivity activity, WikiPageResource pageResource,
        ServiceContext serviceContext) throws Exception {

    int activityType = activity.getType();

    if ((activityType == SocialActivityConstants.TYPE_ADD_ATTACHMENT)
            || (activityType == SocialActivityConstants.TYPE_MOVE_ATTACHMENT_TO_TRASH)
            || (activityType == SocialActivityConstants.TYPE_RESTORE_ATTACHMENT_FROM_TRASH)) {

        String link = null;/*from  w w  w.  j a  v a 2 s . c  om*/

        FileEntry fileEntry = null;

        try {
            long fileEntryId = GetterUtil.getLong(activity.getExtraDataValue("fileEntryId"));

            fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);
        } catch (NoSuchModelException nsme) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nsme, nsme);
            }
        }

        String fileEntryTitle = activity.getExtraDataValue("fileEntryTitle");

        if ((fileEntry != null) && !fileEntry.isInTrash()) {
            StringBundler sb = new StringBundler(9);

            sb.append(serviceContext.getPathMain());
            sb.append("/wiki/get_page_attachment?p_l_id=");
            sb.append(serviceContext.getPlid());
            sb.append("&nodeId=");
            sb.append(pageResource.getNodeId());
            sb.append("&title=");
            sb.append(URLCodec.encodeURL(pageResource.getTitle()));
            sb.append("&fileName=");
            sb.append(fileEntryTitle);

            link = sb.toString();
        }

        return wrapLink(link, fileEntryTitle);
    }

    return StringPool.BLANK;
}

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 {// ww  w .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);
    }
}

From source file:com.liferay.wiki.web.internal.item.selector.resolver.WikiPageURLItemSelectorReturnTypeResolver.java

License:Open Source License

@Override
public String getValue(WikiPage page, ThemeDisplay themeDisplay) throws Exception {

    String layoutFullURL = _portal.getLayoutFullURL(page.getGroupId(), WikiPortletKeys.WIKI);

    if (Validator.isNotNull(layoutFullURL)) {
        return StringBundler.concat(layoutFullURL, Portal.FRIENDLY_URL_SEPARATOR, "wiki/",
                String.valueOf(page.getNodeId()), StringPool.SLASH,
                URLCodec.encodeURL(WikiEscapeUtil.escapeName(page.getTitle())));
    } else {/*from  w ww  . j  a  v  a2 s.co m*/
        PortletURL portletURL = _portal.getControlPanelPortletURL(themeDisplay.getRequest(),
                WikiPortletKeys.WIKI_ADMIN, PortletRequest.RENDER_PHASE);

        portletURL.setParameter("mvcRenderCommandName", "/wiki/view");
        portletURL.setParameter("nodeId", String.valueOf(page.getNodeId()));
        portletURL.setParameter("title", page.getTitle());

        return _http.removeDomain(portletURL.toString());
    }
}