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

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

Introduction

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

Prototype

public static boolean isBlank(String str) 

Source Link

Document

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

Usage

From source file:com.cy.common.util.ValidateUtil.java

/**
 * //from  w  ww .  j a v  a2s.c  om
 * @param mail ?
 * @return 
 */
public static boolean isMail(String mail) {
    if (StringUtils.isBlank(mail)) {
        return false;
    }
    Pattern mailRegx = Pattern
            .compile("^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,4}$");
    Matcher match = mailRegx.matcher(mail);
    return match.matches();
}

From source file:gov.nih.nci.cabig.ctms.tools.configuration.ConfigurationPropertyEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.isBlank(text)) {
        setValue(null);/*from  w  ww  .ja  v a2  s . c om*/
    } else {
        setValue(property.fromStorageFormat(text));
    }
}

From source file:com.salesmanager.core.service.ws.utils.WebServiceUtils.java

/**
 * Validates web service credentials//w  w  w.j a  v a  2  s . c  o m
 * @param locale
 * @param credentials
 * @throws ServiceException
 */
public static void validateCredentials(Locale locale, WebServiceCredentials credentials, Logger log)
        throws ServiceException {
    MessageSource messageSource = (MessageSource) SpringUtil.getBean("messageSource");

    try {

        int merchantId = credentials.getMerchantId();

        String k = EncryptionUtil.generatekey(String.valueOf(merchantId));
        String apiKeyGen = EncryptionUtil.encrypt(k, String.valueOf(merchantId));

        if (StringUtils.isBlank(apiKeyGen) || apiKeyGen.length() < 16) {
            log.error("Problem with API KEY GENERATION " + apiKeyGen);
            throw new ServiceException(messageSource.getMessage("errors.technical", null, locale));
        }

        String apiKey = credentials.getApiKey();

        if (StringUtils.isBlank(apiKey)) {
            throw new ServiceException(
                    messageSource.getMessage("messages.error.ws.invalidcredentials", null, locale));
        }

        if (!apiKeyGen.equals(apiKey)) {
            throw new ServiceException(
                    messageSource.getMessage("messages.error.ws.invalidcredentials", null, locale));
        }

    } catch (Exception e) {

        if (e instanceof ServiceException) {
            throw (ServiceException) e;
        }

        log.error(e);
        throw new ServiceException(messageSource.getMessage("errors.technical", null, locale));
    }

}

From source file:com.twitter.finagle.common.base.MorePreconditions.java

/**
 * Checks that a string is both non-null and non-empty.
 *
 * @see #checkNotBlank(String, String, Object...)
 */// w w w.  j a v  a2s .co  m
public static String checkNotBlank(String argument) {
    Preconditions.checkNotNull(argument, ARG_NOT_BLANK_MSG);
    Preconditions.checkArgument(!StringUtils.isBlank(argument), ARG_NOT_BLANK_MSG);
    return argument;
}

From source file:io.logspace.hq.rest.AbstractLogspaceResourcesBase.java

protected static String getQueryParam(Request req, String name, String defaultValue) {
    String value = StringUtils.trim(req.queryParams(name));
    if (StringUtils.isBlank(value)) {
        return defaultValue;
    }/*from   w  w  w . j  a va2s. co  m*/

    return value;
}

From source file:com.carlomicieli.jtrains.validation.ISOValidationUtils.java

/**
 * Returns {@code true} if the value is a valid 2-letter country code as defined in ISO 3166.
 * @param country the country code/*from  w  ww.  j a v  a  2  s.co  m*/
 * @return {@code true} if the value is a valid country; {@code false} otherwise
 */
public static boolean countryIsValid(String country) {
    if (StringUtils.isBlank(country)) {
        return true;
    }
    return Arrays.binarySearch(Locale.getISOCountries(), country.toUpperCase()) >= 0;
}

From source file:com.googlecode.gmaps4jsf.jsfplugin.util.FacesMojoUtils.java

public static String getWrapperType(String type) {
    String wrapperType = (String) wrapperMap.get(type);

    if (StringUtils.isBlank(wrapperType))
        return type; //if none found just return the same type
    else/*  w w  w. jav a2 s .  com*/
        return wrapperType;
}

From source file:biz.netcentric.cq.tools.actool.validators.Validators.java

public static boolean isValidRegex(String expression) {
    if (StringUtils.isBlank(expression)) {
        return true;
    }//w  w  w. ja  v a2s.c o m
    boolean isValid = true;

    if (expression.startsWith("*")) {
        expression = expression.replaceFirst("\\*", "\\\\*");
    }
    try {
        Pattern.compile(expression);
    } catch (PatternSyntaxException e) {
        LOG.error("Error while validating rep glob: {} ", expression, e);
        isValid = false;
    }

    return isValid;
}

From source file:com.alibaba.ims.platform.util.DateUtil.java

/**
 * ?//w w w  .ja va  2 s.c  o m
 *
 * @param dateStr
 * @param pattern
 * @return
 */
public static Date parse(String dateStr, String pattern) {
    if (StringUtils.isBlank(dateStr)) {
        return null;
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    try {
        return simpleDateFormat.parse(dateStr);
    } catch (ParseException e) {
        logger.error("Parse string to date error.", e);
        return null;
    }
}

From source file:com.ultrapower.eoms.common.plugin.ecside.common.HTMLOptionsUtil.java

    public static String getOptionsList(Map imap,Object defaultKey ,String otherAttribute){
      StringBuffer rs=new StringBuffer();
      Iterator itor=imap.keySet().iterator();
      //  w  ww .j av  a  2s .co m
      while (itor.hasNext()){
//         String key=(String)itor.next();
//         String value=(String)imap.get(key);
         String key=String.valueOf(itor.next()); 
         
         String value=convertString(imap.get(key),""); 
         
         String selected="";
         if (key.equals(defaultKey)){
            selected="selected=\"selected\"";
         }
         otherAttribute=StringUtils.isBlank(otherAttribute)?"":" "+otherAttribute+" ";

         rs.append("<option value=\"").append(key).append("\" ").append(selected).append(otherAttribute).append(" >")
            .append(value).append("</option>\n");
      }
      
      return rs.toString();
   }