Search in sources :

Example 1 with StringParseException

use of com.centurylink.mdw.common.utilities.StringHelper.StringParseException in project mdw-designer by CenturyLinkCloud.

the class MappingEditor method serializeMapping.

/**
 * Converts a list of variable bindings to a string value to be stored with
 * the activity attribute.
 */
public String serializeMapping(List<VariableBinding> bindings) {
    if (getProject().checkRequiredVersion(6, 0, 4)) {
        if (bindings.isEmpty())
            return "";
        JSONObject json = new JSONObject();
        try {
            for (VariableBinding variableBinding : bindings) {
                json.put(variableBinding.getVariableVO().getVariableName(), variableBinding.getExpression());
            }
        } catch (JSONException ex) {
            throw new StringParseException(ex.getMessage(), ex);
        }
        return json.toString();
    } else {
        StringBuffer sb = new StringBuffer();
        boolean first = true;
        for (VariableBinding variableBinding : bindings) {
            if (first)
                first = false;
            else
                sb.append(getRowDelimiter());
            sb.append(variableBinding.getVariableVO().getVariableName());
            sb.append(getColumnDelimiter());
            sb.append(StringHelper.escapeWithBackslash(variableBinding.getExpression() == null ? "" : variableBinding.getExpression(), ";"));
        }
        return sb.toString();
    }
}
Also used : StringParseException(com.centurylink.mdw.common.utilities.StringHelper.StringParseException) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) VariableBinding(com.centurylink.mdw.plugin.designer.model.VariableBinding)

Aggregations

StringParseException (com.centurylink.mdw.common.utilities.StringHelper.StringParseException)1 VariableBinding (com.centurylink.mdw.plugin.designer.model.VariableBinding)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1