Example usage for org.apache.commons.lang3 StringUtils isBlank

List of usage examples for org.apache.commons.lang3 StringUtils isBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isBlank.

Prototype

public static boolean isBlank(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is whitespace, empty ("") or null.

 StringUtils.isBlank(null)      = true StringUtils.isBlank("")        = true StringUtils.isBlank(" ")       = true StringUtils.isBlank("bob")     = false StringUtils.isBlank("  bob  ") = false 

Usage

From source file:com.j2.cs.webservices.metrofax.server.json.JsonLongTypeAdapter.java

@Override
public Number read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*from w  w w. ja  v a 2 s  . co m*/
        return null;
    }

    try {
        String result = in.nextString();
        if (StringUtils.isBlank(result)) {
            return null;
        }
        return Long.parseLong(result);
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:com.tdclighthouse.prototype.utils.FreemarkerUtils.java

public static String renderTemplate(String templatePath, Map<String, Object> model, Class<?> classLoaderOfClass)
        throws TemplateException, IOException {
    if (StringUtils.isBlank(templatePath) || model == null) {
        throw new IllegalArgumentException("both templatePath and model are required.");
    }//from   www . ja  v  a  2 s  .com
    Template tempalte = FreemarkerUtils.getTemplate(templatePath, classLoaderOfClass);
    StringWriter stringWriter = new StringWriter();
    tempalte.process(model, stringWriter);
    return stringWriter.toString();
}

From source file:ext.usercenter.UserCenterService.java

/**
 *  ????//w  w w .  ja v  a  2s .c  om
 * 
 * @param session HTTP Session
 * @param email 
 * @param userpassword ?
 * @param userId Id
 * @param realname ??
 * @return SUCCESS?USERNAME_DUPLICATEemail??UNKNOWN_ERROR
 */
public static RegisterResult registerByEmail(Session session, String email, String userpassword, Long userId,
        String realname) {
    if (null == session || StringUtils.isBlank(email) || StringUtils.isBlank(userpassword) || userId == null
            || StringUtils.isBlank(realname)) {
        throw new IllegalArgumentException("illegal method input param. params: session=" + session + ", email="
                + email + ", userpassword is " + (userpassword == null ? "" : "not") + " null, userId = "
                + userId + ", realname = " + realname);
    }

    String device = DeviceUtil.getDeviceByUrl(Context.current().request().path());
    String ip = Context.current().request().remoteAddress();
    UCResult<UCUser> ucResult = UCClient.register(userpassword, null, realname, email, null, device, ip,
            userId);

    if (ucResult.isSuccess()) {
        LoginResult loginResult = UserAuthService.login(session, email, userpassword);
        if (!loginResult.state.equals(LoginResult.STATE.SUCCESS)) {
            LOGGER.error("register error: register success but login fail.");
            return new RegisterResult(RegisterResult.STATE.UNKNOWN_ERROR, null);
        } else {
            return new RegisterResult(RegisterResult.STATE.SUCCESS, ucResult.data.userpassword);
        }
    } else if (ucResult.duplicateData()) {
        return new RegisterResult(RegisterResult.STATE.USERNAME_DUPLICATE, null);
    } else {
        LOGGER.error("register error: " + ucResult);
    }

    return new RegisterResult(RegisterResult.STATE.UNKNOWN_ERROR, null);
}

From source file:com.quatico.base.aem.test.api.values.TestFile.java

public static String path(String... segments) {
    StringBuilder buf = new StringBuilder();
    for (int count = 0, idx = 0; idx < segments.length; idx++) {
        String cur = segments[idx];
        if (StringUtils.isBlank(cur) && count == 0 || StringUtils.isNotBlank(cur) && buf.length() > 1) {
            buf.append(File.separator);
        }//w w  w  .  j  a  va 2 s. c o  m
        if (StringUtils.isNotBlank(cur)) {
            buf.append(cur);
        }
        count++;
    }
    String result = buf.toString();
    if (result.matches("^\\\\[\\w]{1}:")) { // java.io.File cannot handle leading slashes before drive letters on Windows
        result = result.substring(1);
    }
    return result.replace(ILLEGAL_FILE_SEPARATOR, File.separatorChar);
}

From source file:cop.raml.utils.javadoc.JavaDocUtils.java

public static String getText(List<String> lines) {
    if (CollectionUtils.isEmpty(lines))
        return null;

    StringBuilder buf = new StringBuilder();
    int emptyLines = 0;

    for (String line : lines) {
        if (StringUtils.isBlank(line)) {
            if (buf.length() > 0)
                emptyLines++;//from w w w .  ja  v  a 2  s .  com
        } else if (JavaDocTag.startsWith(line))
            break;
        else
            buf.append(StringUtils.repeat("\n", emptyLines + (buf.length() > 0 ? 1 : 0))).append(line);
    }

    return clearMacros(buf.toString());
}

From source file:gov.nih.nci.caintegrator.security.Cai2AuthenticationProcessingFilter.java

/**
 * {@inheritDoc}//from   ww  w.j av a  2  s .co m
 */
@Override
public Authentication attemptAuthentication(HttpServletRequest request) {
    // Based on AppScan failing because of a "Cross-Site Request Forgery"
    if (StringUtils.isBlank(request.getRequestedSessionId())
            || !request.getRequestedSessionId().equals(request.getSession().getId())) {
        throw new AuthenticationServiceException("The session ID is not attached with this request.");
    }
    request.getSession().invalidate();
    request.getSession(true);
    return super.attemptAuthentication(request);
}

From source file:com.netsteadfast.greenstep.sys.WsAuthenticateUtils.java

public static boolean valid(String authenticate) throws Exception {
    if (StringUtils.isBlank(authenticate)) {
        throw new Exception("null key.");
    }/* w  w  w .j a v  a2 s .com*/
    String idStr = EncryptorUtils.decrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(),
            authenticate);
    if (StringUtils.isBlank(idStr)) {
        throw new Exception("null key.");
    }
    String id[] = idStr.split(";");
    if (id.length != 3) {
        return false;
    }
    if (StringUtils.isBlank(id[0]) || StringUtils.isBlank(id[1])) {
        return false;
    }
    return (usessLogHelper.countByCurrent(id[1], id[0]) > 0 ? true : false);
}

From source file:com.gs.obevo.db.impl.core.checksum.ChecksumEntry.java

/**
 * Static-constructor for the given parameters, with adding the convenience of getting the hash checksum from the
 * given text input in a standard manner.
 *//*from  ww w.  j  av a2s .co  m*/
public static ChecksumEntry createFromText(PhysicalSchema physicalSchema, String objectType, String name1,
        String name2, String checksum) {
    final String data = DAStringUtil.normalizeWhiteSpaceFromString(checksum);
    final String checksumData = StringUtils.isBlank(data) ? "" : DigestUtils.md5Hex(data);
    return new ChecksumEntry(physicalSchema, objectType, name1, name2, checksumData);
}

From source file:com.mxep.web.common.persistence.SearchFilter.java

/**
 * searchParamskey?OPERATOR_FIELDNAME// w  w  w  .  ja v  a  2s  .co  m
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value != null && StringUtils.isBlank(value.toString())) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length < 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = "";
        for (int i = 1; i < names.length; i++) {
            filedName += names[i];
            if ((i + 1) < names.length) {
                filedName += ".";
            }
        }

        Operator operator = getOperator(names[0]);
        if (null == operator) {
            continue;
        }

        // searchFilter
        if (isValidDate(value.toString())) {
            try {
                Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd");
                // ?
                if (operator.equals(Operator.LT) || operator.equals(Operator.LTE)) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    cal.add(Calendar.DAY_OF_YEAR, 1);
                    date = cal.getTime();
                }
                // ????
                if (operator.equals(Operator.GT) || operator.equals(Operator.GTE)) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    date = cal.getTime();
                }
                value = date;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (isValidDateTime(value.toString())) {
            try {
                Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd HH:mm:ss");
                value = date;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:com.bazaarvoice.seo.sdk.util.BVMessageUtil.java

/**
 * Gets the message from resource bundle.
 * Pass the message code including error code and you should get a message
 * that is in the resource bundle message_en_US.properties file.
 * Gives back the same message code if it is not configured in resource bundle.
 * // w ww .  j a  va  2s .c  o  m
 * throws {@link MissingResourceException}
 * @param code
 * @return message from resource bundle.
 */
public static String getMessage(String code) {
    if (StringUtils.isBlank(code)) {
        throw new BVSdkException("ERR0001");
    }

    String message = null;
    try {
        message = _rsrcBundle.getString(code);
    } catch (RuntimeException ex) {
        message = code;
    }

    return message;
}