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

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

Introduction

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

Prototype

public static boolean isEmpty(final CharSequence cs) 

Source Link

Document

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

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

NOTE: This method changed in Lang version 2.0.

Usage

From source file:io.wcm.handler.richtext.impl.DataPropertyUtil.java

/**
 * Converts a headless camel case property name to a HTML5 data attribute name including "data-" prefix.
 * @param headlessCamelCaseName Headless camel case name
 * @return HTML5 data attribute name//from  w  ww  .j  a  v  a 2  s .  c om
 * @throws IllegalArgumentException If parameter name is not valid
 */
public static String toHtml5DataName(String headlessCamelCaseName) {
    if (StringUtils.isEmpty(headlessCamelCaseName)) {
        throw new IllegalArgumentException("Property name is empty.");
    }
    if (!isHeadlessCamelCaseName(headlessCamelCaseName)) {
        throw new IllegalArgumentException(
                "This is not a valid headless camel case property name: " + headlessCamelCaseName);
    }

    StringBuilder html5DataName = new StringBuilder(HTML5_DATA_PREFIX);
    for (int i = 0; i < headlessCamelCaseName.length(); i++) {
        char c = headlessCamelCaseName.charAt(i);
        if (CharUtils.isAsciiAlphaUpper(c)) {
            html5DataName.append('-');
        }
        html5DataName.append(Character.toLowerCase(c));
    }

    return html5DataName.toString();
}

From source file:controllers.SearchApp.java

/**
 * Search contents that current user can read in all projects.
 *
 * @return// www  .  ja va  2  s .c o  m
 */
public static Result searchInAll() {
    // SearchCondition from param
    String searchTypeValue = request().getQueryString("searchType");
    String keyword = request().getQueryString("keyword");
    PageParam pageParam = getPage();

    if (StringUtils.isEmpty(keyword) || StringUtils.isEmpty(searchTypeValue)) {
        return badRequest(ErrorViews.BadRequest.render());
    }

    User user = UserApp.currentUser();
    SearchType searchType = SearchType.getValue(searchTypeValue);

    if (searchType == SearchType.NA) {
        return badRequest(ErrorViews.BadRequest.render());
    }

    SearchResult searchResult = getSearchResult(keyword, user, searchType);
    switch (searchResult.getSearchType()) {
    case ISSUE:
        searchResult.setIssues(Search.findIssues(keyword, user, pageParam));
        break;
    case USER:
        searchResult.setUsers(Search.findUsers(keyword, pageParam));
        break;
    case PROJECT:
        searchResult.setProjects(Search.findProjects(keyword, user, pageParam));
        break;
    case POST:
        searchResult.setPosts(Search.findPosts(keyword, user, pageParam));
        break;
    case MILESTONE:
        searchResult.setMilestones(Search.findMilestones(keyword, user, pageParam));
        break;
    case ISSUE_COMMENT:
        searchResult.setIssueComments(Search.findIssueComments(keyword, user, pageParam));
        break;
    case POST_COMMENT:
        searchResult.setPostComments(Search.findPostComments(keyword, user, pageParam));
        break;
    case REVIEW:
        searchResult.setReviews(Search.findReviews(keyword, user, pageParam));
        break;
    }
    return ok(result.render("title.search", null, null, searchResult));
}

From source file:com.vmware.identity.openidconnect.protocol.ParameterMapUtils.java

public static String getString(Map<String, String> parameters, String key) throws ParseException {
    Validate.notNull(parameters, "parameters");
    Validate.notEmpty(key, "key");

    String result = parameters.get(key);
    if (StringUtils.isEmpty(result)) {
        throw new ParseException(String.format("missing %s parameter", key));
    }/*from   w ww  . ja  v a 2 s. com*/
    return result;
}

From source file:de.pixida.logtest.automatondefinitions.SomeTestAutomaton.java

static String getFileName(final String version) {
    return String.format(TEST_FILE_NAME, StringUtils.isEmpty(version) ? "" : "-" + version);
}

From source file:Action.UserRegisterAction.java

@Override
public void validate() {
    if (StringUtils.isEmpty(userregister.getUsername()))
        addFieldError("userregister.username", "User Name can not be blank");
    if (StringUtils.isEmpty(userregister.getFirst_name()))
        addFieldError("userregister.first_name", "Full Name can not be blank");
    if (StringUtils.isEmpty(userregister.getPassword()))
        addFieldError("userregister.password", "Password can not be blank");
    if (StringUtils.isEmpty(userregister.getGender()))
        addFieldError("userregister.gender", "Gender can not be blank");
    if (StringUtils.isEmpty(userregister.getDob()))
        addFieldError("userregister.dob", "Date Of Birth can not be blank");
    if (StringUtils.isEmpty(userregister.getCourse()))
        addFieldError("userregister.course", "Course can not be blank");
    if (StringUtils.isEmpty(userregister.getEducation()))
        addFieldError("userregister.education", "Education can not be blank");
    if (StringUtils.isEmpty(userregister.getYop()))
        addFieldError("userregister.yop", "Year of pass can not be blank");
    if (StringUtils.isEmpty(userregister.getMob_no()))
        addFieldError("userregister.mob_no", "Contact Number can not be blank");
    if (StringUtils.isEmpty(userregister.getEmail_id()))
        addFieldError("userregister.email_id", "Email can not be blank");
    if (StringUtils.isEmpty(userregister.getCollege()))
        addFieldError("userregister.college", "College Name can not be blank");
}

From source file:dtu.ds.warnme.app.utils.SecurityUtils.java

public static String hashSHA512Base64(String stringToHash) {
    if (StringUtils.isEmpty(stringToHash)) {
        return StringUtils.EMPTY;
    }/*from w  w  w. j av  a 2  s. c  o m*/
    try {
        byte[] bytes = stringToHash.getBytes(CHARSET_UTF8);
        byte[] md5bytes = DigestUtils.sha512(bytes);
        byte[] base64bytes = Base64.encodeBase64(md5bytes);
        return new String(base64bytes, CHARSET_UTF8);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "This system does not support required hashing algorithms.", e);
        throw new IllegalStateException("This system does not support required hashing algorithms.", e);
    }
}

From source file:info.mikaelsvensson.devtools.common.PathUtils.java

public static String getRelativePath(File source, File target) {
    source = source.isDirectory() ? source : source.getParentFile();

    String sourceFixed = fixPath(source);
    String targetFixed = fixPath(target);

    String[] sourceParts = StringUtils.split(sourceFixed, SEP);
    String[] targetParts = StringUtils.split(targetFixed, SEP);
    int sharedParts = 0;
    for (int i = 0; i < sourceParts.length; i++) {
        String sourcePart = sourceParts[i];
        if (targetParts.length == i) {
            break;
        }/*from   w  ww.  j  av  a  2  s .  co  m*/
        String targetPart = targetParts[i];
        if (sourcePart.equals(targetPart)) {
            sharedParts = i;
        }
    }

    String toSharedRoot = StringUtils.repeat(".." + SEP, sourceParts.length - sharedParts - 1);
    String fromSharedRoot = StringUtils.join(targetParts, SEP, sharedParts + 1, targetParts.length);
    if (StringUtils.isEmpty(toSharedRoot) && StringUtils.isEmpty(fromSharedRoot)) {
        return "." + SEP;
    } else {
        return toSharedRoot + fromSharedRoot;
    }

}

From source file:com.qiongsong.ficus.dal.internal.DDLFormatterImpl.java

@Override
public String format(String sql) {
    if (StringUtils.isEmpty(sql)) {
        return sql;
    }/*  w  w  w  . ja  v a 2  s .c o  m*/
    if (sql.toLowerCase(Locale.ROOT).startsWith("create table")) {
        return formatCreateTable(sql);
    } else if (sql.toLowerCase(Locale.ROOT).startsWith("alter table")) {
        return formatAlterTable(sql);
    } else if (sql.toLowerCase(Locale.ROOT).startsWith("comment on")) {
        return formatCommentOn(sql);
    } else {
        return "\n    " + sql;
    }
}

From source file:de.yaio.services.metaextract.client.MetaExtractClient.java

public static MetaExtractClient createClient(final String metaextracturl, final String metaextractusername,
        final String metaextractpassword) {
    if (StringUtils.isEmpty(metaextracturl)) {
        throw new IllegalArgumentException("cant create webshotclient: metaextracturl must not be empty");
    }/*from www . j  a  v a2  s .  com*/
    if (StringUtils.isEmpty(metaextractusername)) {
        throw new IllegalArgumentException("cant create webshotclient: metaextractusername must not be empty");
    }
    if (StringUtils.isEmpty(metaextractpassword)) {
        throw new IllegalArgumentException("cant create webshotclient: metaextractpassword must not be empty");
    }
    return new MetaExtractClient(metaextracturl, metaextractusername, metaextractpassword);
}

From source file:AIR.Common.Json.JsonHelper.java

public static <T> T deserialize(String json, TypeReference<T> typeReference)
        throws JsonParseException, JsonMappingException, IOException {
    if (StringUtils.isEmpty(json))
        return null;

    ObjectMapper mapper = new ObjectMapper();

    return mapper.readValue(json, typeReference);
}