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

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

Introduction

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

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

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

Usage

From source file:com.adobe.acs.commons.users.impl.AbstractAuthorizable.java

public AbstractAuthorizable(Map<String, Object> config) throws EnsureAuthorizableException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, getDefaultPath());
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(getDefaultPath(),
                StringUtils.removeEnd(tmp, this.principalName));
    } else {/*from w ww. ja v a  2  s  .c  o  m*/
        this.principalName = tmp;
        this.intermediatePath = getDefaultPath();
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureAuthorizableException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedAuthorizables.isProtected(this.principalName)) {
        throw new EnsureAuthorizableException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        if (StringUtils.isNotBlank(entry)) {
            try {
                aces.add(new Ace(entry));
            } catch (EnsureAuthorizableException e) {
                log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                        + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
            }
        }
    }
}

From source file:com.adaptris.util.text.mime.InputStreamDataSource.java

private String get(String headerName) {
    String result = null;/*from   w  ww  .  jav  a2  s  .c o m*/
    try {
        String[] s = Args.notNull(headers.getHeader(headerName), headerName);
        result = s[0];
    } catch (IllegalArgumentException e) {

    }
    return StringUtils.defaultIfEmpty(result, "");
}

From source file:com.manydesigns.portofino.actions.admin.database.forms.ConnectionProviderForm.java

public void setFalseString(String falseString) {
    database.setFalseString(StringUtils.defaultIfEmpty(falseString, null));
}

From source file:com.big.data.plan.KafkaSink.java

/**
 * Process status.// w  ww  .j a v  a  2  s .co  m
 * 
 * @return the status
 * @throws EventDeliveryException
 *             the event delivery exception
 */
@Override
public Status process() throws EventDeliveryException {
    Status status = null;

    // Start transaction
    Channel ch = getChannel();
    Transaction txn = ch.getTransaction();
    txn.begin();
    try {
        // This try clause includes whatever Channel operations you want to do
        Event event = ch.take();

        String partitionKey = (String) parameters.get(KafkaFlumeConstans.PARTITION_KEY_NAME);
        String encoding = StringUtils.defaultIfEmpty(
                (String) this.parameters.get(KafkaFlumeConstans.ENCODING_KEY_NAME),
                KafkaFlumeConstans.DEFAULT_ENCODING);
        String topic = Preconditions.checkNotNull(
                (String) this.parameters.get(KafkaFlumeConstans.CUSTOME_TOPIC_KEY_NAME),
                "custom.topic.name is required");

        String eventData = new String(event.getBody(), encoding);

        KeyedMessage<String, String> data;

        // if partition key does'nt exist
        if (StringUtils.isEmpty(partitionKey)) {
            data = new KeyedMessage<String, String>(topic, eventData);
        } else {
            data = new KeyedMessage<String, String>(topic, partitionKey, eventData);
        }

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                    "Send Message to Kafka : [" + eventData + "] -- [" + EventHelper.dumpEvent(event) + "]");
        }

        producer.send(data);
        txn.commit();
        status = Status.READY;
    } catch (Throwable t) {
        txn.rollback();
        status = Status.BACKOFF;

        // re-throw all Errors
        if (t instanceof Error) {
            throw (Error) t;
        }
    } finally {
        txn.close();
    }
    return status;
}

From source file:ch.admin.suis.msghandler.sedex.SedexAdapterConfiguration.java

@Override
public String toString() {
    return MessageFormat.format(
            "\n\tparticipantId: {0};" + "\n\tinbox folder: {1};" + "\n\toutbox folder: {2};"
                    + "\n\treceipt folder: {3};" + "\n\tsent folder: {4};",
            StringUtils.defaultIfEmpty(participantId, ClientCommons.NOT_SPECIFIED),
            StringUtils.defaultIfEmpty(inputDir, ClientCommons.NOT_SPECIFIED),
            StringUtils.defaultIfEmpty(outputDir, ClientCommons.NOT_SPECIFIED),
            StringUtils.defaultIfEmpty(receiptDir, ClientCommons.NOT_SPECIFIED),
            StringUtils.defaultIfEmpty(sentDir, ClientCommons.NOT_SPECIFIED));
}

From source file:com.gst.portfolio.client.domain.ClientIdentifier.java

private ClientIdentifier(final Client client, final CodeValue documentType, final String documentKey,
        final String statusName, String description) {
    this.client = client;
    this.documentType = documentType;
    this.documentKey = StringUtils.defaultIfEmpty(documentKey, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
    ClientIdentifierStatus statusEnum = ClientIdentifierStatus.valueOf(statusName.toUpperCase());
    this.active = null;
    if (statusEnum.isActive()) {
        this.active = statusEnum.getValue();
    }//w  w w  .  jav a  2  s . c  o  m
    this.status = statusEnum.getValue();
}

From source file:com.hand.hap.mybatis.util.OGNL.java

/**
 * FOR INTERNAL USE ONLY//from   w  w w.ja  v a 2s  . c  o  m
 * 
 * @param parameter
 * @return
 */
public static String getOrderByClause(Object parameter) {
    if (parameter == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder(64);
    if (parameter instanceof BaseDTO) {
        String sortName = ((BaseDTO) parameter).getSortname();
        Field[] ids = DTOClassInfo.getIdFields(parameter.getClass());
        if (StringUtil.isNotEmpty(sortName)) {
            if (!COL_PATTERN.matcher(sortName).matches()) {
                throw new RuntimeException("Invalid sortname:" + sortName);
            }
            String order = ((BaseDTO) parameter).getSortorder();
            if (!("ASC".equalsIgnoreCase(order) || "DESC".equalsIgnoreCase(order) || order == null)) {
                throw new RuntimeException("Invalid sortorder:" + order);
            }
            String columnName = unCamel(sortName);

            sb.append(columnName).append(" ");
            sb.append(StringUtils.defaultIfEmpty(order, "ASC"));

            if (ids.length > 0 && !ids[0].getName().equals(sortName)) {
                sb.append(",").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC");
            }
        } else {
            if (ids.length > 0) {
                sb.append(DTOClassInfo.getColumnName(ids[0])).append(" ASC");
            }
        }
    }
    return StringUtils.trimToNull(sb.toString());
}

From source file:io.jenkins.blueocean.blueocean_git_pipeline.GitReadSaveService.java

static GitReadSaveRequest makeSaveRequest(Item item, String branch, String commitMessage, String sourceBranch,
        String filePath, byte[] contents) {
    String defaultBranch = "master";
    GitSCMSource gitSource = null;//from   w ww .j  a v a 2 s.  com
    if (item instanceof MultiBranchProject<?, ?>) {
        MultiBranchProject<?, ?> mbp = (MultiBranchProject<?, ?>) item;
        for (SCMSource s : mbp.getSCMSources()) {
            if (s instanceof GitSCMSource) {
                gitSource = (GitSCMSource) s;
            }
        }
    }

    switch (TYPE) {
    case CLONE:
        return new GitCloneReadSaveRequest(gitSource, StringUtils.defaultIfEmpty(branch, defaultBranch),
                commitMessage, StringUtils.defaultIfEmpty(sourceBranch, defaultBranch), filePath, contents);
    case CACHE_CLONE:
        return new GitCacheCloneReadSaveRequest(gitSource, StringUtils.defaultIfEmpty(branch, defaultBranch),
                commitMessage, StringUtils.defaultIfEmpty(sourceBranch, defaultBranch), filePath, contents);
    default:
        return new GitBareRepoReadSaveRequest(gitSource, StringUtils.defaultIfEmpty(branch, defaultBranch),
                commitMessage, StringUtils.defaultIfEmpty(sourceBranch, defaultBranch), filePath, contents);
    }
}

From source file:com.flexive.faces.FxJsfComponentUtils.java

/**
 * Evaluate the string attribute of a component.
 *
 * @param component     a JSF component/*  w  ww  . ja v a2s  . c  o  m*/
 * @param attributeName the attribute name to be evaluated, e.g. "title"
 * @param defaultValue  the default value to be used if no value is bound
 * @return the bound value, or null if no value is bound
 */
public static String getStringValue(UIComponent component, String attributeName, String defaultValue) {
    return StringUtils.defaultIfEmpty((String) getValue(component, attributeName), defaultValue);
}

From source file:com.gst.organisation.teller.domain.Teller.java

private Teller(final Office staffOffice, final String name, final String description, final LocalDate startDate,
        final LocalDate endDate, final TellerStatus status) {

    this.name = StringUtils.defaultIfEmpty(name, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
    if (startDate != null) {
        this.startDate = startDate.toDateTimeAtStartOfDay().toDate();
    }/*  www  . j a v a  2  s .c om*/
    if (endDate != null) {
        this.endDate = endDate.toDateTimeAtStartOfDay().toDate();
    }
    if (status != null) {
        this.status = status.getValue();
    }
    this.office = staffOffice;

    /*
     if (StringUtils.isNotBlank(name)) {
    this.name = name.trim();
     } else {
    this.name = null;
     }
             
     if (StringUtils.isNotBlank(description)) {
    this.description = description.trim();
     } else {
    this.description = null;
     } */

}