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:au.org.ala.bhl.policy.DefaultRetrievePolicy.java

public boolean shouldRetrieveItem(ItemTO item) {

    if (!StringUtils.isEmpty(item.getLocalCacheFile())) {
        File cachedFile = new File(item.getLocalCacheFile());
        if (!cachedFile.exists()) {
            return true;
        }/* ww  w . j av a  2 s  .  c  o  m*/
    }

    if (StringUtils.isEmpty(item.getStatus())) {
        return true;
    }

    return false;
}

From source file:eu.eidas.auth.engine.metadata.Contact.java

public void setEmail(String email) {
    if (!StringUtils.isEmpty(email)) {
        this.email = email;
    }
}

From source file:com.ms.app.web.commons.utils.JSONPResultUtils.java

public static String getNeedLoginJson(String callback) {
    if (StringUtils.isEmpty(callback)) {
        return JsonResultUtils.getNeedLoginJson();
    }//from w  w  w.  j  a v a 2 s. c o m
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("result", ResultCode.NEED_LOGIN.getValue());// ??
    params.put("message", getMessage(ResultCode.NEED_LOGIN, null));// ???
    params.put("data", "");// ??
    try {
        StringBuilder sb = new StringBuilder(200);
        sb.append(callback);
        sb.append('(');
        sb.append(JsonUtils.object2Json(params));
        sb.append(')');
        return sb.toString();
    } catch (Exception e) {
    }
    return JsonResultUtils.getNeedLoginJson();
}

From source file:net.sourceforge.fenixedu.domain.phd.access.PhdProcessAccessTypeList.java

static public PhdProcessAccessTypeList importFromString(String value) {
    return StringUtils.isEmpty(value) ? EMPTY : new PhdProcessAccessTypeList(value);
}

From source file:com.haulmont.cuba.security.jmx.ServerTokenStore.java

@Override
public String removeTokensByUserLogin(String userLogin) {
    if (StringUtils.isEmpty(userLogin)) {
        return "Please specify the user's login";
    }//from   w  w  w .j av  a  2 s .  c o  m

    try {
        Set<String> tokens = serverTokenStore.getAccessTokenValuesByUserLogin(userLogin);
        if (tokens.isEmpty()) {
            return String.format("No tokens found for user '%s'", userLogin);
        }

        tokens.forEach(serverTokenStore::removeAccessToken);

        return String.format("%s tokens were removed for user '%s' successfully.", tokens.size(), userLogin);
    } catch (Throwable t) {
        return ExceptionUtils.getStackTrace(t);
    }
}

From source file:net.loyin.jfinal.TypeConverter.java

/**
 * test for all types of mysql//w w w .  ja  v  a 2s .c o  m
 * 
 * ???:
 * 1: ?,?,? "", ??? null.
 * 2: ???
 * 3: ? model string,? "" ? null??,
 *    ,  null, ? ""
 * 
 * ?: 1:clazz??String.class, ?sblank,
 *       ? null, ?
 *      2:???? null ?? ModelInjector 
 */
public static final Object convert(Class<?> clazz, String s) throws ParseException {
    // mysql type: varchar, char, enum, set, text, tinytext, mediumtext, longtext
    if (clazz == String.class) {
        return (StringUtils.isEmpty(s) ? null : s); // ???? "", ,?? null.
    }
    s = s.trim();
    if (StringUtils.isEmpty(s)) { // ?? String?,? null,  ??
        return null;
    }
    // ??,, ?, ??null s ?(????null, ?"")

    Object result = null;
    // mysql type: int, integer, tinyint(n) n > 1, smallint, mediumint
    if (clazz == Integer.class || clazz == int.class) {
        result = Integer.parseInt(s);
    }
    // mysql type: bigint
    else if (clazz == Long.class || clazz == long.class) {
        result = Long.parseLong(s);
    }
    // ?java.util.Data?, java.sql.Date, java.sql.Time,java.sql.Timestamp  java.util.Data,  getDate??
    else if (clazz == java.util.Date.class) {
        if (s.length() >= timeStampLen) { // if (x < timeStampLen)  datePattern ?
            // Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
            // result = new java.util.Date(java.sql.Timestamp.valueOf(s).getTime());   // error under jdk 64bit(maybe)
            result = new SimpleDateFormat(timeStampPattern).parse(s);
        } else {
            // result = new java.util.Date(java.sql.Date.valueOf(s).getTime());   // error under jdk 64bit
            result = new SimpleDateFormat(datePattern).parse(s);
        }
    }
    // mysql type: date, year
    else if (clazz == java.sql.Date.class) {
        if (s.length() >= timeStampLen) { // if (x < timeStampLen)  datePattern ?
            // result = new java.sql.Date(java.sql.Timestamp.valueOf(s).getTime());   // error under jdk 64bit(maybe)
            result = new java.sql.Date(new SimpleDateFormat(timeStampPattern).parse(s).getTime());
        } else {
            // result = new java.sql.Date(java.sql.Date.valueOf(s).getTime());   // error under jdk 64bit
            result = new java.sql.Date(new SimpleDateFormat(datePattern).parse(s).getTime());
        }
    }
    // mysql type: time
    else if (clazz == java.sql.Time.class) {
        result = java.sql.Time.valueOf(s);
    }
    // mysql type: timestamp, datetime
    else if (clazz == java.sql.Timestamp.class) {
        result = java.sql.Timestamp.valueOf(s);
    }
    // mysql type: real, double
    else if (clazz == Double.class) {
        result = Double.parseDouble(s);
    }
    // mysql type: float
    else if (clazz == Float.class) {
        result = Float.parseFloat(s);
    }
    // mysql type: bit, tinyint(1)
    else if (clazz == Boolean.class) {
        result = Boolean.parseBoolean(s) || "1".equals(s);
    }
    // mysql type: decimal, numeric
    else if (clazz == java.math.BigDecimal.class) {
        result = new java.math.BigDecimal(s);
    }
    // mysql type: unsigned bigint
    else if (clazz == java.math.BigInteger.class) {
        result = new java.math.BigInteger(s);
    }
    // mysql type: binary, varbinary, tinyblob, blob, mediumblob, longblob. I have not finished the test.
    else if (clazz == byte[].class) {
        result = s.getBytes();
    } else {
        throw new RuntimeException(
                clazz.getName() + " can not be converted, please use other type of attributes in your model!");
    }

    return result;
}

From source file:com.sqewd.os.maracache.api.structs.DataType.java

/**
 * Parse the specified string as the data-type enum.
 *
 * @param value - String value to parse.
 * @return/*from   w ww.j av  a 2s. com*/
 * @throws DataTypeException
 */
public static DataType parse(String value) throws DataTypeException {
    if (!StringUtils.isEmpty(value)) {
        DataType[] types = DataType.values();
        for (DataType t : types) {
            if (t.name().compareToIgnoreCase(value) == 0) {
                return t;
            }
        }
    }
    throw new DataTypeException("Invalid DataType specified. No type found for string. [value=" + value + "]");
}

From source file:com.clican.pluto.dataprocess.spring.parser.DplExecProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    this.setBeanDefinitionStringProperty("resultName", beanDef, element);

    String dplStatement = element.getAttribute("dplStatement");
    if (StringUtils.isEmpty(dplStatement)) {
        dplStatement = "dplStatement";
    }//from w ww .ja v  a 2s  .  com
    String clazz = element.getAttribute("clazz");
    if (StringUtils.isNotEmpty(clazz)) {
        try {
            Class c = Class.forName(clazz);
            beanDef.getPropertyValues().addPropertyValue("clazz", c);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    String singleRow = element.getAttribute("singleRow");
    if (StringUtils.isNotEmpty(singleRow)) {
        beanDef.getPropertyValues().addPropertyValue("singleRow", Boolean.parseBoolean(singleRow));
    }
    String traces = element.getAttribute("traces");
    if (StringUtils.isNotEmpty(traces)) {
        List<String> traceList = new ArrayList<String>();
        for (String trace : traces.split(",")) {
            traceList.add(trace.trim());
        }
        beanDef.getPropertyValues().addPropertyValue("traces", traceList);
    }
    beanDef.getPropertyValues().addPropertyValue("dplStatement", new RuntimeBeanReference(dplStatement));
    beanDef.getPropertyValues().addPropertyValue("dpl", element.getTextContent().trim());
}

From source file:com.netscape.certsrv.dbs.keydb.KeyIdAdapter.java

public KeyId unmarshal(String value) throws Exception {
    return StringUtils.isEmpty(value) ? null : new KeyId(value);
}

From source file:com.asual.lesscss.ResourcePackage.java

public static ResourcePackage fromString(String source) {
    if (!StringUtils.isEmpty(source)) {
        try {/*from ww w  .j a v a  2  s.c  o m*/
            String key;
            String path = null;
            String extension = null;
            int slashIndex = source.lastIndexOf("/");
            int dotIndex = source.lastIndexOf(".");
            if (dotIndex != -1 && slashIndex < dotIndex) {
                extension = source.substring(dotIndex + 1);
                path = source.substring(0, dotIndex);
            } else {
                path = source;
            }
            if (extension != null && !extensions.contains(extension)) {
                return null;
            }
            String[] parts = path.replaceFirst("^/", "").split(SEPARATOR);
            if (cache.containsValue(source)) {
                key = getKeyFromValue(cache, source);
            } else {
                key = parts[parts.length - 1];
                byte[] bytes = null;
                try {
                    bytes = Base64.decodeBase64(key.getBytes(ENCODING));
                    bytes = inflate(bytes);
                } catch (Exception e) {
                }
                key = new String(bytes, ENCODING);
            }
            String[] data = key.split(NEW_LINE);
            ResourcePackage rp = new ResourcePackage((String[]) ArrayUtils.subarray(data, 1, data.length));
            int mask = Integer.valueOf(data[0]);
            if ((mask & NAME_FLAG) != 0) {
                rp.setName(parts[0]);
            }
            if ((mask & VERSION_FLAG) != 0) {
                rp.setVersion(parts[rp.getName() != null ? 1 : 0]);
            }
            rp.setExtension(extension);
            return rp;
        } catch (Exception e) {
        }
    }
    return null;
}