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

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

Introduction

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

Prototype

public static String format(ResourceBundle resourceBundle, String pattern, Object[] arguments) 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.storage.impl.DocumentLibraryFieldRenderer.java

License:Open Source License

protected String handleJSON(String json, Locale locale) {
    JSONObject jsonObject = null;//from   w  ww.  j ava 2 s .c o  m

    try {
        jsonObject = JSONFactoryUtil.createJSONObject(json);
    } catch (JSONException jsone) {
        if (_log.isDebugEnabled()) {
            _log.debug("Unable to parse JSON", jsone);
        }

        return StringPool.BLANK;
    }

    long fileEntryGroupId = jsonObject.getLong("groupId");
    String fileEntryUUID = jsonObject.getString("uuid");

    try {
        FileEntry fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(fileEntryUUID, fileEntryGroupId);

        return fileEntry.getTitle();
    } catch (Exception e) {
        if (e instanceof NoSuchFileEntryException || e instanceof PrincipalException) {

            return LanguageUtil.format(locale, "is-temporarily-unavailable", "content");
        }
    }

    return StringPool.BLANK;
}

From source file:com.liferay.dynamic.data.mapping.storage.impl.LinkToPageFieldRenderer.java

License:Open Source License

protected String handleJSON(String value, Locale locale) {
    JSONObject jsonObject = null;/*from  w w w .  ja v  a 2s .c om*/

    try {
        jsonObject = JSONFactoryUtil.createJSONObject(value);
    } catch (JSONException jsone) {
        if (_log.isDebugEnabled()) {
            _log.debug("Unable to parse JSON", jsone);
        }

        return StringPool.BLANK;
    }

    long groupId = jsonObject.getLong("groupId");
    boolean privateLayout = jsonObject.getBoolean("privateLayout");
    long layoutId = jsonObject.getLong("layoutId");

    try {
        return LayoutServiceUtil.getLayoutName(groupId, privateLayout, layoutId,
                LanguageUtil.getLanguageId(locale));
    } catch (Exception e) {
        if (e instanceof NoSuchLayoutException || e instanceof PrincipalException) {

            return LanguageUtil.format(locale, "is-temporarily-unavailable", "content");
        }
    }

    return StringPool.BLANK;
}

From source file:com.liferay.dynamic.data.mapping.type.document.library.internal.DocumentLibraryDDMFormFieldValueRenderer.java

License:Open Source License

@Override
public String render(DDMFormFieldValue ddmFormFieldValue, Locale locale) {
    JSONObject jsonObject = documentLibraryDDMFormFieldValueAccessor.getValue(ddmFormFieldValue, locale);

    String uuid = jsonObject.getString("uuid");
    long groupId = jsonObject.getLong("groupId");

    if (Validator.isNull(uuid) || (groupId == 0)) {
        return StringPool.BLANK;
    }// w  w  w. ja  v  a  2  s  .  c  om

    try {
        FileEntry fileEntry = dlAppService.getFileEntryByUuidAndGroupId(uuid, groupId);

        return fileEntry.getTitle();
    } catch (Exception e) {
        return LanguageUtil.format(locale, "is-temporarily-unavailable", "content");
    }
}

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  ww w  .j  av a 2 s . 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.faces.bridge.ext.i18n.internal.I18nLiferayImpl.java

License:Open Source License

@Override
public String getMessage(FacesContext facesContext, Locale locale, String messageId, Object... arguments) {

    String value = LanguageUtil.format(locale, messageId, arguments);

    if ((value == null) || value.equals(messageId)) {
        value = super.getMessage(facesContext, locale, messageId, arguments);
    }/*www  .  j  a  va  2s .c o m*/

    return value;
}

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

License:Open Source License

@Override
public String getMessage(Locale locale, String messageId, Object... arguments) {
    String value = LanguageUtil.format(locale, messageId, arguments);

    if ((value == null) || value.equals(messageId)) {
        value = super.getMessage(locale, messageId, arguments);
    }//from  ww  w .j  av a2  s .  c o m

    return value;
}

From source file:com.liferay.frontend.editor.alloyeditor.web.editor.configuration.AlloyEditorConfigContributor.java

License:Open Source License

protected JSONArray getStyleFormatsJSONArray(Locale locale) {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    ResourceBundle resourceBundle = null;

    try {/* www. j  a  v a 2 s. c  om*/
        resourceBundle = _resourceBundleLoader.loadResourceBundle(LocaleUtil.toLanguageId(locale));
    } catch (MissingResourceException mre) {
        resourceBundle = ResourceBundleUtil.EMPTY_RESOURCE_BUNDLE;
    }

    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "normal"), "p", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "1"), "h1", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "2"), "h2", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "3"), "h3", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "4"), "h4", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "preformatted-text"), "pre", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "cited-work"), "cite", null,
            _CKEDITOR_STYLE_INLINE));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "computer-code"), "code", null,
            _CKEDITOR_STYLE_INLINE));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "info-message"), "div",
            "portlet-msg-info", _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "alert-message"), "div",
            "portlet-msg-alert", _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "error-message"), "div",
            "portlet-msg-error", _CKEDITOR_STYLE_BLOCK));

    return jsonArray;
}

From source file:com.liferay.frontend.editor.alloyeditor.web.internal.editor.configuration.AlloyEditorConfigContributor.java

License:Open Source License

protected JSONArray getStyleFormatsJSONArray(Locale locale) {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    ResourceBundle resourceBundle = null;

    try {//  w  ww  . j a  v a  2  s.  c  o  m
        resourceBundle = _resourceBundleLoader.loadResourceBundle(locale);
    } catch (MissingResourceException mre) {
        resourceBundle = ResourceBundleUtil.EMPTY_RESOURCE_BUNDLE;
    }

    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "normal"), "p", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "1"), "h1", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "2"), "h2", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "3"), "h3", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "4"), "h4", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "preformatted-text"), "pre", null,
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "cited-work"), "cite", null,
            _CKEDITOR_STYLE_INLINE));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "computer-code"), "code", null,
            _CKEDITOR_STYLE_INLINE));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "info-message"), "div",
            "portlet-msg-info", _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "alert-message"), "div",
            "portlet-msg-alert", _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "error-message"), "div",
            "portlet-msg-error", _CKEDITOR_STYLE_BLOCK));

    return jsonArray;
}

From source file:com.liferay.frontend.editor.alloyeditor.web.internal.editor.configuration.AlloyEditorCreoleConfigContributor.java

License:Open Source License

protected JSONArray getStyleFormatsJSONArray(Locale locale) {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    ResourceBundle resourceBundle = null;

    try {//from   w w w .  j  ava  2 s  .com
        resourceBundle = _resourceBundleLoader.loadResourceBundle(locale);
    } catch (MissingResourceException mre) {
        resourceBundle = ResourceBundleUtil.EMPTY_RESOURCE_BUNDLE;
    }

    jsonArray.put(
            getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "normal"), "p", _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "1"), "h1",
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "2"), "h2",
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "3"), "h3",
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "4"), "h4",
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "5"), "h5",
            _CKEDITOR_STYLE_BLOCK));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "6"), "h6",
            _CKEDITOR_STYLE_BLOCK));

    return jsonArray;
}

From source file:com.liferay.frontend.editor.ckeditor.web.editor.configuration.CKEditorConfigContributor.java

License:Open Source License

protected JSONArray getStyleFormatsJSONArray(Locale locale) {
    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    ResourceBundle resourceBundle = null;

    try {// w w  w  . ja va 2  s. c o  m
        resourceBundle = _resourceBundleLoader.loadResourceBundle(LocaleUtil.toLanguageId(locale));
    } catch (MissingResourceException mre) {
        resourceBundle = ResourceBundleUtil.EMPTY_RESOURCE_BUNDLE;
    }

    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "normal"), "p", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "1"), "h1", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "2"), "h2", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "3"), "h3", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.format(resourceBundle, "heading-x", "4"), "h4", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "preformatted-text"), "pre", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "cited-work"), "cite", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "computer-code"), "code", null));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "info-message"), "div",
            "portlet-msg-info"));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "alert-message"), "div",
            "portlet-msg-alert"));
    jsonArray.put(getStyleFormatJSONObject(LanguageUtil.get(resourceBundle, "error-message"), "div",
            "portlet-msg-error"));

    return jsonArray;
}