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

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

Introduction

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

Prototype

public static String trimToEmpty(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null.

Usage

From source file:com.hangum.tadpole.preference.dialogs.user.ChangeUsePersonalToGrouprDialog.java

@Override
protected void okPressed() {
    String strEmail = StringUtils.trimToEmpty(textEMail.getText());
    String passwd = StringUtils.trimToEmpty(textPasswd.getText());
    String rePasswd = StringUtils.trimToEmpty(textRePasswd.getText());
    String name = StringUtils.trimToEmpty(textName.getText());
    String strIp = StringUtils.trimToEmpty(textAllowIP.getText());

    if (!validation(strEmail, passwd, rePasswd, name, strIp))
        return;// ww w. j a  va2  s.c  om

    if (MessageDialog.openConfirm(getShell(), Messages.get().Confirm,
            Messages.get().ChangeUsePersonalToGrouprDialog_7)) {
        UserDAO user = new UserDAO();
        user.setSeq(userDAO.getSeq());
        user.setEmail(strEmail);
        user.setPasswd(passwd);
        user.setName(name);
        user.setAllow_ip(strIp);

        try {
            TadpoleSystem_UserQuery.updateUserPersonToGroup(user);
            TadpoleSystemQuery.updateSystemInformation(PublicTadpoleDefine.SYSTEM_USE_GROUP.GROUP.name());

            MessageDialog.openInformation(getShell(), Messages.get().Confirm,
                    Messages.get().ChangeUsePersonalToGrouprDialog_9);
            TadpoleApplicationContextManager.initSystem();
            SessionManager.logout();

        } catch (Exception e) {
            logger.error("data update", e); //$NON-NLS-1$

            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(getShell(), Messages.get().Error, "User Info update", //$NON-NLS-1$
                    errStatus); //$NON-NLS-2$

            return;
        }

        super.okPressed();
    } else {
        return;
    }
}

From source file:com.prowidesoftware.swift.model.field.Field31F.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///from  w  ww  . j a v a2 s. c  o  m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent2())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent3())) {
        result.append("//");
        result.append(StringUtils.trimToEmpty(getComponent3()));
    }
    return result.toString();
}

From source file:com.prowidesoftware.swift.model.field.Field26K.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///from   www  . j av  a 2  s  . c  o m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    appendInLines(result, 2, 7);
    return result.toString();
}

From source file:com.prowidesoftware.swift.model.field.Field344.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//* w  ww .j  a v a 2s.c  om*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent2())) {
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    return result.toString();
}

From source file:com.prowidesoftware.swift.model.field.Field87E.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 */// w  ww  .j a  v  a2 s  .  c  o  m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
    if (StringUtils.isNotEmpty(getComponent2())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    if (StringUtils.isNotEmpty(getComponent3())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent3()));
    }
    result.append(StringUtils.trimToEmpty(getComponent4()));
    return result.toString();
}

From source file:com.prowidesoftware.swift.model.field.Field25P.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///from   w ww . j  av a  2  s . c  o m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    if (StringUtils.isNotEmpty(getComponent2())) {
        result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    return result.toString();
}

From source file:jp.co.nemuzuka.utils.ConvertUtils.java

/**
 * String???.//from  ww  w  .  j  a  v  a  2  s .c  om
 * ??SP?
 * 
 * ?
 * ???String?????
 * @param array ?String?
 * @return ?String?
 */
private static String[] createTrimStrArray(String[] array) {
    Set<String> strSet = new LinkedHashSet<String>();

    for (String value : array) {
        String target = StringUtils.trimToEmpty(value);
        if (StringUtils.isEmpty(target)) {
            continue;
        }
        strSet.add(target);
    }
    return strSet.toArray(new String[0]);
}

From source file:com.prowidesoftware.swift.model.field.Field11A.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//*from   ww  w  .  j av a 2  s  .  c o  m*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(":");
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append("//");
    result.append(StringUtils.trimToEmpty(getComponent2()));
    return result.toString();
}

From source file:com.haulmont.cuba.core.sys.utils.DbUpdaterUtil.java

@SuppressWarnings("AccessStaticViaInstance")
public void execute(String[] args) {
    Options cliOptions = new Options();

    Option dbConnectionOption = OptionBuilder.withArgName("connectionString").hasArgs()
            .withDescription("JDBC Database URL").isRequired().create("dbUrl");

    Option dbUserOption = OptionBuilder.withArgName("userName").hasArgs().withDescription("Database user")
            .isRequired().create("dbUser");

    Option dbPasswordOption = OptionBuilder.withArgName("password").hasArgs()
            .withDescription("Database password").isRequired().create("dbPassword");

    Option dbDriverClassOption = OptionBuilder.withArgName("driverClassName").hasArgs()
            .withDescription("JDBC driver class name").create("dbDriver");

    Option dbDirOption = OptionBuilder.withArgName("filePath").hasArgs()
            .withDescription("Database scripts directory").isRequired().create("scriptsDir");

    Option dbTypeOption = OptionBuilder.withArgName("dbType").hasArgs()
            .withDescription("DBMS type: postgres|mssql|oracle|etc").isRequired().create("dbType");

    Option dbVersionOption = OptionBuilder.withArgName("dbVersion").hasArgs()
            .withDescription("DBMS version: 2012|etc").create("dbVersion");

    Option dbExecuteGroovyOption = OptionBuilder.withArgName("executeGroovy").hasArgs()
            .withDescription("Ignoring Groovy scripts").create("executeGroovy");

    Option showUpdatesOption = OptionBuilder.withDescription("Print update scripts").create("check");

    Option applyUpdatesOption = OptionBuilder.withDescription("Update database").create("update");

    Option createDbOption = OptionBuilder.withDescription("Create database").create("create");

    cliOptions.addOption("help", false, "Print help");
    cliOptions.addOption(dbConnectionOption);
    cliOptions.addOption(dbUserOption);//from  ww  w .ja va 2 s .  com
    cliOptions.addOption(dbPasswordOption);
    cliOptions.addOption(dbDirOption);
    cliOptions.addOption(dbTypeOption);
    cliOptions.addOption(dbVersionOption);
    cliOptions.addOption(dbExecuteGroovyOption);
    cliOptions.addOption(showUpdatesOption);
    cliOptions.addOption(applyUpdatesOption);
    cliOptions.addOption(createDbOption);

    CommandLineParser parser = new PosixParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;
    try {
        cmd = parser.parse(cliOptions, args);
    } catch (ParseException exp) {
        formatter.printHelp("dbupdate", cliOptions);
        return;
    }

    if (cmd.hasOption("help") || (!cmd.hasOption(showUpdatesOption.getOpt()))
            && !cmd.hasOption(applyUpdatesOption.getOpt()) && !cmd.hasOption(createDbOption.getOpt()))
        formatter.printHelp("dbupdate", cliOptions);
    else {
        this.dbScriptsDirectory = cmd.getOptionValue(dbDirOption.getOpt());
        File directory = new File(dbScriptsDirectory);
        if (!directory.exists()) {
            log.error("Not found db update directory");
            return;
        }

        dbmsType = cmd.getOptionValue(dbTypeOption.getOpt());
        dbmsVersion = StringUtils.trimToEmpty(cmd.getOptionValue(dbVersionOption.getOpt()));

        AppContext.Internals.setAppComponents(new AppComponents("core"));

        AppContext.setProperty("cuba.dbmsType", dbmsType);
        AppContext.setProperty("cuba.dbmsVersion", dbmsVersion);

        String dbDriver;
        if (!cmd.hasOption(dbDriverClassOption.getOpt())) {
            switch (dbmsType) {
            case "postgres":
                dbDriver = "org.postgresql.Driver";
                break;
            case "mssql":
                if (MS_SQL_2005.equals(dbmsVersion)) {
                    dbDriver = "net.sourceforge.jtds.jdbc.Driver";
                } else {
                    dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
                }
                break;
            case "oracle":
                dbDriver = "oracle.jdbc.OracleDriver";
                break;
            default:
                log.error(
                        "Unable to determine driver class name by DBMS type. Please provide driverClassName option");
                return;
            }
        } else {
            dbDriver = cmd.getOptionValue(dbDriverClassOption.getOpt());
        }

        try {
            Class.forName(dbDriver);
        } catch (ClassNotFoundException e) {
            log.error("Unable to load driver class " + dbDriver);
            return;
        }

        String connectionStringParam = cmd.getOptionValue(dbConnectionOption.getOpt());
        try {
            this.dataSource = new SingleConnectionDataSource(connectionStringParam,
                    cmd.getOptionValue(dbUserOption.getOpt()), cmd.getOptionValue(dbPasswordOption.getOpt()));
        } catch (SQLException e) {
            log.error("Unable to connect to db: " + connectionStringParam);
            return;
        }

        if (cmd.hasOption(createDbOption.getOpt())) {
            // create database from init scripts
            StringBuilder availableScripts = new StringBuilder();
            for (ScriptResource initScript : getInitScripts()) {
                availableScripts.append("\t").append(getScriptName(initScript)).append("\n");
            }
            log.info("Available create scripts: \n" + availableScripts);
            log.info(String.format("Do you want to create database %s ? [y/n]", connectionStringParam));
            Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
            if ("y".equals(scanner.next())) {
                doInit();
            }
        } else {
            boolean updatesAvailable = false;
            try {
                List<String> scripts;

                executeGroovy = !(cmd.hasOption(dbExecuteGroovyOption.getOpt())
                        && cmd.getOptionValue(dbExecuteGroovyOption.getOpt()).equals("false"));

                scripts = findUpdateDatabaseScripts();

                if (!scripts.isEmpty()) {
                    StringBuilder availableScripts = new StringBuilder();
                    for (String script : scripts) {
                        availableScripts.append("\t").append(script).append("\n");
                    }
                    log.info("Available updates:\n" + availableScripts);
                    updatesAvailable = true;
                } else
                    log.info("No available updates found for database");
            } catch (DbInitializationException e) {
                log.warn("Database not initialized");
                return;
            }

            if (updatesAvailable && cmd.hasOption(applyUpdatesOption.getOpt())) {
                log.info(String.format("Do you want to apply updates to %s ? [y/n]", connectionStringParam));
                Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
                if ("y".equals(scanner.next())) {
                    doUpdate();
                }
            }
        }
    }
}

From source file:com.prowidesoftware.swift.model.field.Field87F.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///from www. j  ava 2  s  . c  o  m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
    if (StringUtils.isNotEmpty(getComponent2())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    if (StringUtils.isNotEmpty(getComponent3())) {
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent3()));
    }
    result.append(StringUtils.trimToEmpty(getComponent4()));
    appendInLines(result, 5, 7);
    return result.toString();
}