Example usage for com.liferay.portal.kernel.util GetterUtil getIntegerValues

List of usage examples for com.liferay.portal.kernel.util GetterUtil getIntegerValues

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util GetterUtil getIntegerValues.

Prototype

public static int[] getIntegerValues(String[] values) 

Source Link

Document

Returns the String array values as an integer array.

Usage

From source file:com.liferay.content.targeting.portlet.CampaignContentDisplayPortlet.java

License:Open Source License

public void updatePreferences(ActionRequest request, ActionResponse response) throws Exception {

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

    long assetEntryIdDefault = ParamUtil.getLong(request, "assetEntryIdDefault");
    boolean contentDefaultValue = ParamUtil.getBoolean(request, "contentDefaultValue");

    if (!contentDefaultValue) {
        assetEntryIdDefault = 0;/*from w  w w . ja  v a  2  s.  com*/
    }

    int[] queryRulesIndexes = StringUtil.split(ParamUtil.getString(request, "queryLogicIndexes"), 0);

    if (ArrayUtil.isEmpty(queryRulesIndexes)) {
        return;
    }

    List<CampaignQueryRule> queryRules = new ArrayList<CampaignQueryRule>();

    for (int queryRulesIndex : queryRulesIndexes) {
        QueryRule queryRule = CampaignQueryRuleUtil.getQueryRule(request, queryRulesIndex,
                themeDisplay.getLocale());

        if (!queryRule.isValid()) {
            continue;
        }

        queryRules.add((CampaignQueryRule) queryRule);
    }

    PortletPreferences portletPreferences = request.getPreferences();

    int[] oldQueryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null));

    for (int queryRulesIndex : oldQueryRulesIndexes) {
        portletPreferences.setValue("campaignId" + queryRulesIndex, StringPool.BLANK);
        portletPreferences.setValue("assetEntryId" + queryRulesIndex, StringPool.BLANK);
    }

    portletPreferences.setValue("enableSocialBookmarks", String.valueOf(false));
    portletPreferences.setValue("showAssetTitle", String.valueOf(false));

    portletPreferences.setValue("assetEntryIdDefault", String.valueOf(assetEntryIdDefault));
    portletPreferences.setValue("contentDefaultValue", String.valueOf(contentDefaultValue));
    portletPreferences.setValues("queryLogicIndexes", ArrayUtil.toStringArray(queryRulesIndexes));

    for (CampaignQueryRule queryRule : queryRules) {
        portletPreferences.setValue("campaignId" + queryRule.getIndex(),
                String.valueOf(queryRule.getCampaignId()));
        portletPreferences.setValue("assetEntryId" + queryRule.getIndex(),
                String.valueOf(queryRule.getAssetEntryId()));
    }

    super.updatePreferences(request, response, portletPreferences);
}

From source file:com.liferay.content.targeting.portlet.UserSegmentContentDisplayPortlet.java

License:Open Source License

public void updatePreferences(ActionRequest request, ActionResponse response) throws Exception {

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

    long assetEntryIdDefault = ParamUtil.getLong(request, "assetEntryIdDefault");
    boolean contentDefaultValue = ParamUtil.getBoolean(request, "contentDefaultValue");

    if (!contentDefaultValue) {
        assetEntryIdDefault = 0;/*from   ww  w  .  j a  va 2s.  co m*/
    }

    int[] queryRulesIndexes = StringUtil.split(ParamUtil.getString(request, "queryLogicIndexes"), 0);

    if (ArrayUtil.isEmpty(queryRulesIndexes)) {
        return;
    }

    List<UserSegmentQueryRule> queryRules = new ArrayList<UserSegmentQueryRule>();

    for (int queryRulesIndex : queryRulesIndexes) {
        QueryRule queryRule = UserSegmentQueryRuleUtil.getQueryRule(request, queryRulesIndex,
                themeDisplay.getLocale());

        if (!queryRule.isValid()) {
            continue;
        }

        queryRules.add((UserSegmentQueryRule) queryRule);
    }

    PortletPreferences portletPreferences = request.getPreferences();

    int[] oldQueryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null));

    for (int queryRulesIndex : oldQueryRulesIndexes) {
        portletPreferences.setValue("queryContains" + queryRulesIndex, StringPool.BLANK);
        portletPreferences.setValue("queryAndOperator" + queryRulesIndex, StringPool.BLANK);
        portletPreferences.setValues("userSegmentAssetCategoryIds" + queryRulesIndex, new String[0]);
        portletPreferences.setValue("assetEntryId" + queryRulesIndex, StringPool.BLANK);
    }

    portletPreferences.setValue("enableSocialBookmarks", String.valueOf(false));
    portletPreferences.setValue("showAssetTitle", String.valueOf(false));

    portletPreferences.setValue("assetEntryIdDefault", String.valueOf(assetEntryIdDefault));
    portletPreferences.setValue("contentDefaultValue", String.valueOf(contentDefaultValue));
    portletPreferences.setValues("queryLogicIndexes", ArrayUtil.toStringArray(queryRulesIndexes));

    for (UserSegmentQueryRule queryRule : queryRules) {
        portletPreferences.setValue("queryContains" + queryRule.getIndex(),
                String.valueOf(queryRule.isContains()));
        portletPreferences.setValue("queryAndOperator" + queryRule.getIndex(),
                String.valueOf(queryRule.isAndOperator()));
        portletPreferences.setValues("userSegmentAssetCategoryIds" + queryRule.getIndex(),
                ArrayUtil.toStringArray(queryRule.getUserSegmentAssetCategoryIds()));
        portletPreferences.setValue("assetEntryId" + queryRule.getIndex(),
                String.valueOf(queryRule.getAssetEntryId()));
    }

    super.updatePreferences(request, response, portletPreferences);
}

From source file:com.liferay.contenttargeting.portlet.CampaignContentDisplayPortlet.java

License:Open Source License

public void updatePreferences(ActionRequest request, ActionResponse response) throws Exception {

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

    long assetEntryIdDefault = ParamUtil.getLong(request, "assetEntryIdDefault");
    boolean contentDefaultValue = ParamUtil.getBoolean(request, "contentDefaultValue");
    int[] queryRulesIndexes = StringUtil.split(ParamUtil.getString(request, "queryLogicIndexes"), 0);

    if (ArrayUtil.isEmpty(queryRulesIndexes)) {
        return;/*from  ww w  .j  a va  2  s  .  co m*/
    }

    List<CampaignQueryRule> queryRules = new ArrayList<CampaignQueryRule>();

    for (int queryRulesIndex : queryRulesIndexes) {
        CampaignQueryRule queryRule = CampaignQueryRuleUtil.getQueryRule(request, queryRulesIndex,
                themeDisplay.getLocale());

        if (!queryRule.isValid()) {
            break;
        }

        queryRules.add(queryRule);
    }

    PortletPreferences portletPreferences = request.getPreferences();

    int[] oldQueryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null));

    for (int queryRulesIndex : oldQueryRulesIndexes) {
        portletPreferences.setValue("campaignId" + queryRulesIndex, StringPool.BLANK);
        portletPreferences.setValue("assetEntryId" + queryRulesIndex, StringPool.BLANK);
    }

    portletPreferences.setValue("enableSocialBookmarks", String.valueOf(false));
    portletPreferences.setValue("showAssetTitle", String.valueOf(false));

    portletPreferences.setValue("assetEntryIdDefault", String.valueOf(assetEntryIdDefault));
    portletPreferences.setValue("contentDefaultValue", String.valueOf(contentDefaultValue));
    portletPreferences.setValues("queryLogicIndexes", ArrayUtil.toStringArray(queryRulesIndexes));

    for (CampaignQueryRule queryRule : queryRules) {
        portletPreferences.setValue("campaignId" + queryRule.getIndex(),
                String.valueOf(queryRule.getCampaignId()));
        portletPreferences.setValue("assetEntryId" + queryRule.getIndex(),
                String.valueOf(queryRule.getAssetEntryId()));
    }

    portletPreferences.store();
}

From source file:com.liferay.contenttargeting.portlet.UserSegmentContentDisplayPortlet.java

License:Open Source License

public void updatePreferences(ActionRequest request, ActionResponse response) throws Exception {

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

    long assetEntryIdDefault = ParamUtil.getLong(request, "assetEntryIdDefault");
    boolean contentDefaultValue = ParamUtil.getBoolean(request, "contentDefaultValue");
    int[] queryRulesIndexes = StringUtil.split(ParamUtil.getString(request, "queryLogicIndexes"), 0);

    if (ArrayUtil.isEmpty(queryRulesIndexes)) {
        return;/*from www . j a  v a2s. co m*/
    }

    List<UserSegmentQueryRule> queryRules = new ArrayList<UserSegmentQueryRule>();

    for (int queryRulesIndex : queryRulesIndexes) {
        UserSegmentQueryRule queryRule = UserSegmentQueryRuleUtil.getQueryRule(request, queryRulesIndex,
                themeDisplay.getLocale());

        if (!queryRule.isValid()) {
            break;
        }

        queryRules.add(queryRule);
    }

    PortletPreferences portletPreferences = request.getPreferences();

    int[] oldQueryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null));

    for (int queryRulesIndex : oldQueryRulesIndexes) {
        portletPreferences.setValue("queryContains" + queryRulesIndex, StringPool.BLANK);
        portletPreferences.setValue("queryAndOperator" + queryRulesIndex, StringPool.BLANK);
        portletPreferences.setValues("userSegmentAssetCategoryIds" + queryRulesIndex, new String[0]);
        portletPreferences.setValue("assetEntryId" + queryRulesIndex, StringPool.BLANK);
    }

    portletPreferences.setValue("enableSocialBookmarks", String.valueOf(false));
    portletPreferences.setValue("showAssetTitle", String.valueOf(false));

    portletPreferences.setValue("assetEntryIdDefault", String.valueOf(assetEntryIdDefault));
    portletPreferences.setValue("contentDefaultValue", String.valueOf(contentDefaultValue));
    portletPreferences.setValues("queryLogicIndexes", ArrayUtil.toStringArray(queryRulesIndexes));

    for (UserSegmentQueryRule queryRule : queryRules) {
        portletPreferences.setValue("queryContains" + queryRule.getIndex(),
                String.valueOf(queryRule.isContains()));
        portletPreferences.setValue("queryAndOperator" + queryRule.getIndex(),
                String.valueOf(queryRule.isAndOperator()));
        portletPreferences.setValues("userSegmentAssetCategoryIds" + queryRule.getIndex(),
                ArrayUtil.toStringArray(queryRule.getUserSegmentAssetCategoryIds()));
        portletPreferences.setValue("assetEntryId" + queryRule.getIndex(),
                String.valueOf(queryRule.getAssetEntryId()));
    }

    portletPreferences.store();
}

From source file:com.liferay.contenttargeting.portlet.util.CampaignQueryRuleUtil.java

License:Open Source License

public static CampaignQueryRule match(long campaignId, PortletPreferences portletPreferences, Locale locale)
        throws PortalException, SystemException {

    int[] queryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null));

    for (int queryRuleIndex : queryRulesIndexes) {
        CampaignQueryRule queryRule = getQueryRule(portletPreferences, queryRuleIndex, locale);

        if (queryRule.isValid() && (queryRule.getCampaignId() == campaignId)) {

            return queryRule;
        }/*from www  .  ja va2s  .  com*/
    }

    return null;
}

From source file:com.liferay.contenttargeting.portlet.util.UserSegmentQueryRuleUtil.java

License:Open Source License

public static UserSegmentQueryRule match(long[] userSegmentAssetCategoryIds,
        PortletPreferences portletPreferences, Locale locale) throws PortalException, SystemException {

    int[] queryRulesIndexes = GetterUtil
            .getIntegerValues(portletPreferences.getValues("queryLogicIndexes", null));

    for (int queryRuleIndex : queryRulesIndexes) {
        UserSegmentQueryRule queryRule = getQueryRule(portletPreferences, queryRuleIndex, locale);

        if (queryRule.isValid() && queryRule.evaluate(userSegmentAssetCategoryIds)) {

            return queryRule;
        }/* www . j a  va2 s .c  o m*/
    }

    return null;
}

From source file:com.liferay.expando.web.internal.portlet.ExpandoPortlet.java

License:Open Source License

protected Serializable getValue(PortletRequest portletRequest, String name, int type) throws PortalException {

    String delimiter = StringPool.COMMA;

    Serializable value = null;/*from  w  w w.  j  a  v a  2s .co m*/

    if (type == ExpandoColumnConstants.BOOLEAN) {
        value = ParamUtil.getBoolean(portletRequest, name);
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
    } else if (type == ExpandoColumnConstants.DATE) {
        User user = _portal.getUser(portletRequest);

        int valueDateMonth = ParamUtil.getInteger(portletRequest, name + "Month");
        int valueDateDay = ParamUtil.getInteger(portletRequest, name + "Day");
        int valueDateYear = ParamUtil.getInteger(portletRequest, name + "Year");
        int valueDateHour = ParamUtil.getInteger(portletRequest, name + "Hour");
        int valueDateMinute = ParamUtil.getInteger(portletRequest, name + "Minute");
        int valueDateAmPm = ParamUtil.getInteger(portletRequest, name + "AmPm");

        if (valueDateAmPm == Calendar.PM) {
            valueDateHour += 12;
        }

        value = _portal.getDate(valueDateMonth, valueDateDay, valueDateYear, valueDateHour, valueDateMinute,
                user.getTimeZone(), ValueDataException.class);
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
    } else if (type == ExpandoColumnConstants.DOUBLE) {
        value = ParamUtil.getDouble(portletRequest, name);
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getDoubleValues(values);
    } else if (type == ExpandoColumnConstants.FLOAT) {
        value = ParamUtil.getFloat(portletRequest, name);
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getFloatValues(values);
    } else if (type == ExpandoColumnConstants.INTEGER) {
        value = ParamUtil.getInteger(portletRequest, name);
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getIntegerValues(values);
    } else if (type == ExpandoColumnConstants.LONG) {
        value = ParamUtil.getLong(portletRequest, name);
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getLongValues(values);
    } else if (type == ExpandoColumnConstants.NUMBER) {
        value = ParamUtil.getNumber(portletRequest, name);
    } else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getNumberValues(values);
    } else if (type == ExpandoColumnConstants.SHORT) {
        value = ParamUtil.getShort(portletRequest, name);
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getShortValues(values);
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        value = StringUtil.split(paramValue, delimiter);
    } else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
        value = (Serializable) LocalizationUtil.getLocalizationMap(portletRequest, name);
    } else {
        value = ParamUtil.getString(portletRequest, name);
    }

    return value;
}

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

License:Open Source License

private List<Integer> getIntegerList(String propertyValue) {

    List<Integer> result = new ArrayList<Integer>();
    int[] values = GetterUtil.getIntegerValues(propertyValue.split(","));
    for (int value : values) {
        result.add(value);//  w w  w .  ja  v a  2 s.  c om
    }
    return result;
}

From source file:com.liferay.portlet.expando.action.EditExpandoAction.java

License:Open Source License

protected Serializable getValue(PortletRequest portletRequest, String name, int type)
        throws PortalException, SystemException {

    String delimiter = StringPool.COMMA;

    Serializable value = null;//from ww w.  j a  v  a2s  . c  o m

    if (type == ExpandoColumnConstants.BOOLEAN) {
        value = ParamUtil.getBoolean(portletRequest, name);
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
    } else if (type == ExpandoColumnConstants.DATE) {
        User user = PortalUtil.getUser(portletRequest);

        int valueDateMonth = ParamUtil.getInteger(portletRequest, name + "Month");
        int valueDateDay = ParamUtil.getInteger(portletRequest, name + "Day");
        int valueDateYear = ParamUtil.getInteger(portletRequest, name + "Year");
        int valueDateHour = ParamUtil.getInteger(portletRequest, name + "Hour");
        int valueDateMinute = ParamUtil.getInteger(portletRequest, name + "Minute");
        int valueDateAmPm = ParamUtil.getInteger(portletRequest, name + "AmPm");

        if (valueDateAmPm == Calendar.PM) {
            valueDateHour += 12;
        }

        value = PortalUtil.getDate(valueDateMonth, valueDateDay, valueDateYear, valueDateHour, valueDateMinute,
                user.getTimeZone(), new ValueDataException());
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
    } else if (type == ExpandoColumnConstants.DOUBLE) {
        value = ParamUtil.getDouble(portletRequest, name);
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getDoubleValues(values);
    } else if (type == ExpandoColumnConstants.FLOAT) {
        value = ParamUtil.getFloat(portletRequest, name);
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getFloatValues(values);
    } else if (type == ExpandoColumnConstants.INTEGER) {
        value = ParamUtil.getInteger(portletRequest, name);
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getIntegerValues(values);
    } else if (type == ExpandoColumnConstants.LONG) {
        value = ParamUtil.getLong(portletRequest, name);
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getLongValues(values);
    } else if (type == ExpandoColumnConstants.SHORT) {
        value = ParamUtil.getShort(portletRequest, name);
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        String[] values = StringUtil.split(paramValue, delimiter);

        value = GetterUtil.getShortValues(values);
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
        String paramValue = ParamUtil.getString(portletRequest, name);

        if (paramValue.contains(StringPool.NEW_LINE)) {
            delimiter = StringPool.NEW_LINE;
        }

        value = StringUtil.split(paramValue, delimiter);
    } else {
        value = ParamUtil.getString(portletRequest, name);
    }

    return value;
}

From source file:com.liferay.portlet.expando.model.impl.ExpandoValueImpl.java

License:Open Source License

public int[] getIntegerArray() throws PortalException, SystemException {
    validate(ExpandoColumnConstants.INTEGER_ARRAY);

    return GetterUtil.getIntegerValues(StringUtil.split(getData()));
}