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

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

Introduction

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

Prototype

public static boolean isBlank(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is whitespace, empty ("") or null.

 StringUtils.isBlank(null)      = true StringUtils.isBlank("")        = true StringUtils.isBlank(" ")       = true StringUtils.isBlank("bob")     = false StringUtils.isBlank("  bob  ") = false 

Usage

From source file:com.phone.cn.entity.search.filter.Condition.java

/**
 * ?key?Condition//from  w  w w. j  av  a 2 s. co  m
 *
 * @param key    name_like
 * @param value
 * @return
 */
@SuppressWarnings("rawtypes")
static Condition newCondition(final String key, final Object value) throws SearchException {

    Assert.notNull(key, "Condition key must not null");

    String[] searchs = StringUtils.split(key, separator);

    if (searchs.length == 0) {
        throw new SearchException("Condition key format must be : property or property_op");
    }

    String searchProperty = searchs[0];

    SearchOperator operator = null;
    if (searchs.length == 1) {
        operator = SearchOperator.custom;
    } else {
        try {
            operator = SearchOperator.valueOf(searchs[1]);
        } catch (IllegalArgumentException e) {
            throw new InvlidSearchOperatorException(searchProperty, searchs[1]);
        }
    }

    boolean allowBlankValue = SearchOperator.isAllowBlankValue(operator);
    boolean isValueBlank = (value == null);
    isValueBlank = isValueBlank || (value instanceof String && StringUtils.isBlank((String) value));
    isValueBlank = isValueBlank || (value instanceof List && ((List) value).size() == 0);
    //???
    if (!allowBlankValue && isValueBlank) {
        return null;
    }

    Condition searchFilter = newCondition(searchProperty, operator, value);

    return searchFilter;
}

From source file:br.msf.maven.utils.IOUtils.java

public static Charset getCharset(final String charsetName) {
    if (StringUtils.isBlank(charsetName)) {
        LOGGER.log(Level.WARNING, "Charset name is blank. Assuming default charset!");
        return Charset.defaultCharset();
    }/* w  w  w .  j av  a 2s  .  c o  m*/
    return Charset.forName(charsetName);
}

From source file:com.axibase.tsd.plain.MessageInsertCommand.java

public MessageInsertCommand(String entityName, Long timeMillis, Map<String, String> tags, String messageText) {
    super(MESSAGE_COMMAND, entityName, timeMillis, tags);
    this.messageText = messageText;
    if ((tags == null || tags.isEmpty()) && StringUtils.isBlank(messageText)) {
        throw new IllegalArgumentException("Either message text or one of the tags is required");
    }//from  w ww  .jav  a2 s.c om
}

From source file:de.micromata.genome.util.matcher.string.StringBlankMatcher.java

@Override
public boolean matchString(String token) {
    return StringUtils.isBlank(token);
}

From source file:com.beginner.core.utils.HttpUtil.java

/**
 * <p>To request the POST way.</p>
 * //from  w w w.  j  a  va  2 s  . c  o m
 * @param url      request URI
 * @param json      request parameter(json format string)
 * @param timeout   request timeout time in milliseconds(The default timeout time for 30 seconds.)
 * @return String   response result
 * @throws Exception
 * @since 1.0.0
 */
public static String post(String url, String json, Integer timeout) throws Exception {

    // Validates input
    if (StringUtils.isBlank(url))
        throw new IllegalArgumentException("The url cannot be null and cannot be empty.");

    //The default timeout time for 30 seconds
    if (null == timeout)
        timeout = 30000;

    String result = null;
    CloseableHttpClient httpClient = null;
    CloseableHttpResponse httpResponse = null;

    try {
        httpClient = HttpClients.createDefault();
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout)
                .setConnectTimeout(timeout).build();

        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(requestConfig);
        httpPost.setHeader("Content-Type", "text/plain");
        httpPost.setEntity(new StringEntity(json, "UTF-8"));

        httpResponse = httpClient.execute(httpPost);

        HttpEntity entity = httpResponse.getEntity();

        result = EntityUtils.toString(entity);

        EntityUtils.consume(entity);
    } catch (Exception e) {
        logger.error("POST?", e);
        return null;
    } finally {
        if (null != httpResponse)
            httpResponse.close();
        if (null != httpClient)
            httpClient.close();
    }
    return result;
}

From source file:com.vmware.photon.controller.api.frontend.exceptions.external.NoIsoAttachedException.java

@Override
public String getMessage() {
    if (!StringUtils.isBlank(id)) {
        return String.format("No ISO attached to the vm %s", id);
    }//  ww  w.java  2  s. c o m
    return "No ISO attached to the vm";
}

From source file:com.mengge.MobileBy.java

protected MobileBy(String locatorString) {
    if (StringUtils.isBlank(locatorString)) {
        throw new IllegalArgumentException("Must supply a not empty locator value.");
    }/* w w  w  .j  a  v a 2  s.  c o  m*/
    this.locatorString = locatorString;
}

From source file:net.gvmtool.api.Uninstall.java

public void version(String version) {
    if (StringUtils.isBlank(version)) {
        throw new IllegalArgumentException("No valid candidate version was provided.");
    }/*from w w  w.ja v a  2  s  . c  o m*/

    Path candidateDir = candidates.get(context, candidateName);
    if (context.candidateHasCurrentVersion(candidateDir)) {
        try {
            Files.delete(context.candidateCurrentVersion(candidateDir));
        } catch (IOException e) {
            throw new RuntimeException("Error removing existing current symlink for candidate " + candidateName,
                    e);
        }
    }

    if (context.candidateVersionInstalled(candidateDir, version)
            && context.candidateVersionIsDir(candidateDir, version)) {
        try {
            Files.delete(context.candidateVersionDir(candidateDir, version));
        } catch (IOException e) {
            throw new RuntimeException("Error removing " + candidateName + " " + version, e);
        }
    }
}

From source file:com.yuanbao.crm.common.entity.search.filter.Condition.java

/**
 * ?key?Condition/*  ww  w.java  2 s  . com*/
 *
 * @param key    name_like
 * @param value
 * @return
 */
static Condition newCondition(final String key, final Object value) throws SearchException {

    Assert.notNull(key, "Condition key must not null");

    String[] searchs = StringUtils.split(key, separator);

    if (searchs.length == 0) {
        throw new SearchException("Condition key format must be : property or property_op");
    }

    String searchProperty = searchs[0];

    SearchOperator operator = null;
    if (searchs.length == 1) {
        operator = SearchOperator.custom;
    } else {
        try {
            operator = SearchOperator.valueOf(searchs[1]);
        } catch (IllegalArgumentException e) {
            throw new InvalidSearchOperatorException(searchProperty, searchs[1]);
        }
    }

    boolean allowBlankValue = SearchOperator.isAllowBlankValue(operator);
    boolean isValueBlank = (value == null);
    isValueBlank = isValueBlank || (value instanceof String && StringUtils.isBlank((String) value));
    isValueBlank = isValueBlank || (value instanceof List && ((List) value).size() == 0);
    //???
    if (!allowBlankValue && isValueBlank) {
        return null;
    }

    Condition searchFilter = newCondition(searchProperty, operator, value);

    return searchFilter;
}

From source file:ch.cyberduck.core.aquaticprime.AbstractLicense.java

@Override
public String getName() {
    String to = this.getValue("Name");
    if (StringUtils.isBlank(to)) {
        to = this.getValue("Email"); // primary key
    }//from   ww  w  . j  ava2s  .  c o m
    return to;
}