Example usage for com.liferay.portal.kernel.json JSONArray get

List of usage examples for com.liferay.portal.kernel.json JSONArray get

Introduction

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

Prototype

public Object get(int index);

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.form.evaluator.internal.functions.JoinFunction.java

License:Open Source License

@Override
public Object evaluate(Object... parameters) {
    if (parameters.length != 2) {
        throw new IllegalArgumentException("Two parameters are expected");
    }/*from w ww.ja  v  a 2 s . c  o m*/

    if (!(parameters[0] instanceof JSONArray)) {
        throw new IllegalArgumentException("JSONArray is expected");
    }

    JSONArray jsonArray = (JSONArray) parameters[0];

    StringBundler sb = new StringBundler(jsonArray.length() * 2 - 1);

    for (int i = 0; i < jsonArray.length(); i++) {
        sb.append(GetterUtil.getString(jsonArray.get(i)));

        if (i < (jsonArray.length() - 1)) {
            sb.append(CharPool.COMMA);
        }
    }

    return sb.toString();
}

From source file:com.liferay.dynamic.data.mapping.type.checkbox.multiple.internal.CheckboxMultipleDDMFormFieldTemplateContextContributor.java

License:Open Source License

protected List<String> getValue(String valueString) {
    JSONArray jsonArray = null;

    try {//from w  w w . j a  v  a  2 s .com
        jsonArray = jsonFactory.createJSONArray(valueString);
    } catch (JSONException jsone) {
        if (_log.isDebugEnabled()) {
            _log.debug(jsone, jsone);
        }

        jsonArray = jsonFactory.createJSONArray();
    }

    List<String> values = new ArrayList<>(jsonArray.length());

    for (int i = 0; i < jsonArray.length(); i++) {
        values.add(String.valueOf(jsonArray.get(i)));
    }

    return values;
}

From source file:com.liferay.dynamic.data.mapping.type.checkbox.multiple.internal.CheckboxMultipleDDMFormFieldValueAccessor.java

License:Open Source License

@Override
public Object map(Object value) {
    if (Validator.isNull(value)) {
        return value;
    }/*from  w  ww .  j  a v  a2s  .  c  o m*/

    try {
        JSONArray jsonArray = jsonFactory.createJSONArray(value.toString());

        StringBundler sb = new StringBundler(jsonArray.length() * 2 - 1);

        for (int i = 0; i < jsonArray.length(); i++) {
            sb.append(jsonArray.get(i));

            if (i < (jsonArray.length() - 1)) {
                sb.append(CharPool.COMMA);
            }
        }

        return sb.toString();
    } catch (JSONException jsone) {
        if (_log.isDebugEnabled()) {
            _log.debug("Unable to parse JSON array", jsone);
        }

        return StringPool.BLANK;
    }
}

From source file:com.liferay.dynamic.data.mapping.type.select.internal.SelectDDMFormFieldValueAccessor.java

License:Open Source License

@Override
public Object map(Object value) {
    if (Validator.isNull(value)) {
        return value;
    }/*from w ww .  j a  va  2 s  .c om*/

    try {
        JSONArray jsonArray = jsonFactory.createJSONArray(value.toString());

        StringBundler sb = new StringBundler(jsonArray.length() * 2 - 1);

        for (int i = 0; i < jsonArray.length(); i++) {
            sb.append(jsonArray.get(i));

            if (i < (jsonArray.length() - 1)) {
                sb.append(CharPool.COMMA);
            }
        }

        return sb.toString();
    } catch (JSONException jsone) {
        _log.error("Unable to parse JSON array", jsone);

        return StringPool.BLANK;
    }
}