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

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

Introduction

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

Prototype

public static boolean isEmpty(String str) 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    String var1 = null;
    String var2 = "";
    String var3 = "    \t\t\t";
    String var4 = "Hello World";

    System.out.println("var1 is blank? = " + StringUtils.isBlank(var1));
    System.out.println("var2 is blank? = " + StringUtils.isBlank(var2));
    System.out.println("var3 is blank? = " + StringUtils.isBlank(var3));
    System.out.println("var4 is blank? = " + StringUtils.isBlank(var4));

    System.out.println("var1 is not blank? = " + StringUtils.isNotBlank(var1));
    System.out.println("var2 is not blank? = " + StringUtils.isNotBlank(var2));
    System.out.println("var3 is not blank? = " + StringUtils.isNotBlank(var3));
    System.out.println("var4 is not blank? = " + StringUtils.isNotBlank(var4));

    System.out.println("var1 is empty? = " + StringUtils.isEmpty(var1));
    System.out.println("var2 is empty? = " + StringUtils.isEmpty(var2));
    System.out.println("var3 is empty? = " + StringUtils.isEmpty(var3));
    System.out.println("var4 is empty? = " + StringUtils.isEmpty(var4));

    System.out.println("var1 is not empty? = " + StringUtils.isNotEmpty(var1));
    System.out.println("var2 is not empty? = " + StringUtils.isNotEmpty(var2));
    System.out.println("var3 is not empty? = " + StringUtils.isNotEmpty(var3));
    System.out.println("var4 is not empty? = " + StringUtils.isNotEmpty(var4));
}

From source file:myproject.HelloWorld.java

/**
   * Main method.//from   ww  w  .  j a  v a2  s.  c  o m
   *
   * @param args Not used
   */
public static void main(String[] args) {
    String empty = null;
    Context context = new DefaultContext();
    ConsoleLogger consoleLogger = new ConsoleLogger(Logger.LEVEL_INFO, "console");
    consoleLogger.info("great it works");
    if (StringUtils.isEmpty(empty)) {
        System.exit(0);
    }
    System.exit(1);
}

From source file:com.eddy.malupdater.MalUpdater.java

public static void main(String args[]) {
    try {//from  w w w.jav a  2 s .  c  om
        initMainLogger();
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
        Logger.getLogger(MalUpdater.class.getName()).log(Level.SEVERE, null, ex);
    }

    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            form = new MalUpdaterForm();

            if (StringUtils.isEmpty(MyProperties.getUsername()) || MyProperties.getPassword().length <= 0) {
                CredentialsPanel credentialsPanel = CredentialsPanel.getInstance();
                credentialsPanel.setVisible(true);
            }
        }
    });
}

From source file:au.org.ala.layers.stats.ObjectsStatsGenerator.java

public static void main(String[] args) {
    long start = System.currentTimeMillis();

    String fid = null;/*from  ww w .j a  v a2 s.  co m*/

    logger.info(
            "args[0] = threadcount, args[1] = db connection string, args[2] = db username, args[3] = password");
    if (args.length >= 4) {
        CONCURRENT_THREADS = Integer.parseInt(args[0]);
        db_url = args[1];
        db_usr = args[2];
        db_pwd = args[3];
    }
    if (args.length > 4) {
        fid = args[4];
    }

    Connection c = getConnection();
    //String count_sql = "select count(*) as cnt from objects where bbox is null or area_km is null";
    String count_sql = "select count(*) as cnt from objects where area_km is null and st_geometrytype(the_geom) <> 'ST_Point' ";
    if (StringUtils.isEmpty(fid)) {
        count_sql = count_sql + " and fid = '" + fid + "'";
    }

    int count = 0;
    try {
        Statement s = c.createStatement();
        ResultSet rs = s.executeQuery(count_sql);
        while (rs.next()) {
            count = rs.getInt("cnt");
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    int iter = count / 200000;

    logger.info("Breaking into " + iter + " iterations");
    for (int i = 0; i <= iter; i++) {
        long iterStart = System.currentTimeMillis();
        //  updateBbox();
        updateArea(fid);
        logger.info("iteration " + i + " completed after " + (System.currentTimeMillis() - iterStart) + "ms");
        logger.info("total time taken is " + (System.currentTimeMillis() - start) + "ms");
    }
}

From source file:com.athena.peacock.agent.Starter.java

/**
 * <pre>//from  w ww  . j  a  v a 2  s. com
 * 
 * </pre>
 * @param args
 */
@SuppressWarnings("resource")
public static void main(String[] args) {

    int rand = (int) (Math.random() * 100) % 50;
    System.setProperty("random.seconds", Integer.toString(rand));

    String configFile = null;

    try {
        configFile = PropertyUtil.getProperty(PeacockConstant.CONFIG_FILE_KEY);
    } catch (Exception e) {
        // nothing to do.
    } finally {
        if (StringUtils.isEmpty(configFile)) {
            configFile = "/peacock/agent/config/agent.conf";
        }
    }

    /**
     * ${peacock.agent.config.file.name} ?? load  ? ??   ? ?  ? .
     */
    String errorMsg = "\n\"" + configFile + "\" file does not exist or cannot read.\n" + "Please check \""
            + configFile + "\" file exists and can read.";

    Assert.isTrue(AgentConfigUtil.exception == null, errorMsg);
    Assert.notNull(AgentConfigUtil.getConfig(PeacockConstant.SERVER_IP), "ServerIP cannot be empty.");
    Assert.notNull(AgentConfigUtil.getConfig(PeacockConstant.SERVER_PORT), "ServerPort cannot be empty.");

    /**
     * Agent ID ??  ${peacock.agent.agent.file.name} ?   ?, 
     *  ?? ?   Agent ID ? ?? .
     */
    String agentFile = null;
    String agentId = null;

    try {
        agentFile = PropertyUtil.getProperty(PeacockConstant.AGENT_ID_FILE_KEY);
    } catch (Exception e) {
        // nothing to do.
    } finally {
        if (StringUtils.isEmpty(agentFile)) {
            agentFile = "/peacock/agent/.agent";
        }
    }

    File file = new File(agentFile);
    boolean isNew = false;

    if (file.exists()) {
        try {
            agentId = IOUtils.toString(file.toURI());

            // ? ? agent ID  agent ID? ? 36? ?   ?.
            if (StringUtils.isEmpty(agentId) || agentId.length() != 36) {
                throw new IOException();
            }
        } catch (IOException e) {
            logger.error(agentFile + " file cannot read or saved invalid agent ID.", e);

            agentId = PeacockAgentIDGenerator.generateId();
            isNew = true;
        }
    } else {
        agentId = PeacockAgentIDGenerator.generateId();
        isNew = true;
    }

    if (isNew) {
        logger.info("New Agent-ID({}) be generated.", agentId);

        try {
            file.setWritable(true);
            OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(file));
            output.write(agentId);
            file.setReadOnly();
            IOUtils.closeQuietly(output);
        } catch (UnsupportedEncodingException e) {
            logger.error("UnsupportedEncodingException has occurred : ", e);
        } catch (FileNotFoundException e) {
            logger.error("FileNotFoundException has occurred : ", e);
        } catch (IOException e) {
            logger.error("IOException has occurred : ", e);
        }
    }

    // Spring Application Context Loading
    logger.debug("Starting application context...");
    AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "classpath:spring/context-*.xml");
    applicationContext.registerShutdownHook();
}

From source file:de.escidoc.core.admin.AdminMain.java

/**
 * Main Method, depends on args[0] which method is executed.
 * /*  w ww .  j av a 2 s  .  co  m*/
 * @param args
 *            arguments given on commandline
 * @throws NoSuchMethodException
 *             e
 * @throws InvocationTargetException
 *             e
 * @throws IllegalAccessException
 *             e
 */
public static void main(final String[] args) {
    int result = 20;

    try {
        AdminMain admin = new AdminMain();

        // call has to have at least one argument
        if (args.length > 0 && !StringUtils.isEmpty(args[0])) {
            String methodToCall = methods.get(args[0]);

            if (!StringUtils.isEmpty(methodToCall)) {
                log.info("memory (free / max. available): " + Runtime.getRuntime().freeMemory() / 1024 / 1024
                        + " MB" + " / " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + " MB");

                Class<?>[] paramTypes = { String[].class };
                Method thisMethod = admin.getClass().getDeclaredMethod(methodToCall, paramTypes);

                thisMethod.invoke(admin, new Object[] { args });
                result = 0;
            } else {
                admin.failMessage("provided tool name: " + StringUtils.join(args, " "));
            }
        } else {
            admin.failMessage();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        e.printStackTrace();
    }
    System.exit(result);
}

From source file:com.athena.chameleon.engine.Starter.java

/**
 * <pre>/*from w w  w .  j a va2 s  . com*/
 * WAS Migration ?  main() ? ? ? .
 *   <ul>
 *      <li>Migration ?  ?? Full Qualified File Name? ??  ? .</li>
 *      <li>? ??   ?? .</li>
 *      <li>Spring Context ?? loading  spring ?  .</li>
 *      <li>Migration engine module? .</li>
 *   </ul>
 * </pre>
 * 
 * @param args
 */
public static void main(String[] args) {
    logger.debug("Starting of Athena Chameleon WAS Migration tool.");

    String sourceFile = null;
    String deployFile = null;
    if (args.length == 0) {
        sourceFile = getSourceFileName();
        deployFile = getApplicationFileName();
    } else if (args.length == 1) {
        sourceFile = args[0].replaceAll("\\\\", "/");
        if (!isExists(sourceFile) || !isValidSourceExtension(sourceFile)) {
            System.out.println(sourceFile
                    + "?()   ?? ?  ? ?.");
            //sourceFile = getSourceFileName();
        }
        deployFile = getApplicationFileName();
    } else if (args.length == 2) {
        sourceFile = args[0].replaceAll("\\\\", "/");
        if (!isExists(sourceFile) || !isValidSourceExtension(sourceFile)) {
            System.out.println(sourceFile
                    + "?()   ?? ?  ? ?.");
            //sourceFile = getSourceFileName();
        }

        deployFile = args[1].replaceAll("\\\\", "/");
        if (!isExists(deployFile) || !isValidApplicationExtension(deployFile)) {
            System.out.println(deployFile
                    + "?()   ?? ?  ? ?.");
            //deployFile = getApplicationFileName();
        }
    } else {
        System.out.println(
                "[Usage] : java -jar athena-chameleon.jar ${Project Source Archive File} ${Application Archive File}");
        System.exit(-1);
    }

    if (StringUtils.isEmpty(sourceFile) && StringUtils.isEmpty(deployFile)) {
        System.out.println(
                "[Error] ? ?   ? ? .");
        System.exit(-1);
    }

    Upload upload = new Upload();
    upload.setProjectNm(getProjectName());
    upload.setAfterWas(getTargetWas());
    upload.setDepartment(getDepartment());
    upload.setPerson(getManagerName());

    logger.debug("Project Source File => [{}]", sourceFile);
    logger.debug("Application Archive File => [{}]", deployFile);

    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/context-*.xml");

    MigrationComponent component = (MigrationComponent) context.getBean("migrationComponent");
    component.migrate(sourceFile, deployFile, upload);
}

From source file:com.nimbits.MainClass.java

public static void main(final String[] args) throws IOException, XMPPException, NimbitsException {
    final HashMap<String, String> argsMap = new HashMap<String, String>();

    if (args == null || args.length == 0) {
        printUsage();//  w w w .j a  v a 2 s . c o  m
        return;
    } else {
        processArgs(args, argsMap);
    }

    if (argsMap.containsKey(Parameters.i.getText())) {
        String[] fileArgs = KeyFile.processKeyFile(argsMap);
        processArgs(fileArgs, argsMap);
    }

    final boolean verbose = argsMap.containsKey(Parameters.verbose.getText());
    final boolean listen = argsMap.containsKey(Parameters.listen.getText());
    final String host = argsMap.containsKey(Parameters.host.getText()) ? argsMap.get(Parameters.host.getText())
            : Path.PATH_NIMBITS_PUBLIC_SERVER;
    final String emailParam = argsMap.containsKey(Parameters.email.getText())
            ? argsMap.get(Parameters.email.getText())
            : null;
    final String key = argsMap.containsKey(Parameters.key.getText()) ? argsMap.get(Parameters.key.getText())
            : null;
    final String appId = argsMap.containsKey(Parameters.appid.getText())
            ? argsMap.get(Parameters.appid.getText())
            : null;
    final String password = argsMap.containsKey(Parameters.password.getText())
            ? argsMap.get(Parameters.password.getText())
            : null;

    final String protocol = argsMap.containsKey(Parameters.protocol.getText())
            ? argsMap.get(Parameters.protocol.getText())
            : null;

    if (StringUtils.isEmpty(emailParam)) {
        throw new NimbitsException("you must specify an account i.e. email=test@example.com");
    }

    if (StringUtils.isNotEmpty(host) && StringUtils.isNotEmpty(emailParam) & StringUtils.isNotEmpty(key)) {
        createClient(host, emailParam, key, password);
    }
    //
    //        if (!loggedIn) {
    //            out(true, "Access Denied.");
    //            return;
    //        }

    if (argsMap.containsKey(Parameters.action.getText())) {
        Action action = Action.valueOf(argsMap.get(Parameters.action.getText()));

        switch (action) {
        case read:
        case readValue:
        case readGps:
        case readJson:
        case readNote:
            readValue(argsMap, action);
            break;
        case record:
        case recordValue:
            recordValue(argsMap, verbose);
            break;
        case listen:
            listen(appId, protocol, emailParam);
            break;

        default:
            printUsage();
        }
    } else if (argsMap.containsKey(Parameters.genkey.getText())
            && argsMap.containsKey(Parameters.out.getText())) {

        out(true, KeyFile.genKey(argsMap));

    }

    out(true, "exiting");

}

From source file:com.npower.dm.util.ConvertMailProfile.java

/**
 * @param args/*from   w w  w  .  ja  va 2s  .  co  m*/
 */
public static void main(String[] args) throws Exception {
    File outputFile = new File("c:/temp/mail.xml");
    FileWriter writer = new FileWriter(outputFile);

    File csvFile = new File("c:/temp/mail.csv");
    BufferedReader reader = new BufferedReader(new FileReader(csvFile));
    String line = reader.readLine();
    while (line != null) {
        line = reader.readLine();
        if (StringUtils.isEmpty(line)) {
            continue;
        }

        String[] cols = StringUtils.split(line, ',');
        Map<String, String> values = new HashMap<String, String>();
        values.put("name", cols[0]);
        values.put("smtp.host", cols[1]);
        values.put("pop.host", cols[2]);

        writeXML(writer, values);
    }

    writer.close();
    reader.close();
}

From source file:com.baidu.rigel.biplatform.ma.file.serv.FileServer.java

/**
 * /*from  w w  w  .j  av a 2s  . co m*/
 * ???server
 * 
 * @param args
 */
public static void main(String[] args) throws Exception {
    //        if (args.length != 1) {
    //            LOGGER.error("can not get enough parameters for starting file server");
    //            printUsage();
    //            System.exit(-1);
    //        }

    FileInputStream fis = null;
    String classLocation = FileServer.class.getProtectionDomain().getCodeSource().getLocation().toString();
    final File configFile = new File(classLocation + "/../conf/fileserver.conf");
    Properties properties = new Properties();
    try {
        if (configFile.exists()) {
            fis = new FileInputStream(configFile);
        } else if (StringUtils.isNotEmpty(args[0])) {
            fis = new FileInputStream(args[0]);
        } else {
            printUsage();
            throw new RuntimeException("can't find correct file server configuration file!");
        }
        properties.load(fis);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }
    int port = -1;
    try {
        port = Integer.valueOf(properties.getProperty(PORT_NUM_KEY));
    } catch (NumberFormatException e) {
        LOGGER.error("parameter is not correct, [port = {}]", args[0]);
        System.exit(-1);
    }

    String location = properties.getProperty(ROOT_DIR_KEY);
    if (StringUtils.isEmpty(location)) {
        LOGGER.error("the location can not be empty");
        System.exit(-1);
    }

    File f = new File(location);
    if (!f.exists() && !f.mkdirs()) {
        LOGGER.error("invalidation location [{}] please verify the input", args[1]);
        System.exit(-1);
    }
    startServer(location, port);
}