Example usage for com.liferay.portal.kernel.language LanguageUtil get

List of usage examples for com.liferay.portal.kernel.language LanguageUtil get

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.language LanguageUtil get.

Prototype

public static String get(ResourceBundle resourceBundle, String key) 

Source Link

Usage

From source file:com.liferay.exportimport.internal.background.task.display.ExportImportBackgroundTaskDisplay.java

License:Open Source License

protected String getStagedModelMessage(Locale locale) {
    StringBundler sb = new StringBundler(8);

    sb.append("<strong>");
    sb.append(LanguageUtil.get(locale, getStatusMessageKey()));
    sb.append(StringPool.TRIPLE_PERIOD);
    sb.append("</strong>");
    sb.append(ResourceActionsUtil.getModelResource(locale, _stagedModelType));
    sb.append("<em>");
    sb.append(HtmlUtil.escape(_stagedModelName));
    sb.append("</em>");

    return sb.toString();
}

From source file:com.liferay.exportimport.internal.background.task.display.LayoutStagingBackgroundTaskDisplay.java

License:Open Source License

@Override
public String getDisplayName(HttpServletRequest request) {
    if ((sourceGroup != null) && !sourceGroup.isStagingGroup()
            && (backgroundTask.getGroupId() == sourceGroup.getGroupId())) {

        return LanguageUtil.get(request, "initial-publication");
    }/*  w ww. j  ava  2 s .c  o  m*/

    if (Validator.isNull(backgroundTask.getName())) {
        return LanguageUtil.get(request, "untitled");
    }

    return backgroundTask.getName();
}

From source file:com.liferay.exportimport.internal.background.task.display.PortletExportImportBackgroundTaskDisplay.java

License:Open Source License

@Override
public String getDisplayName(HttpServletRequest request) {
    if (Validator.isNull(backgroundTask.getName())) {
        return LanguageUtil.get(request, "untitled");
    }//from  w  w w  . j  a va2 s  . co  m

    return portlet.getDisplayName();
}

From source file:com.liferay.exportimport.internal.notifications.ExportImportUserNotificationHandler.java

License:Open Source License

@Override
protected String getBody(UserNotificationEvent userNotificationEvent, ServiceContext serviceContext)
        throws Exception {

    Locale locale = _portal.getLocale(serviceContext.getRequest());

    ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(locale);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload());

    ExportImportConfiguration exportImportConfiguration = null;

    try {/*from   w w w  . j  a  va 2s. com*/
        exportImportConfiguration = _exportImportConfigurationLocalService
                .getExportImportConfiguration(jsonObject.getLong("exportImportConfigurationId"));
    } catch (PortalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return LanguageUtil.get(resourceBundle, "the-process-referenced-by-this-notification-does-not-exist");
    }

    String message = "x-"
            + ExportImportConfigurationConstants.getTypeLabel(exportImportConfiguration.getType());

    int status = jsonObject.getInt("status");

    if (status == BackgroundTaskConstants.STATUS_SUCCESSFUL) {
        message += "-process-finished-successfully";
    } else if (status == BackgroundTaskConstants.STATUS_FAILED) {
        message += "-process-failed";
    } else {
        return "Unable to process notification: " + HtmlUtil.escape(jsonObject.toString());
    }

    long backgroundTaskId = jsonObject.getLong("backgroundTaskId");

    BackgroundTaskDisplay backgroundTaskDisplay = _backgroundTaskDisplayFactory
            .getBackgroundTaskDisplay(backgroundTaskId);

    String processName = backgroundTaskDisplay.getDisplayName(serviceContext.getRequest());

    return LanguageUtil.format(resourceBundle, message, processName);
}

From source file:com.liferay.exportimport.resources.importer.internal.portlet.configuration.icon.ViewJournalSourcePortletConfigurationIcon.java

License:Open Source License

@Override
public String getMessage(PortletRequest portletRequest) {
    return LanguageUtil.get(getResourceBundle(getLocale(portletRequest)), "view-source");
}

From source file:com.liferay.exportimport.staging.StagingImpl.java

License:Open Source License

@Override
public JSONObject getExceptionMessagesJSONObject(Locale locale, Exception e,
        ExportImportConfiguration exportImportConfiguration) {

    JSONObject exceptionMessagesJSONObject = JSONFactoryUtil.createJSONObject();

    String errorMessage = StringPool.BLANK;
    JSONArray errorMessagesJSONArray = null;
    int errorType = 0;
    JSONArray warningMessagesJSONArray = null;

    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", locale, getClass());

    Throwable cause = e.getCause();

    if (e instanceof DuplicateFileEntryException) {
        errorMessage = LanguageUtil.get(locale, "please-enter-a-unique-document-name");
        errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION;
    } else if (e instanceof FileExtensionException) {
        errorMessage = LanguageUtil.format(locale,
                "document-names-must-end-with-one-of-the-following-extensions", ".lar", false);
        errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION;
    } else if (e instanceof FileNameException) {
        errorMessage = LanguageUtil.get(locale, "please-enter-a-file-with-a-valid-file-name");
        errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION;
    } else if (e instanceof FileSizeException || e instanceof LARFileSizeException) {

        if ((exportImportConfiguration != null) && ((exportImportConfiguration
                .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL)
                || (exportImportConfiguration
                        .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_REMOTE)
                || (exportImportConfiguration
                        .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET))) {

            errorMessage = LanguageUtil.get(locale,
                    "file-size-limit-exceeded.-please-ensure-that-the-file-"
                            + "does-not-exceed-the-file-size-limit-in-both-the-"
                            + "live-environment-and-the-staging-environment");
        } else {//w  w w.j a v a  2  s  . c om
            errorMessage = LanguageUtil.format(locale,
                    "please-enter-a-file-with-a-valid-file-size-no-larger-" + "than-x",
                    TextFormatter.formatStorageSize(_dlValidator.getMaxAllowableSize(), locale), false);
        }

        errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION;
    } else if (e instanceof LARTypeException) {
        LARTypeException lte = (LARTypeException) e;

        if (lte.getType() == LARTypeException.TYPE_COMPANY_GROUP) {
            errorMessage = LanguageUtil.format(resourceBundle, "a-x-can-only-be-imported-to-a-x",
                    "global-site");
        } else if (lte.getType() == LARTypeException.TYPE_LAYOUT_PROTOTYPE) {
            errorMessage = LanguageUtil.format(resourceBundle, "a-x-can-only-be-imported-to-a-x",
                    LanguageUtil.get(locale, "page-template"));
        } else if (lte.getType() == LARTypeException.TYPE_LAYOUT_SET) {
            errorMessage = LanguageUtil.format(resourceBundle, "a-x-can-only-be-imported-to-a-x", "site");
        } else if (lte.getType() == LARTypeException.TYPE_LAYOUT_SET_PROTOTYPE) {

            errorMessage = LanguageUtil.format(resourceBundle, "a-x-can-only-be-imported-to-a-x",
                    LanguageUtil.get(locale, "site-template"));
        } else {
            errorMessage = LanguageUtil.format(resourceBundle, "uploaded-lar-file-type-x-does-not-match-x",
                    new Object[] { lte.getActualLARType(),
                            StringUtil.merge(lte.getExpectedLARTypes(), StringPool.COMMA_AND_SPACE) });
        }

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else if (e instanceof LARFileException) {
        LARFileException lfe = (LARFileException) e;

        if (lfe.getType() == LARFileException.TYPE_INVALID_MANIFEST) {
            errorMessage = LanguageUtil.format(resourceBundle, "invalid-manifest.xml-x", lfe.getMessage());
        } else if (lfe.getType() == LARFileException.TYPE_MISSING_MANIFEST) {
            errorMessage = LanguageUtil.get(resourceBundle, "missing-manifest.xml");
        } else {
            errorMessage = LanguageUtil.get(locale, "please-specify-a-lar-file-to-import");
        }

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else if (e instanceof LayoutImportException || cause instanceof LayoutImportException) {

        LayoutImportException lie = null;

        if (e instanceof LayoutImportException) {
            lie = (LayoutImportException) e;
        } else {
            lie = (LayoutImportException) cause;
        }

        if (lie.getType() == LayoutImportException.TYPE_WRONG_BUILD_NUMBER) {

            errorMessage = LanguageUtil.format(resourceBundle,
                    "lar-build-number-x-does-not-match-portal-build-number-x", lie.getArguments());
        } else if (lie.getType() == LayoutImportException.TYPE_WRONG_LAR_SCHEMA_VERSION) {

            errorMessage = LanguageUtil.format(resourceBundle,
                    "lar-schema-version-x-does-not-match-deployed-export-" + "import-schema-version-x",
                    lie.getArguments());
        } else if (lie.getType() == LayoutImportException.TYPE_WRONG_PORTLET_SCHEMA_VERSION) {

            Object[] arguments = lie.getArguments();

            Portlet portlet = _portletLocalService.getPortletById((String) arguments[1]);

            arguments[1] = portlet.getDisplayName();

            errorMessage = LanguageUtil.format(resourceBundle,
                    "portlet's-schema-version-x-in-the-lar-is-not-valid-for-"
                            + "the-deployed-portlet-x-with-schema-version-x",
                    lie.getArguments());
        } else {
            errorMessage = e.getLocalizedMessage();
        }

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else if (e instanceof LayoutPrototypeException) {
        LayoutPrototypeException lpe = (LayoutPrototypeException) e;

        StringBundler sb = new StringBundler(4);

        sb.append("the-lar-file-could-not-be-imported-because-it-");
        sb.append("requires-page-templates-or-site-templates-that-could-");
        sb.append("not-be-found.-please-import-the-following-templates-");
        sb.append("manually");

        errorMessage = LanguageUtil.get(resourceBundle, sb.toString());

        errorMessagesJSONArray = JSONFactoryUtil.createJSONArray();

        List<Tuple> missingLayoutPrototypes = lpe.getMissingLayoutPrototypes();

        for (Tuple missingLayoutPrototype : missingLayoutPrototypes) {
            JSONObject errorMessageJSONObject = JSONFactoryUtil.createJSONObject();

            String layoutPrototypeUuid = (String) missingLayoutPrototype.getObject(1);

            errorMessageJSONObject.put("info", layoutPrototypeUuid);

            String layoutPrototypeName = (String) missingLayoutPrototype.getObject(2);

            errorMessageJSONObject.put("name", layoutPrototypeName);

            String layoutPrototypeClassName = (String) missingLayoutPrototype.getObject(0);

            errorMessageJSONObject.put("type",
                    ResourceActionsUtil.getModelResource(locale, layoutPrototypeClassName));

            errorMessagesJSONArray.put(errorMessageJSONObject);
        }

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else if (e instanceof LocaleException) {
        LocaleException le = (LocaleException) e;

        errorMessage = LanguageUtil.format(locale,
                "the-available-languages-in-the-lar-file-x-do-not-match-the-" + "site's-available-languages-x",
                new String[] { StringUtil.merge(le.getSourceAvailableLocales(), StringPool.COMMA_AND_SPACE),
                        StringUtil.merge(le.getTargetAvailableLocales(), StringPool.COMMA_AND_SPACE) },
                false);

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else if (e instanceof MissingReferenceException) {
        MissingReferenceException mre = (MissingReferenceException) e;

        if ((exportImportConfiguration != null) && ((exportImportConfiguration
                .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL)
                || (exportImportConfiguration
                        .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_REMOTE)
                || (exportImportConfiguration
                        .getType() == ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET))) {

            errorMessage = LanguageUtil.get(locale, "there-are-missing-references-that-could-not-be-found-in-"
                    + "the-live-environment-the-following-elements-are-" + "published-from-their-own-site");
        } else {
            errorMessage = LanguageUtil.get(locale,
                    "there-are-missing-references-that-could-not-be-found-in-" + "the-current-site");
        }

        MissingReferences missingReferences = mre.getMissingReferences();

        errorMessagesJSONArray = getErrorMessagesJSONArray(locale,
                missingReferences.getDependencyMissingReferences());

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
        warningMessagesJSONArray = getWarningMessagesJSONArray(locale,
                missingReferences.getWeakMissingReferences());
    } else if (e instanceof PortletDataException) {
        PortletDataException pde = (PortletDataException) e;

        String referrerClassName = pde.getStagedModelClassName();
        String referrerDisplayName = pde.getStagedModelDisplayName();

        String modelResource = ResourceActionsUtil.getModelResource(locale, referrerClassName);

        if (pde.getType() == PortletDataException.DELETE_PORTLET_DATA) {
            if (Validator.isNotNull(pde.getLocalizedMessage())) {
                errorMessage = LanguageUtil.format(locale,
                        "the-following-error-in-x-while-deleting-its-data-" + "has-stopped-the-process-x",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale),
                                pde.getLocalizedMessage() },
                        false);
            } else {
                errorMessage = LanguageUtil.format(locale,
                        "an-unexpected-error-in-x-while-deleting-its-data-" + "has-stopped-the-process",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale) }, false);
            }
        } else if (pde.getType() == PortletDataException.EXPORT_PORTLET_DATA) {

            if (Validator.isNotNull(pde.getLocalizedMessage())) {
                errorMessage = LanguageUtil.format(locale,
                        "the-following-error-in-x-while-exporting-its-data-" + "has-stopped-the-process-x",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale),
                                pde.getLocalizedMessage() },
                        false);
            } else {
                errorMessage = LanguageUtil.format(locale,
                        "an-unexpected-error-in-x-while-exporting-its-data-" + "has-stopped-the-process",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale) }, false);
            }
        } else if (pde.getType() == PortletDataException.IMPORT_PORTLET_DATA) {

            if (Validator.isNotNull(pde.getLocalizedMessage())) {
                errorMessage = LanguageUtil.format(locale,
                        "the-following-error-in-x-while-importing-its-data-" + "has-stopped-the-process-x",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale),
                                pde.getLocalizedMessage() },
                        false);
            } else {
                errorMessage = LanguageUtil.format(locale,
                        "an-unexpected-error-in-x-while-importing-its-data-" + "has-stopped-the-process",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale) }, false);
            }
        } else if (pde.getType() == PortletDataException.INVALID_GROUP) {
            errorMessage = LanguageUtil.format(locale,
                    "the-x-x-could-not-be-exported-because-it-is-not-in-the-" + "currently-exported-group",
                    new String[] { modelResource, referrerDisplayName }, false);
        } else if (pde.getType() == PortletDataException.MISSING_DEPENDENCY) {
            errorMessage = LanguageUtil.format(locale,
                    "the-x-x-has-missing-references-that-could-not-be-found-" + "during-the-process",
                    new String[] { modelResource, referrerDisplayName }, false);
        } else if (pde.getType() == PortletDataException.PREPARE_MANIFEST_SUMMARY) {

            if (Validator.isNotNull(pde.getLocalizedMessage())) {
                errorMessage = LanguageUtil.format(locale,
                        "the-following-error-in-x-while-preparing-its-" + "manifest-has-stopped-the-process-x",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale),
                                pde.getLocalizedMessage() },
                        false);
            } else {
                errorMessage = LanguageUtil.format(locale,
                        "an-unexpected-error-in-x-while-preparing-its-" + "manifest-has-stopped-the-process",
                        new String[] { _portal.getPortletTitle(pde.getPortletId(), locale) }, false);
            }
        } else if (pde.getType() == PortletDataException.STATUS_IN_TRASH) {
            errorMessage = LanguageUtil.format(locale,
                    "the-x-x-could-not-be-exported-because-it-is-in-the-" + "recycle-bin",
                    new String[] { modelResource, referrerDisplayName }, false);
        } else if (pde.getType() == PortletDataException.STATUS_UNAVAILABLE) {
            errorMessage = LanguageUtil.format(locale,
                    "the-x-x-could-not-be-exported-because-its-workflow-" + "status-is-not-exportable",
                    new String[] { modelResource, referrerDisplayName }, false);
        } else if (Validator.isNotNull(referrerDisplayName)) {
            errorMessage = LanguageUtil.format(resourceBundle,
                    "the-following-error-occurred-while-processing-the-x-x-x",
                    new String[] { modelResource, referrerDisplayName, e.getLocalizedMessage() });
        } else {
            errorMessage = e.getLocalizedMessage();
        }

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else if (e instanceof PortletIdException) {
        PortletIdException pie = (PortletIdException) e;

        Portlet portlet = _portletLocalService.getPortletById(pie.getMessage());

        errorMessage = LanguageUtil.format(resourceBundle, "a-x-can-only-be-imported-to-a-x",
                portlet.getDisplayName() + " Portlet");

        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    } else {
        errorMessage = e.getLocalizedMessage();
        errorType = ServletResponseConstants.SC_FILE_CUSTOM_EXCEPTION;
    }

    exceptionMessagesJSONObject.put("message", errorMessage);

    if ((errorMessagesJSONArray != null) && (errorMessagesJSONArray.length() > 0)) {

        exceptionMessagesJSONObject.put("messageListItems", errorMessagesJSONArray);
    }

    exceptionMessagesJSONObject.put("status", errorType);

    if ((warningMessagesJSONArray != null) && (warningMessagesJSONArray.length() > 0)) {

        exceptionMessagesJSONObject.put("warningMessages", warningMessagesJSONArray);
    }

    return exceptionMessagesJSONObject;
}

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 ww.  j a va2  s  .  c o m
    }

    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.configuration.icon.ExportImportPortletConfigurationIcon.java

License:Open Source License

@Override
public String getMessage(PortletRequest portletRequest) {
    return LanguageUtil.get(getResourceBundle(getLocale(portletRequest)), "export-import");
}

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());/* ww  w .  j  a  v  a 2s.c  om*/
    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.exportimport.web.internal.portlet.configuration.icon.ExportTemplatesConfigurationIcon.java

License:Open Source License

@Override
public String getMessage(PortletRequest portletRequest) {
    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", getLocale(portletRequest),
            getClass());//  w w  w . ja  v  a 2  s  . co m

    return LanguageUtil.get(resourceBundle, "export-templates");
}