Example usage for com.liferay.portal.util PropsValues LOCALE_PREPEND_FRIENDLY_URL_STYLE

List of usage examples for com.liferay.portal.util PropsValues LOCALE_PREPEND_FRIENDLY_URL_STYLE

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues LOCALE_PREPEND_FRIENDLY_URL_STYLE.

Prototype

int LOCALE_PREPEND_FRIENDLY_URL_STYLE

To view the source code for com.liferay.portal.util PropsValues LOCALE_PREPEND_FRIENDLY_URL_STYLE.

Click Source Link

Usage

From source file:com.liferay.portlet.language.action.ViewAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
    HttpSession session = request.getSession();

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

    Layout layout = themeDisplay.getLayout();

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

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    List<Locale> availableLocales = ListUtil.fromArray(LanguageUtil.getAvailableLocales());

    if (availableLocales.contains(locale)) {
        if (themeDisplay.isSignedIn()) {
            User user = themeDisplay.getUser();

            Contact contact = user.getContact();

            AdminUtil.updateUser(actionRequest, user.getUserId(), user.getScreenName(), user.getEmailAddress(),
                    user.getFacebookId(), user.getOpenId(), languageId, user.getTimeZoneId(),
                    user.getGreeting(), user.getComments(), contact.getSmsSn(), contact.getAimSn(),
                    contact.getFacebookSn(), contact.getIcqSn(), contact.getJabberSn(), contact.getMsnSn(),
                    contact.getMySpaceSn(), contact.getSkypeSn(), contact.getTwitterSn(), contact.getYmSn());
        }/*from  www .  j  a va 2s .  c om*/

        session.setAttribute(Globals.LOCALE_KEY, locale);

        LanguageUtil.updateCookie(request, response, locale);
    }

    // Send redirect

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

    if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        redirect = PortalUtil.getLayoutURL(layout, themeDisplay);

        if (themeDisplay.isI18n()) {
            redirect = layout.getFriendlyURL();
        }
    } else {
        String layoutURL = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay, locale);

        int pos = redirect.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

        if (pos == -1) {
            pos = redirect.indexOf(StringPool.QUESTION);
        }

        if (pos != -1) {
            redirect = layoutURL + redirect.substring(pos);
        } else {
            redirect = layoutURL;
        }
    }

    actionResponse.sendRedirect(redirect);
}