Example usage for org.springframework.util StringUtils isEmpty

List of usage examples for org.springframework.util StringUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util StringUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Object str) 

Source Link

Document

Check whether the given object (possibly a String ) is empty.

Usage

From source file:com.reever.humilheme.web.CookieController.java

public Cookie createCookie(HttpServletRequest request, HttpServletResponse response, String conteudo) {
    String path = StringUtils.isEmpty(request.getContextPath()) ? "/" : request.getContextPath();
    try {//from   www  . ja  v a  2s  .co m
        conteudo = URLEncoder.encode(conteudo, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        _logger.error("Erro no encode do cookie", e);
    }
    Cookie cookie = new Cookie(nomeCookie, conteudo);
    cookie.setMaxAge(expiry);
    cookie.setPath(path);
    cookie.setVersion(1);
    response.addCookie(cookie);
    return cookie;
}

From source file:org.obiba.mica.micaConfig.rest.EntityConfigTranslator.java

/**
 * Translates both schema and definition JSON strings defined in the entity configuration.
 *
 * @param locale/*from   w w  w. j  a  va 2 s. co  m*/
 * @param entityConfig
 * @param <T>
 */
public <T extends EntityConfig> void translateSchemaForm(String locale, T entityConfig) {

    if (StringUtils.isEmpty(locale))
        return;

    Translator translator = JsonTranslator
            .buildSafeTranslator(() -> micaConfigService.getTranslations(locale, false));
    translator = new PrefixedValueTranslator(translator);

    TranslationUtils translationUtils = new TranslationUtils();
    entityConfig.setSchema(translationUtils.translate(entityConfig.getSchema(), translator));
    entityConfig.setDefinition(translationUtils.translate(entityConfig.getDefinition(), translator));
}

From source file:com.mycompany.apsdtask.SpringDataEMailStoringSevice.java

@Override
public Stream<EMail> searchEMail(String from, String subject, String after, String before)
        throws ParseException {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    Date afterDate = (StringUtils.isEmpty(after)) ? df.parse("1984-07-13 00:00:00") : df.parse(after);
    Date beforeDate = (StringUtils.isEmpty(before)) ? df.parse("2084-07-13 00:00:00") : df.parse(before);

    Stream<EMail> results;/*from  w  w w. j a  va 2s . c  o m*/
    if (StringUtils.isEmpty(from)) {
        if (StringUtils.isEmpty(subject)) {
            results = eMailRepository.findByDate(afterDate, beforeDate);
        } else {
            results = eMailRepository.findByDateAndSubject(afterDate, beforeDate, subject);
        }
    } else {
        if (StringUtils.isEmpty(subject)) {
            results = eMailRepository.findByDateAndAuthor(afterDate, beforeDate, from);
        } else {
            results = eMailRepository.findByDateAuthorAndSubject(afterDate, beforeDate, from, subject);
        }
    }
    return results;
}

From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.VariationExceptionLevelResolver.java

public ExceptionLevel resolveExceptionLevel(Exception ex) {
    BusinessTestException we = (BusinessTestException) ex;
    String exceptionCode = we.getResultMessages().getList().get(0).getCode();

    if (StringUtils.isEmpty(exceptionCode)) {
        return ExceptionLevel.ERROR;
    }/*from  w ww  .  ja  v a  2 s. c  o  m*/
    String exceptionCodePrefix = exceptionCode.substring(0, 1).toLowerCase();
    if ("d".equals(exceptionCodePrefix)) {
        return ExceptionLevel.ERROR;
    }
    if ("a".equals(exceptionCodePrefix)) {
        return ExceptionLevel.WARN;
    }
    if ("n".equals(exceptionCodePrefix)) {
        return ExceptionLevel.INFO;
    }
    return ExceptionLevel.ERROR;
}

From source file:cn.guoyukun.spring.jpa.repository.callback.DefaultSearchCallback.java

public DefaultSearchCallback(String alias) {
    this.alias = alias;
    if (!StringUtils.isEmpty(alias)) {
        this.aliasWithDot = alias + ".";
    } else {/* ww  w. j  a  va 2s  . co m*/
        this.aliasWithDot = "";
    }
}

From source file:com.ge.predix.uaa.token.lib.HttpServletRequestUtil.java

/**
 * Extract zone subdomain from request. If both subdomain and header are specificied, the zone subdomain in
 * servername overrides the header value.
 *
 * @param headerNames//from   ww w.  j a v  a  2s .  c  om
 */
public static String getZoneName(final HttpServletRequest req, final String serviceBaseDomain,
        final List<String> headerNames) {
    String zoneName = null;

    if (!StringUtils.isEmpty(serviceBaseDomain)) {
        zoneName = getZoneNameFromRequestHostName(req.getServerName(), serviceBaseDomain);
    }

    if (StringUtils.isEmpty(zoneName)) {
        zoneName = findHeader(req, headerNames);
    }
    return zoneName;
}

From source file:org.psikeds.common.config.ConfigDirectoryHelper.java

/**
 * Try to resolve the configuration directory.
 * /*from ww w  .ja v a 2 s  .c o m*/
 * Note: Yes, method level synchronization is not the most efficient,
 * but we only use it for reading the configuration during application
 * startup, so no need to worry about performance here.
 * 
 * @return File object of the config dir; never null but might
 *         not exist or not be readable!
 */
static synchronized File resolveConfigDir() {
    if (cnfdir == null) {
        String dirname = System.getProperty(CONFIG_DIR_SYSTEM_PROPERTY);
        if (StringUtils.isEmpty(dirname)) {
            final StringBuilder sb = new StringBuilder(System.getProperty("user.home"));
            sb.append(File.separatorChar);
            sb.append(FALLBACK_SUB_DIR);
            dirname = sb.toString();
            LOGGER.info("System property {} not set ... fallback to {}", CONFIG_DIR_SYSTEM_PROPERTY, dirname);
        }
        cnfdir = new File(dirname);
        if (!cnfdir.exists() || !cnfdir.isDirectory() || !cnfdir.canRead()) {
            LOGGER.warn("Configuration directory {} does not exist or is not readable!",
                    cnfdir.getAbsolutePath());
        }
    }
    return cnfdir;
}

From source file:io.fabric8.spring.cloud.kubernetes.config.SecretsPropertySource.java

private static Map<String, Object> getSourceData(KubernetesClient client, Environment env,
        SecretsConfigProperties config) {
    String name = getApplicationName(env, config);
    String namespace = getApplicationNamespace(client, config);

    Map<String, Object> result = new HashMap<>();
    try {/*from  www  . j  av a2 s  . c o  m*/
        if (config.getLabels().isEmpty()) {
            if (StringUtils.isEmpty(namespace)) {
                putAll(client.secrets().withName(name).get(), result);
            } else {
                putAll(client.secrets().inNamespace(namespace).withName(name).get(), result);
            }
        } else {
            if (StringUtils.isEmpty(namespace)) {
                client.secrets().withLabels(config.getLabels()).list().getItems()
                        .forEach(s -> putAll(s, result));
            } else {
                client.secrets().inNamespace(namespace).withLabels(config.getLabels()).list().getItems()
                        .forEach(s -> putAll(s, result));

            }
        }
    } catch (Exception e) {
        LOGGER.warn("Can't read secret with name: [{}] or labels [{}] in namespace:[{}]. Ignoring", name,
                config.getLabels(), namespace, e);
    }
    return result;
}

From source file:uk.ac.ebi.ep.data.search.model.Taxonomy.java

public String getCommonName() {
    if (StringUtils.isEmpty(commonName) && "Escherichia coli (strain K12)".equalsIgnoreCase(scientificName)) {
        commonName = "E.Coli";
    }/*from  w  w w.jav  a 2 s .  c  om*/

    if (StringUtils.isEmpty(commonName) && "Bacillus subtilis (strain 168)".equalsIgnoreCase(scientificName)) {
        commonName = "Bacillus subtilis";
    }

    return commonName;
}

From source file:org.jdal.vaadin.ui.SpringViewProvider.java

@SuppressWarnings("rawtypes")
@Override/*ww  w.  j  a  va2 s  .  co  m*/
public View getView(String viewName) {

    if (StringUtils.isEmpty(viewName))
        viewName = defaultView;

    Object view = beanFactory.getBean(viewName);

    Component c = null;

    if (view instanceof org.jdal.vaadin.ui.VaadinView) {
        c = ((VaadinView) view).getPanel();
    } else if (view instanceof Component) {
        c = (Component) view;
    }

    return (View) (c instanceof View ? c : new ComponentViewAdapter(c));
}