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

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

Introduction

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

Prototype

public static String trimToNull(String str) 

Source Link

Document

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

Usage

From source file:com.opengamma.integration.server.copier.ServerDatabasePopulator.java

/**
 * Main method to run the tool. No arguments are needed.
 *
 * @param args  the arguments, unused/*from w w w.j av a2 s . co  m*/
 */
public static void main(final String[] args) { // CSIGNORE
    s_logger.info("Populating demo server database");
    try {
        CommandLineOption option = new CommandLineOption(args, ServerDatabasePopulator.class);
        String configFile = StringUtils.trimToNull(option.getConfigFile());
        String serverUrl = StringUtils.trimToNull(option.getServerUrl());

        if (configFile != null && serverUrl != null) {
            ServerDatabasePopulator populator = new ServerDatabasePopulator(configFile,
                    new DatabasePopulatorTool(serverUrl));
            populator.run();
        }
        System.exit(0);
    } catch (final Exception ex) {
        s_logger.error("Caught exception", ex);
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java

/**
 * @param args// www .  j a va2  s.  c om
 */
public static void main(String[] args) {
    boolean inplace = false;

    String workspace = "/Users/davidabad/workspaces/SIDE-Modules/";
    String frameworkmodulesPath = "/Volumes/Data/SVN/side/HEAD/S-IDE/FrameworksModules/trunk/";
    String classifier_base = "enterprise";
    String version_base = "3.4.6";
    String classifier_target = "enterprise";
    String version_target = "3.4.11";
    String frameworkmodulesInplace = "/Volumes/Data/SVN/projects/Ifremer/IfremerV5/src/modules/mavenProjects";

    Properties props = new Properties();
    try {
        InputStream resourceAsStream = PrepareSIDEModulesMigration.class
                .getResourceAsStream("config.properties");
        if (resourceAsStream != null) {
            props.load(resourceAsStream);

            inplace = Boolean.parseBoolean(props.getProperty("inplace", Boolean.toString(inplace)));
            workspace = props.getProperty("workspace", workspace);
            frameworkmodulesPath = props.getProperty("frameworkmodulesPath", frameworkmodulesPath);
            classifier_base = props.getProperty("classifier_base", classifier_base);
            version_base = props.getProperty("version_base", version_base);
            classifier_target = props.getProperty("classifier_target", classifier_target);
            version_target = props.getProperty("version_target", version_target);
            frameworkmodulesInplace = props.getProperty("frameworkmodulesInplace", frameworkmodulesInplace);
        } else {
            System.out.println("no configuration founded in classpath config.properties");
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    }

    System.out.println("properties :");
    Enumeration<?> propertyNames = props.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String nextElement = propertyNames.nextElement().toString();
        System.out.println("\t " + nextElement + " : " + props.getProperty(nextElement));
    }

    File workspaceFile = new File(workspace);

    File targetHome = new File(workspaceFile, MIGRATION_FOLDER);
    if (targetHome.exists()) {
        try {
            FileUtils.deleteDirectory(targetHome);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    final String versionInProjectName = getVersionInProjectName(classifier_base, version_base);
    String versionInProjectName2 = getVersionInProjectName(classifier_target, version_target);

    if (frameworkmodulesPath.contains(",")) {
        // this is a list of paths
        String[] split = frameworkmodulesPath.split(",");
        for (String string : split) {
            if (StringUtils.trimToNull(string) != null) {
                executeInpath(inplace, string, classifier_base, version_base, classifier_target, version_target,
                        frameworkmodulesInplace, workspaceFile, versionInProjectName, versionInProjectName2);
            }
        }
    } else {
        executeInpath(inplace, frameworkmodulesPath, classifier_base, version_base, classifier_target,
                version_target, frameworkmodulesInplace, workspaceFile, versionInProjectName,
                versionInProjectName2);
    }

    System.out.println("Job's done !");
    System.out.println("Please check " + MIGRATION_FOLDER);
    System.out.println(
            "If all is ok you can use commit.sh in a terminal do : cd " + MIGRATION_FOLDER + "; sh commit.sh");
    System.out.println(
            "This script will create new svn projet and commit resources, add 'target' to svn:ignore ...");

}

From source file:controllers.Notes.java

public static Result save() {
    DynamicForm form = Form.form().bindFromRequest();

    String signature = form.get("signature");
    String url = form.get("url");

    String text = StringUtils.trimToNull(form.get("note"));

    if (signature == null || url == null) {
        return badRequest();
    }/*from w ww. ja v  a2  s  .c o  m*/

    NoteService service = injector().getInstance(NoteService.class);
    if (text == null) {
        service.delete(signature);
    } else {
        Note note = service.find(signature);
        if (note == null) {
            note = new Note();
            note.setSignature(signature);
            note.setAddedOn(new Date());
        }

        note.setText(text);
        note.setUpdatedOn(new Date());
        service.save(note);
    }

    return redirect(url);
}

From source file:com.egt.core.db.util.DBUtils.java

/**
 * Busca el nombre del constraint en el mensaje que envia el RDBMS cuando se produce un conflicto
 *
 * @param message Cadena correspondiente al mensaje que envia el RDBMS
 * @param status Entero correspondiente al tipo de conflicto (cualquiera de las constantes ROW_CONFLICT de
 * SyncResolver)/*from w  w  w .  j  a  va  2 s .  co  m*/
 * @return Si se consigue, el nombre del constraint; de lo contratio retorna null
 */
public static String getConstraintMessageKey(String message, int status) {
    String trimmed = StringUtils.trimToNull(message);
    if (trimmed != null) {
        String[] tokens = StringUtils.split(trimmed, SEPARADORES);
        if (tokens != null && tokens.length > 0) {
            String key;
            for (int i = 0; i < tokens.length; i++) {
                key = tokens[i].toLowerCase();
                if (key.endsWith(SUFIJO) && StringUtils.startsWithAny(key, PREFIJOS)) {
                    if (status == 1 && key.startsWith("fk_")) {
                        key += "_" + status;
                    }
                    return "<" + key + ">";
                }
            }
        }
    }
    return null;
}

From source file:au.org.ala.names.util.FileUtils.java

private static boolean ignore(String line) {
    if (StringUtils.trimToNull(line) == null || line.startsWith("#")) {
        return true;
    }/*w ww . j av  a2 s.c o m*/
    return false;
}

From source file:io.milton.http.annotated.DataBinder.java

/**
 * Trims to null, so will never return a value padded with white space, or only whitespace
 * //ww  w . j av a  2 s. com
 * @param props
 * @param name
 * @return 
 */
public static String getRawParam(Map<String, String> props, String name) {
    String s = props.get(name);
    return StringUtils.trimToNull(s);
}

From source file:com.github.zhanglubing.Tag.java

public static JSONObject serch(String id) {
    if (StringUtils.trimToNull(id) == null) {
        return null;
    }/*from w w w .  j  a v a 2 s  .c  o  m*/
    JSONArray array = getAllTag();
    for (Object object : array) {
        JSONObject tag = JSONObject.fromObject(object);
        if (id.trim().equalsIgnoreCase(tag.getString("id"))) {
            return tag;
        }
    }
    return null;
}

From source file:com.github.zhanglubing.Catalog.java

public static JSONObject serch(String id) {
    if (StringUtils.trimToNull(id) == null) {
        return null;
    }//from   w  w  w  .ja va  2 s.  c  o  m
    JSONArray array = getAllCatalog();
    for (Object object : array) {
        JSONObject catalog = JSONObject.fromObject(object);
        if (id.trim().equalsIgnoreCase(catalog.getString("id"))) {
            return catalog;
        }
    }
    return null;
}

From source file:com.kixeye.chassis.bootstrap.aws.UserData.java

public static UserData parse(String userData) {
    if (!StringUtils.isBlank(userData)) {
        StringTokenizer stringTokenizer = new StringTokenizer(userData, "\n");
        while (stringTokenizer.hasMoreTokens()) {
            String line = stringTokenizer.nextToken();
            int envStartIdx = line.indexOf(ENVIRONMENT_TEXT);
            if (envStartIdx >= 0) {
                String env = line.substring(envStartIdx + ENVIRONMENT_TEXT.length());
                return new UserData(StringUtils.trimToNull(env));
            }//from  ww w  .j a  v  a  2s.  c  o  m
        }
    }
    throw new BootstrapException("Found no environment data in user-data " + userData);
}

From source file:com.enonic.cms.core.structure.SiteProperties.java

public String getProperty(final String propertyKey) {
    return StringUtils.trimToNull(properties.getProperty(propertyKey));
}