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

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

Introduction

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

Prototype

public static boolean isEmpty(final CharSequence cs) 

Source Link

Document

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

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

NOTE: This method changed in Lang version 2.0.

Usage

From source file:de.micromata.genome.gdbfs.FileNameUtils.java

public static String normalize(String name) {
    if (StringUtils.isEmpty(name) == true) {
        return name;
    }/*ww w .  j av  a  2 s .  com*/
    name = StringUtils.replace(name, "\\", "/");
    name = StringUtils.replace(name, "//", "/");
    return name;
}

From source file:com.company.vertxstarter.api.util.SortExpression.java

private static Order parseOrder(String op) {
    if (StringUtils.isEmpty(op)) {
        return Order.ASC;
    } else if (op.equals("-")) {
        return Order.DESC;
    }/*from ww w. j ava 2 s .  c  o  m*/
    return Order.NONE;
}

From source file:com.gs.obevo.db.impl.platforms.mssql.MsSqlParamReader.java

public static ParamReader getParamReader() {
    String dbCredsFile = System.getProperty("dbCredsFile");
    if (StringUtils.isEmpty(dbCredsFile)) {
        dbCredsFile = "mssql-creds.properties";
    }/*from www. java  2 s.  c  o m*/

    return new ParamReader(ConfigFactory.parseResources(dbCredsFile), "mssql", ConfigFactory.parseMap(
            Maps.mutable.<String, Object>of("sysattrs.type", "MSSQL", "logicalSchemas.schema1", "oats")));
}

From source file:com.gs.obevo.db.impl.platforms.postgresql.PostgreSqlParamReader.java

public static ParamReader getParamReader() {
    String dbCredsFile = System.getProperty("dbCredsFile");
    if (StringUtils.isEmpty(dbCredsFile)) {
        dbCredsFile = "postgresql-creds.properties";
    }/*www.j ava  2 s  .co m*/

    return new ParamReader(ConfigFactory.parseResources(dbCredsFile), "postgresql",
            ConfigFactory.parseMap(Maps.mutable.<String, Object>of("sysattrs.type", "POSTGRESQL",
                    "logicalSchemas.schema1", "schema1", "logicalSchemas.schema2", "schema2")));
}

From source file:com.newtranx.util.reverse_proxy.NginxUtils.java

public static final Optional<String> getRealIp(Function<String, String> headerLoader) {
    String realIp = headerLoader.apply("X-Real-IP");
    String xForwardedFor = headerLoader.apply("X-Forwarded-For");
    if (!StringUtils.isEmpty(xForwardedFor)) {
        int i = xForwardedFor.indexOf(',');
        if (i > 0)
            realIp = xForwardedFor.substring(0, i);
        else//from w w  w. ja v a 2s .com
            realIp = xForwardedFor.trim();
    }
    return StringUtils.isEmpty(realIp) ? Optional.empty() : Optional.of(realIp);
}

From source file:com.baifendian.swordfish.execserver.utils.LoggerUtil.java

/**
 * ? jobId // www  .  j a  v  a  2s  .  c  o m
 *
 * @param prefix
 * @param execId
 * @param nodeName
 * @return
 */
public static String genJobId(String prefix, long execId, String nodeName) {
    if (StringUtils.isEmpty(nodeName)) {
        return String.format("%s_%s", prefix, execId);
    }

    String postfix = HttpUtil.getMd5(nodeName).substring(0, 8);

    return String.format("%s_%s_%s", prefix, execId, postfix);
}

From source file:cn.guoyukun.spring.web.utils.DownloadUtils.java

public static void download(HttpServletRequest request, HttpServletResponse response, String filePath,
        String displayName) throws IOException {
    File file = new File(filePath);

    if (StringUtils.isEmpty(displayName)) {
        displayName = file.getName();/* ww w .  j  a v a 2s.c  o  m*/
    }

    if (!file.exists() || !file.canRead()) {
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("??");
        return;
    }

    String userAgent = request.getHeader("User-Agent");
    boolean isIE = (userAgent != null) && (userAgent.toLowerCase().indexOf("msie") != -1);

    response.reset();
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "must-revalidate, no-transform");
    response.setDateHeader("Expires", 0L);

    response.setContentType("application/x-download");
    response.setContentLength((int) file.length());

    String displayFilename = displayName.substring(displayName.lastIndexOf("_") + 1);
    displayFilename = displayFilename.replace(" ", "_");
    if (isIE) {
        displayFilename = URLEncoder.encode(displayFilename, "UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=\"" + displayFilename + "\"");
    } else {
        displayFilename = new String(displayFilename.getBytes("UTF-8"), "ISO8859-1");
        response.setHeader("Content-Disposition", "attachment;filename=" + displayFilename);
    }
    BufferedInputStream is = null;
    OutputStream os = null;
    try {

        os = response.getOutputStream();
        is = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(is, os);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:ch.cyberduck.core.BookmarkNameProvider.java

public static String toString(final Host bookmark, final boolean username) {
    if (StringUtils.isEmpty(bookmark.getNickname())) {
        final String prefix;
        // Return default bookmark name
        if (username && !bookmark.getCredentials().isAnonymousLogin()
                && StringUtils.isNotBlank(bookmark.getCredentials().getUsername())) {
            prefix = String.format("%s@", bookmark.getCredentials().getUsername());
        } else {//from   ww w. j a va2 s. com
            prefix = StringUtils.EMPTY;
        }
        if (StringUtils.isNotBlank(bookmark.getHostname())) {
            return String.format("%s%s \u2013 %s", prefix, StringUtils.strip(bookmark.getHostname()),
                    bookmark.getProtocol().getName());
        }
        if (StringUtils.isNotBlank(bookmark.getProtocol().getDefaultHostname())) {
            return String.format("%s%s \u2013 %s", prefix,
                    StringUtils.strip(bookmark.getProtocol().getDefaultHostname()),
                    bookmark.getProtocol().getName());
        }
        return String.format("%s%s", prefix, bookmark.getProtocol().getName());
    }
    // Return custom bookmark name set
    return bookmark.getNickname();
}

From source file:com.webbfontaine.valuewebb.model.converters.ToAsciiStringConverter.java

private static String convertToAscii(String mixedString) {

    if (StringUtils.isEmpty(UNICODE_TO_ASCII_CONF)) {
        return mixedString;
    }/*  w w w .jav a 2s .co  m*/

    String[] unicodeToAsciiPairs = UNICODE_TO_ASCII_CONF.split(",");

    for (String unicodeToAsciiPair : unicodeToAsciiPairs) {
        String[] mapping = unicodeToAsciiPair.split(":");
        String unicodeSymbol = mapping[0];
        String asciiSymbol = mapping[1];
        mixedString = mixedString.replaceAll(unicodeSymbol, asciiSymbol);
    }
    return mixedString;
}

From source file:com.thoughtworks.go.domain.IpAddress.java

public static IpAddress create(String address) {
    try {// w  ww.j  a  va  2s .c om
        if (StringUtils.isEmpty(address)) {
            return new NullIpAddress();
        }
        return new IpAddress(InetAddress.getByName(address));
    } catch (UnknownHostException e) {
        throw new RuntimeException("IpAddress '" + address + "' is not a valid IP address");
    }
}