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.ms.app.web.validation.validator.RequiredValidator.java

public boolean validate(Object value) {
    if (value instanceof String) {
        String newValue = StringUtils.trimToNull((String) value);
        return newValue != null;
    } else {/*from   w  w  w  .j a  v  a2  s. c  o  m*/
        return value != null;
    }
}

From source file:de.fhg.iais.asc.sipmaker.SipMakerDynamicClass.java

public static String fullClassName(final String packageName, final String className) {
    StringBuilder fullName = new StringBuilder(120); // pre-set of guessed size reduces expandCapacity() and increases performance

    final String trimedPackageName = StringUtils.trimToNull(packageName);
    if (trimedPackageName != null) {
        fullName.append(trimedPackageName);
        if (!trimedPackageName.endsWith(".")) {
            fullName.append(".");
        }/*  w w w.  ja  v a  2 s . c o  m*/
    }
    fullName.append(StringUtils.trimToEmpty(className));

    return fullName.toString();
}

From source file:com.ms.app.web.validation.validator.EmailValidator.java

public boolean validate(Object value) {
    if (value instanceof String) {
        String email = StringUtils.trimToNull((String) value);
        return org.apache.commons.validator.EmailValidator.getInstance().isValid(email);
    } else {/*from   www .  j a  v a 2 s  .co  m*/
        throw new RuntimeException("EmailValidator ??String");
    }
}

From source file:com.opengamma.integration.viewer.status.ViewColumnType.java

/**
 * Produce a ViewColumnType equivalent of a given short name.
 * /*w  w w.jav a  2  s .c  o  m*/
 * @param shortName the shortname, not-null
 * @return the view columntype for the short name or null if there is no match
 */
public static ViewColumnType of(String shortName) {
    shortName = StringUtils.trimToNull(shortName);
    if (shortName != null) {
        ViewColumnType[] values = ViewColumnType.values();
        for (ViewColumnType type : values) {
            if (type.getShortName().equalsIgnoreCase(shortName)) {
                return type;
            }
        }
    }
    return null;
}

From source file:ips1ap101.lib.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)
 * @return Si se consigue, el nombre del constraint; de lo contratio retorna null
 *///  w w w  .  j  a v a2 s.c o m
public static String getConstraintMessageKey(String message, int status) {
    String trimmed = StringUtils.trimToNull(message);
    if (trimmed != null) {
        trimmed = trimmed.replaceAll("[^a-zA-Z0-9_]", " ");
        trimmed = trimmed.trim().toLowerCase();
        String[] tokens = StringUtils.split(trimmed);
        if (tokens != null && tokens.length > 0) {
            String key, string;
            for (int i = 0; i < tokens.length; i++) {
                key = tokens[i];
                if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                    key = StringUtils.removeEnd(key, SUFIJO);
                    if (key.contains("_fk_")) {
                        key += status == 1 ? ".1" : ".2";
                    }
                    string = BundleMensajes.getString(key);
                    return isKey(string) ? string : "<" + key + ">";
                }
            }
        }
    }
    return null;
}

From source file:adalid.commons.util.ObjUtils.java

private static String trimToNull(Object o) {
    return StringUtils.trimToNull(toString(o));
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Get the named cookie from the HTTP Request
 *
 * @param request Request to get the Cookie from
 * @param cookieName name of Cookie to get
 * @return the named Cookie, null if the named Cookie cannot be found
 *//*from   w w  w  .  j a v a 2  s .co  m*/
public static Cookie getCookie(HttpServletRequest request, String cookieName) {
    cookieName = StringUtils.trimToNull(cookieName);
    if (cookieName == null) {
        return null;
    }

    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }

    if (cookies.length > 0) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equals(cookieName, cookie.getName())) {
                return cookie;
            }
        }
    }

    return null;
}

From source file:ips1ap101.lib.base.util.TemporalAddend.java

public TemporalAddend(String string) {
    init();//  www  .j a v  a 2  s . c  o m
    String trimmed = StringUtils.trimToNull(string);
    if (trimmed != null) {
        int end = trimmed.length() - 1;
        char unit = trimmed.charAt(end);
        boolean digit = Character.isDigit(unit);
        _quantity = digit ? quantityOf(trimmed) : quantityOf(trimmed.substring(0, end));
        _unit = ArrayUtils.contains(_validUnits, unit) ? unit : digit ? 'D' : '?';
    }
}

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

private static synchronized InterpreteSql getInstance(String driver, String url, String version) {
    Bitacora.trace(InterpreteSqlCachingServiceLocator.class, "getInstance", driver, url, version);
    String d = StringUtils.trimToNull(driver);
    String u = StringUtils.trimToNull(url);
    //      String v = StringUtils.trimToNull(version);
    if (d == null || u == null) {
        return null;
    }//from  w w  w  .j  av  a2s .c o  m
    InterpreteSql instance;
    if (instances.containsKey(d)) {
        return (InterpreteSql) instances.get(d);
    } else if (StringUtils.containsIgnoreCase(u, "oracle")) {
        instance = new InterpreteSqlOracle();
    } else if (StringUtils.containsIgnoreCase(u, "postgresql")) {
        instance = new InterpreteSqlPostgreSQL();
    } else if (StringUtils.containsIgnoreCase(u, "sqlserver")) {
        instance = new InterpreteSqlSQLServer();
    } else {
        return null;
    }
    instances.put(d, instance);
    return instance;
}

From source file:com.google.code.configprocessor.processing.AbstractAction.java

public String getName() {
    return StringUtils.trimToNull(name);
}