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

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

Introduction

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

Prototype

public Locale getLocale() 

Source Link

Document

Returns the locale used for displaying content.

Usage

From source file:com.liferay.login.web.internal.portlet.util.LoginUtil.java

License:Open Source License

public static Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest,
        String emailFromAddress, String emailFromName, boolean showPasswordTerms) {

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

    Map<String, String> definitionTerms = new LinkedHashMap<>();

    definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress));
    definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName));

    if (showPasswordTerms) {
        definitionTerms.put("[$PASSWORD_RESET_URL$]",
                LanguageUtil.get(themeDisplay.getLocale(), "the-password-reset-url"));
    }//from w w w .  ja v a  2  s  .  c om

    Company company = themeDisplay.getCompany();

    definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname());

    definitionTerms.put("[$REMOTE_ADDRESS$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-browser's-remote-address"));
    definitionTerms.put("[$REMOTE_HOST$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-browser's-remote-host"));
    definitionTerms.put("[$TO_ADDRESS$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient"));
    definitionTerms.put("[$TO_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient"));
    definitionTerms.put("[$USER_ID$]", LanguageUtil.get(themeDisplay.getLocale(), "the-user-id"));

    if (showPasswordTerms) {
        definitionTerms.put("[$USER_PASSWORD$]",
                LanguageUtil.get(themeDisplay.getLocale(), "the-user-password"));
    }

    definitionTerms.put("[$USER_SCREENNAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-user-screen-name"));

    return definitionTerms;
}

From source file:com.liferay.meeting.portlet.action.AddMeetingMVCActionCommand.java

License:Open Source License

protected Calendar getStartCalendar(ActionRequest actionRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Calendar startCalendar = CalendarFactoryUtil.getCalendar(TimeZoneUtil.getTimeZone("GMT"),
            themeDisplay.getLocale());

    int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth");

    startCalendar.set(Calendar.MONTH, startDateMonth);

    int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay");

    startCalendar.set(Calendar.DATE, startDateDay);

    int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear");

    startCalendar.set(Calendar.YEAR, startDateYear);

    int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour");

    int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm");

    if (startDateAmPm == Calendar.PM) {
        startDateHour += 12;/*from www . j  a v a  2s  .  c  o  m*/
    }

    startCalendar.set(Calendar.HOUR_OF_DAY, startDateHour);

    int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute");

    startCalendar.set(Calendar.MINUTE, startDateMinute);

    startCalendar.set(Calendar.SECOND, 0);
    startCalendar.set(Calendar.MILLISECOND, 0);

    return startCalendar;
}

From source file:com.liferay.notifications.web.internal.portlet.configuration.icon.DeliveryPortletConfigurationIcon.java

License:Open Source License

@Override
public String getOnClick(PortletRequest portletRequest, PortletResponse portletResponse) {

    StringBundler sb = new StringBundler(12);

    sb.append("Liferay.Portlet.openWindow({bodyCssClass: ");
    sb.append("'dialog-with-footer', namespace: '");

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    sb.append(portletDisplay.getNamespace());

    sb.append("', portlet: '#p_p_id_");
    sb.append(portletDisplay.getId());//from w ww.  j av  a 2s.  c o  m
    sb.append("_', portletId: '");
    sb.append(portletDisplay.getId());
    sb.append("', title: '");
    sb.append(LanguageUtil.get(themeDisplay.getLocale(), "configuration"));
    sb.append("', uri: '");

    PortletURL deliveryURL = getDeliveryURL(portletRequest);

    sb.append(HtmlUtil.escapeJS(deliveryURL.toString()));

    sb.append("'}); return false;");

    return sb.toString();
}

From source file:com.liferay.notifications.web.internal.portlet.NotificationsPortlet.java

License:Open Source License

public void markAllNotificationsAsRead(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

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

    boolean actionRequired = ParamUtil.getBoolean(actionRequest, "actionRequired");

    _userNotificationEventLocalService.archiveUserNotificationEvents(themeDisplay.getUserId(),
            UserNotificationDeliveryConstants.TYPE_WEBSITE, actionRequired);

    ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale());

    SessionMessages.add(actionRequest, "requestProcessed",
            LanguageUtil.get(resourceBundle, "all-notifications-were-marked-as-read-successfully"));

    _sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.notifications.web.internal.portlet.NotificationsPortlet.java

License:Open Source License

public void updateUserNotificationDelivery(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

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

    long[] userNotificationDeliveryIds = ParamUtil.getLongValues(actionRequest, "userNotificationDeliveryIds");

    for (long userNotificationDeliveryId : userNotificationDeliveryIds) {
        boolean deliver = ParamUtil.getBoolean(actionRequest, String.valueOf(userNotificationDeliveryId));

        _userNotificationDeliveryLocalService.updateUserNotificationDelivery(userNotificationDeliveryId,
                deliver);//from w  w  w . j  a va  2s .  co  m
    }

    ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale());

    SessionMessages.add(actionRequest, "requestProcessed",
            LanguageUtil.get(resourceBundle, "your-configuration-was-saved-sucessfully"));

    _sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.configuration.icon.ConfigurationTemplatesPortletConfigurationIcon.java

License:Open Source License

@Override
public String getMessage(PortletRequest portletRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    return LanguageUtil.get(themeDisplay.getLocale(), "configuration-templates");
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

protected Tuple getNewScope(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    long scopeGroupId = 0;
    String scopeName = null;/*from  w ww . j a  v  a  2  s .c o  m*/

    if (Validator.isNull(scopeType)) {
        scopeGroupId = layout.getGroupId();
    } else if (scopeType.equals("company")) {
        scopeGroupId = themeDisplay.getCompanyGroupId();
        scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
        String scopeLayoutUuid = scopes[1];

        Layout scopeLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid, layout.getGroupId(),
                layout.isPrivateLayout());

        if (!scopeLayout.hasScopeGroup()) {
            Map<Locale, String> nameMap = new HashMap<>();

            String name = String.valueOf(scopeLayout.getPlid());

            nameMap.put(LocaleUtil.getDefault(), name);

            _groupLocalService.addGroup(themeDisplay.getUserId(), GroupConstants.DEFAULT_PARENT_GROUP_ID,
                    Layout.class.getName(), scopeLayout.getPlid(), GroupConstants.DEFAULT_LIVE_GROUP_ID,
                    nameMap, null, 0, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, false, true,
                    null);
        }

        scopeGroupId = scopeLayout.getGroupId();
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
    } else {
        throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return new Tuple(scopeGroupId, scopeName);
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
        return null;
    }//from w  w w  .j a va  2s.  c  o m

    String scopeName = null;

    if (scopeType.equals("company")) {
        scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
        String scopeLayoutUuid = GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

        Layout scopeLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid,
                layout.getGroupId(), layout.isPrivateLayout());

        if (scopeLayout != null) {
            scopeName = scopeLayout.getName(themeDisplay.getLocale());
        }
    } else {
        throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
}

From source file:com.liferay.portlet.configuration.web.internal.portlet.PortletConfigurationPortlet.java

License:Open Source License

protected String getPortletTitle(PortletRequest portletRequest, Portlet portlet,
        PortletPreferences portletPreferences) {

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

    String portletTitle = PortletConfigurationUtil.getPortletTitle(portletPreferences,
            themeDisplay.getLanguageId());

    if (Validator.isNull(portletTitle)) {
        ServletContext servletContext = (ServletContext) portletRequest.getAttribute(WebKeys.CTX);

        portletTitle = _portal.getPortletTitle(portlet, servletContext, themeDisplay.getLocale());
    }//w  w  w . jav  a2 s. c  o m

    return portletTitle;
}

From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java

License:Open Source License

public void updateActions(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    long roleId = ParamUtil.getLong(actionRequest, "roleId");

    Role role = _roleLocalService.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
            || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER)
            || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) {

        throw new RolePermissionsException(roleName);
    }//from www .jav  a2s  .co  m

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] relatedPortletResources = StringUtil
            .split(ParamUtil.getString(actionRequest, "relatedPortletResources"));
    String[] modelResources = StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));

    Map<String, List<String>> resourceActionsMap = new HashMap<>();

    if (Validator.isNotNull(portletResource)) {
        resourceActionsMap.put(portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    for (String relatedPortletResource : relatedPortletResources) {
        resourceActionsMap.put(relatedPortletResource,
                ResourceActionsUtil.getResourceActions(relatedPortletResource, null));
    }

    for (String modelResource : modelResources) {
        resourceActionsMap.put(modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
    }

    int rootResourceScope = ResourceConstants.SCOPE_COMPANY;
    String[] rootResourceGroupIds = null;

    String[] selectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));
    String[] unselectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

        String selResource = entry.getKey();
        List<String> actions = entry.getValue();

        actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

        for (String actionId : actions) {
            String target = selResource + actionId;

            boolean selected = ArrayUtil.contains(selectedTargets, target);

            if (!selected && !ArrayUtil.contains(unselectedTargets, target)) {

                continue;
            }

            String[] groupIds = StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

            groupIds = ArrayUtil.distinct(groupIds);

            int scope = ResourceConstants.SCOPE_COMPANY;

            if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
                    || (role.getType() == RoleConstants.TYPE_PROVIDER)
                    || (role.getType() == RoleConstants.TYPE_SITE)) {

                scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
            } else {
                if (groupIds.length > 0) {
                    scope = ResourceConstants.SCOPE_GROUP;
                }
            }

            updateAction(role, themeDisplay.getScopeGroupId(), selResource, actionId, selected, scope,
                    groupIds);

            if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {

                updateViewControlPanelPermission(role, themeDisplay.getScopeGroupId(), selResource, scope,
                        groupIds);

                rootResourceScope = scope;
                rootResourceGroupIds = groupIds;
            }
        }
    }

    // LPS-38031

    if (rootResourceGroupIds != null) {
        updateViewRootResourcePermission(role, themeDisplay.getScopeGroupId(), portletResource,
                rootResourceScope, rootResourceGroupIds);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

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

    if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
    }
}