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

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

Introduction

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

Prototype

public static boolean isNotBlank(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is not empty (""), not null and not whitespace only.

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

Usage

From source file:com.omertron.bgg.enums.HotItemType.java

/**
 * Convert a string into an Enum type// w w  w .  j a  v  a2 s .  com
 *
 * @param source String representation of the enum to convert
 * @return The enum that matches the source
 * @throws IllegalArgumentException If type is not recognised
 */
public static HotItemType fromString(String source) {
    if (StringUtils.isNotBlank(source)) {
        try {
            return HotItemType.valueOf(source.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("HotItem " + source + " does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("HotItem must not be null");
}

From source file:com.omertron.bgg.enums.ThingType.java

/**
 * Convert a string into an Enum type/*from   ww w . java  2 s . c  o  m*/
 *
 * @param source String representation of the enum to convert
 * @return The enum that matches the source
 * @throws IllegalArgumentException If type is not recognised
 */
public static ThingType fromString(String source) {
    if (StringUtils.isNotBlank(source)) {
        try {
            return ThingType.valueOf(source.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("ThingType " + source + " does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("ThingType must not be null");
}

From source file:com.sniper.springmvc.utils.CookieUtils.java

/**
 *  Cookie// www.  j a  v  a  2  s . c  o  m
 * 
 * @param name
 *            ??
 * @param value
 *            
 * @param maxAge
 *            ??
 */
public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) {
    Cookie cookie = new Cookie(name, null);
    if (StringUtils.isNotBlank(SpringContextHolder.getApplicationContext().getApplicationName())) {
        cookie.setPath(SpringContextHolder.getApplicationContext().getApplicationName());
    } else {
        cookie.setPath("/");
    }
    cookie.setMaxAge(maxAge);
    try {
        cookie.setValue(URLEncoder.encode(value, "utf-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    response.addCookie(cookie);
}

From source file:com.omertron.fanarttvapi.enumeration.ArtworkCategory.java

/**
 * Convert a string into an Enum type.//from   w ww  .j a  va  2  s  .  c o m
 *
 * @param category
 * @return
 * @throws IllegalArgumentException If type is not recognised
 */
public static ArtworkCategory fromString(String category) {
    if (StringUtils.isNotBlank(category)) {
        try {
            return ArtworkCategory.valueOf(category.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("ArtworkCategory '" + category + "' does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("ArtworkCategory must not be null");
}

From source file:com.omnigon.aem.common.utils.LocaleUtils.java

public static String getLanguageCountryCode(Locale locale) {
    if (locale != null) {
        StringBuilder b = new StringBuilder();

        if (StringUtils.isNotBlank(locale.getLanguage())) {
            b.append(locale.getLanguage().toLowerCase());
        }/* w  w  w.j a  v  a 2 s  .c  om*/

        if (StringUtils.isNotBlank(locale.getCountry())) {
            b.append("_");
            b.append(locale.getCountry().toLowerCase());
        }

        return b.toString();
    } else {
        return StringUtils.EMPTY;
    }
}

From source file:edu.usu.sdl.openstorefront.core.util.TranslateUtil.java

public static <T extends LookupEntity> String translate(Class<T> lookupClass, String code) {
    String translated = code;/*from  w  w  w.j  a  v  a  2 s  . c  o  m*/
    if (StringUtils.isNotBlank(code)) {
        Service serviceProxy = ServiceProxyFactory.getServiceProxy();
        LookupEntity lookupEntity = serviceProxy.getLookupService().getLookupEnity(lookupClass, code);
        if (lookupEntity != null) {
            translated = lookupEntity.getDescription();
        } else {
            log.log(Level.WARNING, MessageFormat.format("Unable to find: {0} in lookup: {1}",
                    new Object[] { code, lookupClass.getName() }));
        }
    }
    return translated;
}

From source file:com.omertron.themoviedbapi.enumeration.MediaType.java

/**
 * Convert a string into an Enum type/*ww w  .java  2s.c  o  m*/
 *
 * @param mediaType
 * @return
 * @throws IllegalArgumentException If type is not recognised
 *
 */
public static MediaType fromString(String mediaType) {
    if (StringUtils.isNotBlank(mediaType)) {
        try {
            return MediaType.valueOf(mediaType.trim().toUpperCase());
        } catch (IllegalArgumentException ex) {
            throw new IllegalArgumentException("MediaType " + mediaType + " does not exist.", ex);
        }
    }
    throw new IllegalArgumentException("MediaType must not be null");
}

From source file:cpcc.core.utils.PropertyUtils.java

/**
 * @param <T> generic type definition of values.
 * @param properties the {@code Properties} instance.
 * @param key the key of the property to set.
 * @param value the property value to set.
 *///  w  w w .  jav  a 2  s  . co  m
public static <T> void setProperty(Properties properties, String key, T value) {
    if (StringUtils.isNotBlank(key) && value != null) {
        properties.setProperty(key, value.toString());
    }
}

From source file:com.thinkbiganalytics.jobrepo.rest.controller.QueryUtils.java

/**
 * This will evaluate the {@code incomingFilter} and append/set the value including the {@code defaultFilter} and return a new String with the updated filter
 *//*from w w  w .j  a va 2 s .  c  o m*/
public static String ensureDefaultFilter(String incomingFilter, String defaultFilter) {
    String filter = incomingFilter;
    if (StringUtils.isBlank(filter) || !StringUtils.containsIgnoreCase(filter, defaultFilter)) {
        if (StringUtils.isNotBlank(filter)) {
            if (StringUtils.endsWith(filter, ",")) {
                filter += defaultFilter;
            } else {
                filter += "," + defaultFilter;
            }
        } else {
            filter = defaultFilter;
        }
    }
    return filter;
}

From source file:com.widowcrawler.core.util.DomainUtils.java

public static boolean isBaseDomain(String baseDomain, String url) {
    try {/* w  ww  . j  a v  a2  s. c  om*/
        baseDomain = StringUtils.lowerCase(StringUtils.trim(baseDomain));
        String domain = StringUtils.lowerCase(StringUtils.trimToNull(new URI(url).getHost()));

        if (domain == null) {
            logger.info("Returning false because url's domain is null");
            return false;
        }

        while (StringUtils.isNotBlank(domain)) {
            if (StringUtils.equals(baseDomain, domain)) {
                return true;
            }

            domain = StringUtils.substringAfter(domain, ".");
        }

        return false;

    } catch (URISyntaxException ex) {
        logger.error("Could not determine base domain relationship. Returning default of false.", ex);
        return false;
    }
}