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

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

Introduction

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

Prototype

public static boolean isBlank(String str) 

Source Link

Document

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

Usage

From source file:com.intuit.tank.standalone.agent.StandaloneAgentStartup.java

public static void main(String[] args) {
    StandaloneAgentStartup agentStartup = new StandaloneAgentStartup();

    for (int iter = 0; iter < args.length; ++iter) {
        String argument = args[iter];
        String[] values = argument.split("=");

        if (values[0].equalsIgnoreCase("-controller")) {
            if (values.length < 2) {
                usage();/*from  w ww .j a v a 2  s . co m*/
                return;
            }
            agentStartup.controllerBase = values[1];
            continue;
        } else if (values[0].equalsIgnoreCase("-host")) {
            if (values.length < 2) {
                usage();
                return;
            }
            agentStartup.hostname = values[1];
            continue;
        } else if (values[0].equalsIgnoreCase("-capacity")) {
            if (values.length < 2) {
                usage();
                return;
            }
            try {
                agentStartup.capacity = Integer.parseInt(values[1]);
            } catch (NumberFormatException e) {
                LOG.error("Error parsing capacity " + values[1] + " Capacity must be an integer.");
                System.out.println("Error parsing capacity " + values[1] + " Capacity must be an integer.");
                usage();
                return;
            }
            continue;
        }

    }
    if (StringUtils.isBlank(agentStartup.controllerBase)) {
        usage();
        System.exit(1);
    }
    agentStartup.run();
}

From source file:com.cws.esolutions.core.main.NetworkUtility.java

public static final void main(final String[] args) {
    final String methodName = NetworkUtility.CNAME + "#main(final String[] args)";

    if (DEBUG) {//from w  w w. j ava 2 s.  c  om
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", (Object) args);
    }

    if (args.length == 0) {
        new HelpFormatter().printHelp(NetworkUtility.CNAME, options, true);

        return;
    }

    try {
        CommandLineParser parser = new PosixParser();
        CommandLine commandLine = parser.parse(options, args);

        if (DEBUG) {
            DEBUGGER.debug("CommandLineParser parser: {}", parser);
            DEBUGGER.debug("CommandLine commandLine: {}", commandLine);
        }

        String coreConfiguration = (StringUtils.isBlank(System.getProperty("coreConfigFile")))
                ? NetworkUtility.CORE_SVC_CONFIG
                : System.getProperty("coreConfigFile");
        String securityConfiguration = (StringUtils.isBlank(System.getProperty("secConfigFile")))
                ? NetworkUtility.CORE_LOG_CONFIG
                : System.getProperty("secConfigFile");
        String coreLogging = (StringUtils.isBlank(System.getProperty("coreLogConfig")))
                ? NetworkUtility.SEC_SVC_CONFIG
                : System.getProperty("coreLogConfig");
        String securityLogging = (StringUtils.isBlank(System.getProperty("secLogConfig")))
                ? NetworkUtility.SEC_LOG_CONFIG
                : System.getProperty("secLogConfig");

        if (DEBUG) {
            DEBUGGER.debug("String coreConfiguration: {}", coreConfiguration);
            DEBUGGER.debug("String securityConfiguration: {}", securityConfiguration);
            DEBUGGER.debug("String coreLogging: {}", coreLogging);
            DEBUGGER.debug("String securityLogging: {}", securityLogging);
        }

        SecurityServiceInitializer.initializeService(securityConfiguration, securityLogging, false);
        CoreServiceInitializer.initializeService(coreConfiguration, coreLogging, false, true);

        final CoreConfigurationData coreConfigData = NetworkUtility.appBean.getConfigData();
        final SecurityConfigurationData secConfigData = NetworkUtility.secBean.getConfigData();

        if (DEBUG) {
            DEBUGGER.debug("CoreConfigurationData coreConfigData: {}", coreConfigData);
            DEBUGGER.debug("SecurityConfigurationData secConfig: {}", secConfigData);
        }

        if (commandLine.hasOption("ssh")) {
            if (!(commandLine.hasOption("hostname"))
                    || (!(StringUtils.isBlank(commandLine.getOptionValue("hostname"))))) {
                throw new CoreServiceException("No target host was provided. Unable to process request.");
            } else if (!(commandLine.hasOption("username"))
                    && (StringUtils.isBlank(commandLine.getOptionValue("username")))) {
                throw new CoreServiceException("No username was provided. Using default.");
            }

            // NetworkUtils.executeSshConnection(commandLine.getOptionValue("hostname"), commandList);
        } else if (commandLine.hasOption("http")) {
            if (!(commandLine.hasOption("hostname"))
                    || (!(StringUtils.isBlank(commandLine.getOptionValue("hostname"))))) {
                throw new CoreServiceException("No target host was provided. Unable to process request.");
            } else if (!(commandLine.hasOption("method"))
                    && (StringUtils.isBlank(commandLine.getOptionValue("method")))) {
                throw new CoreServiceException("No HTTP method was provided. Unable to process request.");
            }

            NetworkUtils.executeHttpConnection(new URL(commandLine.getOptionValue("hostname")),
                    commandLine.getOptionValue("method"));
        } else if (commandLine.hasOption("copyFiles")) {
            if (!(commandLine.hasOption("hostname"))
                    || (StringUtils.isBlank(commandLine.getOptionValue("hostname")))) {
                throw new CoreServiceException("No target host was provided. Unable to process request.");
            } else if (!(commandLine.hasOption("sourceFile"))
                    && (StringUtils.isBlank(commandLine.getOptionValue("sourceFile")))) {
                throw new CoreServiceException("No source file(s) were provided. Unable to process request.");
            } else if (!(commandLine.hasOption("targetFile"))
                    && (StringUtils.isBlank(commandLine.getOptionValue("targetFile")))) {
                throw new CoreServiceException("No target file(s) were provided. Unable to process request.");
            }

            List<String> filesToTransfer = new ArrayList<String>(
                    Arrays.asList(commandLine.getOptionValues("sourceFile")));
            List<String> filesToCreate = new ArrayList<String>(
                    Arrays.asList(commandLine.getOptionValues("targetFile")));

            if (DEBUG) {
                DEBUGGER.debug("List<String> filesToTransfer: {}", filesToTransfer);
                DEBUGGER.debug("List<String> filesToCreate: {}", filesToCreate);
            }

            if (commandLine.hasOption("withSSH")) {
                for (String fileName : filesToTransfer) {
                    if (DEBUG) {
                        DEBUGGER.debug("String fileName: {}", fileName);
                    }

                    NetworkUtils.executeSftpTransfer(fileName,
                            filesToCreate.get(filesToTransfer.indexOf(fileName)),
                            commandLine.getOptionValue("hostname"), FileUtils.getFile(fileName).exists());
                }
            }

            else if (commandLine.hasOption("withFTP")) {
                if ((commandLine.hasOption("withSSL"))
                        && (Boolean.valueOf(commandLine.getOptionValue("withSSL")))) {
                    // ftp/s
                }

                // NetworkUtils.executeFtpConnection(sourceFile, targetFile, targetHost, isUpload);
            }
        }
    } catch (ParseException px) {
        ERROR_RECORDER.error(px.getMessage(), px);

        System.err.println("An error occurred during processing: " + px.getMessage());
    } catch (SecurityException sx) {
        ERROR_RECORDER.error(sx.getMessage(), sx);

        System.err.println("An error occurred during processing: " + sx.getMessage());
    } catch (SecurityServiceException ssx) {
        ERROR_RECORDER.error(ssx.getMessage(), ssx);

        System.err.println("An error occurred during processing: " + ssx.getMessage());
    } catch (CoreServiceException csx) {
        ERROR_RECORDER.error(csx.getMessage(), csx);

        System.err.println("An error occurred during processing: " + csx.getMessage());
    } catch (MalformedURLException mux) {
        ERROR_RECORDER.error(mux.getMessage(), mux);

        System.err.println("An error occurred during processing: " + mux.getMessage());
    }
}

From source file:com.enonic.cms.core.search.IndexValueNormalizer.java

public static String normalizeStringValue(final String stringValue) {
    if (StringUtils.isBlank(stringValue)) {
        return "";
    }//from   w w w . ja va 2  s .  co m

    return stringValue.toLowerCase();
}

From source file:com.enonic.cms.core.search.IndexFieldnameNormalizer.java

public static String normalizeFieldName(final String stringValue) {
    if (StringUtils.isBlank(stringValue)) {
        return "";
    }/*from  www.jav  a 2s.  c om*/

    String normalized = replaceSeparators(stringValue);
    normalized = replaceFieldTypeSeparators(normalized);
    normalized = removeAttributeSeparator(normalized);

    return normalized.toLowerCase();
}

From source file:com.yyl.common.utils.excel.FileTools.java

/**
 * ??//  www.  j a v a  2s  .c  o m
 * @return 
 */
public static String getSuffix(String fileName) {
    if (StringUtils.isBlank(fileName)) {
        return "";
    } else if (fileName.contains(".")) {
        return fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
    }
    return "";
}

From source file:com.att.pirates.util.DBUtility.java

public static Connection getDBConnection() throws SQLException, Exception {
    Connection conn = null;// w w w .j ava2 s. c  om
    PropertyReader reader = new PropertyReader();
    String forName = reader.readPropertyByName(PiratesConstants.CLASSFORNAME);
    if (StringUtils.isBlank(forName) || StringUtils.isEmpty(forName)) {
        throw new Exception("forName is empty from property file");
    }

    String serverName = reader.readPropertyByName(PiratesConstants.SERVERNAME);
    String databaseName = reader.readPropertyByName(PiratesConstants.DATABASENAME);
    String user = reader.readPropertyByName(PiratesConstants.USER);
    String password = reader.readPropertyByName(PiratesConstants.PASSWORD);

    if (StringUtils.isBlank(serverName) || StringUtils.isEmpty(databaseName) || StringUtils.isBlank(user)
            || StringUtils.isEmpty(password)) {
        throw new Exception("connection string is empty from property file");
    }

    String url = serverName + ";" + "databaseName=" + databaseName;
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    conn = DriverManager.getConnection(url, user, password);
    return conn;
}

From source file:com.yoncabt.abys.core.util.Util.java

public static List<Integer> parseSequence(String sequence, int maxCount) {
    if (StringUtils.isBlank(sequence)) {
        return Collections.EMPTY_LIST;
    }// ww w  .  j av  a2  s  .c o m
    List<Integer> ret = new ArrayList<>();
    for (String item : sequence.split(",")) {
        if (item.contains("-")) {
            String[] split = item.split("-");
            int start = Integer.parseInt(split[0]);
            int end = Integer.parseInt(split[1]);
            for (int i = start; start < end && i <= end; i++) {
                ret.add(i);
                if (ret.size() > maxCount) {
                    throw new IllegalArgumentException(sequence);
                }
            }
        } else {
            ret.add(Integer.parseInt(item));
            if (ret.size() > maxCount) {
                throw new IllegalArgumentException(sequence);
            }
        }
    }
    return ret;
}

From source file:io.muic.ooc.service.SecurityService.java

public static boolean authenticate(String username, String password, HttpServletRequest request) {
    if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password)
            && DatabaseQueryService.authenticate(username, password)) {
        request.getSession().setAttribute("username", username);
        return true;
    } else {/*w ww . ja v a2  s .  co m*/
        return false;
    }
}

From source file:gov.nih.nci.cabig.caaers.utils.CaaersUtils.java

/**
  * This method will return String//from   www.  j a  v a 2 s. co  m
  * @param inputString
  * @return
  */

/*
 * This method is used by the ReportVersion and the Reporter objects, which store email as a string
 */
public static String getEmailStringWithoutSemiColonsAndSpaces(String inputString) {
    if (StringUtils.isBlank(inputString)) {
        return null;
    }

    return inputString.replace(";", ",").replace(" ", "");
}

From source file:com.fengduo.bee.commons.util.JsonUtils.java

public static boolean isGoodJson(String json) {
    if (StringUtils.isBlank(json)) {
        return false;
    }//  www.j  a v a  2s  .c  om
    try {
        new JsonParser().parse(json);
        return true;
    } catch (JsonParseException e) {
        logger.error("bad json: " + json);
        return false;
    }
}