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.exportimport.web.internal.portlet.action.ExportImportMVCActionCommand.java

License:Open Source License

protected void importData(ActionRequest actionRequest, InputStream inputStream) throws Exception {

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

    long plid = ParamUtil.getLong(actionRequest, "plid");
    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    Map<String, Serializable> importPortletSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportPortletSettingsMap(themeDisplay.getUserId(), plid, groupId, portlet.getPortletId(),
                    actionRequest.getParameterMap(), themeDisplay.getLocale(), themeDisplay.getTimeZone());

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .addDraftExportImportConfiguration(themeDisplay.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_PORTLET, importPortletSettingsMap);

    _exportImportService.importPortletInfoInBackground(exportImportConfiguration, inputStream);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ExportImportMVCActionCommand.java

License:Open Source License

protected void validateFile(ActionRequest actionRequest, ActionResponse actionResponse, String folderName)
        throws Exception {

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

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

    FileEntry fileEntry = _exportImportHelper.getTempFileEntry(groupId, themeDisplay.getUserId(), folderName);

    try (InputStream inputStream = _dlFileEntryLocalService.getFileAsStream(fileEntry.getFileEntryId(),
            fileEntry.getVersion(), false)) {

        MissingReferences missingReferences = validateFile(actionRequest, inputStream);

        Map<String, MissingReference> weakMissingReferences = missingReferences.getWeakMissingReferences();

        if (weakMissingReferences.isEmpty()) {
            return;
        }/*from w  ww.jav  a2  s . c  om*/

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        if ((weakMissingReferences != null) && !weakMissingReferences.isEmpty()) {

            jsonObject.put("warningMessages",
                    _staging.getWarningMessagesJSONArray(themeDisplay.getLocale(), weakMissingReferences));
        }

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    }
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ExportImportMVCActionCommand.java

License:Open Source License

protected MissingReferences validateFile(ActionRequest actionRequest, InputStream inputStream)
        throws Exception {

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

    long plid = ParamUtil.getLong(actionRequest, "plid");
    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    Map<String, Serializable> importPortletSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportPortletSettingsMap(themeDisplay.getUserId(), plid, groupId, portlet.getPortletId(),
                    actionRequest.getParameterMap(), themeDisplay.getLocale(), themeDisplay.getTimeZone());

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .addDraftExportImportConfiguration(themeDisplay.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_PORTLET, importPortletSettingsMap);

    return _exportImportService.validateImportPortletInfo(exportImportConfiguration, inputStream);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ExportLayoutsMVCActionCommand.java

License:Open Source License

protected ExportImportConfiguration getExportImportConfiguration(ActionRequest actionRequest) throws Exception {

    Map<String, Serializable> exportLayoutSettingsMap = null;

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

    if (exportImportConfigurationId > 0) {
        ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
                .fetchExportImportConfiguration(exportImportConfigurationId);

        if (exportImportConfiguration != null) {
            exportLayoutSettingsMap = exportImportConfiguration.getSettingsMap();
        }//from  w w w.j a va  2 s .  c om
    }

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

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

    if (exportLayoutSettingsMap == null) {
        long groupId = ParamUtil.getLong(actionRequest, "liveGroupId");
        long[] layoutIds = getLayoutIds(actionRequest);

        exportLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory.buildExportLayoutSettingsMap(
                themeDisplay.getUserId(), groupId, privateLayout, layoutIds, actionRequest.getParameterMap(),
                themeDisplay.getLocale(), themeDisplay.getTimeZone());
    }

    String taskName = ParamUtil.getString(actionRequest, "name");

    if (Validator.isNull(taskName)) {
        if (privateLayout) {
            taskName = LanguageUtil.get(actionRequest.getLocale(), "private-pages");
        } else {
            taskName = LanguageUtil.get(actionRequest.getLocale(), "public-pages");
        }
    }

    return _exportImportConfigurationLocalService.addDraftExportImportConfiguration(themeDisplay.getUserId(),
            taskName, ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT, exportLayoutSettingsMap);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ImportLayoutsMVCActionCommand.java

License:Open Source License

protected void handleUploadException(ActionRequest actionRequest, ActionResponse actionResponse,
        String folderName, Exception e) throws Exception {

    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    response.setContentType(ContentTypes.TEXT_HTML);
    response.setStatus(HttpServletResponse.SC_OK);

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

    deleteTempFileEntry(themeDisplay.getScopeGroupId(), folderName);

    JSONObject jsonObject = _staging.getExceptionMessagesJSONObject(themeDisplay.getLocale(), e,
            (ExportImportConfiguration) null);

    JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ImportLayoutsMVCActionCommand.java

License:Open Source License

protected void importData(ActionRequest actionRequest, String fileName, InputStream inputStream)
        throws Exception {

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");

    Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportLayoutSettingsMap(themeDisplay.getUserId(), groupId, privateLayout, null,
                    actionRequest.getParameterMap(), themeDisplay.getLocale(), themeDisplay.getTimeZone());

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .addDraftExportImportConfiguration(themeDisplay.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap);

    _exportImportService.importLayoutsInBackground(exportImportConfiguration, inputStream);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ImportLayoutsMVCActionCommand.java

License:Open Source License

protected MissingReferences validateFile(ActionRequest actionRequest, InputStream inputStream)
        throws Exception {

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");

    Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportLayoutSettingsMap(themeDisplay.getUserId(), groupId, privateLayout, null,
                    actionRequest.getParameterMap(), themeDisplay.getLocale(), themeDisplay.getTimeZone());

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .addDraftExportImportConfiguration(themeDisplay.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap);

    return _exportImportService.validateImportLayoutsFile(exportImportConfiguration, inputStream);
}

From source file:com.liferay.exportimport.web.internal.portlet.configuration.icon.ExportImportPortletConfigurationIcon.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  . ja v a2 s .  c  o m
    sb.append("_', portletId: '");
    sb.append(portletDisplay.getId());
    sb.append("', title: '");
    sb.append(LanguageUtil.get(themeDisplay.getLocale(), "export-import"));
    sb.append("', uri: '");
    sb.append(HtmlUtil.escapeJS(portletDisplay.getURLExportImport()));
    sb.append("'}); return false;");

    return sb.toString();
}

From source file:com.liferay.faces.bridge.demos.bean.RuntimeBacking.java

License:Open Source License

@PostConstruct
public void postConstruct() {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Map<String, Object> requestAttributeMap = facesContext.getExternalContext().getRequestMap();
    ThemeDisplay themeDisplay = (ThemeDisplay) requestAttributeMap.get(WebKeys.THEME_DISPLAY);

    try {/* w  w w .j  a v a  2  s. c om*/
        long companyId = themeDisplay.getCompanyId();
        long userId = themeDisplay.getUserId();
        long groupId = themeDisplay.getScopeGroupId();
        long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
        Locale locale = themeDisplay.getLocale();

        StringBuilder content1 = new StringBuilder(9);
        content1.append("<?xml version=\"1.0\"?>");
        content1.append("<root available-locales=\"en_US\" default-locale=\"en_US\">");
        content1.append(
                "<dynamic-element name=\"content\" type=\"text_area\" index-type=\"keyword\" instance-id=\"zeun\">");
        content1.append("<dynamic-content language-id=\"en_US\"><![CDATA[");
        content1.append(
                "<p>Liferay Portal is an enterprise web platform for building business solutions that deliver ");
        content1.append("immediate results and long-term value.</p>");
        content1.append("]]></dynamic-content>");
        content1.append("</dynamic-element>");
        content1.append("</root>");

        JournalArticle article1 = WebContentUtil.getArticle(companyId, userId, groupId, folderId, locale,
                "Liferay Portal", content1.toString());
        this.preferencesArticle1 = getPreferences(article1.getGroupId(), article1.getArticleId());

        StringBuilder content2 = new StringBuilder(9);
        content2.append("<?xml version=\"1.0\"?>");
        content2.append("<root available-locales=\"en_US\" default-locale=\"en_US\">");
        content2.append(
                "<dynamic-element name=\"content\" type=\"text_area\" index-type=\"keyword\" instance-id=\"yujh\">");
        content2.append("<dynamic-content language-id=\"en_US\"><![CDATA[");
        content2.append(
                "<p>Liferay Faces is an umbrella project that provides support for the JavaServer Faces (JSF) ");
        content2.append("standard within Liferay Portal.</p>");
        content2.append("]]></dynamic-content>");
        content2.append("</dynamic-element>");
        content2.append("</root>");

        JournalArticle article2 = WebContentUtil.getArticle(companyId, userId, groupId, folderId, locale,
                "Liferay Faces", content2.toString());
        this.preferencesArticle2 = getPreferences(article2.getGroupId(), article2.getArticleId());
    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:com.liferay.faces.portal.context.internal.LiferayFacesContextImpl.java

License:Open Source License

/**
 * @see  FacesContextHelper#getLocale()/*  w  w w .  java  2  s . c  om*/
 */
@Override
public Locale getLocale() {
    Locale locale = null;

    // Try and get the current user's locale from Liferay, since they can override the locale with the Liferay
    // Language portlet.
    ThemeDisplay themeDisplay = getThemeDisplay();

    if (themeDisplay != null) {
        locale = themeDisplay.getLocale();
    }

    // If Liferay didn't return a locale, then try and get the locale from the JSF ViewRoot.
    if (locale == null) {
        locale = getViewRoot().getLocale();
    }

    // If the JSF ViewRoot didn't return a locale, then try and get it from the JSF Application.
    if (locale == null) {
        locale = getApplication().getDefaultLocale();
    }

    // Otherwise, if we couldn't determine the locale, just use the server's default value.
    if (locale == null) {
        locale = Locale.getDefault();
    }

    return locale;
}