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, String defaultValue) 

Source Link

Usage

From source file:com.beorn.onlinepayment.rule.ConditionRegistry.java

License:Open Source License

public JSONObject toJSONObject(PortletConfig portletConfig, Locale locale) throws JSONException {
    JSONObject result = new JSONObject();

    for (ConditionClassDeclaration conditionClassDeclaration : _conditionClassDeclarations) {
        Class<?> entryClass = conditionClassDeclaration.getConditionClass();
        List<FieldDeclaration> entryFieldDeclarations = conditionClassDeclaration.getFieldDeclarations();

        JSONArray fields = new JSONArray();
        for (FieldDeclaration entryFieldDeclaration : entryFieldDeclarations) {
            String fieldName = entryFieldDeclaration.getName();
            if (fieldName.startsWith(StringPool.UNDERLINE))
                fieldName = fieldName.substring(1);

            ConditionField conditionField = entryFieldDeclaration.getConditionField();

            String label = LanguageUtil.get(portletConfig, locale, conditionField.label());

            JSONObject field = new JSONObject();
            field.put("type", entryFieldDeclaration.getTypeName());
            field.put("label", label);
            field.put("name", fieldName);
            field.put("hint", conditionField.hint());

            fields.put(field);// w  w w  . j a  v  a  2  s  .  com
        }

        JSONObject conditionClass = new JSONObject();
        conditionClass.put("fields", fields);
        result.put(entryClass.getName(), conditionClass);
    }

    return result;
}

From source file:com.beorn.onlinepayment.rule.RuleUtil.java

License:Open Source License

/**
 * Helper method to get an localized message explaining the condition.
 * /*from w  w  w  .j a v a2 s .c om*/
 * @param condition
 *            the condition to explain
 * @param portletConfig
 *            context to find key / translation correspondences
 * @param locale
 *            the locale in which the explanation will be translated
 * @return a localized string explaining the condition
 * @throws RuleException
 */
public static <T> String explain(Condition<T> condition, final PortletConfig portletConfig, final Locale locale)
        throws RuleException {

    return condition.explain(new ConditionExplainContext() {
        public String get(String key) {
            return LanguageUtil.get(portletConfig, locale, key);
        }

        public String format(String key, Object... arguments) {
            return LanguageUtil.format(portletConfig, locale, key, arguments);
        }
    });

}

From source file:com.liferay.asset.util.AssetPublisherAddItemHolder.java

License:Open Source License

/**
 * @see AssetRendererFactory#getTypeName(Locale)
 *///w  w w.ja v  a 2 s  .c o  m
private String _getModelResource(ResourceBundle resourceBundle) {
    String modelResourceNamePrefix = ResourceActionsUtil.getModelResourceNamePrefix();

    String key = modelResourceNamePrefix.concat(_name);

    String value = LanguageUtil.get(_locale, key, null);

    if ((value == null) && (resourceBundle != null)) {
        value = ResourceBundleUtil.getString(resourceBundle, key);
    }

    if (value == null) {
        value = _name;
    }

    return value;
}

From source file:com.liferay.content.targeting.portlet.util.AssetQueryRule.java

License:Open Source License

protected String htmlOperator(Boolean andOperator, boolean contains, PortletConfig portletConfig,
        Locale locale) {/*from w w w . j a  v a  2 s  . c o m*/

    StringBundler sb = new StringBundler(5);

    String cssClass = "query-operator";

    if ((andOperator == null) && !contains) {
        sb.append(LanguageUtil.get(portletConfig, locale, "not"));
        sb.append(StringPool.SPACE);

        cssClass += " first";
    } else {
        sb.append(StringPool.SPACE);

        sb.append(andOperator ? LanguageUtil.get(portletConfig, locale, "and")
                : LanguageUtil.get(portletConfig, locale, "or"));

        sb.append(StringPool.SPACE);

        if (!contains) {
            sb.append(LanguageUtil.get(portletConfig, locale, "not"));
            sb.append(StringPool.SPACE);
        }
    }

    StringBundler html = new StringBundler(5);

    html.append("<span class=\"");
    html.append(cssClass);
    html.append("\">");
    html.append(StringUtil.toLowerCase(sb.toString()));
    html.append("</span>");

    return html.toString();
}

From source file:com.liferay.content.targeting.portlet.util.CampaignQueryRule.java

License:Open Source License

public String getSummary(PortletConfig portletConfig, Locale locale) throws SystemException {

    if (_campaign == null) {
        return LanguageUtil.get(portletConfig, locale, "default");
    }/*from   w  w  w  .j a v a 2  s . c om*/

    return getCampaignName(locale);
}

From source file:com.liferay.content.targeting.portlet.util.UserSegmentQueryRule.java

License:Open Source License

public String getSummary(PortletConfig portletConfig, Locale locale) throws SystemException {

    if (ArrayUtil.isEmpty(_userSegmentAssetCategoryIds)) {
        return LanguageUtil.get(portletConfig, locale, "default");
    }// w ww.j  a v  a 2 s. c o  m

    String summary = StringPool.BLANK;

    if (!_contains) {
        summary = summary + htmlOperator(null, _contains, portletConfig, locale);
    }

    return summary + getUserSegmentNames(locale, htmlOperator(_andOperator, _contains, portletConfig, locale));
}

From source file:com.liferay.mail.vaadin.Lang.java

License:Open Source License

public static String get(String key) {
    return LanguageUtil.get(Controller.get().getPortletConfig(), Controller.get().getUserLocale(), key);
}

From source file:com.liferay.music.portlet.MusicPortlet.java

License:Open Source License

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    try {//ww w.  j  ava  2  s . c  om
        if (resourceRequest.getResourceID().equals("search-resource")) {
            String music = ParamUtil.getString(resourceRequest, "music");

            if (music == null) {
                return;
            }

            Bend bend = BendLocalServiceUtil.getBend(music);

            if (bend == null) {
                if (_log.isInfoEnabled()) {
                    _log.info(music + " was not found.");
                }

                JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

                String message = LanguageUtil.get(getPortletConfig(), resourceRequest.getLocale(),
                        "sorry-we-currently-dont-have-that-in-our-base");

                jsonObject.put("notFound", message);

                writeJSON(resourceRequest, resourceResponse, jsonObject);

                return;
            }

            if (_log.isInfoEnabled()) {
                _log.info(music + " was found.");
            }

            Gson gson = MusicFiles.getGson();

            String json = gson.toJson(bend);

            writeJSON(resourceRequest, resourceResponse, json);
        }
    } catch (Exception e) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("errorMsg", "Error.");

        _log.error(e);

        writeJSON(resourceRequest, resourceResponse, jsonObject);
    }
}

From source file:com.liferay.users.admin.internal.user.initials.generator.UserInitialsGeneratorImpl.java

License:Open Source License

private String[] _getUserInitialsFieldNames(Locale locale) {
    String[] userInitialsFieldNames = _userInitialsFieldNamesMap.get(locale);

    if (userInitialsFieldNames != null) {
        return userInitialsFieldNames;
    }//from   ww w  .  j a va2 s.  com

    userInitialsFieldNames = StringUtil
            .split(LanguageUtil.get(locale, LanguageConstants.KEY_USER_INITIALS_FIELD_NAMES, null));

    if (ArrayUtil.isEmpty(userInitialsFieldNames)) {
        userInitialsFieldNames = _DEFAULT_USER_INITIALS_FIELD_NAMES;
    }

    _userInitialsFieldNamesMap.put(locale, userInitialsFieldNames);

    return userInitialsFieldNames;
}

From source file:com.rivetlogic.tout.portlet.ToutConfigPortlet.java

License:Open Source License

private void displayMatchingPages(ResourceRequest request, ResourceResponse response) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig = (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    try {/* w w w  .j a  v a 2s  .com*/
        String sitesIdsParam = ParamUtil.getString(request, ToutPortletConstants.ATTR_TOUT_SITES);
        String pagesRegex = ParamUtil.getString(request, ToutPortletConstants.ATTR_TOUT_PAGES);
        if (null == pagesRegex || pagesRegex.isEmpty()) {
            printJsonResponse(
                    LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                            ToutPortletConstants.ERROR_BAD_PARAMETER_REGEX),
                    String.valueOf(HttpServletResponse.SC_BAD_REQUEST), response);
            return;
        }
        Pattern pattern = null;
        try {
            pattern = Pattern.compile(pagesRegex.toLowerCase());
        } catch (PatternSyntaxException e) {
            logger.error(e);
            printJsonResponse(
                    LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                            ToutPortletConstants.ERROR_BAD_PARAMETER_REGEX),
                    String.valueOf(HttpServletResponse.SC_BAD_REQUEST), response);
            return;
        }
        String[] sitesIdsArr = (null != sitesIdsParam && !sitesIdsParam.isEmpty()
                ? sitesIdsParam.split(StringPool.COMMA)
                : null);
        Set<Layout> pages = getSitesPages(sitesIdsArr, themeDisplay.getCompanyId());
        Set<String> matchingSitesPagesStr = new HashSet<String>();
        if (null != pages)
            for (Layout layout : pages) {
                if (pattern.matcher(layout.getNameCurrentValue().toLowerCase()).find()) {
                    String matchingSitePageStr = layout.getGroup().getDescriptiveName() + StringPool.SPACE
                            + StringPool.DASH + StringPool.SPACE + layout.getNameCurrentValue();
                    matchingSitesPagesStr.add(matchingSitePageStr);
                }
            }
        if (!matchingSitesPagesStr.isEmpty()) {
            JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
            for (String item : matchingSitesPagesStr) {
                jsonArray.put(JSONFactoryUtil.serialize(item));
            }
            printJsonResponse(jsonArray.toString(), String.valueOf(HttpServletResponse.SC_OK), response);
        } else {
            printJsonResponse(
                    LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                            ToutPortletConstants.ERROR_NO_MATCHING_PAGES),
                    String.valueOf(HttpServletResponse.SC_NOT_FOUND), response);
        }
    } catch (Exception e) {
        logger.error(e);
        printJsonResponse(
                LanguageUtil.get(portletConfig, themeDisplay.getLocale(),
                        ToutPortletConstants.ERROR_RETRIEVING_MATCHING_PAGES),
                String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), response);
    }
}