Example usage for org.springframework.util StringUtils hasText

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

Introduction

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

Prototype

public static boolean hasText(@Nullable String str) 

Source Link

Document

Check whether the given String contains actual text.

Usage

From source file:org.springmodules.validation.bean.conf.loader.xml.handler.SizeRuleElementHandler.java

protected AbstractValidationRule createValidationRule(Element element) {

    String minText = element.getAttribute(MIN_ATTR);
    String maxText = element.getAttribute(MAX_ATTR);

    Integer min = (StringUtils.hasText(minText)) ? new Integer(minText) : null;
    Integer max = (StringUtils.hasText(maxText)) ? new Integer(maxText) : null;

    if (min != null && max != null) {
        return new SizeValidationRule(min.intValue(), max.intValue());
    }//from ww  w .j  a va  2s .  c  o m

    if (min != null) {
        return new MinSizeValidationRule(min.intValue());
    }

    if (max != null) {
        return new MaxSizeValidationRule(max.intValue());
    }

    throw new ValidationConfigurationException(
            "Element '" + ELEMENT_NAME + "' must have either 'min' attribute, 'max' attribute, or both");

}

From source file:org.web4thejob.web.dialog.DefaultHtmlDialog.java

@Override
protected boolean isOKReady() {
    return StringUtils.hasText(getValue());
}

From source file:io.spring.initializr.actuate.stat.ProjectRequestDocumentFactory.java

public ProjectRequestDocument createDocument(ProjectRequestEvent event) {
    InitializrMetadata metadata = this.metadataProvider.get();
    ProjectRequest request = event.getProjectRequest();

    ProjectRequestDocument document = new ProjectRequestDocument();
    document.setGenerationTimestamp(event.getTimestamp());

    handleCloudFlareHeaders(request, document);
    String candidate = (String) request.getParameters().get("x-forwarded-for");
    if (!StringUtils.hasText(document.getRequestIp()) && candidate != null) {
        document.setRequestIp(candidate);
        document.setRequestIpv4(extractIpv4(candidate));
    }//from   ww w.j  a v  a2  s .  c o  m

    Agent agent = extractAgentInformation(request);
    if (agent != null) {
        document.setClientId(agent.getId().getId());
        document.setClientVersion(agent.getVersion());
    }

    document.setGroupId(request.getGroupId());
    document.setArtifactId(request.getArtifactId());
    document.setPackageName(request.getPackageName());
    document.setBootVersion(request.getBootVersion());

    document.setJavaVersion(request.getJavaVersion());
    if (StringUtils.hasText(request.getJavaVersion())
            && metadata.getJavaVersions().get(request.getJavaVersion()) == null) {
        document.setInvalid(true);
        document.setInvalidJavaVersion(true);
    }

    document.setLanguage(request.getLanguage());
    if (StringUtils.hasText(request.getLanguage())
            && metadata.getLanguages().get(request.getLanguage()) == null) {
        document.setInvalid(true);
        document.setInvalidLanguage(true);
    }

    document.setPackaging(request.getPackaging());
    if (StringUtils.hasText(request.getPackaging())
            && metadata.getPackagings().get(request.getPackaging()) == null) {
        document.setInvalid(true);
        document.setInvalidPackaging(true);
    }

    document.setType(request.getType());
    if (StringUtils.hasText(request.getType()) && metadata.getTypes().get(request.getType()) == null) {
        document.setInvalid(true);
        document.setInvalidType(true);
    }

    // Let's not rely on the resolved dependencies here
    List<String> dependencies = new ArrayList<>();
    dependencies.addAll(request.getStyle());
    dependencies.addAll(request.getDependencies());
    dependencies.forEach((id) -> {
        if (metadata.getDependencies().get(id) != null) {
            document.getDependencies().add(id);
        } else {
            document.setInvalid(true);
            document.getInvalidDependencies().add(id);
        }
    });

    // Let's make sure that the document is flagged as invalid no matter what
    if (event instanceof ProjectFailedEvent) {
        ProjectFailedEvent failed = (ProjectFailedEvent) event;
        document.setInvalid(true);
        if (failed.getCause() != null) {
            document.setErrorMessage(failed.getCause().getMessage());
        }
    }

    return document;
}

From source file:com.brienwheeler.svc.usergroups.validation.UserGroupNotExistValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    if (!StringUtils.hasText(value))
        return !constraintAnnotation.failOnEmpty();

    IUserGroupService userGroupService = applicationContext.getBean(constraintAnnotation.userGroupService(),
            IUserGroupService.class);
    return userGroupService.findByNameAndType(value, constraintAnnotation.groupType()) == null;
}

From source file:com.ryantenney.metrics.spring.config.AnnotationDrivenBeanDefinitionParser.java

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    final Object source = parserContext.extractSource(element);

    final CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(),
            source);/*ww w . ja  v  a 2  s . c o m*/
    parserContext.pushContainingComponent(compDefinition);

    String metricsBeanName = element.getAttribute("metric-registry");
    if (!StringUtils.hasText(metricsBeanName)) {
        metricsBeanName = registerComponent(parserContext,
                build(MetricRegistry.class, source, ROLE_APPLICATION));
    }

    String healthCheckBeanName = element.getAttribute("health-check-registry");
    if (!StringUtils.hasText(healthCheckBeanName)) {
        healthCheckBeanName = registerComponent(parserContext,
                build(HealthCheckRegistry.class, source, ROLE_APPLICATION));
    }

    final ProxyConfig proxyConfig = new ProxyConfig();

    if (StringUtils.hasText(element.getAttribute("expose-proxy"))) {
        proxyConfig.setExposeProxy(Boolean.valueOf(element.getAttribute("expose-proxy")));
    }

    if (StringUtils.hasText(element.getAttribute("proxy-target-class"))) {
        proxyConfig.setProxyTargetClass(Boolean.valueOf(element.getAttribute("proxy-target-class")));
    }

    //@formatter:off

    registerComponent(parserContext,
            build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE)
                    .setFactoryMethod("exceptionMetered").addConstructorArgReference(metricsBeanName)
                    .addConstructorArgValue(proxyConfig));

    registerComponent(parserContext,
            build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE)
                    .setFactoryMethod("metered").addConstructorArgReference(metricsBeanName)
                    .addConstructorArgValue(proxyConfig));

    registerComponent(parserContext,
            build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE).setFactoryMethod("timed")
                    .addConstructorArgReference(metricsBeanName).addConstructorArgValue(proxyConfig));

    registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE)
            .setFactoryMethod("gauge").addConstructorArgReference(metricsBeanName));

    registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE)
            .setFactoryMethod("injectMetric").addConstructorArgReference(metricsBeanName));

    registerComponent(parserContext, build(MetricsBeanPostProcessorFactory.class, source, ROLE_INFRASTRUCTURE)
            .setFactoryMethod("healthCheck").addConstructorArgReference(healthCheckBeanName));

    //@formatter:on

    parserContext.popAndRegisterContainingComponent();

    return null;
}

From source file:org.jboss.seam.spring.namespace.BeanManagerBeanDefinitionParser.java

@Override
protected String resolveId(org.w3c.dom.Element element, AbstractBeanDefinition definition,
        ParserContext parserContext) throws BeanDefinitionStoreException {
    String idAttributeValue = element.getAttribute(ID_ATTRIBUTE);
    if (StringUtils.hasText(idAttributeValue)) {
        return idAttributeValue;
    }//  w  ww  .  j a  v a  2 s .com
    return DEFAULT_BEAN_MANAGER_ID;
}

From source file:egov.data.hibernate.repository.config.HibernateRepositoryConfigDefinitionParser.java

@Override
protected void postProcessBeanDefinition(HibernateRepositoryConfiguration ctx, BeanDefinitionBuilder builder,
        BeanDefinitionRegistry registry, Object beanSource) {
    String transactionManagerRef = StringUtils.hasText(ctx.getTransactionManagerRef())
            ? ctx.getTransactionManagerRef()
            : DEFAULT_TRANSACTION_MANAGER_BEAN_NAME;
    builder.addPropertyValue(DEFAULT_TRANSACTION_MANAGER_BEAN_NAME, transactionManagerRef);

    String sessionFactoryRef = StringUtils.hasText(ctx.getSessionFactoryRef()) ? ctx.getSessionFactoryRef()
            : DEFAULT_SESSION_FACTORY_BEAN_NAME;
    builder.addPropertyReference(DEFAULT_SESSION_FACTORY_BEAN_NAME, sessionFactoryRef);
}

From source file:info.jtrac.mail.MailSender.java

public MailSender(Map<String, String> config, MessageSource messageSource, String defaultLocale) {
    // initialize email sender
    this.messageSource = messageSource;
    this.defaultLocale = StringUtils.parseLocaleString(defaultLocale);
    String mailSessionJndiName = config.get("mail.session.jndiname");
    if (StringUtils.hasText(mailSessionJndiName)) {
        initMailSenderFromJndi(mailSessionJndiName);
    }/*  www .j  a  v  a2 s.  co  m*/
    if (sender == null) {
        initMailSenderFromConfig(config);
    }
    // if sender is still null the send* methods will not
    // do anything when called and will just return immediately
}

From source file:info.jtrac.hibernate.SchemaHelper.java

/**
 * create tables using the given Hibernate configuration
 *//*from w  ww .j av  a 2  s . c o m*/
public void createSchema() {
    Configuration cfg = new Configuration();
    if (StringUtils.hasText(dataSourceJndiName)) {
        cfg.setProperty("hibernate.connection.datasource", dataSourceJndiName);
    } else {
        cfg.setProperty("hibernate.connection.driver_class", driverClassName);
        cfg.setProperty("hibernate.connection.url", url);
        cfg.setProperty("hibernate.connection.username", username);
        cfg.setProperty("hibernate.connection.password", password);
    }
    cfg.setProperty("hibernate.dialect", hibernateDialect);
    for (String resource : mappingResources) {
        cfg.addResource(resource);
    }
    logger.info("begin database schema creation =========================");
    new SchemaUpdate(cfg).execute(true, true);
    logger.info("end database schema creation ===========================");
}

From source file:your.microservice.core.util.YourServletUriComponentsBuilder.java

/**
 * Prepare a builder from the host, port, scheme, context path, and
 * servlet mapping of an HttpServletRequest. The results may vary depending
 * on the type of servlet mapping used./*from   ww w  .  j av a2 s. com*/
 *
 * <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path
 * will end with "/main". If the servlet is mapped otherwise, e.g.
 * {@code "/"} or {@code "*.do"}, the result will be the same as
 * if calling {@link #fromContextPath(HttpServletRequest)}.
 * @param request request to build path from
 * @return a URI component builder
 */
public static YourServletUriComponentsBuilder fromServletMapping(HttpServletRequest request) {
    YourServletUriComponentsBuilder builder = fromContextPath(request);
    if (StringUtils.hasText(new UrlPathHelper().getPathWithinServletMapping(request))) {
        builder.path(request.getServletPath());
    }
    return builder;
}