Example usage for org.apache.commons.lang3 StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang3 StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultIfEmpty.

Prototype

public static <T extends CharSequence> T defaultIfEmpty(final T str, final T defaultStr) 

Source Link

Document

Returns either the passed in CharSequence, or if the CharSequence is empty or null , the value of defaultStr .

 StringUtils.defaultIfEmpty(null, "NULL")  = "NULL" StringUtils.defaultIfEmpty("", "NULL")    = "NULL" StringUtils.defaultIfEmpty(" ", "NULL")   = " " StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null)      = null 

Usage

From source file:org.jbpm.formModeler.core.model.BasicTypeDataHolder.java

@Override
public Set<DataFieldHolder> getFieldHolders() {
    try {/*w w w .j a  v a  2  s .  co  m*/
        if (dataFieldHolders == null || dataFieldHolders.size() == 0) {
            dataFieldHolders = new TreeSet<DataFieldHolder>();
            DataFieldHolder datafieldHolder = new DataFieldHolder(this,
                    StringUtils.defaultIfEmpty(inputId, outputId), basicFieldType.getFieldClass());
            dataFieldHolders.add(datafieldHolder);

        }
        return dataFieldHolders;
    } catch (Exception e) {
    }
    return null;
}

From source file:org.jbpm.formModeler.core.processing.fieldHandlers.SubformFieldHandler.java

@Override
public Map getParamValue(Field field, String inputName, Object value) {
    if (value == null)
        return Collections.EMPTY_MAP;

    FormNamespaceData data = getNamespaceManager().getNamespace(inputName);
    Field parentField = data.getForm().getField(data.getFieldNameInParent());
    Form childForm = getEnterDataForm(inputName, parentField);

    Map result = new HashMap();
    DataHolder holder = childForm.getHolders().iterator().next();
    for (Iterator it = childForm.getFormFields().iterator(); it.hasNext();) {
        Field childField = (Field) it.next();
        String bindingExpression = StringUtils.defaultIfEmpty(childField.getInputBinding(),
                childField.getOutputBinding());
        if (!holder.isAssignableForField(childField))
            continue;
        try {//from w w w .  j  a  v a 2  s  .  c  om
            Object val = holder.readFromBindingExperssion(value, bindingExpression);
            FieldHandler fieldManager = getFieldHandlersManager().getHandler(childField.getFieldType());
            Map childrenMap = fieldManager.getParamValue(childField, childField.getFieldName(), val);
            if (childrenMap != null)
                result.putAll(childrenMap);
        } catch (Exception e) {
            log.warn("Error reading value from field '" + childField.getFieldName() + "': ", e);
        }
    }

    return result;
}

From source file:org.jbpm.formModeler.core.processing.formProcessing.FormProcessingContext.java

private FormProcessingContext(int type, Form form, String namespace, String formMode,
        List<String> fieldsToEvaluate) {
    this.type = type;
    this.form = form;

    this.namespace = StringUtils.defaultIfEmpty(namespace, FormProcessor.DEFAULT_NAMESPACE);
    this.formMode = StringUtils.defaultString(formMode);
    switch (type) {
    case TYPE_FORMULA:
        this.fieldsToEvaluateFormula = fieldsToEvaluate;
        break;/*from  w  ww . jav  a2 s . c o m*/
    case TYPE_RANGE:
        this.fieldsToEvaluateRange = fieldsToEvaluate;
        break;
    case TYPE_STYLE:
        this.fieldsToEvaluateStyle = fieldsToEvaluate;
        break;
    case TYPE_DEFAULT_FORMULA:
        this.fieldsToEvaluateDefaultFormula = fieldsToEvaluate;
        break;
    }
}

From source file:org.jbpm.formModeler.core.processing.formStatus.FormStatusManager.java

/**
 * Get form status associated with given form id and namespace
 *
 * @param form    form//  www . j av  a 2s.  c  om
 * @param namespace namespace
 * @return the form status associated with given form id and namespace
 */
public FormStatus getFormStatus(Form form, String namespace) {
    namespace = StringUtils.defaultIfEmpty(namespace, FormProcessor.DEFAULT_NAMESPACE);
    return (FormStatus) formStatuses.get(namespace + FormProcessor.NAMESPACE_SEPARATOR + form.getId());
}

From source file:org.jbpm.formModeler.core.processing.formStatus.FormStatusManager.java

/**
 * Create and store a new form status associated with given form id and namespace
 *
 * @param form    form//w  w w  .j a  v a2  s .c  o  m
 * @param namespace namespace
 * @return the form status associated with given form id and namespace
 */
public FormStatus createFormStatus(Form form, String namespace, Map<String, Object> currentValues) {
    namespace = StringUtils.defaultIfEmpty(namespace, FormProcessor.DEFAULT_NAMESPACE);
    FormStatus fs = new FormStatus(form, namespace, currentValues);
    formStatuses.put(namespace + FormProcessor.NAMESPACE_SEPARATOR + form.getId(), fs);
    return fs;
}

From source file:org.jbpm.formModeler.core.processing.formStatus.FormStatusManager.java

/**
 * Destroy form status associated with given form id and namespace
 *
 * @param formId    form/*w ww  . j av a2 s. co  m*/
 * @param namespace namespace
 */
public void destroyFormStatus(Long formId, String namespace) {
    namespace = StringUtils.defaultIfEmpty(namespace, FormProcessor.DEFAULT_NAMESPACE);
    // Delete this forms tatus and all nested form statuses
    String requestedPreffix = namespace + FormProcessor.NAMESPACE_SEPARATOR + formId;
    for (Iterator it = formStatuses.keySet().iterator(); it.hasNext();) {
        String key = (String) it.next();
        if (key.startsWith(requestedPreffix)) {
            it.remove();
        }
    }
}

From source file:org.jbpm.formModeler.core.processing.formStatus.FormStatusManager.java

/**
 * Clear wrong fields in given formStatus and all their subforms
 *
 * @param formId    form to clear//from   w w  w  . j  av  a2  s  .  co  m
 * @param namespace form starting namespace
 */
public void cascadeClearWrongFields(Long formId, String namespace) {
    namespace = StringUtils.defaultIfEmpty(namespace, FormProcessor.DEFAULT_NAMESPACE);
    // Delete this form status and all nested form statuses
    String requestedPreffix = namespace + FormProcessor.NAMESPACE_SEPARATOR + formId;
    for (Iterator it = formStatuses.keySet().iterator(); it.hasNext();) {
        String key = (String) it.next();
        if (key.startsWith(requestedPreffix)) {
            FormStatus formStatus = (FormStatus) formStatuses.get(key);
            formStatus.clearFormErrors();
        }
    }
}

From source file:org.jbpm.formModeler.core.processing.impl.FormProcessorImpl.java

public void setValues(Form form, String namespace, Map parameterMap, Map filesMap, boolean incremental) {
    if (form != null) {
        namespace = StringUtils.defaultIfEmpty(namespace, DEFAULT_NAMESPACE);
        FormStatus formStatus = getFormStatus(form, namespace);

        if (incremental) {
            Map mergedParameterMap = new HashMap();
            if (formStatus.getLastParameterMap() != null)
                mergedParameterMap.putAll(formStatus.getLastParameterMap());
            if (parameterMap != null)
                mergedParameterMap.putAll(parameterMap);
            formStatus.setLastParameterMap(mergedParameterMap);
        } else {/*  w w w  .j av a2s .  com*/
            formStatus.setLastParameterMap(parameterMap);
        }
        String inputsPrefix = getPrefix(form, namespace);

        for (Field field : form.getFormFields()) {
            setFieldValue(field, formStatus, inputsPrefix, parameterMap, filesMap, incremental);
        }
    }
}

From source file:org.jbpm.formModeler.core.processing.impl.FormProcessorImpl.java

public void persist(String ctxUid) throws Exception {
    ctxUid = StringUtils.defaultIfEmpty(ctxUid, FormProcessor.DEFAULT_NAMESPACE);
    persist(formRenderContextManager.getFormRenderContext(ctxUid));

}

From source file:org.jbpm.formModeler.core.processing.impl.FormProcessorImpl.java

public Map getMapRepresentationToPersist(Form form, String namespace) throws Exception {
    namespace = StringUtils.defaultIfEmpty(namespace, DEFAULT_NAMESPACE);
    Map m = new HashMap();
    FormStatus formStatus = getFormStatus(form, namespace);
    if (!formStatus.getWrongFields().isEmpty()) {
        throw new IllegalArgumentException("Validation error.");
    }//from w w w.  ja va2s .  co m

    fillObjectValues(m, formStatus.getInputValues(), form);

    Set s = (Set) m.get(MODIFIED_FIELD_NAMES);
    if (s == null) {
        m.put(MODIFIED_FIELD_NAMES, s = new TreeSet());
    }
    s.addAll(form.getFieldNames());
    return m;
}